]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
spl: Create a function to init spl_load_info
authorSimon Glass <sjg@chromium.org>
Thu, 22 Aug 2024 13:55:02 +0000 (07:55 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 23 Aug 2024 21:58:42 +0000 (15:58 -0600)
Rather than having every caller set this up individually, create a
common init function. This allows new fields to be added without the
risk of them being left uninited.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
18 files changed:
arch/arm/mach-imx/spl_imx_romapi.c
arch/arm/mach-sunxi/spl_spi_sunxi.c
arch/sandbox/cpu/spl.c
common/spl/spl_blk_fs.c
common/spl/spl_ext.c
common/spl/spl_fat.c
common/spl/spl_mmc.c
common/spl/spl_nand.c
common/spl/spl_net.c
common/spl/spl_nor.c
common/spl/spl_ram.c
common/spl/spl_semihosting.c
common/spl/spl_spi.c
common/spl/spl_ymodem.c
drivers/usb/gadget/f_sdp.c
include/spl.h
test/image/spl_load.c
test/image/spl_load_os.c

index bdaea439d7f37504722ec5ea29dcf246e87383a2..3982f4cca184716f0000a28767c14a57567ed54d 100644 (file)
@@ -108,18 +108,13 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image,
        if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) {
                struct spl_load_info load;
 
-               memset(&load, 0, sizeof(load));
-               spl_set_bl_len(&load, pagesize);
-               load.read = spl_romapi_read_seekable;
+               spl_load_init(&load, spl_romapi_read_seekable, NULL, pagesize);
                return spl_load_simple_fit(spl_image, &load, offset, header);
        } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
                   valid_container_hdr((void *)header)) {
                struct spl_load_info load;
 
-               memset(&load, 0, sizeof(load));
-               spl_set_bl_len(&load, pagesize);
-               load.read = spl_romapi_read_seekable;
-
+               spl_load_init(&load, spl_romapi_read_seekable, NULL, pagesize);
                ret = spl_load_imx_container(spl_image, &load, offset);
        } else {
                /* TODO */
@@ -341,10 +336,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image,
                ss.end = p;
                ss.pagesize = pagesize;
 
-               memset(&load, 0, sizeof(load));
-               spl_set_bl_len(&load, 1);
-               load.read = spl_romapi_read_stream;
-               load.priv = &ss;
+               spl_load_init(&load, spl_romapi_read_stream, &ss, 1);
 
                return spl_load_simple_fit(spl_image, &load, (ulong)phdr, phdr);
        }
index d7abdc2e401e5b7963aa8ef20acbfb7b1f3be1c6..5f72e809952b91443aaff75549ab49bda7300781 100644 (file)
@@ -390,8 +390,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
                struct spl_load_info load;
 
                debug("Found FIT image\n");
-               spl_set_bl_len(&load, 1);
-               load.read = spi_load_read;
+               spl_load_init(&load, spi_load_read, NULL, 1);
                ret = spl_load_simple_fit(spl_image, &load,
                                          load_offset, header);
        } else {
index bcb1ca10a51996e73a424a68dc47ee239ccda4b5..cc46965b73b06226320fe39e17448307c859ddc4 100644 (file)
@@ -221,9 +221,8 @@ int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image)
        int ret;
        int fd;
 
-       memset(&load, '\0', sizeof(load));
-       spl_set_bl_len(&load, IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) ? 512 : 1);
-       load.read = read_fit_image;
+       spl_load_init(&load, read_fit_image, &load_ctx,
+                     IS_ENABLED(CONFIG_SPL_LOAD_BLOCK) ? 512 : 1);
 
        ret = sandbox_find_next_phase(fname, maxlen, true);
        if (ret) {
index bc551c5c074cffc9f7bafddbea9da3b1cc07ad13..bbf90a9741eeb760f710a16db81871b40dc0c910 100644 (file)
@@ -80,11 +80,8 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
                return ret;
        }
 
-       load.read = spl_fit_read;
-       if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN))
-               spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
-       else
-               spl_set_bl_len(&load, 1);
-       load.priv = &dev;
+       spl_load_init(&load, spl_fit_read, &dev,
+                     IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN) ?
+                     ARCH_DMA_MINALIGN : 1);
        return spl_load(spl_image, bootdev, &load, filesize, 0);
 }
index 76f49a5a8a6acbddbfcd96f139fd521a03921a05..c5478820a9ba2dad565700741d362a000130d007 100644 (file)
@@ -51,8 +51,7 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
                goto end;
        }
 
-       spl_set_bl_len(&load, 1);
-       load.read = spl_fit_read;
+       spl_load_init(&load, spl_fit_read, NULL, 1);
        err = spl_load(spl_image, bootdev, &load, filelen, 0);
 
 end:
index bd8aab253a9895aab6898734ca11068a79e4059b..fce451b7664cca73d33f19d93431fd69d33f9023 100644 (file)
@@ -83,12 +83,10 @@ int spl_load_image_fat(struct spl_image_info *spl_image,
                size = 0;
        }
 
