From 1dd705cf990364eaf7312ed327b93fc04b43fbe5 Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Sat, 28 Jan 2023 13:56:14 +0900 Subject: efi: use 32-bit alignment for efi_guid_t Current U-Boot implements 64-bit boundary for efi_guid_t structure. It follows the UEFI specification, page 21 of the UEFI Specification v2.10 says about EFI_GUID: 128-bit buffer containing a unique identifier value. Unless otherwise specified, aligned on a 64-bit boundary. On the other hand, page 163 of the UEFI specification v2.10 and EDK2 reference implementation both define EFI_GUID as struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment is 32-bit not 64-bit like U-Boot efi_guid_t. Due to this alignment difference, EDK2 application "CapsuleApp.efi -P" does not work as expected. This calls EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo() and dump the EFI_FIRMWARE_IMAGE_DESCRIPTOR structure, offsetof(EFI_FIRMWARE_IMAGE_DESCRIPTOR, ImageTypeId) is different, 8 in U-Boot and 4 in EDK2(CapsuleApp.efi). Here is the wrong EFI_GUID dump. wrong dump : ImageTypeId - 00000000-7D83-058B-D550-474CA19560D8 expected : ImageTypeId - 058B7D83-50D5-4C47-A195-60D86AD341C4 EFI_FIRMWARE_IMAGE_DESCRIPTOR structure is defined in UEFI specification: typedef struct { UINT8 ImageIndex; EFI_GUID ImageTypeId; UINT64 ImageId } EFI_FIRMWARE_IMAGE_DESCRIPTOR; There was the relevant patch for linux kernel to use 32-bit alignment for efi_guid_t [1]. U-Boot should get aligned to EDK2 reference implementation and linux kernel. Due to this alignment change, efi_hii_ref structure in include/efi_api.h is affected, but it is not used in the current U-Boot code. [1] https://lore.kernel.org/all/20190202094119.13230-5-ard.biesheuvel@linaro.org/ Cc: Ilias Apalodimas Signed-off-by: Masahisa Kojima Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- include/efi.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/efi.h b/include/efi.h index 42f4e58a917..c3087d3da28 100644 --- a/include/efi.h +++ b/include/efi.h @@ -54,9 +54,18 @@ struct efi_device_path; +/* + * The EFI spec defines the EFI_GUID as + * "128-bit buffer containing a unique identifier value. Unless otherwise specified, + * aligned on a 64-bit boundary". + * Page 163 of the UEFI specification v2.10 and + * EDK2 reference implementation both define EFI_GUID as + * struct { u32 a; u16; b; u16 c; u8 d[8]; }; which is 4-byte + * aligned. + */ typedef struct { u8 b[16]; -} efi_guid_t __attribute__((aligned(8))); +} efi_guid_t __attribute__((aligned(4))); #define EFI_BITS_PER_LONG (sizeof(long) * 8) -- cgit v1.3.1 From 88df36346c767f8756e54cc1941b6cda180b61db Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Thu, 2 Feb 2023 18:24:44 +0900 Subject: eficonfig: CTRL+S to save the boot order The change boot order menu in eficonfig can have at most INT_MAX lines and it is troublesome to scroll down to the "Save" entry. This commit assigns CTRL+S to save the boot order. Signed-off-by: Masahisa Kojima Acked-by: Heinrich Schuchardt --- cmd/eficonfig.c | 6 +++++- common/menu.c | 3 +++ include/menu.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index f365a988d4d..0a17b8cf343 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -28,7 +28,7 @@ const char *eficonfig_menu_desc = static const char *eficonfig_change_boot_order_desc = " Press UP/DOWN to move, +/- to change orde\n" " Press SPACE to activate or deactivate the entry\n" - " Select [Save] to complete, ESC to quit"; + " CTRL+S to save, ESC to quit"; static struct efi_simple_text_output_protocol *cout; static int avail_row; @@ -1983,6 +1983,10 @@ char *eficonfig_choice_change_boot_order(void *data) eficonfig_menu_down(efi_menu); return NULL; + case BKEY_SAVE: + /* force to select "Save" entry */ + efi_menu->active = efi_menu->count - 2; + fallthrough; case BKEY_SELECT: /* "Save" */ if (efi_menu->active == efi_menu->count - 2) { diff --git a/common/menu.c b/common/menu.c index cdcdbb2a185..94514177e4e 100644 --- a/common/menu.c +++ b/common/menu.c @@ -503,6 +503,9 @@ enum bootmenu_key bootmenu_conv_key(int ichar) case CTL_CH('n'): key = BKEY_DOWN; break; + case CTL_CH('s'): + key = BKEY_SAVE; + break; case '+': key = BKEY_PLUS; break; diff --git a/include/menu.h b/include/menu.h index 1e88141d6bf..64ce89b7d26 100644 --- a/include/menu.h +++ b/include/menu.h @@ -53,6 +53,7 @@ enum bootmenu_key { BKEY_PLUS, BKEY_MINUS, BKEY_SPACE, + BKEY_SAVE, BKEY_COUNT, }; -- cgit v1.3.1 From 1f0583beeb32b0eab4d87ea9c0bef247432aa0c6 Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Thu, 2 Feb 2023 18:24:45 +0900 Subject: eficonfig: set EFICONFIG_ENTRY_NUM_MAX to INT_MAX - 1 eficonfig_append_menu_entryi() accepts the number of entries less than or equal to EFICONFIG_ENTRY_NUM_MAX. EFICONFIG_ENTRY_NUM_MAX is currently set as INT_MAX, so the invalid menu count check(efi_menu->count > EFICONFIG_ENTRY_NUM_MAX) in eficonfig_process_common() is always false. This commit sets EFICONFIG_ENTRY_NUM_MAX to (INT_MAX - 1). Reported-by: Coverity (CID 435659) Signed-off-by: Masahisa Kojima Reviewed-by: Heinrich Schuchardt --- include/efi_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/efi_config.h b/include/efi_config.h index e5edbb5e090..01ce9b2b06d 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -11,7 +11,7 @@ #include #include -#define EFICONFIG_ENTRY_NUM_MAX INT_MAX +#define EFICONFIG_ENTRY_NUM_MAX (INT_MAX - 1) #define EFICONFIG_VOLUME_PATH_MAX 512 #define EFICONFIG_FILE_PATH_MAX 512 #define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16)) -- cgit v1.3.1 From 4db17a4b12524d0ec2dc30913dbbf44f968ce8e0 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 10 Feb 2023 08:13:23 +0100 Subject: efi_loader: fix struct efi_input_key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UEFI specification defines filed UnicodeChar as CHAR16. We use u16 for CHAR16 throughout our code. The change fixes the following errors: lib/efi_loader/initrddump.c: In function ‘efi_input’: lib/efi_loader/initrddump.c:218:38: warning: comparison is always false due to limited range of data type [-Wtype-limits] 218 | if (key.unicode_char >= 0xD800 && key.unicode_char <= 0xDBFF) | ^~ lib/efi_loader/initrddump.c:218:68: warning: comparison is always true due to limited range of data type [-Wtype-limits] 218 | if (key.unicode_char >= 0xD800 && key.unicode_char <= 0xDBFF) | ^~ Fixes: 867a6ac86dd8 ("efi: Add start-up library code") Reported-by: Marek Vasut Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/efi_api.h b/include/efi_api.h index 9bd70b0f18c..e1cdaf52479 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -817,7 +817,7 @@ struct efi_simple_text_output_protocol { struct efi_input_key { u16 scan_code; - s16 unicode_char; + u16 unicode_char; }; #define EFI_SHIFT_STATE_INVALID 0x00000000 -- cgit v1.3.1 From 60e3fedc64532c66f5bcd7c5c3d95e51ab2783e7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 10 Feb 2023 08:23:24 +0100 Subject: efi_loader: add definition for efi_main() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit U-Boot provides multiple EFI applications. The entry point is called efi_main(). Provide a definition for this function. This avoids build warnings like lib/efi_loader/initrddump.c:468:21: warning: no previous prototype for ‘efi_main’ [-Wmissing-prototypes] 468 | efi_status_t EFIAPI efi_main(efi_handle_t image_handle, | ^~~~~~~~ Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/efi_api.h b/include/efi_api.h index e1cdaf52479..2d18d25a713 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -513,6 +513,16 @@ struct efi_system_table { struct efi_configuration_table *tables; }; +/** + * efi_main() - entry point of EFI applications + * + * @image_handle: handle with the Loaded Image Protocol + * @systab: pointer to the system table + * Return: status code + */ +efi_status_t EFIAPI efi_main(efi_handle_t image_handle, + struct efi_system_table *systab); + #define EFI_LOADED_IMAGE_PROTOCOL_GUID \ EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \ 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) -- cgit v1.3.1 From a9f20ef37aae226e9d4366d764869bdcf32ddd82 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 10 Feb 2023 09:01:13 +0100 Subject: efi_loader: provide definition for efi_add_known_memory() We should provide a definition in an include for efi_add_known_memory(). Signed-off-by: Heinrich Schuchardt --- include/efi_loader.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/efi_loader.h b/include/efi_loader.h index 4560b0d04cb..c664d6cdf2c 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -1137,4 +1137,11 @@ efi_status_t efi_console_get_u16_string efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size); +/** + * efi_add_known_memory() - add memory banks to EFI memory map + * + * This weak function may be overridden for specific architectures. + */ +void efi_add_known_memory(void); + #endif /* _EFI_LOADER_H */ -- cgit v1.3.1