]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/env_common.c
tricorder: update flash partitioning
[karo-tx-uboot.git] / common / env_common.c
index a960aa8033c3b5a41e717d8712b8550014244a05..c0bfc2f5db3b3efebb7c039747b54abc186c1acc 100644 (file)
@@ -5,23 +5,7 @@
  * (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>
@@ -40,7 +24,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #include <env_default.h>
 
 struct hsearch_data env_htab = {
-       .change_ok = env_change_ok,
+       .change_ok = env_flags_validate,
 };
 
 static uchar __env_get_char_spec(int index)
@@ -81,6 +65,38 @@ const uchar *env_get_addr(int index)
                return &default_environment[index];
 }
 
+/*
+ * Read an environment variable as a boolean
+ * Return -1 if variable does not exist (default to true)
+ */
+int getenv_yesno(const char *var)
+{
+       char *s = getenv(var);
+
+       if (s == NULL)
+               return -1;
+       return (*s == '1' || *s == 'y' || *s == 'Y' || *s == 't' || *s == 'T') ?
+               1 : 0;
+}
+
+/*
+ * Look up the variable from the default environment
+ */
+char *getenv_default(const char *name)
+{
+       char *ret_val;
+       unsigned long really_valid = gd->env_valid;
+       unsigned long real_gd_flags = gd->flags;
+
+       /* Pretend that the image is bad. */
+       gd->flags &= ~GD_FLG_ENV_READY;
+       gd->env_valid = 0;
+       ret_val = getenv(name);
+       gd->env_valid = really_valid;
+       gd->flags = real_gd_flags;
+       return ret_val;
+}
+
 void set_default_env(const char *s)
 {
        int flags = 0;
@@ -124,7 +140,6 @@ int set_default_vars(int nvars, char * const vars[])
                                H_NOCLEAR | H_INTERACTIVE, nvars, vars);
 }
 
-#ifndef CONFIG_SPL_BUILD
 /*
  * Check if CRC is valid and (if yes) import the environment.
  * Note that "buf" may or may not be aligned.
@@ -156,7 +171,6 @@ int env_import(const char *buf, int check)
 
        return 0;
 }
-#endif
 
 void env_relocate(void)
 {