diff options
author | Sean Anderson <sean.anderson@seco.com> | 2022-04-22 14:27:47 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-05-04 15:43:42 -0400 |
commit | 064334e21dde2d38a2f3535ddd593dc4b2dc4674 (patch) | |
tree | 0fcc837c96bc237a0e7cc05d658e60f2d0db3350 | |
parent | 3df4fa5adf6ceabbf0d454d59e443f9753fa6406 (diff) | |
download | u-boot-064334e21dde2d38a2f3535ddd593dc4b2dc4674.zip u-boot-064334e21dde2d38a2f3535ddd593dc4b2dc4674.tar.gz u-boot-064334e21dde2d38a2f3535ddd593dc4b2dc4674.tar.bz2 |
spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
spi_load_image_os performs almost the same steps as the non-falcon-boot
path of spl_spi_load_image. The load address is different, and it also
loads a device tree, but that's it. Refactor the boot process so that
they can both use the same load function.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
-rw-r--r-- | common/spl/spl_spi.c | 87 |
1 files changed, 33 insertions, 54 deletions
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index 037db1a..e724a74 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -18,41 +18,6 @@ #include <asm/global_data.h> #include <dm/ofnode.h> -#if CONFIG_IS_ENABLED(OS_BOOT) -/* - * 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 spl_image_info *spl_image, - struct spl_boot_device *bootdev, - struct spi_flash *flash, - struct image_header *header) -{ - int err; - - /* Read for a header, parse or error out. */ - spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, sizeof(*header), - (void *)header); - - if (image_get_magic(header) != IH_MAGIC) - return -1; - - err = spl_parse_image_header(spl_image, bootdev, header); - if (err) - return err; - - spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, - spl_image->size, (void *)spl_image->load_addr); - - /* Read device tree. */ - spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS, - CONFIG_SYS_SPI_ARGS_SIZE, - (void *)CONFIG_SYS_SPL_ARGS_ADDR); - - return 0; -} -#endif - static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, ulong count, void *buf) { @@ -71,6 +36,29 @@ unsigned int __weak spl_spi_get_uboot_offs(struct spi_flash *flash) return CONFIG_SYS_SPI_U_BOOT_OFFS; } +static int spi_do_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev, + struct spl_load_info *load, + unsigned int payload_offs) +{ + int ret; + struct spi_flash *flash = load->dev; + struct image_header *header = + spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + + /* mkimage header is 64 bytes. */ + ret = spi_flash_read(flash, payload_offs, sizeof(*header), + (void *)header); + if (ret) { + debug("%s: Failed to read from SPI flash (err=%d)\n", + __func__, ret); + return ret; + } + + return spl_load(spl_image, bootdev, load, header, 0, + payload_offs); +} + /* * The main entry for SPI booting. It's necessary that SDRAM is already * configured and available since this code loads the main U-Boot image @@ -79,10 +67,8 @@ unsigned int __weak spl_spi_get_uboot_offs(struct spi_flash *flash) static int spl_spi_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { - int err = 0; unsigned int payload_offs; struct spi_flash *flash; - struct image_header *header; struct spl_load_info load = { .bl_len = 1, .read = spl_spi_fit_read, @@ -106,31 +92,24 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, load.dev = flash; payload_offs = spl_spi_get_uboot_offs(flash); - header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); - if (CONFIG_IS_ENABLED(OF_REAL)) { payload_offs = ofnode_conf_read_int("u-boot,spl-payload-offset", payload_offs); } #if CONFIG_IS_ENABLED(OS_BOOT) - if (spl_start_uboot() || spi_load_image_os(spl_image, bootdev, flash, header)) -#endif - { - /* Load u-boot, mkimage header is 64 bytes. */ - err = spi_flash_read(flash, payload_offs, sizeof(*header), - (void *)header); - if (err) { - debug("%s: Failed to read from SPI flash (err=%d)\n", - __func__, err); - return err; - } - - err = spl_load(spl_image, bootdev, &load, header, 0, - payload_offs); + if (spl_start_uboot()) { + int err = spi_do_load_image(spl_image, bootdev, &load, + CONFIG_SYS_SPI_KERNEL_OFFS); + if (!err) + /* Read device tree. */ + return spi_flash_read(flash, CONFIG_SYS_SPI_ARGS_OFFS, + CONFIG_SYS_SPI_ARGS_SIZE, + (void *)CONFIG_SYS_SPL_ARGS_ADDR); } +#endif - return err; + return spi_do_load_image(spl_image, bootdev, &load, payload_offs); } /* Use priorty 1 so that boards can override this */ SPL_LOAD_IMAGE_METHOD("SPI", 1, BOOT_DEVICE_SPI, spl_spi_load_image); |