xref: /rk3399_rockchip-uboot/include/environment.h (revision b64b7c3df7906342ca8abe8ae31c0c12ced3f401)
1c609719bSwdenk /*
2c609719bSwdenk  * (C) Copyright 2002
3c609719bSwdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4c609719bSwdenk  *
5c609719bSwdenk  * See file CREDITS for list of people who contributed to this
6c609719bSwdenk  * project.
7c609719bSwdenk  *
8c609719bSwdenk  * This program is free software; you can redistribute it and/or
9c609719bSwdenk  * modify it under the terms of the GNU General Public License as
10c609719bSwdenk  * published by the Free Software Foundation; either version 2 of
11c609719bSwdenk  * the License, or (at your option) any later version.
12c609719bSwdenk  *
13c609719bSwdenk  * This program is distributed in the hope that it will be useful,
14c609719bSwdenk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15c609719bSwdenk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c609719bSwdenk  * GNU General Public License for more details.
17c609719bSwdenk  *
18c609719bSwdenk  * You should have received a copy of the GNU General Public License
19c609719bSwdenk  * along with this program; if not, write to the Free Software
20c609719bSwdenk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21c609719bSwdenk  * MA 02111-1307 USA
22c609719bSwdenk  */
23c609719bSwdenk 
24c609719bSwdenk #ifndef _ENVIRONMENT_H_
256f403badSIgor Grinberg #define _ENVIRONMENT_H_
26c609719bSwdenk 
27c609719bSwdenk /**************************************************************************
28c609719bSwdenk  *
29c609719bSwdenk  * The "environment" is stored as a list of '\0' terminated
30c609719bSwdenk  * "name=value" strings. The end of the list is marked by a double
31c609719bSwdenk  * '\0'. New entries are always added at the end. Deleting an entry
32c609719bSwdenk  * shifts the remaining entries to the front. Replacing an entry is a
33c609719bSwdenk  * combination of deleting the old value and adding the new one.
34c609719bSwdenk  *
35c609719bSwdenk  * The environment is preceeded by a 32 bit CRC over the data part.
36c609719bSwdenk  *
37c609719bSwdenk  **************************************************************************
38c609719bSwdenk  */
39c609719bSwdenk 
405a1aceb0SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_ENV_IS_IN_FLASH)
410e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef	CONFIG_ENV_ADDR
426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #  define	CONFIG_ENV_ADDR	(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
43c609719bSwdenk # endif
440e8d1586SJean-Christophe PLAGNIOL-VILLARD # ifndef	CONFIG_ENV_OFFSET
456d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #  define	CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
46c609719bSwdenk # endif
470e8d1586SJean-Christophe PLAGNIOL-VILLARD # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
48507651d6SIgor Grinberg #  define	CONFIG_ENV_ADDR_REDUND	\
49507651d6SIgor Grinberg 		(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
50c609719bSwdenk # endif
510e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE)
520e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifndef	CONFIG_ENV_SECT_SIZE
530e8d1586SJean-Christophe PLAGNIOL-VILLARD #   define	CONFIG_ENV_SECT_SIZE	CONFIG_ENV_SIZE
54500545ccSwdenk #  endif
550e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifndef	CONFIG_ENV_SIZE
560e8d1586SJean-Christophe PLAGNIOL-VILLARD #   define	CONFIG_ENV_SIZE	CONFIG_ENV_SECT_SIZE
57c609719bSwdenk #  endif
58500545ccSwdenk # else
590e8d1586SJean-Christophe PLAGNIOL-VILLARD #  error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined"
60500545ccSwdenk # endif
610e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
620e8d1586SJean-Christophe PLAGNIOL-VILLARD #  define CONFIG_ENV_SIZE_REDUND	CONFIG_ENV_SIZE
63c609719bSwdenk # endif
646d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # if	(CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) &&		\
65507651d6SIgor Grinberg 	(CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <=			\
66507651d6SIgor Grinberg 	(CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)
676f403badSIgor Grinberg #  define ENV_IS_EMBEDDED
68c609719bSwdenk # endif
690e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
706f403badSIgor Grinberg #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
71c609719bSwdenk # endif
720a9e4e77SMike Frysinger # ifdef CONFIG_ENV_IS_EMBEDDED
730a9e4e77SMike Frysinger #  error "do not define CONFIG_ENV_IS_EMBEDDED in your board config"
740a9e4e77SMike Frysinger #  error "it is calculated automatically for you"
750a9e4e77SMike Frysinger # endif
765a1aceb0SJean-Christophe PLAGNIOL-VILLARD #endif	/* CONFIG_ENV_IS_IN_FLASH */
77c609719bSwdenk 
7851bfee19SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_ENV_IS_IN_NAND)
79c9f7351bSBen Gardiner # if defined(CONFIG_ENV_OFFSET_OOB)
80c9f7351bSBen Gardiner #  ifdef CONFIG_ENV_OFFSET_REDUND
81c9f7351bSBen Gardiner #   error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB"
82c9f7351bSBen Gardiner #   error "is set"
83c9f7351bSBen Gardiner #  endif
84c9f7351bSBen Gardiner extern unsigned long nand_env_oob_offset;
85c9f7351bSBen Gardiner #  define CONFIG_ENV_OFFSET nand_env_oob_offset
86c9f7351bSBen Gardiner # else
870e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifndef CONFIG_ENV_OFFSET
880e8d1586SJean-Christophe PLAGNIOL-VILLARD #   error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND"
89e443c944SMarkus Klotzbuecher #  endif
900e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifdef CONFIG_ENV_OFFSET_REDUND
916d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #   define CONFIG_SYS_REDUNDAND_ENVIRONMENT
92e443c944SMarkus Klotzbuecher #  endif
93c9f7351bSBen Gardiner # endif /* CONFIG_ENV_OFFSET_OOB */
94c9f7351bSBen Gardiner # ifndef CONFIG_ENV_SIZE
95c9f7351bSBen Gardiner #  error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND"
96c9f7351bSBen Gardiner # endif
9751bfee19SJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_ENV_IS_IN_NAND */
98e443c944SMarkus Klotzbuecher 
990a9e4e77SMike Frysinger /* Embedded env is only supported for some flash types */
1000a9e4e77SMike Frysinger #ifdef CONFIG_ENV_IS_EMBEDDED
1010a9e4e77SMike Frysinger # if	!defined(CONFIG_ENV_IS_IN_FLASH)	&& \
1020a9e4e77SMike Frysinger 	!defined(CONFIG_ENV_IS_IN_NAND)		&& \
103efb06339SYoshihiro Shimoda 	!defined(CONFIG_ENV_IS_IN_ONENAND)	&& \
104efb06339SYoshihiro Shimoda 	!defined(CONFIG_ENV_IS_IN_SPI_FLASH)
1050a9e4e77SMike Frysinger #  error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type"
1060a9e4e77SMike Frysinger # endif
1070a9e4e77SMike Frysinger #endif
1080a9e4e77SMike Frysinger 
1090a9e4e77SMike Frysinger /*
1100a9e4e77SMike Frysinger  * For the flash types where embedded env is supported, but it cannot be
1110a9e4e77SMike Frysinger  * calculated automatically (i.e. NAND), take the board opt-in.
1120a9e4e77SMike Frysinger  */
1130a9e4e77SMike Frysinger #if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED)
1146f403badSIgor Grinberg # define ENV_IS_EMBEDDED
1150a9e4e77SMike Frysinger #endif
1160a9e4e77SMike Frysinger 
1170a9e4e77SMike Frysinger /* The build system likes to know if the env is embedded */
1180a9e4e77SMike Frysinger #ifdef DO_DEPS_ONLY
1190a9e4e77SMike Frysinger # ifdef ENV_IS_EMBEDDED
12033a6b9e9SWolfgang Denk #  ifndef CONFIG_ENV_IS_EMBEDDED
1210a9e4e77SMike Frysinger #   define CONFIG_ENV_IS_EMBEDDED
1220a9e4e77SMike Frysinger #  endif
1230a9e4e77SMike Frysinger # endif
12433a6b9e9SWolfgang Denk #endif
1250a9e4e77SMike Frysinger 
12637566090SMike Frysinger #include "compiler.h"
127c609719bSwdenk 
1286d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
12989cdab78SMike Frysinger # define ENV_HEADER_SIZE	(sizeof(uint32_t) + 1)
130b218ccb5SWolfgang Denk 
131b218ccb5SWolfgang Denk # define ACTIVE_FLAG   1
132b218ccb5SWolfgang Denk # define OBSOLETE_FLAG 0
133c609719bSwdenk #else
13489cdab78SMike Frysinger # define ENV_HEADER_SIZE	(sizeof(uint32_t))
135c609719bSwdenk #endif
136c609719bSwdenk 
137d09b1787SIgor Grinberg #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
138d09b1787SIgor Grinberg extern char *env_name_spec;
139d09b1787SIgor Grinberg #endif
140c609719bSwdenk 
1410e8d1586SJean-Christophe PLAGNIOL-VILLARD #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
142c609719bSwdenk 
143c609719bSwdenk typedef struct environment_s {
14489cdab78SMike Frysinger 	uint32_t	crc;		/* CRC32 over data bytes	*/
1456d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
146c609719bSwdenk 	unsigned char	flags;		/* active/obsolete flags	*/
147c609719bSwdenk #endif
148c609719bSwdenk 	unsigned char	data[ENV_SIZE]; /* Environment data		*/
149c609719bSwdenk } env_t;
150c609719bSwdenk 
151994bc671SIgor Grinberg #ifdef ENV_IS_EMBEDDED
152994bc671SIgor Grinberg extern env_t environment;
153994bc671SIgor Grinberg #endif /* ENV_IS_EMBEDDED */
154994bc671SIgor Grinberg 
155d1459f0fSIgor Grinberg extern const unsigned char default_environment[];
15627aafe98SIgor Grinberg extern env_t *env_ptr;
15727aafe98SIgor Grinberg 
15827aafe98SIgor Grinberg extern void env_relocate_spec(void);
15927aafe98SIgor Grinberg extern unsigned char env_get_char_spec(int);
16027aafe98SIgor Grinberg 
16127aafe98SIgor Grinberg #if defined(CONFIG_NEEDS_MANUAL_RELOC)
16227aafe98SIgor Grinberg extern void env_reloc(void);
16327aafe98SIgor Grinberg #endif
164d1459f0fSIgor Grinberg 
1652eb1573fSMike Frysinger #ifndef DO_DEPS_ONLY
1662eb1573fSMike Frysinger 
1672eb1573fSMike Frysinger #include <search.h>
1682eb1573fSMike Frysinger 
1692eb1573fSMike Frysinger extern struct hsearch_data env_htab;
1702eb1573fSMike Frysinger 
171b502611bSJoakim Tjernlund /* Function that returns a character from the environment */
172b502611bSJoakim Tjernlund unsigned char env_get_char(int);
173a8409f4fSWolfgang Denk 
174a8409f4fSWolfgang Denk /* Function that returns a pointer to a value from the environment */
175147c7169SMike Frysinger const unsigned char *env_get_addr(int);
176a8409f4fSWolfgang Denk unsigned char env_get_char_memory(int index);
177a8409f4fSWolfgang Denk 
178a8409f4fSWolfgang Denk /* Function that updates CRC of the enironment */
179a8409f4fSWolfgang Denk void env_crc_update(void);
180a8409f4fSWolfgang Denk 
1815bb12dbdSHarald Welte /* [re]set to the default environment */
182ea882bafSWolfgang Denk void set_default_env(const char *s);
183ea882bafSWolfgang Denk 
184*b64b7c3dSGerlando Falauto /* [re]set individual variables to their value in the default environment */
185*b64b7c3dSGerlando Falauto int set_default_vars(int nvars, char * const vars[]);
186*b64b7c3dSGerlando Falauto 
187ea882bafSWolfgang Denk /* Import from binary representation into hash table */
188ea882bafSWolfgang Denk int env_import(const char *buf, int check);
1895bb12dbdSHarald Welte 
190c5983592SGerlando Falauto /*
191c5983592SGerlando Falauto  * Check if variable "name" can be changed from oldval to newval,
192c5983592SGerlando Falauto  * and if so, apply the changes (e.g. baudrate).
193c5983592SGerlando Falauto  * When (flag & H_FORCE) is set, it does not print out any error
194c5983592SGerlando Falauto  * message and forces overwriting of write-once variables.
195c5983592SGerlando Falauto  */
196c5983592SGerlando Falauto int env_check_apply(const char *name, const char *oldval,
197c5983592SGerlando Falauto 			const char *newval, int flag);
198c5983592SGerlando Falauto 
199507651d6SIgor Grinberg #endif /* DO_DEPS_ONLY */
2002eb1573fSMike Frysinger 
201c609719bSwdenk #endif /* _ENVIRONMENT_H_ */
202