[U-Boot] [U-boot] sf: API for spi_flash_get_sector_size

Wolfgang Denk wd at denx.de
Tue Feb 8 16:19:25 CET 2011


Dear Richard Retanubun,

In message <4D515D06.7020209 at RuggedCom.com> you wrote:
> 
> If by "how NOR flash in handled" you mean cmd_flash.c::flash_sect_roundb() then yes, I do want to do this
> but I need to know what number to round it to, no?

The code needs to know that, you don't ;-)

> In the context of cmd_flash, it has access to flash_info_t
> which contains the sector_size information. Also cfi_flash.c also provides a function called flash_sector_size()
> that is called by other components that needs to know. If I have misunderstood what you mean, sorry, please clarify.

You are right.

> To have SPI flash do this, for example; stmicro.c::stmicro_erase() function will auto round up to the nearest sector_size.
> Which is indeed the simpler way. Right now, most drivers/mtd/spi/*.c just does this check:
> 
> <quoted_code>
> sector_size = stm->params->page_size * stm->params->pages_per_sector;
> 
> if (offset % sector_size || len % sector_size) {
> 	debug("SF: Erase offset/length not multiple of sector size\n");
> 	return -1;
> }
> </quoted_code>

This is ok if an explicit size is given - you will se ethe same
behaviour on NOR flash when trying something like

	erase 40000000 40002345

> I am worried about unintentionally erasing more than what the caller requested.
> Would it be better to round up manually and then calls the erase?

No.  If the caller uses the "+<size>" notation he explictly requests
to round up.  He is supposed to know what he is doing.

Being able to use "+${filesize}" allows for many powerful solutions
to standard tasks that without this would result in cumbersome
manipulation of the size - which would then probably break if you
issue a new revision of your hardware with different flash chips fit.

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
"If you'll excuse me a minute, I'm going to have a cup of coffee."
- broadcast from Apollo 11's LEM, "Eagle", to Johnson  Space  Center,
Houston July 20, 1969, 7:27 P.M.


More information about the U-Boot mailing list