diff options
author | Andreas Fenkart <afenkart@gmail.com> | 2017-04-08 09:59:34 (GMT) |
---|---|---|
committer | Jagan Teki <jagan@openedev.com> | 2017-05-03 05:48:20 (GMT) |
commit | 0b2e5bbe6a4f3d25522675198b8beb0093a2e750 (patch) | |
tree | 468e8a8016ef82a14e2cf55da53a67049648ad49 /common/env_sf.c | |
parent | c041c60c6c5c1eafcff21eec76e16ee958a7506e (diff) | |
download | u-boot-0b2e5bbe6a4f3d25522675198b8beb0093a2e750.tar.xz |
env_sf: use DIV_ROUND_UP to calculate number of sectors to erase
simpler to read
Signed-off-by: Andreas Fenkart <afenkart@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jagan@openedev.com>
Tested-by: Jagan Teki <jagan@openedev.com>
Diffstat (limited to 'common/env_sf.c')
-rw-r--r-- | common/env_sf.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/common/env_sf.c b/common/env_sf.c index 6a1583e..9944602 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -80,7 +80,7 @@ int saveenv(void) { env_t env_new; char *saved_buffer = NULL, flag = OBSOLETE_FLAG; - u32 saved_size, saved_offset, sector = 1; + u32 saved_size, saved_offset, sector; int ret; ret = setup_flash_device(); @@ -115,11 +115,7 @@ int saveenv(void) goto done; } - if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) { - sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE; - if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE) - sector++; - } + sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE); puts("Erasing SPI flash..."); ret = spi_flash_erase(env_flash, env_new_offset, @@ -245,7 +241,7 @@ out: #else int saveenv(void) { - u32 saved_size, saved_offset, sector = 1; + u32 saved_size, saved_offset, sector; char *saved_buffer = NULL; int ret = 1; env_t env_new; @@ -268,16 +264,12 @@ int saveenv(void) goto done; } - if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) { - sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE; - if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE) - sector++; - } - ret = env_export(&env_new); if (ret) goto done; + sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE); + puts("Erasing SPI flash..."); ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET, sector * CONFIG_ENV_SECT_SIZE); |