-       load.read = spl_fit_read;
-       if (IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN))
-               spl_set_bl_len(&load, ARCH_DMA_MINALIGN);
-       else
-               spl_set_bl_len(&load, 1);
-       load.priv = (void *)filename;
+       spl_load_init(&load, spl_fit_read, (void *)filename,
+                     IS_ENABLED(CONFIG_SPL_FS_FAT_DMA_ALIGN) ?
+                     ARCH_DMA_MINALIGN : 1);
+
        err = spl_load(spl_image, bootdev, &load, size, 0);
 
 end:
index 887ea760b84fb7be752896f2ebbd3d394862fb03..3fd81608e9f09f89349ffabf0ef8c2410a051bf2 100644 (file)
@@ -46,9 +46,7 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
        struct blk_desc *bd = mmc_get_blk_desc(mmc);
        struct spl_load_info load;
 
-       load.priv = bd;
-       spl_set_bl_len(&load, bd->blksz);
-       load.read = h_spl_load_read;
+       spl_load_init(&load, h_spl_load_read, bd, bd->blksz);
        ret = spl_load(spl_image, bootdev, &load, 0, sector << bd->log2blksz);
        if (ret) {
                puts("mmc_load_image_raw_sector: mmc block read error\n");
index 5631fa6d5635044b33e2a4748d4bbeb5ed4c42fd..22883f4e8b9a7638512560e1835a9ee325b493dc 100644 (file)
@@ -71,9 +71,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
 {
        struct spl_load_info load;
 
-       load.priv = &offset;
-       spl_set_bl_len(&load, 1);
-       load.read = spl_nand_read;
+       spl_load_init(&load, spl_nand_read, &offset, 1);
        return spl_load(spl_image, bootdev, &load, 0, offset);
 }
 
index be7278bb93344d756135fdf6f38919bb557fa9ae..2be7b73ed35dce3cc63f6f9a38963ffa1fb8c670 100644 (file)
@@ -47,8 +47,7 @@ static int spl_net_load_image(struct spl_image_info *spl_image,
                return rv;
        }
 
-       spl_set_bl_len(&load, 1);
-       load.read = spl_net_load_read;
+       spl_load_init(&load, spl_net_load_read, NULL, 1);
        return spl_load(spl_image, bootdev, &load, 0, 0);
 }
 #endif
index ed76b5e1293b574b9598c401317c9a56a317843e..1021d93399930091e6291a1b85663e214de28a9e 100644 (file)
@@ -49,8 +49,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
                        int ret;
 
                        debug("Found FIT\n");
-                       spl_set_bl_len(&load, 1);
-                       load.read = spl_nor_load_read;
+                       spl_load_init(&load, spl_nor_load_read, NULL, 1);
 
                        ret = spl_load_simple_fit(spl_image, &load,
                                                  CONFIG_SYS_OS_BASE,
@@ -93,8 +92,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
         * Load real U-Boot from its location in NOR flash to its
         * defined location in SDRAM
         */
-       spl_set_bl_len(&load, 1);
-       load.read = spl_nor_load_read;
+       spl_load_init(&load, spl_nor_load_read, NULL, 1);
        return spl_load(spl_image, bootdev, &load, 0, spl_nor_get_uboot_base());
 }
 SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);
index 5a23841f6981589344499bfdbd98611904379f31..71b7a8374bbbf534e1b2c28e02205af035fcfd8b 100644 (file)
@@ -69,8 +69,7 @@ static int spl_ram_load_image(struct spl_image_info *spl_image,
                struct spl_load_info load;
 
                debug("Found FIT\n");
-               spl_set_bl_len(&load, 1);
-               load.read = spl_ram_load_read;
+               spl_load_init(&load, spl_ram_load_read, NULL, 1);
                ret = spl_load_simple_fit(spl_image, &load, 0, header);
        } else {
                ulong u_boot_pos = spl_get_image_pos();
index 2047248f39b0a3f608f7b33329f186508ea62c1e..f36863fe48d25859ee9af67a67140893b6e9e262 100644 (file)
@@ -43,9 +43,7 @@ static int spl_smh_load_image(struct spl_image_info *spl_image,
        }
        len = ret;
 
-       load.read = smh_fit_read;
-       spl_set_bl_len(&load, 1);
-       load.priv = &fd;
+       spl_load_init(&load, smh_fit_read, &fd, 1);
        ret = spl_load(spl_image, bootdev, &load, len, 0);
        if (ret)
                log_debug("could not read %s: %d\n", filename, ret);
index 8ab4803f7c4bf5f1a34535d3e5409fc52d6c8668..691a431a9262dd0de653320a924f1d538e04debb 100644 (file)
@@ -77,9 +77,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
                return -ENODEV;
        }
 
