Commit 07efc9e321619c3dec213310c32e011aa6f02783

Authored by TsiChung Liew
Committed by John Rigby
1 parent 4cb4e654ca

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>

Showing 1 changed file with 9 additions and 1 deletions Side-by-side Diff

... ... @@ -63,13 +63,21 @@
63 63  
64 64 int saveenv(void)
65 65 {
  66 + u32 sector = 1;
  67 +
66 68 if (!env_flash) {
67 69 puts("Environment SPI flash not initialized\n");
68 70 return 1;
69 71 }
70 72  
  73 + if (CFG_ENV_SIZE > CFG_ENV_SECT_SIZE) {
  74 + sector = CFG_ENV_SIZE / CFG_ENV_SECT_SIZE;
  75 + if (CFG_ENV_SIZE % CFG_ENV_SECT_SIZE)
  76 + sector++;
  77 + }
  78 +
71 79 puts("Erasing SPI flash...");
72   - if (spi_flash_erase(env_flash, CFG_ENV_OFFSET, CFG_ENV_SIZE))
  80 + if (spi_flash_erase(env_flash, CFG_ENV_OFFSET, sector * CFG_ENV_SECT_SIZE))
73 81 return 1;
74 82  
75 83 puts("Writing to SPI flash...");