diff mbox

[U-Boot,v5,3/3] spl: Support loading a FIT from FAT FS

Message ID 1462363477-20445-4-git-send-email-lokeshvutla@ti.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Lokesh Vutla May 4, 2016, 12:04 p.m. UTC
Detect a FIT when loading from a FAT File system and handle it using the
new FIT SPL support.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
---
 common/spl/spl_fat.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

Comments

Michal Simek May 4, 2016, 2:56 p.m. UTC | #1
On 4.5.2016 14:04, Lokesh Vutla wrote:
> Detect a FIT when loading from a FAT File system and handle it using the
> new FIT SPL support.
> 
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
> ---
>  common/spl/spl_fat.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
> index d761b26..cdb9811 100644
> --- a/common/spl/spl_fat.c
> +++ b/common/spl/spl_fat.c
> @@ -15,6 +15,7 @@
>  #include <fat.h>
>  #include <errno.h>
>  #include <image.h>
> +#include <libfdt.h>
>  
>  static int fat_registered;
>  
> @@ -39,6 +40,20 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
>  	return err;
>  }
>  
> +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
> +			  ulong size, void *buf)
> +{
> +	loff_t actread;
> +	int ret;
> +	char *filename = (char *)load->priv;
> +
> +	ret = fat_read_file(filename, buf, file_offset, size, &actread);
> +	if (ret)
> +		return ret;
> +
> +	return actread;
> +}
> +
>  int spl_load_image_fat(struct blk_desc *block_dev,
>  						int partition,
>  						const char *filename)
> @@ -57,9 +72,21 @@ int spl_load_image_fat(struct blk_desc *block_dev,
>  	if (err <= 0)
>  		goto end;
>  
> -	spl_parse_image_header(header);
> +	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
> +	    image_get_magic(header) == FDT_MAGIC) {
> +		struct spl_load_info load;
> +
> +		debug("Found FIT\n");
> +		load.read = spl_fit_read;
> +		load.bl_len = 1;
> +		load.priv = (void *)filename;
>  
> -	err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
> +		return spl_load_simple_fit(&load, 0, header);
> +	} else {
> +		spl_parse_image_header(header);
> +
> +		err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
> +	}
>  
>  end:
>  #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
> 


Tested-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal
Tom Rini May 6, 2016, 5:47 p.m. UTC | #2
On Wed, May 04, 2016 at 05:34:37PM +0530, Lokesh Vutla wrote:

> Detect a FIT when loading from a FAT File system and handle it using the
> new FIT SPL support.
> 
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass May 19, 2016, 3:59 a.m. UTC | #3
On 4 May 2016 at 06:04, Lokesh Vutla <lokeshvutla@ti.com> wrote:
> Detect a FIT when loading from a FAT File system and handle it using the
> new FIT SPL support.
>
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
> ---
>  common/spl/spl_fat.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index d761b26..cdb9811 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -15,6 +15,7 @@ 
 #include <fat.h>
 #include <errno.h>
 #include <image.h>
+#include <libfdt.h>
 
 static int fat_registered;
 
@@ -39,6 +40,20 @@  static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
 	return err;
 }
 
+static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
+			  ulong size, void *buf)
+{
+	loff_t actread;
+	int ret;
+	char *filename = (char *)load->priv;
+
+	ret = fat_read_file(filename, buf, file_offset, size, &actread);
+	if (ret)
+		return ret;
+
+	return actread;
+}
+
 int spl_load_image_fat(struct blk_desc *block_dev,
 						int partition,
 						const char *filename)
@@ -57,9 +72,21 @@  int spl_load_image_fat(struct blk_desc *block_dev,
 	if (err <= 0)
 		goto end;
 
-	spl_parse_image_header(header);
+	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+	    image_get_magic(header) == FDT_MAGIC) {
+		struct spl_load_info load;
+
+		debug("Found FIT\n");
+		load.read = spl_fit_read;
+		load.bl_len = 1;
+		load.priv = (void *)filename;
 
-	err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
+		return spl_load_simple_fit(&load, 0, header);
+	} else {
+		spl_parse_image_header(header);
+
+		err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
+	}
 
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT