mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-01 08:59:33 +00:00
spl: fit: nand: fix fit loading in case of bad blocks
The offset at which the image to be loaded from NAND is located is retrieved from the itb header. The presence of bad blocks in the area of the NAND where the itb image is located could invalidate the offset which must therefore be adjusted taking into account the state of the sectors concerned. cc: Michael Trimarchi <michael@amarulasolutions.com> Signed-off-by: Dario Binacchi <dariobin@libero.it> Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
This commit is contained in:
parent
585b468a8c
commit
9f6a14c47f
3 changed files with 33 additions and 1 deletions
|
@ -42,8 +42,11 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
|
||||||
static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
|
static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
|
||||||
ulong size, void *dst)
|
ulong size, void *dst)
|
||||||
{
|
{
|
||||||
|
ulong sector;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
sector = *(int *)load->priv;
|
||||||
|
offs = sector + nand_spl_adjust_offset(sector, offs - sector);
|
||||||
ret = nand_spl_load_image(offs, size, dst);
|
ret = nand_spl_load_image(offs, size, dst);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return size;
|
return size;
|
||||||
|
@ -66,7 +69,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
|
||||||
|
|
||||||
debug("Found FIT\n");
|
debug("Found FIT\n");
|
||||||
load.dev = NULL;
|
load.dev = NULL;
|
||||||
load.priv = NULL;
|
load.priv = &offset;
|
||||||
load.filename = NULL;
|
load.filename = NULL;
|
||||||
load.bl_len = 1;
|
load.bl_len = 1;
|
||||||
load.read = spl_nand_fit_read;
|
load.read = spl_nand_fit_read;
|
||||||
|
|
|
@ -41,6 +41,34 @@ int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nand_spl_adjust_offset - Adjust offset from a starting sector
|
||||||
|
* @sector: Address of the sector
|
||||||
|
* @offs: Offset starting from @sector
|
||||||
|
*
|
||||||
|
* If one or more bad blocks are in the address space between @sector
|
||||||
|
* and @sector + @offs, @offs is increased by the NAND block size for
|
||||||
|
* each bad block found.
|
||||||
|
*/
|
||||||
|
u32 nand_spl_adjust_offset(u32 sector, u32 offs)
|
||||||
|
{
|
||||||
|
unsigned int block, lastblock;
|
||||||
|
|
||||||
|
block = sector / CONFIG_SYS_NAND_BLOCK_SIZE;
|
||||||
|
lastblock = (sector + offs) / CONFIG_SYS_NAND_BLOCK_SIZE;
|
||||||
|
|
||||||
|
while (block <= lastblock) {
|
||||||
|
if (nand_is_bad_block(block)) {
|
||||||
|
offs += CONFIG_SYS_NAND_BLOCK_SIZE;
|
||||||
|
lastblock++;
|
||||||
|
}
|
||||||
|
|
||||||
|
block++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offs;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SPL_UBI
|
#ifdef CONFIG_SPL_UBI
|
||||||
/*
|
/*
|
||||||
* Temporary storage for non NAND page aligned and non NAND page sized
|
* Temporary storage for non NAND page aligned and non NAND page sized
|
||||||
|
|
|
@ -120,6 +120,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,
|
||||||
int allexcept);
|
int allexcept);
|
||||||
int nand_get_lock_status(struct mtd_info *mtd, loff_t offset);
|
int nand_get_lock_status(struct mtd_info *mtd, loff_t offset);
|
||||||
|
|
||||||
|
u32 nand_spl_adjust_offset(u32 sector, u32 offs);
|
||||||
int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
|
int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
|
||||||
int nand_spl_read_block(int block, int offset, int len, void *dst);
|
int nand_spl_read_block(int block, int offset, int len, void *dst);
|
||||||
void nand_deselect(void);
|
void nand_deselect(void);
|
||||||
|
|
Loading…
Reference in a new issue