[U-Boot] [PATCH v2 00/27] spl: Use linker list and parameters for SPL image loading

At present the SPL code uses a global spl_image variable which is shared amongst lots of files, some in common/spl and some elsewhere. There is no need for this to be global, and in fact a parameter makes it easier to understand what information the functions act on. It also reduces the BSS use in the SPL (at the expense of stack) which is useful on boards which don't have BSS available early on.
There are many global functions for loading images from each boot device type, like spl_mmc_load_image() and spl_spi_load_image(). Mostly these take the same parameters (none or a u32). There are various rules for compiling in calls to these functions and in some cases somewhat different rules for compiling in the functions themselves. For example, spl_spi_load_image() is called if either of CONFIG_SPL_SPI_SUPPORT or CONFIG_SPL_SPI__FLASHSUPPORT is enabled, but included in the image if CONFIG_SPL_SPI_LOAD is enabled.
There is work in progress to look at that problem (Andrew F. Davis has sent some patches [1]), and this series does not address it. But even with that fixed its seems better to use a linker list and a consistent function signature for loading images.
This series converts spl_image into a parameter and moves the SPL load functions into a linker list, where each method is declared in the file that provides it. The existing dispatching code is dropped.
There is a priorty value attached to each loader which should allow the existing ordering to be maintained.
Code size is about 20 bytes larger on average which I think is acceptable. The BSS size drops by about 64 bytes, but really this just transfers to the stack.
There is an obvious follow-on from this, to move boot_name_table[] into the same linker list struct (i.e. add a name field to struct spl_image_loader). The complication here is that we don't want naming if CONFIG_SPL_LIBCOMMON_SUPPORT is not enabled, since it bloats the code. In addition I think that common/spl/spl.c can be tidied up a little.
Finally, my reading of the load functions is that they could do with some rationalisation once we have a way to init any device without subsystem-specific function calls. For example, spl_sata.c and spl_usb.c contain very similar code but for the init methods.
[1] http://patchwork.ozlabs.org/patch/662945/
Changes in v2: - Fix typo - rename spL_find_loader() to spl_ll_find_loader() - Add a memset() to clear the spl_image data
Simon Glass (27): spl: Move spl_board_load_image() into a generic header spl: Add a parameter to spl_set_header_raw_uboot() spl: Add a parameter to spl_parse_image_header() spl: Add a parameter to jump_to_image_linux() spl: Add function comments to spl_start_uboot() spl: Kconfig: Move SPL_DISPLAY_PRINT to Kconfig spl: Convert boot_device into a struct spl: Add a way to declare an SPL image loader spl: Convert spl_ram_load_image() to use linker list spl: Convert spl_mmc_load_image() to use linker list spl: Convert spl_ubi_load_image() to use linker list spl: Convert spl_nand_load_image() to use linker list spl: Convert spl_onenand_load_image() to use linker list spl: Convert spl_nor_load_image() to use linker list spl: Convert spl_ymodem_load_image() to use linker list spl: Convert spl_usb_load_image() to use linker list spl: Convert spl_sata_load_image() to use linker list spl: spi: Move the generic SPI loader into common/spl spl: Convert spl_spi_load_image() to use linker list spi: Move freescale-specific code into a private header spl: Convert spl_net_load_image() to use linker list spl: Convert spl_board_load_image() to use linker list spl: Pass spl_image as a parameter to load_image() methods spl: Update ext functions to take an spl_image parameter spl: Update fat functions to take an spl_image parameter spl: Update spl_load_simple_fit() to take an spl_image param spl: Make spl_boot_list a local variable
arch/arm/cpu/armv7/omap4/Kconfig | 3 + arch/arm/cpu/armv7/omap5/Kconfig | 3 + arch/arm/include/asm/spl.h | 9 -- arch/arm/lib/spl.c | 4 +- arch/arm/mach-sunxi/board.c | 6 +- arch/arm/mach-uniphier/boot-mode/spl_board.c | 10 +- arch/microblaze/cpu/spl.c | 4 +- arch/powerpc/lib/spl.c | 4 +- arch/sandbox/cpu/spl.c | 4 +- arch/sandbox/include/asm/spl.h | 8 - board/Arcturus/ucp1020/spl.c | 2 - board/freescale/common/spl.h | 13 ++ board/freescale/p1010rdb/spl.c | 3 +- board/freescale/p1022ds/spl.c | 3 +- board/freescale/p1_p2_rdb_pc/spl.c | 3 +- board/freescale/t102xqds/spl.c | 7 +- board/freescale/t102xrdb/spl.c | 7 +- board/freescale/t104xrdb/spl.c | 7 +- board/freescale/t208xqds/spl.c | 7 +- board/freescale/t208xrdb/spl.c | 7 +- common/spl/Kconfig | 9 ++ common/spl/Makefile | 1 + common/spl/spl.c | 178 ++++++++------------- common/spl/spl_ext.c | 21 +-- common/spl/spl_fat.c | 23 +-- common/spl/spl_fit.c | 9 +- common/spl/spl_mmc.c | 72 +++++---- common/spl/spl_nand.c | 37 +++-- common/spl/spl_net.c | 36 ++++- common/spl/spl_nor.c | 18 ++- common/spl/spl_onenand.c | 9 +- common/spl/spl_sata.c | 15 +- .../mtd/spi/spi_spl_load.c => common/spl/spl_spi.c | 22 +-- common/spl/spl_ubi.c | 14 +- common/spl/spl_usb.c | 17 +- common/spl/spl_ymodem.c | 13 +- drivers/mtd/spi/Makefile | 1 - drivers/mtd/spi/fsl_espi_spl.c | 4 +- drivers/mtd/spi/sunxi_spi_spl.c | 11 +- include/configs/ti_omap4_common.h | 1 - include/configs/ti_omap5_common.h | 1 - include/spi_flash.h | 3 - include/spl.h | 151 +++++++++++++---- 43 files changed, 463 insertions(+), 317 deletions(-) create mode 100644 board/freescale/common/spl.h rename drivers/mtd/spi/spi_spl_load.c => common/spl/spl_spi.c (78%)

At present this is only used on ARM and sandbox, but it is just as applicable to other architectures. Move the function prototype into the generic SPL header.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
arch/arm/include/asm/spl.h | 9 --------- arch/sandbox/include/asm/spl.h | 8 -------- include/spl.h | 8 ++++++++ 3 files changed, 8 insertions(+), 17 deletions(-)
diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h index 6f312d6..a0bda28 100644 --- a/arch/arm/include/asm/spl.h +++ b/arch/arm/include/asm/spl.h @@ -33,15 +33,6 @@ enum { }; #endif
-/** - * Board specific load method for boards that have a special way of loading - * U-Boot, which does not fit with the existing SPL code. - * - * @return 0 on success, negative errno value on failure. - */ - -int spl_board_load_image(void); - /* Linker symbols. */ extern char __bss_start[], __bss_end[];
diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h index 59f2401..eb3cb56 100644 --- a/arch/sandbox/include/asm/spl.h +++ b/arch/sandbox/include/asm/spl.h @@ -8,14 +8,6 @@
#define CONFIG_SPL_BOARD_LOAD_IMAGE
-/** - * Board-specific load method for boards that have a special way of loading - * U-Boot, which does not fit with the existing SPL code. - * - * @return 0 on success, negative errno value on failure. - */ -int spl_board_load_image(void); - enum { BOOT_DEVICE_BOARD, }; diff --git a/include/spl.h b/include/spl.h index 8afa085..6c397ca 100644 --- a/include/spl.h +++ b/include/spl.h @@ -144,4 +144,12 @@ void spl_board_init(void); */ bool spl_was_boot_source(void);
+/** + * Board-specific load method for boards that have a special way of loading + * U-Boot, which does not fit with the existing SPL code. + * + * @return 0 on success, negative errno value on failure. + */ +int spl_board_load_image(void); + #endif

On Sat, Sep 24, 2016 at 06:19:51PM -0600, Simon Glass wrote:
At present this is only used on ARM and sandbox, but it is just as applicable to other architectures. Move the function prototype into the generic SPL header.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Rather than act on the global variable, pass the required struct in as a parameter.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
common/spl/spl.c | 14 +++++++------- common/spl/spl_nand.c | 2 +- include/spl.h | 13 ++++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index e14ec80..1a4a5d8 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -82,13 +82,13 @@ __weak void spl_board_prepare_for_boot(void) /* Nothing to do! */ }
-void spl_set_header_raw_uboot(void) +void spl_set_header_raw_uboot(struct spl_image_info *spl_image) { - spl_image.size = CONFIG_SYS_MONITOR_LEN; - spl_image.entry_point = CONFIG_SYS_UBOOT_START; - spl_image.load_addr = CONFIG_SYS_TEXT_BASE; - spl_image.os = IH_OS_U_BOOT; - spl_image.name = "U-Boot"; + spl_image->size = CONFIG_SYS_MONITOR_LEN; + spl_image->entry_point = CONFIG_SYS_UBOOT_START; + spl_image->load_addr = CONFIG_SYS_TEXT_BASE; + spl_image->os = IH_OS_U_BOOT; + spl_image->name = "U-Boot"; }
int spl_parse_image_header(const struct image_header *header) @@ -153,7 +153,7 @@ int spl_parse_image_header(const struct image_header *header) /* Signature not found - assume u-boot.bin */ debug("mkimage signature not found - ih_magic = %x\n", header->ih_magic); - spl_set_header_raw_uboot(); + spl_set_header_raw_uboot(&spl_image); #endif } return 0; diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 0e35e0f..8f9bd5da 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -20,7 +20,7 @@ int spl_nand_load_image(void) nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE, (void *)CONFIG_SYS_NAND_U_BOOT_DST); - spl_set_header_raw_uboot(); + spl_set_header_raw_uboot(&spl_image); nand_deselect();
return 0; diff --git a/include/spl.h b/include/spl.h index 6c397ca..ce449ff 100644 --- a/include/spl.h +++ b/include/spl.h @@ -67,7 +67,18 @@ extern struct spl_image_info spl_image; void preloader_console_init(void); u32 spl_boot_device(void); u32 spl_boot_mode(const u32 boot_device); -void spl_set_header_raw_uboot(void); + +/** + * spl_set_header_raw_uboot() - Set up a standard SPL image structure + * + * This sets up the given spl_image which the standard values obtained from + * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START, + * CONFIG_SYS_TEXT_BASE. + * + * @spl_image: Image to set up + */ +void spl_set_header_raw_uboot(struct spl_image_info *spl_image); + int spl_parse_image_header(const struct image_header *header); void spl_board_prepare_for_linux(void); void spl_board_prepare_for_boot(void);

