Blame view

include/env_internal.h 5.64 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  /* SPDX-License-Identifier: GPL-2.0+ */
c609719b8   wdenk   Initial revision
2
  /*
f3998fdc4   Simon Glass   env: Rename envir...
3
4
5
6
7
8
9
10
   * Internal environment header file. This includes direct access to environment
   * information such as its size and offset, direct access to the default
   * environment and embedded environment (if used). It also provides environment
   * drivers with various declarations.
   *
   * It should not be included by board files, drivers and code other than that
   * related to the environment implementation.
   *
c609719b8   wdenk   Initial revision
11
12
   * (C) Copyright 2002
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
c609719b8   wdenk   Initial revision
13
   */
f3998fdc4   Simon Glass   env: Rename envir...
14
15
  #ifndef _ENV_INTERNAL_H_
  #define _ENV_INTERNAL_H_
c609719b8   wdenk   Initial revision
16

fb1c43cc3   Maxime Ripard   common: Move envi...
17
  #include <linux/kconfig.h>
c609719b8   wdenk   Initial revision
18
19
20
21
22
23
24
25
  /**************************************************************************
   *
   * 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...
26
   * The environment is preceded by a 32 bit CRC over the data part.
c609719b8   wdenk   Initial revision
27
   *
fc0b5948e   Robert P. J. Day   Various, accumula...
28
   *************************************************************************/
c609719b8   wdenk   Initial revision
29

5a1aceb06   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
30
  #if defined(CONFIG_ENV_IS_IN_FLASH)
a8992e788   Tom Rini   env: Remove usele...
31
32
33
34
35
  # if	defined(CONFIG_ENV_ADDR_REDUND) && \
  	((CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) &&		\
  	(CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE) <=		\
  	(CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN))
  #  define ENV_IS_EMBEDDED
c609719b8   wdenk   Initial revision
36
  # endif
507651d61   Igor Grinberg   env: clean enviro...
37
38
39
  # 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...
40
  #  define ENV_IS_EMBEDDED
c609719b8   wdenk   Initial revision
41
  # endif
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
42
43
44
45
  # 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...
46
  #endif	/* CONFIG_ENV_IS_IN_FLASH */
c609719b8   wdenk   Initial revision
47

51bfee192   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
48
  #if defined(CONFIG_ENV_IS_IN_NAND)
c9f7351b5   Ben Gardiner   NAND: environment...
49
50
51
52
53
54
55
  # 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
c9f7351b5   Ben Gardiner   NAND: environment...
56
  # endif /* CONFIG_ENV_OFFSET_OOB */
51bfee192   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
57
  #endif /* CONFIG_ENV_IS_IN_NAND */
e443c944c   Markus Klotzbuecher   Support for redun...
58

0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
59
60
61
62
63
  /*
   * 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...
64
  # define ENV_IS_EMBEDDED
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
65
66
67
68
69
  #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...
70
71
72
  #  ifndef CONFIG_ENV_IS_EMBEDDED
  #   define CONFIG_ENV_IS_EMBEDDED
  #  endif
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
73
74
  # endif
  #endif
375660907   Mike Frysinger   compiler.h: unify...
75
  #include "compiler.h"
c609719b8   wdenk   Initial revision
76

6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
77
  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
89cdab788   Mike Frysinger   crc32: use uint32...
78
  # define ENV_HEADER_SIZE	(sizeof(uint32_t) + 1)
c609719b8   wdenk   Initial revision
79
  #else
89cdab788   Mike Frysinger   crc32: use uint32...
80
  # define ENV_HEADER_SIZE	(sizeof(uint32_t))
c609719b8   wdenk   Initial revision
81
  #endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
82
  #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
c609719b8   wdenk   Initial revision
83

f030b7b26   Simon Glass   env: Move TOTAL_M...
84
85
86
87
88
89
90
91
92
93
94
95
96
  /*
   * If the environment is in RAM, allocate extra space for it in the malloc
   * region.
   */
  #if defined(CONFIG_ENV_IS_EMBEDDED)
  #define TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
  #elif (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE < CONFIG_SYS_MONITOR_BASE) || \
        (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) || \
        defined(CONFIG_ENV_IS_IN_NVRAM)
  #define	TOTAL_MALLOC_LEN	(CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
  #else
  #define	TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
  #endif
507651d61   Igor Grinberg   env: clean enviro...
97
  typedef struct environment_s {
89cdab788   Mike Frysinger   crc32: use uint32...
98
  	uint32_t	crc;		/* CRC32 over data bytes	*/
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
99
  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
d3716dd64   Simon Glass   env: Rename the r...
100
  	unsigned char	flags;		/* active/obsolete flags ENVF_REDUND_ */
c609719b8   wdenk   Initial revision
101
102
  #endif
  	unsigned char	data[ENV_SIZE]; /* Environment data		*/
c6831c74a   Tom Rini   env: Remove CONFI...
103
  } env_t;
c609719b8   wdenk   Initial revision
104

994bc671c   Igor Grinberg   env: move extern ...
105
  #ifdef ENV_IS_EMBEDDED
be54ec162   Simon Glass   env: Rename envir...
106
  extern env_t embedded_environment;
994bc671c   Igor Grinberg   env: move extern ...
107
  #endif /* ENV_IS_EMBEDDED */
d1459f0fa   Igor Grinberg   env: move extern ...
108
  extern const unsigned char default_environment[];
27aafe988   Igor Grinberg   env: clean env_co...
109

2eb1573f0   Mike Frysinger   hashtable: drop a...
110
  #ifndef DO_DEPS_ONLY
170ab1107   Joe Hershberger   env: Add support ...
111
112
  #include <env_attr.h>
  #include <env_callback.h>
2598090b7   Joe Hershberger   env: Add environm...
113
  #include <env_flags.h>
2eb1573f0   Mike Frysinger   hashtable: drop a...
114
  #include <search.h>
4415f1d1f   Simon Glass   env: Create a loc...
115
  enum env_location {
e1caa5841   York Sun   env: Fix env_load...
116
  	ENVL_UNKNOWN,
4415f1d1f   Simon Glass   env: Create a loc...
117
  	ENVL_EEPROM,
73c8ddd02   Ye Li   MLK-18141-1 env: ...
118
  	ENVL_ESATA,
4415f1d1f   Simon Glass   env: Create a loc...
119
120
121
122
123
124
125
126
127
128
129
130
131
  	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   Simon Glass   env: Create a loc...
132
  };
8a3a7e227   Maxime Ripard   env: Pass additio...
133
134
135
136
137
138
  /* 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 */
cd121bdb6   Frank Wunderlich   env: register era...
139
  	ENVOP_ERASE,	/* we want to call the erase function */
8a3a7e227   Maxime Ripard   env: Pass additio...
140
  };
4415f1d1f   Simon Glass   env: Create a loc...
141
  struct env_driver {
ac358beb8   Simon Glass   env: Drop the env...
142
  	const char *name;
4415f1d1f   Simon Glass   env: Create a loc...
143
144
145
  	enum env_location location;
  
  	/**
4415f1d1f   Simon Glass   env: Create a loc...
146
147
148
149
  	 * load() - Load the environment from storage
  	 *
  	 * This method is optional. If not provided, no environment will be
  	 * loaded.
c59519919   Simon Glass   env: Adjust the l...
150
151
  	 *
  	 * @return 0 if OK, -ve on error
4415f1d1f   Simon Glass   env: Create a loc...
152
  	 */
c59519919   Simon Glass   env: Adjust the l...
153
  	int (*load)(void);
4415f1d1f   Simon Glass   env: Create a loc...
154
155
156
157
158
159
160
161
162
163
164
  
  	/**
  	 * save() - Save the environment to storage
  	 *
  	 * This method is required for 'saveenv' to work.
  	 *
  	 * @return 0 if OK, -ve on error
  	 */
  	int (*save)(void);
  
  	/**
cd121bdb6   Frank Wunderlich   env: register era...
165
166
167
168
169
170
171
172
173
  	 * erase() - Erase the environment on storage
  	 *
  	 * This method is optional and required for 'eraseenv' to work.
  	 *
  	 * @return 0 if OK, -ve on error
  	 */
  	int (*erase)(void);
  
  	/**
4415f1d1f   Simon Glass   env: Create a loc...
174
175
176
177
  	 * init() - Set up the initial pre-relocation environment
  	 *
  	 * This method is optional.
  	 *
7938822a6   Simon Glass   env: Drop common ...
178
179
  	 * @return 0 if OK, -ENOENT if no initial environment could be found,
  	 * other -ve on error
4415f1d1f   Simon Glass   env: Create a loc...
180
181
182
183
184
185
186
  	 */
  	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   Simon Glass   env: Drop the env...
187
188
189
190
191
192
  /* Declare the name of a location */
  #ifdef CONFIG_CMD_SAVEENV
  #define ENV_NAME(_name) .name = _name,
  #else
  #define ENV_NAME(_name)
  #endif
4415f1d1f   Simon Glass   env: Create a loc...
193
194
195
196
197
  #ifdef CONFIG_CMD_SAVEENV
  #define env_save_ptr(x) x
  #else
  #define env_save_ptr(x) NULL
  #endif
2eb1573f0   Mike Frysinger   hashtable: drop a...
198
  extern struct hsearch_data env_htab;
507651d61   Igor Grinberg   env: clean enviro...
199
  #endif /* DO_DEPS_ONLY */
2eb1573f0   Mike Frysinger   hashtable: drop a...
200

f3998fdc4   Simon Glass   env: Rename envir...
201
  #endif /* _ENV_INTERNAL_H_ */