From c1528f324c6068936a629233b12c66774accc359 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 11:55:39 +0100 Subject: lib: compile uuid_guid_get_str if CONFIG_LIB_UUID=y Currently uuid_guid_get_str() is only built if CONFIG_PARTITION_TYPE_GUID=y. To make it usable for other GUIDs compile it if CONFIG_LIB_UUID=y. The linker will take care of removing it if it is unused. Signed-off-by: Heinrich Schuchardt --- lib/uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/uuid.c b/lib/uuid.c index e4703dc..56c452e 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -86,11 +86,11 @@ int uuid_str_valid(const char *uuid) return 1; } -#ifdef CONFIG_PARTITION_TYPE_GUID static const struct { const char *string; efi_guid_t guid; } list_guid[] = { +#ifdef CONFIG_PARTITION_TYPE_GUID {"system", PARTITION_SYSTEM_GUID}, {"mbr", LEGACY_MBR_PARTITION_GUID}, {"msft", PARTITION_MSFT_RESERVED_GUID}, @@ -100,6 +100,7 @@ static const struct { {"swap", PARTITION_LINUX_SWAP_GUID}, {"lvm", PARTITION_LINUX_LVM_GUID}, {"u-boot-env", PARTITION_U_BOOT_ENVIRONMENT}, +#endif }; /* @@ -139,7 +140,6 @@ const char *uuid_guid_get_str(const unsigned char *guid_bin) } return NULL; } -#endif /* * uuid_str_to_bin() - convert string UUID or GUID to big endian binary data. -- cgit v1.1 From 04872381206a05d9b9d8211067e59b353d2929fb Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 11:59:21 +0100 Subject: lib: printf code %pUs for GUID text representation In different places text representations are used for GUIDs, e.g. * command efidebug * command part list for GPT partitions To allow reducing code duplication introduce a new printf code %pUs. It will call uuid_guid_get_str() to get a text representation. If none is found it will fallback to %pUl and print a hexadecimal representation. Signed-off-by: Heinrich Schuchardt --- lib/vsprintf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index de9f236..2c84649 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -255,7 +255,7 @@ static char *number(char *buf, char *end, u64 num, return buf; } -static char *string(char *buf, char *end, char *s, int field_width, +static char *string(char *buf, char *end, const char *s, int field_width, int precision, int flags) { int len, i; @@ -387,12 +387,14 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width, * %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10 * %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10 * %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10 + * %pUs: GUID text representation if known or fallback to %pUl */ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width, int precision, int flags, const char *fmt) { char uuid[UUID_STR_LEN + 1]; int str_format; + const char *str; switch (*(++fmt)) { case 'L': @@ -404,6 +406,13 @@ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width, case 'B': str_format = UUID_STR_FORMAT_STD | UUID_STR_UPPER_CASE; break; + case 's': + str = uuid_guid_get_str(addr); + if (str) + return string(buf, end, str, + field_width, precision, flags); + str_format = UUID_STR_FORMAT_GUID; + break; default: str_format = UUID_STR_FORMAT_STD; break; -- cgit v1.1 From a4492eeee14294c61680d56893df4d73880f098e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 12:23:19 +0100 Subject: disk: simplify part_print_efi() Use printf code %pUs to print the text representation of the partition type GUID. Signed-off-by: Heinrich Schuchardt --- disk/part_efi.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 3809333..94e2930 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -221,8 +221,7 @@ void part_print_efi(struct blk_desc *dev_desc) ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); gpt_entry *gpt_pte = NULL; int i = 0; - char uuid[UUID_STR_LEN + 1]; - unsigned char *uuid_bin; + unsigned char *uuid; /* This function validates AND fills in the GPT header and PTE */ if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) @@ -245,17 +244,13 @@ void part_print_efi(struct blk_desc *dev_desc) le64_to_cpu(gpt_pte[i].ending_lba), print_efiname(&gpt_pte[i])); printf("\tattrs:\t0x%016llx\n", gpt_pte[i].attributes.raw); - uuid_bin = (unsigned char *)gpt_pte[i].partition_type_guid.b; - uuid_bin_to_str(uuid_bin, uuid, UUID_STR_FORMAT_GUID); - printf("\ttype:\t%s\n", uuid); - if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID)) { - const char *type = uuid_guid_get_str(uuid_bin); - if (type) - printf("\ttype:\t%s\n", type); - } - uuid_bin = (unsigned char *)gpt_pte[i].unique_partition_guid.b; - uuid_bin_to_str(uuid_bin, uuid, UUID_STR_FORMAT_GUID); - printf("\tguid:\t%s\n", uuid); + uuid = (unsigned char *)gpt_pte[i].partition_type_guid.b; + if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID)) + printf("\ttype:\t%pUl\n\t\t(%pUs)\n", uuid, uuid); + else + printf("\ttype:\t%pUl\n", uuid); + uuid = (unsigned char *)gpt_pte[i].unique_partition_guid.b; + printf("\tguid:\t%pUl\n", uuid); } /* Remember to free pte */ -- cgit v1.1 From d3adee1db87066b1bf8e97fbfe187153ba273628 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 13:04:06 +0100 Subject: sandbox: imply PARTITION_TYPE_GUID CONFIG_PARTITION_TYPE_GUID=y is needed for testing some GPT related functionality. Signed-off-by: Heinrich Schuchardt --- arch/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/Kconfig b/arch/Kconfig index ee32e83..ffb8f5c 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -175,6 +175,7 @@ config SANDBOX imply AVB_VERIFY imply LIBAVB imply CMD_AVB + imply PARTITION_TYPE_GUID imply SCP03 imply CMD_SCP03 imply UDP_FUNCTION_FASTBOOT -- cgit v1.1 From 04641c14071865f3d6b8d39a8ab12a1afa9bda72 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 13:22:06 +0100 Subject: test: add test for %pUs Add a unit test for the %pUs printf code. Use ut_asserteq_str() for checking string results. Signed-off-by: Heinrich Schuchardt --- test/print_ut.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/print_ut.c b/test/print_ut.c index 7b2e7bb..194387f 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -30,17 +30,29 @@ static int print_guid(struct unit_test_state *uts) unsigned char guid[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + unsigned char guid_esp[16] = { + 0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11, + 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B + }; char str[40]; int ret; sprintf(str, "%pUb", guid); - ut_assertok(strcmp("01020304-0506-0708-090a-0b0c0d0e0f10", str)); + ut_asserteq_str("01020304-0506-0708-090a-0b0c0d0e0f10", str); sprintf(str, "%pUB", guid); - ut_assertok(strcmp("01020304-0506-0708-090A-0B0C0D0E0F10", str)); + ut_asserteq_str("01020304-0506-0708-090A-0B0C0D0E0F10", str); sprintf(str, "%pUl", guid); - ut_assertok(strcmp("04030201-0605-0807-090a-0b0c0d0e0f10", str)); + ut_asserteq_str("04030201-0605-0807-090a-0b0c0d0e0f10", str); + sprintf(str, "%pUs", guid); + ut_asserteq_str("04030201-0605-0807-090a-0b0c0d0e0f10", str); sprintf(str, "%pUL", guid); - ut_assertok(strcmp("04030201-0605-0807-090A-0B0C0D0E0F10", str)); + ut_asserteq_str("04030201-0605-0807-090A-0B0C0D0E0F10", str); + sprintf(str, "%pUs", guid_esp); + if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { /* brace needed */ + ut_asserteq_str("system", str); + } else { + ut_asserteq_str("c12a7328-f81f-11d2-ba4b-00a0c93ec93b", str); + } ret = snprintf(str, 4, "%pUL", guid); ut_asserteq(0, str[3]); ut_asserteq(36, ret); -- cgit v1.1 From 3adae64220be502cd6d522c96a3af7dd420a1a67 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 14:10:23 +0100 Subject: cmd: efidebug: simplify printing GUIDs Use "%pS" to print text representations of GUIDs. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 160 ++----------------------------------------------- include/efi_api.h | 8 +++ include/efi_dt_fixup.h | 4 -- include/efi_rng.h | 4 -- lib/uuid.c | 116 +++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 164 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index a977ca9..66ce0fc 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -502,149 +502,6 @@ static int do_efi_show_drivers(struct cmd_tbl *cmdtp, int flag, return CMD_RET_SUCCESS; } -static const struct { - const char *text; - const efi_guid_t guid; -} guid_list[] = { - { - "Device Path", - EFI_DEVICE_PATH_PROTOCOL_GUID, - }, - { - "Device Path To Text", - EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, - }, - { - "Device Path Utilities", - EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, - }, - { - "Unicode Collation 2", - EFI_UNICODE_COLLATION_PROTOCOL2_GUID, - }, - { - "Driver Binding", - EFI_DRIVER_BINDING_PROTOCOL_GUID, - }, - { - "Simple Text Input", - EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, - }, - { - "Simple Text Input Ex", - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, - }, - { - "Simple Text Output", - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, - }, - { - "Block IO", - EFI_BLOCK_IO_PROTOCOL_GUID, - }, - { - "Simple File System", - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, - }, - { - "Loaded Image", - EFI_LOADED_IMAGE_PROTOCOL_GUID, - }, - { - "Graphics Output", - EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, - }, - { - "HII String", - EFI_HII_STRING_PROTOCOL_GUID, - }, - { - "HII Database", - EFI_HII_DATABASE_PROTOCOL_GUID, - }, - { - "HII Config Routing", - EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, - }, - { - "Load File2", - EFI_LOAD_FILE2_PROTOCOL_GUID, - }, - { - "Random Number Generator", - EFI_RNG_PROTOCOL_GUID, - }, - { - "Simple Network", - EFI_SIMPLE_NETWORK_PROTOCOL_GUID, - }, - { - "PXE Base Code", - EFI_PXE_BASE_CODE_PROTOCOL_GUID, - }, - { - "Device-Tree Fixup", - EFI_DT_FIXUP_PROTOCOL_GUID, - }, - { - "System Partition", - PARTITION_SYSTEM_GUID - }, - { - "Firmware Management", - EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID - }, - /* Configuration table GUIDs */ - { - "ACPI table", - EFI_ACPI_TABLE_GUID, - }, - { - "EFI System Resource Table", - EFI_SYSTEM_RESOURCE_TABLE_GUID, - }, - { - "device tree", - EFI_FDT_GUID, - }, - { - "SMBIOS table", - SMBIOS_TABLE_GUID, - }, - { - "Runtime properties", - EFI_RT_PROPERTIES_TABLE_GUID, - }, - { - "TCG2 Final Events Table", - EFI_TCG2_FINAL_EVENTS_TABLE_GUID, - }, -}; - -/** - * get_guid_text - get string of GUID - * - * Return description of GUID. - * - * @guid: GUID - * Return: description of GUID or NULL - */ -static const char *get_guid_text(const void *guid) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(guid_list); i++) { - /* - * As guidcmp uses memcmp() we can safely accept unaligned - * GUIDs. - */ - if (!guidcmp(&guid_list[i].guid, guid)) - return guid_list[i].text; - } - - return NULL; -} - /** * do_efi_show_handles() - show UEFI handles * @@ -664,7 +521,6 @@ static int do_efi_show_handles(struct cmd_tbl *cmdtp, int flag, efi_handle_t *handles; efi_guid_t **guid; efi_uintn_t num, count, i, j; - const char *guid_text; efi_status_t ret; ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL, @@ -692,11 +548,7 @@ static int do_efi_show_handles(struct cmd_tbl *cmdtp, int flag, else putc(' '); - guid_text = get_guid_text(guid[j]); - if (guid_text) - puts(guid_text); - else - printf("%pUl", guid[j]); + printf("%pUs", guid[j]); } putc('\n'); } @@ -873,14 +725,10 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { efi_uintn_t i; - const char *guid_str; - for (i = 0; i < systab.nr_tables; ++i) { - guid_str = get_guid_text(&systab.tables[i].guid); - if (!guid_str) - guid_str = ""; - printf("%pUl %s\n", &systab.tables[i].guid, guid_str); - } + for (i = 0; i < systab.nr_tables; ++i) + printf("%pUl (%pUs)\n", + &systab.tables[i].guid, &systab.tables[i].guid); return CMD_RET_SUCCESS; } diff --git a/include/efi_api.h b/include/efi_api.h index ec9fa89..a60d1bc 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -426,6 +426,14 @@ struct efi_runtime_services { EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, \ 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25) +#define EFI_RNG_PROTOCOL_GUID \ + EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, \ + 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44) + +#define EFI_DT_FIXUP_PROTOCOL_GUID \ + EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, \ + 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00) + /** * struct efi_configuration_table - EFI Configuration Table * diff --git a/include/efi_dt_fixup.h b/include/efi_dt_fixup.h index 9066e8d..8338253 100644 --- a/include/efi_dt_fixup.h +++ b/include/efi_dt_fixup.h @@ -7,10 +7,6 @@ #include -#define EFI_DT_FIXUP_PROTOCOL_GUID \ - EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, \ - 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00) - #define EFI_DT_FIXUP_PROTOCOL_REVISION 0x00010000 /* Add nodes and update properties */ diff --git a/include/efi_rng.h b/include/efi_rng.h index 35f5967..3c62238 100644 --- a/include/efi_rng.h +++ b/include/efi_rng.h @@ -10,10 +10,6 @@ #include /* EFI random number generation protocol related GUID definitions */ -#define EFI_RNG_PROTOCOL_GUID \ - EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, \ - 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44) - #define EFI_RNG_ALGORITHM_RAW \ EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, \ 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61) diff --git a/lib/uuid.c b/lib/uuid.c index 56c452e..60b7ca1 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -101,6 +102,121 @@ static const struct { {"lvm", PARTITION_LINUX_LVM_GUID}, {"u-boot-env", PARTITION_U_BOOT_ENVIRONMENT}, #endif +#ifdef CONFIG_CMD_EFIDEBUG + { + "Device Path", + EFI_DEVICE_PATH_PROTOCOL_GUID, + }, + { + "Device Path To Text", + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, + }, + { + "Device Path Utilities", + EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, + }, + { + "Unicode Collation 2", + EFI_UNICODE_COLLATION_PROTOCOL2_GUID, + }, + { + "Driver Binding", + EFI_DRIVER_BINDING_PROTOCOL_GUID, + }, + { + "Simple Text Input", + EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, + }, + { + "Simple Text Input Ex", + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, + }, + { + "Simple Text Output", + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, + }, + { + "Block IO", + EFI_BLOCK_IO_PROTOCOL_GUID, + }, + { + "Simple File System", + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, + }, + { + "Loaded Image", + EFI_LOADED_IMAGE_PROTOCOL_GUID, + }, + { + "Graphics Output", + EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, + }, + { + "HII String", + EFI_HII_STRING_PROTOCOL_GUID, + }, + { + "HII Database", + EFI_HII_DATABASE_PROTOCOL_GUID, + }, + { + "HII Config Routing", + EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, + }, + { + "Load File2", + EFI_LOAD_FILE2_PROTOCOL_GUID, + }, + { + "Random Number Generator", + EFI_RNG_PROTOCOL_GUID, + }, + { + "Simple Network", + EFI_SIMPLE_NETWORK_PROTOCOL_GUID, + }, + { + "PXE Base Code", + EFI_PXE_BASE_CODE_PROTOCOL_GUID, + }, + { + "Device-Tree Fixup", + EFI_DT_FIXUP_PROTOCOL_GUID, + }, + { + "System Partition", + PARTITION_SYSTEM_GUID + }, + { + "Firmware Management", + EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID + }, + /* Configuration table GUIDs */ + { + "ACPI table", + EFI_ACPI_TABLE_GUID, + }, + { + "EFI System Resource Table", + EFI_SYSTEM_RESOURCE_TABLE_GUID, + }, + { + "device tree", + EFI_FDT_GUID, + }, + { + "SMBIOS table", + SMBIOS_TABLE_GUID, + }, + { + "Runtime properties", + EFI_RT_PROPERTIES_TABLE_GUID, + }, + { + "TCG2 Final Events Table", + EFI_TCG2_FINAL_EVENTS_TABLE_GUID, + }, +#endif }; /* -- cgit v1.1 From ce00a7401aef52b6a67f496fc569c960e53c059e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 14:15:31 +0100 Subject: efi_loader: use %pUs for printing GUIDs For printing GUIDs with macro EFI_ENTRY use %pUs instead of %pUl to provide readable debug output. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 26 +++++++++++++------------- lib/efi_loader/efi_capsule.c | 6 +++--- lib/efi_loader/efi_esrt.c | 6 +++--- lib/efi_loader/efi_file.c | 4 ++-- lib/efi_loader/efi_hii.c | 14 +++++++------- lib/efi_loader/efi_hii_config.c | 2 +- lib/efi_loader/efi_image_loader.c | 2 +- lib/efi_loader/efi_rng.c | 2 +- lib/efi_loader/efi_signature.c | 2 +- lib/efi_loader/efi_var_common.c | 6 +++--- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 20b6969..37b9c68 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -747,7 +747,7 @@ efi_status_t EFIAPI efi_create_event_ex(uint32_t type, efi_uintn_t notify_tpl, { efi_status_t ret; - EFI_ENTRY("%d, 0x%zx, %p, %p, %pUl", type, notify_tpl, notify_function, + EFI_ENTRY("%d, 0x%zx, %p, %p, %pUs", type, notify_tpl, notify_function, notify_context, event_group); /* @@ -1180,7 +1180,7 @@ static efi_status_t EFIAPI efi_install_protocol_interface( { efi_status_t r; - EFI_ENTRY("%p, %pUl, %d, %p", handle, protocol, protocol_interface_type, + EFI_ENTRY("%p, %pUs, %d, %p", handle, protocol, protocol_interface_type, protocol_interface); if (!handle || !protocol || @@ -1383,7 +1383,7 @@ static efi_status_t EFIAPI efi_uninstall_protocol_interface { efi_status_t ret; - EFI_ENTRY("%p, %pUl, %p", handle, protocol, protocol_interface); + EFI_ENTRY("%p, %pUs, %p", handle, protocol, protocol_interface); ret = efi_uninstall_protocol(handle, protocol, protocol_interface); if (ret != EFI_SUCCESS) @@ -1418,7 +1418,7 @@ efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol, struct efi_register_notify_event *item; efi_status_t ret = EFI_SUCCESS; - EFI_ENTRY("%pUl, %p, %p", protocol, event, registration); + EFI_ENTRY("%pUs, %p, %p", protocol, event, registration); if (!protocol || !event || !registration) { ret = EFI_INVALID_PARAMETER; @@ -1601,7 +1601,7 @@ static efi_status_t EFIAPI efi_locate_handle_ext( const efi_guid_t *protocol, void *search_key, efi_uintn_t *buffer_size, efi_handle_t *buffer) { - EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key, + EFI_ENTRY("%d, %pUs, %p, %p, %p", search_type, protocol, search_key, buffer_size, buffer); return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key, @@ -1699,7 +1699,7 @@ static efi_status_t EFIAPI efi_install_configuration_table_ext(const efi_guid_t *guid, void *table) { - EFI_ENTRY("%pUl, %p", guid, table); + EFI_ENTRY("%pUs, %p", guid, table); return EFI_EXIT(efi_install_configuration_table(guid, table)); } @@ -1814,7 +1814,7 @@ static efi_status_t EFIAPI efi_locate_device_path( u8 *remainder; efi_status_t ret; - EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device); + EFI_ENTRY("%pUs, %p, %p", protocol, device_path, device); if (!protocol || !device_path || !*device_path) { ret = EFI_INVALID_PARAMETER; @@ -2303,7 +2303,7 @@ efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle, struct efi_open_protocol_info_item *pos; efi_status_t r; - EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, agent_handle, + EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, agent_handle, controller_handle); if (!efi_search_obj(agent_handle) || @@ -2353,7 +2353,7 @@ static efi_status_t EFIAPI efi_open_protocol_information( struct efi_open_protocol_info_item *item; efi_status_t r; - EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer, + EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, entry_buffer, entry_count); /* Check parameters */ @@ -2477,7 +2477,7 @@ efi_status_t EFIAPI efi_locate_handle_buffer( efi_status_t r; efi_uintn_t buffer_size = 0; - EFI_ENTRY("%d, %pUl, %p, %p, %p", search_type, protocol, search_key, + EFI_ENTRY("%d, %pUs, %p, %p, %p", search_type, protocol, search_key, no_handles, buffer); if (!no_handles || !buffer) { @@ -2523,7 +2523,7 @@ static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol, efi_status_t ret; struct efi_object *efiobj; - EFI_ENTRY("%pUl, %p, %p", protocol, registration, protocol_interface); + EFI_ENTRY("%pUs, %p, %p", protocol, registration, protocol_interface); /* * The UEFI spec explicitly requires a protocol even if a registration @@ -2914,7 +2914,7 @@ static efi_status_t EFIAPI efi_open_protocol struct efi_handler *handler; efi_status_t r = EFI_INVALID_PARAMETER; - EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol, + EFI_ENTRY("%p, %pUs, %p, %p, %p, 0x%x", handle, protocol, protocol_interface, agent_handle, controller_handle, attributes); @@ -3531,7 +3531,7 @@ static efi_status_t EFIAPI efi_reinstall_protocol_interface( { efi_status_t ret; - EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, old_interface, + EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, old_interface, new_interface); /* Uninstall protocol but do not delete handle */ diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 8301eed..4463ae0 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -453,7 +453,7 @@ static efi_status_t efi_capsule_update_firmware( image->update_hardware_instance, handles, no_handles); if (!fmp) { - log_err("FMP driver not found for firmware type %pUl, hardware instance %lld\n", + log_err("FMP driver not found for firmware type %pUs, hardware instance %lld\n", &image->update_image_type_id, image->update_hardware_instance); ret = EFI_UNSUPPORTED; @@ -548,13 +548,13 @@ efi_status_t EFIAPI efi_update_capsule( continue; } - log_debug("Capsule[%d] (guid:%pUl)\n", + log_debug("Capsule[%d] (guid:%pUs)\n", i, &capsule->capsule_guid); if (!guidcmp(&capsule->capsule_guid, &efi_guid_firmware_management_capsule_id)) { ret = efi_capsule_update_firmware(capsule); } else { - log_err("Unsupported capsule type: %pUl\n", + log_err("Unsupported capsule type: %pUs\n", &capsule->capsule_guid); ret = EFI_UNSUPPORTED; } diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c index 3ca55ce..dcc08a6 100644 --- a/lib/efi_loader/efi_esrt.c +++ b/lib/efi_loader/efi_esrt.c @@ -180,7 +180,7 @@ struct efi_system_resource_entry *esrt_find_entry(efi_guid_t *img_fw_class) /* Check if the image with img_fw_class is already in the ESRT. */ for (u32 idx = 0; idx < filled_entries; idx++) { if (!guidcmp(&entry[idx].fw_class, img_fw_class)) { - EFI_PRINT("ESRT found entry for image %pUl at index %u\n", + EFI_PRINT("ESRT found entry for image %pUs at index %u\n", img_fw_class, idx); return &entry[idx]; } @@ -202,7 +202,7 @@ struct efi_system_resource_entry *esrt_find_entry(efi_guid_t *img_fw_class) */ esrt->fw_resource_count++; entry[filled_entries].fw_class = *img_fw_class; - EFI_PRINT("ESRT allocated new entry for image %pUl at index %u\n", + EFI_PRINT("ESRT allocated new entry for image %pUs at index %u\n", img_fw_class, filled_entries); return &entry[filled_entries]; @@ -291,7 +291,7 @@ efi_status_t efi_esrt_add_from_fmp(struct efi_firmware_management_protocol *fmp) EFI_PRINT("ESRT entry mismatches image_type\n"); } else { - EFI_PRINT("ESRT failed to add entry for %pUl\n", + EFI_PRINT("ESRT failed to add entry for %pUs\n", &cur_img_info->image_type_id); continue; } diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 6299fcb..9aa0030 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -824,7 +824,7 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file, efi_status_t ret = EFI_SUCCESS; u16 *dst; - EFI_ENTRY("%p, %pUl, %p, %p", file, info_type, buffer_size, buffer); + EFI_ENTRY("%p, %pUs, %p, %p", file, info_type, buffer_size, buffer); if (!file || !info_type || !buffer_size || (*buffer_size && !buffer)) { @@ -924,7 +924,7 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file, struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_UNSUPPORTED; - EFI_ENTRY("%p, %pUl, %zu, %p", file, info_type, buffer_size, buffer); + EFI_ENTRY("%p, %pUs, %zu, %p", file, info_type, buffer_size, buffer); if (!guidcmp(info_type, &efi_file_info_guid)) { struct efi_file_info *info = (struct efi_file_info *)buffer; diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c index 77e3302..9f87e95 100644 --- a/lib/efi_loader/efi_hii.c +++ b/lib/efi_loader/efi_hii.c @@ -372,7 +372,7 @@ add_packages(struct efi_hii_packagelist *hii, end = ((void *)package_list) + get_unaligned_le32(&package_list->package_length); - EFI_PRINT("package_list: %pUl (%u)\n", &package_list->package_list_guid, + EFI_PRINT("package_list: %pUs (%u)\n", &package_list->package_list_guid, get_unaligned_le32(&package_list->package_length)); package = ((void *)package_list) + sizeof(*package_list); @@ -504,7 +504,7 @@ update_package_list(const struct efi_hii_database_protocol *this, if (!package_list) return EFI_EXIT(EFI_INVALID_PARAMETER); - EFI_PRINT("package_list: %pUl (%u)\n", &package_list->package_list_guid, + EFI_PRINT("package_list: %pUs (%u)\n", &package_list->package_list_guid, get_unaligned_le32(&package_list->package_length)); package = ((void *)package_list) + sizeof(*package_list); @@ -583,7 +583,7 @@ list_package_lists(const struct efi_hii_database_protocol *this, int package_cnt, package_max; efi_status_t ret = EFI_NOT_FOUND; - EFI_ENTRY("%p, %u, %pUl, %p, %p", this, package_type, package_guid, + EFI_ENTRY("%p, %u, %pUs, %p, %p", this, package_type, package_guid, handle_buffer_length, handle); if (!handle_buffer_length || @@ -598,7 +598,7 @@ list_package_lists(const struct efi_hii_database_protocol *this, goto out; } - EFI_PRINT("package type=%x, guid=%pUl, length=%zu\n", (int)package_type, + EFI_PRINT("package type=%x, guid=%pUs, length=%zu\n", (int)package_type, package_guid, *handle_buffer_length); package_cnt = 0; @@ -658,7 +658,7 @@ register_package_notify(const struct efi_hii_database_protocol *this, efi_uintn_t notify_type, efi_handle_t *notify_handle) { - EFI_ENTRY("%p, %u, %pUl, %p, %zu, %p", this, package_type, + EFI_ENTRY("%p, %u, %pUs, %p, %zu, %p", this, package_type, package_guid, package_notify_fn, notify_type, notify_handle); @@ -721,7 +721,7 @@ get_keyboard_layout(const struct efi_hii_database_protocol *this, struct efi_keyboard_layout_data *layout_data; u16 layout_length; - EFI_ENTRY("%p, %pUl, %p, %p", this, key_guid, keyboard_layout_length, + EFI_ENTRY("%p, %pUs, %p, %p", this, key_guid, keyboard_layout_length, keyboard_layout); if (!keyboard_layout_length || @@ -756,7 +756,7 @@ static efi_status_t EFIAPI set_keyboard_layout(const struct efi_hii_database_protocol *this, efi_guid_t *key_guid) { - EFI_ENTRY("%p, %pUl", this, key_guid); + EFI_ENTRY("%p, %pUs", this, key_guid); return EFI_EXIT(EFI_NOT_FOUND); } diff --git a/lib/efi_loader/efi_hii_config.c b/lib/efi_loader/efi_hii_config.c index 237e8ac..31b0c97 100644 --- a/lib/efi_loader/efi_hii_config.c +++ b/lib/efi_loader/efi_hii_config.c @@ -88,7 +88,7 @@ get_alt_config(const struct efi_hii_config_routing_protocol *this, const efi_string_t alt_cfg_id, efi_string_t *alt_cfg_resp) { - EFI_ENTRY("%p, \"%ls\", %pUl, \"%ls\", %p, \"%ls\", %p", + EFI_ENTRY("%p, \"%ls\", %pUs, \"%ls\", %p, \"%ls\", %p", this, config_resp, guid, name, device_path, alt_cfg_id, alt_cfg_resp); diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index 773bd06..255613e 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -676,7 +676,7 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) continue; } if (guidcmp(auth, &efi_guid_cert_type_pkcs7)) { - EFI_PRINT("Certificate type not supported: %pUl\n", + EFI_PRINT("Certificate type not supported: %pUs\n", auth); continue; } diff --git a/lib/efi_loader/efi_rng.c b/lib/efi_loader/efi_rng.c index 0e06546..bb11d8d 100644 --- a/lib/efi_loader/efi_rng.c +++ b/lib/efi_loader/efi_rng.c @@ -122,7 +122,7 @@ static efi_status_t EFIAPI getrng(struct efi_rng_protocol *this, } if (rng_algorithm) { - EFI_PRINT("RNG algorithm %pUl\n", rng_algorithm); + EFI_PRINT("RNG algorithm %pUs\n", rng_algorithm); if (guidcmp(rng_algorithm, &rng_raw_guid)) { status = EFI_UNSUPPORTED; goto back; diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c index 6e3ee3c..3243e2c 100644 --- a/lib/efi_loader/efi_signature.c +++ b/lib/efi_loader/efi_signature.c @@ -174,7 +174,7 @@ bool efi_signature_lookup_digest(struct efi_image_regions *regs, for (siglist = db; siglist; siglist = siglist->next) { /* TODO: support other hash algorithms */ if (guidcmp(&siglist->sig_type, &efi_guid_sha256)) { - EFI_PRINT("Digest algorithm is not supported: %pUl\n", + EFI_PRINT("Digest algorithm is not supported: %pUs\n", &siglist->sig_type); break; } diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 3cbb7c9..9f1dd74 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -62,7 +62,7 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, { efi_status_t ret; - EFI_ENTRY("\"%ls\" %pUl %p %p %p", variable_name, vendor, attributes, + EFI_ENTRY("\"%ls\" %pUs %p %p %p", variable_name, vendor, attributes, data_size, data); ret = efi_get_variable_int(variable_name, vendor, attributes, @@ -96,7 +96,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, { efi_status_t ret; - EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes, + EFI_ENTRY("\"%ls\" %pUs %x %zu %p", variable_name, vendor, attributes, data_size, data); /* Make sure that the EFI_VARIABLE_READ_ONLY flag is not set */ @@ -127,7 +127,7 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, { efi_status_t ret; - EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor); + EFI_ENTRY("%p \"%ls\" %pUs", variable_name_size, variable_name, vendor); ret = efi_get_next_variable_name_int(variable_name_size, variable_name, vendor); -- cgit v1.1 From 983a5a2e72d3292eff417396294188f28e169b04 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 14:53:37 +0100 Subject: cmd: printenv: simplify printing GUIDs Use "%pS" to print text representations of GUIDs. Signed-off-by: Heinrich Schuchardt --- cmd/nvedit_efi.c | 39 ++------------------------------------- lib/uuid.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 710d923..7ebb14e 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -39,40 +39,6 @@ static const struct { {EFI_VARIABLE_READ_ONLY, "RO"}, }; -static const struct { - efi_guid_t guid; - char *text; -} efi_guid_text[] = { - /* signature database */ - {EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"}, - {EFI_IMAGE_SECURITY_DATABASE_GUID, "EFI_IMAGE_SECURITY_DATABASE_GUID"}, - /* certificate type */ - {EFI_CERT_SHA256_GUID, "EFI_CERT_SHA256_GUID"}, - {EFI_CERT_X509_GUID, "EFI_CERT_X509_GUID"}, - {EFI_CERT_TYPE_PKCS7_GUID, "EFI_CERT_TYPE_PKCS7_GUID"}, -}; - -static const char unknown_guid[] = ""; - -/** - * efi_guid_to_str() - convert guid to readable name - * - * @guid: GUID - * Return: string for GUID - * - * convert guid to readable name - */ -static const char *efi_guid_to_str(const efi_guid_t *guid) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(efi_guid_text); i++) - if (!guidcmp(guid, &efi_guid_text[i].guid)) - return efi_guid_text[i].text; - - return unknown_guid; -} - /** * efi_dump_single_var() - show information about a UEFI variable * @@ -111,7 +77,7 @@ static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, bool verbose) goto out; rtc_to_tm(time, &tm); - printf("%ls:\n %pUl %s\n", name, guid, efi_guid_to_str(guid)); + printf("%ls:\n %pUl (%pUs)\n", name, guid, guid); if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) printf(" %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); @@ -497,8 +463,7 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, } if (verbose) { - printf("GUID: %pUl %s\n", &guid, - efi_guid_to_str((const efi_guid_t *)&guid)); + printf("GUID: %pUl (%pUs)\n", &guid, &guid); printf("Attributes: 0x%x\n", attributes); } diff --git a/lib/uuid.c b/lib/uuid.c index 60b7ca1..3ffaab7 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -217,6 +217,30 @@ static const struct { EFI_TCG2_FINAL_EVENTS_TABLE_GUID, }, #endif +#ifdef CONFIG_CMD_NVEDIT_EFI + /* signature database */ + { + "EFI_GLOBAL_VARIABLE_GUID", + EFI_GLOBAL_VARIABLE_GUID, + }, + { + "EFI_IMAGE_SECURITY_DATABASE_GUID", + EFI_IMAGE_SECURITY_DATABASE_GUID, + }, + /* certificate types */ + { + "EFI_CERT_SHA256_GUID", + EFI_CERT_SHA256_GUID, + }, + { + "EFI_CERT_X509_GUID", + EFI_CERT_X509_GUID, + }, + { + "EFI_CERT_TYPE_PKCS7_GUID", + EFI_CERT_TYPE_PKCS7_GUID, + }, +#endif }; /* -- cgit v1.1 From 7884a0986d18be5ab98b5374bd8bacd031c883a9 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 15:49:17 +0100 Subject: efi_selftest: implement printing GUIDs The ESRT test may try to print a GUID if an error occurs. Implement the %pU print code. Correct the ESRT test to use %pU instead of %pUl to avoid the output of character 'l'. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_console.c | 25 +++++++++++++++++++++++++ lib/efi_selftest/efi_selftest_esrt.c | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/efi_selftest/efi_selftest_console.c b/lib/efi_selftest/efi_selftest_console.c index ffd88a1..3187e10 100644 --- a/lib/efi_selftest/efi_selftest_console.c +++ b/lib/efi_selftest/efi_selftest_console.c @@ -70,6 +70,28 @@ static void printx(u64 p, int prec, u16 **buf) *buf = pos; } +/** + * print_guid() - print GUID to an u16 string + * + * @p: GUID to print + * @buf: pointer to buffer address, + * on return position of terminating zero word + */ +static void print_uuid(u8 *p, u16 **buf) +{ + int i; + const u8 seq[] = { + 3, 2, 1, 0, '-', 5, 4, '-', 7, 6, '-', + 8, 9, 10, 11, 12, 13, 14, 15 }; + + for (i = 0; i < sizeof(seq); ++i) { + if (seq[i] == '-') + *(*buf)++ = u'-'; + else + printx(p[seq[i]], 2, buf); + } +} + /* * Print an unsigned 32bit value as decimal number to an u16 string * @@ -212,6 +234,9 @@ void efi_st_printc(int color, const char *fmt, ...) con_out->output_string(con_out, u); pos = buf; break; + case 'U': + print_uuid(va_arg(args, void*), &pos); + break; default: --c; printx((uintptr_t)va_arg(args, void *), diff --git a/lib/efi_selftest/efi_selftest_esrt.c b/lib/efi_selftest/efi_selftest_esrt.c index 99251f2..99793de 100644 --- a/lib/efi_selftest/efi_selftest_esrt.c +++ b/lib/efi_selftest/efi_selftest_esrt.c @@ -121,28 +121,28 @@ static bool lib_test_check_uuid_entry(struct efi_system_resource_table *esrt, for (u32 idx = 0; idx < filled_entries; idx++) { if (!guidcmp(&entry[idx].fw_class, &img_info->image_type_id)) { if (entry[idx].fw_version != img_info->version) { - efi_st_error("ESRT field mismatch for entry with fw_class=%pUl\n", + efi_st_error("ESRT field mismatch for entry with fw_class=%pU\n", &img_info->image_type_id); return false; } if (entry[idx].lowest_supported_fw_version != img_info->lowest_supported_image_version) { - efi_st_error("ESRT field mismatch for entry with fw_class=%pUl\n", + efi_st_error("ESRT field mismatch for entry with fw_class=%pU\n", &img_info->image_type_id); return false; } if (entry[idx].last_attempt_version != img_info->last_attempt_version) { - efi_st_error("ESRT field mismatch for entry with fw_class=%pUl\n", + efi_st_error("ESRT field mismatch for entry with fw_class=%pU\n", &img_info->image_type_id); return false; } if (entry[idx].last_attempt_status != img_info->last_attempt_status) { - efi_st_error("ESRT field mismatch for entry with fw_class=%pUl\n", + efi_st_error("ESRT field mismatch for entry with fw_class=%pU\n", &img_info->image_type_id); return false; } -- cgit v1.1 From 38040a63a3e838a1eeb56c7d18875be485b14f5c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 16 Jan 2022 17:46:38 +0100 Subject: efi_loader: printing TCG2 protocol GUID We support the TCG2 protocol. Allow command efidebug to print it. Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 4 ++++ include/efi_tcg2.h | 4 ---- lib/uuid.c | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index a60d1bc..8d5d835 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -434,6 +434,10 @@ struct efi_runtime_services { EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, \ 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00) +#define EFI_TCG2_PROTOCOL_GUID \ + EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ + 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) + /** * struct efi_configuration_table - EFI Configuration Table * diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h index 50a59f9..874306d 100644 --- a/include/efi_tcg2.h +++ b/include/efi_tcg2.h @@ -19,10 +19,6 @@ #include #include -#define EFI_TCG2_PROTOCOL_GUID \ - EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ - 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) - /* TPMV2 only */ #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002 #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001 diff --git a/lib/uuid.c b/lib/uuid.c index 3ffaab7..24571ef 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -184,6 +184,10 @@ static const struct { EFI_DT_FIXUP_PROTOCOL_GUID, }, { + "TCG2", + EFI_TCG2_PROTOCOL_GUID, + }, + { "System Partition", PARTITION_SYSTEM_GUID }, -- cgit v1.1 From 8699af63b8a5ea36c415b97079651ca02a0aafa5 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Wed, 19 Jan 2022 13:54:41 +0200 Subject: lib/crypto: Enable more algorithms in cert verification Right now the code explicitly limits us to sha1,256 hashes with RSA2048 encryption. But the limitation is artificial since U-Boot supports a wider range of algorithms. The internal image_get_[checksum|crypto]_algo() functions expect an argument in the format of ,. So let's remove the size checking and create the needed string on the fly in order to support more hash/signing combinations. Signed-off-by: Ilias Apalodimas --- lib/crypto/public_key.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/crypto/public_key.c b/lib/crypto/public_key.c index df6033c..3671ed1 100644 --- a/lib/crypto/public_key.c +++ b/lib/crypto/public_key.c @@ -97,6 +97,7 @@ int public_key_verify_signature(const struct public_key *pkey, const struct public_key_signature *sig) { struct image_sign_info info; + char algo[256]; int ret; pr_devel("==>%s()\n", __func__); @@ -108,30 +109,26 @@ int public_key_verify_signature(const struct public_key *pkey, return -EINVAL; memset(&info, '\0', sizeof(info)); + memset(algo, 0, sizeof(algo)); info.padding = image_get_padding_algo("pkcs-1.5"); - /* - * Note: image_get_[checksum|crypto]_algo takes a string - * argument like "," - * TODO: support other hash algorithms - */ - if (strcmp(sig->pkey_algo, "rsa") || (sig->s_size * 8) != 2048) { - pr_warn("Encryption is not RSA2048: %s%d\n", - sig->pkey_algo, sig->s_size * 8); - return -ENOPKG; - } - if (!strcmp(sig->hash_algo, "sha1")) { - info.checksum = image_get_checksum_algo("sha1,rsa2048"); - info.name = "sha1,rsa2048"; - } else if (!strcmp(sig->hash_algo, "sha256")) { - info.checksum = image_get_checksum_algo("sha256,rsa2048"); - info.name = "sha256,rsa2048"; - } else { - pr_warn("unknown msg digest algo: %s\n", sig->hash_algo); + if (strcmp(sig->pkey_algo, "rsa")) { + pr_err("Encryption is not RSA: %s\n", sig->pkey_algo); return -ENOPKG; } + ret = snprintf(algo, sizeof(algo), "%s,%s%d", sig->hash_algo, + sig->pkey_algo, sig->s_size * 8); + + if (ret >= sizeof(algo)) + return -EINVAL; + + info.checksum = image_get_checksum_algo((const char *)algo); + info.name = (const char *)algo; info.crypto = image_get_crypto_algo(info.name); - if (IS_ERR(info.checksum) || IS_ERR(info.crypto)) + if (!info.checksum || !info.crypto) { + pr_err("<%s> not supported on image_get_(checksum|crypto)_algo()\n", + algo); return -ENOPKG; + } info.key = pkey->key; info.keylen = pkey->keylen; -- cgit v1.1 From 3280eaad18df8b6b917d772a5e1d9b789454cbd2 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Jan 2022 20:35:37 +0100 Subject: doc: fix description of build dependencies for Alpine Linux Signed-off-by: Heinrich Schuchardt --- doc/build/gcc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst index 0e0d87a..b883cf7 100644 --- a/doc/build/gcc.rst +++ b/doc/build/gcc.rst @@ -59,7 +59,7 @@ For building U-Boot on Alpine Linux at least the following packages are needed: .. code-block:: bash apk add alpine-sdk bc bison dtc flex linux-headers ncurses-dev \ - openssl-dev python3 py3-setuptools python3-dev sdl2 + openssl-dev perl python3 py3-setuptools python3-dev sdl2-dev Prerequisites ------------- -- cgit v1.1 From f5e9035043fb48baea93ccb3165e75f486906213 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 19 Jan 2022 01:20:45 +0100 Subject: doc: printf() codes Document the format specifier codes used by U-Boot's printf() implementation. Signed-off-by: Heinrich Schuchardt --- doc/develop/index.rst | 1 + doc/develop/printf.rst | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 doc/develop/printf.rst diff --git a/doc/develop/index.rst b/doc/develop/index.rst index 9592d19..c84b10e 100644 --- a/doc/develop/index.rst +++ b/doc/develop/index.rst @@ -21,6 +21,7 @@ Implementation logging makefiles menus + printf uefi/index version diff --git a/doc/develop/printf.rst b/doc/develop/printf.rst new file mode 100644 index 0000000..7b9aea0 --- /dev/null +++ b/doc/develop/printf.rst @@ -0,0 +1,199 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Printf() format codes +===================== + +Each conversion specification consists of: + +* leading '%' character +* zero or more flags +* an optional minimum field width +* an optional precision field preceded by '.' +* an optional length modifier +* a conversion specifier + +Flags +----- + +'space' + fill up with spaces to reach the specified length + +\- + left justify + +\+ + add sign field of decimal conversion + +# + convert to alternative form + + * prepend 0 to octal output + * ignored for decimal output + * prepend 0X to hexadecimal output + +0 + fill up with zeroes to reach the specified length + + +Integer types +------------- + +Length modifiers +'''''''''''''''' + +The optional length modifier specifies the size of the argument. + +no modifier + bool, enum, short, int are passed as int + +%h + convert to (unsigned) short before printing. + Only the low 16 bits are printed. + +%hh + **not implemented** + +%j + **not implemented** + +%l + long + +%ll, %L + long long + +%t + ptr_diff_t + +%z, %Z + size_t, ssize_t + +Conversion specifiers +''''''''''''''''''''' + +Conversion specifiers control the output. + +%d + signed decimal + +%u + unsigned decimal + +%o + unsigned octal + +%x + unsigned lower case hexadecimal + +%X + unsigned upper case hexadecimal + +The floating point conversion specifiers are not implemented: + +* %a +* %A +* %e +* %E +* %f +* %F +* %g +* %G + +The following tables shows the correct combinations of modifiers and specifiers +for the individual integer types. + +=================== ================== +Type Format specifier +=================== ================== +bool %d, %x +char %d, %x +unsigned char %u, %x +short %d, %x +unsigned short %u, %x +int %d, %x +unsigned int %d, %x +long %ld, %lx +unsigned long %lu, %lx +long long %lld, %llx +unsigned long long %llu, %llx +off_t %llu, %llx +ptr_diff_t %td, %tx +fdt_addr_t %pa, see pointers +fdt_size_t %pa, see pointers +phys_addr_t %pa, see pointers +phys_size_t %pa, see pointers +resource_size_t %pa, see pointers +size_t %zu, %zx, %zX +ssize_t %zd, %zx, %zX +=================== ================== + +Characters +---------- + +%% + a '%' character is written + +%c + prints a single character + +%lc + **not implemented** + +Strings +------- + +%s + prints a UTF-8 string (char \*) + +%ls + prints a UTF-16 string (u16 \*) + +Pointers +-------- + +%p + prints the address the pointer points to hexadecimally + +%pa, %pap + prints the value of a phys_addr_t value that the pointer points to + preceded with 0x and zero padding according to the size of phys_addr_t. + The following types should be printed this way: + + * fdt_addr_t + * fdt_size_t + * phys_addr_t + * phys_size_t + * resource_size_t + +%pD + prints a UEFI device path + +%pi4, %pI4 + prints IPv4 address, e.g. '192.168.0.1' + +%pm + prints MAC address without separators, e.g. '001122334455' + +%pM + print MAC address colon separated, e.g. '00:01:02:03:04:05' + +%pUb + prints GUID big endian, lower case + e.g. '00112233-4455-6677-8899-aabbccddeeff' + +%pUB + prints GUID big endian, upper case + e.g. '00112233-4455-6677-8899-AABBCCDDEEFF' + +%pUl + prints GUID little endian, lower case + e.g. '33221100-5544-7766-8899-aabbccddeeff' + +%pUL + prints GUID little endian, upper case + e.g. '33221100-5544-7766-8899-AABBCCDDEEFF' + +%pUs + prints text description of a GUID or if such is not known little endian, + lower case, e.g. 'system' for a GUID identifying an EFI system + partition. -- cgit v1.1