[PATCH v4 19/19] fs: Record loaded files in an ad-hoc bootflow

Simon Glass sjg at chromium.org
Sat Nov 16 00:19:26 CET 2024


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 at chromium.org>
---

Changes in v4:
- Rebase on top of -master (which now has bootflow_efi() test)

Changes in v3:
- Add new patch to record loaded files in an ad-hoc bootflow

Changes in v2:
- Drop patches already applied
- Drop patches which add new image types
- Update to use a new image-type enum in bootflow.h

 doc/develop/bootstd/overview.rst |  3 +++
 fs/fs.c                          | 15 +++++++++++++++
 test/boot/bootflow.c             | 20 ++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/doc/develop/bootstd/overview.rst b/doc/develop/bootstd/overview.rst
index e3ce97cc4f5..c46bd7a5a90 100644
--- a/doc/develop/bootstd/overview.rst
+++ b/doc/develop/bootstd/overview.rst
@@ -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:
 
diff --git a/fs/fs.c b/fs/fs.c
index 1afa0fbeaed..d56c95c1b26 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_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;
@@ -783,6 +786,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);
@@ -806,6 +813,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;
 }
 
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 14de5b591dd..749d79d3295 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -1390,3 +1390,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);
-- 
2.34.1



More information about the U-Boot mailing list