Commit 23869bf80b68af9ef1802b9e556f4fd0e9e57fe5
Committed by
Tom Rini
1 parent
f351eb0f18
Exists in
v2017.01-smarct4x
and in
48 other branches
fw_env: calculate default number of env sectors
The assumed number of environment sectors (always 1) leads to an incorrect top_of_range calculation in fw.env.c when a flash device has an erase block size smaller than the environment data size (number of environment sectors > 1). This change updates the default number of environment sectors to at least cover the size of the environment. Also corrected a false statement about the number of sectors column in fw_env.config. Signed-off-by: Dustin Byford <dustin@cumulusnetworks.com>
Showing 2 changed files with 9 additions and 7 deletions Side-by-side Diff
tools/env/fw_env.c
... | ... | @@ -1246,9 +1246,10 @@ |
1246 | 1246 | strcpy (DEVNAME (0), DEVICE1_NAME); |
1247 | 1247 | DEVOFFSET (0) = DEVICE1_OFFSET; |
1248 | 1248 | ENVSIZE (0) = ENV1_SIZE; |
1249 | - /* Default values are: erase-size=env-size, #sectors=1 */ | |
1249 | + /* Default values are: erase-size=env-size */ | |
1250 | 1250 | DEVESIZE (0) = ENVSIZE (0); |
1251 | - ENVSECTORS (0) = 1; | |
1251 | + /* #sectors=env-size/erase-size (rounded up) */ | |
1252 | + ENVSECTORS (0) = (ENVSIZE(0) + DEVESIZE(0) - 1) / DEVESIZE(0); | |
1252 | 1253 | #ifdef DEVICE1_ESIZE |
1253 | 1254 | DEVESIZE (0) = DEVICE1_ESIZE; |
1254 | 1255 | #endif |
1255 | 1256 | |
... | ... | @@ -1260,9 +1261,10 @@ |
1260 | 1261 | strcpy (DEVNAME (1), DEVICE2_NAME); |
1261 | 1262 | DEVOFFSET (1) = DEVICE2_OFFSET; |
1262 | 1263 | ENVSIZE (1) = ENV2_SIZE; |
1263 | - /* Default values are: erase-size=env-size, #sectors=1 */ | |
1264 | + /* Default values are: erase-size=env-size */ | |
1264 | 1265 | DEVESIZE (1) = ENVSIZE (1); |
1265 | - ENVSECTORS (1) = 1; | |
1266 | + /* #sectors=env-size/erase-size (rounded up) */ | |
1267 | + ENVSECTORS (1) = (ENVSIZE(1) + DEVESIZE(1) - 1) / DEVESIZE(1); | |
1266 | 1268 | #ifdef DEVICE2_ESIZE |
1267 | 1269 | DEVESIZE (1) = DEVICE2_ESIZE; |
1268 | 1270 | #endif |
... | ... | @@ -1320,8 +1322,8 @@ |
1320 | 1322 | DEVESIZE(i) = ENVSIZE(i); |
1321 | 1323 | |
1322 | 1324 | if (rc < 5) |
1323 | - /* Default - 1 sector */ | |
1324 | - ENVSECTORS (i) = 1; | |
1325 | + /* Assume enough env sectors to cover the environment */ | |
1326 | + ENVSECTORS (i) = (ENVSIZE(i) + DEVESIZE(i) - 1) / DEVESIZE(i); | |
1325 | 1327 | |
1326 | 1328 | i++; |
1327 | 1329 | } |
tools/env/fw_env.config
1 | 1 | # Configuration file for fw_(printenv/setenv) utility. |
2 | 2 | # Up to two entries are valid, in this case the redundant |
3 | 3 | # environment sector is assumed present. |
4 | -# Notice, that the "Number of sectors" is ignored on NOR and SPI-dataflash. | |
4 | +# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash. | |
5 | 5 | # Futhermore, if the Flash sector size is ommitted, this value is assumed to |
6 | 6 | # be the same as the Environment size, which is valid for NOR and SPI-dataflash |
7 | 7 |