[U-Boot] [PATCH 5/6] Support environment anywhere within erase area

Guennadi Liakhovetski lg at denx.de
Sun Aug 31 21:39:01 CEST 2008


On Sun, 31 Aug 2008, Wolfgang Denk wrote:

> Dear Guennadi Liakhovetski,
> 
> In message <Pine.LNX.4.64.0808271747470.6718 at axis700.grange> you wrote:
> > This will become more important with NAND support, in which case the minimum
> > erase region is a block, which consists of several pages and can be 256KiB
> > large.
> 
> Please explain.
> 
> What does "anywhere" mean? At offset 0, 1, 5, 17 or 42? Or what?  And
> what exactly is the "erase area" ?

Yes, at any offset. I hope, everybody will not start from tomorrow putting 
their environment at offset 17, but this is supported by this tool now, 
yes.

Erase area - this is all we erase, as opposed to one erase sector. On NOR 
this is limited by the environment size, on NAND by the number of blocks - 
the fifth parameter in the configuration file. This area may contain other 
useful data, which is first read in, then the whole area is erased, the 
environment is replaced in the read-in data, and it is written back - this 
is what I call the back-up process in the code.

> And where's the difference between NAND and NOR flash? For  NOR,  the
> minimum "erase region" is a "block", either, which also can be 256KiB
> large.

This patch enables this for NOR - NAND support comes first with patch 6. 
So, it just enables placing the actual environment at any offset in the 
"erase area".

> > +	/*
> > +	 * Support environment anywhere within erase sectors: read out the
> > +	 * complete area to be erased, replace the environment image, write
> > +	 * the whole block back again.
> > +	 */

This comment should actually serve as an explanation...

> > +	if (DEVESIZE (dev_target) > CFG_ENV_SIZE) {
> > +		data = malloc (DEVESIZE (dev_target));
> > +		if (!data) {
> > +			fprintf (stderr,
> > +				 "Cannot malloc %lu bytes: %s\n",
> > +				 DEVESIZE (dev_target),
> > +				 strerror (errno));
> > +			return -1;
> > +		}
> > +
> > +		rc = ioctl (fd_target, MEMGETINFO, &mtdinfo_target);
> > +		if (rc < 0) {
> > +			perror ("Cannot get MTD information");
> > +			return -1;
> > +		}
> > +
> > +		/* Erase sector size is always a power of 2 */
> > +		erase_offset = DEVOFFSET (dev_target) &
> > +			~(mtdinfo_target.erasesize - 1);
> > +
> > +		rc = flash_read_buf (dev_target, fd_target, data,
> > +				     DEVESIZE (dev_target), erase_offset);
> > +		if (rc < 0)
> > +			return rc;
> > +
> > +		/* Overwrite the old environment */
> > +		memcpy(DEVOFFSET (dev_target) - erase_offset + data,
> > +		       environment.image, CFG_ENV_SIZE);
> > +	} else {
> > +		data = (char *)environment.image;
> > +		erase_offset = DEVOFFSET (dev_target);
> > +	}
> 
> You are talking about "several pages" above. Where is this refelected
> in the code?

You mean in the commit comment? There I am talking about the future code - 
NAND case, which is not yet in this patch.

> Frankly, I don't understand what you are trying to do. Please explain
> your implementation.

Hope, it is a bit clearer now. If not, please ask, will try to explain 
again.

Indeed, this patch series changes the programme in a non-trivial way, 
that's why I had to split this "NAND-support" into several patches, still 
some of them seem to be not clear enough.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.

DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de


More information about the U-Boot mailing list