On Sat, Sep 24, 2016 at 06:19:52PM -0600, Simon Glass wrote:
Rather than act on the global variable, pass the required struct in as a parameter.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Instead of using the global spl_image variable, pass the required struct in as an argument.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
arch/arm/mach-uniphier/boot-mode/spl_board.c | 2 +- common/spl/spl.c | 41 ++++++++++++++-------------- common/spl/spl_ext.c | 2 +- common/spl/spl_fat.c | 2 +- common/spl/spl_mmc.c | 2 +- common/spl/spl_nand.c | 4 +-- common/spl/spl_net.c | 3 +- common/spl/spl_nor.c | 4 +-- common/spl/spl_onenand.c | 2 +- common/spl/spl_ubi.c | 4 +-- common/spl/spl_ymodem.c | 5 ++-- drivers/mtd/spi/spi_spl_load.c | 4 +-- drivers/mtd/spi/sunxi_spi_spl.c | 2 +- include/spl.h | 20 ++++++++++++-- 14 files changed, 58 insertions(+), 39 deletions(-)
diff --git a/arch/arm/mach-uniphier/boot-mode/spl_board.c b/arch/arm/mach-uniphier/boot-mode/spl_board.c index 86292b6..63ab41c 100644 --- a/arch/arm/mach-uniphier/boot-mode/spl_board.c +++ b/arch/arm/mach-uniphier/boot-mode/spl_board.c @@ -113,7 +113,7 @@ int spl_board_load_image(void) return ret; }
- ret = spl_parse_image_header((void *)CONFIG_SYS_TEXT_BASE); + ret = spl_parse_image_header(&spl_image, (void *)CONFIG_SYS_TEXT_BASE); if (ret) return ret;
diff --git a/common/spl/spl.c b/common/spl/spl.c index 1a4a5d8..6195c06 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -91,33 +91,34 @@ void spl_set_header_raw_uboot(struct spl_image_info *spl_image) spl_image->name = "U-Boot"; }
-int spl_parse_image_header(const struct image_header *header) +int spl_parse_image_header(struct spl_image_info *spl_image, + const struct image_header *header) { u32 header_size = sizeof(struct image_header);
if (image_get_magic(header) == IH_MAGIC) { - if (spl_image.flags & SPL_COPY_PAYLOAD_ONLY) { + if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) { /* * On some system (e.g. powerpc), the load-address and * entry-point is located at address 0. We can't load * to 0-0x40. So skip header in this case. */ - spl_image.load_addr = image_get_load(header); - spl_image.entry_point = image_get_ep(header); - spl_image.size = image_get_data_size(header); + spl_image->load_addr = image_get_load(header); + spl_image->entry_point = image_get_ep(header); + spl_image->size = image_get_data_size(header); } else { - spl_image.entry_point = image_get_load(header); + spl_image->entry_point = image_get_load(header); /* Load including the header */ - spl_image.load_addr = spl_image.entry_point - + spl_image->load_addr = spl_image->entry_point - header_size; - spl_image.size = image_get_data_size(header) + + spl_image->size = image_get_data_size(header) + header_size; } - spl_image.os = image_get_os(header); - spl_image.name = image_get_name(header); + spl_image->os = image_get_os(header); + spl_image->name = image_get_name(header); debug("spl: payload image: %.*s load addr: 0x%x size: %d\n", - (int)sizeof(spl_image.name), spl_image.name, - spl_image.load_addr, spl_image.size); + (int)sizeof(spl_image->name), spl_image->name, + spl_image->load_addr, spl_image->size); } else { #ifdef CONFIG_SPL_PANIC_ON_RAW_IMAGE /* @@ -135,13 +136,13 @@ int spl_parse_image_header(const struct image_header *header) ulong start, end;
if (!bootz_setup((ulong)header, &start, &end)) { - spl_image.name = "Linux"; - spl_image.os = IH_OS_LINUX; - spl_image.load_addr = CONFIG_SYS_LOAD_ADDR; - spl_image.entry_point = CONFIG_SYS_LOAD_ADDR; - spl_image.size = end - start; + spl_image->name = "Linux"; + spl_image->os = IH_OS_LINUX; + spl_image->load_addr = CONFIG_SYS_LOAD_ADDR; + spl_image->entry_point = CONFIG_SYS_LOAD_ADDR; + spl_image->size = end - start; debug("spl: payload zImage, load addr: 0x%x size: %d\n", - spl_image.load_addr, spl_image.size); + spl_image->load_addr, spl_image->size); return 0; } #endif @@ -153,7 +154,7 @@ int spl_parse_image_header(const struct image_header *header) /* Signature not found - assume u-boot.bin */ debug("mkimage signature not found - ih_magic = %x\n", header->ih_magic); - spl_set_header_raw_uboot(&spl_image); + spl_set_header_raw_uboot(spl_image); #endif } return 0; @@ -209,7 +210,7 @@ static int spl_ram_load_image(void) header = (struct image_header *) (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
- spl_parse_image_header(header); + spl_parse_image_header(&spl_image, header); }
return 0; diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index a85dc85..e5af24e 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -48,7 +48,7 @@ int spl_load_image_ext(struct blk_desc *block_dev, goto end; }
- err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err < 0) { puts("spl: ext: failed to parse image header\n"); goto end; diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 73d33f5..68702a2 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -84,7 +84,7 @@ int spl_load_image_fat(struct blk_desc *block_dev,
return spl_load_simple_fit(&load, 0, header); } else { - err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err) goto end;
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 7c7f329..97c11b3 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -25,7 +25,7 @@ static int mmc_load_legacy(struct mmc *mmc, ulong sector, unsigned long count; int ret;
- ret = spl_parse_image_header(header); + ret = spl_parse_image_header(&spl_image, header); if (ret) return ret;
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 8f9bd5da..f25220f 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -59,7 +59,7 @@ static int spl_nand_load_element(int offset, struct image_header *header) load.read = spl_nand_fit_read; return spl_load_simple_fit(&load, offset, header); } else { - err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err) return err; return nand_spl_load_image(offset, spl_image.size, @@ -107,7 +107,7 @@ int spl_nand_load_image(void) /* load linux */ nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, sizeof(*header), (void *)header); - err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err) return err; if (header->ih_os == IH_OS_LINUX) { diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index ae71d26..f417d17 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -34,5 +34,6 @@ int spl_net_load_image(const char *device) printf("Problem booting with BOOTP\n"); return rv; } - return spl_parse_image_header((struct image_header *)load_addr); + return spl_parse_image_header(&spl_image, + (struct image_header *)load_addr); } diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index 8ea874c..57771e8 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -29,7 +29,7 @@ int spl_nor_load_image(void) if (image_get_os(header) == IH_OS_LINUX) { /* happy - was a Linux */
- ret = spl_parse_image_header(header); + ret = spl_parse_image_header(&spl_image, header); if (ret) return ret;
@@ -59,7 +59,7 @@ int spl_nor_load_image(void) * Load real U-Boot from its location in NOR flash to its * defined location in SDRAM */ - ret = spl_parse_image_header( + ret = spl_parse_image_header(&spl_image, (const struct image_header *)CONFIG_SYS_UBOOT_BASE); if (ret) return ret; diff --git a/common/spl/spl_onenand.c b/common/spl/spl_onenand.c index 1a28a84..8d2c51b 100644 --- a/common/spl/spl_onenand.c +++ b/common/spl/spl_onenand.c @@ -26,7 +26,7 @@ int spl_onenand_load_image(void) /* Load u-boot */ onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS, CONFIG_SYS_ONENAND_PAGE_SIZE, (void *)header); - ret = spl_parse_image_header(header); + ret = spl_parse_image_header(&spl_image, header); if (ret) return ret; onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS, diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c index f97e1ef..5198bab 100644 --- a/common/spl/spl_ubi.c +++ b/common/spl/spl_ubi.c @@ -54,7 +54,7 @@ int spl_ubi_load_image(u32 boot_device) ret = ubispl_load_volumes(&info, volumes, 2); if (!ret) { header = (struct image_header *)volumes[0].load_addr; - spl_parse_image_header(header); + spl_parse_image_header(&spl_image, header); puts("Linux loaded.\n"); goto out; } @@ -68,7 +68,7 @@ int spl_ubi_load_image(u32 boot_device)
ret = ubispl_load_volumes(&info, volumes, 1); if (!ret) - spl_parse_image_header(header); + spl_parse_image_header(&spl_image, header); out: #ifdef CONFIG_SPL_NAND_SUPPORT if (boot_device == BOOT_DEVICE_NAND) diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 5402301..1323b6f 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -108,8 +108,9 @@ int spl_ymodem_load_image(void) while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) size += res; } else { - spl_parse_image_header((struct image_header *)buf); - ret = spl_parse_image_header((struct image_header *)buf); + spl_parse_image_header(&spl_image, (struct image_header *)buf); + ret = spl_parse_image_header(&spl_image, + (struct image_header *)buf); if (ret) return ret; addr = spl_image.load_addr; diff --git a/drivers/mtd/spi/spi_spl_load.c b/drivers/mtd/spi/spi_spl_load.c index bac1e85..ac5eae3 100644 --- a/drivers/mtd/spi/spi_spl_load.c +++ b/drivers/mtd/spi/spi_spl_load.c @@ -32,7 +32,7 @@ static int spi_load_image_os(struct spi_flash *flash, if (image_get_magic(header) != IH_MAGIC) return -1;
- err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err) return err;
@@ -110,7 +110,7 @@ int spl_spi_load_image(void) CONFIG_SYS_SPI_U_BOOT_OFFS, header); } else { - err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err) return err; err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, diff --git a/drivers/mtd/spi/sunxi_spi_spl.c b/drivers/mtd/spi/sunxi_spi_spl.c index e3ded5b..a992bfa 100644 --- a/drivers/mtd/spi/sunxi_spi_spl.c +++ b/drivers/mtd/spi/sunxi_spi_spl.c @@ -271,7 +271,7 @@ int spl_spi_load_image(void) spi0_init();
spi0_read_data((void *)header, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40); - err = spl_parse_image_header(header); + err = spl_parse_image_header(&spl_image, header); if (err) return err;
diff --git a/include/spl.h b/include/spl.h index ce449ff..8147e6d 100644 --- a/include/spl.h +++ b/include/spl.h @@ -75,11 +75,27 @@ u32 spl_boot_mode(const u32 boot_device); * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START, * CONFIG_SYS_TEXT_BASE. * - * @spl_image: Image to set up + * @spl_image: Image description to set up */ void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
-int spl_parse_image_header(const struct image_header *header); +/** + * spl_parse_image_header() - parse the image header and set up info + * + * This parses the legacy image header information at @header and sets up + * @spl_image according to what is found. If no image header is found, then + * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is + * enabled, then this causes a panic. If CONFIG_SPL_ABORT_ON_RAW_IMAGE is + * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using + * spl_set_header_raw_uboot(), or possibly the bootz header. + * + * @spl_image: Image description to set up + * @header image header to parse + * @return 0 if a header was correctly parsed, -ve on error + */ +int spl_parse_image_header(struct spl_image_info *spl_image, + const struct image_header *header); + void spl_board_prepare_for_linux(void); void spl_board_prepare_for_boot(void); int spl_board_ubi_load_image(u32 boot_device);

On Sat, Sep 24, 2016 at 06:19:53PM -0600, Simon Glass wrote:
Instead of using the global spl_image variable, pass the required struct in as an argument.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Instead of using the global spl_image variable, pass the required struct in as an argument.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
arch/arm/lib/spl.c | 4 ++-- arch/microblaze/cpu/spl.c | 4 ++-- arch/powerpc/lib/spl.c | 4 ++-- common/spl/spl.c | 3 ++- include/spl.h | 12 +++++++++++- 5 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c index 3587ad6..e606d47 100644 --- a/arch/arm/lib/spl.c +++ b/arch/arm/lib/spl.c @@ -47,7 +47,7 @@ void __weak board_init_f(ulong dummy) * arg: Pointer to paramter image in RAM */ #ifdef CONFIG_SPL_OS_BOOT -void __noreturn jump_to_image_linux(void *arg) +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg) { unsigned long machid = 0xffffffff; #ifdef CONFIG_MACH_TYPE @@ -58,7 +58,7 @@ void __noreturn jump_to_image_linux(void *arg) typedef void (*image_entry_arg_t)(int, int, void *) __attribute__ ((noreturn)); image_entry_arg_t image_entry = - (image_entry_arg_t)(uintptr_t) spl_image.entry_point; + (image_entry_arg_t)(uintptr_t) spl_image->entry_point; cleanup_before_linux(); image_entry(0, machid, arg); } diff --git a/arch/microblaze/cpu/spl.c b/arch/microblaze/cpu/spl.c index f4bb091..8e6d926 100644 --- a/arch/microblaze/cpu/spl.c +++ b/arch/microblaze/cpu/spl.c @@ -29,13 +29,13 @@ void spl_board_init(void) }
#ifdef CONFIG_SPL_OS_BOOT -void __noreturn jump_to_image_linux(void *arg) +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg) { debug("Entering kernel arg pointer: 0x%p\n", arg); typedef void (*image_entry_arg_t)(char *, ulong, ulong) __attribute__ ((noreturn)); image_entry_arg_t image_entry = - (image_entry_arg_t)spl_image.entry_point; + (image_entry_arg_t)spl_image->entry_point;
image_entry(NULL, 0, (ulong)arg); } diff --git a/arch/powerpc/lib/spl.c b/arch/powerpc/lib/spl.c index 0e486cc..080b978 100644 --- a/arch/powerpc/lib/spl.c +++ b/arch/powerpc/lib/spl.c @@ -17,14 +17,14 @@ DECLARE_GLOBAL_DATA_PTR; * arg: Pointer to paramter image in RAM */ #ifdef CONFIG_SPL_OS_BOOT -void __noreturn jump_to_image_linux(void *arg) +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg) { debug("Entering kernel arg pointer: 0x%p\n", arg); typedef void (*image_entry_arg_t)(void *, ulong r4, ulong r5, ulong r6, ulong r7, ulong r8, ulong r9) __attribute__ ((noreturn)); image_entry_arg_t image_entry = - (image_entry_arg_t)spl_image.entry_point; + (image_entry_arg_t)spl_image->entry_point;
image_entry(arg, 0, 0, EPAPR_MAGIC, CONFIG_SYS_BOOTMAPSZ, 0, 0); } diff --git a/common/spl/spl.c b/common/spl/spl.c index 6195c06..cb96ef3 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -466,7 +466,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2) case IH_OS_LINUX: debug("Jumping to Linux\n"); spl_board_prepare_for_linux(); - jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR); + jump_to_image_linux(&spl_image, + (void *)CONFIG_SYS_SPL_ARGS_ADDR); #endif default: debug("Unsupported OS image.. Jumping nevertheless..\n"); diff --git a/include/spl.h b/include/spl.h index 8147e6d..aebafa3 100644 --- a/include/spl.h +++ b/include/spl.h @@ -99,7 +99,17 @@ int spl_parse_image_header(struct spl_image_info *spl_image, void spl_board_prepare_for_linux(void); void spl_board_prepare_for_boot(void); int spl_board_ubi_load_image(u32 boot_device); -void __noreturn jump_to_image_linux(void *arg); + +/** + * jump_to_image_linux() - Jump to a Linux kernel from SPL + * + * This jumps into a Linux kernel using the information in @spl_image. + * + * @spl_image: Image description to set up + * @arg: Argument to pass to Linux (typically a device tree pointer) + */ +void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, + void *arg); int spl_start_uboot(void); void spl_display_print(void);

On Sat, Sep 24, 2016 at 06:19:54PM -0600, Simon Glass wrote:
Instead of using the global spl_image variable, pass the required struct in as an argument.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add some comments to describe this function.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
include/spl.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/include/spl.h b/include/spl.h index aebafa3..742e6c2 100644 --- a/include/spl.h +++ b/include/spl.h @@ -110,7 +110,18 @@ int spl_board_ubi_load_image(u32 boot_device); */ void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, void *arg); + +/** + * spl_start_uboot() - Check if SPL should start the kernel or U-Boot + * + * This is called by the various SPL loaders to determine whether the board + * wants to load the kernel or U-Boot. This function should be provided by + * the board. + * + * @return 0 if SPL should start the kernel, 1 if U-Boot must be started + */ int spl_start_uboot(void); + void spl_display_print(void);
/* NAND SPL functions */

On Sat, Sep 24, 2016 at 06:19:55PM -0600, Simon Glass wrote:
Add some comments to describe this function.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Move this option to Kconfig and tidy up existing uses. Also add a function comment to the header file.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
arch/arm/cpu/armv7/omap4/Kconfig | 3 +++ arch/arm/cpu/armv7/omap5/Kconfig | 3 +++ common/spl/Kconfig | 9 +++++++++ include/configs/ti_omap4_common.h | 1 - include/configs/ti_omap5_common.h | 1 - include/spl.h | 7 +++++++ 6 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/armv7/omap4/Kconfig b/arch/arm/cpu/armv7/omap4/Kconfig index c3dc95f..2091dd7 100644 --- a/arch/arm/cpu/armv7/omap4/Kconfig +++ b/arch/arm/cpu/armv7/omap4/Kconfig @@ -33,6 +33,9 @@ config SPL_POWER_SUPPORT config SPL_SERIAL_SUPPORT default y
+config SPL_DISPLAY_PRINT + default y + choice prompt "OMAP4 board select" optional diff --git a/arch/arm/cpu/armv7/omap5/Kconfig b/arch/arm/cpu/armv7/omap5/Kconfig index ef68c53..caa420a 100644 --- a/arch/arm/cpu/armv7/omap5/Kconfig +++ b/arch/arm/cpu/armv7/omap5/Kconfig @@ -33,6 +33,9 @@ config SPL_POWER_SUPPORT config SPL_SERIAL_SUPPORT default y
+config SPL_DISPLAY_PRINT + default y + choice prompt "OMAP5 board select" optional diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 2a8ddbc..84670b1 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -61,6 +61,15 @@ config SPL_SEPARATE_BSS location is used. Normally we put the device tree at the end of BSS but with this option enabled, it goes at _image_binary_end.
+config SPL_DISPLAY_PRINT + depends on SPL + bool "Display a board-specific message in SPL" + help + If this option is enabled, U-Boot will call the function + spl_display_print() immediately after displaying the SPL console + banner ("U-Boot SPL ..."). This function should be provided by + the board. + config TPL bool depends on SPL && SUPPORT_TPL diff --git a/include/configs/ti_omap4_common.h b/include/configs/ti_omap4_common.h index 4115c78..8502c8a 100644 --- a/include/configs/ti_omap4_common.h +++ b/include/configs/ti_omap4_common.h @@ -151,7 +151,6 @@ * So moving TEXT_BASE down to non-HS limit. */ #define CONFIG_SPL_TEXT_BASE 0x40300000 -#define CONFIG_SPL_DISPLAY_PRINT #define CONFIG_SPL_LDSCRIPT "$(CPUDIR)/omap-common/u-boot-spl.lds" #define CONFIG_SYS_SPL_ARGS_ADDR (CONFIG_SYS_SDRAM_BASE + \ (128 << 20)) diff --git a/include/configs/ti_omap5_common.h b/include/configs/ti_omap5_common.h index cbdf0bc..5623a37 100644 --- a/include/configs/ti_omap5_common.h +++ b/include/configs/ti_omap5_common.h @@ -154,7 +154,6 @@ #define CONFIG_SPL_TEXT_BASE 0x40300000 #endif
-#define CONFIG_SPL_DISPLAY_PRINT #define CONFIG_SPL_LDSCRIPT "$(CPUDIR)/omap-common/u-boot-spl.lds" #define CONFIG_SYS_SPL_ARGS_ADDR (CONFIG_SYS_SDRAM_BASE + \ (128 << 20)) diff --git a/include/spl.h b/include/spl.h index 742e6c2..b6990b4 100644 --- a/include/spl.h +++ b/include/spl.h @@ -122,6 +122,13 @@ void __noreturn jump_to_image_linux(struct spl_image_info *spl_image, */ int spl_start_uboot(void);
+/** + * spl_display_print() - Display a board-specific message in SPL + * + * If CONFIG_SPL_DISPLAY_PRINT is enabled, U-Boot will call this function + * immediately after displaying the SPL console banner ("U-Boot SPL ..."). + * This function should be provided by the board. + */ void spl_display_print(void);
/* NAND SPL functions */

