]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - env/nand.c
imx: hab: Check if CSF contains deprecated commands
[people/ms/u-boot.git] / env / nand.c
index 07edabab796b0d6e6ff418b3b6f93c9fe064fb23..904f1c40d6229c877d27b543fd03e4b1d022ca2a 100644 (file)
@@ -40,8 +40,6 @@
 #define CONFIG_ENV_RANGE       CONFIG_ENV_SIZE
 #endif
 
-char *env_name_spec = "NAND";
-
 #if defined(ENV_IS_EMBEDDED)
 env_t *env_ptr = &environment;
 #elif defined(CONFIG_NAND_ENV_DST)
@@ -64,7 +62,7 @@ DECLARE_GLOBAL_DATA_PTR;
  * This way the SPL loads not only the U-Boot image from NAND but
  * also the environment.
  */
-int env_init(void)
+static int env_nand_init(void)
 {
 #if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST)
        int crc1_ok = 0, crc2_ok = 0;
@@ -81,7 +79,7 @@ int env_init(void)
 
        if (!crc1_ok && !crc2_ok) {
                gd->env_addr    = 0;
-               gd->env_valid   = 0;
+               gd->env_valid   = ENV_INVALID;
 
                return 0;
        } else if (crc1_ok && !crc2_ok) {
@@ -185,7 +183,7 @@ static int erase_and_write_env(const struct nand_env_location *location,
        return ret;
 }
 
-int saveenv(void)
+static int env_nand_save(void)
 {
        int     ret = 0;
        ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
@@ -304,7 +302,7 @@ int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result)
        }
 
        if (oob_buf[0] == ENV_OOB_MARKER) {
-               *result = oob_buf[1] * mtd->erasesize;
+               *result = ovoid ob_buf[1] * mtd->erasesize;
        } else if (oob_buf[0] == ENV_OOB_MARKER_OLD) {
                *result = oob_buf[1];
        } else {
@@ -317,46 +315,35 @@ int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result)
 #endif
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-void env_relocate_spec(void)
+static int env_nand_load(void)
 {
-#if !defined(ENV_IS_EMBEDDED)
-       int read1_fail = 0, read2_fail = 0;
+#if defined(ENV_IS_EMBEDDED)
+       return 0;
+#else
+       int read1_fail, read2_fail;
        env_t *tmp_env1, *tmp_env2;
+       int ret = 0;
 
        tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE);
        tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE);
        if (tmp_env1 == NULL || tmp_env2 == NULL) {
                puts("Can't allocate buffers for environment\n");
                set_default_env("!malloc() failed");
+               ret = -EIO;
                goto done;
        }
 
        read1_fail = readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1);
        read2_fail = readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2);
 
-       if (read1_fail && read2_fail)
-               puts("*** Error - No Valid Environment Area found\n");
-       else if (read1_fail || read2_fail)
-               puts("*** Warning - some problems detected "
-                    "reading environment; recovered successfully\n");
-
-       if (read1_fail && read2_fail) {
-               set_default_env("!bad env area");
-               goto done;
-       } else if (!read1_fail && read2_fail) {
-               gd->env_valid = ENV_VALID;
-               env_import((char *)tmp_env1, 1);
-       } else if (read1_fail && !read2_fail) {
-               gd->env_valid = ENV_REDUND;
-               env_import((char *)tmp_env2, 1);
-       } else {
-               env_import_redund((char *)tmp_env1, (char *)tmp_env2);
-       }
+       ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
+                               read2_fail);
 
 done:
        free(tmp_env1);
        free(tmp_env2);
 
+       return ret;
 #endif /* ! ENV_IS_EMBEDDED */
 }
 #else /* ! CONFIG_ENV_OFFSET_REDUND */
@@ -365,7 +352,7 @@ done:
  * device i.e., nand_dev_desc + 0. This is also the behaviour using
  * the new NAND code.
  */
-void env_relocate_spec(void)
+static int env_nand_load(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
        int ret;
@@ -388,19 +375,22 @@ void env_relocate_spec(void)
        ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
        if (ret) {
                set_default_env("!readenv() failed");
-               return;
+               return -EIO;
        }
 
-       env_import(buf, 1);
+       return env_import(buf, 1);
 #endif /* ! ENV_IS_EMBEDDED */
+
+       return 0;
 }
 #endif /* CONFIG_ENV_OFFSET_REDUND */
 
 U_BOOT_ENV_LOCATION(nand) = {
        .location       = ENVL_NAND,
-       .load           = env_relocate_spec,
+       ENV_NAME("NAND")
+       .load           = env_nand_load,
 #if defined(CMD_SAVEENV)
-       .save           = env_save_ptr(saveenv),
+       .save           = env_save_ptr(env_nand_save),
 #endif
-       .init           = env_init,
+       .init           = env_nand_init,
 };