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>
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
397 * @attributes: Attribute value
399 * Print memory map attributes
401 static void print_memory_attributes(u64 attributes)
405 for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++)
406 if (attributes & efi_mem_attrs[i].bit) {
413 puts(efi_mem_attrs[i].text);
417 #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
420 * do_efi_show_memmap() - show UEFI memory map
422 * @cmdtp: Command table
423 * @flag: Command flag
424 * @argc: Number of arguments
425 * @argv: Argument array
426 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
428 * Implement efidebug "memmap" sub-command.
429 * Show UEFI memory map.
431 static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag,
432 int argc, char * const argv[])
434 struct efi_mem_desc *memmap = NULL, *map;
435 efi_uintn_t map_size = 0;
440 ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL, NULL, NULL));
441 if (ret == EFI_BUFFER_TOO_SMALL) {
442 map_size += sizeof(struct efi_mem_desc); /* for my own */
443 ret = EFI_CALL(BS->allocate_pool(EFI_LOADER_DATA,
444 map_size, (void *)&memmap));
445 if (ret != EFI_SUCCESS)
446 return CMD_RET_FAILURE;
447 ret = EFI_CALL(BS->get_memory_map(&map_size, memmap,
450 if (ret != EFI_SUCCESS) {
451 EFI_CALL(BS->free_pool(memmap));
452 return CMD_RET_FAILURE;
455 printf("Type Start%.*s End%.*s Attributes\n",
456 EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
457 printf("================ %.*s %.*s ==========\n",
458 EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
459 for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
460 if (map->type < EFI_MAX_MEMORY_TYPE)
461 type = efi_mem_type_string[map->type];
465 printf("%-16s %.*llx-%.*llx", type,
469 map->physical_start + map->num_pages * EFI_PAGE_SIZE);
471 print_memory_attributes(map->attribute);
475 EFI_CALL(BS->free_pool(memmap));
477 return CMD_RET_SUCCESS;
481 * do_efi_boot_add() - set UEFI load option
483 * @cmdtp: Command table
484 * @flag: Command flag
485 * @argc: Number of arguments
486 * @argv: Argument array
487 * Return: CMD_RET_SUCCESS on success,
488 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
490 * Implement efidebug "boot add" sub-command. Create or change UEFI load option.
492 * efidebug boot add <id> <label> <interface> <devnum>[:<part>] <file> <options>
494 static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag,
495 int argc, char * const argv[])
500 u16 var_name16[9], *p;
502 size_t label_len, label_len16;
504 struct efi_device_path *device_path = NULL, *file_path = NULL;
505 struct efi_load_option lo;
509 int r = CMD_RET_SUCCESS;
511 if (argc < 6 || argc > 7)
512 return CMD_RET_USAGE;
514 id = (int)simple_strtoul(argv[1], &endp, 16);
515 if (*endp != '\0' || id > 0xffff)
516 return CMD_RET_USAGE;
518 sprintf(var_name, "Boot%04X", id);
520 utf8_utf16_strncpy(&p, var_name, 9);
522 guid = efi_global_variable_guid;
525 lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
528 label_len = strlen(argv[2]);
529 label_len16 = utf8_utf16_strnlen(argv[2], label_len);
530 label = malloc((label_len16 + 1) * sizeof(u16));
532 return CMD_RET_FAILURE;
533 lo.label = label; /* label will be changed below */
534 utf8_utf16_strncpy(&label, argv[2], label_len);
537 ret = efi_dp_from_name(argv[3], argv[4], argv[5], &device_path,
539 if (ret != EFI_SUCCESS) {
540 printf("Cannot create device path for \"%s %s\"\n",
545 lo.file_path = file_path;
546 lo.file_path_length = efi_dp_size(file_path)
547 + sizeof(struct efi_device_path); /* for END */
551 lo.optional_data = NULL;
553 lo.optional_data = (const u8 *)argv[6];
555 size = efi_serialize_load_option(&lo, (u8 **)&data);
561 ret = EFI_CALL(RT->set_variable(var_name16, &guid,
562 EFI_VARIABLE_NON_VOLATILE |
563 EFI_VARIABLE_BOOTSERVICE_ACCESS |
564 EFI_VARIABLE_RUNTIME_ACCESS,
566 if (ret != EFI_SUCCESS) {
567 printf("Cannot set %ls\n", var_name16);
572 efi_free_pool(device_path);
573 efi_free_pool(file_path);
580 * do_efi_boot_rm() - delete UEFI load options
582 * @cmdtp: Command table
583 * @flag: Command flag
584 * @argc: Number of arguments
585 * @argv: Argument array
586 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
588 * Implement efidebug "boot rm" sub-command.
589 * Delete UEFI load options.
591 * efidebug boot rm <id> ...
593 static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,
594 int argc, char * const argv[])
604 return CMD_RET_USAGE;
606 guid = efi_global_variable_guid;
607 for (i = 1; i < argc; i++, argv++) {
608 id = (int)simple_strtoul(argv[1], &endp, 16);
609 if (*endp != '\0' || id > 0xffff)
610 return CMD_RET_FAILURE;
612 sprintf(var_name, "Boot%04X", id);
613 utf8_utf16_strncpy((u16 **)&var_name16, var_name, 9);
615 ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL));
617 printf("Cannot remove Boot%04X", id);
618 return CMD_RET_FAILURE;
622 return CMD_RET_SUCCESS;
626 * show_efi_boot_opt_data() - dump UEFI load option
628 * @id: load option number
629 * @data: value of UEFI load option variable
630 * @size: size of the boot option
632 * Decode the value of UEFI load option variable and print information.
634 static void show_efi_boot_opt_data(int id, void *data, size_t size)
636 struct efi_load_option lo;
638 size_t label_len16, label_len;
641 efi_deserialize_load_option(&lo, data);
643 label_len16 = u16_strlen(lo.label);
644 label_len = utf16_utf8_strnlen(lo.label, label_len16);
645 label = malloc(label_len + 1);
649 utf16_utf8_strncpy(&p, lo.label, label_len16);
651 printf("Boot%04X:\n", id);
652 printf(" attributes: %c%c%c (0x%08x)\n",
654 lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
655 /* FORCE RECONNECT */
656 lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-',
658 lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
660 printf(" label: %s\n", label);
662 dp_str = efi_dp_str(lo.file_path);
663 printf(" file_path: %ls\n", dp_str);
664 efi_free_pool(dp_str);
667 print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
668 lo.optional_data, size + (u8 *)data -
669 (u8 *)lo.optional_data, true);
674 * show_efi_boot_opt() - dump UEFI load option
676 * @id: Load option number
678 * Dump information defined by UEFI load option.
680 static void show_efi_boot_opt(int id)
683 u16 var_name16[9], *p;
689 sprintf(var_name, "Boot%04X", id);
691 utf8_utf16_strncpy(&p, var_name, 9);
692 guid = efi_global_variable_guid;
695 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
696 if (ret == (int)EFI_BUFFER_TOO_SMALL) {
698 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
701 if (ret == EFI_SUCCESS)
702 show_efi_boot_opt_data(id, data, size);
703 else if (ret == EFI_NOT_FOUND)
704 printf("Boot%04X: not found\n", id);
709 static int u16_tohex(u16 c)
711 if (c >= '0' && c <= '9')
713 if (c >= 'A' && c <= 'F')
716 /* not hexadecimal */
721 * show_efi_boot_dump() - dump all UEFI load options
723 * @cmdtp: Command table
724 * @flag: Command flag
725 * @argc: Number of arguments
726 * @argv: Argument array
727 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
729 * Implement efidebug "boot dump" sub-command.
730 * Dump information of all UEFI load options defined.
734 static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag,
735 int argc, char * const argv[])
738 efi_uintn_t buf_size, size;
744 return CMD_RET_USAGE;
747 var_name16 = malloc(buf_size);
749 return CMD_RET_FAILURE;
754 ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16,
756 if (ret == EFI_NOT_FOUND)
758 if (ret == EFI_BUFFER_TOO_SMALL) {
760 p = realloc(var_name16, buf_size);
763 return CMD_RET_FAILURE;
766 ret = EFI_CALL(efi_get_next_variable_name(&size,
770 if (ret != EFI_SUCCESS) {
772 return CMD_RET_FAILURE;
775 if (memcmp(var_name16, L"Boot", 8))
778 for (id = 0, i = 0; i < 4; i++) {
779 digit = u16_tohex(var_name16[4 + i]);
782 id = (id << 4) + digit;
784 if (i == 4 && !var_name16[8])
785 show_efi_boot_opt(id);
790 return CMD_RET_SUCCESS;
794 * show_efi_boot_order() - show order of UEFI load options
796 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
798 * Show order of UEFI load options defined by BootOrder variable.
800 static int show_efi_boot_order(void)
803 u16 *bootorder = NULL;
807 u16 var_name16[9], *p16;
809 struct efi_load_option lo;
811 size_t label_len16, label_len;
814 guid = efi_global_variable_guid;
816 ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL, &size,
818 if (ret == EFI_BUFFER_TOO_SMALL) {
819 bootorder = malloc(size);
820 ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL,
823 if (ret == EFI_NOT_FOUND) {
824 printf("BootOrder not defined\n");
825 ret = CMD_RET_SUCCESS;
827 } else if (ret != EFI_SUCCESS) {
828 ret = CMD_RET_FAILURE;
832 num = size / sizeof(u16);
833 for (i = 0; i < num; i++) {
834 sprintf(var_name, "Boot%04X", bootorder[i]);
836 utf8_utf16_strncpy(&p16, var_name, 9);
839 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
841 if (ret != EFI_BUFFER_TOO_SMALL) {
842 printf("%2d: Boot%04X: (not defined)\n",
843 i + 1, bootorder[i]);
849 ret = CMD_RET_FAILURE;
852 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
854 if (ret != EFI_SUCCESS) {
856 ret = CMD_RET_FAILURE;
860 efi_deserialize_load_option(&lo, data);
862 label_len16 = u16_strlen(lo.label);
863 label_len = utf16_utf8_strnlen(lo.label, label_len16);
864 label = malloc(label_len + 1);
867 ret = CMD_RET_FAILURE;
871 utf16_utf8_strncpy(&p, lo.label, label_len16);
872 printf("%2d: Boot%04X: %s\n", i + 1, bootorder[i], label);
884 * do_efi_boot_next() - manage UEFI BootNext variable
886 * @cmdtp: Command table
887 * @flag: Command flag
888 * @argc: Number of arguments
889 * @argv: Argument array
890 * Return: CMD_RET_SUCCESS on success,
891 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
893 * Implement efidebug "boot next" sub-command.
894 * Set BootNext variable.
896 * efidebug boot next <id>
898 static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag,
899 int argc, char * const argv[])
906 int r = CMD_RET_SUCCESS;
909 return CMD_RET_USAGE;
911 bootnext = (u16)simple_strtoul(argv[1], &endp, 16);
912 if (*endp != '\0' || bootnext > 0xffff) {
913 printf("invalid value: %s\n", argv[1]);
918 guid = efi_global_variable_guid;
920 ret = EFI_CALL(RT->set_variable(L"BootNext", &guid,
921 EFI_VARIABLE_NON_VOLATILE |
922 EFI_VARIABLE_BOOTSERVICE_ACCESS |
923 EFI_VARIABLE_RUNTIME_ACCESS,
925 if (ret != EFI_SUCCESS) {
926 printf("Cannot set BootNext\n");
934 * do_efi_boot_order() - manage UEFI BootOrder variable
936 * @cmdtp: Command table
937 * @flag: Command flag
938 * @argc: Number of arguments
939 * @argv: Argument array
940 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
942 * Implement efidebug "boot order" sub-command.
943 * Show order of UEFI load options, or change it in BootOrder variable.
945 * efidebug boot order [<id> ...]
947 static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag,
948 int argc, char * const argv[])
950 u16 *bootorder = NULL;
956 int r = CMD_RET_SUCCESS;
959 return show_efi_boot_order();
964 size = argc * sizeof(u16);
965 bootorder = malloc(size);
967 return CMD_RET_FAILURE;
969 for (i = 0; i < argc; i++) {
970 id = (int)simple_strtoul(argv[i], &endp, 16);
971 if (*endp != '\0' || id > 0xffff) {
972 printf("invalid value: %s\n", argv[i]);
977 bootorder[i] = (u16)id;
980 guid = efi_global_variable_guid;
981 ret = EFI_CALL(RT->set_variable(L"BootOrder", &guid,
982 EFI_VARIABLE_NON_VOLATILE |
983 EFI_VARIABLE_BOOTSERVICE_ACCESS |
984 EFI_VARIABLE_RUNTIME_ACCESS,
986 if (ret != EFI_SUCCESS) {
987 printf("Cannot set BootOrder\n");
996 static cmd_tbl_t cmd_efidebug_boot_sub[] = {
997 U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""),
998 U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""),
999 U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""),
1000 U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""),
1001 U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order,
1006 * do_efi_boot_opt() - manage UEFI load options
1008 * @cmdtp: Command table
1009 * @flag: Command flag
1010 * @argc: Number of arguments
1011 * @argv: Argument array
1012 * Return: CMD_RET_SUCCESS on success,
1013 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1015 * Implement efidebug "boot" sub-command.
1017 static int do_efi_boot_opt(cmd_tbl_t *cmdtp, int flag,
1018 int argc, char * const argv[])
1023 return CMD_RET_USAGE;
1027 cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub,
1028 ARRAY_SIZE(cmd_efidebug_boot_sub));
1030 return CMD_RET_USAGE;
1032 return cp->cmd(cmdtp, flag, argc, argv);
1035 static cmd_tbl_t cmd_efidebug_sub[] = {
1036 U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
1037 U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
1039 U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
1041 U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
1043 U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
1045 U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
1050 * do_efidebug() - display and configure UEFI environment
1052 * @cmdtp: Command table
1053 * @flag: Command flag
1054 * @argc: Number of arguments
1055 * @argv: Argument array
1056 * Return: CMD_RET_SUCCESS on success,
1057 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1059 * Implement efidebug command which allows us to display and
1060 * configure UEFI environment.
1062 static int do_efidebug(cmd_tbl_t *cmdtp, int flag,
1063 int argc, char * const argv[])
1069 return CMD_RET_USAGE;
1073 /* Initialize UEFI drivers */
1074 r = efi_init_obj_list();
1075 if (r != EFI_SUCCESS) {
1076 printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1077 r & ~EFI_ERROR_MASK);
1078 return CMD_RET_FAILURE;
1081 cp = find_cmd_tbl(argv[0], cmd_efidebug_sub,
1082 ARRAY_SIZE(cmd_efidebug_sub));
1084 return CMD_RET_USAGE;
1086 return cp->cmd(cmdtp, flag, argc, argv);
1089 #ifdef CONFIG_SYS_LONGHELP
1090 static char efidebug_help_text[] =
1091 " - UEFI Shell-like interface to configure UEFI environment\n"
1093 "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>]\n"
1094 " - set UEFI BootXXXX variable\n"
1095 " <load options> will be passed to UEFI application\n"
1096 "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
1097 " - delete UEFI BootXXXX variables\n"
1098 "efidebug boot dump\n"
1099 " - dump all UEFI BootXXXX variables\n"
1100 "efidebug boot next <bootid>\n"
1101 " - set UEFI BootNext variable\n"
1102 "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
1103 " - set/show UEFI boot order\n"
1105 "efidebug devices\n"
1106 " - show uefi devices\n"
1107 "efidebug drivers\n"
1108 " - show uefi drivers\n"
1110 " - show uefi handles\n"
1112 " - show loaded images\n"
1114 " - show uefi memory map\n";
1118 efidebug, 10, 0, do_efidebug,
1119 "Configure UEFI environment",