[U-Boot] [PATCH 0/2] spl: Support loading a FIT from SPI

This series makes sure that raw read of fit is dma aligned and supports loading a fit from SPI.
Verified on DRA7-evm.
Lokesh Vutla (2): spl: Make sure destination address is dma aligned when loading fit spl: Support loading a FIT from SPI
common/spl/spl_fit.c | 11 +++++++---- drivers/mtd/spi/spi_spl_load.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-)

Peripherals like spi etc. uses DMA for transfers. So, when loading the fit image the destination address should be dma aligned.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com --- - Assuming u-boot.bin load addr will always be dma aligned.
common/spl/spl_fit.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 4c9fe7b..20396b9 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -91,7 +91,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) void *load_ptr; int fdt_offset, fdt_len; int data_offset, data_size; - int base_offset; + int base_offset, align_len; int src_sector; void *dst;
@@ -117,7 +117,9 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) * In fact the FIT has its own load address, but we assume it cannot * be before CONFIG_SYS_TEXT_BASE. */ - fit = (void *)(CONFIG_SYS_TEXT_BASE - size - info->bl_len); + align_len = ARCH_DMA_MINALIGN - 1; + fit = (void *)((CONFIG_SYS_TEXT_BASE - size - info->bl_len - + align_len) & ~align_len); sectors = (size + info->bl_len - 1) / info->bl_len; count = info->read(info, sector, sectors, fit); debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n", @@ -173,8 +175,9 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) /* * Read the device tree and place it after the image. There may be * some extra data before it since we can only read entire blocks. + * And also align the destination address to ARCH_DMA_MINALIGN. */ - dst = load_ptr + data_size; + dst = (void *)((load + data_size + align_len) & ~align_len); fdt_offset += base_offset; count = info->read(info, sector + fdt_offset / info->bl_len, sectors, dst); @@ -188,7 +191,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) * After this we will have the U-Boot image and its device tree ready * for us to start. */ - memcpy(dst, dst + fdt_offset % info->bl_len, fdt_len); + memcpy(load_ptr + data_size, dst + fdt_offset % info->bl_len, fdt_len);
return 0; }

On Wed, Apr 06, 2016 at 05:32:59PM +0530, Lokesh Vutla wrote:
Peripherals like spi etc. uses DMA for transfers. So, when loading the fit image the destination address should be dma aligned.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

On Wednesday 06 April 2016 05:32 PM, Lokesh Vutla wrote:
Peripherals like spi etc. uses DMA for transfers. So, when loading the fit image the destination address should be dma aligned.
After the v5 of my FS support for FIT[1], this patch is no more necessary. Patch 2 is alone sufficient.
[1] http://patchwork.ozlabs.org/patch/618403/
Thanks and regards, Lokesh
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
- Assuming u-boot.bin load addr will always be dma aligned.
common/spl/spl_fit.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 4c9fe7b..20396b9 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -91,7 +91,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) void *load_ptr; int fdt_offset, fdt_len; int data_offset, data_size;
- int base_offset;
- int base_offset, align_len; int src_sector; void *dst;
@@ -117,7 +117,9 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) * In fact the FIT has its own load address, but we assume it cannot * be before CONFIG_SYS_TEXT_BASE. */
- fit = (void *)(CONFIG_SYS_TEXT_BASE - size - info->bl_len);
- align_len = ARCH_DMA_MINALIGN - 1;
- fit = (void *)((CONFIG_SYS_TEXT_BASE - size - info->bl_len -
sectors = (size + info->bl_len - 1) / info->bl_len; count = info->read(info, sector, sectors, fit); debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",align_len) & ~align_len);
@@ -173,8 +175,9 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) /* * Read the device tree and place it after the image. There may be * some extra data before it since we can only read entire blocks.
*/* And also align the destination address to ARCH_DMA_MINALIGN.
- dst = load_ptr + data_size;
- dst = (void *)((load + data_size + align_len) & ~align_len); fdt_offset += base_offset; count = info->read(info, sector + fdt_offset / info->bl_len, sectors, dst);
@@ -188,7 +191,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit) * After this we will have the U-Boot image and its device tree ready * for us to start. */
- memcpy(dst, dst + fdt_offset % info->bl_len, fdt_len);
memcpy(load_ptr + data_size, dst + fdt_offset % info->bl_len, fdt_len);
return 0;
}

On Thu, May 05, 2016 at 11:22:42AM +0530, Lokesh Vutla wrote:
On Wednesday 06 April 2016 05:32 PM, Lokesh Vutla wrote:
Peripherals like spi etc. uses DMA for transfers. So, when loading the fit image the destination address should be dma aligned.
After the v5 of my FS support for FIT[1], this patch is no more necessary. Patch 2 is alone sufficient.
Thanks. Note that if you register with patchwork you should be able to manage the state of your own patches as well. Thanks!

On Thursday 05 May 2016 04:24 PM, Tom Rini wrote:
On Thu, May 05, 2016 at 11:22:42AM +0530, Lokesh Vutla wrote:
On Wednesday 06 April 2016 05:32 PM, Lokesh Vutla wrote:
Peripherals like spi etc. uses DMA for transfers. So, when loading the fit image the destination address should be dma aligned.
After the v5 of my FS support for FIT[1], this patch is no more necessary. Patch 2 is alone sufficient.
Thanks. Note that if you register with patchwork you should be able to manage the state of your own patches as well. Thanks!
Sure, Ill register with patchwork.
Thanks and regards, Lokesh

Detect a FIT when loading from SPI and handle it using the new FIT SPL support.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com --- drivers/mtd/spi/spi_spl_load.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/spi/spi_spl_load.c b/drivers/mtd/spi/spi_spl_load.c index ca56fe9..a255188 100644 --- a/drivers/mtd/spi/spi_spl_load.c +++ b/drivers/mtd/spi/spi_spl_load.c @@ -44,6 +44,18 @@ static int spi_load_image_os(struct spi_flash *flash, } #endif
+static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector, + ulong count, void *buf) +{ + struct spi_flash *flash = load->dev; + ulong ret; + + ret = spi_flash_read(flash, sector, count, buf); + if (!ret) + return count; + else + return 0; +} /* * 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 @@ -81,9 +93,23 @@ int spl_spi_load_image(void) if (err) return err;
- spl_parse_image_header(header); - err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, - spl_image.size, (void *)spl_image.load_addr); + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) { + struct spl_load_info load; + + debug("Found FIT\n"); + load.dev = flash; + load.priv = NULL; + load.bl_len = 1; + load.read = spl_spi_fit_read; + err = spl_load_simple_fit(&load, + CONFIG_SYS_SPI_U_BOOT_OFFS, + header); + } else { + spl_parse_image_header(header); + err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, + spl_image.size, + (void *)spl_image.load_addr); + } }
return err;

On Wed, Apr 06, 2016 at 05:33:00PM +0530, Lokesh Vutla wrote:
Detect a FIT when loading from SPI and handle it using the new FIT SPL support.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
Reviewed-by: Tom Rini trini@konsulko.com
participants (2)
-
Lokesh Vutla
-
Tom Rini