]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bloblist: Load the bloblist from the previous loader
authorRaymond Mao <raymond.mao@linaro.org>
Sat, 3 Feb 2024 16:36:26 +0000 (08:36 -0800)
committerTom Rini <trini@konsulko.com>
Thu, 29 Feb 2024 14:24:22 +0000 (09:24 -0500)
During bloblist initialization, load the bloblist via boot arguments
from the previous loader.
If a valid bloblist exists in boot arguments, relocate it into the
fixed bloblist memory region.
If not, fallback to support BLOBLIST_ADDR or BLOBLIST_ALLOC.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
common/bloblist.c
include/bloblist.h

index c2fd07575fb0b9dbcb31ecd638e40cf5c4491ecf..ad06d7a1795deb9b1799abfd9348fcfa4706f776 100644 (file)
@@ -487,37 +487,57 @@ int bloblist_reloc(void *to, uint to_size)
        return 0;
 }
 
+/*
+ * Weak default function for getting bloblist from boot args.
+ */
+int __weak xferlist_from_boot_arg(ulong __always_unused addr,
+                                 ulong __always_unused size)
+{
+       return -ENOENT;
+}
+
 int bloblist_init(void)
 {
        bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED);
        int ret = -ENOENT;
        ulong addr, size;
-       bool expected;
-
-       /**
-        * We don't expect to find an existing bloblist in the first phase of
-        * U-Boot that runs. Also we have no way to receive the address of an
-        * allocated bloblist from a previous stage, so it must be at a fixed
+       /*
+        * If U-Boot is not in the first phase, an existing bloblist must be
+        * at a fixed address.
+        */
+       bool from_addr = fixed && !u_boot_first_phase();
+       /*
+        * If U-Boot is in the first phase that an arch custom routine should
+        * install the bloblist passed from previous loader to this fixed
         * address.
         */
-       expected = fixed && !u_boot_first_phase();
+       bool from_boot_arg = fixed && u_boot_first_phase();
+
        if (spl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
-               expected = false;
+               from_addr = false;
        if (fixed)
                addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
                                      CONFIG_BLOBLIST_ADDR);
        size = CONFIG_BLOBLIST_SIZE;
-       if (expected) {
+
+       if (from_boot_arg)
+               ret = xferlist_from_boot_arg(addr, size);
+       else if (from_addr)
                ret = bloblist_check(addr, size);
-               if (ret) {
-                       log_warning("Expected bloblist at %lx not found (err=%d)\n",
-                                   addr, ret);
-               } else {
-                       /* Get the real size, if it is not what we expected */
-                       size = gd->bloblist->total_size;
-               }
-       }
+
+       if (ret)
+               log_warning("Bloblist at %lx not found (err=%d)\n",
+                           addr, ret);
+       else
+               /* Get the real size */
+               size = gd->bloblist->total_size;
+
        if (ret) {
+               /*
+                * If we don't have a bloblist from a fixed address, or the one
+                * in the fixed address is not valid. we must allocate the
+                * memory for it now.
+                */
                if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) {
                        void *ptr = memalign(BLOBLIST_ALIGN, size);
 
@@ -525,7 +545,8 @@ int bloblist_init(void)
                                return log_msg_ret("alloc", -ENOMEM);
                        addr = map_to_sysmem(ptr);
                } else if (!fixed) {
-                       return log_msg_ret("!fixed", ret);
+                       return log_msg_ret("BLOBLIST_FIXED is not enabled",
+                                          ret);
                }
                log_debug("Creating new bloblist size %lx at %lx\n", size,
                          addr);
@@ -538,6 +559,11 @@ int bloblist_init(void)
                return log_msg_ret("ini", ret);
        gd->flags |= GD_FLG_BLOBLIST_READY;
 
+#ifdef DEBUG
+       bloblist_show_stats();
+       bloblist_show_list();
+#endif
+
        return 0;
 }
 
index 0ae079d62aa59006e381981e1bd58121dc0d1760..7fbdd622bcf663c00b5cf58622fc70fd87fb5eca 100644 (file)
@@ -482,4 +482,14 @@ static inline int bloblist_maybe_init(void)
  */
 int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig);
 
+/**
+ * xferlist_from_boot_arg() - Get bloblist from the boot args and relocate it
+ *                           to the specified address.
+ *
+ * @addr: Address for the bloblist
+ * @size: Size of space reserved for the bloblist
+ * Return: 0 if OK, else on error
+ */
+int xferlist_from_boot_arg(ulong addr, ulong size);
+
 #endif /* __BLOBLIST_H */