[U-Boot] flash erasing: len alignment
Wolfgang Denk
wd at denx.de
Thu Dec 11 11:22:49 CET 2008
Dear Mike Frysinger,
In message <200812110431.35694.vapier at gentoo.org> you wrote:
>
> the different flash subsystems dont exactly all operate the same, specifically
> when it comes to erasing. some require you to specify lengths that are
> aligned exactly to the erase sector size whereas others are much more
> intelligent: they automatically round up for you. is there any real arguments
> for a particular method ?
Flash commands *should* support two formats:
1) sector (and bank) numbers, for example:
erase 1:3-6
2) start and end address, for example:
erase 40000000 4003FFFF
3) start address and length, for example:
erase 40000000 +40000
The idea is that addresses (start and end address) have to be exact
and match sector boundaries as needed by the flash device, while
length is handled intelligently, i. e. to erase one sector you can
write
erase 40000000 +1
Sector and bank numbers have to be exact, too, of course.
> personally, i prefer the latter behavior as it makes scripting a hell of a lot
> easier. for example, if i want to load a binary file into a flash, the
> loading process (i.e. tftp) will automatically set $(filesize) which i can
> then use as the erase/write length. otherwise i need to either manually do
> the rounding up based on sector size, or i have to assume ahead of time that
> the file will never exceed a certain max size and use that hardcoded value
> (which leads to wasted time erasing sectors that never actually get used and
> unable to use the same code across multiple platforms).
That's why the "+length" method was added.
> here's an example change to the SPI flash driver:
> --- a/u-boot-2008.10/drivers/mtd/spi/stmicro.c
> +++ b/u-boot-2008.10/drivers/mtd/spi/stmicro.c
> @@ -262,12 +262,12 @@ int stmicro_erase(struct spi_flash
>
> sector_size = stm->params->page_size * stm->params->pages_per_sector;
>
> - if (offset % sector_size || len % sector_size) {
> + if (offset % sector_size) {
> debug("SF: Erase offset/length not multiple of sector size\n");
> return -1;
> }
>
> - len /= sector_size;
> + len = len / sector_size + !!(len % sector_size);
Except for the notation, which I find not so easy to read, that's OK
with me. Is a documentation update needed?
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"May your future be limited only by your dreams."
- Christa McAuliffe
More information about the U-Boot
mailing list