wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2010 |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 6 | * Andreas Heppel <aheppel@sysgo.de> |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 7 | * |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
| 29 | #include <environment.h> |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 30 | #include <linux/stddef.h> |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 31 | #include <search.h> |
| 32 | #include <errno.h> |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 33 | #include <malloc.h> |
| 34 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 37 | /************************************************************************ |
| 38 | * Default settings to be used when no valid environment is found |
| 39 | */ |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 40 | |
Mike Frysinger | 147c716 | 2011-04-23 23:43:21 +0000 | [diff] [blame] | 41 | const uchar default_environment[] = { |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 42 | #ifdef CONFIG_BOOTARGS |
| 43 | "bootargs=" CONFIG_BOOTARGS "\0" |
| 44 | #endif |
| 45 | #ifdef CONFIG_BOOTCOMMAND |
| 46 | "bootcmd=" CONFIG_BOOTCOMMAND "\0" |
| 47 | #endif |
| 48 | #ifdef CONFIG_RAMBOOTCOMMAND |
| 49 | "ramboot=" CONFIG_RAMBOOTCOMMAND "\0" |
| 50 | #endif |
| 51 | #ifdef CONFIG_NFSBOOTCOMMAND |
| 52 | "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0" |
| 53 | #endif |
| 54 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 55 | "bootdelay=" __stringify(CONFIG_BOOTDELAY) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 56 | #endif |
| 57 | #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0) |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 58 | "baudrate=" __stringify(CONFIG_BAUDRATE) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 59 | #endif |
| 60 | #ifdef CONFIG_LOADS_ECHO |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 61 | "loads_echo=" __stringify(CONFIG_LOADS_ECHO) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 62 | #endif |
| 63 | #ifdef CONFIG_ETHADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 64 | "ethaddr=" __stringify(CONFIG_ETHADDR) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 65 | #endif |
| 66 | #ifdef CONFIG_ETH1ADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 67 | "eth1addr=" __stringify(CONFIG_ETH1ADDR) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 68 | #endif |
| 69 | #ifdef CONFIG_ETH2ADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 70 | "eth2addr=" __stringify(CONFIG_ETH2ADDR) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 71 | #endif |
wdenk | 6945979 | 2004-05-29 16:53:29 +0000 | [diff] [blame] | 72 | #ifdef CONFIG_ETH3ADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 73 | "eth3addr=" __stringify(CONFIG_ETH3ADDR) "\0" |
wdenk | 6945979 | 2004-05-29 16:53:29 +0000 | [diff] [blame] | 74 | #endif |
richardretanubun | c68a05f | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 75 | #ifdef CONFIG_ETH4ADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 76 | "eth4addr=" __stringify(CONFIG_ETH4ADDR) "\0" |
richardretanubun | c68a05f | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 77 | #endif |
| 78 | #ifdef CONFIG_ETH5ADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 79 | "eth5addr=" __stringify(CONFIG_ETH5ADDR) "\0" |
richardretanubun | c68a05f | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 80 | #endif |
Benoît Thébaudeau | 84209af | 2012-08-10 07:45:31 +0000 | [diff] [blame] | 81 | #ifdef CONFIG_ETHPRIME |
| 82 | "ethprime=" CONFIG_ETHPRIME "\0" |
| 83 | #endif |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 84 | #ifdef CONFIG_IPADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 85 | "ipaddr=" __stringify(CONFIG_IPADDR) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 86 | #endif |
| 87 | #ifdef CONFIG_SERVERIP |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 88 | "serverip=" __stringify(CONFIG_SERVERIP) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 89 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_SYS_AUTOLOAD |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 91 | "autoload=" CONFIG_SYS_AUTOLOAD "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 92 | #endif |
| 93 | #ifdef CONFIG_PREBOOT |
| 94 | "preboot=" CONFIG_PREBOOT "\0" |
| 95 | #endif |
| 96 | #ifdef CONFIG_ROOTPATH |
Joe Hershberger | 8b3637c | 2011-10-13 13:03:47 +0000 | [diff] [blame] | 97 | "rootpath=" CONFIG_ROOTPATH "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 98 | #endif |
| 99 | #ifdef CONFIG_GATEWAYIP |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 100 | "gatewayip=" __stringify(CONFIG_GATEWAYIP) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 101 | #endif |
| 102 | #ifdef CONFIG_NETMASK |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 103 | "netmask=" __stringify(CONFIG_NETMASK) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 104 | #endif |
| 105 | #ifdef CONFIG_HOSTNAME |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 106 | "hostname=" __stringify(CONFIG_HOSTNAME) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 107 | #endif |
| 108 | #ifdef CONFIG_BOOTFILE |
Joe Hershberger | b3f44c2 | 2011-10-13 13:03:48 +0000 | [diff] [blame] | 109 | "bootfile=" CONFIG_BOOTFILE "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 110 | #endif |
| 111 | #ifdef CONFIG_LOADADDR |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 112 | "loadaddr=" __stringify(CONFIG_LOADADDR) "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 113 | #endif |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 114 | #ifdef CONFIG_CLOCKS_IN_MHZ |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 115 | "clocks_in_mhz=1\0" |
| 116 | #endif |
stroese | ad10dd9 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 117 | #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0) |
Marek Vasut | 5368c55 | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 118 | "pcidelay=" __stringify(CONFIG_PCI_BOOTDELAY)"\0" |
stroese | ad10dd9 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 119 | #endif |
Stephen Warren | 5e724ca | 2012-05-22 09:21:54 +0000 | [diff] [blame] | 120 | #ifdef CONFIG_ENV_VARS_UBOOT_CONFIG |
| 121 | "arch=" CONFIG_SYS_ARCH "\0" |
| 122 | "cpu=" CONFIG_SYS_CPU "\0" |
| 123 | "board=" CONFIG_SYS_BOARD "\0" |
| 124 | #ifdef CONFIG_SYS_VENDOR |
| 125 | "vendor=" CONFIG_SYS_VENDOR "\0" |
| 126 | #endif |
| 127 | #ifdef CONFIG_SYS_SOC |
| 128 | "soc=" CONFIG_SYS_SOC "\0" |
| 129 | #endif |
| 130 | #endif |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 131 | #ifdef CONFIG_EXTRA_ENV_SETTINGS |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 132 | CONFIG_EXTRA_ENV_SETTINGS |
| 133 | #endif |
| 134 | "\0" |
| 135 | }; |
| 136 | |
Gerlando Falauto | c598359 | 2012-08-24 00:11:39 +0000 | [diff] [blame] | 137 | struct hsearch_data env_htab = { |
| 138 | .apply = env_check_apply, |
| 139 | }; |
Mike Frysinger | 2eb1573 | 2010-12-08 06:26:04 -0500 | [diff] [blame] | 140 | |
Igor Grinberg | bf95df4 | 2011-12-26 03:33:10 +0000 | [diff] [blame] | 141 | static uchar __env_get_char_spec(int index) |
| 142 | { |
| 143 | return *((uchar *)(gd->env_addr + index)); |
| 144 | } |
| 145 | uchar env_get_char_spec(int) |
| 146 | __attribute__((weak, alias("__env_get_char_spec"))); |
| 147 | |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 148 | static uchar env_get_char_init(int index) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 149 | { |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 150 | /* if crc was bad, use the default environment */ |
| 151 | if (gd->env_valid) |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 152 | return env_get_char_spec(index); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 153 | else |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 154 | return default_environment[index]; |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 157 | uchar env_get_char_memory(int index) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 158 | { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 159 | return *env_get_addr(index); |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 162 | uchar env_get_char(int index) |
Joakim Tjernlund | b502611 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 163 | { |
Joakim Tjernlund | b502611 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 164 | /* if relocated to RAM */ |
| 165 | if (gd->flags & GD_FLG_RELOC) |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 166 | return env_get_char_memory(index); |
Joakim Tjernlund | b502611 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 167 | else |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 168 | return env_get_char_init(index); |
Joakim Tjernlund | b502611 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 171 | const uchar *env_get_addr(int index) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 172 | { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 173 | if (gd->env_valid) |
| 174 | return (uchar *)(gd->env_addr + index); |
| 175 | else |
| 176 | return &default_environment[index]; |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 179 | void set_default_env(const char *s) |
Harald Welte | 5bb12db | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 180 | { |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 181 | /* |
| 182 | * By default, do not apply changes as they will eventually |
| 183 | * be applied by someone else |
| 184 | */ |
| 185 | int do_apply = 0; |
Harald Welte | 5bb12db | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 186 | if (sizeof(default_environment) > ENV_SIZE) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 187 | puts("*** Error - default environment is too large\n\n"); |
Harald Welte | 5bb12db | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 191 | if (s) { |
| 192 | if (*s == '!') { |
| 193 | printf("*** Warning - %s, " |
| 194 | "using default environment\n\n", |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 195 | s + 1); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 196 | } else { |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 197 | /* |
| 198 | * This set_to_default was explicitly asked for |
| 199 | * by the user, as opposed to being a recovery |
| 200 | * mechanism. Therefore we check every single |
| 201 | * variable and apply changes to the system |
| 202 | * right away (e.g. baudrate, console). |
| 203 | */ |
| 204 | do_apply = 1; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 205 | puts(s); |
| 206 | } |
| 207 | } else { |
| 208 | puts("Using default environment\n\n"); |
| 209 | } |
| 210 | |
Mike Frysinger | 2eb1573 | 2010-12-08 06:26:04 -0500 | [diff] [blame] | 211 | if (himport_r(&env_htab, (char *)default_environment, |
Gerlando Falauto | 348b1f1 | 2012-08-24 00:11:38 +0000 | [diff] [blame] | 212 | sizeof(default_environment), '\0', 0, |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 213 | 0, NULL, do_apply) == 0) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 214 | error("Environment import failed: errno = %d\n", errno); |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 215 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 216 | gd->flags |= GD_FLG_ENV_READY; |
| 217 | } |
| 218 | |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 219 | |
| 220 | /* [re]set individual variables to their value in the default environment */ |
| 221 | int set_default_vars(int nvars, char * const vars[]) |
| 222 | { |
| 223 | /* |
| 224 | * Special use-case: import from default environment |
| 225 | * (and use \0 as a separator) |
| 226 | */ |
| 227 | return himport_r(&env_htab, (const char *)default_environment, |
| 228 | sizeof(default_environment), '\0', H_NOCLEAR, |
| 229 | nvars, vars, 1 /* do_apply */); |
| 230 | } |
| 231 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 232 | #ifndef CONFIG_SPL_BUILD |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 233 | /* |
| 234 | * Check if CRC is valid and (if yes) import the environment. |
| 235 | * Note that "buf" may or may not be aligned. |
| 236 | */ |
| 237 | int env_import(const char *buf, int check) |
| 238 | { |
| 239 | env_t *ep = (env_t *)buf; |
| 240 | |
| 241 | if (check) { |
| 242 | uint32_t crc; |
| 243 | |
| 244 | memcpy(&crc, &ep->crc, sizeof(crc)); |
| 245 | |
| 246 | if (crc32(0, ep->data, ENV_SIZE) != crc) { |
| 247 | set_default_env("!bad CRC"); |
| 248 | return 0; |
| 249 | } |
| 250 | } |
| 251 | |
Gerlando Falauto | 348b1f1 | 2012-08-24 00:11:38 +0000 | [diff] [blame] | 252 | if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, |
Gerlando Falauto | c598359 | 2012-08-24 00:11:39 +0000 | [diff] [blame] | 253 | 0, NULL, 0 /* do_apply */)) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 254 | gd->flags |= GD_FLG_ENV_READY; |
| 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | error("Cannot import environment: errno = %d\n", errno); |
| 259 | |
| 260 | set_default_env("!import failed"); |
| 261 | |
| 262 | return 0; |
Harald Welte | 5bb12db | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 263 | } |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 264 | #endif |
Harald Welte | 5bb12db | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 265 | |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 266 | void env_relocate(void) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 267 | { |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 268 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Heiko Schocher | 60f7da1 | 2010-10-05 14:17:00 +0200 | [diff] [blame] | 269 | env_reloc(); |
| 270 | #endif |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 271 | if (gd->env_valid == 0) { |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 272 | #if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD) |
| 273 | /* Environment not changable */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 274 | set_default_env(NULL); |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 275 | #else |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 276 | bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 277 | set_default_env("!bad CRC"); |
Lei Wen | d259079 | 2010-10-10 12:36:40 +0800 | [diff] [blame] | 278 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 279 | } else { |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 280 | env_relocate_spec(); |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 281 | } |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 282 | } |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 283 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 284 | #if defined(CONFIG_AUTO_COMPLETE) && !defined(CONFIG_SPL_BUILD) |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 285 | int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf) |
| 286 | { |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 287 | ENTRY *match; |
| 288 | int found, idx; |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 289 | |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 290 | idx = 0; |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 291 | found = 0; |
| 292 | cmdv[0] = NULL; |
| 293 | |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 294 | while ((idx = hmatch_r(var, idx, &match, &env_htab))) { |
| 295 | int vallen = strlen(match->key) + 1; |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 296 | |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 297 | if (found >= maxv - 2 || bufsz < vallen) |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 298 | break; |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 299 | |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 300 | cmdv[found++] = buf; |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 301 | memcpy(buf, match->key, vallen); |
| 302 | buf += vallen; |
| 303 | bufsz -= vallen; |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Mike Frysinger | 560d424 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 306 | qsort(cmdv, found, sizeof(cmdv[0]), strcmp_compar); |
| 307 | |
| 308 | if (idx) |
| 309 | cmdv[found++] = "..."; |
Igor Grinberg | 27aafe9 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 310 | |
wdenk | 04a85b3 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 311 | cmdv[found] = NULL; |
| 312 | return found; |
| 313 | } |
| 314 | #endif |