fs: Record loaded files in an ad-hoc bootflow

This makes a start on dealing with images loaded outside the context of
bootstd. For now, it just records these images. They can be listed using
the 'bootstd images' command.

Often, very little is known about these images, but future work could
perhaps use the filename or contents to detect the type.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2024-11-15 16:19:26 -07:00
parent f2f04db05e
commit 9820ce9a2f
3 changed files with 38 additions and 0 deletions

View File

@@ -486,6 +486,9 @@ be visible.
Once a bootflow has been selected, images for those that are not selected can
potentially be dropped from the memory map. For now, this is not implemented.
In cases where images are loaded outside the context of standard boot, an ad-hoc
bootflow is used to keep track of these. They is visible with the
``bootstd images`` command (see :doc:`/usage/cmd/bootstd`).
.. _BootflowStates:

15
fs/fs.c
View File

@@ -5,6 +5,7 @@
#define LOG_CATEGORY LOGC_CORE
#include <bootstd.h>
#include <command.h>
#include <config.h>
#include <display_options.h>
@@ -735,12 +736,14 @@ int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
int fstype)
{
struct blk_desc *dev_desc;
unsigned long addr;
const char *addr_str;
const char *filename;
loff_t bytes;
loff_t pos;
loff_t len_read;
int dev_part;
int ret;
unsigned long time;
char *ep;
@@ -784,6 +787,10 @@ int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
else
pos = 0;
/* save globals before they are cleared */
dev_desc = fs_dev_desc;
dev_part = fs_dev_part;
time = get_timer(0);
ret = _fs_read(filename, addr, pos, bytes, 1, &len_read);
time = get_timer(time);
@@ -807,6 +814,14 @@ int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
env_set_hex("fileaddr", addr);
env_set_hex("filesize", len_read);
if (IS_ENABLED(CONFIG_BOOTSTD) &&
bootstd_img_add(dev_desc, dev_part, filename,
(enum bootflow_img_t)IH_TYPE_INVALID, addr,
len_read)) {
log_err("Failed to record file\n");
return CMD_RET_FAILURE;
}
return 0;
}

View File

@@ -1413,3 +1413,23 @@ static int bootstd_images(struct unit_test_state *uts)
return 0;
}
BOOTSTD_TEST(bootstd_images, UTF_CONSOLE);
/* Check creation of ad-hoc images */
static int bootstd_adhoc(struct unit_test_state *uts)
{
ut_assertok(run_command("load mmc 1:1 1000 /extlinux/extlinux.conf",
0));
ut_assert_nextlinen("595 bytes read");
ut_assertok(run_command("bootstd images", 0));
ut_assert_nextlinen("Seq");
ut_assert_nextlinen("---");
ut_assert_nextline(
" 0 ad-hoc invalid 1000 253 /extlinux/extlinux.conf");
ut_assert_nextlinen("---");
ut_assert_nextline("(1 image)");
ut_assert_console_end();
return 0;
}
BOOTSTD_TEST(bootstd_adhoc, UTF_CONSOLE);