env_nand: simplify readenv()
PATCH v2 1/1 env_nand: simplify readenv()
nand_read_skip_bad() already loops over blocks and handles bad block check so eliminate this redundant logic.
Signed-off-by Tim Harvey <[email protected]>
---
v2: fix limit
common/env_nand.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-)
common/env_nand.c +6 -26
@@ -268,35 +268,15 @@ static int readenv(size_t offset, u_char *buf)#else static int readenv (size_t offset,u_char *buf) { -size_t end = offset +CONFIG_ENV_RANGE ; -size_t amount_loaded =0 ; -size_t blocksize, len; -u_char *char_ptr; +nand_info_t *nand = &nand_info[0 ]; +size_t len; - blocksize = nand_info[0 ].erasesize; -if (!blocksize) + len =min ((size_t )nand->size - offset, (size_t )CONFIG_ENV_RANGE ); +debug ("%s: offset=0x%08x len=0x%08x\n" , __func__, offset, len); +if (nand_read_skip_bad (nand, offset, &len,NULL , nand->size, buf))return 1 ; - len =min (blocksize, (size_t )CONFIG_ENV_SIZE ); -debug ("%s: offset=0x%08x blocksize=0x%08x len=0x%08x\n" , - __func__, offset, blocksize, len); - -while (amount_loaded <CONFIG_ENV_SIZE && offset < end) { -if (nand_block_isbad (&nand_info[0 ], offset)) { - offset += blocksize; - }else { - char_ptr = &buf[amount_loaded]; -if (nand_read_skip_bad (&nand_info[0 ], offset, - &len,NULL , - nand_info[0 ].size, char_ptr)) -return 1 ; - - offset += blocksize; - amount_loaded += len; - } - } - -if (amount_loaded !=CONFIG_ENV_SIZE ) +if (len !=CONFIG_ENV_SIZE )return 1 ;return 0 ;
Signature · 1 line
1.9.1
PATCH v2 1/1 env_nand: simplify readenv()
Quoted 18 lines · Tim Harvey
nand_read_skip_bad()already loops over blocks and handles bad block check so eliminate this redundant logic.Signed-off-by Tim Harvey <[email protected]>---
v2: fix limitcommon/env_nand.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-)common/env_nand.c +0
-0@@ -268,35 +268,15 @@ static int readenv(size_t offset, u_char *buf)#else static int readenv (size_t offset,u_char *buf) {
common/env_nand.c static int readenv(size_t offset, u_char *buf) · line 274
Quoted 10 lines
common/env_nand.c +3
-6-size_t end = offset +CONFIG_ENV_RANGE ; -size_t amount_loaded =0 ; -size_t blocksize, len; -u_char *char_ptr; +nand_info_t *nand = &nand_info[0 ]; +size_t len; - blocksize = nand_info[0 ].erasesize; -if (!blocksize) + len =min ((size_t )nand->size - offset, (size_t )CONFIG_ENV_RANGE );
This should be the limit ("lim", what you currently have as nand->size), not len.
common/env_nand.c static int readenv(size_t offset, u_char *buf) · line 277
Quoted 3 lines
common/env_nand.c +2
-0+debug ("%s: offset=0x%08x len=0x%08x\n" , __func__, offset, len); +if (nand_read_skip_bad (nand, offset, &len,NULL , nand->size, buf))return 1 ;
-Scott