All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@seco.com>
To: Simon Glass <sjg@chromium.org>
Cc: "Pali Rohár" <pali@kernel.org>,
	"Marek Behún" <marek.behun@nic.cz>,
	u-boot@lists.denx.de, "Stefan Roese" <sr@denx.de>,
	"Marek Vasut" <marex@denx.de>,
	"Sean Anderson" <sean.anderson@seco.com>,
	"Nathan Barrett-Morrison" <nathan.morrison@timesys.com>
Subject: [PATCH v2 9/9] spl: spi: Consolidate spi_load_image_os into spl_spi_load_image
Date: Fri, 22 Apr 2022 14:27:47 -0400	[thread overview]
Message-ID: <20220422182748.2309992-10-sean.anderson@seco.com> (raw)
In-Reply-To: <20220422182748.2309992-1-sean.anderson@seco.com>

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>
---

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 037db1a19f..e724a74783 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);
-- 
2.35.1.1320.gc452695387.dirty


      parent reply	other threads:[~2022-04-22 18:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 18:27 [PATCH v2 0/9] spl: Use common function for loading/parsing images Sean Anderson
2022-04-22 18:27 ` [PATCH v2 1/9] spl: Add generic spl_load function Sean Anderson
2022-04-22 18:27 ` [PATCH v2 2/9] spl: Convert ext to use spl_load Sean Anderson
2022-04-22 18:27 ` [PATCH v2 3/9] spl: Convert fat to spl_load Sean Anderson
2022-05-05  0:06   ` Tom Rini
2022-05-05 14:51     ` Sean Anderson
2022-05-05 15:38       ` Tom Rini
2022-05-05 18:53         ` Sean Anderson
2022-05-05 18:58           ` Tom Rini
2022-05-05 19:05             ` Sean Anderson
2022-05-05 19:12               ` Tom Rini
2022-04-22 18:27 ` [PATCH v2 4/9] spl: Convert mmc " Sean Anderson
2022-04-22 18:27 ` [PATCH v2 5/9] spl: Convert net " Sean Anderson
2022-04-22 18:27 ` [PATCH v2 6/9] spl: Convert nor " Sean Anderson
2022-04-22 18:27 ` [PATCH v2 7/9] spl: Convert semihosting " Sean Anderson
2022-04-22 18:27 ` [PATCH v2 8/9] spl: Convert spi " Sean Anderson
2022-04-22 18:27 ` Sean Anderson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220422182748.2309992-10-sean.anderson@seco.com \
    --to=sean.anderson@seco.com \
    --cc=marek.behun@nic.cz \
    --cc=marex@denx.de \
    --cc=nathan.morrison@timesys.com \
    --cc=pali@kernel.org \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.