123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542 |
- // 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 <dm/device.h>
- #include <efi_dt_fixup.h>
- #include <efi_load_initrd.h>
- #include <efi_loader.h>
- #include <efi_rng.h>
- #include <efi_variable.h>
- #include <exports.h>
- #include <hexdump.h>
- #include <log.h>
- #include <malloc.h>
- #include <mapmem.h>
- #include <part.h>
- #include <search.h>
- #include <linux/ctype.h>
- #include <linux/err.h>
- #define BS systab.boottime
- #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
- /**
- * do_efi_capsule_update() - process a capsule update
- *
- * @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 "capsule update" sub-command.
- * process a capsule update.
- *
- * efidebug capsule update [-v] <capsule address>
- */
- static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- struct efi_capsule_header *capsule;
- int verbose = 0;
- char *endp;
- efi_status_t ret;
- if (argc != 2 && argc != 3)
- return CMD_RET_USAGE;
- if (argc == 3) {
- if (strcmp(argv[1], "-v"))
- return CMD_RET_USAGE;
- verbose = 1;
- argc--;
- argv++;
- }
- capsule = (typeof(capsule))hextoul(argv[1], &endp);
- if (endp == argv[1]) {
- printf("Invalid address: %s", argv[1]);
- return CMD_RET_FAILURE;
- }
- if (verbose) {
- printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
- printf("Capsule flags: 0x%x\n", capsule->flags);
- printf("Capsule header size: 0x%x\n", capsule->header_size);
- printf("Capsule image size: 0x%x\n",
- capsule->capsule_image_size);
- }
- ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0));
- if (ret) {
- printf("Cannot handle a capsule at %p\n", capsule);
- return CMD_RET_FAILURE;
- }
- return CMD_RET_SUCCESS;
- }
- #ifdef CONFIG_EFI_CAPSULE_ON_DISK
- static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- efi_status_t ret;
- ret = efi_launch_capsules();
- return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
- }
- #endif
- /**
- * do_efi_capsule_show() - show capsule information
- *
- * @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 "capsule show" sub-command.
- * show capsule information.
- *
- * efidebug capsule show <capsule address>
- */
- static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- struct efi_capsule_header *capsule;
- char *endp;
- if (argc != 2)
- return CMD_RET_USAGE;
- capsule = (typeof(capsule))hextoul(argv[1], &endp);
- if (endp == argv[1]) {
- printf("Invalid address: %s", argv[1]);
- return CMD_RET_FAILURE;
- }
- printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
- printf("Capsule flags: 0x%x\n", capsule->flags);
- printf("Capsule header size: 0x%x\n", capsule->header_size);
- printf("Capsule image size: 0x%x\n",
- capsule->capsule_image_size);
- return CMD_RET_SUCCESS;
- }
- #ifdef CONFIG_EFI_ESRT
- #define EFI_ESRT_FW_TYPE_NUM 4
- char *efi_fw_type_str[EFI_ESRT_FW_TYPE_NUM] = {"unknown", "system FW", "device FW",
- "UEFI driver"};
- #define EFI_ESRT_UPDATE_STATUS_NUM 9
- char *efi_update_status_str[EFI_ESRT_UPDATE_STATUS_NUM] = {"success", "unsuccessful",
- "insufficient resources", "incorrect version", "invalid format",
- "auth error", "power event (AC)", "power event (batt)",
- "unsatisfied dependencies"};
- #define EFI_FW_TYPE_STR_GET(idx) (\
- EFI_ESRT_FW_TYPE_NUM > (idx) ? efi_fw_type_str[(idx)] : "error"\
- )
- #define EFI_FW_STATUS_STR_GET(idx) (\
- EFI_ESRT_UPDATE_STATUS_NUM > (idx) ? efi_update_status_str[(idx)] : "error"\
- )
- /**
- * do_efi_capsule_esrt() - manage UEFI capsules
- *
- * @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 "capsule esrt" sub-command.
- * The prints the current ESRT table.
- *
- * efidebug capsule esrt
- */
- static int do_efi_capsule_esrt(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- struct efi_system_resource_table *esrt = NULL;
- if (argc != 1)
- return CMD_RET_USAGE;
- for (int idx = 0; idx < systab.nr_tables; idx++)
- if (!guidcmp(&efi_esrt_guid, &systab.tables[idx].guid))
- esrt = (struct efi_system_resource_table *)systab.tables[idx].table;
- if (!esrt) {
- log_info("ESRT: table not present\n");
- return CMD_RET_SUCCESS;
- }
- printf("========================================\n");
- printf("ESRT: fw_resource_count=%d\n", esrt->fw_resource_count);
- printf("ESRT: fw_resource_count_max=%d\n", esrt->fw_resource_count_max);
- printf("ESRT: fw_resource_version=%lld\n", esrt->fw_resource_version);
- for (int idx = 0; idx < esrt->fw_resource_count; idx++) {
- printf("[entry %d]==============================\n", idx);
- printf("ESRT: fw_class=%pUL\n", &esrt->entries[idx].fw_class);
- printf("ESRT: fw_type=%s\n", EFI_FW_TYPE_STR_GET(esrt->entries[idx].fw_type));
- printf("ESRT: fw_version=%d\n", esrt->entries[idx].fw_version);
- printf("ESRT: lowest_supported_fw_version=%d\n",
- esrt->entries[idx].lowest_supported_fw_version);
- printf("ESRT: capsule_flags=%d\n",
- esrt->entries[idx].capsule_flags);
- printf("ESRT: last_attempt_version=%d\n",
- esrt->entries[idx].last_attempt_version);
- printf("ESRT: last_attempt_status=%s\n",
- EFI_FW_STATUS_STR_GET(esrt->entries[idx].last_attempt_status));
- }
- printf("========================================\n");
- return CMD_RET_SUCCESS;
- }
- #endif /* CONFIG_EFI_ESRT */
- /**
- * do_efi_capsule_res() - show a capsule update result
- *
- * @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 "capsule result" sub-command.
- * show a capsule update result.
- * If result number is not specified, CapsuleLast will be shown.
- *
- * efidebug capsule result [<capsule result number>]
- */
- static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- int capsule_id;
- char *endp;
- u16 var_name16[12];
- efi_guid_t guid;
- struct efi_capsule_result_variable_header *result = NULL;
- efi_uintn_t size;
- efi_status_t ret;
- if (argc != 1 && argc != 2)
- return CMD_RET_USAGE;
- guid = efi_guid_capsule_report;
- if (argc == 1) {
- size = sizeof(var_name16);
- ret = efi_get_variable_int(u"CapsuleLast", &guid, NULL,
- &size, var_name16, NULL);
- if (ret != EFI_SUCCESS) {
- if (ret == EFI_NOT_FOUND)
- printf("CapsuleLast doesn't exist\n");
- else
- printf("Failed to get CapsuleLast\n");
- return CMD_RET_FAILURE;
- }
- printf("CapsuleLast is %ls\n", var_name16);
- } else {
- argc--;
- argv++;
- capsule_id = hextoul(argv[0], &endp);
- if (capsule_id < 0 || capsule_id > 0xffff)
- return CMD_RET_USAGE;
- efi_create_indexed_name(var_name16, sizeof(var_name16),
- "Capsule", capsule_id);
- }
- size = 0;
- ret = efi_get_variable_int(var_name16, &guid, NULL, &size, NULL, NULL);
- if (ret == EFI_BUFFER_TOO_SMALL) {
- result = malloc(size);
- if (!result)
- return CMD_RET_FAILURE;
- ret = efi_get_variable_int(var_name16, &guid, NULL, &size,
- result, NULL);
- }
- if (ret != EFI_SUCCESS) {
- free(result);
- printf("Failed to get %ls\n", var_name16);
- return CMD_RET_FAILURE;
- }
- printf("Result total size: 0x%x\n", result->variable_total_size);
- printf("Capsule guid: %pUl\n", &result->capsule_guid);
- printf("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n",
- result->capsule_processed.year, result->capsule_processed.month,
- result->capsule_processed.day, result->capsule_processed.hour,
- result->capsule_processed.minute,
- result->capsule_processed.second);
- printf("Capsule status: 0x%lx\n", result->capsule_status);
- free(result);
- return CMD_RET_SUCCESS;
- }
- static struct cmd_tbl cmd_efidebug_capsule_sub[] = {
- U_BOOT_CMD_MKENT(update, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_update,
- "", ""),
- U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show,
- "", ""),
- #ifdef CONFIG_EFI_ESRT
- U_BOOT_CMD_MKENT(esrt, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_esrt,
- "", ""),
- #endif
- #ifdef CONFIG_EFI_CAPSULE_ON_DISK
- U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update,
- "", ""),
- #endif
- U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
- "", ""),
- };
- /**
- * do_efi_capsule() - manage UEFI capsules
- *
- * @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 "capsule" sub-command.
- */
- static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- struct cmd_tbl *cp;
- if (argc < 2)
- return CMD_RET_USAGE;
- argc--; argv++;
- cp = find_cmd_tbl(argv[0], cmd_efidebug_capsule_sub,
- ARRAY_SIZE(cmd_efidebug_capsule_sub));
- if (!cp)
- return CMD_RET_USAGE;
- return cp->cmd(cmdtp, flag, argc, argv);
- }
- #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
- #define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2)
- static const char spc[] = " ";
- static const char sep[] = "================";
- /**
- * 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(struct cmd_tbl *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(efi_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\n",
- EFI_HANDLE_WIDTH - 6, spc);
- printf("%.*s ==================== ====================\n",
- 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\n", handles[i],
- driver_name, image_path_text);
- else
- printf("%p %-20ls <built-in>\n",
- handles[i], driver_name);
- efi_free_pool(driver_name);
- efi_free_pool(image_path_text);
- }
- }
- efi_free_pool(handles);
- return CMD_RET_SUCCESS;
- }
- /**
- * 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(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- efi_handle_t *handles;
- efi_guid_t **guid;
- efi_uintn_t num, count, i, j;
- efi_status_t ret;
- ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL,
- &num, &handles));
- if (ret != EFI_SUCCESS)
- return CMD_RET_FAILURE;
- if (!num)
- return CMD_RET_SUCCESS;
- for (i = 0; i < num; i++) {
- struct efi_handler *handler;
- printf("\n%p", handles[i]);
- if (handles[i]->dev)
- printf(" (%s)", handles[i]->dev->name);
- printf("\n");
- /* Print device path */
- ret = efi_search_protocol(handles[i], &efi_guid_device_path,
- &handler);
- if (ret == EFI_SUCCESS)
- printf(" %pD\n", handler->protocol_interface);
- ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid,
- &count));
- /* Print other protocols */
- for (j = 0; j < count; j++) {
- if (guidcmp(guid[j], &efi_guid_device_path))
- printf(" %pUs\n", guid[j]);
- }
- efi_free_pool(guid);
- }
- efi_free_pool(handles);
- return CMD_RET_SUCCESS;
- }
- /**
- * 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(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- efi_print_image_infos(NULL);
- return CMD_RET_SUCCESS;
- }
- 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",
- [EFI_PERSISTENT_MEMORY_TYPE] = "PERSISTENT",
- };
- 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_SP, "SP"},
- {EFI_MEMORY_RUNTIME, "RT"},
- };
- /**
- * print_memory_attributes() - print memory map attributes
- *
- * @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(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- struct efi_mem_desc *memmap, *map;
- efi_uintn_t map_size;
- const char *type;
- int i;
- efi_status_t ret;
- ret = efi_get_memory_map_alloc(&map_size, &memmap);
- if (ret != EFI_SUCCESS)
- return CMD_RET_FAILURE;
- printf("Type Start%.*s End%.*s Attributes\n",
- EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
- printf("================ %.*s %.*s ==========\n",
- EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
- /*
- * Coverity check: dereferencing null pointer "map."
- * This is a false positive as memmap will always be
- * populated by allocate_pool() above.
- */
- for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
- if (map->type < ARRAY_SIZE(efi_mem_type_string))
- type = efi_mem_type_string[map->type];
- else
- type = "(unknown)";
- printf("%-16s %.*llx-%.*llx", type,
- EFI_PHYS_ADDR_WIDTH,
- (u64)map_to_sysmem((void *)(uintptr_t)
- map->physical_start),
- EFI_PHYS_ADDR_WIDTH,
- (u64)map_to_sysmem((void *)(uintptr_t)
- (map->physical_start +
- map->num_pages * EFI_PAGE_SIZE)));
- print_memory_attributes(map->attribute);
- putc('\n');
- }
- efi_free_pool(memmap);
- return CMD_RET_SUCCESS;
- }
- /**
- * 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(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- efi_show_tables(&systab);
- return CMD_RET_SUCCESS;
- }
- /**
- * create_initrd_dp() - create a special device for our Boot### option
- *
- * @dev: device
- * @part: disk partition
- * @file: filename
- * @shortform: create short form device path
- * Return: pointer to the device path or ERR_PTR
- */
- static
- struct efi_device_path *create_initrd_dp(const char *dev, const char *part,
- const char *file, int shortform)
- {
- struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL, *short_fp = NULL;
- struct efi_device_path *initrd_dp = NULL;
- efi_status_t ret;
- const struct efi_initrd_dp id_dp = {
- .vendor = {
- {
- DEVICE_PATH_TYPE_MEDIA_DEVICE,
- DEVICE_PATH_SUB_TYPE_VENDOR_PATH,
- sizeof(id_dp.vendor),
- },
- EFI_INITRD_MEDIA_GUID,
- },
- .end = {
- DEVICE_PATH_TYPE_END,
- DEVICE_PATH_SUB_TYPE_END,
- sizeof(id_dp.end),
- }
- };
- ret = efi_dp_from_name(dev, part, file, &tmp_dp, &tmp_fp);
- if (ret != EFI_SUCCESS) {
- printf("Cannot create device path for \"%s %s\"\n", part, file);
- goto out;
- }
- if (shortform)
- short_fp = efi_dp_shorten(tmp_fp);
- if (!short_fp)
- short_fp = tmp_fp;
- initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp,
- short_fp);
- out:
- efi_free_pool(tmp_dp);
- efi_free_pool(tmp_fp);
- return initrd_dp;
- }
- /**
- * 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
- *
- * Implement efidebug "boot add" sub-command. Create or change UEFI load option.
- *
- * efidebug boot add -b <id> <label> <interface> <devnum>[:<part>] <file>
- * -i <file> <interface2> <devnum2>[:<part>] <initrd>
- * -s '<options>'
- */
- static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- int id;
- char *endp;
- u16 var_name16[9];
- efi_guid_t guid;
- u16 *label;
- struct efi_device_path *file_path = NULL;
- struct efi_device_path *fp_free = NULL;
- struct efi_device_path *final_fp = NULL;
- struct efi_device_path *initrd_dp = NULL;
- struct efi_load_option lo;
- void *data = NULL;
- efi_uintn_t size;
- efi_uintn_t fp_size = 0;
- efi_status_t ret;
- int r = CMD_RET_SUCCESS;
- guid = efi_global_variable_guid;
- /* attributes */
- lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
- lo.optional_data = NULL;
- lo.label = NULL;
- argc--;
- argv++; /* 'add' */
- for (; argc > 0; argc--, argv++) {
- int shortform;
- if (*argv[0] != '-' || strlen(argv[0]) != 2) {
- r = CMD_RET_USAGE;
- goto out;
- }
- shortform = 0;
- switch (argv[0][1]) {
- case 'b':
- shortform = 1;
- /* fallthrough */
- case 'B':
- if (argc < 5 || lo.label) {
- r = CMD_RET_USAGE;
- goto out;
- }
- id = (int)hextoul(argv[1], &endp);
- if (*endp != '\0' || id > 0xffff)
- return CMD_RET_USAGE;
- efi_create_indexed_name(var_name16, sizeof(var_name16),
- "Boot", id);
- /* label */
- label = efi_convert_string(argv[2]);
- if (!label)
- return CMD_RET_FAILURE;
- lo.label = label; /* label will be changed below */
- /* file path */
- ret = efi_dp_from_name(argv[3], argv[4], argv[5],
- NULL, &fp_free);
- if (ret != EFI_SUCCESS) {
- printf("Cannot create device path for \"%s %s\"\n",
- argv[3], argv[4]);
- r = CMD_RET_FAILURE;
- goto out;
- }
- if (shortform)
- file_path = efi_dp_shorten(fp_free);
- if (!file_path)
- file_path = fp_free;
- fp_size += efi_dp_size(file_path) +
- sizeof(struct efi_device_path);
- argc -= 5;
- argv += 5;
- break;
- case 'i':
- shortform = 1;
- /* fallthrough */
- case 'I':
- if (argc < 3 || initrd_dp) {
- r = CMD_RET_USAGE;
- goto out;
- }
- initrd_dp = create_initrd_dp(argv[1], argv[2], argv[3],
- shortform);
- if (!initrd_dp) {
- printf("Cannot add an initrd\n");
- r = CMD_RET_FAILURE;
- goto out;
- }
- argc -= 3;
- argv += 3;
- fp_size += efi_dp_size(initrd_dp) +
- sizeof(struct efi_device_path);
- break;
- case 's':
- if (argc < 1 || lo.optional_data) {
- r = CMD_RET_USAGE;
- goto out;
- }
- lo.optional_data = (const u8 *)argv[1];
- argc -= 1;
- argv += 1;
- break;
- default:
- r = CMD_RET_USAGE;
- goto out;
- }
- }
- if (!file_path) {
- printf("Missing binary\n");
- r = CMD_RET_USAGE;
- goto out;
- }
- final_fp = efi_dp_concat(file_path, initrd_dp);
- if (!final_fp) {
- printf("Cannot create final device path\n");
- r = CMD_RET_FAILURE;
- goto out;
- }
- lo.file_path = final_fp;
- lo.file_path_length = fp_size;
- size = efi_serialize_load_option(&lo, (u8 **)&data);
- if (!size) {
- r = CMD_RET_FAILURE;
- goto out;
- }
- ret = efi_set_variable_int(var_name16, &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, data, false);
- if (ret != EFI_SUCCESS) {
- printf("Cannot set %ls\n", var_name16);
- r = CMD_RET_FAILURE;
- }
- out:
- free(data);
- efi_free_pool(final_fp);
- efi_free_pool(initrd_dp);
- efi_free_pool(fp_free);
- free(lo.label);
- return r;
- }
- /**
- * 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.
- *
- * efidebug boot rm <id> ...
- */
- static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- efi_guid_t guid;
- int id, i;
- char *endp;
- u16 var_name16[9];
- 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)hextoul(argv[1], &endp);
- if (*endp != '\0' || id > 0xffff)
- return CMD_RET_FAILURE;
- efi_create_indexed_name(var_name16, sizeof(var_name16),
- "Boot", id);
- ret = efi_set_variable_int(var_name16, &guid, 0, 0, NULL,
- false);
- if (ret) {
- printf("Cannot remove %ls\n", var_name16);
- return CMD_RET_FAILURE;
- }
- }
- return CMD_RET_SUCCESS;
- }
- /**
- * show_efi_boot_opt_data() - dump UEFI load option
- *
- * @varname16: variable name
- * @data: value of UEFI load option variable
- * @size: size of the boot option
- *
- * Decode the value of UEFI load option variable and print information.
- */
- static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
- {
- struct efi_device_path *initrd_path = NULL;
- struct efi_load_option lo;
- efi_status_t ret;
- ret = efi_deserialize_load_option(&lo, data, size);
- if (ret != EFI_SUCCESS) {
- printf("%ls: invalid load option\n", varname16);
- return;
- }
- printf("%ls:\nattributes: %c%c%c (0x%08x)\n",
- varname16,
- /* 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);
- printf(" label: %ls\n", lo.label);
- printf(" file_path: %pD\n", lo.file_path);
- initrd_path = efi_dp_from_lo(&lo, &efi_lf2_initrd_guid);
- if (initrd_path) {
- printf(" initrd_path: %pD\n", initrd_path);
- efi_free_pool(initrd_path);
- }
- printf(" data:\n");
- print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
- lo.optional_data, *size, true);
- }
- /**
- * show_efi_boot_opt() - dump UEFI load option
- *
- * @varname16: variable name
- *
- * Dump information defined by UEFI load option.
- */
- static void show_efi_boot_opt(u16 *varname16)
- {
- void *data;
- efi_uintn_t size;
- efi_status_t ret;
- size = 0;
- ret = efi_get_variable_int(varname16, &efi_global_variable_guid,
- NULL, &size, NULL, NULL);
- if (ret == EFI_BUFFER_TOO_SMALL) {
- data = malloc(size);
- if (!data) {
- printf("ERROR: Out of memory\n");
- return;
- }
- ret = efi_get_variable_int(varname16, &efi_global_variable_guid,
- NULL, &size, data, NULL);
- if (ret == EFI_SUCCESS)
- show_efi_boot_opt_data(varname16, data, &size);
- free(data);
- }
- }
- /**
- * 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.
- *
- * efidebug boot dump
- */
- static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- u16 *var_name16, *p;
- efi_uintn_t buf_size, size;
- efi_guid_t guid;
- efi_status_t ret;
- if (argc > 1)
- return CMD_RET_USAGE;
- buf_size = 128;
- var_name16 = malloc(buf_size);
- if (!var_name16)
- return CMD_RET_FAILURE;
- var_name16[0] = 0;
- for (;;) {
- size = buf_size;
- ret = efi_get_next_variable_name_int(&size, var_name16, &guid);
- if (ret == EFI_NOT_FOUND)
- break;
- 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_get_next_variable_name_int(&size, var_name16,
- &guid);
- }
- if (ret != EFI_SUCCESS) {
- free(var_name16);
- return CMD_RET_FAILURE;
- }
- if (efi_varname_is_load_option(var_name16, NULL))
- show_efi_boot_opt(var_name16);
- }
- free(var_name16);
- 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)
- {
- u16 *bootorder;
- efi_uintn_t size;
- int num, i;
- u16 var_name16[9];
- void *data;
- struct efi_load_option lo;
- efi_status_t ret;
- size = 0;
- ret = efi_get_variable_int(u"BootOrder", &efi_global_variable_guid,
- NULL, &size, NULL, NULL);
- if (ret != EFI_BUFFER_TOO_SMALL) {
- if (ret == EFI_NOT_FOUND) {
- printf("BootOrder not defined\n");
- return CMD_RET_SUCCESS;
- } else {
- return CMD_RET_FAILURE;
- }
- }
- bootorder = malloc(size);
- if (!bootorder) {
- printf("ERROR: Out of memory\n");
- return CMD_RET_FAILURE;
- }
- ret = efi_get_variable_int(u"BootOrder", &efi_global_variable_guid,
- NULL, &size, bootorder, NULL);
- if (ret != EFI_SUCCESS) {
- ret = CMD_RET_FAILURE;
- goto out;
- }
- num = size / sizeof(u16);
- for (i = 0; i < num; i++) {
- efi_create_indexed_name(var_name16, sizeof(var_name16),
- "Boot", bootorder[i]);
- size = 0;
- ret = efi_get_variable_int(var_name16,
- &efi_global_variable_guid, NULL,
- &size, NULL, NULL);
- if (ret != EFI_BUFFER_TOO_SMALL) {
- printf("%2d: %ls: (not defined)\n", i + 1, var_name16);
- continue;
- }
- data = malloc(size);
- if (!data) {
- ret = CMD_RET_FAILURE;
- goto out;
- }
- ret = efi_get_variable_int(var_name16,
- &efi_global_variable_guid, NULL,
- &size, data, NULL);
- if (ret != EFI_SUCCESS) {
- free(data);
- ret = CMD_RET_FAILURE;
- goto out;
- }
- ret = efi_deserialize_load_option(&lo, data, &size);
- if (ret != EFI_SUCCESS) {
- printf("%ls: invalid load option\n", var_name16);
- ret = CMD_RET_FAILURE;
- goto out;
- }
- printf("%2d: %ls: %ls\n", i + 1, var_name16, lo.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.
- *
- * efidebug boot next <id>
- */
- static int do_efi_boot_next(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- u16 bootnext;
- efi_uintn_t size;
- char *endp;
- efi_guid_t guid;
- efi_status_t ret;
- int r = CMD_RET_SUCCESS;
- if (argc != 2)
- return CMD_RET_USAGE;
- bootnext = (u16)hextoul(argv[1], &endp);
- if (*endp) {
- printf("invalid value: %s\n", argv[1]);
- r = CMD_RET_FAILURE;
- goto out;
- }
- guid = efi_global_variable_guid;
- size = sizeof(u16);
- ret = efi_set_variable_int(u"BootNext", &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, &bootnext, false);
- if (ret != EFI_SUCCESS) {
- printf("Cannot set BootNext\n");
- r = CMD_RET_FAILURE;
- }
- out:
- return r;
- }
- /**
- * 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.
- *
- * efidebug boot order [<id> ...]
- */
- static int do_efi_boot_order(struct cmd_tbl *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;
- int r = CMD_RET_SUCCESS;
- 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)hextoul(argv[i], &endp);
- if (*endp != '\0' || id > 0xffff) {
- printf("invalid value: %s\n", argv[i]);
- r = CMD_RET_FAILURE;
- goto out;
- }
- bootorder[i] = (u16)id;
- }
- guid = efi_global_variable_guid;
- ret = efi_set_variable_int(u"BootOrder", &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, bootorder, true);
- if (ret != EFI_SUCCESS) {
- printf("Cannot set BootOrder\n");
- r = CMD_RET_FAILURE;
- }
- out:
- free(bootorder);
- return r;
- }
- static struct cmd_tbl 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.
- */
- static int do_efi_boot_opt(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- struct cmd_tbl *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);
- }
- /**
- * do_efi_test_bootmgr() - run simple bootmgr for test
- *
- * @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 "test bootmgr" sub-command.
- * Run simple bootmgr for test.
- *
- * efidebug test bootmgr
- */
- static __maybe_unused int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- efi_handle_t image;
- efi_uintn_t exit_data_size = 0;
- u16 *exit_data = NULL;
- efi_status_t ret;
- void *load_options = NULL;
- ret = efi_bootmgr_load(&image, &load_options);
- printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK);
- /* We call efi_start_image() even if error for test purpose. */
- ret = EFI_CALL(efi_start_image(image, &exit_data_size, &exit_data));
- printf("efi_start_image() returned: %ld\n", ret & ~EFI_ERROR_MASK);
- if (ret && exit_data)
- efi_free_pool(exit_data);
- efi_restore_gd();
- free(load_options);
- return CMD_RET_SUCCESS;
- }
- static struct cmd_tbl cmd_efidebug_test_sub[] = {
- #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR
- U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr,
- "", ""),
- #endif
- };
- /**
- * do_efi_test() - 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 "test" sub-command.
- */
- static int do_efi_test(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- struct cmd_tbl *cp;
- if (argc < 2)
- return CMD_RET_USAGE;
- argc--; argv++;
- cp = find_cmd_tbl(argv[0], cmd_efidebug_test_sub,
- ARRAY_SIZE(cmd_efidebug_test_sub));
- if (!cp)
- return CMD_RET_USAGE;
- return cp->cmd(cmdtp, flag, argc, argv);
- }
- /**
- * do_efi_query_info() - QueryVariableInfo EFI service
- *
- * @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_FAILURE on failure
- *
- * Implement efidebug "test" sub-command.
- */
- static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag,
- int argc, char * const argv[])
- {
- efi_status_t ret;
- u32 attr = 0;
- u64 max_variable_storage_size;
- u64 remain_variable_storage_size;
- u64 max_variable_size;
- int i;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-bs"))
- attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
- else if (!strcmp(argv[i], "-rt"))
- attr |= EFI_VARIABLE_RUNTIME_ACCESS;
- else if (!strcmp(argv[i], "-nv"))
- attr |= EFI_VARIABLE_NON_VOLATILE;
- else if (!strcmp(argv[i], "-at"))
- attr |=
- EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
- }
- ret = efi_query_variable_info_int(attr, &max_variable_storage_size,
- &remain_variable_storage_size,
- &max_variable_size);
- if (ret != EFI_SUCCESS) {
- printf("Error: Cannot query UEFI variables, r = %lu\n",
- ret & ~EFI_ERROR_MASK);
- return CMD_RET_FAILURE;
- }
- printf("Max storage size %llu\n", max_variable_storage_size);
- printf("Remaining storage size %llu\n", remain_variable_storage_size);
- printf("Max variable size %llu\n", max_variable_size);
- return CMD_RET_SUCCESS;
- }
- static struct cmd_tbl cmd_efidebug_sub[] = {
- U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
- #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
- U_BOOT_CMD_MKENT(capsule, CONFIG_SYS_MAXARGS, 1, do_efi_capsule,
- "", ""),
- #endif
- U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
- "", ""),
- U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles,
- "", ""),
- U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images,
- "", ""),
- U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap,
- "", ""),
- U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables,
- "", ""),
- U_BOOT_CMD_MKENT(test, CONFIG_SYS_MAXARGS, 1, do_efi_test,
- "", ""),
- U_BOOT_CMD_MKENT(query, CONFIG_SYS_MAXARGS, 1, do_efi_query_info,
- "", ""),
- };
- /**
- * 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.
- */
- static int do_efidebug(struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
- {
- struct cmd_tbl *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\n",
- 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\n"
- "\n"
- "efidebug boot add - set UEFI BootXXXX variable\n"
- " -b|-B <bootid> <label> <interface> <devnum>[:<part>] <file path>\n"
- " -i|-I <interface> <devnum>[:<part>] <initrd file path>\n"
- " (-b, -i for short form device path)\n"
- " -s '<optional data>'\n"
- "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n"
- " - delete UEFI BootXXXX variables\n"
- "efidebug boot dump\n"
- " - dump all UEFI BootXXXX variables\n"
- "efidebug boot next <bootid>\n"
- " - set UEFI BootNext variable\n"
- "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n"
- " - set/show UEFI boot order\n"
- "\n"
- #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
- "efidebug capsule update [-v] <capsule address>\n"
- " - process a capsule\n"
- "efidebug capsule disk-update\n"
- " - update a capsule from disk\n"
- "efidebug capsule show <capsule address>\n"
- " - show capsule information\n"
- "efidebug capsule result [<capsule result var>]\n"
- " - show a capsule update result\n"
- #ifdef CONFIG_EFI_ESRT
- "efidebug capsule esrt\n"
- " - print the ESRT\n"
- #endif
- "\n"
- #endif
- "efidebug drivers\n"
- " - show UEFI drivers\n"
- "efidebug dh\n"
- " - show UEFI handles\n"
- "efidebug images\n"
- " - show loaded images\n"
- "efidebug memmap\n"
- " - show UEFI memory map\n"
- "efidebug tables\n"
- " - show UEFI configuration tables\n"
- #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR
- "efidebug test bootmgr\n"
- " - run simple bootmgr for test\n"
- #endif
- "efidebug query [-nv][-bs][-rt][-at]\n"
- " - show size of UEFI variables store\n";
- #endif
- U_BOOT_CMD(
- efidebug, CONFIG_SYS_MAXARGS, 0, do_efidebug,
- "Configure UEFI environment",
- efidebug_help_text
- );
|