summaryrefslogtreecommitdiff
path: root/env/common.c
diff options
context:
space:
mode:
authorSimon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>2018-01-31 14:47:11 +0100
committerTom Rini <trini@konsulko.com>2018-02-01 08:05:49 -0500
commit31f044bd91df58bed6bb8cfadfc187eedac1442e (patch)
tree6ec2b974d9b6c14666e9b743d5078a6f5b0ab050 /env/common.c
parent42a1820bbcc7dfedcf625b88a1013c11e9ef6709 (diff)
downloadu-boot-31f044bd91df58bed6bb8cfadfc187eedac1442e.tar.gz
u-boot-31f044bd91df58bed6bb8cfadfc187eedac1442e.tar.bz2
u-boot-31f044bd91df58bed6bb8cfadfc187eedac1442e.zip
env: move more common code to env_import_redund
There is more common code in mmc, nand and ubi env drivers that can be shared by moving to env_import_redund. For this, a status/error value whether the buffers were loaded are passed as additional parameters to env_import_redund. Ideally, these are already returned to the env driver by the storage driver. This is the case for mmc, nand and ubi, so for this change, code deduplicated. Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Diffstat (limited to 'env/common.c')
-rw-r--r--env/common.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/env/common.c b/env/common.c
index 363ba6fead..f21ff70096 100644
--- a/env/common.c
+++ b/env/common.c
@@ -138,7 +138,8 @@ int env_import(const char *buf, int check)
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
static unsigned char env_flags;
-int env_import_redund(const char *buf1, const char *buf2)
+int env_import_redund(const char *buf1, int buf1_read_fail,
+ const char *buf2, int buf2_read_fail)
{
int crc1_ok, crc2_ok;
env_t *ep, *tmp_env1, *tmp_env2;
@@ -146,6 +147,24 @@ int env_import_redund(const char *buf1, const char *buf2)
tmp_env1 = (env_t *)buf1;
tmp_env2 = (env_t *)buf2;
+ if (buf1_read_fail && buf2_read_fail) {
+ puts("*** Error - No Valid Environment Area found\n");
+ } else if (buf1_read_fail || buf2_read_fail) {
+ puts("*** Warning - some problems detected ");
+ puts("reading environment; recovered successfully\n");
+ }
+
+ if (buf1_read_fail && buf2_read_fail) {
+ set_default_env("!bad env area");
+ return -EIO;
+ } else if (!buf1_read_fail && buf2_read_fail) {
+ gd->env_valid = ENV_VALID;
+ return env_import((char *)tmp_env1, 1);
+ } else if (buf1_read_fail && !buf2_read_fail) {
+ gd->env_valid = ENV_REDUND;
+ return env_import((char *)tmp_env2, 1);
+ }
+
crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) ==
tmp_env1->crc;
crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) ==