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>
diff --git a/doc/develop/bootstd/overview.rst b/doc/develop/bootstd/overview.rst
index e3ce97c..c46bd7a 100644
--- a/doc/develop/bootstd/overview.rst
+++ b/doc/develop/bootstd/overview.rst
@@ -486,6 +486,9 @@
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:
diff --git a/fs/fs.c b/fs/fs.c
index 1afa0fb..d56c95c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -5,6 +5,7 @@
#define LOG_CATEGORY LOGC_CORE
+#include <bootstd.h>
#include <command.h>
#include <config.h>
#include <display_options.h>
@@ -734,12 +735,14 @@
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;
@@ -783,6 +786,10 @@
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);
@@ -806,6 +813,14 @@
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;
}
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 14de5b5..749d79d 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -1390,3 +1390,23 @@
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);