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;
188 EFI_DEVICE_PATH_PROTOCOL_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,
220 EFI_BLOCK_IO_PROTOCOL_GUID,
223 "Simple File System",
224 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
228 EFI_LOADED_IMAGE_PROTOCOL_GUID,
232 EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
236 EFI_HII_STRING_PROTOCOL_GUID,
240 EFI_HII_DATABASE_PROTOCOL_GUID,
243 "HII Config Routing",
244 EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID,
248 EFI_SIMPLE_NETWORK_PROTOCOL_GUID,
252 EFI_PXE_BASE_CODE_PROTOCOL_GUID,
257 * get_guid_text - get string of protocol guid
258 * @guid: Protocol guid
261 * Return string for display to represent the protocol.
263 static const char *get_guid_text(const efi_guid_t *guid)
267 for (i = 0; i < ARRAY_SIZE(guid_list); i++)
268 if (!guidcmp(&guid_list[i].guid, guid))
271 if (i != ARRAY_SIZE(guid_list))
272 return guid_list[i].text;
278 * do_efi_show_handles() - show UEFI handles
280 * @cmdtp: Command table
281 * @flag: Command flag
282 * @argc: Number of arguments
283 * @argv: Argument array
284 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
286 * Implement efidebug "dh" sub-command.
287 * Show all UEFI handles and their information, currently all protocols
290 static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag,
291 int argc, char * const argv[])
293 efi_handle_t *handles;
295 efi_uintn_t num, count, i, j;
296 const char *guid_text;
299 ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL,
301 if (ret != EFI_SUCCESS)
302 return CMD_RET_FAILURE;
305 return CMD_RET_SUCCESS;
307 printf("Handle%.*s Protocols\n", EFI_HANDLE_WIDTH - 6, spc);
308 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
309 for (i = 0; i < num; i++) {
310 printf("%p", handles[i]);
311 ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid,
318 for (j = 0; j < count; j++) {
324 guid_text = get_guid_text(guid[j]);
328 printf("%pUl", guid[j]);
333 EFI_CALL(BS->free_pool(handles));
335 return CMD_RET_SUCCESS;
339 * do_efi_show_images() - show UEFI images
341 * @cmdtp: Command table
342 * @flag: Command flag
343 * @argc: Number of arguments
344 * @argv: Argument array
345 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
347 * Implement efidebug "images" sub-command.
348 * Show all UEFI loaded images and their information.
350 static int do_efi_show_images(cmd_tbl_t *cmdtp, int flag,
351 int argc, char * const argv[])
353 efi_print_image_infos(NULL);
355 return CMD_RET_SUCCESS;
358 static const char * const efi_mem_type_string[] = {
359 [EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
360 [EFI_LOADER_CODE] = "LOADER CODE",
361 [EFI_LOADER_DATA] = "LOADER DATA",
362 [EFI_BOOT_SERVICES_CODE] = "BOOT CODE",
363 [EFI_BOOT_SERVICES_DATA] = "BOOT DATA",
364 [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE",
365 [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA",
366 [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL",
367 [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM",
368 [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM",
369 [EFI_ACPI_MEMORY_NVS] = "ACPI NVS",
370 [EFI_MMAP_IO] = "IO",
371 [EFI_MMAP_IO_PORT] = "IO PORT",
372 [EFI_PAL_CODE] = "PAL",
375 static const struct efi_mem_attrs {
378 } efi_mem_attrs[] = {
379 {EFI_MEMORY_UC, "UC"},
380 {EFI_MEMORY_UC, "UC"},
381 {EFI_MEMORY_WC, "WC"},
382 {EFI_MEMORY_WT, "WT"},
383 {EFI_MEMORY_WB, "WB"},
384 {EFI_MEMORY_UCE, "UCE"},
385 {EFI_MEMORY_WP, "WP"},
386 {EFI_MEMORY_RP, "RP"},
387 {EFI_MEMORY_XP, "WP"},
388 {EFI_MEMORY_NV, "NV"},
389 {EFI_MEMORY_MORE_RELIABLE, "REL"},
390 {EFI_MEMORY_RO, "RO"},
391 {EFI_MEMORY_RUNTIME, "RT"},
395 * print_memory_attributes() - print memory map attributes
396 * @attributes: Attribute value
398 * Print memory map attributes
400 static void print_memory_attributes(u64 attributes)
404 for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++)
405 if (attributes & efi_mem_attrs[i].bit) {
412 puts(efi_mem_attrs[i].text);
416 #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
419 * do_efi_show_memmap() - show UEFI memory map
421 * @cmdtp: Command table
422 * @flag: Command flag
423 * @argc: Number of arguments
424 * @argv: Argument array
425 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
427 * Implement efidebug "memmap" sub-command.
428 * Show UEFI memory map.
430 static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag,
431 int argc, char * const argv[])
433 struct efi_mem_desc *memmap = NULL, *map;
434 efi_uintn_t map_size = 0;
439 ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL, NULL, NULL));
440 if (ret == EFI_BUFFER_TOO_SMALL) {
441 map_size += sizeof(struct efi_mem_desc); /* for my own */
442 ret = EFI_CALL(BS->allocate_pool(EFI_LOADER_DATA,
443 map_size, (void *)&memmap));
444 if (ret != EFI_SUCCESS)
445 return CMD_RET_FAILURE;
446 ret = EFI_CALL(BS->get_memory_map(&map_size, memmap,
449 if (ret != EFI_SUCCESS) {
450 EFI_CALL(BS->free_pool(memmap));
451 return CMD_RET_FAILURE;
454 printf("Type Start%.*s End%.*s Attributes\n",
455 EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
456 printf("================ %.*s %.*s ==========\n",
457 EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
458 for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
459 if (map->type < EFI_MAX_MEMORY_TYPE)
460 type = efi_mem_type_string[map->type];
464 printf("%-16s %.*llx-%.*llx", type,
468 map->physical_start + map->num_pages * EFI_PAGE_SIZE);
470 print_memory_attributes(map->attribute);
474 EFI_CALL(BS->free_pool(memmap));
476 return CMD_RET_SUCCESS;
480 * do_efi_boot_add() - set UEFI load option
482 * @cmdtp: Command table
483 * @flag: Command flag
484 * @argc: Number of arguments
485 * @argv: Argument array
486 * Return: CMD_RET_SUCCESS on success,
487 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
489 * Implement efidebug "boot add" sub-command.
490 * Create or change UEFI load option.
491 * - boot add <id> <label> <interface> <devnum>[:<part>] <file> <options>
493 static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag,
494 int argc, char * const argv[])
499 u16 var_name16[9], *p;
501 size_t label_len, label_len16;
503 struct efi_device_path *device_path = NULL, *file_path = NULL;
504 struct efi_load_option lo;
509 if (argc < 6 || argc > 7)
510 return CMD_RET_USAGE;
512 id = (int)simple_strtoul(argv[1], &endp, 16);
513 if (*endp != '\0' || id > 0xffff)
514 return CMD_RET_USAGE;
516 sprintf(var_name, "Boot%04X", id);
518 utf8_utf16_strncpy(&p, var_name, 9);
520 guid = efi_global_variable_guid;
523 lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
526 label_len = strlen(argv[2]);
527 label_len16 = utf8_utf16_strnlen(argv[2], label_len);
528 label = malloc((label_len16 + 1) * sizeof(u16));
530 return CMD_RET_FAILURE;
531 lo.label = label; /* label will be changed below */
532 utf8_utf16_strncpy(&label, argv[2], label_len);
535 ret = efi_dp_from_name(argv[3], argv[4], argv[5], &device_path,
537 if (ret != EFI_SUCCESS) {
538 printf("Cannot create device path for \"%s %s\"\n",
540 ret = CMD_RET_FAILURE;
543 lo.file_path = file_path;
544 lo.file_path_length = efi_dp_size(file_path)
545 + sizeof(struct efi_device_path); /* for END */
548 lo.optional_data = (u8 *)(argc == 6 ? "" : argv[6]);
550 size = efi_serialize_load_option(&lo, (u8 **)&data);
552 ret = CMD_RET_FAILURE;
556 ret = EFI_CALL(RT->set_variable(var_name16, &guid,
557 EFI_VARIABLE_BOOTSERVICE_ACCESS |
558 EFI_VARIABLE_RUNTIME_ACCESS,
560 ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
563 efi_free_pool(device_path);
564 efi_free_pool(file_path);
571 * do_efi_boot_rm() - delete UEFI load options
573 * @cmdtp: Command table
574 * @flag: Command flag
575 * @argc: Number of arguments
576 * @argv: Argument array
577 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
579 * Implement efidebug "boot rm" sub-command.
580 * Delete UEFI load options.
583 static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,
584 int argc, char * const argv[])
594 return CMD_RET_USAGE;
596 guid = efi_global_variable_guid;
597 for (i = 1; i < argc; i++, argv++) {
598 id = (int)simple_strtoul(argv[1], &endp, 16);
599 if (*endp != '\0' || id > 0xffff)
600 return CMD_RET_FAILURE;
602 sprintf(var_name, "Boot%04X", id);
603 utf8_utf16_strncpy((u16 **)&var_name16, var_name, 9);
605 ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL));
607 printf("cannot remove Boot%04X", id);
608 return CMD_RET_FAILURE;
612 return CMD_RET_SUCCESS;
616 * show_efi_boot_opt_data() - dump UEFI load option
618 * @id: Load option number
619 * @data: Value of UEFI load option variable
621 * Decode the value of UEFI load option variable and print information.
623 static void show_efi_boot_opt_data(int id, void *data)
625 struct efi_load_option lo;
627 size_t label_len16, label_len;
630 efi_deserialize_load_option(&lo, data);
632 label_len16 = u16_strlen(lo.label);
633 label_len = utf16_utf8_strnlen(lo.label, label_len16);
634 label = malloc(label_len + 1);
638 utf16_utf8_strncpy(&p, lo.label, label_len16);
640 printf("Boot%04X:\n", id);
641 printf("\tattributes: %c%c%c (0x%08x)\n",
643 lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
644 /* FORCE RECONNECT */
645 lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-',
647 lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
649 printf("\tlabel: %s\n", label);
651 dp_str = efi_dp_str(lo.file_path);
652 printf("\tfile_path: %ls\n", dp_str);
653 efi_free_pool(dp_str);
655 printf("\tdata: %s\n", lo.optional_data);
661 * show_efi_boot_opt() - dump UEFI load option
663 * @id: Load option number
665 * Dump information defined by UEFI load option.
667 static void show_efi_boot_opt(int id)
670 u16 var_name16[9], *p;
676 sprintf(var_name, "Boot%04X", id);
678 utf8_utf16_strncpy(&p, var_name, 9);
679 guid = efi_global_variable_guid;
682 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
683 if (ret == (int)EFI_BUFFER_TOO_SMALL) {
685 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
688 if (ret == EFI_SUCCESS)
689 show_efi_boot_opt_data(id, data);
690 else if (ret == EFI_NOT_FOUND)
691 printf("Boot%04X: not found\n", id);
697 * show_efi_boot_dump() - dump all UEFI load options
699 * @cmdtp: Command table
700 * @flag: Command flag
701 * @argc: Number of arguments
702 * @argv: Argument array
703 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
705 * Implement efidebug "boot dump" sub-command.
706 * Dump information of all UEFI load options defined.
709 static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag,
710 int argc, char * const argv[])
713 char * const regexlist[] = {regex};
714 char *variables = NULL, *boot, *value;
719 return CMD_RET_USAGE;
721 snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_Boot[0-9A-F]+");
723 /* TODO: use GetNextVariableName? */
724 len = hexport_r(&env_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY,
725 &variables, 0, 1, regexlist);
728 return CMD_RET_SUCCESS;
731 return CMD_RET_FAILURE;
735 value = strstr(boot, "Boot") + 4;
736 id = (int)simple_strtoul(value, NULL, 16);
737 show_efi_boot_opt(id);
738 boot = strchr(boot, '\n');
745 return CMD_RET_SUCCESS;
749 * show_efi_boot_order() - show order of UEFI load options
751 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
753 * Show order of UEFI load options defined by BootOrder variable.
755 static int show_efi_boot_order(void)
758 u16 *bootorder = NULL;
762 u16 var_name16[9], *p16;
764 struct efi_load_option lo;
766 size_t label_len16, label_len;
769 guid = efi_global_variable_guid;
771 ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL, &size,
773 if (ret == EFI_BUFFER_TOO_SMALL) {
774 bootorder = malloc(size);
775 ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL,
778 if (ret == EFI_NOT_FOUND) {
779 printf("BootOrder not defined\n");
780 ret = CMD_RET_SUCCESS;
782 } else if (ret != EFI_SUCCESS) {
783 ret = CMD_RET_FAILURE;
787 num = size / sizeof(u16);
788 for (i = 0; i < num; i++) {
789 sprintf(var_name, "Boot%04X", bootorder[i]);
791 utf8_utf16_strncpy(&p16, var_name, 9);
794 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
796 if (ret != EFI_BUFFER_TOO_SMALL) {
797 printf("%2d: Boot%04X: (not defined)\n",
798 i + 1, bootorder[i]);
804 ret = CMD_RET_FAILURE;
807 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
809 if (ret != EFI_SUCCESS) {
811 ret = CMD_RET_FAILURE;
815 efi_deserialize_load_option(&lo, data);
817 label_len16 = u16_strlen(lo.label);
818 label_len = utf16_utf8_strnlen(lo.label, label_len16);
819 label = malloc(label_len + 1);
822 ret = CMD_RET_FAILURE;
826 utf16_utf8_strncpy(&p, lo.label, label_len16);
827 printf("%2d: Boot%04X: %s\n", i + 1, bootorder[i], label);
839 * do_efi_boot_next() - manage UEFI BootNext variable
841 * @cmdtp: Command table
842 * @flag: Command flag
843 * @argc: Number of arguments
844 * @argv: Argument array
845 * Return: CMD_RET_SUCCESS on success,
846 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
848 * Implement efidebug "boot next" sub-command.
849 * Set BootNext variable.
852 static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag,
853 int argc, char * const argv[])
862 return CMD_RET_USAGE;
864 bootnext = (u16)simple_strtoul(argv[1], &endp, 16);
865 if (*endp != '\0' || bootnext > 0xffff) {
866 printf("invalid value: %s\n", argv[1]);
867 ret = CMD_RET_FAILURE;
871 guid = efi_global_variable_guid;
873 ret = EFI_CALL(RT->set_variable(L"BootNext", &guid,
874 EFI_VARIABLE_BOOTSERVICE_ACCESS |
875 EFI_VARIABLE_RUNTIME_ACCESS,
877 ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
883 * do_efi_boot_order() - manage UEFI BootOrder variable
885 * @cmdtp: Command table
886 * @flag: Command flag
887 * @argc: Number of arguments
888 * @argv: Argument array
889 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
891 * Implement efidebug "boot order" sub-command.
892 * Show order of UEFI load options, or change it in BootOrder variable.
893 * - boot order [<id> ...]
895 static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag,
896 int argc, char * const argv[])
898 u16 *bootorder = NULL;
906 return show_efi_boot_order();
911 size = argc * sizeof(u16);
912 bootorder = malloc(size);
914 return CMD_RET_FAILURE;
916 for (i = 0; i < argc; i++) {
917 id = (int)simple_strtoul(argv[i], &endp, 16);
918 if (*endp != '\0' || id > 0xffff) {
919 printf("invalid value: %s\n", argv[i]);
920 ret = CMD_RET_FAILURE;
924 bootorder[i] = (u16)id;
927 guid = efi_global_variable_guid;
928 ret = EFI_CALL(RT->set_variable(L"BootOrder", &guid,
929 EFI_VARIABLE_BOOTSERVICE_ACCESS |
930 EFI_VARIABLE_RUNTIME_ACCESS,
932 ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
939 static cmd_tbl_t cmd_efidebug_boot_sub[] = {
940 U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""),
941 U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""),
942 U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""),
943 U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""),
944 U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order,
949 * do_efi_boot_opt() - manage UEFI load options
951 * @cmdtp: Command table
952 * @flag: Command flag
953 * @argc: Number of arguments
954 * @argv: Argument array
955 * Return: CMD_RET_SUCCESS on success,
956 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
958 * Implement efidebug "boot" sub-command.
959 * See above for details of sub-commands.
961 static int do_efi_boot_opt(cmd_tbl_t *cmdtp, int flag,
962 int argc, char * const argv[])
967 return CMD_RET_USAGE;
971 cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub,
972 ARRAY_SIZE(cmd_efidebug_boot_sub));
974 return CMD_RET_USAGE;
976 return cp->cmd(cmdtp, flag, argc, argv);
979 static cmd_tbl_t cmd_efidebug_sub[] = {
980 U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
981 U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
983 U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
985 U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
987 U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
989 U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
994 * do_efidebug() - display and configure UEFI environment
996 * @cmdtp: Command table
997 * @flag: Command flag
998 * @argc: Number of arguments
999 * @argv: Argument array
1000 * Return: CMD_RET_SUCCESS on success,
1001 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1003 * Implement efidebug command which allows us to display and
1004 * configure UEFI environment.
1005 * See above for details of sub-commands.
1007 static int do_efidebug(cmd_tbl_t *cmdtp, int flag,
1008 int argc, char * const argv[])
1014 return CMD_RET_USAGE;
1018 /* Initialize UEFI drivers */
1019 r = efi_init_obj_list();
1020 if (r != EFI_SUCCESS) {
1021 printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1022 r & ~EFI_ERROR_MASK);
1023 return CMD_RET_FAILURE;
1026 cp = find_cmd_tbl(argv[0], cmd_efidebug_sub,
1027 ARRAY_SIZE(cmd_efidebug_sub));
1029 return CMD_RET_USAGE;
1031 return cp->cmd(cmdtp, flag, argc, argv);
1034 #ifdef CONFIG_SYS_LONGHELP
1035 static char efidebug_help_text[] =
1036 " - UEFI Shell-like interface to configure UEFI environment\n"
1038 "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>]\n"
1039 " - set UEFI BootXXXX variable\n"
1040 " <load options> will be passed to UEFI application\n"
1041 "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
1042 " - delete UEFI BootXXXX variables\n"
1043 "efidebug boot dump\n"
1044 " - dump all UEFI BootXXXX variables\n"
1045 "efidebug boot next <bootid>\n"
1046 " - set UEFI BootNext variable\n"
1047 "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
1048 " - set/show UEFI boot order\n"
1050 "efidebug devices\n"
1051 " - show uefi devices\n"
1052 "efidebug drivers\n"
1053 " - show uefi drivers\n"
1055 " - show uefi handles\n"
1057 " - show loaded images\n"
1059 " - show uefi memory map\n";
1063 efidebug, 10, 0, do_efidebug,
1064 "Configure UEFI environment",