The debug version of the UEFI shell on x86 requires a HOB list. This implementation allows to generate an empty HOB list.
Generate the HOB list on the sandbox and on x86 by default. Signed-off-by: Heinrich Schuchardt <[email protected]> --- v2: Free allocated memory if efi_install_configuration_table() fails. --- include/efi_hob.h | 32 ++++++++++++++++++++++++++++++++ include/efi_loader.h | 9 +++++++++ lib/efi_loader/Kconfig | 8 ++++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_hob.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 7 +++++++ 6 files changed, 95 insertions(+) create mode 100644 include/efi_hob.h create mode 100644 lib/efi_loader/efi_hob.c diff --git a/include/efi_hob.h b/include/efi_hob.h new file mode 100644 index 00000000000..b401e6c2fa1 --- /dev/null +++ b/include/efi_hob.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * HOB list + * + * Copyright (c) 2025 Heinrich Schuchardt + */ + +#ifndef _EFI_HOB_H +#define _EFI_HOB_H 1 + +#include <efi.h> + +/** + * define EFI_HOB_TYPE_END_OF_HOB_LIST - end of hob list + */ +#define EFI_HOB_TYPE_END_OF_HOB_LIST 0xFFFF + +/** + * struct efi_hob_header - EFI_HOB_GENERIC_HEADER + */ +struct efi_hob_header { + /** @hob_type: type of HOB data structure */ + u16 hob_type; + /** @hob_length: HOB length including header in bytes */ + u16 hob_length; + /** @reserved: always 0 */ + u32 reserved; +}; + +extern const efi_guid_t efi_guid_hob_list; + +#endif /* _EFI_HOB_H */ diff --git a/include/efi_loader.h b/include/efi_loader.h index 3e70ac07055..6183da64196 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -714,6 +714,15 @@ efi_status_t efi_acpi_register(void); */ efi_status_t efi_smbios_register(void); +/** + * efi_hob_list_register() - install HOB list + * + * The EFI shell on X86 requires a HOB list + * + * Return: status code + */ +efi_status_t efi_hob_list_register(void); + struct efi_simple_file_system_protocol * efi_fs_from_path(struct efi_device_path *fp); diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 13e44be1d06..b4f0d1dc23a 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -406,6 +406,14 @@ config EFI_LOADER_HII U-Boot implements enough of its features to be able to run the UEFI Shell, but not more than that. +config EFI_HOB + bool 'HOB list' + default y if SANDBOX || X86 + help + Install a HOB list. The UEFI shell on x86 requires a HOB list + to be present. Our list is empty as we don't implement the + UEFI Platform Initialization Specification. + config EFI_UNICODE_COLLATION_PROTOCOL2 bool "Unicode collation protocol" default y diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index bfa607c8827..f010101125f 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -39,6 +39,7 @@ obj-y += efi_dt_fixup.o obj-y += efi_fdt.o obj-y += efi_file.o obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o efi_hii_config.o +obj-$(CONFIG_EFI_HOB) += efi_hob.o obj-y += efi_image_loader.o obj-y += efi_load_options.o obj-y += efi_memory.o diff --git a/lib/efi_loader/efi_hob.c b/lib/efi_loader/efi_hob.c new file mode 100644 index 00000000000..f15439d31e0 --- /dev/null +++ b/lib/efi_loader/efi_hob.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Provide HOB list + * + * Copyright (c) 2025 Heinrich Schuchardt + */ + +#include <efi_hob.h> +#include <efi_loader.h> + +const efi_guid_t efi_guid_hob_list = EFI_HOB_LIST; + +/** + * efi_hob_list_register() - install HOB list + * + * The EFI shell on X86 requires a HOB list + * + * Return: status code + */ +efi_status_t efi_hob_list_register(void) +{ + struct efi_hob_header *hob; + efi_status_t ret; + + hob = efi_alloc(sizeof(struct efi_hob_header)); + if (!hob) + return EFI_OUT_OF_RESOURCES; + + hob->hob_type = EFI_HOB_TYPE_END_OF_HOB_LIST; + hob->hob_length = sizeof(struct efi_hob_header); + hob->reserved = 0; + + ret = efi_install_configuration_table(&efi_guid_hob_list, hob); + if (ret != EFI_SUCCESS) + efi_free_pool(hob); + + return ret; +} diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index f06cf49e443..e9b6ffd27b8 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -7,6 +7,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_hob.h> #include <efi_loader.h> #include <efi_variable.h> #include <log.h> @@ -308,6 +309,12 @@ efi_status_t efi_init_obj_list(void) goto out; } + if (IS_ENABLED(CONFIG_EFI_HOB)) { + ret = efi_hob_list_register(); + if (ret != EFI_SUCCESS) + goto out; + } + if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { ret = efi_tcg2_register(); if (ret != EFI_SUCCESS) -- 2.51.0

