2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Andreas Heppel <aheppel@sysgo.de>
8 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 #include <environment.h>
30 #include <cmd_nvedit.h>
31 #include <linux/stddef.h>
34 #ifdef CONFIG_SHOW_BOOT_PROGRESS
35 # include <status_led.h>
36 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
38 # define SHOW_BOOT_PROGRESS(arg)
41 #ifdef CONFIG_AMIGAONEG3SE
42 extern void enable_nvram(void);
43 extern void disable_nvram(void);
48 #define DEBUGF(fmt,args...) printf(fmt ,##args)
50 #define DEBUGF(fmt,args...)
53 extern env_t *env_ptr;
55 extern void env_relocate_spec (void);
56 extern uchar env_get_char_spec(int);
58 static uchar env_get_char_init (int index);
59 uchar (*env_get_char)(int) = env_get_char_init;
61 /************************************************************************
62 * Default settings to be used when no valid environment is found
65 #define MK_STR(x) XMK_STR(x)
67 uchar default_environment[] = {
68 #ifdef CONFIG_BOOTARGS
69 "bootargs=" CONFIG_BOOTARGS "\0"
71 #ifdef CONFIG_BOOTCOMMAND
72 "bootcmd=" CONFIG_BOOTCOMMAND "\0"
74 #ifdef CONFIG_RAMBOOTCOMMAND
75 "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
77 #ifdef CONFIG_NFSBOOTCOMMAND
78 "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
80 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
81 "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
83 #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
84 "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
86 #ifdef CONFIG_LOADS_ECHO
87 "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
90 "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
92 #ifdef CONFIG_ETH1ADDR
93 "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
95 #ifdef CONFIG_ETH2ADDR
96 "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
99 "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
101 #ifdef CONFIG_SERVERIP
102 "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
105 "autoload=" CFG_AUTOLOAD "\0"
107 #ifdef CONFIG_PREBOOT
108 "preboot=" CONFIG_PREBOOT "\0"
110 #ifdef CONFIG_ROOTPATH
111 "rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
113 #ifdef CONFIG_GATEWAYIP
114 "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
116 #ifdef CONFIG_NETMASK
117 "netmask=" MK_STR(CONFIG_NETMASK) "\0"
119 #ifdef CONFIG_HOSTNAME
120 "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
122 #ifdef CONFIG_BOOTFILE
123 "bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
125 #ifdef CONFIG_LOADADDR
126 "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
128 #ifdef CONFIG_CLOCKS_IN_MHZ
131 #ifdef CONFIG_EXTRA_ENV_SETTINGS
132 CONFIG_EXTRA_ENV_SETTINGS
138 void env_crc_update (void)
140 env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
143 static uchar env_get_char_init (int index)
145 DECLARE_GLOBAL_DATA_PTR;
148 /* if crc was bad, use the default environment */
151 c = env_get_char_spec(index);
153 c = default_environment[index];
159 uchar env_get_char_memory (int index)
161 DECLARE_GLOBAL_DATA_PTR;
164 return ( *((uchar *)(gd->env_addr + index)) );
166 return ( default_environment[index] );
170 uchar *env_get_addr (int index)
172 DECLARE_GLOBAL_DATA_PTR;
175 return ( ((uchar *)(gd->env_addr + index)) );
177 return (&default_environment[index]);
181 void env_relocate (void)
183 DECLARE_GLOBAL_DATA_PTR;
185 DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
188 #ifdef CONFIG_AMIGAONEG3SE
192 #ifdef ENV_IS_EMBEDDED
194 * The environment buffer is embedded with the text segment,
195 * just relocate the environment pointer
197 env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off);
198 DEBUGF ("%s[%d] embedded ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
201 * We must allocate a buffer for the environment
203 env_ptr = (env_t *)malloc (CFG_ENV_SIZE);
204 DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
208 * After relocation to RAM, we can always use the "memory" functions
210 env_get_char = env_get_char_memory;
212 if (gd->env_valid == 0) {
213 #if defined(CONFIG_GTH) || defined(CFG_ENV_IS_NOWHERE) /* Environment not changable */
214 puts ("Using default environment\n\n");
216 puts ("*** Warning - bad CRC, using default environment\n\n");
217 SHOW_BOOT_PROGRESS (-1);
220 if (sizeof(default_environment) > ENV_SIZE)
222 puts ("*** Error - default environment is too large\n\n");
226 memset (env_ptr, 0, sizeof(env_t));
227 memcpy (env_ptr->data,
229 sizeof(default_environment));
230 #ifdef CFG_REDUNDAND_ENVIRONMENT
231 env_ptr->flags = 0xFF;
237 env_relocate_spec ();
239 gd->env_addr = (ulong)&(env_ptr->data);
241 #ifdef CONFIG_AMIGAONEG3SE