public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/2] spl: Support loading a FIT from SPI
@ 2016-04-06 12:02 Lokesh Vutla
  2016-04-06 12:02 ` [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit Lokesh Vutla
  2016-04-06 12:03 ` [U-Boot] [PATCH 2/2] spl: Support loading a FIT from SPI Lokesh Vutla
  0 siblings, 2 replies; 8+ messages in thread
From: Lokesh Vutla @ 2016-04-06 12:02 UTC (permalink / raw)
  To: u-boot

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

-- 
2.1.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit
  2016-04-06 12:02 [U-Boot] [PATCH 0/2] spl: Support loading a FIT from SPI Lokesh Vutla
@ 2016-04-06 12:02 ` Lokesh Vutla
  2016-04-08 19:45   ` Tom Rini
  2016-05-05  5:52   ` Lokesh Vutla
  2016-04-06 12:03 ` [U-Boot] [PATCH 2/2] spl: Support loading a FIT from SPI Lokesh Vutla
  1 sibling, 2 replies; 8+ messages in thread
From: Lokesh Vutla @ 2016-04-06 12:02 UTC (permalink / raw)
  To: u-boot

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;
 }
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 2/2] spl: Support loading a FIT from SPI
  2016-04-06 12:02 [U-Boot] [PATCH 0/2] spl: Support loading a FIT from SPI Lokesh Vutla
  2016-04-06 12:02 ` [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit Lokesh Vutla
@ 2016-04-06 12:03 ` Lokesh Vutla
  2016-04-08 19:45   ` Tom Rini
  1 sibling, 1 reply; 8+ messages in thread
From: Lokesh Vutla @ 2016-04-06 12:03 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit
  2016-04-06 12:02 ` [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit Lokesh Vutla
@ 2016-04-08 19:45   ` Tom Rini
  2016-05-05  5:52   ` Lokesh Vutla
  1 sibling, 0 replies; 8+ messages in thread
From: Tom Rini @ 2016-04-08 19:45 UTC (permalink / raw)
  To: u-boot

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>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160408/32ec2bc4/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 2/2] spl: Support loading a FIT from SPI
  2016-04-06 12:03 ` [U-Boot] [PATCH 2/2] spl: Support loading a FIT from SPI Lokesh Vutla
@ 2016-04-08 19:45   ` Tom Rini
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2016-04-08 19:45 UTC (permalink / raw)
  To: u-boot

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>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160408/513e2ae5/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit
  2016-04-06 12:02 ` [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit Lokesh Vutla
  2016-04-08 19:45   ` Tom Rini
@ 2016-05-05  5:52   ` Lokesh Vutla
  2016-05-05 10:54     ` Tom Rini
  1 sibling, 1 reply; 8+ messages in thread
From: Lokesh Vutla @ 2016-05-05  5:52 UTC (permalink / raw)
  To: u-boot



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 -
> +			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;
>  }
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit
  2016-05-05  5:52   ` Lokesh Vutla
@ 2016-05-05 10:54     ` Tom Rini
  2016-05-06 10:15       ` Lokesh Vutla
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Rini @ 2016-05-05 10:54 UTC (permalink / raw)
  To: u-boot

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.
> 
> [1] http://patchwork.ozlabs.org/patch/618403/

Thanks.  Note that if you register with patchwork you should be able to
manage the state of your own patches as well.  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160505/8ed109ca/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit
  2016-05-05 10:54     ` Tom Rini
@ 2016-05-06 10:15       ` Lokesh Vutla
  0 siblings, 0 replies; 8+ messages in thread
From: Lokesh Vutla @ 2016-05-06 10:15 UTC (permalink / raw)
  To: u-boot



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.
>>
>> [1] http://patchwork.ozlabs.org/patch/618403/
> 
> 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

> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-06 10:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-06 12:02 [U-Boot] [PATCH 0/2] spl: Support loading a FIT from SPI Lokesh Vutla
2016-04-06 12:02 ` [U-Boot] [PATCH 1/2] spl: Make sure destination address is dma aligned when loading fit Lokesh Vutla
2016-04-08 19:45   ` Tom Rini
2016-05-05  5:52   ` Lokesh Vutla
2016-05-05 10:54     ` Tom Rini
2016-05-06 10:15       ` Lokesh Vutla
2016-04-06 12:03 ` [U-Boot] [PATCH 2/2] spl: Support loading a FIT from SPI Lokesh Vutla
2016-04-08 19:45   ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox