]> git.sur5r.net Git - u-boot/commitdiff
Change CFG_ENV_SIZE to CFG_ENV_SECT_SIZE for SPI sector erase
authorTsiChung Liew <Tsi-Chung.Liew@freescale.com>
Thu, 7 Aug 2008 00:37:17 +0000 (19:37 -0500)
committerJohn Rigby <jrigby@freescale.com>
Thu, 14 Aug 2008 18:31:56 +0000 (12:31 -0600)
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>
common/env_sf.c

index d641a9a73cacf41e75085fb51f0c1f7b7799034d..9077d783c344cbbd23026342309189cbf57b71c3 100644 (file)
@@ -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...");