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>
17 #include <linux/ctype.h>
19 #define BS systab.boottime
20 #define RT systab.runtime
23 * efi_get_device_handle_info() - get information of UEFI device
25 * @handle: Handle of UEFI device
26 * @dev_path_text: Pointer to text of device path
27 * Return: 0 on success, -1 on failure
29 * Currently return a formatted text of device path.
31 static int efi_get_device_handle_info(efi_handle_t handle
, u16
**dev_path_text
)
33 struct efi_device_path
*dp
;
36 ret
= EFI_CALL(BS
->open_protocol(handle
, &efi_guid_device_path
,
37 (void **)&dp
, NULL
/* FIXME */, NULL
,
38 EFI_OPEN_PROTOCOL_GET_PROTOCOL
));
39 if (ret
== EFI_SUCCESS
) {
40 *dev_path_text
= efi_dp_str(dp
);
47 #define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2)
49 static const char spc
[] = " ";
50 static const char sep
[] = "================";
53 * do_efi_show_devices() - show UEFI devices
55 * @cmdtp: Command table
57 * @argc: Number of arguments
58 * @argv: Argument array
59 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
61 * Implement efidebug "devices" sub-command.
62 * Show all UEFI devices and their information.
64 static int do_efi_show_devices(cmd_tbl_t
*cmdtp
, int flag
,
65 int argc
, char * const argv
[])
67 efi_handle_t
*handles
;
72 ret
= EFI_CALL(BS
->locate_handle_buffer(ALL_HANDLES
, NULL
, NULL
,
74 if (ret
!= EFI_SUCCESS
)
75 return CMD_RET_FAILURE
;
78 return CMD_RET_SUCCESS
;
80 printf("Device%.*s Device Path\n", EFI_HANDLE_WIDTH
- 6, spc
);
81 printf("%.*s ====================\n", EFI_HANDLE_WIDTH
, sep
);
82 for (i
= 0; i
< num
; i
++) {
83 if (!efi_get_device_handle_info(handles
[i
], &dev_path_text
)) {
84 printf("%p %ls\n", handles
[i
], dev_path_text
);
85 efi_free_pool(dev_path_text
);
89 EFI_CALL(BS
->free_pool(handles
));
91 return CMD_RET_SUCCESS
;
95 * efi_get_driver_handle_info() - get information of UEFI driver
97 * @handle: Handle of UEFI device
98 * @driver_name: Driver name
99 * @image_path: Pointer to text of device path
100 * Return: 0 on success, -1 on failure
102 * Currently return no useful information as all UEFI drivers are
105 static int efi_get_driver_handle_info(efi_handle_t handle
, u16
**driver_name
,
108 struct efi_handler
*handler
;
109 struct efi_loaded_image
*image
;
114 * TODO: support EFI_COMPONENT_NAME2_PROTOCOL
119 ret
= efi_search_protocol(handle
, &efi_guid_loaded_image
, &handler
);
120 if (ret
!= EFI_SUCCESS
) {
125 image
= handler
->protocol_interface
;
126 *image_path
= efi_dp_str(image
->file_path
);
132 * do_efi_show_drivers() - show UEFI drivers
134 * @cmdtp: Command table
135 * @flag: Command flag
136 * @argc: Number of arguments
137 * @argv: Argument array
138 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
140 * Implement efidebug "drivers" sub-command.
141 * Show all UEFI drivers and their information.
143 static int do_efi_show_drivers(cmd_tbl_t
*cmdtp
, int flag
,
144 int argc
, char * const argv
[])
146 efi_handle_t
*handles
;
148 u16
*driver_name
, *image_path_text
;
151 ret
= EFI_CALL(BS
->locate_handle_buffer(
152 BY_PROTOCOL
, &efi_guid_driver_binding_protocol
,
153 NULL
, &num
, &handles
));
154 if (ret
!= EFI_SUCCESS
)
155 return CMD_RET_FAILURE
;
158 return CMD_RET_SUCCESS
;
160 printf("Driver%.*s Name Image Path\n",
161 EFI_HANDLE_WIDTH
- 6, spc
);
162 printf("%.*s ==================== ====================\n",
163 EFI_HANDLE_WIDTH
, sep
);
164 for (i
= 0; i
< num
; i
++) {
165 if (!efi_get_driver_handle_info(handles
[i
], &driver_name
,
168 printf("%p %-20ls %ls\n", handles
[i
],
169 driver_name
, image_path_text
);
171 printf("%p %-20ls <built-in>\n",
172 handles
[i
], driver_name
);
173 EFI_CALL(BS
->free_pool(driver_name
));
174 EFI_CALL(BS
->free_pool(image_path_text
));
178 EFI_CALL(BS
->free_pool(handles
));
180 return CMD_RET_SUCCESS
;
183 static const struct {
185 const efi_guid_t guid
;
189 EFI_DEVICE_PATH_PROTOCOL_GUID
,
192 "Device Path To Text",
193 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID
,
196 "Device Path Utilities",
197 EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID
,
200 "Unicode Collation 2",
201 EFI_UNICODE_COLLATION_PROTOCOL2_GUID
,
205 EFI_DRIVER_BINDING_PROTOCOL_GUID
,
209 EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID
,
212 "Simple Text Input Ex",
213 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID
,
216 "Simple Text Output",
217 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID
,
221 EFI_BLOCK_IO_PROTOCOL_GUID
,
224 "Simple File System",
225 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
,
229 EFI_LOADED_IMAGE_PROTOCOL_GUID
,
233 EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
,
237 EFI_HII_STRING_PROTOCOL_GUID
,
241 EFI_HII_DATABASE_PROTOCOL_GUID
,
244 "HII Config Routing",
245 EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID
,
249 EFI_SIMPLE_NETWORK_PROTOCOL_GUID
,
253 EFI_PXE_BASE_CODE_PROTOCOL_GUID
,
258 * get_guid_text - get string of protocol guid
259 * @guid: Protocol guid
262 * Return string for display to represent the protocol.
264 static const char *get_guid_text(const efi_guid_t
*guid
)
268 for (i
= 0; i
< ARRAY_SIZE(guid_list
); i
++)
269 if (!guidcmp(&guid_list
[i
].guid
, guid
))
272 if (i
!= ARRAY_SIZE(guid_list
))
273 return guid_list
[i
].text
;
279 * do_efi_show_handles() - show UEFI handles
281 * @cmdtp: Command table
282 * @flag: Command flag
283 * @argc: Number of arguments
284 * @argv: Argument array
285 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
287 * Implement efidebug "dh" sub-command.
288 * Show all UEFI handles and their information, currently all protocols
291 static int do_efi_show_handles(cmd_tbl_t
*cmdtp
, int flag
,
292 int argc
, char * const argv
[])
294 efi_handle_t
*handles
;
296 efi_uintn_t num
, count
, i
, j
;
297 const char *guid_text
;
300 ret
= EFI_CALL(BS
->locate_handle_buffer(ALL_HANDLES
, NULL
, NULL
,
302 if (ret
!= EFI_SUCCESS
)
303 return CMD_RET_FAILURE
;
306 return CMD_RET_SUCCESS
;
308 printf("Handle%.*s Protocols\n", EFI_HANDLE_WIDTH
- 6, spc
);
309 printf("%.*s ====================\n", EFI_HANDLE_WIDTH
, sep
);
310 for (i
= 0; i
< num
; i
++) {
311 printf("%p", handles
[i
]);
312 ret
= EFI_CALL(BS
->protocols_per_handle(handles
[i
], &guid
,
319 for (j
= 0; j
< count
; j
++) {
325 guid_text
= get_guid_text(guid
[j
]);
329 printf("%pUl", guid
[j
]);
334 EFI_CALL(BS
->free_pool(handles
));
336 return CMD_RET_SUCCESS
;
340 * do_efi_show_images() - show UEFI images
342 * @cmdtp: Command table
343 * @flag: Command flag
344 * @argc: Number of arguments
345 * @argv: Argument array
346 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
348 * Implement efidebug "images" sub-command.
349 * Show all UEFI loaded images and their information.
351 static int do_efi_show_images(cmd_tbl_t
*cmdtp
, int flag
,
352 int argc
, char * const argv
[])
354 efi_print_image_infos(NULL
);
356 return CMD_RET_SUCCESS
;
359 static const char * const efi_mem_type_string
[] = {
360 [EFI_RESERVED_MEMORY_TYPE
] = "RESERVED",
361 [EFI_LOADER_CODE
] = "LOADER CODE",
362 [EFI_LOADER_DATA
] = "LOADER DATA",
363 [EFI_BOOT_SERVICES_CODE
] = "BOOT CODE",
364 [EFI_BOOT_SERVICES_DATA
] = "BOOT DATA",
365 [EFI_RUNTIME_SERVICES_CODE
] = "RUNTIME CODE",
366 [EFI_RUNTIME_SERVICES_DATA
] = "RUNTIME DATA",
367 [EFI_CONVENTIONAL_MEMORY
] = "CONVENTIONAL",
368 [EFI_UNUSABLE_MEMORY
] = "UNUSABLE MEM",
369 [EFI_ACPI_RECLAIM_MEMORY
] = "ACPI RECLAIM MEM",
370 [EFI_ACPI_MEMORY_NVS
] = "ACPI NVS",
371 [EFI_MMAP_IO
] = "IO",
372 [EFI_MMAP_IO_PORT
] = "IO PORT",
373 [EFI_PAL_CODE
] = "PAL",
376 static const struct efi_mem_attrs
{
379 } efi_mem_attrs
[] = {
380 {EFI_MEMORY_UC
, "UC"},
381 {EFI_MEMORY_UC
, "UC"},
382 {EFI_MEMORY_WC
, "WC"},
383 {EFI_MEMORY_WT
, "WT"},
384 {EFI_MEMORY_WB
, "WB"},
385 {EFI_MEMORY_UCE
, "UCE"},
386 {EFI_MEMORY_WP
, "WP"},
387 {EFI_MEMORY_RP
, "RP"},
388 {EFI_MEMORY_XP
, "WP"},
389 {EFI_MEMORY_NV
, "NV"},
390 {EFI_MEMORY_MORE_RELIABLE
, "REL"},
391 {EFI_MEMORY_RO
, "RO"},
392 {EFI_MEMORY_RUNTIME
, "RT"},
396 * print_memory_attributes() - print memory map attributes
398 * @attributes: Attribute value
400 * Print memory map attributes
402 static void print_memory_attributes(u64 attributes
)
406 for (sep
= 0, i
= 0; i
< ARRAY_SIZE(efi_mem_attrs
); i
++)
407 if (attributes
& efi_mem_attrs
[i
].bit
) {
414 puts(efi_mem_attrs
[i
].text
);
418 #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
421 * do_efi_show_memmap() - show UEFI memory map
423 * @cmdtp: Command table
424 * @flag: Command flag
425 * @argc: Number of arguments
426 * @argv: Argument array
427 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
429 * Implement efidebug "memmap" sub-command.
430 * Show UEFI memory map.
432 static int do_efi_show_memmap(cmd_tbl_t
*cmdtp
, int flag
,
433 int argc
, char * const argv
[])
435 struct efi_mem_desc
*memmap
= NULL
, *map
;
436 efi_uintn_t map_size
= 0;
441 ret
= EFI_CALL(BS
->get_memory_map(&map_size
, memmap
, NULL
, NULL
, NULL
));
442 if (ret
== EFI_BUFFER_TOO_SMALL
) {
443 map_size
+= sizeof(struct efi_mem_desc
); /* for my own */
444 ret
= EFI_CALL(BS
->allocate_pool(EFI_LOADER_DATA
,
445 map_size
, (void *)&memmap
));
446 if (ret
!= EFI_SUCCESS
)
447 return CMD_RET_FAILURE
;
448 ret
= EFI_CALL(BS
->get_memory_map(&map_size
, memmap
,
451 if (ret
!= EFI_SUCCESS
) {
452 EFI_CALL(BS
->free_pool(memmap
));
453 return CMD_RET_FAILURE
;
456 printf("Type Start%.*s End%.*s Attributes\n",
457 EFI_PHYS_ADDR_WIDTH
- 5, spc
, EFI_PHYS_ADDR_WIDTH
- 3, spc
);
458 printf("================ %.*s %.*s ==========\n",
459 EFI_PHYS_ADDR_WIDTH
, sep
, EFI_PHYS_ADDR_WIDTH
, sep
);
460 for (i
= 0, map
= memmap
; i
< map_size
/ sizeof(*map
); map
++, i
++) {
461 if (map
->type
< EFI_MAX_MEMORY_TYPE
)
462 type
= efi_mem_type_string
[map
->type
];
466 printf("%-16s %.*llx-%.*llx", type
,
470 map
->physical_start
+ map
->num_pages
* EFI_PAGE_SIZE
);
472 print_memory_attributes(map
->attribute
);
476 EFI_CALL(BS
->free_pool(memmap
));
478 return CMD_RET_SUCCESS
;
482 * do_efi_boot_add() - set UEFI load option
484 * @cmdtp: Command table
485 * @flag: Command flag
486 * @argc: Number of arguments
487 * @argv: Argument array
488 * Return: CMD_RET_SUCCESS on success,
489 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
491 * Implement efidebug "boot add" sub-command. Create or change UEFI load option.
493 * efidebug boot add <id> <label> <interface> <devnum>[:<part>] <file> <options>
495 static int do_efi_boot_add(cmd_tbl_t
*cmdtp
, int flag
,
496 int argc
, char * const argv
[])
501 u16 var_name16
[9], *p
;
503 size_t label_len
, label_len16
;
505 struct efi_device_path
*device_path
= NULL
, *file_path
= NULL
;
506 struct efi_load_option lo
;
510 int r
= CMD_RET_SUCCESS
;
512 if (argc
< 6 || argc
> 7)
513 return CMD_RET_USAGE
;
515 id
= (int)simple_strtoul(argv
[1], &endp
, 16);
516 if (*endp
!= '\0' || id
> 0xffff)
517 return CMD_RET_USAGE
;
519 sprintf(var_name
, "Boot%04X", id
);
521 utf8_utf16_strncpy(&p
, var_name
, 9);
523 guid
= efi_global_variable_guid
;
526 lo
.attributes
= LOAD_OPTION_ACTIVE
; /* always ACTIVE */
529 label_len
= strlen(argv
[2]);
530 label_len16
= utf8_utf16_strnlen(argv
[2], label_len
);
531 label
= malloc((label_len16
+ 1) * sizeof(u16
));
533 return CMD_RET_FAILURE
;
534 lo
.label
= label
; /* label will be changed below */
535 utf8_utf16_strncpy(&label
, argv
[2], label_len
);
538 ret
= efi_dp_from_name(argv
[3], argv
[4], argv
[5], &device_path
,
540 if (ret
!= EFI_SUCCESS
) {
541 printf("Cannot create device path for \"%s %s\"\n",
546 lo
.file_path
= file_path
;
547 lo
.file_path_length
= efi_dp_size(file_path
)
548 + sizeof(struct efi_device_path
); /* for END */
552 lo
.optional_data
= NULL
;
554 lo
.optional_data
= (const u8
*)argv
[6];
556 size
= efi_serialize_load_option(&lo
, (u8
**)&data
);
562 ret
= EFI_CALL(RT
->set_variable(var_name16
, &guid
,
563 EFI_VARIABLE_NON_VOLATILE
|
564 EFI_VARIABLE_BOOTSERVICE_ACCESS
|
565 EFI_VARIABLE_RUNTIME_ACCESS
,
567 if (ret
!= EFI_SUCCESS
) {
568 printf("Cannot set %ls\n", var_name16
);
573 efi_free_pool(device_path
);
574 efi_free_pool(file_path
);
581 * do_efi_boot_rm() - delete UEFI load options
583 * @cmdtp: Command table
584 * @flag: Command flag
585 * @argc: Number of arguments
586 * @argv: Argument array
587 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
589 * Implement efidebug "boot rm" sub-command.
590 * Delete UEFI load options.
592 * efidebug boot rm <id> ...
594 static int do_efi_boot_rm(cmd_tbl_t
*cmdtp
, int flag
,
595 int argc
, char * const argv
[])
605 return CMD_RET_USAGE
;
607 guid
= efi_global_variable_guid
;
608 for (i
= 1; i
< argc
; i
++, argv
++) {
609 id
= (int)simple_strtoul(argv
[1], &endp
, 16);
610 if (*endp
!= '\0' || id
> 0xffff)
611 return CMD_RET_FAILURE
;
613 sprintf(var_name
, "Boot%04X", id
);
614 utf8_utf16_strncpy((u16
**)&var_name16
, var_name
, 9);
616 ret
= EFI_CALL(RT
->set_variable(var_name16
, &guid
, 0, 0, NULL
));
618 printf("Cannot remove Boot%04X", id
);
619 return CMD_RET_FAILURE
;
623 return CMD_RET_SUCCESS
;
627 * show_efi_boot_opt_data() - dump UEFI load option
629 * @id: load option number
630 * @data: value of UEFI load option variable
631 * @size: size of the boot option
633 * Decode the value of UEFI load option variable and print information.
635 static void show_efi_boot_opt_data(int id
, void *data
, size_t size
)
637 struct efi_load_option lo
;
639 size_t label_len16
, label_len
;
642 efi_deserialize_load_option(&lo
, data
);
644 label_len16
= u16_strlen(lo
.label
);
645 label_len
= utf16_utf8_strnlen(lo
.label
, label_len16
);
646 label
= malloc(label_len
+ 1);
650 utf16_utf8_strncpy(&p
, lo
.label
, label_len16
);
652 printf("Boot%04X:\n", id
);
653 printf(" attributes: %c%c%c (0x%08x)\n",
655 lo
.attributes
& LOAD_OPTION_ACTIVE
? 'A' : '-',
656 /* FORCE RECONNECT */
657 lo
.attributes
& LOAD_OPTION_FORCE_RECONNECT
? 'R' : '-',
659 lo
.attributes
& LOAD_OPTION_HIDDEN
? 'H' : '-',
661 printf(" label: %s\n", label
);
663 dp_str
= efi_dp_str(lo
.file_path
);
664 printf(" file_path: %ls\n", dp_str
);
665 efi_free_pool(dp_str
);
668 print_hex_dump(" ", DUMP_PREFIX_OFFSET
, 16, 1,
669 lo
.optional_data
, size
+ (u8
*)data
-
670 (u8
*)lo
.optional_data
, true);
675 * show_efi_boot_opt() - dump UEFI load option
677 * @id: Load option number
679 * Dump information defined by UEFI load option.
681 static void show_efi_boot_opt(int id
)
684 u16 var_name16
[9], *p
;
690 sprintf(var_name
, "Boot%04X", id
);
692 utf8_utf16_strncpy(&p
, var_name
, 9);
693 guid
= efi_global_variable_guid
;
696 ret
= EFI_CALL(RT
->get_variable(var_name16
, &guid
, NULL
, &size
, NULL
));
697 if (ret
== (int)EFI_BUFFER_TOO_SMALL
) {
699 ret
= EFI_CALL(RT
->get_variable(var_name16
, &guid
, NULL
, &size
,
702 if (ret
== EFI_SUCCESS
)
703 show_efi_boot_opt_data(id
, data
, size
);
704 else if (ret
== EFI_NOT_FOUND
)
705 printf("Boot%04X: not found\n", id
);
710 static int u16_tohex(u16 c
)
712 if (c
>= '0' && c
<= '9')
714 if (c
>= 'A' && c
<= 'F')
717 /* not hexadecimal */
722 * show_efi_boot_dump() - dump all UEFI load options
724 * @cmdtp: Command table
725 * @flag: Command flag
726 * @argc: Number of arguments
727 * @argv: Argument array
728 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
730 * Implement efidebug "boot dump" sub-command.
731 * Dump information of all UEFI load options defined.
735 static int do_efi_boot_dump(cmd_tbl_t
*cmdtp
, int flag
,
736 int argc
, char * const argv
[])
739 efi_uintn_t buf_size
, size
;
745 return CMD_RET_USAGE
;
748 var_name16
= malloc(buf_size
);
750 return CMD_RET_FAILURE
;
755 ret
= EFI_CALL(efi_get_next_variable_name(&size
, var_name16
,
757 if (ret
== EFI_NOT_FOUND
)
759 if (ret
== EFI_BUFFER_TOO_SMALL
) {
761 p
= realloc(var_name16
, buf_size
);
764 return CMD_RET_FAILURE
;
767 ret
= EFI_CALL(efi_get_next_variable_name(&size
,
771 if (ret
!= EFI_SUCCESS
) {
773 return CMD_RET_FAILURE
;
776 if (memcmp(var_name16
, L
"Boot", 8))
779 for (id
= 0, i
= 0; i
< 4; i
++) {
780 digit
= u16_tohex(var_name16
[4 + i
]);
783 id
= (id
<< 4) + digit
;
785 if (i
== 4 && !var_name16
[8])
786 show_efi_boot_opt(id
);
791 return CMD_RET_SUCCESS
;
795 * show_efi_boot_order() - show order of UEFI load options
797 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
799 * Show order of UEFI load options defined by BootOrder variable.
801 static int show_efi_boot_order(void)
804 u16
*bootorder
= NULL
;
808 u16 var_name16
[9], *p16
;
810 struct efi_load_option lo
;
812 size_t label_len16
, label_len
;
815 guid
= efi_global_variable_guid
;
817 ret
= EFI_CALL(RT
->get_variable(L
"BootOrder", &guid
, NULL
, &size
,
819 if (ret
== EFI_BUFFER_TOO_SMALL
) {
820 bootorder
= malloc(size
);
821 ret
= EFI_CALL(RT
->get_variable(L
"BootOrder", &guid
, NULL
,
824 if (ret
== EFI_NOT_FOUND
) {
825 printf("BootOrder not defined\n");
826 ret
= CMD_RET_SUCCESS
;
828 } else if (ret
!= EFI_SUCCESS
) {
829 ret
= CMD_RET_FAILURE
;
833 num
= size
/ sizeof(u16
);
834 for (i
= 0; i
< num
; i
++) {
835 sprintf(var_name
, "Boot%04X", bootorder
[i
]);
837 utf8_utf16_strncpy(&p16
, var_name
, 9);
840 ret
= EFI_CALL(RT
->get_variable(var_name16
, &guid
, NULL
, &size
,
842 if (ret
!= EFI_BUFFER_TOO_SMALL
) {
843 printf("%2d: Boot%04X: (not defined)\n",
844 i
+ 1, bootorder
[i
]);
850 ret
= CMD_RET_FAILURE
;
853 ret
= EFI_CALL(RT
->get_variable(var_name16
, &guid
, NULL
, &size
,
855 if (ret
!= EFI_SUCCESS
) {
857 ret
= CMD_RET_FAILURE
;
861 efi_deserialize_load_option(&lo
, data
);
863 label_len16
= u16_strlen(lo
.label
);
864 label_len
= utf16_utf8_strnlen(lo
.label
, label_len16
);
865 label
= malloc(label_len
+ 1);
868 ret
= CMD_RET_FAILURE
;
872 utf16_utf8_strncpy(&p
, lo
.label
, label_len16
);
873 printf("%2d: Boot%04X: %s\n", i
+ 1, bootorder
[i
], label
);
885 * do_efi_boot_next() - manage UEFI BootNext variable
887 * @cmdtp: Command table
888 * @flag: Command flag
889 * @argc: Number of arguments
890 * @argv: Argument array
891 * Return: CMD_RET_SUCCESS on success,
892 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
894 * Implement efidebug "boot next" sub-command.
895 * Set BootNext variable.
897 * efidebug boot next <id>
899 static int do_efi_boot_next(cmd_tbl_t
*cmdtp
, int flag
,
900 int argc
, char * const argv
[])
907 int r
= CMD_RET_SUCCESS
;
910 return CMD_RET_USAGE
;
912 bootnext
= (u16
)simple_strtoul(argv
[1], &endp
, 16);
913 if (*endp
!= '\0' || bootnext
> 0xffff) {
914 printf("invalid value: %s\n", argv
[1]);
919 guid
= efi_global_variable_guid
;
921 ret
= EFI_CALL(RT
->set_variable(L
"BootNext", &guid
,
922 EFI_VARIABLE_NON_VOLATILE
|
923 EFI_VARIABLE_BOOTSERVICE_ACCESS
|
924 EFI_VARIABLE_RUNTIME_ACCESS
,
926 if (ret
!= EFI_SUCCESS
) {
927 printf("Cannot set BootNext\n");
935 * do_efi_boot_order() - manage UEFI BootOrder variable
937 * @cmdtp: Command table
938 * @flag: Command flag
939 * @argc: Number of arguments
940 * @argv: Argument array
941 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
943 * Implement efidebug "boot order" sub-command.
944 * Show order of UEFI load options, or change it in BootOrder variable.
946 * efidebug boot order [<id> ...]
948 static int do_efi_boot_order(cmd_tbl_t
*cmdtp
, int flag
,
949 int argc
, char * const argv
[])
951 u16
*bootorder
= NULL
;
957 int r
= CMD_RET_SUCCESS
;
960 return show_efi_boot_order();
965 size
= argc
* sizeof(u16
);
966 bootorder
= malloc(size
);
968 return CMD_RET_FAILURE
;
970 for (i
= 0; i
< argc
; i
++) {
971 id
= (int)simple_strtoul(argv
[i
], &endp
, 16);
972 if (*endp
!= '\0' || id
> 0xffff) {
973 printf("invalid value: %s\n", argv
[i
]);
978 bootorder
[i
] = (u16
)id
;
981 guid
= efi_global_variable_guid
;
982 ret
= EFI_CALL(RT
->set_variable(L
"BootOrder", &guid
,
983 EFI_VARIABLE_NON_VOLATILE
|
984 EFI_VARIABLE_BOOTSERVICE_ACCESS
|
985 EFI_VARIABLE_RUNTIME_ACCESS
,
987 if (ret
!= EFI_SUCCESS
) {
988 printf("Cannot set BootOrder\n");
997 static cmd_tbl_t cmd_efidebug_boot_sub
[] = {
998 U_BOOT_CMD_MKENT(add
, CONFIG_SYS_MAXARGS
, 1, do_efi_boot_add
, "", ""),
999 U_BOOT_CMD_MKENT(rm
, CONFIG_SYS_MAXARGS
, 1, do_efi_boot_rm
, "", ""),
1000 U_BOOT_CMD_MKENT(dump
, CONFIG_SYS_MAXARGS
, 1, do_efi_boot_dump
, "", ""),
1001 U_BOOT_CMD_MKENT(next
, CONFIG_SYS_MAXARGS
, 1, do_efi_boot_next
, "", ""),
1002 U_BOOT_CMD_MKENT(order
, CONFIG_SYS_MAXARGS
, 1, do_efi_boot_order
,
1007 * do_efi_boot_opt() - manage UEFI load options
1009 * @cmdtp: Command table
1010 * @flag: Command flag
1011 * @argc: Number of arguments
1012 * @argv: Argument array
1013 * Return: CMD_RET_SUCCESS on success,
1014 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1016 * Implement efidebug "boot" sub-command.
1018 static int do_efi_boot_opt(cmd_tbl_t
*cmdtp
, int flag
,
1019 int argc
, char * const argv
[])
1024 return CMD_RET_USAGE
;
1028 cp
= find_cmd_tbl(argv
[0], cmd_efidebug_boot_sub
,
1029 ARRAY_SIZE(cmd_efidebug_boot_sub
));
1031 return CMD_RET_USAGE
;
1033 return cp
->cmd(cmdtp
, flag
, argc
, argv
);
1036 static cmd_tbl_t cmd_efidebug_sub
[] = {
1037 U_BOOT_CMD_MKENT(boot
, CONFIG_SYS_MAXARGS
, 1, do_efi_boot_opt
, "", ""),
1038 U_BOOT_CMD_MKENT(devices
, CONFIG_SYS_MAXARGS
, 1, do_efi_show_devices
,
1040 U_BOOT_CMD_MKENT(drivers
, CONFIG_SYS_MAXARGS
, 1, do_efi_show_drivers
,
1042 U_BOOT_CMD_MKENT(dh
, CONFIG_SYS_MAXARGS
, 1, do_efi_show_handles
,
1044 U_BOOT_CMD_MKENT(images
, CONFIG_SYS_MAXARGS
, 1, do_efi_show_images
,
1046 U_BOOT_CMD_MKENT(memmap
, CONFIG_SYS_MAXARGS
, 1, do_efi_show_memmap
,
1051 * do_efidebug() - display and configure UEFI environment
1053 * @cmdtp: Command table
1054 * @flag: Command flag
1055 * @argc: Number of arguments
1056 * @argv: Argument array
1057 * Return: CMD_RET_SUCCESS on success,
1058 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1060 * Implement efidebug command which allows us to display and
1061 * configure UEFI environment.
1063 static int do_efidebug(cmd_tbl_t
*cmdtp
, int flag
,
1064 int argc
, char * const argv
[])
1070 return CMD_RET_USAGE
;
1074 /* Initialize UEFI drivers */
1075 r
= efi_init_obj_list();
1076 if (r
!= EFI_SUCCESS
) {
1077 printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1078 r
& ~EFI_ERROR_MASK
);
1079 return CMD_RET_FAILURE
;
1082 cp
= find_cmd_tbl(argv
[0], cmd_efidebug_sub
,
1083 ARRAY_SIZE(cmd_efidebug_sub
));
1085 return CMD_RET_USAGE
;
1087 return cp
->cmd(cmdtp
, flag
, argc
, argv
);
1090 #ifdef CONFIG_SYS_LONGHELP
1091 static char efidebug_help_text
[] =
1092 " - UEFI Shell-like interface to configure UEFI environment\n"
1094 "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>]\n"
1095 " - set UEFI BootXXXX variable\n"
1096 " <load options> will be passed to UEFI application\n"
1097 "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
1098 " - delete UEFI BootXXXX variables\n"
1099 "efidebug boot dump\n"
1100 " - dump all UEFI BootXXXX variables\n"
1101 "efidebug boot next <bootid>\n"
1102 " - set UEFI BootNext variable\n"
1103 "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
1104 " - set/show UEFI boot order\n"
1106 "efidebug devices\n"
1107 " - show uefi devices\n"
1108 "efidebug drivers\n"
1109 " - show uefi drivers\n"
1111 " - show uefi handles\n"
1113 " - show loaded images\n"
1115 " - show uefi memory map\n";
1119 efidebug
, 10, 0, do_efidebug
,
1120 "Configure UEFI environment",