From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Retanubun Date: Tue, 8 Feb 2011 10:11:02 -0500 Subject: [U-Boot] [U-boot] sf: API for spi_flash_get_sector_size In-Reply-To: <20110208144008.8471614B9A0D@gemini.denx.de> References: <4D514F6E.6040101@RuggedCom.com> <20110208144008.8471614B9A0D@gemini.denx.de> Message-ID: <4D515D06.7020209@RuggedCom.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 02/08/11 09:40, Wolfgang Denk wrote: Thanks for the speedy response Wolfgang, > Dear Richard Retanubun, > > In message<4D514F6E.6040101@RuggedCom.com> you wrote: >> >> When calling spi_flash_erase, which eventually calls stmicro_erase, one must do so while knowing >> what the sector_size is of the flash. Is there a recommened API to getting this from struct stmicro_spi_flash_params? > > Why would you need to know the sector size? > > To align your erase command accordingly? Yep. I think you are taking the wrong approach here. Look at how NOR flash is handled: we don't need > to know the sector sizes there either. Instead we support the format > "+N" (often used as "+${fileszize}") which will _internally_ round up > N to match the next erase block boundary. > > Do the same for SPI flash. 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? 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. 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: 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; } 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? Thanks for your time - Richard