From 0f781d2aa55117b40f2e5dda3ab5bccc1e21594c Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Fri, 27 Oct 2023 12:50:50 -0700 Subject: [PATCH] boot: load device tree even if no original config exists Firmware may not have loaded a devicetree, for example if the device shipped with windows and exclusively supports ACPI. We should always load the specified devicetree regardless of firmware state to enable booting on platforms where Linux only supports DT. Note: in _cleanup, the orig. config is NULL in this case, and passing NULL to InstallConfigurationTable is permitted by the EFI spec. See: https://uefi.org/specs/UEFI/2.10/07_Services_Boot_Services.html Fixes #24059 Co-authored-by: Daniel Thompson --- src/boot/efi/devicetree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/boot/efi/devicetree.c b/src/boot/efi/devicetree.c index 3916bca946f..b1397805103 100644 --- a/src/boot/efi/devicetree.c +++ b/src/boot/efi/devicetree.c @@ -71,9 +71,10 @@ EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir assert(root_dir); assert(name); + /* Capture the original value for the devicetree table. NULL is not an error in this case so we don't + * need to check the return value. NULL simply means the system fw had no devicetree initially (and + * is the correct value to use to return to the initial state if needed). */ state->orig = find_configuration_table(MAKE_GUID_PTR(EFI_DTB_TABLE)); - if (!state->orig) - return EFI_UNSUPPORTED; err = root_dir->Open(root_dir, &handle, name, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY); if (err != EFI_SUCCESS) @@ -112,9 +113,10 @@ EFI_STATUS devicetree_install_from_memory( assert(state); assert(dtb_buffer && dtb_length > 0); + /* Capture the original value for the devicetree table. NULL is not an error in this case so we don't + * need to check the return value. NULL simply means the system fw had no devicetree initially (and + * is the correct value to use to return to the initial state if needed). */ state->orig = find_configuration_table(MAKE_GUID_PTR(EFI_DTB_TABLE)); - if (!state->orig) - return EFI_UNSUPPORTED; err = devicetree_allocate(state, dtb_length); if (err != EFI_SUCCESS)