summaryrefslogtreecommitdiffstats
path: root/common/env_sf.c
diff options
context:
space:
mode:
authorTsiChung Liew <Tsi-Chung.Liew@freescale.com>2008-08-06 19:37:17 -0500
committerJohn Rigby <jrigby@freescale.com>2008-08-14 12:31:56 -0600
commit07efc9e321619c3dec213310c32e011aa6f02783 (patch)
tree076d8858958bd9e1a0ca6ca8294ce8e0a4dcffc4 /common/env_sf.c
parent4cb4e654cafabaa1ac180d37b00c8f6095dae9c9 (diff)
downloadblackbird-obmc-uboot-07efc9e321619c3dec213310c32e011aa6f02783.tar.gz
blackbird-obmc-uboot-07efc9e321619c3dec213310c32e011aa6f02783.zip
Change CFG_ENV_SIZE to CFG_ENV_SECT_SIZE for SPI sector erase
The CFG_ENV_SIZE is not suitable used for SPI flash erase sector size if CFG_ENV_SIZE is less than CFG_ENV_SECT_SIZE. Add condition check if CFG_ENV_SIZE is larger than CFG_ENV_SECT_SIZE, calculate the right number of sectors for erasing. Signed-off-by: TsiChung Liew <Tsi-Chung.Liew@freescale.com>
Diffstat (limited to 'common/env_sf.c')
-rw-r--r--common/env_sf.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/env_sf.c b/common/env_sf.c
index d641a9a73c..9077d783c3 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -63,13 +63,21 @@ uchar env_get_char_spec(int index)
int saveenv(void)
{
+ u32 sector = 1;
+
if (!env_flash) {
puts("Environment SPI flash not initialized\n");
return 1;
}
+ if (CFG_ENV_SIZE > CFG_ENV_SECT_SIZE) {
+ sector = CFG_ENV_SIZE / CFG_ENV_SECT_SIZE;
+ if (CFG_ENV_SIZE % CFG_ENV_SECT_SIZE)
+ sector++;
+ }
+
puts("Erasing SPI flash...");
- if (spi_flash_erase(env_flash, CFG_ENV_OFFSET, CFG_ENV_SIZE))
+ if (spi_flash_erase(env_flash, CFG_ENV_OFFSET, sector * CFG_ENV_SECT_SIZE))
return 1;
puts("Writing to SPI flash...");
OpenPOWER on IntegriCloud