blob: 5fb7b1e3c6a9ebd8201b57fd0e6b635944e6f347 [file] [log] [blame]
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * UEFI Shell-like command
4 *
5 * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
6 */
7
8#include <charset.h>
9#include <common.h>
10#include <command.h>
11#include <efi_loader.h>
Heinrich Schuchardt79693352020-09-27 14:50:25 +020012#include <efi_rng.h>
AKASHI Takahiro59df7e72019-02-25 15:54:38 +090013#include <exports.h>
Heinrich Schuchardt39a1ff82019-04-29 13:51:45 +020014#include <hexdump.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060015#include <log.h>
AKASHI Takahiro59df7e72019-02-25 15:54:38 +090016#include <malloc.h>
Heinrich Schuchardta415d612020-03-14 08:44:07 +010017#include <mapmem.h>
AKASHI Takahiro59df7e72019-02-25 15:54:38 +090018#include <search.h>
19#include <linux/ctype.h>
20
AKASHI Takahiro355cdb52019-02-25 15:54:39 +090021#define BS systab.boottime
AKASHI Takahiro7f35ced2020-11-17 09:28:01 +090022#define RT systab.runtime
23
24#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
25/**
26 * do_efi_capsule_update() - process a capsule update
27 *
28 * @cmdtp: Command table
29 * @flag: Command flag
30 * @argc: Number of arguments
31 * @argv: Argument array
32 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
33 *
34 * Implement efidebug "capsule update" sub-command.
35 * process a capsule update.
36 *
37 * efidebug capsule update [-v] <capsule address>
38 */
39static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag,
40 int argc, char * const argv[])
41{
42 struct efi_capsule_header *capsule;
43 int verbose = 0;
44 char *endp;
45 efi_status_t ret;
46
47 if (argc != 2 && argc != 3)
48 return CMD_RET_USAGE;
49
50 if (argc == 3) {
51 if (strcmp(argv[1], "-v"))
52 return CMD_RET_USAGE;
53
54 verbose = 1;
55 argc--;
56 argv++;
57 }
58
59 capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
60 if (endp == argv[1]) {
61 printf("Invalid address: %s", argv[1]);
62 return CMD_RET_FAILURE;
63 }
64
65 if (verbose) {
66 printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
67 printf("Capsule flags: 0x%x\n", capsule->flags);
68 printf("Capsule header size: 0x%x\n", capsule->header_size);
69 printf("Capsule image size: 0x%x\n",
70 capsule->capsule_image_size);
71 }
72
73 ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL));
74 if (ret) {
75 printf("Cannot handle a capsule at %p", capsule);
76 return CMD_RET_FAILURE;
77 }
78
79 return CMD_RET_SUCCESS;
80}
81
Sughosh Ganu74075952020-12-30 19:27:11 +053082static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag,
83 int argc, char * const argv[])
84{
85 efi_status_t ret;
86
87 ret = efi_launch_capsules();
88
89 return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
90}
91
AKASHI Takahiro7f35ced2020-11-17 09:28:01 +090092/**
93 * do_efi_capsule_show() - show capsule information
94 *
95 * @cmdtp: Command table
96 * @flag: Command flag
97 * @argc: Number of arguments
98 * @argv: Argument array
99 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
100 *
101 * Implement efidebug "capsule show" sub-command.
102 * show capsule information.
103 *
104 * efidebug capsule show <capsule address>
105 */
106static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,
107 int argc, char * const argv[])
108{
109 struct efi_capsule_header *capsule;
110 char *endp;
111
112 if (argc != 2)
113 return CMD_RET_USAGE;
114
115 capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
116 if (endp == argv[1]) {
117 printf("Invalid address: %s", argv[1]);
118 return CMD_RET_FAILURE;
119 }
120
121 printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
122 printf("Capsule flags: 0x%x\n", capsule->flags);
123 printf("Capsule header size: 0x%x\n", capsule->header_size);
124 printf("Capsule image size: 0x%x\n",
125 capsule->capsule_image_size);
126
127 return CMD_RET_SUCCESS;
128}
129
130/**
131 * do_efi_capsule_res() - show a capsule update result
132 *
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
138 *
139 * Implement efidebug "capsule result" sub-command.
140 * show a capsule update result.
141 * If result number is not specified, CapsuleLast will be shown.
142 *
143 * efidebug capsule result [<capsule result number>]
144 */
145static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
146 int argc, char * const argv[])
147{
148 int capsule_id;
149 char *endp;
150 char var_name[12];
151 u16 var_name16[12], *p;
152 efi_guid_t guid;
153 struct efi_capsule_result_variable_header *result = NULL;
154 efi_uintn_t size;
155 efi_status_t ret;
156
157 if (argc != 1 && argc != 2)
158 return CMD_RET_USAGE;
159
160 guid = efi_guid_capsule_report;
161 if (argc == 1) {
162 size = sizeof(var_name16);
163 ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
164 &size, var_name16));
165 if (ret != EFI_SUCCESS) {
166 if (ret == EFI_NOT_FOUND)
167 printf("CapsuleLast doesn't exist\n");
168 else
169 printf("Failed to get CapsuleLast\n");
170
171 return CMD_RET_FAILURE;
172 }
173 printf("CapsuleLast is %ls\n", var_name16);
174 } else {
175 argc--;
176 argv++;
177
178 capsule_id = simple_strtoul(argv[0], &endp, 16);
179 if (capsule_id < 0 || capsule_id > 0xffff)
180 return CMD_RET_USAGE;
181
182 sprintf(var_name, "Capsule%04X", capsule_id);
183 p = var_name16;
184 utf8_utf16_strncpy(&p, var_name, 9);
185 }
186
187 size = 0;
188 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
189 if (ret == EFI_BUFFER_TOO_SMALL) {
190 result = malloc(size);
191 ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
192 result));
193 if (ret != EFI_SUCCESS) {
194 free(result);
195 printf("Failed to get %ls\n", var_name16);
196
197 return CMD_RET_FAILURE;
198 }
199 }
200
201 printf("Result total size: 0x%x\n", result->variable_total_size);
202 printf("Capsule guid: %pUl\n", &result->capsule_guid);
203 printf("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n",
204 result->capsule_processed.year, result->capsule_processed.month,
205 result->capsule_processed.day, result->capsule_processed.hour,
206 result->capsule_processed.minute,
207 result->capsule_processed.second);
208 printf("Capsule status: 0x%lx\n", result->capsule_status);
209
210 free(result);
211
212 return CMD_RET_SUCCESS;
213}
214
215static struct cmd_tbl cmd_efidebug_capsule_sub[] = {
216 U_BOOT_CMD_MKENT(update, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_update,
217 "", ""),
218 U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show,
219 "", ""),
Sughosh Ganu74075952020-12-30 19:27:11 +0530220 U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update,
221 "", ""),
AKASHI Takahiro7f35ced2020-11-17 09:28:01 +0900222 U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
223 "", ""),
224};
225
226/**
227 * do_efi_capsule() - manage UEFI capsules
228 *
229 * @cmdtp: Command table
230 * @flag: Command flag
231 * @argc: Number of arguments
232 * @argv: Argument array
233 * Return: CMD_RET_SUCCESS on success,
234 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
235 *
236 * Implement efidebug "capsule" sub-command.
237 */
238static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag,
239 int argc, char * const argv[])
240{
241 struct cmd_tbl *cp;
242
243 if (argc < 2)
244 return CMD_RET_USAGE;
245
246 argc--; argv++;
247
248 cp = find_cmd_tbl(argv[0], cmd_efidebug_capsule_sub,
249 ARRAY_SIZE(cmd_efidebug_capsule_sub));
250 if (!cp)
251 return CMD_RET_USAGE;
252
253 return cp->cmd(cmdtp, flag, argc, argv);
254}
255#endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900256
257/**
AKASHI Takahiro355cdb52019-02-25 15:54:39 +0900258 * efi_get_device_handle_info() - get information of UEFI device
259 *
260 * @handle: Handle of UEFI device
261 * @dev_path_text: Pointer to text of device path
262 * Return: 0 on success, -1 on failure
263 *
264 * Currently return a formatted text of device path.
265 */
266static int efi_get_device_handle_info(efi_handle_t handle, u16 **dev_path_text)
267{
268 struct efi_device_path *dp;
269 efi_status_t ret;
270
271 ret = EFI_CALL(BS->open_protocol(handle, &efi_guid_device_path,
272 (void **)&dp, NULL /* FIXME */, NULL,
273 EFI_OPEN_PROTOCOL_GET_PROTOCOL));
274 if (ret == EFI_SUCCESS) {
275 *dev_path_text = efi_dp_str(dp);
276 return 0;
277 } else {
278 return -1;
279 }
280}
281
282#define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2)
283
284static const char spc[] = " ";
285static const char sep[] = "================";
286
287/**
288 * do_efi_show_devices() - show UEFI devices
289 *
290 * @cmdtp: Command table
291 * @flag: Command flag
292 * @argc: Number of arguments
293 * @argv: Argument array
294 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
295 *
296 * Implement efidebug "devices" sub-command.
297 * Show all UEFI devices and their information.
298 */
Simon Glass09140112020-05-10 11:40:03 -0600299static int do_efi_show_devices(struct cmd_tbl *cmdtp, int flag,
300 int argc, char *const argv[])
AKASHI Takahiro355cdb52019-02-25 15:54:39 +0900301{
302 efi_handle_t *handles;
303 efi_uintn_t num, i;
304 u16 *dev_path_text;
305 efi_status_t ret;
306
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200307 ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL,
AKASHI Takahiro355cdb52019-02-25 15:54:39 +0900308 &num, &handles));
309 if (ret != EFI_SUCCESS)
310 return CMD_RET_FAILURE;
311
312 if (!num)
313 return CMD_RET_SUCCESS;
314
315 printf("Device%.*s Device Path\n", EFI_HANDLE_WIDTH - 6, spc);
316 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
317 for (i = 0; i < num; i++) {
318 if (!efi_get_device_handle_info(handles[i], &dev_path_text)) {
319 printf("%p %ls\n", handles[i], dev_path_text);
320 efi_free_pool(dev_path_text);
321 }
322 }
323
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200324 efi_free_pool(handles);
AKASHI Takahiro355cdb52019-02-25 15:54:39 +0900325
326 return CMD_RET_SUCCESS;
327}
328
329/**
AKASHI Takahiro66eaf562019-02-25 15:54:40 +0900330 * efi_get_driver_handle_info() - get information of UEFI driver
331 *
332 * @handle: Handle of UEFI device
333 * @driver_name: Driver name
334 * @image_path: Pointer to text of device path
335 * Return: 0 on success, -1 on failure
336 *
337 * Currently return no useful information as all UEFI drivers are
338 * built-in..
339 */
340static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name,
341 u16 **image_path)
342{
343 struct efi_handler *handler;
344 struct efi_loaded_image *image;
345 efi_status_t ret;
346
347 /*
348 * driver name
349 * TODO: support EFI_COMPONENT_NAME2_PROTOCOL
350 */
351 *driver_name = NULL;
352
353 /* image name */
354 ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler);
355 if (ret != EFI_SUCCESS) {
356 *image_path = NULL;
357 return 0;
358 }
359
360 image = handler->protocol_interface;
361 *image_path = efi_dp_str(image->file_path);
362
363 return 0;
364}
365
366/**
367 * do_efi_show_drivers() - show UEFI drivers
368 *
369 * @cmdtp: Command table
370 * @flag: Command flag
371 * @argc: Number of arguments
372 * @argv: Argument array
373 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
374 *
375 * Implement efidebug "drivers" sub-command.
376 * Show all UEFI drivers and their information.
377 */
Simon Glass09140112020-05-10 11:40:03 -0600378static int do_efi_show_drivers(struct cmd_tbl *cmdtp, int flag,
379 int argc, char *const argv[])
AKASHI Takahiro66eaf562019-02-25 15:54:40 +0900380{
381 efi_handle_t *handles;
382 efi_uintn_t num, i;
383 u16 *driver_name, *image_path_text;
384 efi_status_t ret;
385
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200386 ret = EFI_CALL(efi_locate_handle_buffer(
AKASHI Takahiro66eaf562019-02-25 15:54:40 +0900387 BY_PROTOCOL, &efi_guid_driver_binding_protocol,
388 NULL, &num, &handles));
389 if (ret != EFI_SUCCESS)
390 return CMD_RET_FAILURE;
391
392 if (!num)
393 return CMD_RET_SUCCESS;
394
395 printf("Driver%.*s Name Image Path\n",
396 EFI_HANDLE_WIDTH - 6, spc);
397 printf("%.*s ==================== ====================\n",
398 EFI_HANDLE_WIDTH, sep);
399 for (i = 0; i < num; i++) {
400 if (!efi_get_driver_handle_info(handles[i], &driver_name,
401 &image_path_text)) {
402 if (image_path_text)
403 printf("%p %-20ls %ls\n", handles[i],
404 driver_name, image_path_text);
405 else
406 printf("%p %-20ls <built-in>\n",
407 handles[i], driver_name);
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200408 efi_free_pool(driver_name);
409 efi_free_pool(image_path_text);
AKASHI Takahiro66eaf562019-02-25 15:54:40 +0900410 }
411 }
412
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200413 efi_free_pool(handles);
AKASHI Takahiro66eaf562019-02-25 15:54:40 +0900414
415 return CMD_RET_SUCCESS;
416}
417
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900418static const struct {
419 const char *text;
420 const efi_guid_t guid;
421} guid_list[] = {
422 {
423 "Device Path",
Heinrich Schuchardtdec88e42019-04-20 07:39:11 +0200424 EFI_DEVICE_PATH_PROTOCOL_GUID,
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900425 },
426 {
427 "Device Path To Text",
428 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID,
429 },
430 {
431 "Device Path Utilities",
432 EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID,
433 },
434 {
435 "Unicode Collation 2",
436 EFI_UNICODE_COLLATION_PROTOCOL2_GUID,
437 },
438 {
439 "Driver Binding",
440 EFI_DRIVER_BINDING_PROTOCOL_GUID,
441 },
442 {
443 "Simple Text Input",
444 EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID,
445 },
446 {
447 "Simple Text Input Ex",
448 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID,
449 },
450 {
451 "Simple Text Output",
452 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID,
453 },
454 {
455 "Block IO",
Heinrich Schuchardtdec88e42019-04-20 07:39:11 +0200456 EFI_BLOCK_IO_PROTOCOL_GUID,
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900457 },
458 {
459 "Simple File System",
460 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
461 },
462 {
463 "Loaded Image",
Heinrich Schuchardtdec88e42019-04-20 07:39:11 +0200464 EFI_LOADED_IMAGE_PROTOCOL_GUID,
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900465 },
466 {
Heinrich Schuchardtdec88e42019-04-20 07:39:11 +0200467 "Graphics Output",
468 EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900469 },
Heinrich Schuchardt391bc8a2019-04-20 07:57:28 +0200470 {
471 "HII String",
472 EFI_HII_STRING_PROTOCOL_GUID,
473 },
474 {
475 "HII Database",
476 EFI_HII_DATABASE_PROTOCOL_GUID,
477 },
478 {
479 "HII Config Routing",
480 EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID,
481 },
482 {
Ilias Apalodimasec80b472020-02-21 09:55:45 +0200483 "Load File2",
484 EFI_LOAD_FILE2_PROTOCOL_GUID,
485 },
486 {
Heinrich Schuchardt79693352020-09-27 14:50:25 +0200487 "Random Number Generator",
488 EFI_RNG_PROTOCOL_GUID,
489 },
490 {
Heinrich Schuchardt391bc8a2019-04-20 07:57:28 +0200491 "Simple Network",
492 EFI_SIMPLE_NETWORK_PROTOCOL_GUID,
493 },
494 {
495 "PXE Base Code",
496 EFI_PXE_BASE_CODE_PROTOCOL_GUID,
497 },
Heinrich Schuchardt986e0642020-01-07 05:57:47 +0100498 /* Configuration table GUIDs */
499 {
500 "ACPI table",
501 EFI_ACPI_TABLE_GUID,
502 },
503 {
504 "device tree",
505 EFI_FDT_GUID,
506 },
507 {
508 "SMBIOS table",
509 SMBIOS_TABLE_GUID,
510 },
Heinrich Schuchardt76be6872020-02-19 20:48:49 +0100511 {
512 "Runtime properties",
513 EFI_RT_PROPERTIES_TABLE_GUID,
514 },
Ilias Apalodimas94e78202020-11-30 11:47:41 +0200515 {
516 "TCG2 Final Events Table",
517 EFI_TCG2_FINAL_EVENTS_TABLE_GUID,
518 },
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900519};
520
521/**
Heinrich Schuchardt173cd9e2020-01-07 06:02:33 +0100522 * get_guid_text - get string of GUID
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900523 *
Heinrich Schuchardt173cd9e2020-01-07 06:02:33 +0100524 * Return description of GUID.
525 *
526 * @guid: GUID
527 * Return: description of GUID or NULL
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900528 */
Heinrich Schuchardt173cd9e2020-01-07 06:02:33 +0100529static const char *get_guid_text(const void *guid)
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900530{
531 int i;
532
Heinrich Schuchardt173cd9e2020-01-07 06:02:33 +0100533 for (i = 0; i < ARRAY_SIZE(guid_list); i++) {
534 /*
535 * As guidcmp uses memcmp() we can safely accept unaligned
536 * GUIDs.
537 */
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900538 if (!guidcmp(&guid_list[i].guid, guid))
Heinrich Schuchardt173cd9e2020-01-07 06:02:33 +0100539 return guid_list[i].text;
540 }
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900541
Heinrich Schuchardt173cd9e2020-01-07 06:02:33 +0100542 return NULL;
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900543}
544
545/**
546 * do_efi_show_handles() - show UEFI handles
547 *
548 * @cmdtp: Command table
549 * @flag: Command flag
550 * @argc: Number of arguments
551 * @argv: Argument array
552 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
553 *
554 * Implement efidebug "dh" sub-command.
555 * Show all UEFI handles and their information, currently all protocols
556 * added to handle.
557 */
Simon Glass09140112020-05-10 11:40:03 -0600558static int do_efi_show_handles(struct cmd_tbl *cmdtp, int flag,
559 int argc, char *const argv[])
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900560{
561 efi_handle_t *handles;
562 efi_guid_t **guid;
563 efi_uintn_t num, count, i, j;
564 const char *guid_text;
565 efi_status_t ret;
566
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200567 ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL,
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900568 &num, &handles));
569 if (ret != EFI_SUCCESS)
570 return CMD_RET_FAILURE;
571
572 if (!num)
573 return CMD_RET_SUCCESS;
574
575 printf("Handle%.*s Protocols\n", EFI_HANDLE_WIDTH - 6, spc);
576 printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
577 for (i = 0; i < num; i++) {
578 printf("%p", handles[i]);
579 ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid,
580 &count));
581 if (ret || !count) {
582 putc('\n');
583 continue;
584 }
585
586 for (j = 0; j < count; j++) {
587 if (j)
588 printf(", ");
589 else
590 putc(' ');
591
592 guid_text = get_guid_text(guid[j]);
593 if (guid_text)
594 puts(guid_text);
595 else
596 printf("%pUl", guid[j]);
597 }
598 putc('\n');
599 }
600
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200601 efi_free_pool(handles);
AKASHI Takahiroa8014622019-02-25 15:54:41 +0900602
603 return CMD_RET_SUCCESS;
604}
605
AKASHI Takahiro66eaf562019-02-25 15:54:40 +0900606/**
AKASHI Takahirofa536732019-02-25 15:54:42 +0900607 * do_efi_show_images() - show UEFI images
608 *
609 * @cmdtp: Command table
610 * @flag: Command flag
611 * @argc: Number of arguments
612 * @argv: Argument array
613 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
614 *
615 * Implement efidebug "images" sub-command.
616 * Show all UEFI loaded images and their information.
617 */
Simon Glass09140112020-05-10 11:40:03 -0600618static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag,
619 int argc, char *const argv[])
AKASHI Takahirofa536732019-02-25 15:54:42 +0900620{
621 efi_print_image_infos(NULL);
622
623 return CMD_RET_SUCCESS;
624}
625
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900626static const char * const efi_mem_type_string[] = {
627 [EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
628 [EFI_LOADER_CODE] = "LOADER CODE",
629 [EFI_LOADER_DATA] = "LOADER DATA",
630 [EFI_BOOT_SERVICES_CODE] = "BOOT CODE",
631 [EFI_BOOT_SERVICES_DATA] = "BOOT DATA",
632 [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE",
633 [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA",
634 [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL",
635 [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM",
636 [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM",
637 [EFI_ACPI_MEMORY_NVS] = "ACPI NVS",
638 [EFI_MMAP_IO] = "IO",
639 [EFI_MMAP_IO_PORT] = "IO PORT",
640 [EFI_PAL_CODE] = "PAL",
Heinrich Schuchardtdd9056c2020-04-29 20:21:39 +0200641 [EFI_PERSISTENT_MEMORY_TYPE] = "PERSISTENT",
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900642};
643
644static const struct efi_mem_attrs {
645 const u64 bit;
646 const char *text;
647} efi_mem_attrs[] = {
648 {EFI_MEMORY_UC, "UC"},
649 {EFI_MEMORY_UC, "UC"},
650 {EFI_MEMORY_WC, "WC"},
651 {EFI_MEMORY_WT, "WT"},
652 {EFI_MEMORY_WB, "WB"},
653 {EFI_MEMORY_UCE, "UCE"},
654 {EFI_MEMORY_WP, "WP"},
655 {EFI_MEMORY_RP, "RP"},
656 {EFI_MEMORY_XP, "WP"},
657 {EFI_MEMORY_NV, "NV"},
658 {EFI_MEMORY_MORE_RELIABLE, "REL"},
659 {EFI_MEMORY_RO, "RO"},
Heinrich Schuchardt255a4732020-05-19 07:20:46 +0200660 {EFI_MEMORY_SP, "SP"},
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900661 {EFI_MEMORY_RUNTIME, "RT"},
662};
663
664/**
665 * print_memory_attributes() - print memory map attributes
Heinrich Schuchardt0b016562019-07-14 14:00:41 +0200666 *
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900667 * @attributes: Attribute value
668 *
669 * Print memory map attributes
670 */
671static void print_memory_attributes(u64 attributes)
672{
673 int sep, i;
674
675 for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++)
676 if (attributes & efi_mem_attrs[i].bit) {
677 if (sep) {
678 putc('|');
679 } else {
680 putc(' ');
681 sep = 1;
682 }
683 puts(efi_mem_attrs[i].text);
684 }
685}
686
687#define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
688
689/**
690 * do_efi_show_memmap() - show UEFI memory map
691 *
692 * @cmdtp: Command table
693 * @flag: Command flag
694 * @argc: Number of arguments
695 * @argv: Argument array
696 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
697 *
698 * Implement efidebug "memmap" sub-command.
699 * Show UEFI memory map.
700 */
Simon Glass09140112020-05-10 11:40:03 -0600701static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag,
702 int argc, char *const argv[])
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900703{
704 struct efi_mem_desc *memmap = NULL, *map;
705 efi_uintn_t map_size = 0;
706 const char *type;
707 int i;
708 efi_status_t ret;
709
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200710 ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL);
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900711 if (ret == EFI_BUFFER_TOO_SMALL) {
712 map_size += sizeof(struct efi_mem_desc); /* for my own */
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200713 ret = efi_allocate_pool(EFI_LOADER_DATA, map_size,
714 (void *)&memmap);
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900715 if (ret != EFI_SUCCESS)
716 return CMD_RET_FAILURE;
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200717 ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL);
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900718 }
719 if (ret != EFI_SUCCESS) {
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200720 efi_free_pool(memmap);
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900721 return CMD_RET_FAILURE;
722 }
723
724 printf("Type Start%.*s End%.*s Attributes\n",
725 EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
726 printf("================ %.*s %.*s ==========\n",
727 EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
AKASHI Takahiroe2a5b862020-05-08 14:50:18 +0900728 /*
729 * Coverity check: dereferencing null pointer "map."
730 * This is a false positive as memmap will always be
731 * populated by allocate_pool() above.
732 */
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900733 for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
Heinrich Schuchardtdd9056c2020-04-29 20:21:39 +0200734 if (map->type < ARRAY_SIZE(efi_mem_type_string))
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900735 type = efi_mem_type_string[map->type];
736 else
737 type = "(unknown)";
738
739 printf("%-16s %.*llx-%.*llx", type,
740 EFI_PHYS_ADDR_WIDTH,
Heinrich Schuchardt6c0ef352020-03-27 04:33:17 +0000741 (u64)map_to_sysmem((void *)(uintptr_t)
742 map->physical_start),
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900743 EFI_PHYS_ADDR_WIDTH,
Heinrich Schuchardt6c0ef352020-03-27 04:33:17 +0000744 (u64)map_to_sysmem((void *)(uintptr_t)
745 (map->physical_start +
746 map->num_pages * EFI_PAGE_SIZE)));
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900747
748 print_memory_attributes(map->attribute);
749 putc('\n');
750 }
751
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200752 efi_free_pool(memmap);
AKASHI Takahiro00358bb2019-02-25 15:54:43 +0900753
754 return CMD_RET_SUCCESS;
755}
756
AKASHI Takahirofa536732019-02-25 15:54:42 +0900757/**
Heinrich Schuchardt986e0642020-01-07 05:57:47 +0100758 * do_efi_show_tables() - show UEFI configuration tables
759 *
760 * @cmdtp: Command table
761 * @flag: Command flag
762 * @argc: Number of arguments
763 * @argv: Argument array
764 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
765 *
766 * Implement efidebug "tables" sub-command.
767 * Show UEFI configuration tables.
768 */
Simon Glass09140112020-05-10 11:40:03 -0600769static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
770 int argc, char *const argv[])
Heinrich Schuchardt986e0642020-01-07 05:57:47 +0100771{
772 efi_uintn_t i;
773 const char *guid_str;
774
775 for (i = 0; i < systab.nr_tables; ++i) {
776 guid_str = get_guid_text(&systab.tables[i].guid);
777 if (!guid_str)
778 guid_str = "";
779 printf("%pUl %s\n", &systab.tables[i].guid, guid_str);
780 }
781
782 return CMD_RET_SUCCESS;
783}
784
785/**
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900786 * do_efi_boot_add() - set UEFI load option
787 *
788 * @cmdtp: Command table
789 * @flag: Command flag
790 * @argc: Number of arguments
791 * @argv: Argument array
792 * Return: CMD_RET_SUCCESS on success,
793 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
794 *
Heinrich Schuchardt0b016562019-07-14 14:00:41 +0200795 * Implement efidebug "boot add" sub-command. Create or change UEFI load option.
796 *
797 * efidebug boot add <id> <label> <interface> <devnum>[:<part>] <file> <options>
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900798 */
Simon Glass09140112020-05-10 11:40:03 -0600799static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
800 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900801{
802 int id;
803 char *endp;
804 char var_name[9];
805 u16 var_name16[9], *p;
806 efi_guid_t guid;
807 size_t label_len, label_len16;
808 u16 *label;
809 struct efi_device_path *device_path = NULL, *file_path = NULL;
810 struct efi_load_option lo;
811 void *data = NULL;
812 efi_uintn_t size;
Heinrich Schuchardt428a4702019-06-20 12:48:04 +0200813 efi_status_t ret;
Heinrich Schuchardta332f252019-06-20 12:59:45 +0200814 int r = CMD_RET_SUCCESS;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900815
816 if (argc < 6 || argc > 7)
817 return CMD_RET_USAGE;
818
819 id = (int)simple_strtoul(argv[1], &endp, 16);
820 if (*endp != '\0' || id > 0xffff)
Heinrich Schuchardt1fa442e2019-02-28 20:41:58 +0100821 return CMD_RET_USAGE;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900822
823 sprintf(var_name, "Boot%04X", id);
824 p = var_name16;
825 utf8_utf16_strncpy(&p, var_name, 9);
826
827 guid = efi_global_variable_guid;
828
829 /* attributes */
830 lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
831
832 /* label */
833 label_len = strlen(argv[2]);
834 label_len16 = utf8_utf16_strnlen(argv[2], label_len);
835 label = malloc((label_len16 + 1) * sizeof(u16));
836 if (!label)
837 return CMD_RET_FAILURE;
838 lo.label = label; /* label will be changed below */
839 utf8_utf16_strncpy(&label, argv[2], label_len);
840
841 /* file path */
842 ret = efi_dp_from_name(argv[3], argv[4], argv[5], &device_path,
843 &file_path);
844 if (ret != EFI_SUCCESS) {
845 printf("Cannot create device path for \"%s %s\"\n",
846 argv[3], argv[4]);
Heinrich Schuchardt428a4702019-06-20 12:48:04 +0200847 r = CMD_RET_FAILURE;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900848 goto out;
849 }
850 lo.file_path = file_path;
851 lo.file_path_length = efi_dp_size(file_path)
852 + sizeof(struct efi_device_path); /* for END */
853
854 /* optional data */
AKASHI Takahirod67591d2020-05-08 14:50:47 +0900855 if (argc == 6)
Heinrich Schuchardt39a1ff82019-04-29 13:51:45 +0200856 lo.optional_data = NULL;
857 else
858 lo.optional_data = (const u8 *)argv[6];
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900859
860 size = efi_serialize_load_option(&lo, (u8 **)&data);
861 if (!size) {
Heinrich Schuchardt428a4702019-06-20 12:48:04 +0200862 r = CMD_RET_FAILURE;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900863 goto out;
864 }
865
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200866 ret = EFI_CALL(efi_set_variable(var_name16, &guid,
AKASHI Takahirof658c2e2019-06-04 15:52:10 +0900867 EFI_VARIABLE_NON_VOLATILE |
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900868 EFI_VARIABLE_BOOTSERVICE_ACCESS |
869 EFI_VARIABLE_RUNTIME_ACCESS,
870 size, data));
Heinrich Schuchardta332f252019-06-20 12:59:45 +0200871 if (ret != EFI_SUCCESS) {
872 printf("Cannot set %ls\n", var_name16);
873 r = CMD_RET_FAILURE;
874 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900875out:
876 free(data);
877 efi_free_pool(device_path);
878 efi_free_pool(file_path);
879 free(lo.label);
880
Heinrich Schuchardt428a4702019-06-20 12:48:04 +0200881 return r;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900882}
883
884/**
885 * do_efi_boot_rm() - delete UEFI load options
886 *
887 * @cmdtp: Command table
888 * @flag: Command flag
889 * @argc: Number of arguments
890 * @argv: Argument array
891 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
892 *
893 * Implement efidebug "boot rm" sub-command.
894 * Delete UEFI load options.
Heinrich Schuchardt0b016562019-07-14 14:00:41 +0200895 *
896 * efidebug boot rm <id> ...
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900897 */
Simon Glass09140112020-05-10 11:40:03 -0600898static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
899 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900900{
901 efi_guid_t guid;
902 int id, i;
903 char *endp;
904 char var_name[9];
AKASHI Takahiroe8bced62020-02-28 09:05:04 +0900905 u16 var_name16[9], *p;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900906 efi_status_t ret;
907
908 if (argc == 1)
909 return CMD_RET_USAGE;
910
911 guid = efi_global_variable_guid;
912 for (i = 1; i < argc; i++, argv++) {
913 id = (int)simple_strtoul(argv[1], &endp, 16);
914 if (*endp != '\0' || id > 0xffff)
915 return CMD_RET_FAILURE;
916
917 sprintf(var_name, "Boot%04X", id);
AKASHI Takahiroe8bced62020-02-28 09:05:04 +0900918 p = var_name16;
919 utf8_utf16_strncpy(&p, var_name, 9);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900920
Heinrich Schuchardta30c7232020-05-02 16:08:37 +0200921 ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900922 if (ret) {
Heinrich Schuchardt30efb5d2020-03-02 20:13:10 +0100923 printf("Cannot remove %ls\n", var_name16);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900924 return CMD_RET_FAILURE;
925 }
926 }
927
928 return CMD_RET_SUCCESS;
929}
930
931/**
932 * show_efi_boot_opt_data() - dump UEFI load option
933 *
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +0200934 * @varname16: variable name
Heinrich Schuchardt39a1ff82019-04-29 13:51:45 +0200935 * @data: value of UEFI load option variable
936 * @size: size of the boot option
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900937 *
938 * Decode the value of UEFI load option variable and print information.
939 */
Heinrich Schuchardt0e69bcf2020-05-31 22:46:09 +0200940static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900941{
942 struct efi_load_option lo;
943 char *label, *p;
944 size_t label_len16, label_len;
945 u16 *dp_str;
Heinrich Schuchardt0e69bcf2020-05-31 22:46:09 +0200946 efi_status_t ret;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900947
Heinrich Schuchardt0e69bcf2020-05-31 22:46:09 +0200948 ret = efi_deserialize_load_option(&lo, data, size);
949 if (ret != EFI_SUCCESS) {
950 printf("%ls: invalid load option\n", varname16);
951 return;
952 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900953
954 label_len16 = u16_strlen(lo.label);
955 label_len = utf16_utf8_strnlen(lo.label, label_len16);
956 label = malloc(label_len + 1);
957 if (!label)
958 return;
959 p = label;
960 utf16_utf8_strncpy(&p, lo.label, label_len16);
961
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +0200962 printf("%ls:\nattributes: %c%c%c (0x%08x)\n",
963 varname16,
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900964 /* ACTIVE */
965 lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
966 /* FORCE RECONNECT */
967 lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-',
968 /* HIDDEN */
969 lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
970 lo.attributes);
Heinrich Schuchardt39a1ff82019-04-29 13:51:45 +0200971 printf(" label: %s\n", label);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900972
973 dp_str = efi_dp_str(lo.file_path);
Heinrich Schuchardt39a1ff82019-04-29 13:51:45 +0200974 printf(" file_path: %ls\n", dp_str);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900975 efi_free_pool(dp_str);
976
Heinrich Schuchardt39a1ff82019-04-29 13:51:45 +0200977 printf(" data:\n");
978 print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
Heinrich Schuchardt0e69bcf2020-05-31 22:46:09 +0200979 lo.optional_data, *size, true);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900980 free(label);
981}
982
983/**
984 * show_efi_boot_opt() - dump UEFI load option
985 *
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +0200986 * @varname16: variable name
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900987 *
988 * Dump information defined by UEFI load option.
989 */
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +0200990static void show_efi_boot_opt(u16 *varname16)
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900991{
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +0200992 void *data;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900993 efi_uintn_t size;
AKASHI Takahiro0bffb8c2019-11-26 10:11:22 +0900994 efi_status_t ret;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900995
AKASHI Takahiro59df7e72019-02-25 15:54:38 +0900996 size = 0;
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +0200997 ret = EFI_CALL(efi_get_variable(varname16, &efi_global_variable_guid,
998 NULL, &size, NULL));
AKASHI Takahiro0bffb8c2019-11-26 10:11:22 +0900999 if (ret == EFI_BUFFER_TOO_SMALL) {
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001000 data = malloc(size);
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +02001001 if (!data) {
1002 printf("ERROR: Out of memory\n");
1003 return;
1004 }
1005 ret = EFI_CALL(efi_get_variable(varname16,
1006 &efi_global_variable_guid,
1007 NULL, &size, data));
1008 if (ret == EFI_SUCCESS)
Heinrich Schuchardt0e69bcf2020-05-31 22:46:09 +02001009 show_efi_boot_opt_data(varname16, data, &size);
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +02001010 free(data);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001011 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001012}
1013
AKASHI Takahiroffe21572019-04-26 09:44:18 +09001014static int u16_tohex(u16 c)
1015{
1016 if (c >= '0' && c <= '9')
1017 return c - '0';
1018 if (c >= 'A' && c <= 'F')
1019 return c - 'A' + 10;
1020
1021 /* not hexadecimal */
1022 return -1;
1023}
1024
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001025/**
1026 * show_efi_boot_dump() - dump all UEFI load options
1027 *
1028 * @cmdtp: Command table
1029 * @flag: Command flag
1030 * @argc: Number of arguments
1031 * @argv: Argument array
1032 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1033 *
1034 * Implement efidebug "boot dump" sub-command.
1035 * Dump information of all UEFI load options defined.
Heinrich Schuchardta6ccba02019-07-25 20:52:23 +02001036 *
1037 * efidebug boot dump
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001038 */
Simon Glass09140112020-05-10 11:40:03 -06001039static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag,
1040 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001041{
AKASHI Takahiroffe21572019-04-26 09:44:18 +09001042 u16 *var_name16, *p;
1043 efi_uintn_t buf_size, size;
1044 efi_guid_t guid;
1045 int id, i, digit;
1046 efi_status_t ret;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001047
1048 if (argc > 1)
1049 return CMD_RET_USAGE;
1050
AKASHI Takahiroffe21572019-04-26 09:44:18 +09001051 buf_size = 128;
1052 var_name16 = malloc(buf_size);
1053 if (!var_name16)
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001054 return CMD_RET_FAILURE;
1055
AKASHI Takahiroffe21572019-04-26 09:44:18 +09001056 var_name16[0] = 0;
1057 for (;;) {
1058 size = buf_size;
1059 ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16,
1060 &guid));
1061 if (ret == EFI_NOT_FOUND)
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001062 break;
AKASHI Takahiroffe21572019-04-26 09:44:18 +09001063 if (ret == EFI_BUFFER_TOO_SMALL) {
1064 buf_size = size;
1065 p = realloc(var_name16, buf_size);
1066 if (!p) {
1067 free(var_name16);
1068 return CMD_RET_FAILURE;
1069 }
1070 var_name16 = p;
1071 ret = EFI_CALL(efi_get_next_variable_name(&size,
1072 var_name16,
1073 &guid));
1074 }
1075 if (ret != EFI_SUCCESS) {
1076 free(var_name16);
1077 return CMD_RET_FAILURE;
1078 }
1079
1080 if (memcmp(var_name16, L"Boot", 8))
1081 continue;
1082
1083 for (id = 0, i = 0; i < 4; i++) {
1084 digit = u16_tohex(var_name16[4 + i]);
1085 if (digit < 0)
1086 break;
1087 id = (id << 4) + digit;
1088 }
1089 if (i == 4 && !var_name16[8])
Heinrich Schuchardtb5f4e9e2020-04-29 19:20:35 +02001090 show_efi_boot_opt(var_name16);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001091 }
AKASHI Takahiroffe21572019-04-26 09:44:18 +09001092
1093 free(var_name16);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001094
1095 return CMD_RET_SUCCESS;
1096}
1097
1098/**
1099 * show_efi_boot_order() - show order of UEFI load options
1100 *
1101 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1102 *
1103 * Show order of UEFI load options defined by BootOrder variable.
1104 */
1105static int show_efi_boot_order(void)
1106{
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001107 u16 *bootorder;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001108 efi_uintn_t size;
1109 int num, i;
1110 char var_name[9];
1111 u16 var_name16[9], *p16;
1112 void *data;
1113 struct efi_load_option lo;
1114 char *label, *p;
1115 size_t label_len16, label_len;
1116 efi_status_t ret;
1117
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001118 size = 0;
Heinrich Schuchardta30c7232020-05-02 16:08:37 +02001119 ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid,
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001120 NULL, &size, NULL));
1121 if (ret != EFI_BUFFER_TOO_SMALL) {
1122 if (ret == EFI_NOT_FOUND) {
1123 printf("BootOrder not defined\n");
1124 return CMD_RET_SUCCESS;
1125 } else {
1126 return CMD_RET_FAILURE;
1127 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001128 }
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001129 bootorder = malloc(size);
1130 if (!bootorder) {
1131 printf("ERROR: Out of memory\n");
1132 return CMD_RET_FAILURE;
1133 }
1134 ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid,
1135 NULL, &size, bootorder));
1136 if (ret != EFI_SUCCESS) {
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001137 ret = CMD_RET_FAILURE;
1138 goto out;
1139 }
1140
1141 num = size / sizeof(u16);
1142 for (i = 0; i < num; i++) {
1143 sprintf(var_name, "Boot%04X", bootorder[i]);
1144 p16 = var_name16;
1145 utf8_utf16_strncpy(&p16, var_name, 9);
1146
1147 size = 0;
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001148 ret = EFI_CALL(efi_get_variable(var_name16,
1149 &efi_global_variable_guid, NULL,
1150 &size, NULL));
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001151 if (ret != EFI_BUFFER_TOO_SMALL) {
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001152 printf("%2d: %s: (not defined)\n", i + 1, var_name);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001153 continue;
1154 }
1155
1156 data = malloc(size);
1157 if (!data) {
1158 ret = CMD_RET_FAILURE;
1159 goto out;
1160 }
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001161 ret = EFI_CALL(efi_get_variable(var_name16,
1162 &efi_global_variable_guid, NULL,
1163 &size, data));
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001164 if (ret != EFI_SUCCESS) {
1165 free(data);
1166 ret = CMD_RET_FAILURE;
1167 goto out;
1168 }
1169
Heinrich Schuchardt0e69bcf2020-05-31 22:46:09 +02001170 ret = efi_deserialize_load_option(&lo, data, &size);
1171 if (ret != EFI_SUCCESS) {
1172 printf("%ls: invalid load option\n", var_name16);
1173 ret = CMD_RET_FAILURE;
1174 goto out;
1175 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001176
1177 label_len16 = u16_strlen(lo.label);
1178 label_len = utf16_utf8_strnlen(lo.label, label_len16);
1179 label = malloc(label_len + 1);
1180 if (!label) {
1181 free(data);
1182 ret = CMD_RET_FAILURE;
1183 goto out;
1184 }
1185 p = label;
1186 utf16_utf8_strncpy(&p, lo.label, label_len16);
Heinrich Schuchardtf9f5f922020-04-29 21:15:08 +02001187 printf("%2d: %s: %s\n", i + 1, var_name, label);
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001188 free(label);
1189
1190 free(data);
1191 }
1192out:
1193 free(bootorder);
1194
1195 return ret;
1196}
1197
1198/**
1199 * do_efi_boot_next() - manage UEFI BootNext variable
1200 *
1201 * @cmdtp: Command table
1202 * @flag: Command flag
1203 * @argc: Number of arguments
1204 * @argv: Argument array
1205 * Return: CMD_RET_SUCCESS on success,
1206 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1207 *
1208 * Implement efidebug "boot next" sub-command.
1209 * Set BootNext variable.
Heinrich Schuchardt0b016562019-07-14 14:00:41 +02001210 *
1211 * efidebug boot next <id>
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001212 */
Simon Glass09140112020-05-10 11:40:03 -06001213static int do_efi_boot_next(struct cmd_tbl *cmdtp, int flag,
1214 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001215{
1216 u16 bootnext;
1217 efi_uintn_t size;
1218 char *endp;
1219 efi_guid_t guid;
1220 efi_status_t ret;
Heinrich Schuchardta332f252019-06-20 12:59:45 +02001221 int r = CMD_RET_SUCCESS;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001222
1223 if (argc != 2)
1224 return CMD_RET_USAGE;
1225
1226 bootnext = (u16)simple_strtoul(argv[1], &endp, 16);
Heinrich Schuchardtbdb15772020-05-09 17:59:19 +02001227 if (*endp) {
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001228 printf("invalid value: %s\n", argv[1]);
Heinrich Schuchardt428a4702019-06-20 12:48:04 +02001229 r = CMD_RET_FAILURE;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001230 goto out;
1231 }
1232
1233 guid = efi_global_variable_guid;
1234 size = sizeof(u16);
Heinrich Schuchardta30c7232020-05-02 16:08:37 +02001235 ret = EFI_CALL(efi_set_variable(L"BootNext", &guid,
AKASHI Takahirof658c2e2019-06-04 15:52:10 +09001236 EFI_VARIABLE_NON_VOLATILE |
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001237 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1238 EFI_VARIABLE_RUNTIME_ACCESS,
1239 size, &bootnext));
Heinrich Schuchardta332f252019-06-20 12:59:45 +02001240 if (ret != EFI_SUCCESS) {
1241 printf("Cannot set BootNext\n");
1242 r = CMD_RET_FAILURE;
1243 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001244out:
Heinrich Schuchardt428a4702019-06-20 12:48:04 +02001245 return r;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001246}
1247
1248/**
1249 * do_efi_boot_order() - manage UEFI BootOrder variable
1250 *
1251 * @cmdtp: Command table
1252 * @flag: Command flag
1253 * @argc: Number of arguments
1254 * @argv: Argument array
1255 * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
1256 *
1257 * Implement efidebug "boot order" sub-command.
1258 * Show order of UEFI load options, or change it in BootOrder variable.
Heinrich Schuchardt0b016562019-07-14 14:00:41 +02001259 *
1260 * efidebug boot order [<id> ...]
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001261 */
Simon Glass09140112020-05-10 11:40:03 -06001262static int do_efi_boot_order(struct cmd_tbl *cmdtp, int flag,
1263 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001264{
1265 u16 *bootorder = NULL;
1266 efi_uintn_t size;
1267 int id, i;
1268 char *endp;
1269 efi_guid_t guid;
1270 efi_status_t ret;
Heinrich Schuchardta332f252019-06-20 12:59:45 +02001271 int r = CMD_RET_SUCCESS;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001272
1273 if (argc == 1)
1274 return show_efi_boot_order();
1275
1276 argc--;
1277 argv++;
1278
1279 size = argc * sizeof(u16);
1280 bootorder = malloc(size);
1281 if (!bootorder)
1282 return CMD_RET_FAILURE;
1283
1284 for (i = 0; i < argc; i++) {
1285 id = (int)simple_strtoul(argv[i], &endp, 16);
1286 if (*endp != '\0' || id > 0xffff) {
1287 printf("invalid value: %s\n", argv[i]);
Heinrich Schuchardt428a4702019-06-20 12:48:04 +02001288 r = CMD_RET_FAILURE;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001289 goto out;
1290 }
1291
1292 bootorder[i] = (u16)id;
1293 }
1294
1295 guid = efi_global_variable_guid;
Heinrich Schuchardta30c7232020-05-02 16:08:37 +02001296 ret = EFI_CALL(efi_set_variable(L"BootOrder", &guid,
AKASHI Takahirof658c2e2019-06-04 15:52:10 +09001297 EFI_VARIABLE_NON_VOLATILE |
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001298 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1299 EFI_VARIABLE_RUNTIME_ACCESS,
1300 size, bootorder));
Heinrich Schuchardta332f252019-06-20 12:59:45 +02001301 if (ret != EFI_SUCCESS) {
1302 printf("Cannot set BootOrder\n");
1303 r = CMD_RET_FAILURE;
1304 }
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001305out:
1306 free(bootorder);
1307
Heinrich Schuchardt428a4702019-06-20 12:48:04 +02001308 return r;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001309}
1310
Simon Glass09140112020-05-10 11:40:03 -06001311static struct cmd_tbl cmd_efidebug_boot_sub[] = {
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001312 U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""),
1313 U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""),
1314 U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""),
1315 U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""),
1316 U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order,
1317 "", ""),
1318};
1319
1320/**
1321 * do_efi_boot_opt() - manage UEFI load options
1322 *
1323 * @cmdtp: Command table
1324 * @flag: Command flag
1325 * @argc: Number of arguments
1326 * @argv: Argument array
1327 * Return: CMD_RET_SUCCESS on success,
1328 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1329 *
1330 * Implement efidebug "boot" sub-command.
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001331 */
Simon Glass09140112020-05-10 11:40:03 -06001332static int do_efi_boot_opt(struct cmd_tbl *cmdtp, int flag,
1333 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001334{
Simon Glass09140112020-05-10 11:40:03 -06001335 struct cmd_tbl *cp;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001336
1337 if (argc < 2)
1338 return CMD_RET_USAGE;
1339
1340 argc--; argv++;
1341
1342 cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub,
1343 ARRAY_SIZE(cmd_efidebug_boot_sub));
1344 if (!cp)
1345 return CMD_RET_USAGE;
1346
1347 return cp->cmd(cmdtp, flag, argc, argv);
1348}
1349
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001350/**
1351 * do_efi_test_bootmgr() - run simple bootmgr for test
1352 *
1353 * @cmdtp: Command table
1354 * @flag: Command flag
1355 * @argc: Number of arguments
1356 * @argv: Argument array
1357 * Return: CMD_RET_SUCCESS on success,
1358 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1359 *
1360 * Implement efidebug "test bootmgr" sub-command.
1361 * Run simple bootmgr for test.
1362 *
1363 * efidebug test bootmgr
1364 */
Simon Glass09140112020-05-10 11:40:03 -06001365static int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag,
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001366 int argc, char * const argv[])
1367{
1368 efi_handle_t image;
1369 efi_uintn_t exit_data_size = 0;
1370 u16 *exit_data = NULL;
1371 efi_status_t ret;
Heinrich Schuchardtbc78d222020-08-11 18:20:50 +02001372 void *load_options = NULL;
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001373
Heinrich Schuchardt0ad64002020-08-07 17:49:39 +02001374 ret = efi_bootmgr_load(&image, &load_options);
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001375 printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK);
1376
1377 /* We call efi_start_image() even if error for test purpose. */
1378 ret = EFI_CALL(efi_start_image(image, &exit_data_size, &exit_data));
1379 printf("efi_start_image() returned: %ld\n", ret & ~EFI_ERROR_MASK);
1380 if (ret && exit_data)
1381 efi_free_pool(exit_data);
1382
1383 efi_restore_gd();
1384
Heinrich Schuchardt0ad64002020-08-07 17:49:39 +02001385 free(load_options);
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001386 return CMD_RET_SUCCESS;
1387}
1388
Simon Glass09140112020-05-10 11:40:03 -06001389static struct cmd_tbl cmd_efidebug_test_sub[] = {
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001390 U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr,
1391 "", ""),
1392};
1393
1394/**
1395 * do_efi_test() - manage UEFI load options
1396 *
1397 * @cmdtp: Command table
1398 * @flag: Command flag
1399 * @argc: Number of arguments
1400 * @argv: Argument array
1401 * Return: CMD_RET_SUCCESS on success,
1402 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1403 *
1404 * Implement efidebug "test" sub-command.
1405 */
Simon Glass09140112020-05-10 11:40:03 -06001406static int do_efi_test(struct cmd_tbl *cmdtp, int flag,
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001407 int argc, char * const argv[])
1408{
Simon Glass09140112020-05-10 11:40:03 -06001409 struct cmd_tbl *cp;
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001410
1411 if (argc < 2)
1412 return CMD_RET_USAGE;
1413
1414 argc--; argv++;
1415
1416 cp = find_cmd_tbl(argv[0], cmd_efidebug_test_sub,
1417 ARRAY_SIZE(cmd_efidebug_test_sub));
1418 if (!cp)
1419 return CMD_RET_USAGE;
1420
1421 return cp->cmd(cmdtp, flag, argc, argv);
1422}
1423
Ilias Apalodimasb0e4f2c2020-05-17 22:25:45 +03001424/**
1425 * do_efi_query_info() - QueryVariableInfo EFI service
1426 *
1427 * @cmdtp: Command table
1428 * @flag: Command flag
1429 * @argc: Number of arguments
1430 * @argv: Argument array
1431 * Return: CMD_RET_SUCCESS on success,
1432 * CMD_RET_USAGE or CMD_RET_FAILURE on failure
1433 *
1434 * Implement efidebug "test" sub-command.
1435 */
1436
Simon Glass09140112020-05-10 11:40:03 -06001437static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag,
Ilias Apalodimasb0e4f2c2020-05-17 22:25:45 +03001438 int argc, char * const argv[])
1439{
1440 efi_status_t ret;
1441 u32 attr = 0;
1442 u64 max_variable_storage_size;
1443 u64 remain_variable_storage_size;
1444 u64 max_variable_size;
1445 int i;
1446
1447 for (i = 1; i < argc; i++) {
1448 if (!strcmp(argv[i], "-bs"))
1449 attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
1450 else if (!strcmp(argv[i], "-rt"))
1451 attr |= EFI_VARIABLE_RUNTIME_ACCESS;
1452 else if (!strcmp(argv[i], "-nv"))
1453 attr |= EFI_VARIABLE_NON_VOLATILE;
1454 else if (!strcmp(argv[i], "-at"))
1455 attr |=
1456 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
1457 }
1458
1459 ret = EFI_CALL(efi_query_variable_info(attr,
1460 &max_variable_storage_size,
1461 &remain_variable_storage_size,
1462 &max_variable_size));
1463 if (ret != EFI_SUCCESS) {
1464 printf("Error: Cannot query UEFI variables, r = %lu\n",
1465 ret & ~EFI_ERROR_MASK);
1466 return CMD_RET_FAILURE;
1467 }
1468
1469 printf("Max storage size %llu\n", max_variable_storage_size);
1470 printf("Remaining storage size %llu\n", remain_variable_storage_size);
1471 printf("Max variable size %llu\n", max_variable_size);
1472
1473 return CMD_RET_SUCCESS;
1474}
1475
Simon Glass09140112020-05-10 11:40:03 -06001476static struct cmd_tbl cmd_efidebug_sub[] = {
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001477 U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
AKASHI Takahiro7f35ced2020-11-17 09:28:01 +09001478#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
1479 U_BOOT_CMD_MKENT(capsule, CONFIG_SYS_MAXARGS, 1, do_efi_capsule,
1480 "", ""),
1481#endif
AKASHI Takahiro355cdb52019-02-25 15:54:39 +09001482 U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
1483 "", ""),
AKASHI Takahiro66eaf562019-02-25 15:54:40 +09001484 U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
1485 "", ""),
AKASHI Takahiroa8014622019-02-25 15:54:41 +09001486 U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
1487 "", ""),
AKASHI Takahirofa536732019-02-25 15:54:42 +09001488 U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
1489 "", ""),
AKASHI Takahiro00358bb2019-02-25 15:54:43 +09001490 U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
1491 "", ""),
Heinrich Schuchardt986e0642020-01-07 05:57:47 +01001492 U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables,
1493 "", ""),
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001494 U_BOOT_CMD_MKENT(test, CONFIG_SYS_MAXARGS, 1, do_efi_test,
1495 "", ""),
Ilias Apalodimasb0e4f2c2020-05-17 22:25:45 +03001496 U_BOOT_CMD_MKENT(query, CONFIG_SYS_MAXARGS, 1, do_efi_query_info,
1497 "", ""),
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001498};
1499
1500/**
1501 * do_efidebug() - display and configure UEFI environment
1502 *
1503 * @cmdtp: Command table
1504 * @flag: Command flag
1505 * @argc: Number of arguments
1506 * @argv: Argument array
1507 * Return: CMD_RET_SUCCESS on success,
1508 * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
1509 *
1510 * Implement efidebug command which allows us to display and
1511 * configure UEFI environment.
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001512 */
Simon Glass09140112020-05-10 11:40:03 -06001513static int do_efidebug(struct cmd_tbl *cmdtp, int flag,
1514 int argc, char *const argv[])
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001515{
Simon Glass09140112020-05-10 11:40:03 -06001516 struct cmd_tbl *cp;
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001517 efi_status_t r;
1518
1519 if (argc < 2)
1520 return CMD_RET_USAGE;
1521
1522 argc--; argv++;
1523
1524 /* Initialize UEFI drivers */
1525 r = efi_init_obj_list();
1526 if (r != EFI_SUCCESS) {
1527 printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
1528 r & ~EFI_ERROR_MASK);
1529 return CMD_RET_FAILURE;
1530 }
1531
1532 cp = find_cmd_tbl(argv[0], cmd_efidebug_sub,
1533 ARRAY_SIZE(cmd_efidebug_sub));
1534 if (!cp)
1535 return CMD_RET_USAGE;
1536
1537 return cp->cmd(cmdtp, flag, argc, argv);
1538}
1539
1540#ifdef CONFIG_SYS_LONGHELP
1541static char efidebug_help_text[] =
1542 " - UEFI Shell-like interface to configure UEFI environment\n"
1543 "\n"
1544 "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>]\n"
1545 " - set UEFI BootXXXX variable\n"
1546 " <load options> will be passed to UEFI application\n"
1547 "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
1548 " - delete UEFI BootXXXX variables\n"
1549 "efidebug boot dump\n"
1550 " - dump all UEFI BootXXXX variables\n"
1551 "efidebug boot next <bootid>\n"
1552 " - set UEFI BootNext variable\n"
1553 "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
1554 " - set/show UEFI boot order\n"
AKASHI Takahiro355cdb52019-02-25 15:54:39 +09001555 "\n"
AKASHI Takahiro7f35ced2020-11-17 09:28:01 +09001556#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
1557 "efidebug capsule update [-v] <capsule address>\n"
1558 " - process a capsule\n"
Sughosh Ganu74075952020-12-30 19:27:11 +05301559 "efidebug capsule disk-update\n"
1560 " - update a capsule from disk\n"
AKASHI Takahiro7f35ced2020-11-17 09:28:01 +09001561 "efidebug capsule show <capsule address>\n"
1562 " - show capsule information\n"
1563 "efidebug capsule result [<capsule result var>]\n"
1564 " - show a capsule update result\n"
1565 "\n"
1566#endif
AKASHI Takahiro355cdb52019-02-25 15:54:39 +09001567 "efidebug devices\n"
Heinrich Schuchardt07e2fe72020-01-07 07:48:15 +01001568 " - show UEFI devices\n"
AKASHI Takahiro66eaf562019-02-25 15:54:40 +09001569 "efidebug drivers\n"
Heinrich Schuchardt07e2fe72020-01-07 07:48:15 +01001570 " - show UEFI drivers\n"
AKASHI Takahiroa8014622019-02-25 15:54:41 +09001571 "efidebug dh\n"
Heinrich Schuchardt07e2fe72020-01-07 07:48:15 +01001572 " - show UEFI handles\n"
AKASHI Takahirofa536732019-02-25 15:54:42 +09001573 "efidebug images\n"
AKASHI Takahiro00358bb2019-02-25 15:54:43 +09001574 " - show loaded images\n"
1575 "efidebug memmap\n"
Heinrich Schuchardt07e2fe72020-01-07 07:48:15 +01001576 " - show UEFI memory map\n"
Heinrich Schuchardt986e0642020-01-07 05:57:47 +01001577 "efidebug tables\n"
AKASHI Takahiro525fc062020-04-14 11:51:48 +09001578 " - show UEFI configuration tables\n"
1579 "efidebug test bootmgr\n"
Ilias Apalodimasb0e4f2c2020-05-17 22:25:45 +03001580 " - run simple bootmgr for test\n"
1581 "efidebug query [-nv][-bs][-rt][-at]\n"
1582 " - show size of UEFI variables store\n";
AKASHI Takahiro59df7e72019-02-25 15:54:38 +09001583#endif
1584
1585U_BOOT_CMD(
1586 efidebug, 10, 0, do_efidebug,
1587 "Configure UEFI environment",
1588 efidebug_help_text
1589);