Blame view

include/environment.h 6.59 KB
c609719b8   wdenk   Initial revision
1
2
3
4
  /*
   * (C) Copyright 2002
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
5
   * SPDX-License-Identifier:	GPL-2.0+
c609719b8   wdenk   Initial revision
6
7
8
   */
  
  #ifndef _ENVIRONMENT_H_
6f403bad8   Igor Grinberg   env: remove value...
9
  #define _ENVIRONMENT_H_
c609719b8   wdenk   Initial revision
10
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   Robert P. J. Day   Various, accumula...
19
   * The environment is preceded by a 32 bit CRC over the data part.
c609719b8   wdenk   Initial revision
20
   *
fc0b5948e   Robert P. J. Day   Various, accumula...
21
   *************************************************************************/
c609719b8   wdenk   Initial revision
22

5a1aceb06   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
23
  #if defined(CONFIG_ENV_IS_IN_FLASH)
507651d61   Igor Grinberg   env: clean enviro...
24
25
  # ifndef	CONFIG_ENV_ADDR
  #  define	CONFIG_ENV_ADDR	(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
c609719b8   wdenk   Initial revision
26
  # endif
507651d61   Igor Grinberg   env: clean enviro...
27
28
  # ifndef	CONFIG_ENV_OFFSET
  #  define	CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
c609719b8   wdenk   Initial revision
29
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
30
  # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
507651d61   Igor Grinberg   env: clean enviro...
31
32
  #  define	CONFIG_ENV_ADDR_REDUND	\
  		(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
c609719b8   wdenk   Initial revision
33
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
34
  # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE)
507651d61   Igor Grinberg   env: clean enviro...
35
36
  #  ifndef	CONFIG_ENV_SECT_SIZE
  #   define	CONFIG_ENV_SECT_SIZE	CONFIG_ENV_SIZE
500545cc6   wdenk   Fix problem with ...
37
  #  endif
507651d61   Igor Grinberg   env: clean enviro...
38
39
  #  ifndef	CONFIG_ENV_SIZE
  #   define	CONFIG_ENV_SIZE	CONFIG_ENV_SECT_SIZE
500545cc6   wdenk   Fix problem with ...
40
41
  #  endif
  # else
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
42
  #  error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined"
c609719b8   wdenk   Initial revision
43
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   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   wdenk   Initial revision
46
  # endif
507651d61   Igor Grinberg   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   Igor Grinberg   env: remove value...
50
  #  define ENV_IS_EMBEDDED
c609719b8   wdenk   Initial revision
51
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
52
  # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
6f403bad8   Igor Grinberg   env: remove value...
53
  #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
c609719b8   wdenk   Initial revision
54
  # endif
0a9e4e772   Mike Frysinger   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   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
59
  #endif	/* CONFIG_ENV_IS_IN_FLASH */
c609719b8   wdenk   Initial revision
60

5707df779   Bo Shen   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   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
66
  #if defined(CONFIG_ENV_IS_IN_NAND)
c9f7351b5   Ben Gardiner   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   Jean-Christophe PLAGNIOL-VILLARD   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   Markus Klotzbuecher   Support for redun...
84
  # endif
51bfee192   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
85
  #endif /* CONFIG_ENV_IS_IN_NAND */
e443c944c   Markus Klotzbuecher   Support for redun...
86

2b74433f3   Joe Hershberger   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   Joe Hershberger   env: Add redundan...
94
95
96
  # if defined(CONFIG_ENV_UBI_VOLUME_REDUND)
  #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
  # endif
2b74433f3   Joe Hershberger   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   Mike Frysinger   unify {CONFIG_,}E...
104
105
  /* Embedded env is only supported for some flash types */
  #ifdef CONFIG_ENV_IS_EMBEDDED
507651d61   Igor Grinberg   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   Mike Frysinger   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   Igor Grinberg   env: remove value...
119
  # define ENV_IS_EMBEDDED
0a9e4e772   Mike Frysinger   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   Wolfgang Denk   environment.h: fi...
125
126
127
  #  ifndef CONFIG_ENV_IS_EMBEDDED
  #   define CONFIG_ENV_IS_EMBEDDED
  #  endif
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
128
129
  # endif
  #endif
375660907   Mike Frysinger   compiler.h: unify...
130
  #include "compiler.h"
c609719b8   wdenk   Initial revision
131

6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
132
  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
89cdab788   Mike Frysinger   crc32: use uint32...
133
  # define ENV_HEADER_SIZE	(sizeof(uint32_t) + 1)
b218ccb54   Wolfgang Denk   Redundant environ...
134
135
136
  
  # define ACTIVE_FLAG   1
  # define OBSOLETE_FLAG 0
c609719b8   wdenk   Initial revision
137
  #else
89cdab788   Mike Frysinger   crc32: use uint32...
138
  # define ENV_HEADER_SIZE	(sizeof(uint32_t))
c609719b8   wdenk   Initial revision
139
  #endif
d09b1787a   Igor Grinberg   env: clean cmd_nv...
140
141
142
  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
  extern char *env_name_spec;
  #endif
c609719b8   wdenk   Initial revision
143

a4223b746   Marek Vasut   env: Implement su...
144
145
146
147
  #ifdef CONFIG_ENV_AES
  /* Make sure the payload is multiple of AES block size */
  #define ENV_SIZE ((CONFIG_ENV_SIZE - ENV_HEADER_SIZE) & ~(16 - 1))
  #else
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
148
  #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
a4223b746   Marek Vasut   env: Implement su...
149
  #endif
c609719b8   wdenk   Initial revision
150

507651d61   Igor Grinberg   env: clean enviro...
151
  typedef struct environment_s {
89cdab788   Mike Frysinger   crc32: use uint32...
152
  	uint32_t	crc;		/* CRC32 over data bytes	*/
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
153
  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
c609719b8   wdenk   Initial revision
154
155
156
  	unsigned char	flags;		/* active/obsolete flags	*/
  #endif
  	unsigned char	data[ENV_SIZE]; /* Environment data		*/
a4223b746   Marek Vasut   env: Implement su...
157
158
159
160
161
162
  } env_t
  #ifdef CONFIG_ENV_AES
  /* Make sure the env is aligned to block size. */
  __attribute__((aligned(16)))
  #endif
  ;
c609719b8   wdenk   Initial revision
163

994bc671c   Igor Grinberg   env: move extern ...
164
165
166
  #ifdef ENV_IS_EMBEDDED
  extern env_t environment;
  #endif /* ENV_IS_EMBEDDED */
d1459f0fa   Igor Grinberg   env: move extern ...
167
  extern const unsigned char default_environment[];
27aafe988   Igor Grinberg   env: clean env_co...
168
169
170
171
172
173
174
175
  extern env_t *env_ptr;
  
  extern void env_relocate_spec(void);
  extern unsigned char env_get_char_spec(int);
  
  #if defined(CONFIG_NEEDS_MANUAL_RELOC)
  extern void env_reloc(void);
  #endif
d1459f0fa   Igor Grinberg   env: move extern ...
176

ac77f42d0   Dmitry Lifshitz   env_mmc: add mmc_...
177
178
179
180
  #ifdef CONFIG_ENV_IS_IN_MMC
  #include <mmc.h>
  
  extern int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr);
