/** * 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\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)) { printf("%p %ls\n", handles[i], dev_path_text); efi_free_pool(dev_path_text); } } EFI_CALL(BS->free_pool(handles)); return CMD_RET_SUCCESS; }
/* * Tear down unit test. * * @return: EFI_ST_SUCCESS for success */ static int teardown(void) { efi_status_t r = EFI_ST_SUCCESS; if (image) { r = efi_free_pool(image); if (r != EFI_SUCCESS) { efi_st_error("Failed to free image\n"); return EFI_ST_FAILURE; } } return r; }
/** * show_efi_boot_opt_data() - dump UEFI load option * * @id: Load option number * @data: Value of UEFI load option variable * * Decode the value of UEFI load option variable and print information. */ static void show_efi_boot_opt_data(int id, void *data) { 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:\n", id); printf("\tattributes: %c%c%c (0x%08x)\n", /* 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("\tlabel: %s\n", label); dp_str = efi_dp_str(lo.file_path); printf("\tfile_path: %ls\n", dp_str); efi_free_pool(dp_str); printf("\tdata: %s\n", lo.optional_data); free(label); }
/** * 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. * - boot add <id> <label> <interface> <devnum>[:<part>] <file> <options> */ 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; int ret; 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 */ /* 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\"\n", argv[3], argv[4]); ret = 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 */ lo.optional_data = (u8 *)(argc == 6 ? "" : argv[6]); size = efi_serialize_load_option(&lo, (u8 **)&data); if (!size) { ret = CMD_RET_FAILURE; goto out; } ret = EFI_CALL(RT->set_variable(var_name16, &guid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, data)); ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); out: free(data); efi_free_pool(device_path); efi_free_pool(file_path); free(lo.label); return ret; }