#include <common.h>
#include <command.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
#define RT systab.runtime
argv++;
}
- capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
+ capsule = (typeof(capsule))hextoul(argv[1], &endp);
if (endp == argv[1]) {
printf("Invalid address: %s", argv[1]);
return CMD_RET_FAILURE;
capsule->capsule_image_size);
}
- ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL));
+ ret = EFI_CALL(RT->update_capsule(&capsule, 1, 0));
if (ret) {
printf("Cannot handle a capsule at %p", 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[])
{
return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
}
+#endif
/**
* do_efi_capsule_show() - show capsule information
if (argc != 2)
return CMD_RET_USAGE;
- capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
+ capsule = (typeof(capsule))hextoul(argv[1], &endp);
if (endp == argv[1]) {
printf("Invalid address: %s", argv[1]);
return CMD_RET_FAILURE;
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
*
{
int capsule_id;
char *endp;
- char var_name[12];
- u16 var_name16[12], *p;
+ u16 var_name16[12];
efi_guid_t guid;
struct efi_capsule_result_variable_header *result = NULL;
efi_uintn_t size;
guid = efi_guid_capsule_report;
if (argc == 1) {
size = sizeof(var_name16);
- ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
- &size, 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");
argc--;
argv++;
- capsule_id = simple_strtoul(argv[0], &endp, 16);
+ capsule_id = hextoul(argv[0], &endp);
if (capsule_id < 0 || capsule_id > 0xffff)
return CMD_RET_USAGE;
- sprintf(var_name, "Capsule%04X", capsule_id);
- p = var_name16;
- utf8_utf16_strncpy(&p, var_name, 9);
+ efi_create_indexed_name(var_name16, sizeof(var_name16),
+ "Capsule", capsule_id);
}
size = 0;
- ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
+ 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_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
- result));
+ ret = efi_get_variable_int(var_name16, &guid, NULL, &size,
+ result, NULL);
}
if (ret != EFI_SUCCESS) {
free(result);
"", ""),
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,
"", ""),
};
#endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */
/**
- * efi_get_device_handle_info() - get information of UEFI device
+ * efi_get_device_path_text() - get device path text
*
- * @handle: Handle of UEFI device
- * @dev_path_text: Pointer to text of device path
- * Return: 0 on success, -1 on failure
+ * Return the text representation of the device path of a handle.
*
- * Currently return a formatted text of device path.
+ * @handle: handle of UEFI device
+ * Return:
+ * Pointer to the device path text or NULL.
+ * The caller is responsible for calling FreePool().
*/
-static int efi_get_device_handle_info(efi_handle_t handle, u16 **dev_path_text)
+static u16 *efi_get_device_path_text(efi_handle_t handle)
{
- struct efi_device_path *dp;
+ struct efi_handler *handler;
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;
+ ret = efi_search_protocol(handle, &efi_guid_device_path, &handler);
+ if (ret == EFI_SUCCESS && handler->protocol_interface) {
+ struct efi_device_path *dp = handler->protocol_interface;
+
+ return efi_dp_str(dp);
} else {
- return -1;
+ return NULL;
}
}
printf("Device%.*s Device Path\n", EFI_HANDLE_WIDTH - 6, spc);
printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep);
for (i = 0; i < num; i++) {
- if (!efi_get_device_handle_info(handles[i], &dev_path_text)) {
+ dev_path_text = efi_get_device_path_text(handles[i]);
+ if (dev_path_text) {
printf("%p %ls\n", handles[i], dev_path_text);
efi_free_pool(dev_path_text);
}
return CMD_RET_SUCCESS;
}
-static const struct {
- const char *text;
- const efi_guid_t guid;
-} guid_list[] = {
- {
- "Device Path",
- EFI_DEVICE_PATH_PROTOCOL_GUID,
- },
- {
- "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",
- EFI_BLOCK_IO_PROTOCOL_GUID,
- },
- {
- "Simple File System",
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
- },
- {
- "Loaded Image",
- EFI_LOADED_IMAGE_PROTOCOL_GUID,
- },
- {
- "Graphics Output",
- EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
- },
- {
- "HII String",
- EFI_HII_STRING_PROTOCOL_GUID,
- },
- {
- "HII Database",
- EFI_HII_DATABASE_PROTOCOL_GUID,
- },
- {
- "HII Config Routing",
- EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID,
- },
- {
- "Load File2",
- EFI_LOAD_FILE2_PROTOCOL_GUID,
- },
- {
- "Random Number Generator",
- EFI_RNG_PROTOCOL_GUID,
- },
- {
- "Simple Network",
- EFI_SIMPLE_NETWORK_PROTOCOL_GUID,
- },
- {
- "PXE Base Code",
- EFI_PXE_BASE_CODE_PROTOCOL_GUID,
- },
- {
- "Device-Tree Fixup",
- EFI_DT_FIXUP_PROTOCOL_GUID,
- },
- /* Configuration table GUIDs */
- {
- "ACPI table",
- EFI_ACPI_TABLE_GUID,
- },
- {
- "device tree",
- EFI_FDT_GUID,
- },
- {
- "SMBIOS table",
- SMBIOS_TABLE_GUID,
- },
- {
- "Runtime properties",
- EFI_RT_PROPERTIES_TABLE_GUID,
- },
- {
- "TCG2 Final Events Table",
- EFI_TCG2_FINAL_EVENTS_TABLE_GUID,
- },
-};
-
-/**
- * get_guid_text - get string of GUID
- *
- * Return description of GUID.
- *
- * @guid: GUID
- * Return: description of GUID or NULL
- */
-static const char *get_guid_text(const void *guid)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(guid_list); i++) {
- /*
- * As guidcmp uses memcmp() we can safely accept unaligned
- * GUIDs.
- */
- if (!guidcmp(&guid_list[i].guid, guid))
- return guid_list[i].text;
- }
-
- return NULL;
-}
-
/**
* do_efi_show_handles() - show UEFI handles
*
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(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL,
else
putc(' ');
- guid_text = get_guid_text(guid[j]);
- if (guid_text)
- puts(guid_text);
- else
- printf("%pUl", guid[j]);
+ printf("%pUs", guid[j]);
}
putc('\n');
}
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\n", &systab.tables[i].guid, guid_str);
- }
+ for (i = 0; i < systab.nr_tables; ++i)
+ printf("%pUl (%pUs)\n",
+ &systab.tables[i].guid, &systab.tables[i].guid);
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
*
*
* Implement efidebug "boot add" sub-command. Create or change UEFI load option.
*
- * efidebug boot add <id> <label> <interface> <devnum>[:<part>] <file> <options>
+ * 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;
- char var_name[9];
- u16 var_name16[9], *p;
+ u16 var_name16[9];
efi_guid_t guid;
size_t label_len, label_len16;
u16 *label;
- struct efi_device_path *device_path = NULL, *file_path = NULL;
+ 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;
- if (argc < 6 || argc > 7)
- return CMD_RET_USAGE;
-
- id = (int)simple_strtoul(argv[1], &endp, 16);
- if (*endp != '\0' || id > 0xffff)
- return CMD_RET_USAGE;
-
- 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 */
+ lo.optional_data = NULL;
+ lo.label = NULL;
- /* 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);
+ argc--;
+ argv++; /* 'add' */
+ for (; argc > 0; argc--, argv++) {
+ int shortform;
- /* 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\"\n",
- argv[3], argv[4]);
+ 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_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],
+ 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 = file_path;
- lo.file_path_length = efi_dp_size(file_path)
- + sizeof(struct efi_device_path); /* for END */
- /* optional data */
- if (argc == 6)
- lo.optional_data = NULL;
- else
- lo.optional_data = (const u8 *)argv[6];
+ lo.file_path = final_fp;
+ lo.file_path_length = fp_size;
size = efi_serialize_load_option(&lo, (u8 **)&data);
if (!size) {
goto out;
}
- ret = EFI_CALL(efi_set_variable(var_name16, &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, data));
+ 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(device_path);
- efi_free_pool(file_path);
+ efi_free_pool(final_fp);
+ efi_free_pool(initrd_dp);
+ efi_free_pool(fp_free);
free(lo.label);
return r;
efi_guid_t guid;
int id, i;
char *endp;
- char var_name[9];
- u16 var_name16[9], *p;
+ u16 var_name16[9];
efi_status_t ret;
if (argc == 1)
guid = efi_global_variable_guid;
for (i = 1; i < argc; i++, argv++) {
- id = (int)simple_strtoul(argv[1], &endp, 16);
+ id = (int)hextoul(argv[1], &endp);
if (*endp != '\0' || id > 0xffff)
return CMD_RET_FAILURE;
- sprintf(var_name, "Boot%04X", id);
- p = var_name16;
- utf8_utf16_strncpy(&p, var_name, 9);
-
- ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
+ 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;
*/
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;
- char *label, *p;
- size_t label_len16, label_len;
- u16 *dp_str;
efi_status_t ret;
ret = efi_deserialize_load_option(&lo, data, size);
return;
}
- 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("%ls:\nattributes: %c%c%c (0x%08x)\n",
varname16,
/* ACTIVE */
/* HIDDEN */
lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
lo.attributes);
- printf(" label: %s\n", label);
+ printf(" label: %ls\n", lo.label);
- dp_str = efi_dp_str(lo.file_path);
- printf(" file_path: %ls\n", dp_str);
- efi_free_pool(dp_str);
+ 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);
- free(label);
}
/**
return CMD_RET_FAILURE;
}
- if (memcmp(var_name16, L"Boot", 8))
+ if (memcmp(var_name16, u"Boot", 8))
continue;
for (id = 0, i = 0; i < 4; i++) {
u16 *bootorder;
efi_uintn_t size;
int num, i;
- char var_name[9];
- u16 var_name16[9], *p16;
+ u16 var_name16[9];
void *data;
struct efi_load_option lo;
- char *label, *p;
- size_t label_len16, label_len;
efi_status_t ret;
size = 0;
- ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid,
+ ret = EFI_CALL(efi_get_variable(u"BootOrder", &efi_global_variable_guid,
NULL, &size, NULL));
if (ret != EFI_BUFFER_TOO_SMALL) {
if (ret == EFI_NOT_FOUND) {
printf("ERROR: Out of memory\n");
return CMD_RET_FAILURE;
}
- ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid,
+ ret = EFI_CALL(efi_get_variable(u"BootOrder", &efi_global_variable_guid,
NULL, &size, bootorder));
if (ret != EFI_SUCCESS) {
ret = CMD_RET_FAILURE;
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);
+ efi_create_indexed_name(var_name16, sizeof(var_name16),
+ "Boot", bootorder[i]);
size = 0;
ret = EFI_CALL(efi_get_variable(var_name16,
&efi_global_variable_guid, NULL,
&size, NULL));
if (ret != EFI_BUFFER_TOO_SMALL) {
- printf("%2d: %s: (not defined)\n", i + 1, var_name);
+ printf("%2d: %ls: (not defined)\n", i + 1, var_name16);
continue;
}
goto out;
}
- 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: %s: %s\n", i + 1, var_name, label);
- free(label);
+ printf("%2d: %ls: %ls\n", i + 1, var_name16, lo.label);
free(data);
}
if (argc != 2)
return CMD_RET_USAGE;
- bootnext = (u16)simple_strtoul(argv[1], &endp, 16);
+ bootnext = (u16)hextoul(argv[1], &endp);
if (*endp) {
printf("invalid value: %s\n", argv[1]);
r = CMD_RET_FAILURE;
guid = efi_global_variable_guid;
size = sizeof(u16);
- ret = EFI_CALL(efi_set_variable(L"BootNext", &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, &bootnext));
+ 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;
return CMD_RET_FAILURE;
for (i = 0; i < argc; i++) {
- id = (int)simple_strtoul(argv[i], &endp, 16);
+ id = (int)hextoul(argv[i], &endp);
if (*endp != '\0' || id > 0xffff) {
printf("invalid value: %s\n", argv[i]);
r = CMD_RET_FAILURE;
}
guid = efi_global_variable_guid;
- ret = EFI_CALL(efi_set_variable(L"BootOrder", &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, bootorder));
+ 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;
static char efidebug_help_text[] =
" - UEFI Shell-like interface to configure UEFI environment\n"
"\n"
- "efidebug boot add <bootid> <label> <interface> <devnum>[:<part>] <file path> [<load options>]\n"
- " - set UEFI BootXXXX variable\n"
- " <load options> will be passed to UEFI application\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"
" - 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 devices\n"
#endif
U_BOOT_CMD(
- efidebug, 10, 0, do_efidebug,
+ efidebug, CONFIG_SYS_MAXARGS, 0, do_efidebug,
"Configure UEFI environment",
efidebug_help_text
);