On Sat, Sep 24, 2016 at 06:19:56PM -0600, Simon Glass wrote:
Move this option to Kconfig and tidy up existing uses. Also add a function comment to the header file.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:19:56PM -0600, Simon Glass wrote:
Move this option to Kconfig and tidy up existing uses. Also add a function comment to the header file.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

At present some spl_xxx_load_image() functions take a parameter and some don't. Of those that do, most take an integer but one takes a string.
Convert this parameter into a struct so that we can pass all functions the same thing. This will allow us to use a common function signature.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
arch/arm/mach-sunxi/board.c | 2 +- arch/arm/mach-uniphier/boot-mode/spl_board.c | 2 +- arch/sandbox/cpu/spl.c | 2 +- common/spl/spl.c | 37 ++++++++++++++----------- common/spl/spl_mmc.c | 6 ++--- common/spl/spl_nand.c | 2 +- common/spl/spl_net.c | 6 ++--- common/spl/spl_nor.c | 2 +- common/spl/spl_onenand.c | 2 +- common/spl/spl_sata.c | 2 +- common/spl/spl_ubi.c | 6 ++--- common/spl/spl_usb.c | 2 +- common/spl/spl_ymodem.c | 2 +- drivers/mtd/spi/spi_spl_load.c | 2 +- drivers/mtd/spi/sunxi_spi_spl.c | 2 +- include/spl.h | 40 ++++++++++++++++++++-------- 16 files changed, 70 insertions(+), 47 deletions(-)
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c index 6d9518d..8a385a2 100644 --- a/arch/arm/mach-sunxi/board.c +++ b/arch/arm/mach-sunxi/board.c @@ -133,7 +133,7 @@ static int gpio_init(void) return 0; }
-int spl_board_load_image(void) +int spl_board_load_image(struct spl_boot_device *bootdev) { debug("Returning to FEL sp=%x, lr=%x\n", fel_stash.sp, fel_stash.lr); return_to_fel(fel_stash.sp, fel_stash.lr); diff --git a/arch/arm/mach-uniphier/boot-mode/spl_board.c b/arch/arm/mach-uniphier/boot-mode/spl_board.c index 63ab41c..4eadc2f 100644 --- a/arch/arm/mach-uniphier/boot-mode/spl_board.c +++ b/arch/arm/mach-uniphier/boot-mode/spl_board.c @@ -65,7 +65,7 @@ int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32), return 0; }
-int spl_board_load_image(void) +int spl_board_load_image(struct spl_boot_device *bootdev) { int (*send_cmd)(u32 cmd, u32 arg); int (*card_blockaddr)(u32 rca); diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c index e8349c0..4cee293 100644 --- a/arch/sandbox/cpu/spl.c +++ b/arch/sandbox/cpu/spl.c @@ -38,7 +38,7 @@ void spl_board_announce_boot_device(void) printf("%s\n", fname); }
-int spl_board_load_image(void) +int spl_board_load_image(struct spl_boot_device *bootdev) { char fname[256]; int ret; diff --git a/common/spl/spl.c b/common/spl/spl.c index cb96ef3..3716e6a 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -185,7 +185,7 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, return count; }
-static int spl_ram_load_image(void) +static int spl_ram_load_image(struct spl_boot_device *bootdev) { struct image_header *header;
@@ -346,66 +346,71 @@ static inline void announce_boot_device(u32 boot_device) { }
static int spl_load_image(u32 boot_device) { + struct spl_boot_device bootdev; + + bootdev.boot_device = boot_device; + bootdev.boot_device_name = NULL; + switch (boot_device) { #ifdef CONFIG_SPL_RAM_DEVICE case BOOT_DEVICE_RAM: - return spl_ram_load_image(); + return spl_ram_load_image(&bootdev); #endif #ifdef CONFIG_SPL_MMC_SUPPORT case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2: case BOOT_DEVICE_MMC2_2: - return spl_mmc_load_image(boot_device); + return spl_mmc_load_image(&bootdev); #endif #ifdef CONFIG_SPL_UBI case BOOT_DEVICE_NAND: case BOOT_DEVICE_ONENAND: - return spl_ubi_load_image(boot_device); + return spl_ubi_load_image(&bootdev); #else #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND: - return spl_nand_load_image(); + return spl_nand_load_image(&bootdev); #endif #ifdef CONFIG_SPL_ONENAND_SUPPORT case BOOT_DEVICE_ONENAND: - return spl_onenand_load_image(); + return spl_onenand_load_image(&bootdev); #endif #endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR: - return spl_nor_load_image(); + return spl_nor_load_image(&bootdev); #endif #ifdef CONFIG_SPL_YMODEM_SUPPORT case BOOT_DEVICE_UART: - return spl_ymodem_load_image(); + return spl_ymodem_load_image(&bootdev); #endif #if defined(CONFIG_SPL_SPI_SUPPORT) || defined(CONFIG_SPL_SPI_FLASH_SUPPORT) case BOOT_DEVICE_SPI: - return spl_spi_load_image(); + return spl_spi_load_image(&bootdev); #endif #ifdef CONFIG_SPL_ETH_SUPPORT case BOOT_DEVICE_CPGMAC: #ifdef CONFIG_SPL_ETH_DEVICE - return spl_net_load_image(CONFIG_SPL_ETH_DEVICE); -#else - return spl_net_load_image(NULL); + bootdev.boot_device_name = CONFIG_SPL_ETH_DEVICE; #endif + return spl_net_load_image(&bootdev); #endif #ifdef CONFIG_SPL_USBETH_SUPPORT case BOOT_DEVICE_USBETH: - return spl_net_load_image("usb_ether"); + bootdev.boot_device_name = "usb_ether"; + return spl_net_load_image(&bootdev); #endif #ifdef CONFIG_SPL_USB_SUPPORT case BOOT_DEVICE_USB: - return spl_usb_load_image(); + return spl_usb_load_image(&bootdev); #endif #ifdef CONFIG_SPL_SATA_SUPPORT case BOOT_DEVICE_SATA: - return spl_sata_load_image(); + return spl_sata_load_image(&bootdev); #endif #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE case BOOT_DEVICE_BOARD: - return spl_board_load_image(); + return spl_board_load_image(&bootdev); #endif default: #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 97c11b3..899caf4 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -267,14 +267,14 @@ int spl_mmc_do_fs_boot(struct mmc *mmc) } #endif
-int spl_mmc_load_image(u32 boot_device) +int spl_mmc_load_image(struct spl_boot_device *bootdev) { struct mmc *mmc = NULL; u32 boot_mode; int err = 0; __maybe_unused int part;
- err = spl_mmc_find_device(&mmc, boot_device); + err = spl_mmc_find_device(&mmc, bootdev->boot_device); if (err) return err;
@@ -286,7 +286,7 @@ int spl_mmc_load_image(u32 boot_device) return err; }
- boot_mode = spl_boot_mode(boot_device); + boot_mode = spl_boot_mode(bootdev->boot_device); err = -EINVAL; switch (boot_mode) { case MMCSD_MODE_EMMCBOOT: diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index f25220f..575de66 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -13,7 +13,7 @@ #include <fdt.h>
#if defined(CONFIG_SPL_NAND_RAW_ONLY) -int spl_nand_load_image(void) +int spl_nand_load_image(struct spl_boot_device *bootdev) { nand_init();
diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index f417d17..730f88e 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -14,7 +14,7 @@
DECLARE_GLOBAL_DATA_PTR;
-int spl_net_load_image(const char *device) +int spl_net_load_image(struct spl_boot_device *bootdev) { int rv;
@@ -27,8 +27,8 @@ int spl_net_load_image(const char *device) printf("No Ethernet devices found\n"); return -ENODEV; } - if (device) - setenv("ethact", device); + if (bootdev->boot_device_name) + setenv("ethact", bootdev->boot_device_name); rv = net_loop(BOOTP); if (rv < 0) { printf("Problem booting with BOOTP\n"); diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index 57771e8..f10d679 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -7,7 +7,7 @@ #include <common.h> #include <spl.h>
-int spl_nor_load_image(void) +int spl_nor_load_image(struct spl_boot_device *bootdev) { int ret; /* diff --git a/common/spl/spl_onenand.c b/common/spl/spl_onenand.c index 8d2c51b..f5e2f95 100644 --- a/common/spl/spl_onenand.c +++ b/common/spl/spl_onenand.c @@ -14,7 +14,7 @@ #include <asm/io.h> #include <onenand_uboot.h>
-int spl_onenand_load_image(void) +int spl_onenand_load_image(struct spl_boot_device *bootdev) { struct image_header *header; int ret; diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 9d8cc7c..77fd73c 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -20,7 +20,7 @@
DECLARE_GLOBAL_DATA_PTR;
-int spl_sata_load_image(void) +int spl_sata_load_image(struct spl_boot_device *bootdev) { int err; struct blk_desc *stor_dev; diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c index 5198bab..d64e6cf 100644 --- a/common/spl/spl_ubi.c +++ b/common/spl/spl_ubi.c @@ -12,14 +12,14 @@ #include <ubispl.h> #include <spl.h>
-int spl_ubi_load_image(u32 boot_device) +int spl_ubi_load_image(struct spl_boot_device *bootdev) { struct image_header *header; struct ubispl_info info; struct ubispl_load volumes[2]; int ret = 1;
- switch (boot_device) { + switch (bootdev->boot_device) { #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND: nand_init(); @@ -71,7 +71,7 @@ int spl_ubi_load_image(u32 boot_device) spl_parse_image_header(&spl_image, header); out: #ifdef CONFIG_SPL_NAND_SUPPORT - if (boot_device == BOOT_DEVICE_NAND) + if (bootdev->boot_device == BOOT_DEVICE_NAND) nand_deselect(); #endif return ret; diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index 04fa667..f990336 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -22,7 +22,7 @@ DECLARE_GLOBAL_DATA_PTR; static int usb_stor_curr_dev = -1; /* current device */ #endif
-int spl_usb_load_image(void) +int spl_usb_load_image(struct spl_boot_device *bootdev) { int err; struct blk_desc *stor_dev; diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 1323b6f..d82b138 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -68,7 +68,7 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset, return size; }
-int spl_ymodem_load_image(void) +int spl_ymodem_load_image(struct spl_boot_device *bootdev) { int size = 0; int err; diff --git a/drivers/mtd/spi/spi_spl_load.c b/drivers/mtd/spi/spi_spl_load.c index ac5eae3..e4cc0d0 100644 --- a/drivers/mtd/spi/spi_spl_load.c +++ b/drivers/mtd/spi/spi_spl_load.c @@ -65,7 +65,7 @@ static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, * configured and available since this code loads the main U-Boot image * from SPI into SDRAM and starts it from there. */ -int spl_spi_load_image(void) +int spl_spi_load_image(struct spl_boot_device *bootdev) { int err = 0; struct spi_flash *flash; diff --git a/drivers/mtd/spi/sunxi_spi_spl.c b/drivers/mtd/spi/sunxi_spi_spl.c index a992bfa..767959c 100644 --- a/drivers/mtd/spi/sunxi_spi_spl.c +++ b/drivers/mtd/spi/sunxi_spi_spl.c @@ -262,7 +262,7 @@ static void spi0_read_data(void *buf, u32 addr, u32 len)
/*****************************************************************************/
-int spl_spi_load_image(void) +int spl_spi_load_image(struct spl_boot_device *bootdev) { int err; struct image_header *header; diff --git a/include/spl.h b/include/spl.h index b6990b4..63ca68c 100644 --- a/include/spl.h +++ b/include/spl.h @@ -131,35 +131,53 @@ int spl_start_uboot(void); */ void spl_display_print(void);
+/** + * struct spl_boot_device - Describes a boot device used by SPL + * + * @boot_device: A number indicating the BOOT_DEVICE type. There are various + * BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently + * numbered. + * @boot_device_name: Named boot device, or NULL if none. + * + * Note: Additional fields can be added here, bearing in mind that SPL is + * size-sensitive and common fields will be present on all boards. This + * struct can also be used to return additional information about the load + * process if that becomes useful. + */ +struct spl_boot_device { + uint boot_device; + const char *boot_device_name; +}; + /* NAND SPL functions */ -int spl_nand_load_image(void); +int spl_nand_load_image(struct spl_boot_device *bootdev);
/* OneNAND SPL functions */ -int spl_onenand_load_image(void); +int spl_onenand_load_image(struct spl_boot_device *bootdev);
/* NOR SPL functions */ -int spl_nor_load_image(void); +int spl_nor_load_image(struct spl_boot_device *bootdev);
/* UBI SPL functions */ -int spl_ubi_load_image(u32 boot_device); +int spl_ubi_load_image(struct spl_boot_device *bootdev);
/* MMC SPL functions */ -int spl_mmc_load_image(u32 boot_device); +int spl_mmc_load_image(struct spl_boot_device *bootdev);
/* YMODEM SPL functions */ -int spl_ymodem_load_image(void); +int spl_ymodem_load_image(struct spl_boot_device *bootdev);
/* SPI SPL functions */ -int spl_spi_load_image(void); +int spl_spi_load_image(struct spl_boot_device *bootdev);
/* Ethernet SPL functions */ -int spl_net_load_image(const char *device); +int spl_net_load_image(struct spl_boot_device *bootdev);
/* USB SPL functions */ -int spl_usb_load_image(void); +int spl_usb_load_image(struct spl_boot_device *bootdev);
/* SATA SPL functions */ -int spl_sata_load_image(void); +int spl_sata_load_image(struct spl_boot_device *bootdev);
/* SPL FAT image functions */ int spl_load_image_fat(struct blk_desc *block_dev, int partition, @@ -205,6 +223,6 @@ bool spl_was_boot_source(void); * * @return 0 on success, negative errno value on failure. */ -int spl_board_load_image(void); +int spl_board_load_image(struct spl_boot_device *bootdev);
#endif

On Sat, Sep 24, 2016 at 06:19:57PM -0600, Simon Glass wrote:
At present some spl_xxx_load_image() functions take a parameter and some don't. Of those that do, most take an integer but one takes a string.
Convert this parameter into a struct so that we can pass all functions the same thing. This will allow us to use a common function signature.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:19:57PM -0600, Simon Glass wrote:
At present some spl_xxx_load_image() functions take a parameter and some don't. Of those that do, most take an integer but one takes a string.
Convert this parameter into a struct so that we can pass all functions the same thing. This will allow us to use a common function signature.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list macro which can be used to declare an SPL image loader. Update spl_load_image() to search available loaders for the correct one.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Fix typo - rename spL_find_loader() to spl_ll_find_loader()
common/spl/spl.c | 20 ++++++++++++++++++++ include/spl.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 3716e6a..4c3784c 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -344,12 +344,32 @@ static void announce_boot_device(u32 boot_device) static inline void announce_boot_device(u32 boot_device) { } #endif
+static struct spl_image_loader *spl_ll_find_loader(uint boot_device) +{ + struct spl_image_loader *drv = + ll_entry_start(struct spl_image_loader, spl_image_loader); + const int n_ents = + ll_entry_count(struct spl_image_loader, spl_image_loader); + struct spl_image_loader *entry; + + for (entry = drv; entry != drv + n_ents; entry++) { + if (boot_device == entry->boot_device) + return entry; + } + + /* Not found */ + return NULL; +} + static int spl_load_image(u32 boot_device) { struct spl_boot_device bootdev; + struct spl_image_loader *loader = spl_ll_find_loader(boot_device);
bootdev.boot_device = boot_device; bootdev.boot_device_name = NULL; + if (loader) + return loader->load_image(&bootdev);
switch (boot_device) { #ifdef CONFIG_SPL_RAM_DEVICE diff --git a/include/spl.h b/include/spl.h index 63ca68c..8f19310 100644 --- a/include/spl.h +++ b/include/spl.h @@ -149,6 +149,38 @@ struct spl_boot_device { const char *boot_device_name; };
+/** + * Holds information about a way of loading an SPL image + * + * @boot_device: Boot device that this loader supports + * @load_image: Function to call to load image + */ +struct spl_image_loader { + uint boot_device; + /** + * load_image() - Load an SPL image + * + * @bootdev: describes the boot device to load from + */ + int (*load_image)(struct spl_boot_device *bootdev); +}; + +/* Declare an SPL image loader */ +#define SPL_LOAD_IMAGE(__name) \ + ll_entry_declare(struct spl_image_loader, __name, spl_image_loader) + +/* + * __priority is the priority of this method, 0 meaning it will be the top + * choice for this device, 9 meaning it is the bottom choice. + * __boot_device is the BOOT_DEVICE_... value + * __method is the load_image function to call + */ +#define SPL_LOAD_IMAGE_METHOD(__priority, __boot_device, __method) \ + SPL_LOAD_IMAGE(__method ## __priority ## __boot_device) = { \ + .boot_device = __boot_device, \ + .load_image = __method, \ + } + /* NAND SPL functions */ int spl_nand_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:19:58PM -0600, Simon Glass wrote:
Add a linker list macro which can be used to declare an SPL image loader. Update spl_load_image() to search available loaders for the correct one.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:19:58PM -0600, Simon Glass wrote:
Add a linker list macro which can be used to declare an SPL image loader. Update spl_load_image() to search available loaders for the correct one.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 4c3784c..2bba423 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -215,6 +215,7 @@ static int spl_ram_load_image(struct spl_boot_device *bootdev)
return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_RAM, spl_ram_load_image); #endif
int spl_init(void) @@ -372,10 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_RAM_DEVICE - case BOOT_DEVICE_RAM: - return spl_ram_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_MMC_SUPPORT case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2:

On Sat, Sep 24, 2016 at 06:19:59PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:19:59PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Converted the DFU case as well and applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 6 ------ common/spl/spl_mmc.c | 6 +++++- include/spl.h | 3 --- 3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 2bba423..3162bf4 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,12 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_MMC_SUPPORT - case BOOT_DEVICE_MMC1: - case BOOT_DEVICE_MMC2: - case BOOT_DEVICE_MMC2_2: - return spl_mmc_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_UBI case BOOT_DEVICE_NAND: case BOOT_DEVICE_ONENAND: diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 899caf4..5e8172e 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -267,7 +267,7 @@ int spl_mmc_do_fs_boot(struct mmc *mmc) } #endif
-int spl_mmc_load_image(struct spl_boot_device *bootdev) +static int spl_mmc_load_image(struct spl_boot_device *bootdev) { struct mmc *mmc = NULL; u32 boot_mode; @@ -345,3 +345,7 @@ int spl_mmc_load_image(struct spl_boot_device *bootdev)
return err; } + +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_MMC1, spl_mmc_load_image); +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_MMC2, spl_mmc_load_image); +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image); diff --git a/include/spl.h b/include/spl.h index 8f19310..dc57c66 100644 --- a/include/spl.h +++ b/include/spl.h @@ -193,9 +193,6 @@ int spl_nor_load_image(struct spl_boot_device *bootdev); /* UBI SPL functions */ int spl_ubi_load_image(struct spl_boot_device *bootdev);
-/* MMC SPL functions */ -int spl_mmc_load_image(struct spl_boot_device *bootdev); - /* YMODEM SPL functions */ int spl_ymodem_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:00PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:00PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 6 ------ common/spl/spl_ubi.c | 3 +++ include/spl.h | 3 --- 3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 3162bf4..d6615f1 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,11 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_UBI - case BOOT_DEVICE_NAND: - case BOOT_DEVICE_ONENAND: - return spl_ubi_load_image(&bootdev); -#else #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND: return spl_nand_load_image(&bootdev); @@ -386,7 +381,6 @@ static int spl_load_image(u32 boot_device) case BOOT_DEVICE_ONENAND: return spl_onenand_load_image(&bootdev); #endif -#endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR: return spl_nor_load_image(&bootdev); diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c index d64e6cf..3ef00aa 100644 --- a/common/spl/spl_ubi.c +++ b/common/spl/spl_ubi.c @@ -76,3 +76,6 @@ out: #endif return ret; } +/* Use priorty 0 so that Ubi will override NAND and ONENAND methods */ +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_NAND, spl_ubi_load_image); +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_ONENAND, spl_ubi_load_image); diff --git a/include/spl.h b/include/spl.h index dc57c66..cdcd88f 100644 --- a/include/spl.h +++ b/include/spl.h @@ -190,9 +190,6 @@ int spl_onenand_load_image(struct spl_boot_device *bootdev); /* NOR SPL functions */ int spl_nor_load_image(struct spl_boot_device *bootdev);
-/* UBI SPL functions */ -int spl_ubi_load_image(struct spl_boot_device *bootdev); - /* YMODEM SPL functions */ int spl_ymodem_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:01PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:01PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_nand.c | 4 +++- include/spl.h | 3 --- 3 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index d6615f1..888432a 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,10 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_NAND_SUPPORT - case BOOT_DEVICE_NAND: - return spl_nand_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_ONENAND_SUPPORT case BOOT_DEVICE_ONENAND: return spl_onenand_load_image(&bootdev); diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 575de66..ed758e5 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -67,7 +67,7 @@ static int spl_nand_load_element(int offset, struct image_header *header) } }
-int spl_nand_load_image(void) +static int spl_nand_load_image(struct spl_boot_device *bootdev) { int err; struct image_header *header; @@ -145,3 +145,5 @@ int spl_nand_load_image(void) return err; } #endif +/* Use priorty 1 so that Ubi can override this */ +SPL_LOAD_IMAGE_METHOD(1, BOOT_DEVICE_NAND, spl_nand_load_image); diff --git a/include/spl.h b/include/spl.h index cdcd88f..86bddd8 100644 --- a/include/spl.h +++ b/include/spl.h @@ -181,9 +181,6 @@ struct spl_image_loader { .load_image = __method, \ }
-/* NAND SPL functions */ -int spl_nand_load_image(struct spl_boot_device *bootdev); - /* OneNAND SPL functions */ int spl_onenand_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:02PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:02PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_onenand.c | 4 +++- include/spl.h | 3 --- 3 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 888432a..b838b3a 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,10 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_ONENAND_SUPPORT - case BOOT_DEVICE_ONENAND: - return spl_onenand_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR: return spl_nor_load_image(&bootdev); diff --git a/common/spl/spl_onenand.c b/common/spl/spl_onenand.c index f5e2f95..361a1b3 100644 --- a/common/spl/spl_onenand.c +++ b/common/spl/spl_onenand.c @@ -14,7 +14,7 @@ #include <asm/io.h> #include <onenand_uboot.h>
-int spl_onenand_load_image(struct spl_boot_device *bootdev) +static int spl_onenand_load_image(struct spl_boot_device *bootdev) { struct image_header *header; int ret; @@ -34,3 +34,5 @@ int spl_onenand_load_image(struct spl_boot_device *bootdev)
return 0; } +/* Use priorty 1 so that Ubi can override this */ +SPL_LOAD_IMAGE_METHOD(1, BOOT_DEVICE_ONENAND, spl_onenand_load_image); diff --git a/include/spl.h b/include/spl.h index 86bddd8..b7a3592 100644 --- a/include/spl.h +++ b/include/spl.h @@ -181,9 +181,6 @@ struct spl_image_loader { .load_image = __method, \ }
-/* OneNAND SPL functions */ -int spl_onenand_load_image(struct spl_boot_device *bootdev); - /* NOR SPL functions */ int spl_nor_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:03PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:03PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_nor.c | 3 ++- include/spl.h | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index b838b3a..2ea7c4e 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,10 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_NOR_SUPPORT - case BOOT_DEVICE_NOR: - return spl_nor_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_YMODEM_SUPPORT case BOOT_DEVICE_UART: return spl_ymodem_load_image(&bootdev); diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index f10d679..b55fcc5 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -7,7 +7,7 @@ #include <common.h> #include <spl.h>
-int spl_nor_load_image(struct spl_boot_device *bootdev) +static int spl_nor_load_image(struct spl_boot_device *bootdev) { int ret; /* @@ -70,3 +70,4 @@ int spl_nor_load_image(struct spl_boot_device *bootdev)
return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_NOR, spl_nor_load_image); diff --git a/include/spl.h b/include/spl.h index b7a3592..6338bcf 100644 --- a/include/spl.h +++ b/include/spl.h @@ -181,9 +181,6 @@ struct spl_image_loader { .load_image = __method, \ }
-/* NOR SPL functions */ -int spl_nor_load_image(struct spl_boot_device *bootdev); - /* YMODEM SPL functions */ int spl_ymodem_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:04PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:04PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_ymodem.c | 3 ++- include/spl.h | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 2ea7c4e..1d037f5 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,10 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_YMODEM_SUPPORT - case BOOT_DEVICE_UART: - return spl_ymodem_load_image(&bootdev); -#endif #if defined(CONFIG_SPL_SPI_SUPPORT) || defined(CONFIG_SPL_SPI_FLASH_SUPPORT) case BOOT_DEVICE_SPI: return spl_spi_load_image(&bootdev); diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index d82b138..168b951 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -68,7 +68,7 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset, return size; }
-int spl_ymodem_load_image(struct spl_boot_device *bootdev) +static int spl_ymodem_load_image(struct spl_boot_device *bootdev) { int size = 0; int err; @@ -132,3 +132,4 @@ end_stream: printf("Loaded %d bytes\n", size); return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_UART, spl_ymodem_load_image); diff --git a/include/spl.h b/include/spl.h index 6338bcf..3605911 100644 --- a/include/spl.h +++ b/include/spl.h @@ -181,9 +181,6 @@ struct spl_image_loader { .load_image = __method, \ }
-/* YMODEM SPL functions */ -int spl_ymodem_load_image(struct spl_boot_device *bootdev); - /* SPI SPL functions */ int spl_spi_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:05PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:05PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_usb.c | 3 ++- include/spl.h | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 1d037f5..5e7ced3 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -389,10 +389,6 @@ static int spl_load_image(u32 boot_device) bootdev.boot_device_name = "usb_ether"; return spl_net_load_image(&bootdev); #endif -#ifdef CONFIG_SPL_USB_SUPPORT - case BOOT_DEVICE_USB: - return spl_usb_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_SATA_SUPPORT case BOOT_DEVICE_SATA: return spl_sata_load_image(&bootdev); diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index f990336..2bc321a 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -22,7 +22,7 @@ DECLARE_GLOBAL_DATA_PTR; static int usb_stor_curr_dev = -1; /* current device */ #endif
-int spl_usb_load_image(struct spl_boot_device *bootdev) +static int spl_usb_load_image(struct spl_boot_device *bootdev) { int err; struct blk_desc *stor_dev; @@ -61,3 +61,4 @@ int spl_usb_load_image(struct spl_boot_device *bootdev)
return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USB, spl_usb_load_image); diff --git a/include/spl.h b/include/spl.h index 3605911..677e3a1 100644 --- a/include/spl.h +++ b/include/spl.h @@ -187,9 +187,6 @@ int spl_spi_load_image(struct spl_boot_device *bootdev); /* Ethernet SPL functions */ int spl_net_load_image(struct spl_boot_device *bootdev);
-/* USB SPL functions */ -int spl_usb_load_image(struct spl_boot_device *bootdev); - /* SATA SPL functions */ int spl_sata_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:06PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:06PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_sata.c | 3 ++- include/spl.h | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 5e7ced3..3f4e48a 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -389,10 +389,6 @@ static int spl_load_image(u32 boot_device) bootdev.boot_device_name = "usb_ether"; return spl_net_load_image(&bootdev); #endif -#ifdef CONFIG_SPL_SATA_SUPPORT - case BOOT_DEVICE_SATA: - return spl_sata_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE case BOOT_DEVICE_BOARD: return spl_board_load_image(&bootdev); diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 77fd73c..1a21c05 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -20,7 +20,7 @@
DECLARE_GLOBAL_DATA_PTR;
-int spl_sata_load_image(struct spl_boot_device *bootdev) +static int spl_sata_load_image(struct spl_boot_device *bootdev) { int err; struct blk_desc *stor_dev; @@ -53,3 +53,4 @@ int spl_sata_load_image(struct spl_boot_device *bootdev)
return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_SATA, spl_sata_load_image); diff --git a/include/spl.h b/include/spl.h index 677e3a1..279896d 100644 --- a/include/spl.h +++ b/include/spl.h @@ -187,9 +187,6 @@ int spl_spi_load_image(struct spl_boot_device *bootdev); /* Ethernet SPL functions */ int spl_net_load_image(struct spl_boot_device *bootdev);
-/* SATA SPL functions */ -int spl_sata_load_image(struct spl_boot_device *bootdev); - /* SPL FAT image functions */ int spl_load_image_fat(struct blk_desc *block_dev, int partition, const char *filename);

On Sat, Sep 24, 2016 at 06:20:07PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:07PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

All the other SPL loaders are in this directory, so move the SPI one in there too.
There are two board-specific SPI loaders (fsl and sunxi). These remain in the drivers/mtd/spi directory, since they do not contain generic code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
common/spl/Makefile | 1 + drivers/mtd/spi/spi_spl_load.c => common/spl/spl_spi.c | 0 drivers/mtd/spi/Makefile | 1 - 3 files changed, 1 insertion(+), 1 deletion(-) rename drivers/mtd/spi/spi_spl_load.c => common/spl/spl_spi.c (100%)
diff --git a/common/spl/Makefile b/common/spl/Makefile index b15f0f6..275b06c 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -24,4 +24,5 @@ obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o obj-$(CONFIG_SPL_FAT_SUPPORT) += spl_fat.o obj-$(CONFIG_SPL_EXT_SUPPORT) += spl_ext.o obj-$(CONFIG_SPL_SATA_SUPPORT) += spl_sata.o +obj-$(CONFIG_SPL_SPI_LOAD) += spl_spi.o endif diff --git a/drivers/mtd/spi/spi_spl_load.c b/common/spl/spl_spi.c similarity index 100% rename from drivers/mtd/spi/spi_spl_load.c rename to common/spl/spl_spi.c diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile index 6f47a66..f3dc409 100644 --- a/drivers/mtd/spi/Makefile +++ b/drivers/mtd/spi/Makefile @@ -8,7 +8,6 @@ obj-$(CONFIG_DM_SPI_FLASH) += sf-uclass.o
ifdef CONFIG_SPL_BUILD -obj-$(CONFIG_SPL_SPI_LOAD) += spi_spl_load.o obj-$(CONFIG_SPL_SPI_BOOT) += fsl_espi_spl.o obj-$(CONFIG_SPL_SPI_SUNXI) += sunxi_spi_spl.o endif

On Sat, Sep 24, 2016 at 06:20:08PM -0600, Simon Glass wrote:
All the other SPL loaders are in this directory, so move the SPI one in there too.
There are two board-specific SPI loaders (fsl and sunxi). These remain in the drivers/mtd/spi directory, since they do not contain generic code.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code. Also set up the sunxi function.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 4 ---- common/spl/spl_spi.c | 4 +++- drivers/mtd/spi/sunxi_spi_spl.c | 4 +++- include/spl.h | 3 --- 4 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 3f4e48a..9c8dcbb 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,10 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#if defined(CONFIG_SPL_SPI_SUPPORT) || defined(CONFIG_SPL_SPI_FLASH_SUPPORT) - case BOOT_DEVICE_SPI: - return spl_spi_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_ETH_SUPPORT case BOOT_DEVICE_CPGMAC: #ifdef CONFIG_SPL_ETH_DEVICE diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index e4cc0d0..b9294f2 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -65,7 +65,7 @@ static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, * configured and available since this code loads the main U-Boot image * from SPI into SDRAM and starts it from there. */ -int spl_spi_load_image(struct spl_boot_device *bootdev) +static int spl_spi_load_image(struct spl_boot_device *bootdev) { int err = 0; struct spi_flash *flash; @@ -121,3 +121,5 @@ int spl_spi_load_image(struct spl_boot_device *bootdev)
return err; } +/* Use priorty 1 so that boards can override this */ +SPL_LOAD_IMAGE_METHOD(1, BOOT_DEVICE_SPI, spl_spi_load_image); diff --git a/drivers/mtd/spi/sunxi_spi_spl.c b/drivers/mtd/spi/sunxi_spi_spl.c index 767959c..70d6d15 100644 --- a/drivers/mtd/spi/sunxi_spi_spl.c +++ b/drivers/mtd/spi/sunxi_spi_spl.c @@ -262,7 +262,7 @@ static void spi0_read_data(void *buf, u32 addr, u32 len)
/*****************************************************************************/
-int spl_spi_load_image(struct spl_boot_device *bootdev) +static int spl_spi_load_image(struct spl_boot_device *bootdev) { int err; struct image_header *header; @@ -281,3 +281,5 @@ int spl_spi_load_image(struct spl_boot_device *bootdev) spi0_deinit(); return 0; } +/* Use priorty 0 to override the default if it happens to be linked in */ +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_SPI, spl_spi_load_image); diff --git a/include/spl.h b/include/spl.h index 279896d..29dcf5b 100644 --- a/include/spl.h +++ b/include/spl.h @@ -181,9 +181,6 @@ struct spl_image_loader { .load_image = __method, \ }
-/* SPI SPL functions */ -int spl_spi_load_image(struct spl_boot_device *bootdev); - /* Ethernet SPL functions */ int spl_net_load_image(struct spl_boot_device *bootdev);

On Sat, Sep 24, 2016 at 06:20:09PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code. Also set up the sunxi function.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:09PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code. Also set up the sunxi function.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

At present there are two SPI functions only used by freescale which are defined in the spi_flash.h header. One function name matches an existing generic SPL function.
Move these into a private header to avoid confusion.
Arcturus looks like it does not actually support SPI, so drop the SPI code from that board.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
board/Arcturus/ucp1020/spl.c | 2 -- board/freescale/common/spl.h | 13 +++++++++++++ board/freescale/p1010rdb/spl.c | 3 ++- board/freescale/p1022ds/spl.c | 3 ++- board/freescale/p1_p2_rdb_pc/spl.c | 3 ++- board/freescale/t102xqds/spl.c | 7 ++++--- board/freescale/t102xrdb/spl.c | 7 ++++--- board/freescale/t104xrdb/spl.c | 7 ++++--- board/freescale/t208xqds/spl.c | 7 ++++--- board/freescale/t208xrdb/spl.c | 7 ++++--- drivers/mtd/spi/fsl_espi_spl.c | 4 ++-- include/spi_flash.h | 3 --- 12 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 board/freescale/common/spl.h
diff --git a/board/Arcturus/ucp1020/spl.c b/board/Arcturus/ucp1020/spl.c index 9315bb7..9c19c87 100644 --- a/board/Arcturus/ucp1020/spl.c +++ b/board/Arcturus/ucp1020/spl.c @@ -119,8 +119,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)
#ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); -#elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/common/spl.h b/board/freescale/common/spl.h new file mode 100644 index 0000000..88c987e --- /dev/null +++ b/board/freescale/common/spl.h @@ -0,0 +1,13 @@ +/* + * Copyright 2016 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __FREESCALE_BOARD_SPL_H +#define __FREESCALE_BOARD_SPL_H + +void fsl_spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst); +void fsl_spi_boot(void) __noreturn; + +#endif diff --git a/board/freescale/p1010rdb/spl.c b/board/freescale/p1010rdb/spl.c index f858408..9844194 100644 --- a/board/freescale/p1010rdb/spl.c +++ b/board/freescale/p1010rdb/spl.c @@ -12,6 +12,7 @@ #include <i2c.h> #include <fsl_esdhc.h> #include <spi_flash.h> +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -103,7 +104,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/p1022ds/spl.c b/board/freescale/p1022ds/spl.c index 04db767..6a5fe74 100644 --- a/board/freescale/p1022ds/spl.c +++ b/board/freescale/p1022ds/spl.c @@ -14,6 +14,7 @@ #include "../common/ngpixis.h" #include <fsl_esdhc.h> #include <spi_flash.h> +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -120,7 +121,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/p1_p2_rdb_pc/spl.c b/board/freescale/p1_p2_rdb_pc/spl.c index 76a3cf4..9e8f359 100644 --- a/board/freescale/p1_p2_rdb_pc/spl.c +++ b/board/freescale/p1_p2_rdb_pc/spl.c @@ -13,6 +13,7 @@ #include <i2c.h> #include <fsl_esdhc.h> #include <spi_flash.h> +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -117,7 +118,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/t102xqds/spl.c b/board/freescale/t102xqds/spl.c index d59d343..61bfb29 100644 --- a/board/freescale/t102xqds/spl.c +++ b/board/freescale/t102xqds/spl.c @@ -14,6 +14,7 @@ #include <spi_flash.h> #include "../common/qixis.h" #include "t102xqds_qixis.h" +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -132,8 +133,8 @@ void board_init_r(gd_t *gd, ulong dest_addr) (uchar *)CONFIG_ENV_ADDR); #endif #ifdef CONFIG_SPL_SPI_BOOT - spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, - (uchar *)CONFIG_ENV_ADDR); + fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, + (uchar *)CONFIG_ENV_ADDR); #endif
gd->env_addr = (ulong)(CONFIG_ENV_ADDR); @@ -146,7 +147,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/t102xrdb/spl.c b/board/freescale/t102xrdb/spl.c index bd3cbbf..6d8866e 100644 --- a/board/freescale/t102xrdb/spl.c +++ b/board/freescale/t102xrdb/spl.c @@ -13,6 +13,7 @@ #include <fsl_esdhc.h> #include <spi_flash.h> #include "../common/sleep.h" +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -119,8 +120,8 @@ void board_init_r(gd_t *gd, ulong dest_addr) (uchar *)CONFIG_ENV_ADDR); #endif #ifdef CONFIG_SPL_SPI_BOOT - spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, - (uchar *)CONFIG_ENV_ADDR); + fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, + (uchar *)CONFIG_ENV_ADDR); #endif
gd->env_addr = (ulong)(CONFIG_ENV_ADDR); @@ -133,7 +134,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/t104xrdb/spl.c b/board/freescale/t104xrdb/spl.c index 4b35af6..1c2023b 100644 --- a/board/freescale/t104xrdb/spl.c +++ b/board/freescale/t104xrdb/spl.c @@ -13,6 +13,7 @@ #include <fsl_esdhc.h> #include <spi_flash.h> #include "../common/sleep.h" +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -114,8 +115,8 @@ void board_init_r(gd_t *gd, ulong dest_addr) (uchar *)CONFIG_ENV_ADDR); #endif #ifdef CONFIG_SPL_SPI_BOOT - spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, - (uchar *)CONFIG_ENV_ADDR); + fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, + (uchar *)CONFIG_ENV_ADDR); #endif gd->env_addr = (ulong)(CONFIG_ENV_ADDR); gd->env_valid = 1; @@ -129,7 +130,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/t208xqds/spl.c b/board/freescale/t208xqds/spl.c index bb02dab..b1e1cf1 100644 --- a/board/freescale/t208xqds/spl.c +++ b/board/freescale/t208xqds/spl.c @@ -14,6 +14,7 @@ #include <spi_flash.h> #include "../common/qixis.h" #include "t208xqds_qixis.h" +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -118,8 +119,8 @@ void board_init_r(gd_t *gd, ulong dest_addr) (uchar *)CONFIG_ENV_ADDR); #endif #ifdef CONFIG_SPL_SPI_BOOT - spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, - (uchar *)CONFIG_ENV_ADDR); + fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, + (uchar *)CONFIG_ENV_ADDR); #endif
gd->env_addr = (ulong)(CONFIG_ENV_ADDR); @@ -132,7 +133,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/board/freescale/t208xrdb/spl.c b/board/freescale/t208xrdb/spl.c index 2ff05a2..bb23865 100644 --- a/board/freescale/t208xrdb/spl.c +++ b/board/freescale/t208xrdb/spl.c @@ -12,6 +12,7 @@ #include <mmc.h> #include <fsl_esdhc.h> #include <spi_flash.h> +#include "../common/spl.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -88,8 +89,8 @@ void board_init_r(gd_t *gd, ulong dest_addr) (uchar *)CONFIG_ENV_ADDR); #endif #ifdef CONFIG_SPL_SPI_BOOT - spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, - (uchar *)CONFIG_ENV_ADDR); + fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, + (uchar *)CONFIG_ENV_ADDR); #endif
gd->env_addr = (ulong)(CONFIG_ENV_ADDR); @@ -102,7 +103,7 @@ void board_init_r(gd_t *gd, ulong dest_addr) #ifdef CONFIG_SPL_MMC_BOOT mmc_boot(); #elif defined(CONFIG_SPL_SPI_BOOT) - spi_boot(); + fsl_spi_boot(); #elif defined(CONFIG_SPL_NAND_BOOT) nand_boot(); #endif diff --git a/drivers/mtd/spi/fsl_espi_spl.c b/drivers/mtd/spi/fsl_espi_spl.c index b915469..1dd44e2 100644 --- a/drivers/mtd/spi/fsl_espi_spl.c +++ b/drivers/mtd/spi/fsl_espi_spl.c @@ -12,7 +12,7 @@ #define ESPI_BOOT_IMAGE_ADDR 0x50 #define CONFIG_CFG_DATA_SECTOR 0
-void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst) +void fsl_spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst) { struct spi_flash *flash;
@@ -31,7 +31,7 @@ void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst) * configured and available since this code loads the main U-Boot image * from SPI into SDRAM and starts it from there. */ -void spi_boot(void) +void fsl_spi_boot(void) { void (*uboot)(void) __noreturn; u32 offset, code_len, copy_len = 0; diff --git a/include/spi_flash.h b/include/spi_flash.h index d0ce9e7..be2fe3f 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -239,7 +239,4 @@ static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len, return flash->flash_unlock(flash, ofs, len); }
-void spi_boot(void) __noreturn; -void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst); - #endif /* _SPI_FLASH_H_ */

