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