[U-Boot-Users] [PATCH]env_nand.c Added bad block management for environment variables

Scott Wood scottwood at freescale.com
Fri May 30 19:28:42 CEST 2008


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




More information about the U-Boot mailing list