Blame view

include/environment.h 5.76 KB
c609719b8   wdenk   Initial revision
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /*
   * (C) Copyright 2002
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
   * See file CREDITS for list of people who contributed to this
   * project.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
   * published by the Free Software Foundation; either version 2 of
   * the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
   * MA 02111-1307 USA
   */
  
  #ifndef _ENVIRONMENT_H_
6f403bad8   Igor Grinberg   env: remove value...
25
  #define _ENVIRONMENT_H_
c609719b8   wdenk   Initial revision
26
27
28
29
30
31
32
33
34
35
36
37
38
  
  /**************************************************************************
   *
   * 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.
   *
   * The environment is preceeded by a 32 bit CRC over the data part.
   *
   **************************************************************************
   */
5a1aceb06   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
39
  #if defined(CONFIG_ENV_IS_IN_FLASH)
507651d61   Igor Grinberg   env: clean enviro...
40
41
  # ifndef	CONFIG_ENV_ADDR
  #  define	CONFIG_ENV_ADDR	(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
c609719b8   wdenk   Initial revision
42
  # endif
507651d61   Igor Grinberg   env: clean enviro...
43
44
  # ifndef	CONFIG_ENV_OFFSET
  #  define	CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
c609719b8   wdenk   Initial revision
45
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
46
  # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
507651d61   Igor Grinberg   env: clean enviro...
47
48
  #  define	CONFIG_ENV_ADDR_REDUND	\
  		(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
c609719b8   wdenk   Initial revision
49
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
50
  # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE)
507651d61   Igor Grinberg   env: clean enviro...
51
52
  #  ifndef	CONFIG_ENV_SECT_SIZE
  #   define	CONFIG_ENV_SECT_SIZE	CONFIG_ENV_SIZE
500545cc6   wdenk   Fix problem with ...
53
  #  endif
507651d61   Igor Grinberg   env: clean enviro...
54
55
  #  ifndef	CONFIG_ENV_SIZE
  #   define	CONFIG_ENV_SIZE	CONFIG_ENV_SECT_SIZE
500545cc6   wdenk   Fix problem with ...
56
57
  #  endif
  # else
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
58
  #  error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined"
c609719b8   wdenk   Initial revision
59
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
60
61
  # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
  #  define CONFIG_ENV_SIZE_REDUND	CONFIG_ENV_SIZE
c609719b8   wdenk   Initial revision
62
  # endif
507651d61   Igor Grinberg   env: clean enviro...
63
64
65
  # 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...
66
  #  define ENV_IS_EMBEDDED
c609719b8   wdenk   Initial revision
67
  # endif
0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
68
  # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
6f403bad8   Igor Grinberg   env: remove value...
69
  #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
c609719b8   wdenk   Initial revision
70
  # endif
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
71
72
73
74
  # 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...
75
  #endif	/* CONFIG_ENV_IS_IN_FLASH */
c609719b8   wdenk   Initial revision
76

51bfee192   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
77
  #if defined(CONFIG_ENV_IS_IN_NAND)
c9f7351b5   Ben Gardiner   NAND: environment...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  # 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...
93
94
  # ifndef CONFIG_ENV_SIZE
  #  error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND"
e443c944c   Markus Klotzbuecher   Support for redun...
95
  # endif
51bfee192   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV_IS...
96
  #endif /* CONFIG_ENV_IS_IN_NAND */
e443c944c   Markus Klotzbuecher   Support for redun...
97

0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
98
99
  /* Embedded env is only supported for some flash types */
  #ifdef CONFIG_ENV_IS_EMBEDDED
507651d61   Igor Grinberg   env: clean enviro...
100
101
102
103
  # 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...
104
105
106
107
108
109
110
111
112
  #  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...
113
  # define ENV_IS_EMBEDDED
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
114
115
116
117
118
  #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...
119
120
121
  #  ifndef CONFIG_ENV_IS_EMBEDDED
  #   define CONFIG_ENV_IS_EMBEDDED
  #  endif
0a9e4e772   Mike Frysinger   unify {CONFIG_,}E...
122
123
  # endif
  #endif
375660907   Mike Frysinger   compiler.h: unify...
124
  #include "compiler.h"
c609719b8   wdenk   Initial revision
125

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

0e8d15866   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ENV ma...
138
  #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
c609719b8   wdenk   Initial revision
139

507651d61   Igor Grinberg   env: clean enviro...
140
  typedef struct environment_s {
89cdab788   Mike Frysinger   crc32: use uint32...
141
  	uint32_t	crc;		/* CRC32 over data bytes	*/
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
142
  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
c609719b8   wdenk   Initial revision
143
144
145
146
  	unsigned char	flags;		/* active/obsolete flags	*/
  #endif
  	unsigned char	data[ENV_SIZE]; /* Environment data		*/
  } env_t;
994bc671c   Igor Grinberg   env: move extern ...
147
148
149
  #ifdef ENV_IS_EMBEDDED
  extern env_t environment;
  #endif /* ENV_IS_EMBEDDED */
d1459f0fa   Igor Grinberg   env: move extern ...
150
  extern const unsigned char default_environment[];
27aafe988   Igor Grinberg   env: clean env_co...
151
152
153
154
155
156
157
158
  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 ...
159

2eb1573f0   Mike Frysinger   hashtable: drop a...
160
161
162
163
164
  #ifndef DO_DEPS_ONLY
  
  #include <search.h>
  
  extern struct hsearch_data env_htab;
b502611b5   Joakim Tjernlund   Change env_get_ch...
165
  /* Function that returns a character from the environment */
507651d61   Igor Grinberg   env: clean enviro...
166
  unsigned char env_get_char(int);
a8409f4f1   Wolfgang Denk   environment: clea...
167
168
  
  /* Function that returns a pointer to a value from the environment */
147c7169e   Mike Frysinger   constify default env
169
  const unsigned char *env_get_addr(int);
507651d61   Igor Grinberg   env: clean enviro...
170
  unsigned char env_get_char_memory(int index);
a8409f4f1   Wolfgang Denk   environment: clea...
171
172
  
  /* Function that updates CRC of the enironment */
507651d61   Igor Grinberg   env: clean enviro...
173
  void env_crc_update(void);
a8409f4f1   Wolfgang Denk   environment: clea...
174

5bb12dbd7   Harald Welte   Remove code dupli...
175
  /* [re]set to the default environment */
ea882baf9   Wolfgang Denk   New implementatio...
176
177
178
179
  void set_default_env(const char *s);
  
  /* Import from binary representation into hash table */
  int env_import(const char *buf, int check);
5bb12dbd7   Harald Welte   Remove code dupli...
180

507651d61   Igor Grinberg   env: clean enviro...
181
  #endif /* DO_DEPS_ONLY */
2eb1573f0   Mike Frysinger   hashtable: drop a...
182

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