]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/env_nand.c
bootm: Avoid 256-byte overflow in fixup_silent_linux()
[karo-tx-uboot.git] / common / env_nand.c
index 3cb75c89624d087019dacfcc6f21a1f4e7e0a3ad..b745822be781fe3e4f14c1682032a2448e4be4f7 100644 (file)
@@ -66,11 +66,6 @@ env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-uchar env_get_char_spec(int index)
-{
-       return *((uchar *)(gd->env_addr + index));
-}
-
 /*
  * This is called before nand_init() so we can't read NAND to
  * validate env data.
@@ -191,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;
@@ -231,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;
@@ -243,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;
        }
@@ -286,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;
@@ -336,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;
 
@@ -347,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");
@@ -403,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);