spl: Support loading a FIT from NAND
Subsystems (2)
cover spl: Support loading a FIT from NAND
This series adds support for loading a FIT image from NAND. Also fixes copying of image from am335x nand.
Verified on Am437x-GP evm with FIT enabled.
Lokesh Vutla (2):
mtd: nand: am335x: spl: Fix copying of image
spl: Support loading a FIT from NAND
common/spl/spl_nand.c | 33 ++++++++++++++++++++++++++++++--- drivers/mtd/nand/am335x_spl_bch.c | 15 ++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/2 mtd: nand: am335x: spl: Fix copying of image
When offset is not aligned to page address, it is possible that extra offset will be read from nand. Adjust the image such that first byte of the image is at load address after the first page is read.
--- drivers/mtd/nand/am335x_spl_bch.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/mtd/nand/am335x_spl_bch.c +14 -1
@@ -173,7 +173,7 @@ static int nand_read_page(int block, int page, void *dst)int nand_spl_load_image (uint32_t offs,unsigned int size,void *dst) {unsigned int block, lastblock; -unsigned int page; +unsigned int page, page_offset;/* * offs has to be aligned to a page address!
@@ -181,6 +181,7 @@ int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst) block = offs /CONFIG_SYS_NAND_BLOCK_SIZE ; lastblock = (offs + size -1 ) /CONFIG_SYS_NAND_BLOCK_SIZE ; page = (offs %CONFIG_SYS_NAND_BLOCK_SIZE ) /CONFIG_SYS_NAND_PAGE_SIZE ; + page_offset = offs %CONFIG_SYS_NAND_PAGE_SIZE ;while (block <= lastblock) {if (!nand_is_bad_block (block)) {
@@ -189,6 +190,18 @@ int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)*/ while (page <CONFIG_SYS_NAND_PAGE_COUNT ) {nand_read_page (block, page, dst); +/* +* When offs is not aligned to page address the +* extra offset is copied to dst as well. Copy +* the image such that its first byte will be +*@the dst. +*/ +if (unlikely (page_offset)) { +memmove (dst, dst + page_offset, +CONFIG_SYS_NAND_PAGE_SIZE ); + dst = (void *)((int )dst - page_offset); + page_offset =0 ; + } dst +=CONFIG_SYS_NAND_PAGE_SIZE ; page++; }
Signature · 1 line
2.1.4
PATCH 1/2 mtd: nand: am335x: spl: Fix copying of image
Quoted 5 lines · Lokesh Vutla
When offset is not aligned to page address, it is possible that extra offset will be read from nand. Adjust the image such that first byte of the image is at load address after the first page is read.
Signed-off-by Lokesh Vutla <[email protected]>
Signature · 8 lines
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/20160412/f5824ee6/attachment.sig>
PATCH 2/2 spl: Support loading a FIT from NAND
In reply to Lokesh VutlaDetect a FIT when loading from NAND and handle it using the new FIT SPL support.
--- common/spl/spl_nand.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
common/spl/spl_nand.c +30 -3
@@ -9,6 +9,8 @@#include <spl.h> #include <asm/io.h> #include <nand.h> +#include <libfdt_env.h> +#include <fdt.h> #if defined(CONFIG_SPL_NAND_RAW_ONLY )int spl_nand_load_image (void )
@@ -24,6 +26,19 @@ int spl_nand_load_image(void) return 0; }#else + +static ulong spl_nand_fit_read (struct spl_load_info *load,ulong offs, +ulong size,void *dst) +{ +int ret; + + ret =nand_spl_load_image (offs, size, dst); +if (!ret) +return size; +else +return 0 ; +} +static int spl_nand_load_element (int offset,struct image_header *header) {int err;
@@ -32,9 +47,21 @@ static int spl_nand_load_element(int offset, struct image_header *header)if (err)return err; -spl_parse_image_header (header); -return nand_spl_load_image (offset, spl_image.size, - (void *)(unsigned long )spl_image.load_addr); +if (IS_ENABLED (CONFIG_SPL_LOAD_FIT ) && +image_get_magic (header) ==FDT_MAGIC ) { +struct spl_load_info load; + +debug ("Found FIT\n" ); + load.dev =NULL ; + load.priv =NULL ; + load.bl_len =1 ; + load.read = spl_nand_fit_read; +return spl_load_simple_fit (&load, offset, header); + }else { +spl_parse_image_header (header); +return nand_spl_load_image (offset, spl_image.size, + (void *)spl_image.load_addr); + } }int spl_nand_load_image (void )
Signature · 1 line
2.1.4
PATCH 2/2 spl: Support loading a FIT from NAND
Quoted 4 lines · Lokesh Vutla
Detect a FIT when loading from NAND and handle it using the new FIT SPL support.
Signed-off-by Lokesh Vutla <[email protected]>
Signature · 8 lines
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/20160412/fbcb2ced/attachment.sig>