1 // SPDX-License-Identifier: GPL-2.0+
3 * UEFI Shell-like command
5 * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
11 #include <efi_loader.h>
12 #include <environment.h>
16 #include <linux/ctype.h>
18 #define BS systab.boottime
19 #define RT systab.runtime
22 * efi_get_device_handle_info() - get information of UEFI device
24 * @handle: Handle of UEFI device
25 * @dev_path_text: Pointer to text of device path
26 * Return: 0 on success, -1 on failure
28 * Currently return a formatted text of device path.
30 static int efi_get_device_handle_info(efi_handle_t handle, u16 **dev_path_text)
32 struct efi_device_path *dp;
35 ret = EFI_CALL(BS->open_protocol(handle, &efi_guid_device_path,
36 (void **)&dp, NULL /* FIXME */, NULL,
37 EFI_OPEN_PROTOCOL_GET_PROTOCOL));
38 if (ret == EFI_SUCCESS) {
39 *dev_path_text = efi_dp_str(dp);
46 #define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2)
48 static const char spc[] = " ";
49 static const char sep[] = "================";
52 * do_efi_show_devices() - show UEFI devices
54 * @cmdtp: Command table
56 * @argc: Number of arguments
57 * @argv: Argument array
58 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
60 * Implement efidebug "devices" sub-command.
61 * Show all UEFI devices and their information.
63 static int do_efi_show_devices(cmd_tbl_t *cmdtp, int flag,
64 int argc, char * const argv[])
66 efi_handle_t *handles;
71 ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL,
73 if (ret != EFI_SUCCESS)
74 return CMD_RET_FAILURE;
77 return CMD_RET_SUCCESS;
79 printf("Device%.*s Device Path\n", EFI_HANDLE_WIDTH - 6, spc);
80 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
81 for (i = 0; i < num; i++) {
82 if (!efi_get_device_handle_info(handles[i], &dev_path_text)) {
83 printf("%p %ls\n", handles[i], dev_path_text);
84 efi_free_pool(dev_path_text);
88 EFI_CALL(BS->free_pool(handles));
90 return CMD_RET_SUCCESS;
94 * efi_get_driver_handle_info() - get information of UEFI driver
96 * @handle: Handle of UEFI device
97 * @driver_name: Driver name
98 * @image_path: Pointer to text of device path
99 * Return: 0 on success, -1 on failure
101 * Currently return no useful information as all UEFI drivers are
104 static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name,
107 struct efi_handler *handler;
108 struct efi_loaded_image *image;
113 * TODO: support EFI_COMPONENT_NAME2_PROTOCOL
118 ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler);
119 if (ret != EFI_SUCCESS) {
124 image = handler->protocol_interface;
125 *image_path = efi_dp_str(image->file_path);
131 * do_efi_show_drivers() - show UEFI drivers
133 * @cmdtp: Command table
134 * @flag: Command flag
135 * @argc: Number of arguments
136 * @argv: Argument array
137 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
139 * Implement efidebug "drivers" sub-command.
140 * Show all UEFI drivers and their information.
142 static int do_efi_show_drivers(cmd_tbl_t *cmdtp, int flag,
143 int argc, char * const argv[])
145 efi_handle_t *handles;
147 u16 *driver_name, *image_path_text;
150 ret = EFI_CALL(BS->locate_handle_buffer(
151 BY_PROTOCOL, &efi_guid_driver_binding_protocol,
152 NULL, &num, &handles));
153 if (ret != EFI_SUCCESS)
154 return CMD_RET_FAILURE;
157 return CMD_RET_SUCCESS;
159 printf("Driver%.*s Name Image Path\n",
160 EFI_HANDLE_WIDTH - 6, spc);
161 printf("%.*s ==================== ====================\n",
162 EFI_HANDLE_WIDTH, sep);
163 for (i = 0; i < num; i++) {
164 if (!efi_get_driver_handle_info(handles[i], &driver_name,
167 printf("%p %-20ls %ls\n", handles[i],
168 driver_name, image_path_text);
170 printf("%p %-20ls <built-in>\n",
171 handles[i], driver_name);
172 EFI_CALL(BS->free_pool(driver_name));
173 EFI_CALL(BS->free_pool(image_path_text));
177 EFI_CALL(BS->free_pool(handles));
179 return CMD_RET_SUCCESS;
182 static const struct {
184 const efi_guid_t guid;
191 "Device Path To Text",
192 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID,
195 "Device Path Utilities",
196 EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID,
199 "Unicode Collation 2",
200 EFI_UNICODE_COLLATION_PROTOCOL2_GUID,
204 EFI_DRIVER_BINDING_PROTOCOL_GUID,
208 EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID,
211 "Simple Text Input Ex",
212 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID,
215 "Simple Text Output",
216 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID,
223 "Simple File System",
224 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
228 LOADED_IMAGE_PROTOCOL_GUID,
237 * get_guid_text - get string of protocol guid
238 * @guid: Protocol guid
241 * Return string for display to represent the protocol.
243 static const char *get_guid_text(const efi_guid_t *guid)
247 for (i = 0; i < ARRAY_SIZE(guid_list); i++)
248 if (!guidcmp(&guid_list[i].guid, guid))
251 if (i != ARRAY_SIZE(guid_list))
252 return guid_list[i].text;
258 * do_efi_show_handles() - show UEFI handles
260 * @cmdtp: Command table
261 * @flag: Command flag
262 * @argc: Number of arguments
263 * @argv: Argument array
264 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
266 * Implement efidebug "dh" sub-command.
267 * Show all UEFI handles and their information, currently all protocols
270 static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag,
271 int argc, char * const argv[])
273 efi_handle_t *handles;
275 efi_uintn_t num, count, i, j;
276 const char *guid_text;
279 ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL,
281 if (ret != EFI_SUCCESS)
282 return CMD_RET_FAILURE;
285 return CMD_RET_SUCCESS;
287 printf("Handle%.*s Protocols\n", EFI_HANDLE_WIDTH - 6, spc);
288 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
289 for (i = 0; i < num; i++) {
290 printf("%p", handles[i]);
291 ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid,
298 for (j = 0; j < count; j++) {
304 guid_text = get_guid_text(guid[j]);
308 printf("%pUl", guid[j]);
313 EFI_CALL(BS->free_pool(handles));
315 return CMD_RET_SUCCESS;
319 * do_efi_show_images() - show UEFI images
321 * @cmdtp: Command table
322 * @flag: Command flag
323 * @argc: Number of arguments
324 * @argv: Argument array
325 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
327 * Implement efidebug "images" sub-command.
328 * Show all UEFI loaded images and their information.
330 static int do_efi_show_images(cmd_tbl_t *cmdtp, int flag,
331 int argc, char * const argv[])
333 efi_print_image_infos(NULL);
335 return CMD_RET_SUCCESS;
338 static const char * const efi_mem_type_string[] = {
339 [EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
340 [EFI_LOADER_CODE] = "LOADER CODE",
341 [EFI_LOADER_DATA] = "LOADER DATA",
342 [EFI_BOOT_SERVICES_CODE] = "BOOT CODE",
343 [EFI_BOOT_SERVICES_DATA] = "BOOT DATA",
344 [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE",
345 [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA",
346 [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL",
347 [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM",
348 [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM",
349 [EFI_ACPI_MEMORY_NVS] = "ACPI NVS",
350 [EFI_MMAP_IO] = "IO",
351 [EFI_MMAP_IO_PORT] = "IO PORT",
352 [EFI_PAL_CODE] = "PAL",
355 static const struct efi_mem_attrs {
358 } efi_mem_attrs[] = {
359 {EFI_MEMORY_UC, "UC"},
360 {EFI_MEMORY_UC, "UC"},
361 {EFI_MEMORY_WC, "WC"},
362 {EFI_MEMORY_WT, "WT"},
363 {EFI_MEMORY_WB, "WB"},
364 {EFI_MEMORY_UCE, "UCE"},
365 {EFI_MEMORY_WP, "WP"},
366 {EFI_MEMORY_RP, "RP"},
367 {EFI_MEMORY_XP, "WP"},
368 {EFI_MEMORY_NV, "NV"},
369 {EFI_MEMORY_MORE_RELIABLE, "REL"},
370 {EFI_MEMORY_RO, "RO"},
371 {EFI_MEMORY_RUNTIME, "RT"},
375 * print_memory_attributes() - print memory map attributes
376 * @attributes: Attribute value
378 * Print memory map attributes
380 static void print_memory_attributes(u64 attributes)
384 for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++)
385 if (attributes & efi_mem_attrs[i].bit) {
392 puts(efi_mem_attrs[i].text);
396 #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
399 * do_efi_show_memmap() - show UEFI memory map
401 * @cmdtp: Command table
402 * @flag: Command flag
403 * @argc: Number of arguments
404 * @argv: Argument array
405 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
407 * Implement efidebug "memmap" sub-command.
408 * Show UEFI memory map.
410 static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag,
411 int argc, char * const argv[])
413 struct efi_mem_desc *memmap = NULL, *map;
414 efi_uintn_t map_size = 0;
419 ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL, NULL, NULL));
420 if (ret == EFI_BUFFER_TOO_SMALL) {
421 map_size += sizeof(struct efi_mem_desc); /* for my own */
422 ret = EFI_CALL(BS->allocate_pool(EFI_LOADER_DATA,
423 map_size, (void *)&memmap));
424 if (ret != EFI_SUCCESS)
425 return CMD_RET_FAILURE;
426 ret = EFI_CALL(BS->get_memory_map(&map_size, memmap,
429 if (ret != EFI_SUCCESS) {
430 EFI_CALL(BS->free_pool(memmap));
431 return CMD_RET_FAILURE;
434 printf("Type Start%.*s End%.*s Attributes\n",
435 EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
436 printf("================ %.*s %.*s ==========\n",
437 EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
438 for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
439 if (map->type < EFI_MAX_MEMORY_TYPE)
440 type = efi_mem_type_string[map->type];
444 printf("%-16s %.*llx-%.*llx", type,
448 map->physical_start + map->num_pages * EFI_PAGE_SIZE);
450 print_memory_attributes(map->attribute);
454 EFI_CALL(BS->free_pool(memmap));
456 return CMD_RET_SUCCESS;
460 * do_efi_boot_add() - set UEFI load option
462 * @cmdtp: Command table
463 * @flag: Command flag
464 * @argc: Number of arguments
465 * @argv: Argument array
466 * Return: CMD_RET_SUCCESS on success,
467 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
469 * Implement efidebug "boot add" sub-command.
470 * Create or change UEFI load option.
471 * - boot add <id> <label> <interface> <devnum>[:<part>] <file> <options>
473 static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag,
474 int argc, char * const argv[])
479 u16 var_name16[9], *p;
481 size_t label_len, label_len16;
483 struct efi_device_path *device_path = NULL, *file_path = NULL;
484 struct efi_load_option lo;
489 if (argc < 6 || argc > 7)
490 return CMD_RET_USAGE;
492 id = (int)simple_strtoul(argv[1], &endp, 16);
493 if (*endp != '\0' || id > 0xffff)
494 return CMD_RET_FAILURE;
496 sprintf(var_name, "Boot%04X", id);
498 utf8_utf16_strncpy(&p, var_name, 9);
500 guid = efi_global_variable_guid;
503 lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
506 label_len = strlen(argv[2]);
507 label_len16 = utf8_utf16_strnlen(argv[2], label_len);
508 label = malloc((label_len16 + 1) * sizeof(u16));
510 return CMD_RET_FAILURE;
511 lo.label = label; /* label will be changed below */
512 utf8_utf16_strncpy(&label, argv[2], label_len);
515 ret = efi_dp_from_name(argv[3], argv[4], argv[5], &device_path,
517 if (ret != EFI_SUCCESS) {
518 printf("Cannot create device path for \"%s %s\"\n",
520 ret = CMD_RET_FAILURE;
523 lo.file_path = file_path;
524 lo.file_path_length = efi_dp_size(file_path)
525 + sizeof(struct efi_device_path); /* for END */
528 lo.optional_data = (u8 *)(argc == 6 ? "" : argv[6]);
530 size = efi_serialize_load_option(&lo, (u8 **)&data);
532 ret = CMD_RET_FAILURE;
536 ret = EFI_CALL(RT->set_variable(var_name16, &guid,
537 EFI_VARIABLE_BOOTSERVICE_ACCESS |
538 EFI_VARIABLE_RUNTIME_ACCESS,
540 ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
543 efi_free_pool(device_path);
544 efi_free_pool(file_path);
551 * do_efi_boot_rm() - delete UEFI load options
553 * @cmdtp: Command table
554 * @flag: Command flag
555 * @argc: Number of arguments
556 * @argv: Argument array
557 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
559 * Implement efidebug "boot rm" sub-command.
560 * Delete UEFI load options.
563 static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,
564 int argc, char * const argv[])
574 return CMD_RET_USAGE;
576 guid = efi_global_variable_guid;
577 for (i = 1; i < argc; i++, argv++) {
578 id = (int)simple_strtoul(argv[1], &endp, 16);
579 if (*endp != '\0' || id > 0xffff)
580 return CMD_RET_FAILURE;
582 sprintf(var_name, "Boot%04X", id);
583 utf8_utf16_strncpy((u16 **)&var_name16, var_name, 9);
585 ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL));
587 printf("cannot remove Boot%04X", id);
588 return CMD_RET_FAILURE;
592 return CMD_RET_SUCCESS;
596 * show_efi_boot_opt_data() - dump UEFI load option
598 * @id: Load option number
599 * @data: Value of UEFI load option variable
601 * Decode the value of UEFI load option variable and print information.
603 static void show_efi_boot_opt_data(int id, void *data)
605 struct efi_load_option lo;
607 size_t label_len16, label_len;
610 efi_deserialize_load_option(&lo, data);
612 label_len16 = u16_strlen(lo.label);
613 label_len = utf16_utf8_strnlen(lo.label, label_len16);
614 label = malloc(label_len + 1);
618 utf16_utf8_strncpy(&p, lo.label, label_len16);
620 printf("Boot%04X:\n", id);
621 printf("\tattributes: %c%c%c (0x%08x)\n",
623 lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
624 /* FORCE RECONNECT */
625 lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-',
627 lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
629 printf("\tlabel: %s\n", label);
631 dp_str = efi_dp_str(lo.file_path);
632 printf("\tfile_path: %ls\n", dp_str);
633 efi_free_pool(dp_str);
635 printf("\tdata: %s\n", lo.optional_data);
641 * show_efi_boot_opt() - dump UEFI load option
643 * @id: Load option number
645 * Dump information defined by UEFI load option.
647 static void show_efi_boot_opt(int id)
650 u16 var_name16[9], *p;
656 sprintf(var_name, "Boot%04X", id);
658 utf8_utf16_strncpy(&p, var_name, 9);
659 guid = efi_global_variable_guid;
662 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
663 if (ret == (int)EFI_BUFFER_TOO_SMALL) {
665 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
668 if (ret == EFI_SUCCESS)
669 show_efi_boot_opt_data(id, data);
670 else if (ret == EFI_NOT_FOUND)
671 printf("Boot%04X: not found\n", id);
677 * show_efi_boot_dump() - dump all UEFI load options
679 * @cmdtp: Command table
680 * @flag: Command flag
681 * @argc: Number of arguments
682 * @argv: Argument array
683 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
685 * Implement efidebug "boot dump" sub-command.
686 * Dump information of all UEFI load options defined.
689 static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag,
690 int argc, char * const argv[])
693 char * const regexlist[] = {regex};
694 char *variables = NULL, *boot, *value;
699 return CMD_RET_USAGE;
701 snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_Boot[0-9A-F]+");
703 /* TODO: use GetNextVariableName? */
704 len = hexport_r(&env_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY,
705 &variables, 0, 1, regexlist);
708 return CMD_RET_SUCCESS;
711 return CMD_RET_FAILURE;
715 value = strstr(boot, "Boot") + 4;
716 id = (int)simple_strtoul(value, NULL, 16);
717 show_efi_boot_opt(id);
718 boot = strchr(boot, '\n');
725 return CMD_RET_SUCCESS;
729 * show_efi_boot_order() - show order of UEFI load options
731 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
733 * Show order of UEFI load options defined by BootOrder variable.
735 static int show_efi_boot_order(void)
738 u16 *bootorder = NULL;
742 u16 var_name16[9], *p16;
744 struct efi_load_option lo;
746 size_t label_len16, label_len;
749 guid = efi_global_variable_guid;
751 ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL, &size,
753 if (ret == EFI_BUFFER_TOO_SMALL) {
754 bootorder = malloc(size);
755 ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL,
758 if (ret == EFI_NOT_FOUND) {
759 printf("BootOrder not defined\n");
760 ret = CMD_RET_SUCCESS;
762 } else if (ret != EFI_SUCCESS) {
763 ret = CMD_RET_FAILURE;
767 num = size / sizeof(u16);
768 for (i = 0; i < num; i++) {
769 sprintf(var_name, "Boot%04X", bootorder[i]);
771 utf8_utf16_strncpy(&p16, var_name, 9);
774 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
776 if (ret != EFI_BUFFER_TOO_SMALL) {
777 printf("%2d: Boot%04X: (not defined)\n",
778 i + 1, bootorder[i]);
784 ret = CMD_RET_FAILURE;
787 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
789 if (ret != EFI_SUCCESS) {
791 ret = CMD_RET_FAILURE;
795 efi_deserialize_load_option(&lo, data);
797 label_len16 = u16_strlen(lo.label);
798 label_len = utf16_utf8_strnlen(lo.label, label_len16);
799 label = malloc(label_len + 1);
802 ret = CMD_RET_FAILURE;
806 utf16_utf8_strncpy(&p, lo.label, label_len16);
807 printf("%2d: Boot%04X: %s\n", i + 1, bootorder[i], label);
819 * do_efi_boot_next() - manage UEFI BootNext variable
821 * @cmdtp: Command table
822 * @flag: Command flag
823 * @argc: Number of arguments
824 * @argv: Argument array
825 * Return: CMD_RET_SUCCESS on success,
826 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
828 * Implement efidebug "boot next" sub-command.
829 * Set BootNext variable.
832 static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag,
833 int argc, char * const argv[])
842 return CMD_RET_USAGE;
844 bootnext = (u16)simple_strtoul(argv[1], &endp, 16);
845 if (*endp != '\0' || bootnext > 0xffff) {
846 printf("invalid value: %s\n", argv[1]);
847 ret = CMD_RET_FAILURE;
851 guid = efi_global_variable_guid;
853 ret = EFI_CALL(RT->set_variable(L"BootNext", &guid,
854 EFI_VARIABLE_BOOTSERVICE_ACCESS |
855 EFI_VARIABLE_RUNTIME_ACCESS,
857 ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
863 * do_efi_boot_order() - manage UEFI BootOrder variable
865 * @cmdtp: Command table
866 * @flag: Command flag
867 * @argc: Number of arguments
868 * @argv: Argument array
869 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
871 * Implement efidebug "boot order" sub-command.
872 * Show order of UEFI load options, or change it in BootOrder variable.
873 * - boot order [<id> ...]
875 static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag,
876 int argc, char * const argv[])
878 u16 *bootorder = NULL;
886 return show_efi_boot_order();
891 size = argc * sizeof(u16);
892 bootorder = malloc(size);
894 return CMD_RET_FAILURE;
896 for (i = 0; i < argc; i++) {
897 id = (int)simple_strtoul(argv[i], &endp, 16);
898 if (*endp != '\0' || id > 0xffff) {
899 printf("invalid value: %s\n", argv[i]);
900 ret = CMD_RET_FAILURE;
904 bootorder[i] = (u16)id;
907 guid = efi_global_variable_guid;
908 ret = EFI_CALL(RT->set_variable(L"BootOrder", &guid,
909 EFI_VARIABLE_BOOTSERVICE_ACCESS |
910 EFI_VARIABLE_RUNTIME_ACCESS,
912 ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
919 static cmd_tbl_t cmd_efidebug_boot_sub[] = {
920 U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""),
921 U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""),
922 U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""),
923 U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""),
924 U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order,
929 * do_efi_boot_opt() - manage UEFI load options
931 * @cmdtp: Command table
932 * @flag: Command flag
933 * @argc: Number of arguments
934 * @argv: Argument array
935 * Return: CMD_RET_SUCCESS on success,
936 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
938 * Implement efidebug "boot" sub-command.
939 * See above for details of sub-commands.
941 static int do_efi_boot_opt(cmd_tbl_t *cmdtp, int flag,
942 int argc, char * const argv[])
947 return CMD_RET_USAGE;
951 cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub,
952 ARRAY_SIZE(cmd_efidebug_boot_sub));
954 return CMD_RET_USAGE;
956 return cp->cmd(cmdtp, flag, argc, argv);
959 static cmd_tbl_t cmd_efidebug_sub[] = {
960 U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
961 U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
963 U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
965 U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
967 U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
969 U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
974 * do_efidebug() - display and configure UEFI environment
976 * @cmdtp: Command table
977 * @flag: Command flag
978 * @argc: Number of arguments
979 * @argv: Argument array
980 * Return: CMD_RET_SUCCESS on success,
981 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
983 * Implement efidebug command which allows us to display and
984 * configure UEFI environment.
985 * See above for details of sub-commands.
987 static int do_efidebug(cmd_tbl_t *cmdtp, int flag,
988 int argc, char * const argv[])
994 return CMD_RET_USAGE;
998 /* Initialize UEFI drivers */
999 r = efi_init_obj_list();
1000 if (r != EFI_SUCCESS) {
1001 printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1002 r & ~EFI_ERROR_MASK);
1003 return CMD_RET_FAILURE;
1006 cp = find_cmd_tbl(argv[0], cmd_efidebug_sub,
1007 ARRAY_SIZE(cmd_efidebug_sub));
1009 return CMD_RET_USAGE;
1011 return cp->cmd(cmdtp, flag, argc, argv);
1014 #ifdef CONFIG_SYS_LONGHELP
1015 static char efidebug_help_text[] =
1016 " - UEFI Shell-like interface to configure UEFI environment\n"
1018 "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>]\n"
1019 " - set UEFI BootXXXX variable\n"
1020 " <load options> will be passed to UEFI application\n"
1021 "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
1022 " - delete UEFI BootXXXX variables\n"
1023 "efidebug boot dump\n"
1024 " - dump all UEFI BootXXXX variables\n"
1025 "efidebug boot next <bootid>\n"
1026 " - set UEFI BootNext variable\n"
1027 "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
1028 " - set/show UEFI boot order\n"
1030 "efidebug devices\n"
1031 " - show uefi devices\n"
1032 "efidebug drivers\n"
1033 " - show uefi drivers\n"
1035 " - show uefi handles\n"
1037 " - show loaded images\n"
1039 " - show uefi memory map\n";
1043 efidebug, 10, 0, do_efidebug,
1044 "Configure UEFI environment",