mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-01 00:49:43 +00:00
bootstd: Add a command to read all files for a bootflow
Some bootflows (such as EFI and ChromiumOS) delay reading the kernel until it is needed to boot. This saves time when scanning and avoids needing to allocate memory for something that may never be used. To permit reading of these files, add a new 'bootflow read' command. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
cbb607d2d9
commit
c279224ea6
7 changed files with 197 additions and 6 deletions
|
@ -445,6 +445,22 @@ void bootflow_remove(struct bootflow *bflow)
|
||||||
free(bflow);
|
free(bflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
|
||||||
|
int bootflow_read_all(struct bootflow *bflow)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (bflow->state != BOOTFLOWST_READY)
|
||||||
|
return log_msg_ret("rd", -EPROTO);
|
||||||
|
|
||||||
|
ret = bootmeth_read_all(bflow->method, bflow);
|
||||||
|
if (ret)
|
||||||
|
return log_msg_ret("rd2", ret);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* BOOTSTD_FULL */
|
||||||
|
|
||||||
int bootflow_boot(struct bootflow *bflow)
|
int bootflow_boot(struct bootflow *bflow)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
@ -61,6 +61,18 @@ int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow,
|
||||||
return ops->set_bootflow(dev, bflow, buf, size);
|
return ops->set_bootflow(dev, bflow, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
|
||||||
|
int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow)
|
||||||
|
{
|
||||||
|
const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
|
||||||
|
|
||||||
|
if (!ops->read_all)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
|
return ops->read_all(dev, bflow);
|
||||||
|
}
|
||||||
|
#endif /* BOOTSTD_FULL */
|
||||||
|
|
||||||
int bootmeth_boot(struct udevice *dev, struct bootflow *bflow)
|
int bootmeth_boot(struct udevice *dev, struct bootflow *bflow)
|
||||||
{
|
{
|
||||||
const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
|
const struct bootmeth_ops *ops = bootmeth_get_ops(dev);
|
||||||
|
|
|
@ -395,13 +395,30 @@ static int cros_read_file(struct udevice *dev, struct bootflow *bflow,
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_IS_ENABLED(BOOSTD_FULL)
|
||||||
|
static int cros_read_all(struct udevice *dev, struct bootflow *bflow)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (bflow->buf)
|
||||||
|
return log_msg_ret("ld", -EALREADY);
|
||||||
|
ret = cros_read_kernel(bflow);
|
||||||
|
if (ret)
|
||||||
|
return log_msg_ret("rd", ret);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* BOOSTD_FULL */
|
||||||
|
|
||||||
static int cros_boot(struct udevice *dev, struct bootflow *bflow)
|
static int cros_boot(struct udevice *dev, struct bootflow *bflow)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = cros_read_kernel(bflow);
|
if (!bflow->buf) {
|
||||||
if (ret)
|
ret = cros_read_kernel(bflow);
|
||||||
return log_msg_ret("rd", ret);
|
if (ret)
|
||||||
|
return log_msg_ret("rd", ret);
|
||||||
|
}
|
||||||
#ifdef CONFIG_X86
|
#ifdef CONFIG_X86
|
||||||
zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0,
|
zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0,
|
||||||
map_to_sysmem(bflow->x86_setup),
|
map_to_sysmem(bflow->x86_setup),
|
||||||
|
@ -425,6 +442,9 @@ static struct bootmeth_ops cros_bootmeth_ops = {
|
||||||
.read_bootflow = cros_read_bootflow,
|
.read_bootflow = cros_read_bootflow,
|
||||||
.read_file = cros_read_file,
|
.read_file = cros_read_file,
|
||||||
.boot = cros_boot,
|
.boot = cros_boot,
|
||||||
|
#if CONFIG_IS_ENABLED(BOOSTD_FULL)
|
||||||
|
.read_all = cros_read_all,
|
||||||
|
#endif /* BOOSTD_FULL */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct udevice_id cros_bootmeth_ids[] = {
|
static const struct udevice_id cros_bootmeth_ids[] = {
|
||||||
|
|
|
@ -379,6 +379,35 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_bootflow_read(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
|
char *const argv[])
|
||||||
|
{
|
||||||
|
struct bootstd_priv *std;
|
||||||
|
struct bootflow *bflow;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = bootstd_get_priv(&std);
|
||||||
|
if (ret)
|
||||||
|
return CMD_RET_FAILURE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Require a current bootflow. Users can use 'bootflow scan -b' to
|
||||||
|
* automatically scan and boot, if needed.
|
||||||
|
*/
|
||||||
|
if (!std->cur_bootflow) {
|
||||||
|
printf("No bootflow selected\n");
|
||||||
|
return CMD_RET_FAILURE;
|
||||||
|
}
|
||||||
|
bflow = std->cur_bootflow;
|
||||||
|
ret = bootflow_read_all(bflow);
|
||||||
|
if (ret) {
|
||||||
|
printf("Failed: err=%dE\n", ret);
|
||||||
|
return CMD_RET_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_bootflow_boot(struct cmd_tbl *cmdtp, int flag, int argc,
|
static int do_bootflow_boot(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
char *const argv[])
|
char *const argv[])
|
||||||
{
|
{
|
||||||
|
@ -519,7 +548,8 @@ static char bootflow_help_text[] =
|
||||||
"bootflow list [-e] - list scanned bootflows (-e errors)\n"
|
"bootflow list [-e] - list scanned bootflows (-e errors)\n"
|
||||||
"bootflow select [<num>|<name>] - select a bootflow\n"
|
"bootflow select [<num>|<name>] - select a bootflow\n"
|
||||||
"bootflow info [-ds] - show info on current bootflow (-d dump bootflow)\n"
|
"bootflow info [-ds] - show info on current bootflow (-d dump bootflow)\n"
|
||||||
"bootflow boot - boot current bootflow (or first available if none selected)\n"
|
"bootflow read - read all current-bootflow files\n"
|
||||||
|
"bootflow boot - boot current bootflow\n"
|
||||||
"bootflow menu [-t] - show a menu of available bootflows\n"
|
"bootflow menu [-t] - show a menu of available bootflows\n"
|
||||||
"bootflow cmdline [set|get|clear|delete|auto] <param> [<value>] - update cmdline";
|
"bootflow cmdline [set|get|clear|delete|auto] <param> [<value>] - update cmdline";
|
||||||
#else
|
#else
|
||||||
|
@ -533,6 +563,7 @@ U_BOOT_CMD_WITH_SUBCMDS(bootflow, "Boot flows", bootflow_help_text,
|
||||||
U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootflow_list),
|
U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootflow_list),
|
||||||
U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootflow_select),
|
U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootflow_select),
|
||||||
U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootflow_info),
|
U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootflow_info),
|
||||||
|
U_BOOT_SUBCMD_MKENT(read, 1, 1, do_bootflow_read),
|
||||||
U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot),
|
U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot),
|
||||||
U_BOOT_SUBCMD_MKENT(menu, 2, 1, do_bootflow_menu),
|
U_BOOT_SUBCMD_MKENT(menu, 2, 1, do_bootflow_menu),
|
||||||
U_BOOT_SUBCMD_MKENT(cmdline, 4, 1, do_bootflow_cmdline),
|
U_BOOT_SUBCMD_MKENT(cmdline, 4, 1, do_bootflow_cmdline),
|
||||||
|
|
|
@ -12,6 +12,7 @@ Synopis
|
||||||
bootflow list [-e]
|
bootflow list [-e]
|
||||||
bootflow select [<num|name>]
|
bootflow select [<num|name>]
|
||||||
bootflow info [-ds]
|
bootflow info [-ds]
|
||||||
|
bootflow read
|
||||||
bootflow boot
|
bootflow boot
|
||||||
bootflow cmdline [set|get|clear|delete|auto] <param> [<value>]
|
bootflow cmdline [set|get|clear|delete|auto] <param> [<value>]
|
||||||
|
|
||||||
|
@ -194,10 +195,26 @@ Use the `-d` flag to dump out the contents of the bootfile file.
|
||||||
The `-s` flag shows any x86 setup block, instead of the above.
|
The `-s` flag shows any x86 setup block, instead of the above.
|
||||||
|
|
||||||
|
|
||||||
|
bootflow read
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This reads any files related to the bootflow. Some bootflows with large files
|
||||||
|
avoid doing this when the bootflow is scanned, since it uses a lot of memory
|
||||||
|
and takes extra time. The files are then automatically read when `bootflow boot`
|
||||||
|
is used.
|
||||||
|
|
||||||
|
This command reads these files immediately. Typically this fills in the bootflow
|
||||||
|
`buf` property, which can be used to examine the bootflow.
|
||||||
|
|
||||||
|
Note that reading the files does not result in any extra parsing, nor loading of
|
||||||
|
images in the files. This is purely used to read in the data ready for
|
||||||
|
booting, or examination.
|
||||||
|
|
||||||
|
|
||||||
bootflow boot
|
bootflow boot
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
This boots the current bootflow.
|
This boots the current bootflow, reading any required files first.
|
||||||
|
|
||||||
|
|
||||||
bootflow cmdline
|
bootflow cmdline
|
||||||
|
@ -580,6 +597,67 @@ This shows looking at x86 setup information::
|
||||||
Init size : 1383000
|
Init size : 1383000
|
||||||
Handover offset : 0
|
Handover offset : 0
|
||||||
|
|
||||||
|
This shows reading a bootflow to examine the kernel::
|
||||||
|
|
||||||
|
=> bootfl i 0
|
||||||
|
Name:
|
||||||
|
Device: emmc@1c,0.bootdev
|
||||||
|
Block dev: emmc@1c,0.blk
|
||||||
|
Method: cros
|
||||||
|
State: ready
|
||||||
|
Partition: 2
|
||||||
|
Subdir: (none)
|
||||||
|
Filename: <NULL>
|
||||||
|
Buffer: 0
|
||||||
|
Size: 63ee00 (6548992 bytes)
|
||||||
|
OS: ChromeOS
|
||||||
|
Cmdline: console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 root=PARTUUID=35c775e7-3735-d745-93e5-d9e0238f7ed0/PARTNROFF=1 rootwait rw dm_verity.error_behavior=3 dm_verity.max_bios=-1 dm_verity.dev_wait=0 dm="1 vroot none rw 1,0 3788800 verity payload=ROOT_DEV hashtree=HASH_DEV hashstart=3788800 alg=sha1 root_hexdigest=55052b629d3ac889f25a9583ea12cdcd3ea15ff8 salt=a2d4d9e574069f4fed5e3961b99054b7a4905414b60a25d89974a7334021165c" noinitrd vt.global_cursor_default=0 kern_guid=35c775e7-3735-d745-93e5-d9e0238f7ed0 add_efi_memmap boot=local noresume noswap i915.modeset=1 tpm_tis.force=1 tpm_tis.interrupts=0 nmi_watchdog=panic,lapic disablevmx=off
|
||||||
|
X86 setup: 77b56010
|
||||||
|
Logo: (none)
|
||||||
|
FDT: <NULL>
|
||||||
|
Error: 0
|
||||||
|
|
||||||
|
Note that `Buffer` is 0 so it has not be read yet. Using `bootflow read`::
|
||||||
|
|
||||||
|
=> bootfl read
|
||||||
|
=> bootfl info
|
||||||
|
Name:
|
||||||
|
Device: emmc@1c,0.bootdev
|
||||||
|
Block dev: emmc@1c,0.blk
|
||||||
|
Method: cros
|
||||||
|
State: ready
|
||||||
|
Partition: 2
|
||||||
|
Subdir: (none)
|
||||||
|
Filename: <NULL>
|
||||||
|
Buffer: 77b7e400
|
||||||
|
Size: 63ee00 (6548992 bytes)
|
||||||
|
OS: ChromeOS
|
||||||
|
Cmdline: console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 root=PARTUUID=35c775e7-3735-d745-93e5-d9e0238f7ed0/PARTNROFF=1 rootwait rw dm_verity.error_behavior=3 dm_verity.max_bios=-1 dm_verity.dev_wait=0 dm="1 vroot none rw 1,0 3788800 verity payload=ROOT_DEV hashtree=HASH_DEV hashstart=3788800 alg=sha1 root_hexdigest=55052b629d3ac889f25a9583ea12cdcd3ea15ff8 salt=a2d4d9e574069f4fed5e3961b99054b7a4905414b60a25d89974a7334021165c" noinitrd vt.global_cursor_default=0 kern_guid=35c775e7-3735-d745-93e5-d9e0238f7ed0 add_efi_memmap boot=local noresume noswap i915.modeset=1 tpm_tis.force=1 tpm_tis.interrupts=0 nmi_watchdog=panic,lapic disablevmx=off
|
||||||
|
X86 setup: 781b4400
|
||||||
|
Logo: (none)
|
||||||
|
FDT: <NULL>
|
||||||
|
Error: 0
|
||||||
|
|
||||||
|
Now the buffer can be accessed::
|
||||||
|
|
||||||
|
=> md 77b7e400
|
||||||
|
77b7e400: 1186f6fc 40000002 b8fa0c75 00000018 .......@u.......
|
||||||
|
77b7e410: c08ed88e a68dd08e 000001e8 000000e8 ................
|
||||||
|
77b7e420: ed815d00 00000021 62c280b8 89e80100 .]..!......b....
|
||||||
|
77b7e430: 22f7e8c4 c0850061 22ec850f eb890061 ..."a......"a...
|
||||||
|
77b7e440: 0230868b 01480000 21d0f7c3 00fb81c3 ..0...H....!....
|
||||||
|
77b7e450: 7d010000 0000bb05 c3810100 00d4f000 ...}............
|
||||||
|
77b7e460: 8130858d 85890061 00618132 3095010f ..0.a...2.a....0
|
||||||
|
77b7e470: 0f006181 c883e020 e0220f20 e000bb8d .a.. ... .".....
|
||||||
|
77b7e480: c0310062 001800b9 8dabf300 62e000bb b.1............b
|
||||||
|
77b7e490: 07878d00 89000010 00bb8d07 8d0062f0 .............b..
|
||||||
|
77b7e4a0: 00100787 0004b900 07890000 00100005 ................
|
||||||
|
77b7e4b0: 08c78300 8df37549 630000bb 0183b800 ....Iu.....c....
|
||||||
|
77b7e4c0: 00b90000 89000008 00000507 c7830020 ............ ...
|
||||||
|
77b7e4d0: f3754908 e000838d 220f0062 0080b9d8 .Iu.....b.."....
|
||||||
|
77b7e4e0: 320fc000 08e8ba0f c031300f b8d0000f ...2.....01.....
|
||||||
|
77b7e4f0: 00000020 6ad8000f 00858d10 50000002 ......j.......P
|
||||||
|
|
||||||
|
|
||||||
Return value
|
Return value
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -352,6 +352,17 @@ void bootflow_free(struct bootflow *bflow);
|
||||||
*/
|
*/
|
||||||
int bootflow_boot(struct bootflow *bflow);
|
int bootflow_boot(struct bootflow *bflow);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bootflow_read_all() - Read all bootflow files
|
||||||
|
*
|
||||||
|
* Some bootmeths delay reading of large files until booting is requested. This
|
||||||
|
* causes those files to be read.
|
||||||
|
*
|
||||||
|
* @bflow: Bootflow to read
|
||||||
|
* Return: result of trying to read
|
||||||
|
*/
|
||||||
|
int bootflow_read_all(struct bootflow *bflow);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bootflow_run_boot() - Try to boot a bootflow
|
* bootflow_run_boot() - Try to boot a bootflow
|
||||||
*
|
*
|
||||||
|
|
|
@ -119,7 +119,16 @@ struct bootmeth_ops {
|
||||||
*/
|
*/
|
||||||
int (*read_file)(struct udevice *dev, struct bootflow *bflow,
|
int (*read_file)(struct udevice *dev, struct bootflow *bflow,
|
||||||
const char *file_path, ulong addr, ulong *sizep);
|
const char *file_path, ulong addr, ulong *sizep);
|
||||||
|
#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
|
||||||
|
/**
|
||||||
|
* readall() - read all files for a bootflow
|
||||||
|
*
|
||||||
|
* @dev: Bootmethod device to boot
|
||||||
|
* @bflow: Bootflow to read
|
||||||
|
* Return: 0 if OK, -EIO on I/O error, other -ve on other error
|
||||||
|
*/
|
||||||
|
int (*read_all)(struct udevice *dev, struct bootflow *bflow);
|
||||||
|
#endif /* BOOTSTD_FULL */
|
||||||
/**
|
/**
|
||||||
* boot() - boot a bootflow
|
* boot() - boot a bootflow
|
||||||
*
|
*
|
||||||
|
@ -223,6 +232,20 @@ int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow,
|
||||||
int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow,
|
int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow,
|
||||||
const char *file_path, ulong addr, ulong *sizep);
|
const char *file_path, ulong addr, ulong *sizep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bootmeth_read_all() - read all bootflow files
|
||||||
|
*
|
||||||
|
* Some bootmeths delay reading of large files until booting is requested. This
|
||||||
|
* causes those files to be read.
|
||||||
|
*
|
||||||
|
* @dev: Bootmethod device to use
|
||||||
|
* @bflow: Bootflow to read
|
||||||
|
* Return: does not return on success, since it should boot the
|
||||||
|
* Operating Systemn. Returns -EFAULT if that fails, other -ve on
|
||||||
|
* other error
|
||||||
|
*/
|
||||||
|
int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bootmeth_boot() - boot a bootflow
|
* bootmeth_boot() - boot a bootflow
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue