xref: /rk3399_rockchip-uboot/include/environment.h (revision ea882baf9c17cd142c99e3ff640d3ab01daa5cec)
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_
25c609719bSwdenk #define _ENVIRONMENT_H_	1
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)
486d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #  define CONFIG_ENV_ADDR_REDUND	(CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
49c609719bSwdenk # endif
500e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE)
510e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifndef  CONFIG_ENV_SECT_SIZE
520e8d1586SJean-Christophe PLAGNIOL-VILLARD #   define CONFIG_ENV_SECT_SIZE	CONFIG_ENV_SIZE
53500545ccSwdenk #  endif
540e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifndef  CONFIG_ENV_SIZE
550e8d1586SJean-Christophe PLAGNIOL-VILLARD #   define CONFIG_ENV_SIZE	CONFIG_ENV_SECT_SIZE
56c609719bSwdenk #  endif
57500545ccSwdenk # else
580e8d1586SJean-Christophe PLAGNIOL-VILLARD #  error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined"
59500545ccSwdenk # endif
600e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
610e8d1586SJean-Christophe PLAGNIOL-VILLARD #  define CONFIG_ENV_SIZE_REDUND	CONFIG_ENV_SIZE
62c609719bSwdenk # endif
636d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
646d0f6bcfSJean-Christophe PLAGNIOL-VILLARD      (CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) <= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)
65c609719bSwdenk #  define ENV_IS_EMBEDDED	1
66c609719bSwdenk # endif
670e8d1586SJean-Christophe PLAGNIOL-VILLARD # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
686d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT	1
69c609719bSwdenk # endif
700a9e4e77SMike Frysinger # ifdef CONFIG_ENV_IS_EMBEDDED
710a9e4e77SMike Frysinger #  error "do not define CONFIG_ENV_IS_EMBEDDED in your board config"
720a9e4e77SMike Frysinger #  error "it is calculated automatically for you"
730a9e4e77SMike Frysinger # endif
745a1aceb0SJean-Christophe PLAGNIOL-VILLARD #endif	/* CONFIG_ENV_IS_IN_FLASH */
75c609719bSwdenk 
7651bfee19SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_ENV_IS_IN_NAND)
77c9f7351bSBen Gardiner # if defined(CONFIG_ENV_OFFSET_OOB)
78c9f7351bSBen Gardiner #  ifdef CONFIG_ENV_OFFSET_REDUND
79c9f7351bSBen Gardiner #   error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB"
80c9f7351bSBen Gardiner #   error "is set"
81c9f7351bSBen Gardiner #  endif
82c9f7351bSBen Gardiner extern unsigned long nand_env_oob_offset;
83c9f7351bSBen Gardiner #  define CONFIG_ENV_OFFSET nand_env_oob_offset
84c9f7351bSBen Gardiner # else
850e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifndef CONFIG_ENV_OFFSET
860e8d1586SJean-Christophe PLAGNIOL-VILLARD #   error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND"
87e443c944SMarkus Klotzbuecher #  endif
880e8d1586SJean-Christophe PLAGNIOL-VILLARD #  ifdef CONFIG_ENV_OFFSET_REDUND
896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #   define CONFIG_SYS_REDUNDAND_ENVIRONMENT
90e443c944SMarkus Klotzbuecher #  endif
91c9f7351bSBen Gardiner # endif /* CONFIG_ENV_OFFSET_OOB */
92c9f7351bSBen Gardiner # ifndef CONFIG_ENV_SIZE
93c9f7351bSBen Gardiner #  error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND"
94c9f7351bSBen Gardiner # endif
9551bfee19SJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_ENV_IS_IN_NAND */
96e443c944SMarkus Klotzbuecher 
9775eb82ecSunsik Kim #if defined(CONFIG_ENV_IS_IN_MG_DISK)
9875eb82ecSunsik Kim # ifndef CONFIG_ENV_ADDR
9975eb82ecSunsik Kim #  error "Need to define CONFIG_ENV_ADDR when using CONFIG_ENV_IS_IN_MG_DISK"
10075eb82ecSunsik Kim # endif
10175eb82ecSunsik Kim # ifndef CONFIG_ENV_SIZE
10275eb82ecSunsik Kim #  error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_MG_DISK"
10375eb82ecSunsik Kim # endif
10475eb82ecSunsik Kim #endif /* CONFIG_ENV_IS_IN_MG_DISK */
10575eb82ecSunsik Kim 
1060a9e4e77SMike Frysinger /* Embedded env is only supported for some flash types */
1070a9e4e77SMike Frysinger #ifdef CONFIG_ENV_IS_EMBEDDED
1080a9e4e77SMike Frysinger # if !defined(CONFIG_ENV_IS_IN_FLASH) && \
1090a9e4e77SMike Frysinger      !defined(CONFIG_ENV_IS_IN_NAND) && \
1100a9e4e77SMike Frysinger      !defined(CONFIG_ENV_IS_IN_ONENAND)
1110a9e4e77SMike Frysinger #  error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type"
1120a9e4e77SMike Frysinger # endif
1130a9e4e77SMike Frysinger #endif
1140a9e4e77SMike Frysinger 
1150a9e4e77SMike Frysinger /*
1160a9e4e77SMike Frysinger  * For the flash types where embedded env is supported, but it cannot be
1170a9e4e77SMike Frysinger  * calculated automatically (i.e. NAND), take the board opt-in.
1180a9e4e77SMike Frysinger  */
1190a9e4e77SMike Frysinger #if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED)
1200a9e4e77SMike Frysinger # define ENV_IS_EMBEDDED 1
1210a9e4e77SMike Frysinger #endif
1220a9e4e77SMike Frysinger 
1230a9e4e77SMike Frysinger /* The build system likes to know if the env is embedded */
1240a9e4e77SMike Frysinger #ifdef DO_DEPS_ONLY
1250a9e4e77SMike Frysinger # ifdef ENV_IS_EMBEDDED
1260a9e4e77SMike Frysinger #  define CONFIG_ENV_IS_EMBEDDED
1270a9e4e77SMike Frysinger # endif
1280a9e4e77SMike Frysinger #endif
1290a9e4e77SMike Frysinger 
13037566090SMike Frysinger #include "compiler.h"
131c609719bSwdenk 
1326d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
13389cdab78SMike Frysinger # define ENV_HEADER_SIZE	(sizeof(uint32_t) + 1)
134b218ccb5SWolfgang Denk 
135b218ccb5SWolfgang Denk # define ACTIVE_FLAG   1
136b218ccb5SWolfgang Denk # define OBSOLETE_FLAG 0
137c609719bSwdenk #else
13889cdab78SMike Frysinger # define ENV_HEADER_SIZE	(sizeof(uint32_t))
139c609719bSwdenk #endif
140c609719bSwdenk 
141c609719bSwdenk 
1420e8d1586SJean-Christophe PLAGNIOL-VILLARD #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
143c609719bSwdenk 
144c609719bSwdenk typedef	struct environment_s {
14589cdab78SMike Frysinger 	uint32_t	crc;		/* CRC32 over data bytes	*/
1466d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
147c609719bSwdenk 	unsigned char	flags;		/* active/obsolete flags	*/
148c609719bSwdenk #endif
149c609719bSwdenk 	unsigned char	data[ENV_SIZE]; /* Environment data		*/
150c609719bSwdenk } env_t;
151c609719bSwdenk 
152b502611bSJoakim Tjernlund /* Function that returns a character from the environment */
153b502611bSJoakim Tjernlund unsigned char env_get_char (int);
154a8409f4fSWolfgang Denk 
155a8409f4fSWolfgang Denk /* Function that returns a pointer to a value from the environment */
156a8409f4fSWolfgang Denk unsigned char *env_get_addr(int);
157a8409f4fSWolfgang Denk unsigned char env_get_char_memory (int index);
158a8409f4fSWolfgang Denk 
159a8409f4fSWolfgang Denk /* Function that updates CRC of the enironment */
160a8409f4fSWolfgang Denk void env_crc_update (void);
161a8409f4fSWolfgang Denk 
1625bb12dbdSHarald Welte /* [re]set to the default environment */
163*ea882bafSWolfgang Denk void set_default_env(const char *s);
164*ea882bafSWolfgang Denk 
165*ea882bafSWolfgang Denk /* Import from binary representation into hash table */
166*ea882bafSWolfgang Denk int env_import(const char *buf, int check);
1675bb12dbdSHarald Welte 
168c609719bSwdenk #endif	/* _ENVIRONMENT_H_ */
169