1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43#include <common.h>
44#include <command.h>
45#include <environment.h>
46#include <linux/stddef.h>
47
48DECLARE_GLOBAL_DATA_PTR;
49
50#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
51extern void *nvram_read(void *dest, const long src, size_t count);
52extern void nvram_write(long dest, const void *src, size_t count);
53env_t *env_ptr = NULL;
54#else
55env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
56#endif
57
58char * env_name_spec = "NVRAM";
59
60extern uchar default_environment[];
61
62#ifdef CONFIG_AMIGAONEG3SE
63uchar env_get_char_spec (int index)
64{
65#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
66 uchar c;
67
68 nvram_read(&c, CONFIG_ENV_ADDR+index, 1);
69
70 return c;
71#else
72 uchar retval;
73 enable_nvram();
74 retval = *((uchar *)(gd->env_addr + index));
75 disable_nvram();
76 return retval;
77#endif
78}
79#else
80uchar env_get_char_spec (int index)
81{
82#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
83 uchar c;
84
85 nvram_read(&c, CONFIG_ENV_ADDR+index, 1);
86
87 return c;
88#else
89 return *((uchar *)(gd->env_addr + index));
90#endif
91}
92#endif
93
94void env_relocate_spec (void)
95{
96#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE)
97 nvram_read(env_ptr, CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
98#else
99 memcpy (env_ptr, (void*)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
100#endif
101}
102
103int saveenv (void)
104{
105 int rcode = 0;
106#ifdef CONFIG_AMIGAONEG3SE
107 enable_nvram();
108#endif
109#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
110 nvram_write(CONFIG_ENV_ADDR, env_ptr, CONFIG_ENV_SIZE);
111#else
112 if (memcpy ((char *)CONFIG_ENV_ADDR, env_ptr, CONFIG_ENV_SIZE) == NULL)
113 rcode = 1 ;
114#endif
115#ifdef CONFIG_AMIGAONEG3SE
116 udelay(10000);
117 disable_nvram();
118#endif
119 return rcode;
120}
121
122
123
124
125
126
127
128int env_init (void)
129{
130#ifdef CONFIG_AMIGAONEG3SE
131 enable_nvram();
132#endif
133#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE)
134 ulong crc;
135 uchar data[ENV_SIZE];
136 nvram_read (&crc, CONFIG_ENV_ADDR, sizeof(ulong));
137 nvram_read (data, CONFIG_ENV_ADDR+sizeof(ulong), ENV_SIZE);
138
139 if (crc32(0, data, ENV_SIZE) == crc) {
140 gd->env_addr = (ulong)CONFIG_ENV_ADDR + sizeof(long);
141#else
142 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
143 gd->env_addr = (ulong)&(env_ptr->data);
144#endif
145 gd->env_valid = 1;
146 } else {
147 gd->env_addr = (ulong)&default_environment[0];
148 gd->env_valid = 0;
149 }
150#ifdef CONFIG_AMIGAONEG3SE
151 disable_nvram();
152#endif
153 return (0);
154}
155