X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cmd%2Fefidebug.c;h=32430e62f0ac90a2475cb7903f64d97b019d083a;hb=d181191e1215204d825db7837ed2c64a5196a734;hp=479e37714cddf0091d89433bd60b1daa665d0eb4;hpb=428a470a27733cce9751224c5fee7aec28504282;p=oweals%2Fu-boot.git diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 479e37714c..32430e62f0 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -9,15 +9,15 @@ #include #include #include -#include #include #include +#include #include +#include #include #include #define BS systab.boottime -#define RT systab.runtime /** * efi_get_device_handle_info() - get information of UEFI device @@ -61,15 +61,15 @@ static const char sep[] = "================"; * Implement efidebug "devices" sub-command. * Show all UEFI devices and their information. */ -static int do_efi_show_devices(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) +static int do_efi_show_devices(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) { efi_handle_t *handles; efi_uintn_t num, i; u16 *dev_path_text; efi_status_t ret; - ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL, + ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL, &num, &handles)); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; @@ -86,7 +86,7 @@ static int do_efi_show_devices(cmd_tbl_t *cmdtp, int flag, } } - EFI_CALL(BS->free_pool(handles)); + efi_free_pool(handles); return CMD_RET_SUCCESS; } @@ -140,15 +140,15 @@ static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name, * Implement efidebug "drivers" sub-command. * Show all UEFI drivers and their information. */ -static int do_efi_show_drivers(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) +static int do_efi_show_drivers(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) { efi_handle_t *handles; efi_uintn_t num, i; u16 *driver_name, *image_path_text; efi_status_t ret; - ret = EFI_CALL(BS->locate_handle_buffer( + ret = EFI_CALL(efi_locate_handle_buffer( BY_PROTOCOL, &efi_guid_driver_binding_protocol, NULL, &num, &handles)); if (ret != EFI_SUCCESS) @@ -170,12 +170,12 @@ static int do_efi_show_drivers(cmd_tbl_t *cmdtp, int flag, else printf("%p %-20ls \n", handles[i], driver_name); - EFI_CALL(BS->free_pool(driver_name)); - EFI_CALL(BS->free_pool(image_path_text)); + efi_free_pool(driver_name); + efi_free_pool(image_path_text); } } - EFI_CALL(BS->free_pool(handles)); + efi_free_pool(handles); return CMD_RET_SUCCESS; } @@ -244,6 +244,10 @@ static const struct { "HII Config Routing", EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, }, + { + "Load File2", + EFI_LOAD_FILE2_PROTOCOL_GUID, + }, { "Simple Network", EFI_SIMPLE_NETWORK_PROTOCOL_GUID, @@ -252,27 +256,47 @@ static const struct { "PXE Base Code", EFI_PXE_BASE_CODE_PROTOCOL_GUID, }, + /* Configuration table GUIDs */ + { + "ACPI table", + EFI_ACPI_TABLE_GUID, + }, + { + "device tree", + EFI_FDT_GUID, + }, + { + "SMBIOS table", + SMBIOS_TABLE_GUID, + }, + { + "Runtime properties", + EFI_RT_PROPERTIES_TABLE_GUID, + }, }; /** - * get_guid_text - get string of protocol guid - * @guid: Protocol guid - * Return: String + * get_guid_text - get string of GUID + * + * Return description of GUID. * - * Return string for display to represent the protocol. + * @guid: GUID + * Return: description of GUID or NULL */ -static const char *get_guid_text(const efi_guid_t *guid) +static const char *get_guid_text(const void *guid) { int i; - for (i = 0; i < ARRAY_SIZE(guid_list); 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)) - break; + return guid_list[i].text; + } - if (i != ARRAY_SIZE(guid_list)) - return guid_list[i].text; - else - return NULL; + return NULL; } /** @@ -288,8 +312,8 @@ static const char *get_guid_text(const efi_guid_t *guid) * Show all UEFI handles and their information, currently all protocols * added to handle. */ -static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) +static int do_efi_show_handles(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) { efi_handle_t *handles; efi_guid_t **guid; @@ -297,7 +321,7 @@ static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag, const char *guid_text; efi_status_t ret; - ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL, + ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL, &num, &handles)); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; @@ -331,7 +355,7 @@ static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag, putc('\n'); } - EFI_CALL(BS->free_pool(handles)); + efi_free_pool(handles); return CMD_RET_SUCCESS; } @@ -348,8 +372,8 @@ static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag, * Implement efidebug "images" sub-command. * Show all UEFI loaded images and their information. */ -static int do_efi_show_images(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) +static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) { efi_print_image_infos(NULL); @@ -371,6 +395,7 @@ static const char * const efi_mem_type_string[] = { [EFI_MMAP_IO] = "IO", [EFI_MMAP_IO_PORT] = "IO PORT", [EFI_PAL_CODE] = "PAL", + [EFI_PERSISTENT_MEMORY_TYPE] = "PERSISTENT", }; static const struct efi_mem_attrs { @@ -389,11 +414,13 @@ static const struct efi_mem_attrs { {EFI_MEMORY_NV, "NV"}, {EFI_MEMORY_MORE_RELIABLE, "REL"}, {EFI_MEMORY_RO, "RO"}, + {EFI_MEMORY_SP, "SP"}, {EFI_MEMORY_RUNTIME, "RT"}, }; /** * print_memory_attributes() - print memory map attributes + * * @attributes: Attribute value * * Print memory map attributes @@ -428,8 +455,8 @@ static void print_memory_attributes(u64 attributes) * Implement efidebug "memmap" sub-command. * Show UEFI memory map. */ -static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) +static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) { struct efi_mem_desc *memmap = NULL, *map; efi_uintn_t map_size = 0; @@ -437,18 +464,17 @@ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, int i; efi_status_t ret; - ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL, NULL, NULL)); + ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); if (ret == EFI_BUFFER_TOO_SMALL) { map_size += sizeof(struct efi_mem_desc); /* for my own */ - ret = EFI_CALL(BS->allocate_pool(EFI_LOADER_DATA, - map_size, (void *)&memmap)); + ret = efi_allocate_pool(EFI_LOADER_DATA, map_size, + (void *)&memmap); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; - ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, - NULL, NULL, NULL)); + ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); } if (ret != EFI_SUCCESS) { - EFI_CALL(BS->free_pool(memmap)); + efi_free_pool(memmap); return CMD_RET_FAILURE; } @@ -456,23 +482,59 @@ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc); printf("================ %.*s %.*s ==========\n", EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep); + /* + * Coverity check: dereferencing null pointer "map." + * This is a false positive as memmap will always be + * populated by allocate_pool() above. + */ for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) { - if (map->type < EFI_MAX_MEMORY_TYPE) + if (map->type < ARRAY_SIZE(efi_mem_type_string)) type = efi_mem_type_string[map->type]; else type = "(unknown)"; printf("%-16s %.*llx-%.*llx", type, EFI_PHYS_ADDR_WIDTH, - map->physical_start, + (u64)map_to_sysmem((void *)(uintptr_t) + map->physical_start), EFI_PHYS_ADDR_WIDTH, - map->physical_start + map->num_pages * EFI_PAGE_SIZE); + (u64)map_to_sysmem((void *)(uintptr_t) + (map->physical_start + + map->num_pages * EFI_PAGE_SIZE))); print_memory_attributes(map->attribute); putc('\n'); } - EFI_CALL(BS->free_pool(memmap)); + efi_free_pool(memmap); + + return CMD_RET_SUCCESS; +} + +/** + * do_efi_show_tables() - show UEFI configuration tables + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "tables" sub-command. + * Show UEFI configuration tables. + */ +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); + } return CMD_RET_SUCCESS; } @@ -487,12 +549,12 @@ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, * Return: CMD_RET_SUCCESS on success, * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure * - * Implement efidebug "boot add" sub-command. - * Create or change UEFI load option. - * - boot add