Blame view
include/environment.h
8.53 KB
83d290c56 SPDX: Convert all... |
1 |
/* SPDX-License-Identifier: GPL-2.0+ */ |
c609719b8 Initial revision |
2 3 4 |
/* * (C) Copyright 2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
c609719b8 Initial revision |
5 6 7 |
*/ #ifndef _ENVIRONMENT_H_ |
6f403bad8 env: remove value... |
8 |
#define _ENVIRONMENT_H_ |
c609719b8 Initial revision |
9 |
|
fb1c43cc3 common: Move envi... |
10 |
#include <linux/kconfig.h> |
c609719b8 Initial revision |
11 12 13 14 15 16 17 18 |
/************************************************************************** * * The "environment" is stored as a list of '\0' terminated * "name=value" strings. The end of the list is marked by a double * '\0'. New entries are always added at the end. Deleting an entry * shifts the remaining entries to the front. Replacing an entry is a * combination of deleting the old value and adding the new one. * |
fc0b5948e Various, accumula... |
19 |
* The environment is preceded by a 32 bit CRC over the data part. |
c609719b8 Initial revision |
20 |
* |
fc0b5948e Various, accumula... |
21 |
*************************************************************************/ |
c609719b8 Initial revision |
22 |
|
5a1aceb06 rename CFG_ENV_IS... |
23 |
#if defined(CONFIG_ENV_IS_IN_FLASH) |
507651d61 env: clean enviro... |
24 25 |
# ifndef CONFIG_ENV_ADDR # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) |
c609719b8 Initial revision |
26 |
# endif |
507651d61 env: clean enviro... |
27 28 |
# ifndef CONFIG_ENV_OFFSET # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE) |
c609719b8 Initial revision |
29 |
# endif |
0e8d15866 rename CFG_ENV ma... |
30 |
# if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND) |
507651d61 env: clean enviro... |
31 32 |
# define CONFIG_ENV_ADDR_REDUND \ (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND) |
c609719b8 Initial revision |
33 |
# endif |
0e8d15866 rename CFG_ENV ma... |
34 |
# if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE) |
507651d61 env: clean enviro... |
35 36 |
# ifndef CONFIG_ENV_SECT_SIZE # define CONFIG_ENV_SECT_SIZE CONFIG_ENV_SIZE |
500545cc6 Fix problem with ... |
37 |
# endif |
507651d61 env: clean enviro... |
38 39 |
# ifndef CONFIG_ENV_SIZE # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE |
500545cc6 Fix problem with ... |
40 41 |
# endif # else |
0e8d15866 rename CFG_ENV ma... |
42 |
# error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined" |
c609719b8 Initial revision |
43 |
# endif |
0e8d15866 rename CFG_ENV ma... |
44 45 |
# if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND) # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE |
c609719b8 Initial revision |
46 |
# endif |
507651d61 env: clean enviro... |
47 48 49 |
# if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \ (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= \ (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) |
6f403bad8 env: remove value... |
50 |
# define ENV_IS_EMBEDDED |
c609719b8 Initial revision |
51 |
# endif |
0e8d15866 rename CFG_ENV ma... |
52 |
# if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) |
6f403bad8 env: remove value... |
53 |
# define CONFIG_SYS_REDUNDAND_ENVIRONMENT |
c609719b8 Initial revision |
54 |
# endif |
0a9e4e772 unify {CONFIG_,}E... |
55 56 57 58 |
# ifdef CONFIG_ENV_IS_EMBEDDED # error "do not define CONFIG_ENV_IS_EMBEDDED in your board config" # error "it is calculated automatically for you" # endif |
5a1aceb06 rename CFG_ENV_IS... |
59 |
#endif /* CONFIG_ENV_IS_IN_FLASH */ |
c609719b8 Initial revision |
60 |
|
5707df779 mmc: fix env in m... |
61 62 63 64 65 |
#if defined(CONFIG_ENV_IS_IN_MMC) # ifdef CONFIG_ENV_OFFSET_REDUND # define CONFIG_SYS_REDUNDAND_ENVIRONMENT # endif #endif |
51bfee192 rename CFG_ENV_IS... |
66 |
#if defined(CONFIG_ENV_IS_IN_NAND) |
c9f7351b5 NAND: environment... |
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# if defined(CONFIG_ENV_OFFSET_OOB) # ifdef CONFIG_ENV_OFFSET_REDUND # error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB" # error "is set" # endif extern unsigned long nand_env_oob_offset; # define CONFIG_ENV_OFFSET nand_env_oob_offset # else # ifndef CONFIG_ENV_OFFSET # error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND" # endif # ifdef CONFIG_ENV_OFFSET_REDUND # define CONFIG_SYS_REDUNDAND_ENVIRONMENT # endif # endif /* CONFIG_ENV_OFFSET_OOB */ |
0e8d15866 rename CFG_ENV ma... |
82 83 |
# ifndef CONFIG_ENV_SIZE # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND" |
e443c944c Support for redun... |
84 |
# endif |
51bfee192 rename CFG_ENV_IS... |
85 |
#endif /* CONFIG_ENV_IS_IN_NAND */ |
e443c944c Support for redun... |
86 |
|
2b74433f3 env: Add support ... |
87 88 89 90 91 92 93 |
#if defined(CONFIG_ENV_IS_IN_UBI) # ifndef CONFIG_ENV_UBI_PART # error "Need to define CONFIG_ENV_UBI_PART when using CONFIG_ENV_IS_IN_UBI" # endif # ifndef CONFIG_ENV_UBI_VOLUME # error "Need to define CONFIG_ENV_UBI_VOLUME when using CONFIG_ENV_IS_IN_UBI" # endif |
785881f77 env: Add redundan... |
94 95 96 |
# if defined(CONFIG_ENV_UBI_VOLUME_REDUND) # define CONFIG_SYS_REDUNDAND_ENVIRONMENT # endif |
2b74433f3 env: Add support ... |
97 98 99 100 101 102 103 |
# ifndef CONFIG_ENV_SIZE # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_UBI" # endif # ifndef CONFIG_CMD_UBI # error "Need to define CONFIG_CMD_UBI when using CONFIG_ENV_IS_IN_UBI" # endif #endif /* CONFIG_ENV_IS_IN_UBI */ |
0a9e4e772 unify {CONFIG_,}E... |
104 105 |
/* Embedded env is only supported for some flash types */ #ifdef CONFIG_ENV_IS_EMBEDDED |
507651d61 env: clean enviro... |
106 107 108 109 |
# if !defined(CONFIG_ENV_IS_IN_FLASH) && \ !defined(CONFIG_ENV_IS_IN_NAND) && \ !defined(CONFIG_ENV_IS_IN_ONENAND) && \ !defined(CONFIG_ENV_IS_IN_SPI_FLASH) |
0a9e4e772 unify {CONFIG_,}E... |
110 111 112 113 114 115 116 117 118 |
# error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type" # endif #endif /* * For the flash types where embedded env is supported, but it cannot be * calculated automatically (i.e. NAND), take the board opt-in. */ #if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED) |
6f403bad8 env: remove value... |
119 |
# define ENV_IS_EMBEDDED |
0a9e4e772 unify {CONFIG_,}E... |
120 121 122 123 124 |
#endif /* The build system likes to know if the env is embedded */ #ifdef DO_DEPS_ONLY # ifdef ENV_IS_EMBEDDED |
33a6b9e90 environment.h: fi... |
125 126 127 |
# ifndef CONFIG_ENV_IS_EMBEDDED # define CONFIG_ENV_IS_EMBEDDED # endif |
0a9e4e772 unify {CONFIG_,}E... |
128 129 |
# endif #endif |
375660907 compiler.h: unify... |
130 |
#include "compiler.h" |
c609719b8 Initial revision |
131 |
|
6d0f6bcf3 rename CFG_ macro... |
132 |
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT |
89cdab788 crc32: use uint32... |
133 |
# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1) |
b218ccb54 Redundant environ... |
134 135 136 |
# define ACTIVE_FLAG 1 # define OBSOLETE_FLAG 0 |
c609719b8 Initial revision |
137 |
#else |
89cdab788 crc32: use uint32... |
138 |
# define ENV_HEADER_SIZE (sizeof(uint32_t)) |
c609719b8 Initial revision |
139 |
#endif |
0e8d15866 rename CFG_ENV ma... |
140 |
#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) |
c609719b8 Initial revision |
141 |
|
507651d61 env: clean enviro... |
142 |
typedef struct environment_s { |
89cdab788 crc32: use uint32... |
143 |
uint32_t crc; /* CRC32 over data bytes */ |
6d0f6bcf3 rename CFG_ macro... |
144 |
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT |
c609719b8 Initial revision |
145 146 147 |
unsigned char flags; /* active/obsolete flags */ #endif unsigned char data[ENV_SIZE]; /* Environment data */ |
c6831c74a env: Remove CONFI... |
148 |
} env_t; |
c609719b8 Initial revision |
149 |
|
994bc671c env: move extern ... |
150 151 152 |
#ifdef ENV_IS_EMBEDDED extern env_t environment; #endif /* ENV_IS_EMBEDDED */ |
d1459f0fa env: move extern ... |
153 |
extern const unsigned char default_environment[]; |
27aafe988 env: clean env_co... |
154 |
|
27aafe988 env: clean env_co... |
155 156 157 |
#if defined(CONFIG_NEEDS_MANUAL_RELOC) extern void env_reloc(void); #endif |
d1459f0fa env: move extern ... |
158 |
|
2eb1573f0 hashtable: drop a... |
159 |
#ifndef DO_DEPS_ONLY |
170ab1107 env: Add support ... |
160 161 |
#include <env_attr.h> #include <env_callback.h> |
2598090b7 env: Add environm... |
162 |
#include <env_flags.h> |
2eb1573f0 hashtable: drop a... |
163 |
#include <search.h> |
203e94f6c env: Add an enum ... |
164 165 166 167 168 169 |
/* Value for environment validity */ enum env_valid { ENV_INVALID, /* No valid environment */ ENV_VALID, /* First or only environment is valid */ ENV_REDUND, /* Redundant environment is valid */ }; |
4415f1d1f env: Create a loc... |
170 |
enum env_location { |
e1caa5841 env: Fix env_load... |
171 |
ENVL_UNKNOWN, |
4415f1d1f env: Create a loc... |
172 |
ENVL_EEPROM, |
ffdc4c02e MLK-18141-1 env: ... |
173 |
ENVL_ESATA, |
4415f1d1f env: Create a loc... |
174 175 176 177 178 179 180 181 182 183 184 185 186 |
ENVL_EXT4, ENVL_FAT, ENVL_FLASH, ENVL_MMC, ENVL_NAND, ENVL_NVRAM, ENVL_ONENAND, ENVL_REMOTE, ENVL_SPI_FLASH, ENVL_UBI, ENVL_NOWHERE, ENVL_COUNT, |
4415f1d1f env: Create a loc... |
187 |
}; |
8a3a7e227 env: Pass additio... |
188 189 190 191 192 193 194 |
/* value for the various operations we want to perform on the env */ enum env_operation { ENVOP_GET_CHAR, /* we want to call the get_char function */ ENVOP_INIT, /* we want to call the init function */ ENVOP_LOAD, /* we want to call the load function */ ENVOP_SAVE, /* we want to call the save function */ }; |
4415f1d1f env: Create a loc... |
195 |
struct env_driver { |
ac358beb8 env: Drop the env... |
196 |
const char *name; |
4415f1d1f env: Create a loc... |
197 198 199 |
enum env_location location; /** |
4415f1d1f env: Create a loc... |
200 201 202 203 |
* load() - Load the environment from storage * * This method is optional. If not provided, no environment will be * loaded. |
c59519919 env: Adjust the l... |
204 205 |
* * @return 0 if OK, -ve on error |
4415f1d1f env: Create a loc... |
206 |
*/ |
c59519919 env: Adjust the l... |
207 |
int (*load)(void); |
4415f1d1f env: Create a loc... |
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
/** * save() - Save the environment to storage * * This method is required for 'saveenv' to work. * * @return 0 if OK, -ve on error */ int (*save)(void); /** * init() - Set up the initial pre-relocation environment * * This method is optional. * |
7938822a6 env: Drop common ... |
223 224 |
* @return 0 if OK, -ENOENT if no initial environment could be found, * other -ve on error |
4415f1d1f env: Create a loc... |
225 226 227 228 229 230 231 |
*/ int (*init)(void); }; /* Declare a new environment location driver */ #define U_BOOT_ENV_LOCATION(__name) \ ll_entry_declare(struct env_driver, __name, env_driver) |
ac358beb8 env: Drop the env... |
232 233 234 235 236 237 |
/* Declare the name of a location */ #ifdef CONFIG_CMD_SAVEENV #define ENV_NAME(_name) .name = _name, #else #define ENV_NAME(_name) #endif |
4415f1d1f env: Create a loc... |
238 239 240 241 242 |
#ifdef CONFIG_CMD_SAVEENV #define env_save_ptr(x) x #else #define env_save_ptr(x) NULL #endif |
2eb1573f0 hashtable: drop a... |
243 |
extern struct hsearch_data env_htab; |
a8409f4f1 environment: clea... |
244 |
/* Function that updates CRC of the enironment */ |
507651d61 env: clean enviro... |
245 |
void env_crc_update(void); |
a8409f4f1 environment: clea... |
246 |
|
267541f77 env: Add support ... |
247 |
/* Look up the variable from the default environment */ |
723806cc5 env: Rename some ... |
248 |
char *env_get_default(const char *name); |
267541f77 env: Add support ... |
249 |
|
5bb12dbd7 Remove code dupli... |
250 |
/* [re]set to the default environment */ |
c5d548a9f env: common: acce... |
251 |
void set_default_env(const char *s, int flags); |
ea882baf9 New implementatio... |
252 |
|
b64b7c3df env: make "env de... |
253 |
/* [re]set individual variables to their value in the default environment */ |
477f8116d cmd: nvedit: prop... |
254 |
int set_default_vars(int nvars, char * const vars[], int flags); |
b64b7c3df env: make "env de... |
255 |
|
ea882baf9 New implementatio... |
256 257 |
/* Import from binary representation into hash table */ int env_import(const char *buf, int check); |
5bb12dbd7 Remove code dupli... |
258 |
|
7ce1526ed env: Add env_expo... |
259 260 |
/* Export from hash table into binary representation */ int env_export(env_t *env_out); |
76768f5f0 env: Add generic ... |
261 262 |
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT /* Select and import one of two redundant environments */ |
31f044bd9 env: move more co... |
263 264 |
int env_import_redund(const char *buf1, int buf1_status, const char *buf2, int buf2_status); |
76768f5f0 env: Add generic ... |
265 |
#endif |
565d9002a MLK-22279-1 env: ... |
266 267 268 269 270 |
#ifdef ENV_IS_EMBEDDED #define env_get_offset(x) x #else long long env_get_offset(long long defautl_offset); #endif |
ac358beb8 env: Drop the env... |
271 |
/** |
a69d0f60e env: Drop env_get... |
272 273 |
* env_get_char() - Get a character from the early environment * |
919d25c92 u-boot: Fix sever... |
274 |
* This reads from the pre-relocation environment |
a69d0f60e env: Drop env_get... |
275 276 277 278 279 |
* * @index: Index of character to read (0 = first) * @return character read, or -ve on error */ int env_get_char(int index); |
310fb14b2 env: Drop env_rel... |
280 281 282 283 284 285 |
/** * env_load() - Load the environment from storage * * @return 0 if OK, -ve on error */ int env_load(void); |
01510091d env: Drop saveenv... |
286 287 288 289 290 291 |
/** * env_save() - Save the environment to storage * * @return 0 if OK, -ve on error */ int env_save(void); |
7bcdf1957 env: Relocate env... |
292 293 294 295 |
/** * env_fix_drivers() - Updates envdriver as per relocation */ void env_fix_drivers(void); |
9925f1dbc net: Move enetadd... |
296 297 298 |
void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr); int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr); int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr); |
507651d61 env: clean enviro... |
299 |
#endif /* DO_DEPS_ONLY */ |
2eb1573f0 hashtable: drop a... |
300 |
|
507651d61 env: clean enviro... |
301 |
#endif /* _ENVIRONMENT_H_ */ |