summaryrefslogtreecommitdiff
path: root/env
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2019-01-26 22:47:55 -0500
committerTom Rini <trini@konsulko.com>2019-01-26 22:47:55 -0500
commit0da90255083681a02b24528f80da9d4062ff634a (patch)
tree3046fb2c4824adaf891d0356e024da0dd0b2398f /env
parent87f78478a4a1bf574db0b0e575ca37cf91fb187c (diff)
parent320194ae35801811bd7754f23ac04bd841d25aa3 (diff)
downloadu-boot-0da90255083681a02b24528f80da9d4062ff634a.tar.gz
Merge branch '2019-01-25-master-imports'
- snapdragon 820c improvements - poplar updates - DFU + SPL cleanups - Improve the mediatek mmc driver - Other minor cleanups / improvements
Diffstat (limited to 'env')
-rw-r--r--env/common.c4
-rw-r--r--env/env.c25
2 files changed, 21 insertions, 8 deletions
diff --git a/env/common.c b/env/common.c
index d1a6a52860..324502ed82 100644
--- a/env/common.c
+++ b/env/common.c
@@ -115,7 +115,7 @@ int env_import(const char *buf, int check)
if (crc32(0, ep->data, ENV_SIZE) != crc) {
set_default_env("bad CRC", 0);
- return -EIO;
+ return -ENOMSG; /* needed for env_load() */
}
}
@@ -169,7 +169,7 @@ int env_import_redund(const char *buf1, int buf1_read_fail,
if (!crc1_ok && !crc2_ok) {
set_default_env("bad CRC", 0);
- return -EIO;
+ return -ENOMSG; /* needed for env_load() */
} else if (crc1_ok && !crc2_ok) {
gd->env_valid = ENV_VALID;
} else if (!crc1_ok && crc2_ok) {
diff --git a/env/env.c b/env/env.c
index 003509d342..4b417b90a2 100644
--- a/env/env.c
+++ b/env/env.c
@@ -177,6 +177,7 @@ int env_get_char(int index)
int env_load(void)
{
struct env_driver *drv;
+ int best_prio = -1;
int prio;
for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) {
@@ -195,20 +196,32 @@ int env_load(void)
* one message.
*/
ret = drv->load();
- if (ret) {
- debug("Failed (%d)\n", ret);
- } else {
+ if (!ret) {
printf("OK\n");
return 0;
+ } else if (ret == -ENOMSG) {
+ /* Handle "bad CRC" case */
+ if (best_prio == -1)
+ best_prio = prio;
+ } else {
+ debug("Failed (%d)\n", ret);
}
}
/*
* In case of invalid environment, we set the 'default' env location
- * to the highest priority. In this way, next calls to env_save()
- * will restore the environment at the right place.
+ * to the best choice, i.e.:
+ * 1. Environment location with bad CRC, if such location was found
+ * 2. Otherwise use the location with highest priority
+ *
+ * This way, next calls to env_save() will restore the environment
+ * at the right place.
*/
- env_get_location(ENVOP_LOAD, 0);
+ if (best_prio >= 0)
+ debug("Selecting environment with bad CRC\n");
+ else
+ best_prio = 0;
+ env_get_location(ENVOP_LOAD, best_prio);
return -ENODEV;
}