Skip to content
Snippets Groups Projects
Commit c1f51e0f authored by Marcin Niestroj's avatar Marcin Niestroj Committed by Heiko Schocher
Browse files

common: env_ubi: Clear environment buffer before reading


In case we have restarted u-boot there is a chance that environment
buffer contains old environment (from the previous boot). If UBI volume
is zero size, ubi_volume_read() doesn't modify the buffer and exits
successfully.

We need to clear buffer manually before reading it from UBI, so the
invalid CRC will cause setting default environment in case that the UBI
volume is zero size.

Signed-off-by: default avatarMarcin Niestroj <m.niestroj@grinn-global.com>
parent 6b3943f1
No related branches found
No related tags found
No related merge requests found
...@@ -115,6 +115,17 @@ void env_relocate_spec(void) ...@@ -115,6 +115,17 @@ void env_relocate_spec(void)
int crc1_ok = 0, crc2_ok = 0; int crc1_ok = 0, crc2_ok = 0;
env_t *ep, *tmp_env1, *tmp_env2; env_t *ep, *tmp_env1, *tmp_env2;
/*
* In case we have restarted u-boot there is a chance that buffer
* contains old environment (from the previous boot).
* If UBI volume is zero size, ubi_volume_read() doesn't modify the
* buffer.
* We need to clear buffer manually here, so the invalid CRC will
* cause setting default environment as expected.
*/
memset(env1_buf, 0x0, CONFIG_ENV_SIZE);
memset(env2_buf, 0x0, CONFIG_ENV_SIZE);
tmp_env1 = (env_t *)env1_buf; tmp_env1 = (env_t *)env1_buf;
tmp_env2 = (env_t *)env2_buf; tmp_env2 = (env_t *)env2_buf;
...@@ -174,6 +185,16 @@ void env_relocate_spec(void) ...@@ -174,6 +185,16 @@ void env_relocate_spec(void)
{ {
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
/*
* In case we have restarted u-boot there is a chance that buffer
* contains old environment (from the previous boot).
* If UBI volume is zero size, ubi_volume_read() doesn't modify the
* buffer.
* We need to clear buffer manually here, so the invalid CRC will
* cause setting default environment as expected.
*/
memset(buf, 0x0, CONFIG_ENV_SIZE);
if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) {
printf("\n** Cannot find mtd partition \"%s\"\n", printf("\n** Cannot find mtd partition \"%s\"\n",
CONFIG_ENV_UBI_PART); CONFIG_ENV_UBI_PART);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment