]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/env_nand.c
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / common / env_nand.c
index e8daec9712bdc8d8df2f2989d7fb2c082de70c34..b745822be781fe3e4f14c1682032a2448e4be4f7 100644 (file)
@@ -186,7 +186,7 @@ int saveenv(void)
                return 1;
 
        res = (char *)&env_new.data;
-       len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+       len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
        if (len < 0) {
                error("Cannot export environment: errno = %d\n", errno);
                return 1;
@@ -226,7 +226,7 @@ int saveenv(void)
 int saveenv(void)
 {
        int     ret = 0;
-       env_t   env_new;
+       ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
        ssize_t len;
        char    *res;
        nand_erase_options_t nand_erase_options;
@@ -238,20 +238,20 @@ int saveenv(void)
        if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
                return 1;
 
-       res = (char *)&env_new.data;
-       len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
+       res = (char *)&env_new->data;
+       len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
        if (len < 0) {
                error("Cannot export environment: errno = %d\n", errno);
                return 1;
        }
-       env_new.crc = crc32(0, env_new.data, ENV_SIZE);
+       env_new->crc = crc32(0, env_new->data, ENV_SIZE);
 
        puts("Erasing Nand...\n");
        if (nand_erase_opts(&nand_info[0], &nand_erase_options))
                return 1;
 
        puts("Writing to Nand... ");
-       if (writeenv(CONFIG_ENV_OFFSET, (u_char *)&env_new)) {
+       if (writeenv(CONFIG_ENV_OFFSET, (u_char *)env_new)) {
                puts("FAILED!\n");
                return 1;
        }
@@ -281,7 +281,8 @@ int readenv(size_t offset, u_char *buf)
                } else {
                        char_ptr = &buf[amount_loaded];
                        if (nand_read_skip_bad(&nand_info[0], offset,
-                                              &len, char_ptr))
+                                              &len, NULL,
+                                              nand_info[0].size, char_ptr))
                                return 1;
 
                        offset += blocksize;
@@ -331,6 +332,7 @@ int get_nand_env_oob(nand_info_t *nand, unsigned long *result)
 void env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
+       int read1_fail = 0, read2_fail = 0;
        int crc1_ok = 0, crc2_ok = 0;
        env_t *ep, *tmp_env1, *tmp_env2;
 
@@ -342,14 +344,19 @@ void env_relocate_spec(void)
                goto done;
        }
 
-       if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1))
-               puts("No Valid Environment Area found\n");
+       read1_fail = readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1);
+       read2_fail = readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2);
 
-       if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2))
-               puts("No Valid Redundant Environment Area found\n");
+       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");
 
-       crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc;
-       crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc;
+       crc1_ok = !read1_fail &&
+               (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
+       crc2_ok = !read2_fail &&
+               (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
 
        if (!crc1_ok && !crc2_ok) {
                set_default_env("!bad CRC");
@@ -398,7 +405,7 @@ void env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
        int ret;
-       char buf[CONFIG_ENV_SIZE];
+       ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
 
 #if defined(CONFIG_ENV_OFFSET_OOB)
        ret = get_nand_env_oob(&nand_info[0], &nand_env_oob_offset);