All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH]env_nand.c Added bad block management	for environment variables
Date: Wed, 28 May 2008 12:57:04 -0500	[thread overview]
Message-ID: <20080528175704.GA3090@loki.buserror.net> (raw)
In-Reply-To: <c13b1cfc0805270701s38288252k5de057bd96d8c856@mail.gmail.com>

On Tue, May 27, 2008 at 10:01:14AM -0400, Stuart Wood wrote:
> Hi All, This is my first attempt at submitting a change so please be
> patient and kind. This change allows for the environment variables to be
> stored in a rand of nand flash. If the first block is bad then the
> environment is stored in the next one, and so on. It introduces
> CFG_ENV_RANGE to define the size of the area that way contain the
> environment data. This will allow the environment to be loaded over an
> area with bad blocks from the factory without a problem.

This will break any board that doesn't define CFG_ENV_RANGE... it should
default to CFG_ENV_SIZE if unset.

>  	if(gd->env_valid == 1) {
> -		puts ("Erasing redundant Nand...");
> -		if (nand_erase(&nand_info[0],
> -			       CFG_ENV_OFFSET_REDUND, CFG_ENV_SIZE))
> +		puts ("Erasing redundant Nand...\n");
> +		for (offset = CFG_ENV_OFFSET_REDUND; offset <
> +				CFG_ENV_OFFSET_REDUND + CFG_ENV_RANGE; )
> +		{
> +			if (nand_erase(&nand_info[0],
> +					offset, CFG_ENV_SIZE)) {
> +				offset += CFG_ENV_SIZE;
> +			} else {
> +				break;
> +			}
> +		}

Please factor this code out instead of duplicating it for both environment
instances.

It'd also be nicer as something like this:

offset = CFG_ENV_REDUND;
end = offset + CFG_ENV_RANGE;

while (offset < end && nand_erase(&nand_info[0], offset, CFG_ENV_SIZE))
	offset += CFG_ENV_SIZE;

> @@ -189,15 +215,30 @@ int saveenv(void)
>  int saveenv(void)
>  {
>  	size_t total;
> +	size_t offset;
>  	int ret = 0;
> 
> -	puts ("Erasing Nand...");
> -	if (nand_erase(&nand_info[0], CFG_ENV_OFFSET, CFG_ENV_SIZE))
> +	if (CFG_ENV_RANGE < CFG_ENV_SIZE)
>  		return 1;
> +	puts ("Erasing Nand...\n");
> +	for (offset = CFG_ENV_OFFSET; offset <
> +			CFG_ENV_OFFSET + CFG_ENV_RANGE; )
> +	{
> +		if (nand_erase(&nand_info[0],
> +				offset, CFG_ENV_SIZE)) {
> +			offset += CFG_ENV_SIZE;
> +		} else {
> +			break;
> +		}
> +	}
> +	if (offset >= CFG_ENV_OFFSET + CFG_ENV_RANGE) {
> +		puts ("Nand area is completely bad!\n");
> +		return 1;
> +	}

It'd be nice if we could reduce the duplication between the two versions of
saveenv() as well.

> +	for (offset = CFG_ENV_OFFSET; offset < CFG_ENV_OFFSET + CFG_ENV_RANGE ; ) {
> +		if (nand_block_isbad (&nand_info[0], offset)) {
> +			offset += CFG_ENV_SIZE;
> +		} else {
> +			nand_read(&nand_info[0], offset, &total,
> +				(u_char*) tmp_env1);
> +			break;
> +		}
> +	}
> +	for (offset = CFG_ENV_OFFSET_REDUND; offset <
> +			CFG_ENV_OFFSET_REDUND + CFG_ENV_RANGE ; ) {
> +		if (nand_block_isbad (&nand_info[0], offset)) {
> +			offset += CFG_ENV_SIZE;
> +		} else {
> +			nand_read(&nand_info[0], offset, &total,
> +				(u_char*) tmp_env2);
> +			break;
> +		}
> +	}

Same comments as saveenv().

-Scott

  reply	other threads:[~2008-05-28 17:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-27 14:01 [U-Boot-Users] [PATCH]env_nand.c Added bad block management for environment variables Stuart Wood
2008-05-28 17:57 ` Scott Wood [this message]
2008-05-29 17:14   ` Stuart Wood
2008-05-29 17:30     ` Scott Wood
2008-05-29 17:32       ` Scott Wood
2008-05-30 15:14         ` Stuart Wood
2008-05-30 17:28           ` Scott Wood
2008-05-30 20:05             ` Stuart Wood
2008-06-02 20:03               ` Scott Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080528175704.GA3090@loki.buserror.net \
    --to=scottwood@freescale.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.