From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Fri, 30 May 2008 12:28:42 -0500 Subject: [U-Boot-Users] [PATCH]env_nand.c Added bad block management for environment variables In-Reply-To: References: <20080528175704.GA3090@loki.buserror.net> <483EE840.6030002@freescale.com> <483EE8CB.1060406@freescale.com> Message-ID: <20080530172842.GA2950@loki.buserror.net> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Fri, May 30, 2008 at 11:14:10AM -0400, Stuart Wood wrote: > +int writeenv(size_t offset, u_char * buf) No space after '*'. > + char_ptr = &buf[amount_saved]; > + if (nand_write(&nand_info[0], offset, &blocksize, char_ptr)) { Wrap long line. > + return 1; > + } else { The "else" is superfluous. > + puts ("Erasing redundant Nand...\n"); > + nand_erase(&nand_info[0], CFG_ENV_OFFSET_REDUND, CFG_ENV_RANGE); > + If erasing fails for reasons other than a bad block, we should abort. If erasing fails due to a bad block, we should skip past it; however, the current erase code fails and does not try to erase any further blocks. Use nand_erase_opts() instead. > - if (ret || total != CFG_ENV_SIZE) > + if (ret || total != CFG_ENV_SIZE) { > + puts("FAILED!\n"); > return 1; > + } total is no longer referenced anywhere but here and the initialization; remove it. > + while (amount_loaded < CFG_ENV_SIZE && offset < end) { > + if (nand_block_isbad(&nand_info[0], offset)) { > + offset += blocksize; > + } else { > + char_ptr = &buf[amount_loaded]; > + nand_read(&nand_info[0], offset, &blocksize, char_ptr); Please check the return value of nand_read. -Scott