Blame view
cmd/efidebug.c
27.2 KB
59df7e7e7 cmd: add efidebug... |
1 2 3 4 5 6 7 8 9 10 11 |
// SPDX-License-Identifier: GPL-2.0+ /* * UEFI Shell-like command * * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited */ #include <charset.h> #include <common.h> #include <command.h> #include <efi_loader.h> |
59df7e7e7 cmd: add efidebug... |
12 |
#include <exports.h> |
39a1ff8ce efi_loader: optio... |
13 |
#include <hexdump.h> |
59df7e7e7 cmd: add efidebug... |
14 |
#include <malloc.h> |
a415d61ea cmd: map addresse... |
15 |
#include <mapmem.h> |
59df7e7e7 cmd: add efidebug... |
16 17 |
#include <search.h> #include <linux/ctype.h> |
355cdb5a7 cmd: efidebug: ad... |
18 |
#define BS systab.boottime |
59df7e7e7 cmd: add efidebug... |
19 20 21 |
#define RT systab.runtime /** |
355cdb5a7 cmd: efidebug: ad... |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
* efi_get_device_handle_info() - get information of UEFI device * * @handle: Handle of UEFI device * @dev_path_text: Pointer to text of device path * Return: 0 on success, -1 on failure * * Currently return a formatted text of device path. */ static int efi_get_device_handle_info(efi_handle_t handle, u16 **dev_path_text) { struct efi_device_path *dp; efi_status_t ret; ret = EFI_CALL(BS->open_protocol(handle, &efi_guid_device_path, (void **)&dp, NULL /* FIXME */, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL)); if (ret == EFI_SUCCESS) { *dev_path_text = efi_dp_str(dp); return 0; } else { return -1; } } #define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2) static const char spc[] = " "; static const char sep[] = "================"; /** * do_efi_show_devices() - show UEFI devices * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "devices" sub-command. * Show all UEFI devices and their information. */ static int do_efi_show_devices(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { efi_handle_t *handles; efi_uintn_t num, i; u16 *dev_path_text; efi_status_t ret; ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL, &num, &handles)); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; if (!num) return CMD_RET_SUCCESS; printf("Device%.*s Device Path ", EFI_HANDLE_WIDTH - 6, spc); printf("%.*s ==================== ", EFI_HANDLE_WIDTH, sep); for (i = 0; i < num; i++) { if (!efi_get_device_handle_info(handles[i], &dev_path_text)) { printf("%p %ls ", handles[i], dev_path_text); efi_free_pool(dev_path_text); } } EFI_CALL(BS->free_pool(handles)); return CMD_RET_SUCCESS; } /** |
66eaf5664 cmd: efidebug: ad... |
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
* efi_get_driver_handle_info() - get information of UEFI driver * * @handle: Handle of UEFI device * @driver_name: Driver name * @image_path: Pointer to text of device path * Return: 0 on success, -1 on failure * * Currently return no useful information as all UEFI drivers are * built-in.. */ static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name, u16 **image_path) { struct efi_handler *handler; struct efi_loaded_image *image; efi_status_t ret; /* * driver name * TODO: support EFI_COMPONENT_NAME2_PROTOCOL */ *driver_name = NULL; /* image name */ ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler); if (ret != EFI_SUCCESS) { *image_path = NULL; return 0; } image = handler->protocol_interface; *image_path = efi_dp_str(image->file_path); return 0; } /** * do_efi_show_drivers() - show UEFI drivers * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "drivers" sub-command. * Show all UEFI drivers and their information. */ static int do_efi_show_drivers(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { efi_handle_t *handles; efi_uintn_t num, i; u16 *driver_name, *image_path_text; efi_status_t ret; ret = EFI_CALL(BS->locate_handle_buffer( BY_PROTOCOL, &efi_guid_driver_binding_protocol, NULL, &num, &handles)); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; if (!num) return CMD_RET_SUCCESS; printf("Driver%.*s Name Image Path ", EFI_HANDLE_WIDTH - 6, spc); printf("%.*s ==================== ==================== ", EFI_HANDLE_WIDTH, sep); for (i = 0; i < num; i++) { if (!efi_get_driver_handle_info(handles[i], &driver_name, &image_path_text)) { if (image_path_text) printf("%p %-20ls %ls ", handles[i], driver_name, image_path_text); else printf("%p %-20ls <built-in> ", handles[i], driver_name); EFI_CALL(BS->free_pool(driver_name)); EFI_CALL(BS->free_pool(image_path_text)); } } EFI_CALL(BS->free_pool(handles)); return CMD_RET_SUCCESS; } |
a80146205 cmd: efidebug: ad... |
188 189 190 191 192 193 |
static const struct { const char *text; const efi_guid_t guid; } guid_list[] = { { "Device Path", |
dec88e41e efi_loader: consi... |
194 |
EFI_DEVICE_PATH_PROTOCOL_GUID, |
a80146205 cmd: efidebug: ad... |
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
}, { "Device Path To Text", EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, }, { "Device Path Utilities", EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, }, { "Unicode Collation 2", EFI_UNICODE_COLLATION_PROTOCOL2_GUID, }, { "Driver Binding", EFI_DRIVER_BINDING_PROTOCOL_GUID, }, { "Simple Text Input", EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, }, { "Simple Text Input Ex", EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, }, { "Simple Text Output", EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, }, { "Block IO", |
dec88e41e efi_loader: consi... |
226 |
EFI_BLOCK_IO_PROTOCOL_GUID, |
a80146205 cmd: efidebug: ad... |
227 228 229 230 231 232 233 |
}, { "Simple File System", EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, }, { "Loaded Image", |
dec88e41e efi_loader: consi... |
234 |
EFI_LOADED_IMAGE_PROTOCOL_GUID, |
a80146205 cmd: efidebug: ad... |
235 236 |
}, { |
dec88e41e efi_loader: consi... |
237 238 |
"Graphics Output", EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, |
a80146205 cmd: efidebug: ad... |
239 |
}, |
391bc8a93 efi_loader: more ... |
240 241 242 243 244 245 246 247 248 249 250 251 252 |
{ "HII String", EFI_HII_STRING_PROTOCOL_GUID, }, { "HII Database", EFI_HII_DATABASE_PROTOCOL_GUID, }, { "HII Config Routing", EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, }, { |
ec80b4735 efi_loader: Imple... |
253 254 255 256 |
"Load File2", EFI_LOAD_FILE2_PROTOCOL_GUID, }, { |
391bc8a93 efi_loader: more ... |
257 258 259 260 261 262 263 |
"Simple Network", EFI_SIMPLE_NETWORK_PROTOCOL_GUID, }, { "PXE Base Code", EFI_PXE_BASE_CODE_PROTOCOL_GUID, }, |
986e06488 cmd: efidebug: ne... |
264 265 266 267 268 269 270 271 272 273 274 275 276 |
/* Configuration table GUIDs */ { "ACPI table", EFI_ACPI_TABLE_GUID, }, { "device tree", EFI_FDT_GUID, }, { "SMBIOS table", SMBIOS_TABLE_GUID, }, |
76be68728 efi_loader: imple... |
277 278 279 280 |
{ "Runtime properties", EFI_RT_PROPERTIES_TABLE_GUID, }, |
a80146205 cmd: efidebug: ad... |
281 282 283 |
}; /** |
173cd9e73 cmd: efidebug: si... |
284 |
* get_guid_text - get string of GUID |
a80146205 cmd: efidebug: ad... |
285 |
* |
173cd9e73 cmd: efidebug: si... |
286 287 288 289 |
* Return description of GUID. * * @guid: GUID * Return: description of GUID or NULL |
a80146205 cmd: efidebug: ad... |
290 |
*/ |
173cd9e73 cmd: efidebug: si... |
291 |
static const char *get_guid_text(const void *guid) |
a80146205 cmd: efidebug: ad... |
292 293 |
{ int i; |
173cd9e73 cmd: efidebug: si... |
294 295 296 297 298 |
for (i = 0; i < ARRAY_SIZE(guid_list); i++) { /* * As guidcmp uses memcmp() we can safely accept unaligned * GUIDs. */ |
a80146205 cmd: efidebug: ad... |
299 |
if (!guidcmp(&guid_list[i].guid, guid)) |
173cd9e73 cmd: efidebug: si... |
300 301 |
return guid_list[i].text; } |
a80146205 cmd: efidebug: ad... |
302 |
|
173cd9e73 cmd: efidebug: si... |
303 |
return NULL; |
a80146205 cmd: efidebug: ad... |
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
} /** * do_efi_show_handles() - show UEFI handles * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "dh" sub-command. * Show all UEFI handles and their information, currently all protocols * added to handle. */ static int do_efi_show_handles(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { efi_handle_t *handles; efi_guid_t **guid; efi_uintn_t num, count, i, j; const char *guid_text; efi_status_t ret; ret = EFI_CALL(BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL, &num, &handles)); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; if (!num) return CMD_RET_SUCCESS; printf("Handle%.*s Protocols ", EFI_HANDLE_WIDTH - 6, spc); printf("%.*s ==================== ", EFI_HANDLE_WIDTH, sep); for (i = 0; i < num; i++) { printf("%p", handles[i]); ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid, &count)); if (ret || !count) { putc(' '); continue; } for (j = 0; j < count; j++) { if (j) printf(", "); else putc(' '); guid_text = get_guid_text(guid[j]); if (guid_text) puts(guid_text); else printf("%pUl", guid[j]); } putc(' '); } EFI_CALL(BS->free_pool(handles)); return CMD_RET_SUCCESS; } |
66eaf5664 cmd: efidebug: ad... |
370 |
/** |
fa5367342 cmd: efidebug: ad... |
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
* do_efi_show_images() - show UEFI images * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "images" sub-command. * Show all UEFI loaded images and their information. */ static int do_efi_show_images(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { efi_print_image_infos(NULL); return CMD_RET_SUCCESS; } |
00358bb80 cmd: efidebug: ad... |
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
static const char * const efi_mem_type_string[] = { [EFI_RESERVED_MEMORY_TYPE] = "RESERVED", [EFI_LOADER_CODE] = "LOADER CODE", [EFI_LOADER_DATA] = "LOADER DATA", [EFI_BOOT_SERVICES_CODE] = "BOOT CODE", [EFI_BOOT_SERVICES_DATA] = "BOOT DATA", [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE", [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA", [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL", [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM", [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM", [EFI_ACPI_MEMORY_NVS] = "ACPI NVS", [EFI_MMAP_IO] = "IO", [EFI_MMAP_IO_PORT] = "IO PORT", [EFI_PAL_CODE] = "PAL", }; static const struct efi_mem_attrs { const u64 bit; const char *text; } efi_mem_attrs[] = { {EFI_MEMORY_UC, "UC"}, {EFI_MEMORY_UC, "UC"}, {EFI_MEMORY_WC, "WC"}, {EFI_MEMORY_WT, "WT"}, {EFI_MEMORY_WB, "WB"}, {EFI_MEMORY_UCE, "UCE"}, {EFI_MEMORY_WP, "WP"}, {EFI_MEMORY_RP, "RP"}, {EFI_MEMORY_XP, "WP"}, {EFI_MEMORY_NV, "NV"}, {EFI_MEMORY_MORE_RELIABLE, "REL"}, {EFI_MEMORY_RO, "RO"}, {EFI_MEMORY_RUNTIME, "RT"}, }; /** * print_memory_attributes() - print memory map attributes |
0b0165692 efi_loader: funct... |
427 |
* |
00358bb80 cmd: efidebug: ad... |
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
* @attributes: Attribute value * * Print memory map attributes */ static void print_memory_attributes(u64 attributes) { int sep, i; for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++) if (attributes & efi_mem_attrs[i].bit) { if (sep) { putc('|'); } else { putc(' '); sep = 1; } puts(efi_mem_attrs[i].text); } } #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2) /** * do_efi_show_memmap() - show UEFI memory map * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "memmap" sub-command. * Show UEFI memory map. */ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct efi_mem_desc *memmap = NULL, *map; efi_uintn_t map_size = 0; const char *type; int i; efi_status_t ret; ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL, NULL, NULL)); if (ret == EFI_BUFFER_TOO_SMALL) { map_size += sizeof(struct efi_mem_desc); /* for my own */ ret = EFI_CALL(BS->allocate_pool(EFI_LOADER_DATA, map_size, (void *)&memmap)); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL, NULL, NULL)); } if (ret != EFI_SUCCESS) { EFI_CALL(BS->free_pool(memmap)); return CMD_RET_FAILURE; } printf("Type Start%.*s End%.*s Attributes ", EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc); printf("================ %.*s %.*s ========== ", EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep); for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) { if (map->type < EFI_MAX_MEMORY_TYPE) type = efi_mem_type_string[map->type]; else type = "(unknown)"; printf("%-16s %.*llx-%.*llx", type, EFI_PHYS_ADDR_WIDTH, |
6c0ef35cd cmd: efidebug: fi... |
500 501 |
(u64)map_to_sysmem((void *)(uintptr_t) map->physical_start), |
00358bb80 cmd: efidebug: ad... |
502 |
EFI_PHYS_ADDR_WIDTH, |
6c0ef35cd cmd: efidebug: fi... |
503 504 505 |
(u64)map_to_sysmem((void *)(uintptr_t) (map->physical_start + map->num_pages * EFI_PAGE_SIZE))); |
00358bb80 cmd: efidebug: ad... |
506 507 508 509 510 511 512 513 514 515 |
print_memory_attributes(map->attribute); putc(' '); } EFI_CALL(BS->free_pool(memmap)); return CMD_RET_SUCCESS; } |
fa5367342 cmd: efidebug: ad... |
516 |
/** |
986e06488 cmd: efidebug: ne... |
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
* do_efi_show_tables() - show UEFI configuration tables * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "tables" sub-command. * Show UEFI configuration tables. */ static int do_efi_show_tables(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { efi_uintn_t i; const char *guid_str; for (i = 0; i < systab.nr_tables; ++i) { guid_str = get_guid_text(&systab.tables[i].guid); if (!guid_str) guid_str = ""; printf("%pUl %s ", &systab.tables[i].guid, guid_str); } return CMD_RET_SUCCESS; } /** |
59df7e7e7 cmd: add efidebug... |
546 547 548 549 550 551 552 553 554 |
* do_efi_boot_add() - set UEFI load option * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure * |
0b0165692 efi_loader: funct... |
555 556 557 |
* Implement efidebug "boot add" sub-command. Create or change UEFI load option. * * efidebug boot add <id> <label> <interface> <devnum>[:<part>] <file> <options> |
59df7e7e7 cmd: add efidebug... |
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
*/ static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int id; char *endp; char var_name[9]; u16 var_name16[9], *p; efi_guid_t guid; size_t label_len, label_len16; u16 *label; struct efi_device_path *device_path = NULL, *file_path = NULL; struct efi_load_option lo; void *data = NULL; efi_uintn_t size; |
428a470a2 efi_loader: consi... |
573 |
efi_status_t ret; |
a332f2519 efi_loader: consi... |
574 |
int r = CMD_RET_SUCCESS; |
59df7e7e7 cmd: add efidebug... |
575 576 577 578 579 580 |
if (argc < 6 || argc > 7) return CMD_RET_USAGE; id = (int)simple_strtoul(argv[1], &endp, 16); if (*endp != '\0' || id > 0xffff) |
1fa442ed4 efi_loader: error... |
581 |
return CMD_RET_USAGE; |
59df7e7e7 cmd: add efidebug... |
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
sprintf(var_name, "Boot%04X", id); p = var_name16; utf8_utf16_strncpy(&p, var_name, 9); guid = efi_global_variable_guid; /* attributes */ lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */ /* label */ label_len = strlen(argv[2]); label_len16 = utf8_utf16_strnlen(argv[2], label_len); label = malloc((label_len16 + 1) * sizeof(u16)); if (!label) return CMD_RET_FAILURE; lo.label = label; /* label will be changed below */ utf8_utf16_strncpy(&label, argv[2], label_len); /* file path */ ret = efi_dp_from_name(argv[3], argv[4], argv[5], &device_path, &file_path); if (ret != EFI_SUCCESS) { printf("Cannot create device path for \"%s %s\" ", argv[3], argv[4]); |
428a470a2 efi_loader: consi... |
608 |
r = CMD_RET_FAILURE; |
59df7e7e7 cmd: add efidebug... |
609 610 611 612 613 614 615 |
goto out; } lo.file_path = file_path; lo.file_path_length = efi_dp_size(file_path) + sizeof(struct efi_device_path); /* for END */ /* optional data */ |
39a1ff8ce efi_loader: optio... |
616 617 618 619 |
if (argc < 6) lo.optional_data = NULL; else lo.optional_data = (const u8 *)argv[6]; |
59df7e7e7 cmd: add efidebug... |
620 621 622 |
size = efi_serialize_load_option(&lo, (u8 **)&data); if (!size) { |
428a470a2 efi_loader: consi... |
623 |
r = CMD_RET_FAILURE; |
59df7e7e7 cmd: add efidebug... |
624 625 626 627 |
goto out; } ret = EFI_CALL(RT->set_variable(var_name16, &guid, |
f658c2e19 cmd: efidebug: ma... |
628 |
EFI_VARIABLE_NON_VOLATILE | |
59df7e7e7 cmd: add efidebug... |
629 630 631 |
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, data)); |
a332f2519 efi_loader: consi... |
632 633 634 635 636 |
if (ret != EFI_SUCCESS) { printf("Cannot set %ls ", var_name16); r = CMD_RET_FAILURE; } |
59df7e7e7 cmd: add efidebug... |
637 638 639 640 641 |
out: free(data); efi_free_pool(device_path); efi_free_pool(file_path); free(lo.label); |
428a470a2 efi_loader: consi... |
642 |
return r; |
59df7e7e7 cmd: add efidebug... |
643 644 645 646 647 648 649 650 651 652 653 654 655 |
} /** * do_efi_boot_rm() - delete UEFI load options * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "boot rm" sub-command. * Delete UEFI load options. |
0b0165692 efi_loader: funct... |
656 657 |
* * efidebug boot rm <id> ... |
59df7e7e7 cmd: add efidebug... |
658 659 660 661 662 663 664 665 |
*/ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { efi_guid_t guid; int id, i; char *endp; char var_name[9]; |
e8bced62b cmd: efidebug: fi... |
666 |
u16 var_name16[9], *p; |
59df7e7e7 cmd: add efidebug... |
667 668 669 670 671 672 673 674 675 676 677 678 |
efi_status_t ret; if (argc == 1) return CMD_RET_USAGE; guid = efi_global_variable_guid; for (i = 1; i < argc; i++, argv++) { id = (int)simple_strtoul(argv[1], &endp, 16); if (*endp != '\0' || id > 0xffff) return CMD_RET_FAILURE; sprintf(var_name, "Boot%04X", id); |
e8bced62b cmd: efidebug: fi... |
679 680 |
p = var_name16; utf8_utf16_strncpy(&p, var_name, 9); |
59df7e7e7 cmd: add efidebug... |
681 682 683 |
ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL)); if (ret) { |
30efb5dd4 cmd: efidebug: co... |
684 685 |
printf("Cannot remove %ls ", var_name16); |
59df7e7e7 cmd: add efidebug... |
686 687 688 689 690 691 692 693 694 695 |
return CMD_RET_FAILURE; } } return CMD_RET_SUCCESS; } /** * show_efi_boot_opt_data() - dump UEFI load option * |
39a1ff8ce efi_loader: optio... |
696 697 698 |
* @id: load option number * @data: value of UEFI load option variable * @size: size of the boot option |
59df7e7e7 cmd: add efidebug... |
699 700 701 |
* * Decode the value of UEFI load option variable and print information. */ |
39a1ff8ce efi_loader: optio... |
702 |
static void show_efi_boot_opt_data(int id, void *data, size_t size) |
59df7e7e7 cmd: add efidebug... |
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
{ struct efi_load_option lo; char *label, *p; size_t label_len16, label_len; u16 *dp_str; efi_deserialize_load_option(&lo, data); label_len16 = u16_strlen(lo.label); label_len = utf16_utf8_strnlen(lo.label, label_len16); label = malloc(label_len + 1); if (!label) return; p = label; utf16_utf8_strncpy(&p, lo.label, label_len16); printf("Boot%04X: ", id); |
39a1ff8ce efi_loader: optio... |
721 722 |
printf(" attributes: %c%c%c (0x%08x) ", |
59df7e7e7 cmd: add efidebug... |
723 724 725 726 727 728 729 |
/* ACTIVE */ lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-', /* FORCE RECONNECT */ lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-', /* HIDDEN */ lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-', lo.attributes); |
39a1ff8ce efi_loader: optio... |
730 731 |
printf(" label: %s ", label); |
59df7e7e7 cmd: add efidebug... |
732 733 |
dp_str = efi_dp_str(lo.file_path); |
39a1ff8ce efi_loader: optio... |
734 735 |
printf(" file_path: %ls ", dp_str); |
59df7e7e7 cmd: add efidebug... |
736 |
efi_free_pool(dp_str); |
39a1ff8ce efi_loader: optio... |
737 738 739 740 741 |
printf(" data: "); print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1, lo.optional_data, size + (u8 *)data - (u8 *)lo.optional_data, true); |
59df7e7e7 cmd: add efidebug... |
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
free(label); } /** * show_efi_boot_opt() - dump UEFI load option * * @id: Load option number * * Dump information defined by UEFI load option. */ static void show_efi_boot_opt(int id) { char var_name[9]; u16 var_name16[9], *p; efi_guid_t guid; void *data = NULL; efi_uintn_t size; |
0bffb8c46 cmd: efidebug: fi... |
759 |
efi_status_t ret; |
59df7e7e7 cmd: add efidebug... |
760 761 762 763 764 765 766 767 |
sprintf(var_name, "Boot%04X", id); p = var_name16; utf8_utf16_strncpy(&p, var_name, 9); guid = efi_global_variable_guid; size = 0; ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL)); |
0bffb8c46 cmd: efidebug: fi... |
768 |
if (ret == EFI_BUFFER_TOO_SMALL) { |
59df7e7e7 cmd: add efidebug... |
769 770 771 772 773 |
data = malloc(size); ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, data)); } if (ret == EFI_SUCCESS) |
39a1ff8ce efi_loader: optio... |
774 |
show_efi_boot_opt_data(id, data, size); |
59df7e7e7 cmd: add efidebug... |
775 776 777 778 779 780 |
else if (ret == EFI_NOT_FOUND) printf("Boot%04X: not found ", id); free(data); } |
ffe215744 cmd: efidebug: re... |
781 782 783 784 785 786 787 788 789 790 |
static int u16_tohex(u16 c) { if (c >= '0' && c <= '9') return c - '0'; if (c >= 'A' && c <= 'F') return c - 'A' + 10; /* not hexadecimal */ return -1; } |
59df7e7e7 cmd: add efidebug... |
791 792 793 794 795 796 797 798 799 800 801 |
/** * show_efi_boot_dump() - dump all UEFI load options * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "boot dump" sub-command. * Dump information of all UEFI load options defined. |
a6ccba0c3 efi_loader: efide... |
802 803 |
* * efidebug boot dump |
59df7e7e7 cmd: add efidebug... |
804 805 806 807 |
*/ static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
ffe215744 cmd: efidebug: re... |
808 809 810 811 812 |
u16 *var_name16, *p; efi_uintn_t buf_size, size; efi_guid_t guid; int id, i, digit; efi_status_t ret; |
59df7e7e7 cmd: add efidebug... |
813 814 815 |
if (argc > 1) return CMD_RET_USAGE; |
ffe215744 cmd: efidebug: re... |
816 817 818 |
buf_size = 128; var_name16 = malloc(buf_size); if (!var_name16) |
59df7e7e7 cmd: add efidebug... |
819 |
return CMD_RET_FAILURE; |
ffe215744 cmd: efidebug: re... |
820 821 822 823 824 825 |
var_name16[0] = 0; for (;;) { size = buf_size; ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16, &guid)); if (ret == EFI_NOT_FOUND) |
59df7e7e7 cmd: add efidebug... |
826 |
break; |
ffe215744 cmd: efidebug: re... |
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
if (ret == EFI_BUFFER_TOO_SMALL) { buf_size = size; p = realloc(var_name16, buf_size); if (!p) { free(var_name16); return CMD_RET_FAILURE; } var_name16 = p; ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16, &guid)); } if (ret != EFI_SUCCESS) { free(var_name16); return CMD_RET_FAILURE; } if (memcmp(var_name16, L"Boot", 8)) continue; for (id = 0, i = 0; i < 4; i++) { digit = u16_tohex(var_name16[4 + i]); if (digit < 0) break; id = (id << 4) + digit; } if (i == 4 && !var_name16[8]) show_efi_boot_opt(id); |
59df7e7e7 cmd: add efidebug... |
855 |
} |
ffe215744 cmd: efidebug: re... |
856 857 |
free(var_name16); |
59df7e7e7 cmd: add efidebug... |
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
return CMD_RET_SUCCESS; } /** * show_efi_boot_order() - show order of UEFI load options * * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Show order of UEFI load options defined by BootOrder variable. */ static int show_efi_boot_order(void) { efi_guid_t guid; u16 *bootorder = NULL; efi_uintn_t size; int num, i; char var_name[9]; u16 var_name16[9], *p16; void *data; struct efi_load_option lo; char *label, *p; size_t label_len16, label_len; efi_status_t ret; guid = efi_global_variable_guid; size = 0; ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL, &size, NULL)); if (ret == EFI_BUFFER_TOO_SMALL) { bootorder = malloc(size); ret = EFI_CALL(RT->get_variable(L"BootOrder", &guid, NULL, &size, bootorder)); } if (ret == EFI_NOT_FOUND) { printf("BootOrder not defined "); ret = CMD_RET_SUCCESS; goto out; } else if (ret != EFI_SUCCESS) { ret = CMD_RET_FAILURE; goto out; } num = size / sizeof(u16); for (i = 0; i < num; i++) { sprintf(var_name, "Boot%04X", bootorder[i]); p16 = var_name16; utf8_utf16_strncpy(&p16, var_name, 9); size = 0; ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL)); if (ret != EFI_BUFFER_TOO_SMALL) { printf("%2d: Boot%04X: (not defined) ", i + 1, bootorder[i]); continue; } data = malloc(size); if (!data) { ret = CMD_RET_FAILURE; goto out; } ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, data)); if (ret != EFI_SUCCESS) { free(data); ret = CMD_RET_FAILURE; goto out; } efi_deserialize_load_option(&lo, data); label_len16 = u16_strlen(lo.label); label_len = utf16_utf8_strnlen(lo.label, label_len16); label = malloc(label_len + 1); if (!label) { free(data); ret = CMD_RET_FAILURE; goto out; } p = label; utf16_utf8_strncpy(&p, lo.label, label_len16); printf("%2d: Boot%04X: %s ", i + 1, bootorder[i], label); free(label); free(data); } out: free(bootorder); return ret; } /** * do_efi_boot_next() - manage UEFI BootNext variable * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure * * Implement efidebug "boot next" sub-command. * Set BootNext variable. |
0b0165692 efi_loader: funct... |
967 968 |
* * efidebug boot next <id> |
59df7e7e7 cmd: add efidebug... |
969 970 971 972 973 974 975 976 977 |
*/ static int do_efi_boot_next(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { u16 bootnext; efi_uintn_t size; char *endp; efi_guid_t guid; efi_status_t ret; |
a332f2519 efi_loader: consi... |
978 |
int r = CMD_RET_SUCCESS; |
59df7e7e7 cmd: add efidebug... |
979 980 981 982 983 984 985 986 |
if (argc != 2) return CMD_RET_USAGE; bootnext = (u16)simple_strtoul(argv[1], &endp, 16); if (*endp != '\0' || bootnext > 0xffff) { printf("invalid value: %s ", argv[1]); |
428a470a2 efi_loader: consi... |
987 |
r = CMD_RET_FAILURE; |
59df7e7e7 cmd: add efidebug... |
988 989 990 991 992 993 |
goto out; } guid = efi_global_variable_guid; size = sizeof(u16); ret = EFI_CALL(RT->set_variable(L"BootNext", &guid, |
f658c2e19 cmd: efidebug: ma... |
994 |
EFI_VARIABLE_NON_VOLATILE | |
59df7e7e7 cmd: add efidebug... |
995 996 997 |
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &bootnext)); |
a332f2519 efi_loader: consi... |
998 999 1000 1001 1002 |
if (ret != EFI_SUCCESS) { printf("Cannot set BootNext "); r = CMD_RET_FAILURE; } |
59df7e7e7 cmd: add efidebug... |
1003 |
out: |
428a470a2 efi_loader: consi... |
1004 |
return r; |
59df7e7e7 cmd: add efidebug... |
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
} /** * do_efi_boot_order() - manage UEFI BootOrder variable * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure * * Implement efidebug "boot order" sub-command. * Show order of UEFI load options, or change it in BootOrder variable. |
0b0165692 efi_loader: funct... |
1018 1019 |
* * efidebug boot order [<id> ...] |
59df7e7e7 cmd: add efidebug... |
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
*/ static int do_efi_boot_order(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { u16 *bootorder = NULL; efi_uintn_t size; int id, i; char *endp; efi_guid_t guid; efi_status_t ret; |
a332f2519 efi_loader: consi... |
1030 |
int r = CMD_RET_SUCCESS; |
59df7e7e7 cmd: add efidebug... |
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 |
if (argc == 1) return show_efi_boot_order(); argc--; argv++; size = argc * sizeof(u16); bootorder = malloc(size); if (!bootorder) return CMD_RET_FAILURE; for (i = 0; i < argc; i++) { id = (int)simple_strtoul(argv[i], &endp, 16); if (*endp != '\0' || id > 0xffff) { printf("invalid value: %s ", argv[i]); |
428a470a2 efi_loader: consi... |
1048 |
r = CMD_RET_FAILURE; |
59df7e7e7 cmd: add efidebug... |
1049 1050 1051 1052 1053 1054 1055 1056 |
goto out; } bootorder[i] = (u16)id; } guid = efi_global_variable_guid; ret = EFI_CALL(RT->set_variable(L"BootOrder", &guid, |
f658c2e19 cmd: efidebug: ma... |
1057 |
EFI_VARIABLE_NON_VOLATILE | |
59df7e7e7 cmd: add efidebug... |
1058 1059 1060 |
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, bootorder)); |
a332f2519 efi_loader: consi... |
1061 1062 1063 1064 1065 |
if (ret != EFI_SUCCESS) { printf("Cannot set BootOrder "); r = CMD_RET_FAILURE; } |
59df7e7e7 cmd: add efidebug... |
1066 1067 |
out: free(bootorder); |
428a470a2 efi_loader: consi... |
1068 |
return r; |
59df7e7e7 cmd: add efidebug... |
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
} static cmd_tbl_t cmd_efidebug_boot_sub[] = { U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""), U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""), U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""), U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""), U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order, "", ""), }; /** * do_efi_boot_opt() - manage UEFI load options * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure * * Implement efidebug "boot" sub-command. |
59df7e7e7 cmd: add efidebug... |
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
*/ static int do_efi_boot_opt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { cmd_tbl_t *cp; if (argc < 2) return CMD_RET_USAGE; argc--; argv++; cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub, ARRAY_SIZE(cmd_efidebug_boot_sub)); if (!cp) return CMD_RET_USAGE; return cp->cmd(cmdtp, flag, argc, argv); } static cmd_tbl_t cmd_efidebug_sub[] = { U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""), |
355cdb5a7 cmd: efidebug: ad... |
1112 1113 |
U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices, "", ""), |
66eaf5664 cmd: efidebug: ad... |
1114 1115 |
U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers, "", ""), |
a80146205 cmd: efidebug: ad... |
1116 1117 |
U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles, "", ""), |
fa5367342 cmd: efidebug: ad... |
1118 1119 |
U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images, "", ""), |
00358bb80 cmd: efidebug: ad... |
1120 1121 |
U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap, "", ""), |
986e06488 cmd: efidebug: ne... |
1122 1123 |
U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables, "", ""), |
59df7e7e7 cmd: add efidebug... |
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 |
}; /** * do_efidebug() - display and configure UEFI environment * * @cmdtp: Command table * @flag: Command flag * @argc: Number of arguments * @argv: Argument array * Return: CMD_RET_SUCCESS on success, * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure * * Implement efidebug command which allows us to display and * configure UEFI environment. |
59df7e7e7 cmd: add efidebug... |
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 |
*/ static int do_efidebug(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { cmd_tbl_t *cp; efi_status_t r; if (argc < 2) return CMD_RET_USAGE; argc--; argv++; /* Initialize UEFI drivers */ r = efi_init_obj_list(); if (r != EFI_SUCCESS) { printf("Error: Cannot initialize UEFI sub-system, r = %lu ", r & ~EFI_ERROR_MASK); return CMD_RET_FAILURE; } cp = find_cmd_tbl(argv[0], cmd_efidebug_sub, ARRAY_SIZE(cmd_efidebug_sub)); if (!cp) return CMD_RET_USAGE; return cp->cmd(cmdtp, flag, argc, argv); } #ifdef CONFIG_SYS_LONGHELP static char efidebug_help_text[] = " - UEFI Shell-like interface to configure UEFI environment " " " "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>] " " - set UEFI BootXXXX variable " " <load options> will be passed to UEFI application " "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]] " " - delete UEFI BootXXXX variables " "efidebug boot dump " " - dump all UEFI BootXXXX variables " "efidebug boot next <bootid> " " - set UEFI BootNext variable " "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]] " " - set/show UEFI boot order " |
355cdb5a7 cmd: efidebug: ad... |
1195 1196 1197 1198 |
" " "efidebug devices " |
07e2fe797 cmd: efidebug: ca... |
1199 1200 |
" - show UEFI devices " |
66eaf5664 cmd: efidebug: ad... |
1201 1202 |
"efidebug drivers " |
07e2fe797 cmd: efidebug: ca... |
1203 1204 |
" - show UEFI drivers " |
a80146205 cmd: efidebug: ad... |
1205 1206 |
"efidebug dh " |
07e2fe797 cmd: efidebug: ca... |
1207 1208 |
" - show UEFI handles " |
fa5367342 cmd: efidebug: ad... |
1209 1210 |
"efidebug images " |
00358bb80 cmd: efidebug: ad... |
1211 1212 1213 1214 |
" - show loaded images " "efidebug memmap " |
07e2fe797 cmd: efidebug: ca... |
1215 1216 |
" - show UEFI memory map " |
986e06488 cmd: efidebug: ne... |
1217 1218 1219 1220 |
"efidebug tables " " - show UEFI configuration tables "; |
59df7e7e7 cmd: add efidebug... |
1221 1222 1223 1224 1225 1226 1227 |
#endif U_BOOT_CMD( efidebug, 10, 0, do_efidebug, "Configure UEFI environment", efidebug_help_text ); |