On Sat, Sep 24, 2016 at 06:20:10PM -0600, Simon Glass wrote:
At present there are two SPI functions only used by freescale which are defined in the spi_flash.h header. One function name matches an existing generic SPL function.
Move these into a private header to avoid confusion.
Arcturus looks like it does not actually support SPI, so drop the SPI code from that board.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:10PM -0600, Simon Glass wrote:
At present there are two SPI functions only used by freescale which are defined in the spi_flash.h header. One function name matches an existing generic SPL function.
Move these into a private header to avoid confusion.
Arcturus looks like it does not actually support SPI, so drop the SPI code from that board.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code. We need two variants - one for BOOT_DEVICE_CPGMAC and one for BOOT_DEVICE_USBETH.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/spl/spl.c | 12 ------------ common/spl/spl_net.c | 26 +++++++++++++++++++++++++- include/spl.h | 3 --- 3 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 9c8dcbb..06a326d 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -373,18 +373,6 @@ static int spl_load_image(u32 boot_device) return loader->load_image(&bootdev);
switch (boot_device) { -#ifdef CONFIG_SPL_ETH_SUPPORT - case BOOT_DEVICE_CPGMAC: -#ifdef CONFIG_SPL_ETH_DEVICE - bootdev.boot_device_name = CONFIG_SPL_ETH_DEVICE; -#endif - return spl_net_load_image(&bootdev); -#endif -#ifdef CONFIG_SPL_USBETH_SUPPORT - case BOOT_DEVICE_USBETH: - bootdev.boot_device_name = "usb_ether"; - return spl_net_load_image(&bootdev); -#endif #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE case BOOT_DEVICE_BOARD: return spl_board_load_image(&bootdev); diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index 730f88e..0cbd995 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -14,7 +14,8 @@
DECLARE_GLOBAL_DATA_PTR;
-int spl_net_load_image(struct spl_boot_device *bootdev) +#if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT) +static int spl_net_load_image(struct spl_boot_device *bootdev) { int rv;
@@ -37,3 +38,26 @@ int spl_net_load_image(struct spl_boot_device *bootdev) return spl_parse_image_header(&spl_image, (struct image_header *)load_addr); } +#endif + +#ifdef CONFIG_SPL_ETH_SUPPORT +int spl_net_load_image_cpgmac(struct spl_boot_device *bootdev) +{ +#ifdef CONFIG_SPL_ETH_DEVICE + bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE; +#endif + + return spl_net_load_image(bootdev); +} +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_CPGMAC, spl_net_load_image_cpgmac); +#endif + +#ifdef CONFIG_SPL_USBETH_SUPPORT +int spl_net_load_image_usb(struct spl_boot_device *bootdev) +{ + bootdev->boot_device_name = "usb_ether"; + + return spl_net_load_image(bootdev); +} +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USBETH, spl_net_load_image_usb); +#endif diff --git a/include/spl.h b/include/spl.h index 29dcf5b..24a6ec4 100644 --- a/include/spl.h +++ b/include/spl.h @@ -181,9 +181,6 @@ struct spl_image_loader { .load_image = __method, \ }
-/* Ethernet SPL functions */ -int spl_net_load_image(struct spl_boot_device *bootdev); - /* SPL FAT image functions */ int spl_load_image_fat(struct blk_desc *block_dev, int partition, const char *filename);