6e7b7df4d   Dmitry Lifshitz   env_mmc: support ...
181
182
183
  # ifdef CONFIG_SYS_MMC_ENV_PART
  extern uint mmc_get_env_part(struct mmc *mmc);
  # endif
ac77f42d0   Dmitry Lifshitz   env_mmc: add mmc_...
184
  #endif
2eb1573f0   Mike Frysinger   hashtable: drop a...
185
  #ifndef DO_DEPS_ONLY
170ab1107   Joe Hershberger   env: Add support ...
186
187
  #include <env_attr.h>
  #include <env_callback.h>
2598090b7   Joe Hershberger   env: Add environm...
188
  #include <env_flags.h>
2eb1573f0   Mike Frysinger   hashtable: drop a...
189
190
191
  #include <search.h>
  
  extern struct hsearch_data env_htab;
b502611b5   Joakim Tjernlund   Change env_get_ch...
192
  /* Function that returns a character from the environment */
507651d61   Igor Grinberg   env: clean enviro...
193
  unsigned char env_get_char(int);
a8409f4f1   Wolfgang Denk   environment: clea...
194
195
  
  /* Function that returns a pointer to a value from the environment */
147c7169e   Mike Frysinger   constify default env
196
  const unsigned char *env_get_addr(int);
507651d61   Igor Grinberg   env: clean enviro...
197
  unsigned char env_get_char_memory(int index);
a8409f4f1   Wolfgang Denk   environment: clea...
198
199
  
  /* Function that updates CRC of the enironment */
507651d61   Igor Grinberg   env: clean enviro...
200
  void env_crc_update(void);
a8409f4f1   Wolfgang Denk   environment: clea...
201

267541f77   Joe Hershberger   env: Add support ...
202
203
  /* Look up the variable from the default environment */
  char *getenv_default(const char *name);
5bb12dbd7   Harald Welte   Remove code dupli...
204
  /* [re]set to the default environment */
ea882baf9   Wolfgang Denk   New implementatio...
205
  void set_default_env(const char *s);
b64b7c3df   Gerlando Falauto   env: make "env de...
206
207
  /* [re]set individual variables to their value in the default environment */
  int set_default_vars(int nvars, char * const vars[]);
ea882baf9   Wolfgang Denk   New implementatio...
208
209
  /* Import from binary representation into hash table */
  int env_import(const char *buf, int check);
5bb12dbd7   Harald Welte   Remove code dupli...
210

7ce1526ed   Marek Vasut   env: Add env_expo...
211
212
  /* Export from hash table into binary representation */
  int env_export(env_t *env_out);
507651d61   Igor Grinberg   env: clean enviro...
213
  #endif /* DO_DEPS_ONLY */
2eb1573f0   Mike Frysinger   hashtable: drop a...
214

507651d61   Igor Grinberg   env: clean enviro...
215
  #endif /* _ENVIRONMENT_H_ */