]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/env_nand.c
karo: tx28: change default loadaddr for TX28S
[karo-tx-uboot.git] / common / env_nand.c
index 382e8aec5e2554627801b7b93188538d9c38ecef..9ae28ecbe7aa3dbc80bffc21cf1e553894a6b0ec 100644 (file)
  * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  * Andreas Heppel <aheppel@sysgo.de>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+ 
  */
 
 #include <common.h>
@@ -60,8 +44,6 @@ char *env_name_spec = "NAND";
 env_t *env_ptr = &environment;
 #elif defined(CONFIG_NAND_ENV_DST)
 env_t *env_ptr = (env_t *)CONFIG_NAND_ENV_DST;
-#else /* ! ENV_IS_EMBEDDED */
-env_t *env_ptr;
 #endif /* ENV_IS_EMBEDDED */
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -281,7 +263,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;
@@ -352,8 +335,10 @@ void env_relocate_spec(void)
                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");
@@ -376,7 +361,9 @@ void env_relocate_spec(void)
                        gd->env_valid = 1;
        }
 
+#ifdef CONFIG_NAND_ENV_DST
        free(env_ptr);
+#endif
 
        if (gd->env_valid == 1)
                ep = tmp_env1;