[PATCH v4 9/9] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
Sean Anderson
sean.anderson at seco.com
Mon Jul 24 19:12:56 CEST 2023
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 at seco.com>
---
(no changes since v2)
Changes in v2:
- New
common/spl/spl_spi.c | 87 +++++++++++++++++---------------------------
1 file changed, 33 insertions(+), 54 deletions(-)
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 75929710935..39c528293e2 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 legacy_img_hdr *header)
-{
- int err;
-
- /* Read for a header, parse or error out. */
- spi_flash_read(flash, CFG_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, CFG_SYS_SPI_KERNEL_OFFS,
- spl_image->size, (void *)spl_image->load_addr);
-
- /* Read device tree. */
- spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS,
- CFG_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)
{
@@ -81,6 +46,29 @@ u32 __weak spl_spi_boot_cs(void)
return CONFIG_SF_DEFAULT_CS;
}
+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 legacy_img_hdr *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
@@ -89,10 +77,8 @@ u32 __weak spl_spi_boot_cs(void)
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 legacy_img_hdr *header;
unsigned int sf_bus = spl_spi_boot_bus();
unsigned int sf_cs = spl_spi_boot_cs();
struct spl_load_info load = {
@@ -116,31 +102,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,
+ CFG_SYS_SPI_KERNEL_OFFS);
+ if (!err)
+ /* Read device tree. */
+ return spi_flash_read(flash, CFG_SYS_SPI_ARGS_OFFS,
+ CFG_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);
--
2.35.1.1320.gc452695387.dirty
More information about the U-Boot
mailing list