]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/env_nvram.c
sata: wait for device updating signature to host
[people/ms/u-boot.git] / common / env_nvram.c
CommitLineData
c609719b
WD
1/*
2 * (C) Copyright 2000-2002
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>
7
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/*
28 * 09-18-2001 Andreas Heppel, Sysgo RTS GmbH <aheppel@sysgo.de>
29 *
30 * It might not be possible in all cases to use 'memcpy()' to copy
31 * the environment to NVRAM, as the NVRAM might not be mapped into
32 * the memory space. (I.e. this is the case for the BAB750). In those
33 * cases it might be possible to access the NVRAM using a different
34 * method. For example, the RTC on the BAB750 is accessible in IO
35 * space using its address and data registers. To enable usage of
36 * NVRAM in those cases I invented the functions 'nvram_read()' and
37 * 'nvram_write()', which will be activated upon the configuration
38 * #define CFG_NVRAM_ACCESS_ROUTINE. Note, that those functions are
39 * strongly dependent on the used HW, and must be redefined for each
40 * board that wants to use them.
41 */
42
43#include <common.h>
44
d87080b7
WD
45DECLARE_GLOBAL_DATA_PTR;
46
c609719b
WD
47#ifdef CFG_ENV_IS_IN_NVRAM /* Environment is in NVRAM */
48
49#include <command.h>
50#include <environment.h>
c609719b 51#include <linux/stddef.h>
c609719b
WD
52
53#ifdef CFG_NVRAM_ACCESS_ROUTINE
54extern void *nvram_read(void *dest, const long src, size_t count);
55extern void nvram_write(long dest, const void *src, size_t count);
56env_t *env_ptr = NULL;
57#else
58env_t *env_ptr = (env_t *)CFG_ENV_ADDR;
59#endif
60
61char * env_name_spec = "NVRAM";
62
63extern uchar default_environment[];
64extern int default_environment_size;
65
7c7a23bd
WD
66#ifdef CONFIG_AMIGAONEG3SE
67uchar env_get_char_spec (int index)
68{
69#ifdef CFG_NVRAM_ACCESS_ROUTINE
70 uchar c;
71
72 nvram_read(&c, CFG_ENV_ADDR+index, 1);
c609719b 73
7c7a23bd
WD
74 return c;
75#else
7c7a23bd
WD
76 uchar retval;
77 enable_nvram();
78 retval = *((uchar *)(gd->env_addr + index));
79 disable_nvram();
80 return retval;
81#endif
82}
83#else
c609719b
WD
84uchar env_get_char_spec (int index)
85{
86#ifdef CFG_NVRAM_ACCESS_ROUTINE
87 uchar c;
88
89 nvram_read(&c, CFG_ENV_ADDR+index, 1);
90
91 return c;
92#else
c609719b
WD
93 return *((uchar *)(gd->env_addr + index));
94#endif
95}
7c7a23bd 96#endif
c609719b
WD
97
98void env_relocate_spec (void)
99{
100#if defined(CFG_NVRAM_ACCESS_ROUTINE)
101 nvram_read(env_ptr, CFG_ENV_ADDR, CFG_ENV_SIZE);
102#else
103 memcpy (env_ptr, (void*)CFG_ENV_ADDR, CFG_ENV_SIZE);
104#endif
105}
106
107int saveenv (void)
108{
109 int rcode = 0;
7c7a23bd
WD
110#ifdef CONFIG_AMIGAONEG3SE
111 enable_nvram();
112#endif
c609719b
WD
113#ifdef CFG_NVRAM_ACCESS_ROUTINE
114 nvram_write(CFG_ENV_ADDR, env_ptr, CFG_ENV_SIZE);
115#else
116 if (memcpy ((char *)CFG_ENV_ADDR, env_ptr, CFG_ENV_SIZE) == NULL)
117 rcode = 1 ;
7c7a23bd
WD
118#endif
119#ifdef CONFIG_AMIGAONEG3SE
120 udelay(10000);
121 disable_nvram();
c609719b
WD
122#endif
123 return rcode;
124}
125
126
127/************************************************************************
128 * Initialize Environment use
129 *
130 * We are still running from ROM, so data use is limited
131 */
132int env_init (void)
133{
7c7a23bd
WD
134#ifdef CONFIG_AMIGAONEG3SE
135 enable_nvram();
136#endif
c609719b
WD
137#if defined(CFG_NVRAM_ACCESS_ROUTINE)
138 ulong crc;
139 uchar data[ENV_SIZE];
140 nvram_read (&crc, CFG_ENV_ADDR, sizeof(ulong));
141 nvram_read (data, CFG_ENV_ADDR+sizeof(ulong), ENV_SIZE);
142
143 if (crc32(0, data, ENV_SIZE) == crc) {
144 gd->env_addr = (ulong)CFG_ENV_ADDR + sizeof(long);
145#else
146 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
147 gd->env_addr = (ulong)&(env_ptr->data);
148#endif
149 gd->env_valid = 1;
150 } else {
151 gd->env_addr = (ulong)&default_environment[0];
152 gd->env_valid = 0;
153 }
7c7a23bd
WD
154#ifdef CONFIG_AMIGAONEG3SE
155 disable_nvram();
156#endif
c609719b
WD
157 return (0);
158}
159
160#endif /* CFG_ENV_IS_IN_NVRAM */