]> git.sur5r.net Git - u-boot/blobdiff - env/common.c
bootm.c: Correct the flush_len used in bootm_load_os()
[u-boot] / env / common.c
index 363ba6feadfed905e34ddfe2a444a4da966c2d1b..dc8a14f519059f3d44c5d1f30609675be8a781a6 100644 (file)
@@ -1,11 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000-2010
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
  * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  * Andreas Heppel <aheppel@sysgo.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -138,7 +137,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 +146,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) ==
@@ -208,6 +226,7 @@ void env_relocate(void)
 {
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
        env_reloc();
+       env_fix_drivers();
        env_htab.change_ok += gd->reloc_off;
 #endif
        if (gd->env_valid == ENV_INVALID) {