2aacef
From 8cbb38625364640f390b2df2cda44ff3877fb16d Mon Sep 17 00:00:00 2001
2aacef
From: Jan Janssen <medhefgo@web.de>
2aacef
Date: Mon, 14 Nov 2022 14:37:13 +0100
2aacef
Subject: [PATCH] boot: Do not require a loaded image path
2aacef
2aacef
If the device path to text protocol is not available (looking angrily at
2aacef
Apple) we would fail to boot because we cannot get the loaded image
2aacef
path. As this is only used for cosmetic purposes, we can just silently
2aacef
continue.
2aacef
2aacef
Fixes: #25363
2aacef
(cherry picked from commit af7ef648cddeb96da525de2410565d166f75cc96)
2aacef
2aacef
Related: #2138081
2aacef
---
2aacef
 src/boot/efi/boot.c | 13 +++----------
2aacef
 1 file changed, 3 insertions(+), 10 deletions(-)
2aacef
2aacef
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
2aacef
index 17d4ec2d09..b490a1d972 100644
2aacef
--- a/src/boot/efi/boot.c
2aacef
+++ b/src/boot/efi/boot.c
2aacef
@@ -471,7 +471,6 @@ static void print_status(Config *config, char16_t *loaded_image_path) {
2aacef
         _cleanup_free_ char16_t *device_part_uuid = NULL;
2aacef
 
2aacef
         assert(config);
2aacef
-        assert(loaded_image_path);
2aacef
 
2aacef
         clear_screen(COLOR_NORMAL);
2aacef
         console_query_mode(&x_max, &y_max);
2aacef
@@ -619,7 +618,6 @@ static bool menu_run(
2aacef
 
2aacef
         assert(config);
2aacef
         assert(chosen_entry);
2aacef
-        assert(loaded_image_path);
2aacef
 
2aacef
         EFI_STATUS err;
2aacef
         UINTN visible_max = 0;
2aacef
@@ -1478,7 +1476,7 @@ static void config_entry_add_type1(
2aacef
                         entry->loader = xstra_to_path(value);
2aacef
 
2aacef
                         /* do not add an entry for ourselves */
2aacef
-                        if (loaded_image_path && strcaseeq16(entry->loader, loaded_image_path)) {
2aacef
+                        if (strcaseeq16(entry->loader, loaded_image_path)) {
2aacef
                                 entry->type = LOADER_UNDEFINED;
2aacef
                                 break;
2aacef
                         }
2aacef
@@ -1908,12 +1906,11 @@ static ConfigEntry *config_entry_add_loader_auto(
2aacef
         assert(root_dir);
2aacef
         assert(id);
2aacef
         assert(title);
2aacef
-        assert(loader || loaded_image_path);
2aacef
 
2aacef
         if (!config->auto_entries)
2aacef
                 return NULL;
2aacef
 
2aacef
-        if (loaded_image_path) {
2aacef
+        if (!loader) {
2aacef
                 loader = L"\\EFI\\BOOT\\BOOT" EFI_MACHINE_TYPE_NAME ".efi";
2aacef
 
2aacef
                 /* We are trying to add the default EFI loader here,
2aacef
@@ -2562,7 +2559,6 @@ static void export_variables(
2aacef
         char16_t uuid[37];
2aacef
 
2aacef
         assert(loaded_image);
2aacef
-        assert(loaded_image_path);
2aacef
 
2aacef
         efivar_set_time_usec(LOADER_GUID, L"LoaderTimeInitUSec", init_usec);
2aacef
         efivar_set(LOADER_GUID, L"LoaderInfo", L"systemd-boot " GIT_VERSION, 0);
2aacef
@@ -2591,7 +2587,6 @@ static void config_load_all_entries(
2aacef
 
2aacef
         assert(config);
2aacef
         assert(loaded_image);
2aacef
-        assert(loaded_image_path);
2aacef
         assert(root_dir);
2aacef
 
2aacef
         config_load_defaults(config, root_dir);
2aacef
@@ -2676,9 +2671,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
2aacef
         if (err != EFI_SUCCESS)
2aacef
                 return log_error_status_stall(err, L"Error getting a LoadedImageProtocol handle: %r", err);
2aacef
 
2aacef
-        err = device_path_to_str(loaded_image->FilePath, &loaded_image_path);
2aacef
-        if (err != EFI_SUCCESS)
2aacef
-                return log_error_status_stall(err, L"Error getting loaded image path: %r", err);
2aacef
+        (void) device_path_to_str(loaded_image->FilePath, &loaded_image_path);
2aacef
 
2aacef
         export_variables(loaded_image, loaded_image_path, init_usec);
2aacef