diff mbox series

[U-Boot] SPL: SPI: sunxi: add SPL FIT image support

Message ID 20170922215722.30232-1-andre.przywara@arm.com
State Accepted
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series [U-Boot] SPL: SPI: sunxi: add SPL FIT image support | expand

Commit Message

Andre Przywara Sept. 22, 2017, 9:57 p.m. UTC
The sunxi-specific SPI load routine only knows how to load a legacy
U-Boot image.
Teach it how to handle FIT images as well, simply by providing the
existing SPL FIT loader with the right loader routine to access the SPI
NOR flash.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reported-by: Peter Kosa <kope@madnet.sk>

---
Hi,

this patch was actually part of an early version of the SPL FIT series,
but I somehow managed to drop it during some rebase.
This is needed to enable SPI boot when using a FIT image, so this fixes
SPI booting on 64-bit Allwinner boards, like the OrangePi PC2 and the Pine64
SoPine.
I would be grateful if it could make it into v2017.11.

Cheers,
Andre.

 drivers/mtd/spi/sunxi_spi_spl.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

Comments

Maxime Ripard Sept. 25, 2017, 10:07 a.m. UTC | #1
On Fri, Sep 22, 2017 at 09:57:22PM +0000, Andre Przywara wrote:
> The sunxi-specific SPI load routine only knows how to load a legacy
> U-Boot image.
> Teach it how to handle FIT images as well, simply by providing the
> existing SPL FIT loader with the right loader routine to access the SPI
> NOR flash.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> Reported-by: Peter Kosa <kope@madnet.sk>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Maxime
Jagan Teki Sept. 27, 2017, 7:16 a.m. UTC | #2
On Mon, Sep 25, 2017 at 3:37 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> On Fri, Sep 22, 2017 at 09:57:22PM +0000, Andre Przywara wrote:
>> The sunxi-specific SPI load routine only knows how to load a legacy
>> U-Boot image.
>> Teach it how to handle FIT images as well, simply by providing the
>> existing SPL FIT loader with the right loader routine to access the SPI
>> NOR flash.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
>> Reported-by: Peter Kosa <kope@madnet.sk>
>
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> Maxime

Applied to u-boot-spi/master

thanks!
diff mbox series

Patch

diff --git a/drivers/mtd/spi/sunxi_spi_spl.c b/drivers/mtd/spi/sunxi_spi_spl.c
index 852abd41de..35835c2798 100644
--- a/drivers/mtd/spi/sunxi_spi_spl.c
+++ b/drivers/mtd/spi/sunxi_spi_spl.c
@@ -8,6 +8,7 @@ 
 #include <spl.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <libfdt.h>
 
 #ifdef CONFIG_SPL_OS_BOOT
 #error CONFIG_SPL_OS_BOOT is not supported yet
@@ -261,27 +262,51 @@  static void spi0_read_data(void *buf, u32 addr, u32 len)
 	}
 }
 
+static ulong spi_load_read(struct spl_load_info *load, ulong sector,
+			   ulong count, void *buf)
+{
+	spi0_read_data(buf, sector, count);
+
+	return count;
+}
+
 /*****************************************************************************/
 
 static int spl_spi_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	int err;
+	int ret = 0;
 	struct image_header *header;
 	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
 
 	spi0_init();
 
 	spi0_read_data((void *)header, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40);
-	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);
+        if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+		image_get_magic(header) == FDT_MAGIC) {
+		struct spl_load_info load;
+
+		debug("Found FIT image\n");
+		load.dev = NULL;
+		load.priv = NULL;
+		load.filename = NULL;
+		load.bl_len = 1;
+		load.read = spi_load_read;
+		ret = spl_load_simple_fit(spl_image, &load,
+					  CONFIG_SYS_SPI_U_BOOT_OFFS, header);
+	} else {
+		ret = spl_parse_image_header(spl_image, header);
+		if (ret)
+			return ret;
+
+		spi0_read_data((void *)spl_image->load_addr,
+			       CONFIG_SYS_SPI_U_BOOT_OFFS, spl_image->size);
+	}
 
 	spi0_deinit();
-	return 0;
+
+	return ret;
 }
 /* Use priorty 0 to override the default if it happens to be linked in */
 SPL_LOAD_IMAGE_METHOD("sunxi SPI", 0, BOOT_DEVICE_SPI, spl_spi_load_image);