]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: spl: add unit test for the "full" FIT loader
authorFrancesco Valla <francesco@valla.it>
Thu, 4 Jun 2026 20:41:40 +0000 (22:41 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 17 Jun 2026 20:16:41 +0000 (14:16 -0600)
Following what is already done for the "simple" FIT loader, add a unit
test for the "full" loader.

Signed-off-by: Francesco Valla <francesco@valla.it>
arch/sandbox/cpu/spl.c
arch/sandbox/include/asm/spl.h
test/image/spl_load_os.c

index 7ee4975523e30a1e3fb845ac19c71da93ef36290..1668b58d3fbb37686fc176ca7ef4fbf04fac5056 100644 (file)
@@ -265,6 +265,43 @@ int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image)
        return 0;
 }
 
+int sandbox_spl_load_fit_full(char *fname, int maxlen,
+                             struct spl_image_info *image)
+{
+       struct legacy_img_hdr *header;
+       long long size;
+       int ret;
+       int fd;
+
+       ret = sandbox_find_next_phase(fname, maxlen, true);
+       if (ret) {
+               printf("%s not found, error %d\n", fname, ret);
+               return log_msg_ret("nph", ret);
+       }
+
+       log_debug("reading from %s\n", fname);
+       fd = os_open(fname, OS_O_RDONLY);
+       if (fd < 0) {
+               printf("Failed to open '%s'\n", fname);
+               return log_msg_ret("ope", -errno);
+       }
+
+       if (os_get_filesize(fname, &size))
+               return log_msg_ret("fis", -ENOENT);
+
+       header = spl_get_load_buffer(0, size);
+
+       if (os_read(fd, header, size) != size)
+               return log_msg_ret("rea", -EIO);
+       os_close(fd);
+
+       ret = spl_load_fit_image(image, header);
+       if (ret)
+               return log_msg_ret("slf", ret);
+
+       return 0;
+}
+
 static int upl_load_from_image(struct spl_image_info *spl_image,
                               struct spl_boot_device *bootdev)
 {
index d824b2123a259253912c9f037071481d0e212aad..49a613ba92db6c0880c95d1e70b1573af962ba2f 100644 (file)
@@ -46,4 +46,18 @@ int sandbox_find_next_phase(char *fname, int maxlen, bool use_img);
  */
 int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image);
 
+/**
+ * sandbox_spl_load_fit_full() - Load the next phase from a FIT with the "full" loader
+ *
+ * Loads a FIT containing the next phase and sets it up for booting, using the
+ * "full" FIT loader
+ *
+ * @fname: Returns filename loaded
+ * @maxlen: Maximum length for @fname including \0
+ * @image: Place to put SPL-image information
+ * Return: 0 if OK, -ve on error
+ */
+int sandbox_spl_load_fit_full(char *fname, int maxlen,
+                             struct spl_image_info *image);
+
 #endif
index d17cf116a0e8923885dc6b45246f2b289fbee604..ba9d7979a09bba1739a75b108673183a9a1cef12 100644 (file)
@@ -21,3 +21,14 @@ static int spl_test_load(struct unit_test_state *uts)
 }
 SPL_TEST(spl_test_load, 0);
 
+static int spl_test_load_fit_full(struct unit_test_state *uts)
+{
+       struct spl_image_info image;
+       char fname[256];
+
+       ut_assertok(sandbox_spl_load_fit_full(fname, sizeof(fname), &image));
+
+       return 0;
+}
+SPL_TEST(spl_test_load_fit_full, 0);
+