common: env_nand: Ensure that we have nand_info[0] prior to use
PATCH v3 1/1 common: env_nand: Ensure that we have nand_info[0] prior to use
Now that nand_info[] is an array of pointers we need to ensure that it's been populated prior to use. We may for example have ENV in NAND set in configurations that run on boards with and without NAND (where default env is fine enough, such as omap3_beagle and beagleboard (NAND) vs beagle xM (no NAND)).
---
Changes in v3:
- Don't overload the blocksize check in readenv(), and now that blocksize would never be zero (this was the previous way to see that we had no NAND detected), remove that check.
- Address the CONFIG_ENV_OFFSET_OOB case in env_relocate_spec() as this too would fail now if no NAND was detected.
Changes in v2:
- Oops, move check on the saveenv side in to erase_and_write_env
--- common/env_nand.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
common/env_nand.c +7 -4
@@ -163,6 +163,9 @@ static int erase_and_write_env(const struct env_location *location, {int ret =0 ; +if (!nand_info[0 ]) +return 1 ; +printf ("Erasing %s...\n" , location->name);if (nand_erase_opts (nand_info[0 ], &location->erase_opts))return 1 ;
@@ -247,10 +250,10 @@ static int readenv(size_t offset, u_char *buf)size_t blocksize, len;u_char *char_ptr; - blocksize = nand_info[0 ]->erasesize; -if (!blocksize) +if (!nand_info[0 ])return 1 ; + blocksize = nand_info[0 ]->erasesize; len =min (blocksize, (size_t )CONFIG_ENV_SIZE );while (amount_loaded <CONFIG_ENV_SIZE && offset < end) {
@@ -387,12 +390,12 @@ void env_relocate_spec(void)ALLOC_CACHE_ALIGN_BUFFER (char, buf,CONFIG_ENV_SIZE );#if defined(CONFIG_ENV_OFFSET_OOB ) - ret =get_nand_env_oob (nand_info[0 ], &nand_env_oob_offset);/* * If unable to read environment offset from NAND OOB then fall through * to the normal environment reading code below */ -if (!ret) { +if (nand_info[0 ] && !get_nand_env_oob (nand_info[0 ], + &nand_env_oob_offset)) {printf ("Found Environment offset in OOB..\n" ); }else {set_default_env ("!no env offset in OOB" );
Signature · 1 line
1.9.1
PATCH v3 1/1 common: env_nand: Ensure that we have nand_info[0] prior to use
Quoted 17 lines · Tom Rini
Now that nand_info[] is an array of pointers we need to ensure that it's been populated prior to use.??We may for example have ENV in NAND set in configurations that run on boards with and without NAND (where default env is fine enough, such as
omap3_beagleand beagleboard (NAND) vs beagle xM (no NAND)).Fixes b616d9b0a708 ("nand: Embed mtd_info in struct nand_chip")Cc Scott Wood <[email protected]>Signed-off-by Tom Rini <[email protected]>---
Changes in v3:
- Don't overload the blocksize check inreadenv(), and now that ? blocksize would never be zero (this was the previous way to see that ? we had no NAND detected), remove that check.
- Address theCONFIG_ENV_OFFSET_OOBcase inenv_relocate_spec()as this ? too would fail now if no NAND was detected.
Quoted 5 lines
Changes in v2:
- Oops, move check on the saveenv side in toerase_and_write_env
---
?common/env_nand.c | 11 +++++++----
?1 file changed, 7 insertions(+), 4 deletions(-)
-Scott
PATCH v3 1/1 common: env_nand: Ensure that we have nand_info[0] prior to use
In reply to Tom RiniQuoted 10 lines · Tom Rini
Now that nand_info[] is an array of pointers we need to ensure that it's been populated prior to use. We may for example have ENV in NAND set in configurations that run on boards with and without NAND (where default env is fine enough, such as
omap3_beagleand beagleboard (NAND) vs beagle xM (no NAND)).Fixes b616d9b0a708 ("nand: Embed mtd_info in struct nand_chip")Cc Scott Wood <[email protected]>Signed-off-by Tom Rini <[email protected]>Acked-by Scott Wood <[email protected]>
Applied to u-boot/master, thanks!
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/20160815/36c8a222/attachment.sig>