1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _ENV_INTERNAL_H_
16#define _ENV_INTERNAL_H_
17
18#include <linux/kconfig.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32#if defined(CONFIG_ENV_IS_IN_FLASH)
33# ifndef CONFIG_ENV_ADDR
34# define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
35# endif
36# ifndef CONFIG_ENV_OFFSET
37# define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
38# endif
39# if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
40# define CONFIG_ENV_ADDR_REDUND \
41 (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
42# endif
43# if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE)
44# ifndef CONFIG_ENV_SECT_SIZE
45# define CONFIG_ENV_SECT_SIZE CONFIG_ENV_SIZE
46# endif
47# ifndef CONFIG_ENV_SIZE
48# define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
49# endif
50# else
51# error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined"
52# endif
53# if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
54# define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE
55# endif
56# if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
57 (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= \
58 (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)
59# define ENV_IS_EMBEDDED
60# endif
61# if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
62# define CONFIG_SYS_REDUNDAND_ENVIRONMENT
63# endif
64# ifdef CONFIG_ENV_IS_EMBEDDED
65# error "do not define CONFIG_ENV_IS_EMBEDDED in your board config"
66# error "it is calculated automatically for you"
67# endif
68#endif
69
70#if defined(CONFIG_ENV_IS_IN_MMC)
71# ifdef CONFIG_ENV_OFFSET_REDUND
72# define CONFIG_SYS_REDUNDAND_ENVIRONMENT
73# endif
74#endif
75
76#if defined(CONFIG_ENV_IS_IN_NAND)
77# if defined(CONFIG_ENV_OFFSET_OOB)
78# ifdef CONFIG_ENV_OFFSET_REDUND
79# error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB"
80# error "is set"
81# endif
82extern unsigned long nand_env_oob_offset;
83# define CONFIG_ENV_OFFSET nand_env_oob_offset
84# else
85# ifndef CONFIG_ENV_OFFSET
86# error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND"
87# endif
88# ifdef CONFIG_ENV_OFFSET_REDUND
89# define CONFIG_SYS_REDUNDAND_ENVIRONMENT
90# endif
91# endif
92# ifndef CONFIG_ENV_SIZE
93# error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND"
94# endif
95#endif
96
97#if defined(CONFIG_ENV_IS_IN_UBI)
98# ifndef CONFIG_ENV_UBI_PART
99# error "Need to define CONFIG_ENV_UBI_PART when using CONFIG_ENV_IS_IN_UBI"
100# endif
101# ifndef CONFIG_ENV_UBI_VOLUME
102# error "Need to define CONFIG_ENV_UBI_VOLUME when using CONFIG_ENV_IS_IN_UBI"
103# endif
104# if defined(CONFIG_ENV_UBI_VOLUME_REDUND)
105# define CONFIG_SYS_REDUNDAND_ENVIRONMENT
106# endif
107# ifndef CONFIG_ENV_SIZE
108# error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_UBI"
109# endif
110# ifndef CONFIG_CMD_UBI
111# error "Need to define CONFIG_CMD_UBI when using CONFIG_ENV_IS_IN_UBI"
112# endif
113#endif
114
115
116#ifdef CONFIG_ENV_IS_EMBEDDED
117# if !defined(CONFIG_ENV_IS_IN_FLASH) && \
118 !defined(CONFIG_ENV_IS_IN_NAND) && \
119 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
120 !defined(CONFIG_ENV_IS_IN_SPI_FLASH)
121# error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type"
122# endif
123#endif
124
125
126
127
128
129#if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED)
130# define ENV_IS_EMBEDDED
131#endif
132
133
134#ifdef DO_DEPS_ONLY
135# ifdef ENV_IS_EMBEDDED
136# ifndef CONFIG_ENV_IS_EMBEDDED
137# define CONFIG_ENV_IS_EMBEDDED
138# endif
139# endif
140#endif
141
142#include "compiler.h"
143
144#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
145# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
146#else
147# define ENV_HEADER_SIZE (sizeof(uint32_t))
148#endif
149
150#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
151
152
153
154
155
156#if defined(CONFIG_ENV_IS_EMBEDDED)
157#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
158#elif (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE < CONFIG_SYS_MONITOR_BASE) || \
159 (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) || \
160 defined(CONFIG_ENV_IS_IN_NVRAM)
161#define TOTAL_MALLOC_LEN (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
162#else
163#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
164#endif
165
166typedef struct environment_s {
167 uint32_t crc;
168#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
169 unsigned char flags;
170#endif
171 unsigned char data[ENV_SIZE];
172} env_t;
173
174#ifdef ENV_IS_EMBEDDED
175extern env_t embedded_environment;
176#endif
177
178extern const unsigned char default_environment[];
179
180#ifndef DO_DEPS_ONLY
181
182#include <env_attr.h>
183#include <env_callback.h>
184#include <env_flags.h>
185#include <search.h>
186
187enum env_location {
188 ENVL_UNKNOWN,
189 ENVL_EEPROM,
190 ENVL_EXT4,
191 ENVL_FAT,
192 ENVL_FLASH,
193 ENVL_MMC,
194 ENVL_NAND,
195 ENVL_NVRAM,
196 ENVL_ONENAND,
197 ENVL_REMOTE,
198 ENVL_SPI_FLASH,
199 ENVL_UBI,
200 ENVL_NOWHERE,
201
202 ENVL_COUNT,
203};
204
205
206enum env_operation {
207 ENVOP_GET_CHAR,
208 ENVOP_INIT,
209 ENVOP_LOAD,
210 ENVOP_SAVE,
211 ENVOP_ERASE,
212};
213
214struct env_driver {
215 const char *name;
216 enum env_location location;
217
218
219
220
221
222
223
224
225
226 int (*load)(void);
227
228
229
230
231
232
233
234
235 int (*save)(void);
236
237
238
239
240
241
242
243
244 int (*erase)(void);
245
246
247
248
249
250
251
252
253
254 int (*init)(void);
255};
256
257
258#define U_BOOT_ENV_LOCATION(__name) \
259 ll_entry_declare(struct env_driver, __name, env_driver)
260
261
262#ifdef CONFIG_CMD_SAVEENV
263#define ENV_NAME(_name) .name = _name,
264#else
265#define ENV_NAME(_name)
266#endif
267
268#ifdef CONFIG_CMD_SAVEENV
269#define env_save_ptr(x) x
270#else
271#define env_save_ptr(x) NULL
272#endif
273
274extern struct hsearch_data env_htab;
275
276#endif
277
278#endif
279