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# if defined(CONFIG_ENV_ADDR_REDUND) && \
34 ((CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
35 (CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE) <= \
36 (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN))
37# define ENV_IS_EMBEDDED
38# endif
39# if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
40 (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= \
41 (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)
42# define ENV_IS_EMBEDDED
43# endif
44# ifdef CONFIG_ENV_IS_EMBEDDED
45# error "do not define CONFIG_ENV_IS_EMBEDDED in your board config"
46# error "it is calculated automatically for you"
47# endif
48#endif
49
50#if defined(CONFIG_ENV_IS_IN_NAND)
51# if defined(CONFIG_ENV_OFFSET_OOB)
52# ifdef CONFIG_ENV_OFFSET_REDUND
53# error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB"
54# error "is set"
55# endif
56extern unsigned long nand_env_oob_offset;
57# define CONFIG_ENV_OFFSET nand_env_oob_offset
58# endif
59#endif
60
61
62
63
64
65#if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED)
66# define ENV_IS_EMBEDDED
67#endif
68
69
70#ifdef DO_DEPS_ONLY
71# ifdef ENV_IS_EMBEDDED
72# ifndef CONFIG_ENV_IS_EMBEDDED
73# define CONFIG_ENV_IS_EMBEDDED
74# endif
75# endif
76#endif
77
78#include "compiler.h"
79
80#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
81# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
82#else
83# define ENV_HEADER_SIZE (sizeof(uint32_t))
84#endif
85
86#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
87
88
89
90
91
92#if defined(CONFIG_ENV_IS_EMBEDDED)
93#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
94#elif (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE < CONFIG_SYS_MONITOR_BASE) || \
95 (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) || \
96 defined(CONFIG_ENV_IS_IN_NVRAM)
97#define TOTAL_MALLOC_LEN (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
98#else
99#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
100#endif
101
102typedef struct environment_s {
103 uint32_t crc;
104#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
105 unsigned char flags;
106#endif
107 unsigned char data[ENV_SIZE];
108} env_t;
109
110#ifdef ENV_IS_EMBEDDED
111extern env_t embedded_environment;
112#endif
113
114extern const unsigned char default_environment[];
115
116#ifndef DO_DEPS_ONLY
117
118#include <env_attr.h>
119#include <env_callback.h>
120#include <env_flags.h>
121#include <search.h>
122
123enum env_location {
124 ENVL_UNKNOWN,
125 ENVL_EEPROM,
126 ENVL_EXT4,
127 ENVL_FAT,
128 ENVL_FLASH,
129 ENVL_MMC,
130 ENVL_NAND,
131 ENVL_NVRAM,
132 ENVL_ONENAND,
133 ENVL_REMOTE,
134 ENVL_SPI_FLASH,
135 ENVL_UBI,
136 ENVL_NOWHERE,
137
138 ENVL_COUNT,
139};
140
141
142enum env_operation {
143 ENVOP_GET_CHAR,
144 ENVOP_INIT,
145 ENVOP_LOAD,
146 ENVOP_SAVE,
147 ENVOP_ERASE,
148};
149
150struct env_driver {
151 const char *name;
152 enum env_location location;
153
154
155
156
157
158
159
160
161
162 int (*load)(void);
163
164
165
166
167
168
169
170
171 int (*save)(void);
172
173
174
175
176
177
178
179
180 int (*erase)(void);
181
182
183
184
185
186
187
188
189
190 int (*init)(void);
191};
192
193
194#define U_BOOT_ENV_LOCATION(__name) \
195 ll_entry_declare(struct env_driver, __name, env_driver)
196
197
198#ifdef CONFIG_CMD_SAVEENV
199#define ENV_NAME(_name) .name = _name,
200#else
201#define ENV_NAME(_name)
202#endif
203
204#ifdef CONFIG_CMD_SAVEENV
205#define env_save_ptr(x) x
206#else
207#define env_save_ptr(x) NULL
208#endif
209
210extern struct hsearch_data env_htab;
211
212#endif
213
214#endif
215