bootstd: Update bootmeth_alloc_file() to record images
authorSimon Glass <sjg@chromium.org>
Fri, 15 Nov 2024 23:19:14 +0000 (16:19 -0700)
committerTom Rini <trini@konsulko.com>
Wed, 15 Jan 2025 14:48:42 +0000 (08:48 -0600)
As a first step to recording images and where they came from, update
this function to do so, since it is used by two bootmeths

Create a helper function in the bootflow system, since recorded
images are always associated with bootflows.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/bootflow.c
boot/bootmeth-uclass.c
boot/bootmeth_extlinux.c
boot/bootmeth_script.c
include/bootflow.h
include/bootmeth.h

index 94f34dc..a10d301 100644 (file)
@@ -976,3 +976,24 @@ const char *bootflow_img_type_name(enum bootflow_img_t type)
 
        return name;
 }
+
+struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname,
+                                     enum bootflow_img_t type, ulong addr,
+                                     ulong size)
+{
+       struct bootflow_img img, *ptr;
+
+       memset(&img, '\0', sizeof(struct bootflow_img));
+       img.fname = strdup(fname);
+       if (!img.fname)
+               return NULL;
+
+       img.type = type;
+       img.addr = addr;
+       img.size = size;
+       ptr = alist_add(&bflow->images, img);
+       if (!ptr)
+               return NULL;
+
+       return ptr;
+}
index 5b5fea3..c219631 100644 (file)
@@ -6,6 +6,7 @@
 
 #define LOG_CATEGORY UCLASS_BOOTSTD
 
+#include <alist.h>
 #include <blk.h>
 #include <bootflow.h>
 #include <bootmeth.h>
@@ -326,8 +327,10 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
        return 0;
 }
 
-int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
+int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align,
+                       enum bootflow_img_t type)
 {
+       struct blk_desc *desc = NULL;
        void *buf;
        uint size;
        int ret;
@@ -344,6 +347,13 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
        bflow->state = BOOTFLOWST_READY;
        bflow->buf = buf;
 
+       if (bflow->blk)
+               desc = dev_get_uclass_plat(bflow->blk);
+
+       if (!bootflow_img_add(bflow, bflow->fname, type, map_to_sysmem(buf),
+                             size))
+               return log_msg_ret("bai", -ENOMEM);
+
        return 0;
 }
 
index be8fbf4..6c158c2 100644 (file)
@@ -159,7 +159,7 @@ static int extlinux_read_bootflow(struct udevice *dev, struct bootflow *bflow)
                return log_msg_ret("try", ret);
        size = bflow->size;
 
-       ret = bootmeth_alloc_file(bflow, 0x10000, 1);
+       ret = bootmeth_alloc_file(bflow, 0x10000, 1, BFI_EXTLINUX_CFG);
        if (ret)
                return log_msg_ret("read", ret);
 
index c5cbf18..a2fb289 100644 (file)
@@ -98,7 +98,8 @@ static int script_read_bootflow_file(struct udevice *bootstd,
        if (!bflow->subdir)
                return log_msg_ret("prefix", -ENOMEM);
 
-       ret = bootmeth_alloc_file(bflow, 0x10000, ARCH_DMA_MINALIGN);
+       ret = bootmeth_alloc_file(bflow, 0x10000, ARCH_DMA_MINALIGN,
+                                 (enum bootflow_img_t)IH_TYPE_SCRIPT);
        if (ret)
                return log_msg_ret("read", ret);
 
index f407bb3..e09cff2 100644 (file)
@@ -613,4 +613,19 @@ int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg);
  * Return: Image name, or "unknown" if not known
  */
 const char *bootflow_img_type_name(enum bootflow_img_t type);
+
+/**
+ * bootflow_img_add() - Add a new image to a bootflow
+ *
+ * @bflow: Bootflow to add to
+ * @fname: Image filename (will be allocated)
+ * @type: Image type
+ * @addr: Address the image was loaded to, or 0 if not loaded
+ * @size: Image size
+ * Return: pointer to the added image, or NULL if out of memory
+ */
+struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname,
+                                     enum bootflow_img_t type, ulong addr,
+                                     ulong size);
+
 #endif
index a08ebf0..e812974 100644 (file)
@@ -7,11 +7,11 @@
 #ifndef __bootmeth_h
 #define __bootmeth_h
 
+#include <bootflow.h>
+#include <image.h>
 #include <linux/bitops.h>
 
 struct blk_desc;
-struct bootflow;
-struct bootflow_iter;
 struct udevice;
 
 /**
@@ -365,10 +365,12 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
  * @bflow: Information about file to read
  * @size_limit: Maximum file size to permit
  * @align: Allocation alignment (1 for unaligned)
+ * @type: File type (IH_TYPE_...)
  * Return: 0 if OK, -E2BIG if file is too large, -ENOMEM if out of memory,
  *     other -ve on other error
  */
-int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align);
+int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align,
+                       enum bootflow_img_t type);
 
 /**
  * bootmeth_alloc_other() - Allocate and read a file for a bootflow