1 // SPDX-License-Identifier: GPL-2.0+
3 * UEFI Shell-like command
5 * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
11 #include <efi_dt_fixup.h>
12 #include <efi_load_initrd.h>
13 #include <efi_loader.h>
22 #include <linux/ctype.h>
23 #include <linux/err.h>
25 #define BS systab.boottime
26 #define RT systab.runtime
28 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
30 * do_efi_capsule_update() - process a capsule update
32 * @cmdtp: Command table
34 * @argc: Number of arguments
35 * @argv: Argument array
36 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
38 * Implement efidebug "capsule update" sub-command.
39 * process a capsule update.
41 * efidebug capsule update [-v] <capsule address>
43 static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag,
44 int argc, char * const argv[])
46 struct efi_capsule_header *capsule;
51 if (argc != 2 && argc != 3)
55 if (strcmp(argv[1], "-v"))
63 capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
64 if (endp == argv[1]) {
65 printf("Invalid address: %s", argv[1]);
66 return CMD_RET_FAILURE;
70 printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
71 printf("Capsule flags: 0x%x\n", capsule->flags);
72 printf("Capsule header size: 0x%x\n", capsule->header_size);
73 printf("Capsule image size: 0x%x\n",
74 capsule->capsule_image_size);
77 ret = EFI_CALL(RT->update_capsule(&capsule, 1, 0));
79 printf("Cannot handle a capsule at %p", capsule);
80 return CMD_RET_FAILURE;
83 return CMD_RET_SUCCESS;
86 static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag,
87 int argc, char * const argv[])
91 ret = efi_launch_capsules();
93 return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
97 * do_efi_capsule_show() - show capsule information
99 * @cmdtp: Command table
100 * @flag: Command flag
101 * @argc: Number of arguments
102 * @argv: Argument array
103 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
105 * Implement efidebug "capsule show" sub-command.
106 * show capsule information.
108 * efidebug capsule show <capsule address>
110 static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,
111 int argc, char * const argv[])
113 struct efi_capsule_header *capsule;
117 return CMD_RET_USAGE;
119 capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
120 if (endp == argv[1]) {
121 printf("Invalid address: %s", argv[1]);
122 return CMD_RET_FAILURE;
125 printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
126 printf("Capsule flags: 0x%x\n", capsule->flags);
127 printf("Capsule header size: 0x%x\n", capsule->header_size);
128 printf("Capsule image size: 0x%x\n",
129 capsule->capsule_image_size);
131 return CMD_RET_SUCCESS;
134 #ifdef CONFIG_EFI_ESRT
136 #define EFI_ESRT_FW_TYPE_NUM 4
137 char *efi_fw_type_str[EFI_ESRT_FW_TYPE_NUM] = {"unknown", "system FW", "device FW",
140 #define EFI_ESRT_UPDATE_STATUS_NUM 9
141 char *efi_update_status_str[EFI_ESRT_UPDATE_STATUS_NUM] = {"success", "unsuccessful",
142 "insufficient resources", "incorrect version", "invalid format",
143 "auth error", "power event (AC)", "power event (batt)",
144 "unsatisfied dependencies"};
146 #define EFI_FW_TYPE_STR_GET(idx) (\
147 EFI_ESRT_FW_TYPE_NUM > (idx) ? efi_fw_type_str[(idx)] : "error"\
150 #define EFI_FW_STATUS_STR_GET(idx) (\
151 EFI_ESRT_UPDATE_STATUS_NUM > (idx) ? efi_update_status_str[(idx)] : "error"\
155 * do_efi_capsule_esrt() - manage UEFI capsules
157 * @cmdtp: Command table
158 * @flag: Command flag
159 * @argc: Number of arguments
160 * @argv: Argument array
161 * Return: CMD_RET_SUCCESS on success,
162 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
164 * Implement efidebug "capsule esrt" sub-command.
165 * The prints the current ESRT table.
167 * efidebug capsule esrt
169 static int do_efi_capsule_esrt(struct cmd_tbl *cmdtp, int flag,
170 int argc, char * const argv[])
172 struct efi_system_resource_table *esrt = NULL;
175 return CMD_RET_USAGE;
177 for (int idx = 0; idx < systab.nr_tables; idx++)
178 if (!guidcmp(&efi_esrt_guid, &systab.tables[idx].guid))
179 esrt = (struct efi_system_resource_table *)systab.tables[idx].table;
182 log_info("ESRT: table not present\n");
183 return CMD_RET_SUCCESS;
186 printf("========================================\n");
187 printf("ESRT: fw_resource_count=%d\n", esrt->fw_resource_count);
188 printf("ESRT: fw_resource_count_max=%d\n", esrt->fw_resource_count_max);
189 printf("ESRT: fw_resource_version=%lld\n", esrt->fw_resource_version);
191 for (int idx = 0; idx < esrt->fw_resource_count; idx++) {
192 printf("[entry %d]==============================\n", idx);
193 printf("ESRT: fw_class=%pUL\n", &esrt->entries[idx].fw_class);
194 printf("ESRT: fw_type=%s\n", EFI_FW_TYPE_STR_GET(esrt->entries[idx].fw_type));
195 printf("ESRT: fw_version=%d\n", esrt->entries[idx].fw_version);
196 printf("ESRT: lowest_supported_fw_version=%d\n",
197 esrt->entries[idx].lowest_supported_fw_version);
198 printf("ESRT: capsule_flags=%d\n",
199 esrt->entries[idx].capsule_flags);
200 printf("ESRT: last_attempt_version=%d\n",
201 esrt->entries[idx].last_attempt_version);
202 printf("ESRT: last_attempt_status=%s\n",
203 EFI_FW_STATUS_STR_GET(esrt->entries[idx].last_attempt_status));
205 printf("========================================\n");
207 return CMD_RET_SUCCESS;
209 #endif /* CONFIG_EFI_ESRT */
211 * do_efi_capsule_res() - show a capsule update result
213 * @cmdtp: Command table
214 * @flag: Command flag
215 * @argc: Number of arguments
216 * @argv: Argument array
217 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
219 * Implement efidebug "capsule result" sub-command.
220 * show a capsule update result.
221 * If result number is not specified, CapsuleLast will be shown.
223 * efidebug capsule result [<capsule result number>]
225 static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
226 int argc, char * const argv[])
231 u16 var_name16[12], *p;
233 struct efi_capsule_result_variable_header *result = NULL;
237 if (argc != 1 && argc != 2)
238 return CMD_RET_USAGE;
240 guid = efi_guid_capsule_report;
242 size = sizeof(var_name16);
243 ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
245 if (ret != EFI_SUCCESS) {
246 if (ret == EFI_NOT_FOUND)
247 printf("CapsuleLast doesn't exist\n");
249 printf("Failed to get CapsuleLast\n");
251 return CMD_RET_FAILURE;
253 printf("CapsuleLast is %ls\n", var_name16);
258 capsule_id = simple_strtoul(argv[0], &endp, 16);
259 if (capsule_id < 0 || capsule_id > 0xffff)
260 return CMD_RET_USAGE;
262 sprintf(var_name, "Capsule%04X", capsule_id);
264 utf8_utf16_strncpy(&p, var_name, 9);
268 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
269 if (ret == EFI_BUFFER_TOO_SMALL) {
270 result = malloc(size);
272 return CMD_RET_FAILURE;
273 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
276 if (ret != EFI_SUCCESS) {
278 printf("Failed to get %ls\n", var_name16);
280 return CMD_RET_FAILURE;
283 printf("Result total size: 0x%x\n", result->variable_total_size);
284 printf("Capsule guid: %pUl\n", &result->capsule_guid);
285 printf("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n",
286 result->capsule_processed.year, result->capsule_processed.month,
287 result->capsule_processed.day, result->capsule_processed.hour,
288 result->capsule_processed.minute,
289 result->capsule_processed.second);
290 printf("Capsule status: 0x%lx\n", result->capsule_status);
294 return CMD_RET_SUCCESS;
297 static struct cmd_tbl cmd_efidebug_capsule_sub[] = {
298 U_BOOT_CMD_MKENT(update, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_update,
300 U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show,
302 #ifdef CONFIG_EFI_ESRT
303 U_BOOT_CMD_MKENT(esrt, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_esrt,
306 U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update,
308 U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
313 * do_efi_capsule() - manage UEFI capsules
315 * @cmdtp: Command table
316 * @flag: Command flag
317 * @argc: Number of arguments
318 * @argv: Argument array
319 * Return: CMD_RET_SUCCESS on success,
320 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
322 * Implement efidebug "capsule" sub-command.
324 static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag,
325 int argc, char * const argv[])
330 return CMD_RET_USAGE;
334 cp = find_cmd_tbl(argv[0], cmd_efidebug_capsule_sub,
335 ARRAY_SIZE(cmd_efidebug_capsule_sub));
337 return CMD_RET_USAGE;
339 return cp->cmd(cmdtp, flag, argc, argv);
341 #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
344 * efi_get_device_path_text() - get device path text
346 * Return the text representation of the device path of a handle.
348 * @handle: handle of UEFI device
350 * Pointer to the device path text or NULL.
351 * The caller is responsible for calling FreePool().
353 static u16 *efi_get_device_path_text(efi_handle_t handle)
355 struct efi_handler *handler;
358 ret = efi_search_protocol(handle, &efi_guid_device_path, &handler);
359 if (ret == EFI_SUCCESS && handler->protocol_interface) {
360 struct efi_device_path *dp = handler->protocol_interface;
362 return efi_dp_str(dp);
368 #define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2)
370 static const char spc[] = " ";
371 static const char sep[] = "================";
374 * do_efi_show_devices() - show UEFI devices
376 * @cmdtp: Command table
377 * @flag: Command flag
378 * @argc: Number of arguments
379 * @argv: Argument array
380 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
382 * Implement efidebug "devices" sub-command.
383 * Show all UEFI devices and their information.
385 static int do_efi_show_devices(struct cmd_tbl *cmdtp, int flag,
386 int argc, char *const argv[])
388 efi_handle_t *handles;
393 ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL,
395 if (ret != EFI_SUCCESS)
396 return CMD_RET_FAILURE;
399 return CMD_RET_SUCCESS;
401 printf("Device%.*s Device Path\n", EFI_HANDLE_WIDTH - 6, spc);
402 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
403 for (i = 0; i < num; i++) {
404 dev_path_text = efi_get_device_path_text(handles[i]);
406 printf("%p %ls\n", handles[i], dev_path_text);
407 efi_free_pool(dev_path_text);
411 efi_free_pool(handles);
413 return CMD_RET_SUCCESS;
417 * efi_get_driver_handle_info() - get information of UEFI driver
419 * @handle: Handle of UEFI device
420 * @driver_name: Driver name
421 * @image_path: Pointer to text of device path
422 * Return: 0 on success, -1 on failure
424 * Currently return no useful information as all UEFI drivers are
427 static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name,
430 struct efi_handler *handler;
431 struct efi_loaded_image *image;
436 * TODO: support EFI_COMPONENT_NAME2_PROTOCOL
441 ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler);
442 if (ret != EFI_SUCCESS) {
447 image = handler->protocol_interface;
448 *image_path = efi_dp_str(image->file_path);
454 * do_efi_show_drivers() - show UEFI drivers
456 * @cmdtp: Command table
457 * @flag: Command flag
458 * @argc: Number of arguments
459 * @argv: Argument array
460 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
462 * Implement efidebug "drivers" sub-command.
463 * Show all UEFI drivers and their information.
465 static int do_efi_show_drivers(struct cmd_tbl *cmdtp, int flag,
466 int argc, char *const argv[])
468 efi_handle_t *handles;
470 u16 *driver_name, *image_path_text;
473 ret = EFI_CALL(efi_locate_handle_buffer(
474 BY_PROTOCOL, &efi_guid_driver_binding_protocol,
475 NULL, &num, &handles));
476 if (ret != EFI_SUCCESS)
477 return CMD_RET_FAILURE;
480 return CMD_RET_SUCCESS;
482 printf("Driver%.*s Name Image Path\n",
483 EFI_HANDLE_WIDTH - 6, spc);
484 printf("%.*s ==================== ====================\n",
485 EFI_HANDLE_WIDTH, sep);
486 for (i = 0; i < num; i++) {
487 if (!efi_get_driver_handle_info(handles[i], &driver_name,
490 printf("%p %-20ls %ls\n", handles[i],
491 driver_name, image_path_text);
493 printf("%p %-20ls <built-in>\n",
494 handles[i], driver_name);
495 efi_free_pool(driver_name);
496 efi_free_pool(image_path_text);
500 efi_free_pool(handles);
502 return CMD_RET_SUCCESS;
505 static const struct {
507 const efi_guid_t guid;
511 EFI_DEVICE_PATH_PROTOCOL_GUID,
514 "Device Path To Text",
515 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID,
518 "Device Path Utilities",
519 EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID,
522 "Unicode Collation 2",
523 EFI_UNICODE_COLLATION_PROTOCOL2_GUID,
527 EFI_DRIVER_BINDING_PROTOCOL_GUID,
531 EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID,
534 "Simple Text Input Ex",
535 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID,
538 "Simple Text Output",
539 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID,
543 EFI_BLOCK_IO_PROTOCOL_GUID,
546 "Simple File System",
547 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
551 EFI_LOADED_IMAGE_PROTOCOL_GUID,
555 EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
559 EFI_HII_STRING_PROTOCOL_GUID,
563 EFI_HII_DATABASE_PROTOCOL_GUID,
566 "HII Config Routing",
567 EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID,
571 EFI_LOAD_FILE2_PROTOCOL_GUID,
574 "Random Number Generator",
575 EFI_RNG_PROTOCOL_GUID,
579 EFI_SIMPLE_NETWORK_PROTOCOL_GUID,
583 EFI_PXE_BASE_CODE_PROTOCOL_GUID,
587 EFI_DT_FIXUP_PROTOCOL_GUID,
591 PARTITION_SYSTEM_GUID
594 "Firmware Management",
595 EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID
597 /* Configuration table GUIDs */
603 "EFI System Resource Table",
604 EFI_SYSTEM_RESOURCE_TABLE_GUID,
615 "Runtime properties",
616 EFI_RT_PROPERTIES_TABLE_GUID,
619 "TCG2 Final Events Table",
620 EFI_TCG2_FINAL_EVENTS_TABLE_GUID,
625 * get_guid_text - get string of GUID
627 * Return description of GUID.
630 * Return: description of GUID or NULL
632 static const char *get_guid_text(const void *guid)
636 for (i = 0; i < ARRAY_SIZE(guid_list); i++) {
638 * As guidcmp uses memcmp() we can safely accept unaligned
641 if (!guidcmp(&guid_list[i].guid, guid))
642 return guid_list[i].text;
649 * do_efi_show_handles() - show UEFI handles
651 * @cmdtp: Command table
652 * @flag: Command flag
653 * @argc: Number of arguments
654 * @argv: Argument array
655 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
657 * Implement efidebug "dh" sub-command.
658 * Show all UEFI handles and their information, currently all protocols
661 static int do_efi_show_handles(struct cmd_tbl *cmdtp, int flag,
662 int argc, char *const argv[])
664 efi_handle_t *handles;
666 efi_uintn_t num, count, i, j;
667 const char *guid_text;
670 ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL,
672 if (ret != EFI_SUCCESS)
673 return CMD_RET_FAILURE;
676 return CMD_RET_SUCCESS;
678 printf("Handle%.*s Protocols\n", EFI_HANDLE_WIDTH - 6, spc);
679 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
680 for (i = 0; i < num; i++) {
681 printf("%p", handles[i]);
682 ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid,
689 for (j = 0; j < count; j++) {
695 guid_text = get_guid_text(guid[j]);
699 printf("%pUl", guid[j]);
704 efi_free_pool(handles);
706 return CMD_RET_SUCCESS;
710 * do_efi_show_images() - show UEFI images
712 * @cmdtp: Command table
713 * @flag: Command flag
714 * @argc: Number of arguments
715 * @argv: Argument array
716 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
718 * Implement efidebug "images" sub-command.
719 * Show all UEFI loaded images and their information.
721 static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag,
722 int argc, char *const argv[])
724 efi_print_image_infos(NULL);
726 return CMD_RET_SUCCESS;
729 static const char * const efi_mem_type_string[] = {
730 [EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
731 [EFI_LOADER_CODE] = "LOADER CODE",
732 [EFI_LOADER_DATA] = "LOADER DATA",
733 [EFI_BOOT_SERVICES_CODE] = "BOOT CODE",
734 [EFI_BOOT_SERVICES_DATA] = "BOOT DATA",
735 [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE",
736 [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA",
737 [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL",
738 [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM",
739 [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM",
740 [EFI_ACPI_MEMORY_NVS] = "ACPI NVS",
741 [EFI_MMAP_IO] = "IO",
742 [EFI_MMAP_IO_PORT] = "IO PORT",
743 [EFI_PAL_CODE] = "PAL",
744 [EFI_PERSISTENT_MEMORY_TYPE] = "PERSISTENT",
747 static const struct efi_mem_attrs {
750 } efi_mem_attrs[] = {
751 {EFI_MEMORY_UC, "UC"},
752 {EFI_MEMORY_UC, "UC"},
753 {EFI_MEMORY_WC, "WC"},
754 {EFI_MEMORY_WT, "WT"},
755 {EFI_MEMORY_WB, "WB"},
756 {EFI_MEMORY_UCE, "UCE"},
757 {EFI_MEMORY_WP, "WP"},
758 {EFI_MEMORY_RP, "RP"},
759 {EFI_MEMORY_XP, "WP"},
760 {EFI_MEMORY_NV, "NV"},
761 {EFI_MEMORY_MORE_RELIABLE, "REL"},
762 {EFI_MEMORY_RO, "RO"},
763 {EFI_MEMORY_SP, "SP"},
764 {EFI_MEMORY_RUNTIME, "RT"},
768 * print_memory_attributes() - print memory map attributes
770 * @attributes: Attribute value
772 * Print memory map attributes
774 static void print_memory_attributes(u64 attributes)
778 for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++)
779 if (attributes & efi_mem_attrs[i].bit) {
786 puts(efi_mem_attrs[i].text);
790 #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
793 * do_efi_show_memmap() - show UEFI memory map
795 * @cmdtp: Command table
796 * @flag: Command flag
797 * @argc: Number of arguments
798 * @argv: Argument array
799 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
801 * Implement efidebug "memmap" sub-command.
802 * Show UEFI memory map.
804 static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag,
805 int argc, char *const argv[])
807 struct efi_mem_desc *memmap = NULL, *map;
808 efi_uintn_t map_size = 0;
813 ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL);
814 if (ret == EFI_BUFFER_TOO_SMALL) {
815 map_size += sizeof(struct efi_mem_desc); /* for my own */
816 ret = efi_allocate_pool(EFI_LOADER_DATA, map_size,
818 if (ret != EFI_SUCCESS)
819 return CMD_RET_FAILURE;
820 ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL);
822 if (ret != EFI_SUCCESS) {
823 efi_free_pool(memmap);
824 return CMD_RET_FAILURE;
827 printf("Type Start%.*s End%.*s Attributes\n",
828 EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
829 printf("================ %.*s %.*s ==========\n",
830 EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
832 * Coverity check: dereferencing null pointer "map."
833 * This is a false positive as memmap will always be
834 * populated by allocate_pool() above.
836 for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
837 if (map->type < ARRAY_SIZE(efi_mem_type_string))
838 type = efi_mem_type_string[map->type];
842 printf("%-16s %.*llx-%.*llx", type,
844 (u64)map_to_sysmem((void *)(uintptr_t)
845 map->physical_start),
847 (u64)map_to_sysmem((void *)(uintptr_t)
848 (map->physical_start +
849 map->num_pages * EFI_PAGE_SIZE)));
851 print_memory_attributes(map->attribute);
855 efi_free_pool(memmap);
857 return CMD_RET_SUCCESS;
861 * do_efi_show_tables() - show UEFI configuration tables
863 * @cmdtp: Command table
864 * @flag: Command flag
865 * @argc: Number of arguments
866 * @argv: Argument array
867 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
869 * Implement efidebug "tables" sub-command.
870 * Show UEFI configuration tables.
872 static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
873 int argc, char *const argv[])
876 const char *guid_str;
878 for (i = 0; i < systab.nr_tables; ++i) {
879 guid_str = get_guid_text(&systab.tables[i].guid);
882 printf("%pUl %s\n", &systab.tables[i].guid, guid_str);
885 return CMD_RET_SUCCESS;
889 * create_initrd_dp() - Create a special device for our Boot### option
892 * @part: Disk partition
894 * Return: Pointer to the device path or ERR_PTR
898 struct efi_device_path *create_initrd_dp(const char *dev, const char *part,
902 struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL;
903 struct efi_device_path *initrd_dp = NULL;
905 const struct efi_initrd_dp id_dp = {
908 DEVICE_PATH_TYPE_MEDIA_DEVICE,
909 DEVICE_PATH_SUB_TYPE_VENDOR_PATH,
910 sizeof(id_dp.vendor),
912 EFI_INITRD_MEDIA_GUID,
915 DEVICE_PATH_TYPE_END,
916 DEVICE_PATH_SUB_TYPE_END,
921 ret = efi_dp_from_name(dev, part, file, &tmp_dp, &tmp_fp);
922 if (ret != EFI_SUCCESS) {
923 printf("Cannot create device path for \"%s %s\"\n", part, file);
927 initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp,
931 efi_free_pool(tmp_dp);
932 efi_free_pool(tmp_fp);
937 * do_efi_boot_add() - set UEFI load option
939 * @cmdtp: Command table
940 * @flag: Command flag
941 * @argc: Number of arguments
942 * @argv: Argument array
943 * Return: CMD_RET_SUCCESS on success,
944 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
946 * Implement efidebug "boot add" sub-command. Create or change UEFI load option.
948 * efidebug boot add -b <id> <label> <interface> <devnum>[:<part>] <file>
949 * -i <file> <interface2> <devnum2>[:<part>] <initrd>
952 static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
953 int argc, char *const argv[])
958 u16 var_name16[9], *p;
960 size_t label_len, label_len16;
962 struct efi_device_path *device_path = NULL, *file_path = NULL;
963 struct efi_device_path *final_fp = NULL;
964 struct efi_device_path *initrd_dp = NULL;
965 struct efi_load_option lo;
968 efi_uintn_t fp_size = 0;
970 int r = CMD_RET_SUCCESS;
972 guid = efi_global_variable_guid;
975 lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
976 lo.optional_data = NULL;
981 for (; argc > 0; argc--, argv++) {
982 if (!strcmp(argv[0], "-b")) {
983 if (argc < 5 || lo.label) {
987 id = (int)simple_strtoul(argv[1], &endp, 16);
988 if (*endp != '\0' || id > 0xffff)
989 return CMD_RET_USAGE;
991 sprintf(var_name, "Boot%04X", id);
993 utf8_utf16_strncpy(&p, var_name, 9);
996 label_len = strlen(argv[2]);
997 label_len16 = utf8_utf16_strnlen(argv[2], label_len);
998 label = malloc((label_len16 + 1) * sizeof(u16));
1000 return CMD_RET_FAILURE;
1001 lo.label = label; /* label will be changed below */
1002 utf8_utf16_strncpy(&label, argv[2], label_len);
1005 ret = efi_dp_from_name(argv[3], argv[4], argv[5],
1006 &device_path, &file_path);
1007 if (ret != EFI_SUCCESS) {
1008 printf("Cannot create device path for \"%s %s\"\n",
1010 r = CMD_RET_FAILURE;
1013 fp_size += efi_dp_size(file_path) +
1014 sizeof(struct efi_device_path);
1017 } else if (!strcmp(argv[0], "-i")) {
1018 if (argc < 3 || initrd_dp) {
1023 initrd_dp = create_initrd_dp(argv[1], argv[2], argv[3]);
1025 printf("Cannot add an initrd\n");
1026 r = CMD_RET_FAILURE;
1031 fp_size += efi_dp_size(initrd_dp) +
1032 sizeof(struct efi_device_path);
1033 } else if (!strcmp(argv[0], "-s")) {
1034 if (argc < 1 || lo.optional_data) {
1038 lo.optional_data = (const u8 *)argv[1];
1048 printf("Missing binary\n");
1053 final_fp = efi_dp_concat(file_path, initrd_dp);
1055 printf("Cannot create final device path\n");
1056 r = CMD_RET_FAILURE;
1060 lo.file_path = final_fp;
1061 lo.file_path_length = fp_size;
1063 size = efi_serialize_load_option(&lo, (u8 **)&data);
1065 r = CMD_RET_FAILURE;
1069 ret = EFI_CALL(efi_set_variable(var_name16, &guid,
1070 EFI_VARIABLE_NON_VOLATILE |
1071 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1072 EFI_VARIABLE_RUNTIME_ACCESS,
1074 if (ret != EFI_SUCCESS) {
1075 printf("Cannot set %ls\n", var_name16);
1076 r = CMD_RET_FAILURE;
1081 efi_free_pool(final_fp);
1082 efi_free_pool(initrd_dp);
1083 efi_free_pool(device_path);
1084 efi_free_pool(file_path);
1091 * do_efi_boot_rm() - delete UEFI load options
1093 * @cmdtp: Command table
1094 * @flag: Command flag
1095 * @argc: Number of arguments
1096 * @argv: Argument array
1097 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1099 * Implement efidebug "boot rm" sub-command.
1100 * Delete UEFI load options.
1102 * efidebug boot rm <id> ...
1104 static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
1105 int argc, char *const argv[])
1111 u16 var_name16[9], *p;
1115 return CMD_RET_USAGE;
1117 guid = efi_global_variable_guid;
1118 for (i = 1; i < argc; i++, argv++) {
1119 id = (int)simple_strtoul(argv[1], &endp, 16);
1120 if (*endp != '\0' || id > 0xffff)
1121 return CMD_RET_FAILURE;
1123 sprintf(var_name, "Boot%04X", id);
1125 utf8_utf16_strncpy(&p, var_name, 9);
1127 ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
1129 printf("Cannot remove %ls\n", var_name16);
1130 return CMD_RET_FAILURE;
1134 return CMD_RET_SUCCESS;
1138 * show_efi_boot_opt_data() - dump UEFI load option
1140 * @varname16: variable name
1141 * @data: value of UEFI load option variable
1142 * @size: size of the boot option
1144 * Decode the value of UEFI load option variable and print information.
1146 static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
1148 struct efi_device_path *initrd_path = NULL;
1149 struct efi_load_option lo;
1151 size_t label_len16, label_len;
1154 efi_uintn_t initrd_dp_size;
1155 const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID;
1157 ret = efi_deserialize_load_option(&lo, data, size);
1158 if (ret != EFI_SUCCESS) {
1159 printf("%ls: invalid load option\n", varname16);
1163 label_len16 = u16_strlen(lo.label);
1164 label_len = utf16_utf8_strnlen(lo.label, label_len16);
1165 label = malloc(label_len + 1);
1169 utf16_utf8_strncpy(&p, lo.label, label_len16);
1171 printf("%ls:\nattributes: %c%c%c (0x%08x)\n",
1174 lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
1175 /* FORCE RECONNECT */
1176 lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-',
1178 lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
1180 printf(" label: %s\n", label);
1182 dp_str = efi_dp_str(lo.file_path);
1183 printf(" file_path: %ls\n", dp_str);
1184 efi_free_pool(dp_str);
1186 initrd_path = efi_dp_from_lo(&lo, &initrd_dp_size, lf2_initrd_guid);
1188 dp_str = efi_dp_str(initrd_path);
1189 printf(" initrd_path: %ls\n", dp_str);
1190 efi_free_pool(dp_str);
1191 efi_free_pool(initrd_path);
1195 print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
1196 lo.optional_data, *size, true);
1201 * show_efi_boot_opt() - dump UEFI load option
1203 * @varname16: variable name
1205 * Dump information defined by UEFI load option.
1207 static void show_efi_boot_opt(u16 *varname16)
1214 ret = EFI_CALL(efi_get_variable(varname16, &efi_global_variable_guid,
1215 NULL, &size, NULL));
1216 if (ret == EFI_BUFFER_TOO_SMALL) {
1217 data = malloc(size);
1219 printf("ERROR: Out of memory\n");
1222 ret = EFI_CALL(efi_get_variable(varname16,
1223 &efi_global_variable_guid,
1224 NULL, &size, data));
1225 if (ret == EFI_SUCCESS)
1226 show_efi_boot_opt_data(varname16, data, &size);
1231 static int u16_tohex(u16 c)
1233 if (c >= '0' && c <= '9')
1235 if (c >= 'A' && c <= 'F')
1236 return c - 'A' + 10;
1238 /* not hexadecimal */
1243 * show_efi_boot_dump() - dump all UEFI load options
1245 * @cmdtp: Command table
1246 * @flag: Command flag
1247 * @argc: Number of arguments
1248 * @argv: Argument array
1249 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1251 * Implement efidebug "boot dump" sub-command.
1252 * Dump information of all UEFI load options defined.
1254 * efidebug boot dump
1256 static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag,
1257 int argc, char *const argv[])
1259 u16 *var_name16, *p;
1260 efi_uintn_t buf_size, size;
1266 return CMD_RET_USAGE;
1269 var_name16 = malloc(buf_size);
1271 return CMD_RET_FAILURE;
1276 ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16,
1278 if (ret == EFI_NOT_FOUND)
1280 if (ret == EFI_BUFFER_TOO_SMALL) {
1282 p = realloc(var_name16, buf_size);
1285 return CMD_RET_FAILURE;
1288 ret = EFI_CALL(efi_get_next_variable_name(&size,
1292 if (ret != EFI_SUCCESS) {
1294 return CMD_RET_FAILURE;
1297 if (memcmp(var_name16, L"Boot", 8))
1300 for (id = 0, i = 0; i < 4; i++) {
1301 digit = u16_tohex(var_name16[4 + i]);
1304 id = (id << 4) + digit;
1306 if (i == 4 && !var_name16[8])
1307 show_efi_boot_opt(var_name16);
1312 return CMD_RET_SUCCESS;
1316 * show_efi_boot_order() - show order of UEFI load options
1318 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1320 * Show order of UEFI load options defined by BootOrder variable.
1322 static int show_efi_boot_order(void)
1328 u16 var_name16[9], *p16;
1330 struct efi_load_option lo;
1332 size_t label_len16, label_len;
1336 ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid,
1337 NULL, &size, NULL));
1338 if (ret != EFI_BUFFER_TOO_SMALL) {
1339 if (ret == EFI_NOT_FOUND) {
1340 printf("BootOrder not defined\n");
1341 return CMD_RET_SUCCESS;
1343 return CMD_RET_FAILURE;
1346 bootorder = malloc(size);
1348 printf("ERROR: Out of memory\n");
1349 return CMD_RET_FAILURE;
1351 ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid,
1352 NULL, &size, bootorder));
1353 if (ret != EFI_SUCCESS) {
1354 ret = CMD_RET_FAILURE;
1358 num = size / sizeof(u16);
1359 for (i = 0; i < num; i++) {
1360 sprintf(var_name, "Boot%04X", bootorder[i]);
1362 utf8_utf16_strncpy(&p16, var_name, 9);
1365 ret = EFI_CALL(efi_get_variable(var_name16,
1366 &efi_global_variable_guid, NULL,
1368 if (ret != EFI_BUFFER_TOO_SMALL) {
1369 printf("%2d: %s: (not defined)\n", i + 1, var_name);
1373 data = malloc(size);
1375 ret = CMD_RET_FAILURE;
1378 ret = EFI_CALL(efi_get_variable(var_name16,
1379 &efi_global_variable_guid, NULL,
1381 if (ret != EFI_SUCCESS) {
1383 ret = CMD_RET_FAILURE;
1387 ret = efi_deserialize_load_option(&lo, data, &size);
1388 if (ret != EFI_SUCCESS) {
1389 printf("%ls: invalid load option\n", var_name16);
1390 ret = CMD_RET_FAILURE;
1394 label_len16 = u16_strlen(lo.label);
1395 label_len = utf16_utf8_strnlen(lo.label, label_len16);
1396 label = malloc(label_len + 1);
1399 ret = CMD_RET_FAILURE;
1403 utf16_utf8_strncpy(&p, lo.label, label_len16);
1404 printf("%2d: %s: %s\n", i + 1, var_name, label);
1416 * do_efi_boot_next() - manage UEFI BootNext variable
1418 * @cmdtp: Command table
1419 * @flag: Command flag
1420 * @argc: Number of arguments
1421 * @argv: Argument array
1422 * Return: CMD_RET_SUCCESS on success,
1423 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1425 * Implement efidebug "boot next" sub-command.
1426 * Set BootNext variable.
1428 * efidebug boot next <id>
1430 static int do_efi_boot_next(struct cmd_tbl *cmdtp, int flag,
1431 int argc, char *const argv[])
1438 int r = CMD_RET_SUCCESS;
1441 return CMD_RET_USAGE;
1443 bootnext = (u16)simple_strtoul(argv[1], &endp, 16);
1445 printf("invalid value: %s\n", argv[1]);
1446 r = CMD_RET_FAILURE;
1450 guid = efi_global_variable_guid;
1452 ret = EFI_CALL(efi_set_variable(L"BootNext", &guid,
1453 EFI_VARIABLE_NON_VOLATILE |
1454 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1455 EFI_VARIABLE_RUNTIME_ACCESS,
1457 if (ret != EFI_SUCCESS) {
1458 printf("Cannot set BootNext\n");
1459 r = CMD_RET_FAILURE;
1466 * do_efi_boot_order() - manage UEFI BootOrder variable
1468 * @cmdtp: Command table
1469 * @flag: Command flag
1470 * @argc: Number of arguments
1471 * @argv: Argument array
1472 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1474 * Implement efidebug "boot order" sub-command.
1475 * Show order of UEFI load options, or change it in BootOrder variable.
1477 * efidebug boot order [<id> ...]
1479 static int do_efi_boot_order(struct cmd_tbl *cmdtp, int flag,
1480 int argc, char *const argv[])
1482 u16 *bootorder = NULL;
1488 int r = CMD_RET_SUCCESS;
1491 return show_efi_boot_order();
1496 size = argc * sizeof(u16);
1497 bootorder = malloc(size);
1499 return CMD_RET_FAILURE;
1501 for (i = 0; i < argc; i++) {
1502 id = (int)simple_strtoul(argv[i], &endp, 16);
1503 if (*endp != '\0' || id > 0xffff) {
1504 printf("invalid value: %s\n", argv[i]);
1505 r = CMD_RET_FAILURE;
1509 bootorder[i] = (u16)id;
1512 guid = efi_global_variable_guid;
1513 ret = EFI_CALL(efi_set_variable(L"BootOrder", &guid,
1514 EFI_VARIABLE_NON_VOLATILE |
1515 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1516 EFI_VARIABLE_RUNTIME_ACCESS,
1518 if (ret != EFI_SUCCESS) {
1519 printf("Cannot set BootOrder\n");
1520 r = CMD_RET_FAILURE;
1528 static struct cmd_tbl cmd_efidebug_boot_sub[] = {
1529 U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""),
1530 U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""),
1531 U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""),
1532 U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""),
1533 U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order,
1538 * do_efi_boot_opt() - manage UEFI load options
1540 * @cmdtp: Command table
1541 * @flag: Command flag
1542 * @argc: Number of arguments
1543 * @argv: Argument array
1544 * Return: CMD_RET_SUCCESS on success,
1545 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1547 * Implement efidebug "boot" sub-command.
1549 static int do_efi_boot_opt(struct cmd_tbl *cmdtp, int flag,
1550 int argc, char *const argv[])
1555 return CMD_RET_USAGE;
1559 cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub,
1560 ARRAY_SIZE(cmd_efidebug_boot_sub));
1562 return CMD_RET_USAGE;
1564 return cp->cmd(cmdtp, flag, argc, argv);
1568 * do_efi_test_bootmgr() - run simple bootmgr for test
1570 * @cmdtp: Command table
1571 * @flag: Command flag
1572 * @argc: Number of arguments
1573 * @argv: Argument array
1574 * Return: CMD_RET_SUCCESS on success,
1575 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1577 * Implement efidebug "test bootmgr" sub-command.
1578 * Run simple bootmgr for test.
1580 * efidebug test bootmgr
1582 static __maybe_unused int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag,
1583 int argc, char * const argv[])
1586 efi_uintn_t exit_data_size = 0;
1587 u16 *exit_data = NULL;
1589 void *load_options = NULL;
1591 ret = efi_bootmgr_load(&image, &load_options);
1592 printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK);
1594 /* We call efi_start_image() even if error for test purpose. */
1595 ret = EFI_CALL(efi_start_image(image, &exit_data_size, &exit_data));
1596 printf("efi_start_image() returned: %ld\n", ret & ~EFI_ERROR_MASK);
1597 if (ret && exit_data)
1598 efi_free_pool(exit_data);
1603 return CMD_RET_SUCCESS;
1606 static struct cmd_tbl cmd_efidebug_test_sub[] = {
1607 #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR
1608 U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr,
1614 * do_efi_test() - manage UEFI load options
1616 * @cmdtp: Command table
1617 * @flag: Command flag
1618 * @argc: Number of arguments
1619 * @argv: Argument array
1620 * Return: CMD_RET_SUCCESS on success,
1621 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1623 * Implement efidebug "test" sub-command.
1625 static int do_efi_test(struct cmd_tbl *cmdtp, int flag,
1626 int argc, char * const argv[])
1631 return CMD_RET_USAGE;
1635 cp = find_cmd_tbl(argv[0], cmd_efidebug_test_sub,
1636 ARRAY_SIZE(cmd_efidebug_test_sub));
1638 return CMD_RET_USAGE;
1640 return cp->cmd(cmdtp, flag, argc, argv);
1644 * do_efi_query_info() - QueryVariableInfo EFI service
1646 * @cmdtp: Command table
1647 * @flag: Command flag
1648 * @argc: Number of arguments
1649 * @argv: Argument array
1650 * Return: CMD_RET_SUCCESS on success,
1651 * CMD_RET_USAGE or CMD_RET_FAILURE on failure
1653 * Implement efidebug "test" sub-command.
1656 static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag,
1657 int argc, char * const argv[])
1661 u64 max_variable_storage_size;
1662 u64 remain_variable_storage_size;
1663 u64 max_variable_size;
1666 for (i = 1; i < argc; i++) {
1667 if (!strcmp(argv[i], "-bs"))
1668 attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
1669 else if (!strcmp(argv[i], "-rt"))
1670 attr |= EFI_VARIABLE_RUNTIME_ACCESS;
1671 else if (!strcmp(argv[i], "-nv"))
1672 attr |= EFI_VARIABLE_NON_VOLATILE;
1673 else if (!strcmp(argv[i], "-at"))
1675 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
1678 ret = EFI_CALL(efi_query_variable_info(attr,
1679 &max_variable_storage_size,
1680 &remain_variable_storage_size,
1681 &max_variable_size));
1682 if (ret != EFI_SUCCESS) {
1683 printf("Error: Cannot query UEFI variables, r = %lu\n",
1684 ret & ~EFI_ERROR_MASK);
1685 return CMD_RET_FAILURE;
1688 printf("Max storage size %llu\n", max_variable_storage_size);
1689 printf("Remaining storage size %llu\n", remain_variable_storage_size);
1690 printf("Max variable size %llu\n", max_variable_size);
1692 return CMD_RET_SUCCESS;
1695 static struct cmd_tbl cmd_efidebug_sub[] = {
1696 U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
1697 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
1698 U_BOOT_CMD_MKENT(capsule, CONFIG_SYS_MAXARGS, 1, do_efi_capsule,
1701 U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
1703 U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
1705 U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
1707 U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
1709 U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
1711 U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables,
1713 U_BOOT_CMD_MKENT(test, CONFIG_SYS_MAXARGS, 1, do_efi_test,
1715 U_BOOT_CMD_MKENT(query, CONFIG_SYS_MAXARGS, 1, do_efi_query_info,
1720 * do_efidebug() - display and configure UEFI environment
1722 * @cmdtp: Command table
1723 * @flag: Command flag
1724 * @argc: Number of arguments
1725 * @argv: Argument array
1726 * Return: CMD_RET_SUCCESS on success,
1727 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1729 * Implement efidebug command which allows us to display and
1730 * configure UEFI environment.
1732 static int do_efidebug(struct cmd_tbl *cmdtp, int flag,
1733 int argc, char *const argv[])
1739 return CMD_RET_USAGE;
1743 /* Initialize UEFI drivers */
1744 r = efi_init_obj_list();
1745 if (r != EFI_SUCCESS) {
1746 printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1747 r & ~EFI_ERROR_MASK);
1748 return CMD_RET_FAILURE;
1751 cp = find_cmd_tbl(argv[0], cmd_efidebug_sub,
1752 ARRAY_SIZE(cmd_efidebug_sub));
1754 return CMD_RET_USAGE;
1756 return cp->cmd(cmdtp, flag, argc, argv);
1759 #ifdef CONFIG_SYS_LONGHELP
1760 static char efidebug_help_text[] =
1761 " - UEFI Shell-like interface to configure UEFI environment\n"
1763 "efidebug boot add "
1764 "-b <bootid> <label> <interface> <devnum>[:<part>] <file path> "
1765 "-i <interface> <devnum>[:<part>] <initrd file path> "
1766 "-s '<optional data>'\n"
1767 " - set UEFI BootXXXX variable\n"
1768 " <load options> will be passed to UEFI application\n"
1769 "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
1770 " - delete UEFI BootXXXX variables\n"
1771 "efidebug boot dump\n"
1772 " - dump all UEFI BootXXXX variables\n"
1773 "efidebug boot next <bootid>\n"
1774 " - set UEFI BootNext variable\n"
1775 "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
1776 " - set/show UEFI boot order\n"
1778 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
1779 "efidebug capsule update [-v] <capsule address>\n"
1780 " - process a capsule\n"
1781 "efidebug capsule disk-update\n"
1782 " - update a capsule from disk\n"
1783 "efidebug capsule show <capsule address>\n"
1784 " - show capsule information\n"
1785 "efidebug capsule result [<capsule result var>]\n"
1786 " - show a capsule update result\n"
1787 #ifdef CONFIG_EFI_ESRT
1788 "efidebug capsule esrt\n"
1789 " - print the ESRT\n"
1793 "efidebug devices\n"
1794 " - show UEFI devices\n"
1795 "efidebug drivers\n"
1796 " - show UEFI drivers\n"
1798 " - show UEFI handles\n"
1800 " - show loaded images\n"
1802 " - show UEFI memory map\n"
1804 " - show UEFI configuration tables\n"
1805 #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR
1806 "efidebug test bootmgr\n"
1807 " - run simple bootmgr for test\n"
1809 "efidebug query [-nv][-bs][-rt][-at]\n"
1810 " - show size of UEFI variables store\n";
1814 efidebug, CONFIG_SYS_MAXARGS, 0, do_efidebug,
1815 "Configure UEFI environment",