On Sat, Sep 24, 2016 at 06:20:11PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code. We need two variants - one for BOOT_DEVICE_CPGMAC and one for BOOT_DEVICE_USBETH.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:11PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code. We need two variants - one for BOOT_DEVICE_CPGMAC and one for BOOT_DEVICE_USBETH.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Add a linker list declaration for this method and remove the explicit switch() code. Update existing users.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
arch/arm/mach-sunxi/board.c | 5 ++++- arch/arm/mach-uniphier/boot-mode/spl_board.c | 3 ++- arch/sandbox/cpu/spl.c | 3 ++- common/spl/spl.c | 13 ++----------- include/spl.h | 8 -------- 5 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c index 8a385a2..22f3e3c 100644 --- a/arch/arm/mach-sunxi/board.c +++ b/arch/arm/mach-sunxi/board.c @@ -133,13 +133,16 @@ static int gpio_init(void) return 0; }
-int spl_board_load_image(struct spl_boot_device *bootdev) +#ifdef CONFIG_SPL_BUILD +static int spl_board_load_image(struct spl_boot_device *bootdev) { debug("Returning to FEL sp=%x, lr=%x\n", fel_stash.sp, fel_stash.lr); return_to_fel(fel_stash.sp, fel_stash.lr);
return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_BOARD, spl_board_load_image); +#endif
void s_init(void) { diff --git a/arch/arm/mach-uniphier/boot-mode/spl_board.c b/arch/arm/mach-uniphier/boot-mode/spl_board.c index 4eadc2f..e2b202e 100644 --- a/arch/arm/mach-uniphier/boot-mode/spl_board.c +++ b/arch/arm/mach-uniphier/boot-mode/spl_board.c @@ -65,7 +65,7 @@ int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32), return 0; }
-int spl_board_load_image(struct spl_boot_device *bootdev) +static int spl_board_load_image(struct spl_boot_device *bootdev) { int (*send_cmd)(u32 cmd, u32 arg); int (*card_blockaddr)(u32 rca); @@ -126,3 +126,4 @@ int spl_board_load_image(struct spl_boot_device *bootdev)
return 0; } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_BOARD, spl_board_load_image); diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c index 4cee293..2c45354 100644 --- a/arch/sandbox/cpu/spl.c +++ b/arch/sandbox/cpu/spl.c @@ -38,7 +38,7 @@ void spl_board_announce_boot_device(void) printf("%s\n", fname); }
-int spl_board_load_image(struct spl_boot_device *bootdev) +static int spl_board_load_image(struct spl_boot_device *bootdev) { char fname[256]; int ret; @@ -50,6 +50,7 @@ int spl_board_load_image(struct spl_boot_device *bootdev) /* Hopefully this will not return */ return os_spl_to_uboot(fname); } +SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_BOARD, spl_board_load_image);
void spl_board_init(void) { diff --git a/common/spl/spl.c b/common/spl/spl.c index 06a326d..a5719f2 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -372,19 +372,10 @@ static int spl_load_image(u32 boot_device) if (loader) return loader->load_image(&bootdev);
- switch (boot_device) { -#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE - case BOOT_DEVICE_BOARD: - return spl_board_load_image(&bootdev); -#endif - default: #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT) - puts("SPL: Unsupported Boot Device!\n"); + puts("SPL: Unsupported Boot Device!\n"); #endif - return -ENODEV; - } - - return -EINVAL; + return -ENODEV; }
void board_init_r(gd_t *dummy1, ulong dummy2) diff --git a/include/spl.h b/include/spl.h index 24a6ec4..cfab92b 100644 --- a/include/spl.h +++ b/include/spl.h @@ -219,12 +219,4 @@ void spl_board_init(void); */ bool spl_was_boot_source(void);
-/** - * Board-specific load method for boards that have a special way of loading - * U-Boot, which does not fit with the existing SPL code. - * - * @return 0 on success, negative errno value on failure. - */ -int spl_board_load_image(struct spl_boot_device *bootdev); - #endif

On Sat, Sep 24, 2016 at 06:20:12PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code. Update existing users.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

On Sat, Sep 24, 2016 at 06:20:12PM -0600, Simon Glass wrote:
Add a linker list declaration for this method and remove the explicit switch() code. Update existing users.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Rather than having a global variable, pass the spl_image as a parameter. This avoids BSS use, and makes it clearer what the function is actually doing.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
arch/arm/mach-sunxi/board.c | 3 +- arch/arm/mach-uniphier/boot-mode/spl_board.c | 9 ++--- arch/sandbox/cpu/spl.c | 3 +- common/spl/spl.c | 7 ++-- common/spl/spl_mmc.c | 54 +++++++++++++++------------- common/spl/spl_nand.c | 33 +++++++++-------- common/spl/spl_net.c | 15 ++++---- common/spl/spl_nor.c | 17 ++++----- common/spl/spl_onenand.c | 7 ++-- common/spl/spl_sata.c | 3 +- common/spl/spl_spi.c | 18 +++++----- common/spl/spl_ubi.c | 7 ++-- common/spl/spl_usb.c | 3 +- common/spl/spl_ymodem.c | 9 ++--- include/spl.h | 4 ++- 15 files changed, 110 insertions(+), 82 deletions(-)
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c index 22f3e3c..7713813 100644 --- a/arch/arm/mach-sunxi/board.c +++ b/arch/arm/mach-sunxi/board.c @@ -134,7 +134,8 @@ static int gpio_init(void) }
#ifdef CONFIG_SPL_BUILD -static int spl_board_load_image(struct spl_boot_device *bootdev) +static int spl_board_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { debug("Returning to FEL sp=%x, lr=%x\n", fel_stash.sp, fel_stash.lr); return_to_fel(fel_stash.sp, fel_stash.lr); diff --git a/arch/arm/mach-uniphier/boot-mode/spl_board.c b/arch/arm/mach-uniphier/boot-mode/spl_board.c index e2b202e..854ab05 100644 --- a/arch/arm/mach-uniphier/boot-mode/spl_board.c +++ b/arch/arm/mach-uniphier/boot-mode/spl_board.c @@ -65,7 +65,8 @@ int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32), return 0; }
-static int spl_board_load_image(struct spl_boot_device *bootdev) +static int spl_board_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int (*send_cmd)(u32 cmd, u32 arg); int (*card_blockaddr)(u32 rca); @@ -113,12 +114,12 @@ static int spl_board_load_image(struct spl_boot_device *bootdev) return ret; }
- ret = spl_parse_image_header(&spl_image, (void *)CONFIG_SYS_TEXT_BASE); + ret = spl_parse_image_header(spl_image, (void *)CONFIG_SYS_TEXT_BASE); if (ret) return ret;
- ret = (*load_image)(dev_addr, spl_image.load_addr, - spl_image.size / 512); + ret = (*load_image)(dev_addr, spl_image->load_addr, + spl_image->size / 512); if (ret) { printf("failed to load image\n"); return ret; diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c index 2c45354..1ad7fb6 100644 --- a/arch/sandbox/cpu/spl.c +++ b/arch/sandbox/cpu/spl.c @@ -38,7 +38,8 @@ void spl_board_announce_boot_device(void) printf("%s\n", fname); }
-static int spl_board_load_image(struct spl_boot_device *bootdev) +static int spl_board_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { char fname[256]; int ret; diff --git a/common/spl/spl.c b/common/spl/spl.c index a5719f2..39b1229 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -185,7 +185,8 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, return count; }
-static int spl_ram_load_image(struct spl_boot_device *bootdev) +static int spl_ram_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { struct image_header *header;
@@ -210,7 +211,7 @@ static int spl_ram_load_image(struct spl_boot_device *bootdev) header = (struct image_header *) (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
- spl_parse_image_header(&spl_image, header); + spl_parse_image_header(spl_image, header); }
return 0; @@ -370,7 +371,7 @@ static int spl_load_image(u32 boot_device) bootdev.boot_device = boot_device; bootdev.boot_device_name = NULL; if (loader) - return loader->load_image(&bootdev); + return loader->load_image(&spl_image, &bootdev);
#if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT) puts("SPL: Unsupported Boot Device!\n"); diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 5e8172e..6536e66 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -18,26 +18,26 @@
DECLARE_GLOBAL_DATA_PTR;
-static int mmc_load_legacy(struct mmc *mmc, ulong sector, - struct image_header *header) +static int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc, + ulong sector, struct image_header *header) { u32 image_size_sectors; unsigned long count; int ret;
- ret = spl_parse_image_header(&spl_image, header); + ret = spl_parse_image_header(spl_image, header); if (ret) return ret;
/* convert size to sectors - round up */ - image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) / + image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) / mmc->read_bl_len;
/* Read the header too to avoid extra memcpy */ count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors, - (void *)(ulong)spl_image.load_addr); + (void *)(ulong)spl_image->load_addr); debug("read %x sectors to %x\n", image_size_sectors, - spl_image.load_addr); + spl_image->load_addr); if (count != image_size_sectors) return -EIO;
@@ -52,7 +52,8 @@ static ulong h_spl_load_read(struct spl_load_info *load, ulong sector, return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf); }
-static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector) +static int mmc_load_image_raw_sector(struct spl_image_info *spl_image, + struct mmc *mmc, unsigned long sector) { unsigned long count; struct image_header *header; @@ -81,7 +82,7 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector) load.read = h_spl_load_read; ret = spl_load_simple_fit(&load, sector, header); } else { - ret = mmc_load_legacy(mmc, sector, header); + ret = mmc_load_legacy(spl_image, mmc, sector, header); }
end: @@ -150,7 +151,8 @@ static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device) }
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION -static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) +static int mmc_load_image_raw_partition(struct spl_image_info *spl_image, + struct mmc *mmc, int partition) { disk_partition_t info; int err; @@ -164,22 +166,24 @@ static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) }
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR - return mmc_load_image_raw_sector(mmc, info.start + - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); + return mmc_load_image_raw_sector(spl_image, mmc, + info.start + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); #else - return mmc_load_image_raw_sector(mmc, info.start); + return mmc_load_image_raw_sector(spl_image, mmc, info.start); #endif } #else #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION -1 -static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) +static int mmc_load_image_raw_partition(struct spl_image_info *spl_image, + struct mmc *mmc, int partition) { return -ENOSYS; } #endif
#ifdef CONFIG_SPL_OS_BOOT -static int mmc_load_image_raw_os(struct mmc *mmc) +static int mmc_load_image_raw_os(struct spl_image_info *spl_image, + struct mmc *mmc) { unsigned long count; int ret; @@ -195,12 +199,12 @@ static int mmc_load_image_raw_os(struct mmc *mmc) return -1; }
- ret = mmc_load_image_raw_sector(mmc, + ret = mmc_load_image_raw_sector(spl_image, mmc, CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); if (ret) return ret;
- if (spl_image.os != IH_OS_LINUX) { + if (spl_image->os != IH_OS_LINUX) { puts("Expected Linux image is not found. Trying to start U-boot\n"); return -ENOENT; } @@ -212,14 +216,15 @@ int spl_start_uboot(void) { return 1; } -static int mmc_load_image_raw_os(struct mmc *mmc) +static int mmc_load_image_raw_os(struct spl_image_info *spl_image, + struct mmc *mmc) { return -ENOSYS; } #endif
#ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION -int spl_mmc_do_fs_boot(struct mmc *mmc) +static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) { int err = -ENOSYS;
@@ -261,13 +266,14 @@ int spl_mmc_do_fs_boot(struct mmc *mmc) return err; } #else -int spl_mmc_do_fs_boot(struct mmc *mmc) +static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) { return -ENOSYS; } #endif
-static int spl_mmc_load_image(struct spl_boot_device *bootdev) +static int spl_mmc_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { struct mmc *mmc = NULL; u32 boot_mode; @@ -312,17 +318,17 @@ static int spl_mmc_load_image(struct spl_boot_device *bootdev) debug("spl: mmc boot mode: raw\n");
if (!spl_start_uboot()) { - err = mmc_load_image_raw_os(mmc); + err = mmc_load_image_raw_os(spl_image, mmc); if (!err) return err; }
- err = mmc_load_image_raw_partition(mmc, + err = mmc_load_image_raw_partition(spl_image, mmc, CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION); if (!err) return err; #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR) - err = mmc_load_image_raw_sector(mmc, + err = mmc_load_image_raw_sector(spl_image, mmc, CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); if (!err) return err; @@ -331,7 +337,7 @@ static int spl_mmc_load_image(struct spl_boot_device *bootdev) case MMCSD_MODE_FS: debug("spl: mmc boot mode: fs\n");
- err = spl_mmc_do_fs_boot(mmc); + err = spl_mmc_do_fs_boot(spl_image, mmc); if (!err) return err;
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index ed758e5..5cf712e 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -13,14 +13,15 @@ #include <fdt.h>
#if defined(CONFIG_SPL_NAND_RAW_ONLY) -int spl_nand_load_image(struct spl_boot_device *bootdev) +int spl_nand_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { nand_init();
nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE, (void *)CONFIG_SYS_NAND_U_BOOT_DST); - spl_set_header_raw_uboot(&spl_image); + spl_set_header_raw_uboot(spl_image); nand_deselect();
return 0; @@ -39,7 +40,8 @@ static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs, return 0; }
-static int spl_nand_load_element(int offset, struct image_header *header) +static int spl_nand_load_element(struct spl_image_info *spl_image, + int offset, struct image_header *header) { int err;
@@ -59,15 +61,16 @@ static int spl_nand_load_element(int offset, struct image_header *header) load.read = spl_nand_fit_read; return spl_load_simple_fit(&load, offset, header); } else { - err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err) return err; - return nand_spl_load_image(offset, spl_image.size, - (void *)(ulong)spl_image.load_addr); + return nand_spl_load_image(offset, spl_image->size, + (void *)(ulong)spl_image->load_addr); } }
-static int spl_nand_load_image(struct spl_boot_device *bootdev) +static int spl_nand_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int err; struct image_header *header; @@ -107,15 +110,15 @@ static int spl_nand_load_image(struct spl_boot_device *bootdev) /* load linux */ nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, sizeof(*header), (void *)header); - err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err) return err; if (header->ih_os == IH_OS_LINUX) { /* happy - was a linux */ err = nand_spl_load_image( CONFIG_SYS_NAND_SPL_KERNEL_OFFS, - spl_image.size, - (void *)spl_image.load_addr); + spl_image->size, + (void *)spl_image->load_addr); nand_deselect(); return err; } else { @@ -127,17 +130,19 @@ static int spl_nand_load_image(struct spl_boot_device *bootdev) } #endif #ifdef CONFIG_NAND_ENV_DST - spl_nand_load_element(CONFIG_ENV_OFFSET, header); + spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET, header); #ifdef CONFIG_ENV_OFFSET_REDUND - spl_nand_load_element(CONFIG_ENV_OFFSET_REDUND, header); + spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET_REDUND, header); #endif #endif /* Load u-boot */ - err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header); + err = spl_nand_load_element(spl_image, CONFIG_SYS_NAND_U_BOOT_OFFS, + header); #ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND #if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND if (err) - err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND, + err = spl_nand_load_element(spl_image, + CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND, header); #endif #endif diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index 0cbd995..f4b4bc4 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -15,7 +15,8 @@ DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT) -static int spl_net_load_image(struct spl_boot_device *bootdev) +static int spl_net_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int rv;
@@ -35,29 +36,31 @@ static int spl_net_load_image(struct spl_boot_device *bootdev) printf("Problem booting with BOOTP\n"); return rv; } - return spl_parse_image_header(&spl_image, + return spl_parse_image_header(spl_image, (struct image_header *)load_addr); } #endif
#ifdef CONFIG_SPL_ETH_SUPPORT -int spl_net_load_image_cpgmac(struct spl_boot_device *bootdev) +int spl_net_load_image_cpgmac(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { #ifdef CONFIG_SPL_ETH_DEVICE bootdev->boot_device_name = CONFIG_SPL_ETH_DEVICE; #endif
- return spl_net_load_image(bootdev); + return spl_net_load_image(spl_image, bootdev); } SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_CPGMAC, spl_net_load_image_cpgmac); #endif
#ifdef CONFIG_SPL_USBETH_SUPPORT -int spl_net_load_image_usb(struct spl_boot_device *bootdev) +int spl_net_load_image_usb(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { bootdev->boot_device_name = "usb_ether";
- return spl_net_load_image(bootdev); + return spl_net_load_image(spl_image, bootdev); } SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USBETH, spl_net_load_image_usb); #endif diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index b55fcc5..6bfa399 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -7,14 +7,15 @@ #include <common.h> #include <spl.h>
-static int spl_nor_load_image(struct spl_boot_device *bootdev) +static int spl_nor_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int ret; /* * Loading of the payload to SDRAM is done with skipping of * the mkimage header in this SPL NOR driver */ - spl_image.flags |= SPL_COPY_PAYLOAD_ONLY; + spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
#ifdef CONFIG_SPL_OS_BOOT if (!spl_start_uboot()) { @@ -29,14 +30,14 @@ static int spl_nor_load_image(struct spl_boot_device *bootdev) if (image_get_os(header) == IH_OS_LINUX) { /* happy - was a Linux */
- ret = spl_parse_image_header(&spl_image, header); + ret = spl_parse_image_header(spl_image, header); if (ret) return ret;
- memcpy((void *)spl_image.load_addr, + memcpy((void *)spl_image->load_addr, (void *)(CONFIG_SYS_OS_BASE + sizeof(struct image_header)), - spl_image.size); + spl_image->size);
/* * Copy DT blob (fdt) to SDRAM. Passing pointer to @@ -59,14 +60,14 @@ static int spl_nor_load_image(struct spl_boot_device *bootdev) * Load real U-Boot from its location in NOR flash to its * defined location in SDRAM */ - ret = spl_parse_image_header(&spl_image, + ret = spl_parse_image_header(spl_image, (const struct image_header *)CONFIG_SYS_UBOOT_BASE); if (ret) return ret;
- memcpy((void *)(unsigned long)spl_image.load_addr, + memcpy((void *)(unsigned long)spl_image->load_addr, (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)), - spl_image.size); + spl_image->size);
return 0; } diff --git a/common/spl/spl_onenand.c b/common/spl/spl_onenand.c index 361a1b3..f076e2c 100644 --- a/common/spl/spl_onenand.c +++ b/common/spl/spl_onenand.c @@ -14,7 +14,8 @@ #include <asm/io.h> #include <onenand_uboot.h>
-static int spl_onenand_load_image(struct spl_boot_device *bootdev) +static int spl_onenand_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { struct image_header *header; int ret; @@ -26,11 +27,11 @@ static int spl_onenand_load_image(struct spl_boot_device *bootdev) /* Load u-boot */ onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS, CONFIG_SYS_ONENAND_PAGE_SIZE, (void *)header); - ret = spl_parse_image_header(&spl_image, header); + ret = spl_parse_image_header(spl_image, header); if (ret) return ret; onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS, - spl_image.size, (void *)spl_image.load_addr); + spl_image->size, (void *)spl_image->load_addr);
return 0; } diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 1a21c05..19b5ba5 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -20,7 +20,8 @@
DECLARE_GLOBAL_DATA_PTR;
-static int spl_sata_load_image(struct spl_boot_device *bootdev) +static int spl_sata_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int err; struct blk_desc *stor_dev; diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index b9294f2..4bf3d65 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -20,7 +20,8 @@ * Load the kernel, check for a valid header we can parse, and if found load * the kernel and then device tree. */ -static int spi_load_image_os(struct spi_flash *flash, +static int spi_load_image_os(struct spl_image_info *spl_image, + struct spi_flash *flash, struct image_header *header) { int err; @@ -32,12 +33,12 @@ static int spi_load_image_os(struct spi_flash *flash, if (image_get_magic(header) != IH_MAGIC) return -1;
- err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err) return err;
spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, - spl_image.size, (void *)spl_image.load_addr); + spl_image->size, (void *)spl_image->load_addr);
/* Read device tree. */ spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS, @@ -65,7 +66,8 @@ static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, * configured and available since this code loads the main U-Boot image * from SPI into SDRAM and starts it from there. */ -static int spl_spi_load_image(struct spl_boot_device *bootdev) +static int spl_spi_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int err = 0; struct spi_flash *flash; @@ -88,7 +90,7 @@ static int spl_spi_load_image(struct spl_boot_device *bootdev) header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
#ifdef CONFIG_SPL_OS_BOOT - if (spl_start_uboot() || spi_load_image_os(flash, header)) + if (spl_start_uboot() || spi_load_image_os(spl_image, flash, header)) #endif { /* Load u-boot, mkimage header is 64 bytes. */ @@ -110,12 +112,12 @@ static int spl_spi_load_image(struct spl_boot_device *bootdev) CONFIG_SYS_SPI_U_BOOT_OFFS, header); } else { - err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err) return err; err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, - spl_image.size, - (void *)spl_image.load_addr); + spl_image->size, + (void *)spl_image->load_addr); } }
diff --git a/common/spl/spl_ubi.c b/common/spl/spl_ubi.c index 3ef00aa..c03910b 100644 --- a/common/spl/spl_ubi.c +++ b/common/spl/spl_ubi.c @@ -12,7 +12,8 @@ #include <ubispl.h> #include <spl.h>
-int spl_ubi_load_image(struct spl_boot_device *bootdev) +int spl_ubi_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { struct image_header *header; struct ubispl_info info; @@ -54,7 +55,7 @@ int spl_ubi_load_image(struct spl_boot_device *bootdev) ret = ubispl_load_volumes(&info, volumes, 2); if (!ret) { header = (struct image_header *)volumes[0].load_addr; - spl_parse_image_header(&spl_image, header); + spl_parse_image_header(spl_image, header); puts("Linux loaded.\n"); goto out; } @@ -68,7 +69,7 @@ int spl_ubi_load_image(struct spl_boot_device *bootdev)
ret = ubispl_load_volumes(&info, volumes, 1); if (!ret) - spl_parse_image_header(&spl_image, header); + spl_parse_image_header(spl_image, header); out: #ifdef CONFIG_SPL_NAND_SUPPORT if (bootdev->boot_device == BOOT_DEVICE_NAND) diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index 2bc321a..aaa4f81 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -22,7 +22,8 @@ DECLARE_GLOBAL_DATA_PTR; static int usb_stor_curr_dev = -1; /* current device */ #endif
-static int spl_usb_load_image(struct spl_boot_device *bootdev) +static int spl_usb_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int err; struct blk_desc *stor_dev; diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 168b951..8fbf895 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -68,7 +68,8 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset, return size; }
-static int spl_ymodem_load_image(struct spl_boot_device *bootdev) +static int spl_ymodem_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int size = 0; int err; @@ -108,12 +109,12 @@ static int spl_ymodem_load_image(struct spl_boot_device *bootdev) while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) size += res; } else { - spl_parse_image_header(&spl_image, (struct image_header *)buf); - ret = spl_parse_image_header(&spl_image, + spl_parse_image_header(spl_image, (struct image_header *)buf); + ret = spl_parse_image_header(spl_image, (struct image_header *)buf); if (ret) return ret; - addr = spl_image.load_addr; + addr = spl_image->load_addr; memcpy((void *)addr, buf, res); size += res; addr += res; diff --git a/include/spl.h b/include/spl.h index cfab92b..72cb96c 100644 --- a/include/spl.h +++ b/include/spl.h @@ -160,9 +160,11 @@ struct spl_image_loader { /** * load_image() - Load an SPL image * + * @spl_image: place to put image information * @bootdev: describes the boot device to load from */ - int (*load_image)(struct spl_boot_device *bootdev); + int (*load_image)(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev); };
/* Declare an SPL image loader */

On Sat, Sep 24, 2016 at 06:20:13PM -0600, Simon Glass wrote:
Rather than having a global variable, pass the spl_image as a parameter. This avoids BSS use, and makes it clearer what the function is actually doing.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Update the ext loader to avoid using the spl_image global variable.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
common/spl/spl_ext.c | 21 ++++++++++++--------- common/spl/spl_mmc.c | 4 ++-- drivers/mtd/spi/sunxi_spi_spl.c | 9 +++++---- include/spl.h | 6 ++++-- 4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index e5af24e..b93e1ea 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -10,9 +10,9 @@ #include <image.h>
#ifdef CONFIG_SPL_EXT_SUPPORT -int spl_load_image_ext(struct blk_desc *block_dev, - int partition, - const char *filename) +int spl_load_image_ext(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition, + const char *filename) { s32 err; struct image_header *header; @@ -48,13 +48,13 @@ int spl_load_image_ext(struct blk_desc *block_dev, goto end; }
- err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err < 0) { puts("spl: ext: failed to parse image header\n"); goto end; }
- err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen); + err = ext4fs_read((char *)spl_image->load_addr, filelen, &actlen);
end: #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT @@ -67,7 +67,8 @@ end: }
#ifdef CONFIG_SPL_OS_BOOT -int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) +int spl_load_image_ext_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition) { int err; __maybe_unused loff_t filelen, actlen; @@ -104,7 +105,8 @@ int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) } file = getenv("falcon_image_file"); if (file) { - err = spl_load_image_ext(block_dev, partition, file); + err = spl_load_image_ext(spl_image, block_dev, + partition, file); if (err != 0) { puts("spl: falling back to default\n"); goto defaults; @@ -134,11 +136,12 @@ defaults: return -1; }
- return spl_load_image_ext(block_dev, partition, + return spl_load_image_ext(spl_image, block_dev, partition, CONFIG_SPL_FS_LOAD_KERNEL_NAME); } #else -int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) +int spl_load_image_ext_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition) { return -ENOSYS; } diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 6536e66..5f5d9d0 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -245,13 +245,13 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc) #endif #ifdef CONFIG_SPL_EXT_SUPPORT if (!spl_start_uboot()) { - err = spl_load_image_ext_os(&mmc->block_dev, + err = spl_load_image_ext_os(spl_image, &mmc->block_dev, CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME - err = spl_load_image_ext(&mmc->block_dev, + err = spl_load_image_ext(spl_image, &mmc->block_dev, CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); if (!err) diff --git a/drivers/mtd/spi/sunxi_spi_spl.c b/drivers/mtd/spi/sunxi_spi_spl.c index 70d6d15..67c7edd 100644 --- a/drivers/mtd/spi/sunxi_spi_spl.c +++ b/drivers/mtd/spi/sunxi_spi_spl.c @@ -262,7 +262,8 @@ static void spi0_read_data(void *buf, u32 addr, u32 len)
/*****************************************************************************/
-static int spl_spi_load_image(struct spl_boot_device *bootdev) +static int spl_spi_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) { int err; struct image_header *header; @@ -271,12 +272,12 @@ static int spl_spi_load_image(struct spl_boot_device *bootdev) spi0_init();
spi0_read_data((void *)header, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40); - err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err) return err;
- spi0_read_data((void *)spl_image.load_addr, CONFIG_SYS_SPI_U_BOOT_OFFS, - spl_image.size); + spi0_read_data((void *)spl_image->load_addr, CONFIG_SYS_SPI_U_BOOT_OFFS, + spl_image->size);
spi0_deinit(); return 0; diff --git a/include/spl.h b/include/spl.h index 72cb96c..25f6ffe 100644 --- a/include/spl.h +++ b/include/spl.h @@ -191,9 +191,11 @@ int spl_load_image_fat_os(struct blk_desc *block_dev, int partition); void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
/* SPL EXT image functions */ -int spl_load_image_ext(struct blk_desc *block_dev, int partition, +int spl_load_image_ext(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition, const char *filename); -int spl_load_image_ext_os(struct blk_desc *block_dev, int partition); +int spl_load_image_ext_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition);
/** * spl_init() - Set up device tree and driver model in SPL if enabled

On Sat, Sep 24, 2016 at 06:20:14PM -0600, Simon Glass wrote:
Update the ext loader to avoid using the spl_image global variable.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Update the fat loader to avoid using the spl_image global variable.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
common/spl/spl_fat.c | 21 ++++++++++++--------- common/spl/spl_mmc.c | 4 ++-- common/spl/spl_sata.c | 11 +++++++---- common/spl/spl_usb.c | 13 ++++++++----- include/spl.h | 6 ++++-- 5 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 68702a2..e2bb000 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -54,9 +54,9 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, return actread; }
-int spl_load_image_fat(struct blk_desc *block_dev, - int partition, - const char *filename) +int spl_load_image_fat(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition, + const char *filename) { int err; struct image_header *header; @@ -84,12 +84,12 @@ int spl_load_image_fat(struct blk_desc *block_dev,
return spl_load_simple_fit(&load, 0, header); } else { - err = spl_parse_image_header(&spl_image, header); + err = spl_parse_image_header(spl_image, header); if (err) goto end;
err = file_fat_read(filename, - (u8 *)(uintptr_t)spl_image.load_addr, 0); + (u8 *)(uintptr_t)spl_image->load_addr, 0); }
end: @@ -103,7 +103,8 @@ end: }
#ifdef CONFIG_SPL_OS_BOOT -int spl_load_image_fat_os(struct blk_desc *block_dev, int partition) +int spl_load_image_fat_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition) { int err; __maybe_unused char *file; @@ -123,7 +124,8 @@ int spl_load_image_fat_os(struct blk_desc *block_dev, int partition) } file = getenv("falcon_image_file"); if (file) { - err = spl_load_image_fat(block_dev, partition, file); + err = spl_load_image_fat(spl_image, block_dev, + partition, file); if (err != 0) { puts("spl: falling back to default\n"); goto defaults; @@ -148,11 +150,12 @@ defaults: return -1; }
- return spl_load_image_fat(block_dev, partition, + return spl_load_image_fat(spl_image, block_dev, partition, CONFIG_SPL_FS_LOAD_KERNEL_NAME); } #else -int spl_load_image_fat_os(struct blk_desc *block_dev, int partition) +int spl_load_image_fat_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition) { return -ENOSYS; } diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 5f5d9d0..16a6b49 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -230,13 +230,13 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc)
#ifdef CONFIG_SPL_FAT_SUPPORT if (!spl_start_uboot()) { - err = spl_load_image_fat_os(mmc_get_blk_desc(mmc), + err = spl_load_image_fat_os(spl_image, mmc_get_blk_desc(mmc), CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME - err = spl_load_image_fat(mmc_get_blk_desc(mmc), + err = spl_load_image_fat(spl_image, mmc_get_blk_desc(mmc), CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); if (!err) diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 19b5ba5..a3c07cd 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -41,12 +41,15 @@ static int spl_sata_load_image(struct spl_image_info *spl_image, }
#ifdef CONFIG_SPL_OS_BOOT - if (spl_start_uboot() || spl_load_image_fat_os(stor_dev, - CONFIG_SYS_SATA_FAT_BOOT_PARTITION)) + if (spl_start_uboot() || + spl_load_image_fat_os(spl_image, stor_dev, + CONFIG_SYS_SATA_FAT_BOOT_PARTITION)) #endif - err = spl_load_image_fat(stor_dev, - CONFIG_SYS_SATA_FAT_BOOT_PARTITION, + { + err = spl_load_image_fat(spl_image, stor_dev, + CONFIG_SYS_SATA_FAT_BOOT_PARTITION, CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); + } if (err) { puts("Error loading sata device\n"); return err; diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index aaa4f81..e37966e 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -48,12 +48,15 @@ static int spl_usb_load_image(struct spl_image_info *spl_image, debug("boot mode - FAT\n");
#ifdef CONFIG_SPL_OS_BOOT - if (spl_start_uboot() || spl_load_image_fat_os(stor_dev, - CONFIG_SYS_USB_FAT_BOOT_PARTITION)) + if (spl_start_uboot() || + spl_load_image_fat_os(spl_image, stor_dev, + CONFIG_SYS_USB_FAT_BOOT_PARTITION)) #endif - err = spl_load_image_fat(stor_dev, - CONFIG_SYS_USB_FAT_BOOT_PARTITION, - CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); + { + err = spl_load_image_fat(spl_image, stor_dev, + CONFIG_SYS_USB_FAT_BOOT_PARTITION, + CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); + }
if (err) { puts("Error loading from USB device\n"); diff --git a/include/spl.h b/include/spl.h index 25f6ffe..947fc75 100644 --- a/include/spl.h +++ b/include/spl.h @@ -184,9 +184,11 @@ struct spl_image_loader { }
/* SPL FAT image functions */ -int spl_load_image_fat(struct blk_desc *block_dev, int partition, +int spl_load_image_fat(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition, const char *filename); -int spl_load_image_fat_os(struct blk_desc *block_dev, int partition); +int spl_load_image_fat_os(struct spl_image_info *spl_image, + struct blk_desc *block_dev, int partition);
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);