-       load.priv = flash;
-       spl_set_bl_len(&load, 1);
-       load.read = spl_spi_fit_read;
+       spl_load_init(&load, spl_spi_fit_read, flash, 1);
 
 #if CONFIG_IS_ENABLED(OS_BOOT)
        if (spl_start_uboot()) {
index 4c7222af612dc92d59d85899c46d524923f3182f..2be957134c1b7a851f41b0cf390f6d89461c5c99 100644 (file)
@@ -132,11 +132,9 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image,
                struct ymodem_fit_info info;
 
                debug("Found FIT\n");
-               load.priv = (void *)&info;
-               spl_set_bl_len(&load, 1);
+               spl_load_init(&load, ymodem_read_fit, (void *)&info, 1);
                info.buf = buf;
                info.image_read = BUF_SIZE;
-               load.read = ymodem_read_fit;
                ret = spl_load_simple_fit(spl_image, &load, 0, (void *)buf);
                size = info.image_read;
 
index 514c097591bf6fbcc8b3355f07ec085c6ca391ef..5d62eb475d0f8eec2c824f9f544f7ed87105ad96 100644 (file)
@@ -842,9 +842,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
                                struct spl_load_info load;
 
                                debug("Found FIT\n");
-                               load.priv = header;
-                               spl_set_bl_len(&load, 1);
-                               load.read = sdp_load_read;
+                               spl_load_init(&load, sdp_load_read, header, 1);
                                spl_load_simple_fit(spl_image, &load, 0,
                                                    header);
 
@@ -855,9 +853,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
                            valid_container_hdr((void *)header)) {
                                struct spl_load_info load;
 
-                               load.priv = header;
-                               spl_set_bl_len(&load, 1);
-                               load.read = sdp_load_read;
+                               spl_load_init(&load, sdp_load_read, header, 1);
                                spl_load_imx_container(spl_image, &load, 0);
                                return SDP_EXIT;
                        }
index fb26e3f55373e6349b0f40adc599e3dc893e1989..de808ccd41317661b6a8b9aa3f8c4e2fae98769d 100644 (file)
@@ -282,28 +282,32 @@ static inline void *spl_image_fdt_addr(struct spl_image_info *info)
 #endif
 }
 
+struct spl_load_info;
+
+/**
+ * spl_load_reader() - Read from device
+ *
+ * @load: Information about the load state
+ * @offset: Offset to read from in bytes. This must be a multiple of
+ *          @load->bl_len.
+ * @count: Number of bytes to read. This must be a multiple of
+ *         @load->bl_len.
+ * @buf: Buffer to read into
+ * @return number of bytes read, 0 on error
+ */
+typedef ulong (*spl_load_reader)(struct spl_load_info *load, ulong sector,
+                                ulong count, void *buf);
+
 /**
  * Information required to load data from a device
  *
+ * @read: Function to call to read from the device
  * @priv: Private data for the device
  * @bl_len: Block length for reading in bytes
- * @read: Function to call to read from the device
  */
 struct spl_load_info {
+       spl_load_reader read;
        void *priv;
-       /**
-        * read() - Read from device
-        *
-        * @load: Information about the load state
-        * @offset: Offset to read from in bytes. This must be a multiple of
-        *          @load->bl_len.
-        * @count: Number of bytes to read. This must be a multiple of
-        *         @load->bl_len.
-        * @buf: Buffer to read into
-        * @return number of bytes read, 0 on error
-        */
-       ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
-                     void *buf);
 #if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
        int bl_len;
 #endif
@@ -328,6 +332,18 @@ static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len)
 #endif
 }
 
+/**
+ * spl_load_init() - Set up a new spl_load_info structure
+ */
+static inline void spl_load_init(struct spl_load_info *load,
+                                spl_load_reader h_read, void *priv,
+                                uint bl_len)
+{
+       load->read = h_read;
+       load->priv = priv;
+       spl_set_bl_len(load, bl_len);
+}
+
 /*
  * We need to know the position of U-Boot in memory so we can jump to it. We
  * allow any U-Boot binary to be used (u-boot.bin, u-boot-nodtb.bin,
index 7cbad40ea0cde8d26b12fef50265114038fcf624..3b6206955d361954796b11786d98838e9b2e0e97 100644 (file)
@@ -343,9 +343,7 @@ static int spl_test_image(struct unit_test_state *uts, const char *test_name,
        } else {
                struct spl_load_info load;
 
-               spl_set_bl_len(&load, 1);
-               load.priv = img;
-               load.read = spl_test_read;
+               spl_load_init(&load, spl_test_read, img, 1);
                if (type == IMX8)
                        ut_assertok(spl_load_imx_container(&info_read, &load,
                                                           0));
index 56105a59236d8849caae1fecd425a8f08e2df4cb..d17cf116a0e8923885dc6b45246f2b289fbee604 100644 (file)
@@ -20,3 +20,4 @@ static int spl_test_load(struct unit_test_state *uts)
        return 0;
 }
 SPL_TEST(spl_test_load, 0);
+