X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fenv_ubi.c;h=0ac2f65f0b24be57a7b2c123d3ef7a1faa8f0c6e;hb=beb71279d865deb77b2faa86d7d1d180df8339a0;hp=77bbfa6ef43caf051ba5166dd8045944e6e7a821;hpb=7ce1526ed2bf7a7499a843d38b30095fa2894659;p=oweals%2Fu-boot.git diff --git a/common/env_ubi.c b/common/env_ubi.c index 77bbfa6ef4..0ac2f65f0b 100644 --- a/common/env_ubi.c +++ b/common/env_ubi.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #undef crc32 @@ -114,6 +115,17 @@ void env_relocate_spec(void) int crc1_ok = 0, crc2_ok = 0; 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_env2 = (env_t *)env2_buf; @@ -173,6 +185,16 @@ void env_relocate_spec(void) { 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)) { printf("\n** Cannot find mtd partition \"%s\"\n", CONFIG_ENV_UBI_PART); @@ -180,8 +202,7 @@ void env_relocate_spec(void) return; } - if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)&buf, - CONFIG_ENV_SIZE)) { + if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) { printf("\n** Unable to read env from %s:%s **\n", CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME); set_default_env(NULL);