On Sat, Sep 24, 2016 at 06:20:15PM -0600, Simon Glass wrote:
Update the fat loader to avoid using the spl_image global variable.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

Upda the SPL FIT code to use the spl_image parameter.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: None
common/spl/spl.c | 2 +- common/spl/spl_fat.c | 2 +- common/spl/spl_fit.c | 9 +++++---- common/spl/spl_mmc.c | 2 +- common/spl/spl_nand.c | 2 +- common/spl/spl_spi.c | 2 +- common/spl/spl_ymodem.c | 2 +- include/spl.h | 4 +++- 8 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 39b1229..f5c7ffe 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -199,7 +199,7 @@ static int spl_ram_load_image(struct spl_image_info *spl_image, debug("Found FIT\n"); load.bl_len = 1; load.read = spl_ram_load_read; - spl_load_simple_fit(&load, 0, header); + spl_load_simple_fit(spl_image, &load, 0, header); } else { debug("Legacy image\n"); /* diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index e2bb000..a14acce 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -82,7 +82,7 @@ int spl_load_image_fat(struct spl_image_info *spl_image, load.filename = (void *)filename; load.priv = NULL;
- return spl_load_simple_fit(&load, 0, header); + return spl_load_simple_fit(spl_image, &load, 0, header); } else { err = spl_parse_image_header(spl_image, header); if (err) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index be86072..aae556f 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -123,7 +123,8 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size, return (data_size + info->bl_len - 1) / info->bl_len; }
-int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) +int spl_load_simple_fit(struct spl_image_info *spl_image, + struct spl_load_info *info, ulong sector, void *fit) { int sectors; ulong size, load; @@ -184,9 +185,9 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) data_size = fdt_getprop_u32(fit, node, "data-size"); load = fdt_getprop_u32(fit, node, "load"); debug("data_offset=%x, data_size=%x\n", data_offset, data_size); - spl_image.load_addr = load; - spl_image.entry_point = load; - spl_image.os = IH_OS_U_BOOT; + spl_image->load_addr = load; + spl_image->entry_point = load; + spl_image->os = IH_OS_U_BOOT;
/* * Work out where to place the image. We read it so that the first diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 16a6b49..c674e61 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -80,7 +80,7 @@ static int mmc_load_image_raw_sector(struct spl_image_info *spl_image, load.filename = NULL; load.bl_len = mmc->read_bl_len; load.read = h_spl_load_read; - ret = spl_load_simple_fit(&load, sector, header); + ret = spl_load_simple_fit(spl_image, &load, sector, header); } else { ret = mmc_load_legacy(spl_image, mmc, sector, header); } diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 5cf712e..d1abda6 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -59,7 +59,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image, load.filename = NULL; load.bl_len = 1; load.read = spl_nand_fit_read; - return spl_load_simple_fit(&load, offset, header); + return spl_load_simple_fit(spl_image, &load, offset, header); } else { err = spl_parse_image_header(spl_image, header); if (err) diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index 4bf3d65..a3caafb 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -108,7 +108,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, load.filename = NULL; load.bl_len = 1; load.read = spl_spi_fit_read; - err = spl_load_simple_fit(&load, + err = spl_load_simple_fit(spl_image, &load, CONFIG_SYS_SPI_U_BOOT_OFFS, header); } else { diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 8fbf895..13e8e51 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -103,7 +103,7 @@ static int spl_ymodem_load_image(struct spl_image_info *spl_image, info.buf = buf; info.image_read = BUF_SIZE; load.read = ymodem_read_fit; - ret = spl_load_simple_fit(&load, 0, (void *)buf); + ret = spl_load_simple_fit(spl_image, &load, 0, (void *)buf); size = info.image_read;
while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) diff --git a/include/spl.h b/include/spl.h index 947fc75..7514d8e 100644 --- a/include/spl.h +++ b/include/spl.h @@ -49,6 +49,7 @@ struct spl_load_info {
/** * spl_load_simple_fit() - Loads a fit image from a device. + * @spl_image: Image description to set up * @info: Structure containing the information required to load data. * @sector: Sector number where FIT image is located in the device * @fdt: Pointer to the copied FIT header. @@ -57,7 +58,8 @@ struct spl_load_info { * specified load address and copies the dtb to end of u-boot image. * Returns 0 on success. */ -int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fdt); +int spl_load_simple_fit(struct spl_image_info *spl_image, + struct spl_load_info *info, ulong sector, void *fdt);
#define SPL_COPY_PAYLOAD_ONLY 1

On Sat, Sep 24, 2016 at 06:20:16PM -0600, Simon Glass wrote:
Upda the SPL FIT code to use the spl_image parameter.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

There is no need for this to be in the BSS region. By moving it we can delay use of BSS in SPL. This is useful for machines where the BSS region is not in writeable space. On 64-bit x86, SPL runs from SPI flash and it is easier to eliminate BSS use than link SPL to run with BSS at a particular cache-as-RAM (CAR) address.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com ---
Changes in v2: - Add a memset() to clear the spl_image data
common/spl/spl.c | 24 ++++++++++++------------ include/spl.h | 2 -- 2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index f5c7ffe..76c0d8e 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -29,7 +29,6 @@ DECLARE_GLOBAL_DATA_PTR; #endif
u32 *boot_params_ptr = NULL; -struct spl_image_info spl_image;
/* Define board data structure */ static bd_t bdata __attribute__ ((section(".data"))); @@ -255,14 +254,6 @@ int spl_init(void) #define BOOT_DEVICE_NONE 0xdeadbeef #endif
-static u32 spl_boot_list[] = { - BOOT_DEVICE_NONE, - BOOT_DEVICE_NONE, - BOOT_DEVICE_NONE, - BOOT_DEVICE_NONE, - BOOT_DEVICE_NONE, -}; - __weak void board_boot_order(u32 *spl_boot_list) { spl_boot_list[0] = spl_boot_device(); @@ -363,7 +354,7 @@ static struct spl_image_loader *spl_ll_find_loader(uint boot_device) return NULL; }
-static int spl_load_image(u32 boot_device) +static int spl_load_image(struct spl_image_info *spl_image, u32 boot_device) { struct spl_boot_device bootdev; struct spl_image_loader *loader = spl_ll_find_loader(boot_device); @@ -371,7 +362,7 @@ static int spl_load_image(u32 boot_device) bootdev.boot_device = boot_device; bootdev.boot_device_name = NULL; if (loader) - return loader->load_image(&spl_image, &bootdev); + return loader->load_image(spl_image, &bootdev);
#if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT) puts("SPL: Unsupported Boot Device!\n"); @@ -381,6 +372,14 @@ static int spl_load_image(u32 boot_device)
void board_init_r(gd_t *dummy1, ulong dummy2) { + u32 spl_boot_list[] = { + BOOT_DEVICE_NONE, + BOOT_DEVICE_NONE, + BOOT_DEVICE_NONE, + BOOT_DEVICE_NONE, + BOOT_DEVICE_NONE, + }; + struct spl_image_info spl_image; int i;
debug(">>spl:board_init_r()\n"); @@ -406,11 +405,12 @@ void board_init_r(gd_t *dummy1, ulong dummy2) spl_board_init(); #endif
+ memset(&spl_image, '\0', sizeof(spl_image)); board_boot_order(spl_boot_list); for (i = 0; i < ARRAY_SIZE(spl_boot_list) && spl_boot_list[i] != BOOT_DEVICE_NONE; i++) { announce_boot_device(spl_boot_list[i]); - if (!spl_load_image(spl_boot_list[i])) + if (!spl_load_image(&spl_image, spl_boot_list[i])) break; }
diff --git a/include/spl.h b/include/spl.h index 7514d8e..b51ba90 100644 --- a/include/spl.h +++ b/include/spl.h @@ -63,8 +63,6 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
#define SPL_COPY_PAYLOAD_ONLY 1
-extern struct spl_image_info spl_image; - /* SPL common functions */ void preloader_console_init(void); u32 spl_boot_device(void);

On Sat, Sep 24, 2016 at 06:20:17PM -0600, Simon Glass wrote:
There is no need for this to be in the BSS region. By moving it we can delay use of BSS in SPL. This is useful for machines where the BSS region is not in writeable space. On 64-bit x86, SPL runs from SPI flash and it is easier to eliminate BSS use than link SPL to run with BSS at a particular cache-as-RAM (CAR) address.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!
participants (2)
-
Simon Glass
-
Tom Rini