]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/env_nand.c
karo: tx6: use _LP voltage settings for low power mode voltages
[karo-tx-uboot.git] / common / env_nand.c
index 8cc2055eb366c6b5bf0d5d3f0dd6df589462f454..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,12 +44,8 @@ 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 */
 
-DEFINE_CACHE_ALIGN_BUFFER(char, env_buf, CONFIG_ENV_SIZE);
-
 DECLARE_GLOBAL_DATA_PTR;
 
 /*
@@ -175,7 +155,7 @@ static unsigned char env_flags;
 
 int saveenv(void)
 {
-       env_t   *env_new = (env_t *)env_buf;
+       env_t   env_new;
        ssize_t len;
        char    *res;
        int     ret = 0;
@@ -187,14 +167,14 @@ int saveenv(void)
        if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
                return 1;
 
-       res = (char *)env_new->data;
+       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->flags  = ++env_flags; /* increase the serial */
+       env_new.crc     = crc32(0, env_new.data, ENV_SIZE);
+       env_new.flags   = ++env_flags; /* increase the serial */
 
        if (gd->env_valid == 1) {
                puts("Erasing redundant NAND...\n");
@@ -203,7 +183,7 @@ int saveenv(void)
                        return 1;
 
                puts("Writing to redundant NAND... ");
-               ret = writeenv(CONFIG_ENV_OFFSET_REDUND, (u_char *)env_new);
+               ret = writeenv(CONFIG_ENV_OFFSET_REDUND, (u_char *)&env_new);
        } else {
                puts("Erasing NAND...\n");
                nand_erase_options.offset = CONFIG_ENV_OFFSET;
@@ -211,7 +191,7 @@ int saveenv(void)
                        return 1;
 
                puts("Writing to NAND... ");
-               ret = writeenv(CONFIG_ENV_OFFSET, (u_char *)env_new);
+               ret = writeenv(CONFIG_ENV_OFFSET, (u_char *)&env_new);
        }
        if (ret) {
                puts("FAILED!\n");
@@ -228,7 +208,7 @@ int saveenv(void)
 int saveenv(void)
 {
        int     ret = 0;
-       env_t   *env_new = (env_t *)env_buf;
+       ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
        ssize_t len;
        char    *res;
        nand_erase_options_t nand_erase_options;
@@ -240,7 +220,7 @@ int saveenv(void)
        if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)
                return 1;
 
-       res = (char *)env_new->data;
+       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);
@@ -283,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;
@@ -380,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;
@@ -406,6 +389,7 @@ void env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
        int ret;
+       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);
@@ -421,13 +405,13 @@ void env_relocate_spec(void)
        }
 #endif
 
-       ret = readenv(CONFIG_ENV_OFFSET, (u_char *)env_buf);
+       ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf);
        if (ret) {
                set_default_env("!readenv() failed");
                return;
        }
 
-       env_import(env_buf, 1);
+       env_import(buf, 1);
 #endif /* ! ENV_IS_EMBEDDED */
 }
 #endif /* CONFIG_ENV_OFFSET_REDUND */