Blame view
include/environment.h
6.59 KB
c609719b8
|
1 2 3 4 |
/* * (C) Copyright 2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601
|
5 |
* SPDX-License-Identifier: GPL-2.0+ |
c609719b8
|
6 7 8 |
*/ #ifndef _ENVIRONMENT_H_ |
6f403bad8
|
9 |
#define _ENVIRONMENT_H_ |
c609719b8
|
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
|
19 |
* The environment is preceded by a 32 bit CRC over the data part. |
c609719b8
|
20 |
* |
fc0b5948e
|
21 |
*************************************************************************/ |
c609719b8
|
22 |
|
5a1aceb06
|
23 |
#if defined(CONFIG_ENV_IS_IN_FLASH) |
507651d61
|
24 25 |
# ifndef CONFIG_ENV_ADDR # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) |
c609719b8
|
26 |
# endif |
507651d61
|
27 28 |
# ifndef CONFIG_ENV_OFFSET # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE) |
c609719b8
|
29 |
# endif |
0e8d15866
|
30 |
# if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND) |
507651d61
|
31 32 |
# define CONFIG_ENV_ADDR_REDUND \ (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND) |
c609719b8
|
33 |
# endif |
0e8d15866
|
34 |
# if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE) |
507651d61
|
35 36 |
# ifndef CONFIG_ENV_SECT_SIZE # define CONFIG_ENV_SECT_SIZE CONFIG_ENV_SIZE |
500545cc6
|
37 |
# endif |
507651d61
|
38 39 |
# ifndef CONFIG_ENV_SIZE # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE |
500545cc6
|
40 41 |
# endif # else |
0e8d15866
|
42 |
# error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined" |
c609719b8
|
43 |
# endif |
0e8d15866
|
44 45 |
# if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND) # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE |
c609719b8
|
46 |
# endif |
507651d61
|
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
|
50 |
# define ENV_IS_EMBEDDED |
c609719b8
|
51 |
# endif |
0e8d15866
|
52 |
# if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) |
6f403bad8
|
53 |
# define CONFIG_SYS_REDUNDAND_ENVIRONMENT |
c609719b8
|
54 |
# endif |
0a9e4e772
|
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
|
59 |
#endif /* CONFIG_ENV_IS_IN_FLASH */ |
c609719b8
|
60 |
|
5707df779
|
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
|
66 |
#if defined(CONFIG_ENV_IS_IN_NAND) |
c9f7351b5
|
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
|
82 83 |
# ifndef CONFIG_ENV_SIZE # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND" |
e443c944c
|
84 |
# endif |
51bfee192
|
85 |
#endif /* CONFIG_ENV_IS_IN_NAND */ |
e443c944c
|
86 |
|
2b74433f3
|
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
|
94 95 96 |
# if defined(CONFIG_ENV_UBI_VOLUME_REDUND) # define CONFIG_SYS_REDUNDAND_ENVIRONMENT # endif |
2b74433f3
|
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
|
104 105 |
/* Embedded env is only supported for some flash types */ #ifdef CONFIG_ENV_IS_EMBEDDED |
507651d61
|
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
|
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
|
119 |
# define ENV_IS_EMBEDDED |
0a9e4e772
|
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
|
125 126 127 |
# ifndef CONFIG_ENV_IS_EMBEDDED # define CONFIG_ENV_IS_EMBEDDED # endif |
0a9e4e772
|
128 129 |
# endif #endif |
375660907
|
130 |
#include "compiler.h" |
c609719b8
|
131 |
|
6d0f6bcf3
|
132 |
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT |
89cdab788
|
133 |
# define ENV_HEADER_SIZE (sizeof(uint32_t) + 1) |
b218ccb54
|
134 135 136 |
# define ACTIVE_FLAG 1 # define OBSOLETE_FLAG 0 |
c609719b8
|
137 |
#else |
89cdab788
|
138 |
# define ENV_HEADER_SIZE (sizeof(uint32_t)) |
c609719b8
|
139 |
#endif |
d09b1787a
|
140 141 142 |
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) extern char *env_name_spec; #endif |
c609719b8
|
143 |
|
a4223b746
|
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
|
148 |
#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) |
a4223b746
|
149 |
#endif |
c609719b8
|
150 |
|
507651d61
|
151 |
typedef struct environment_s { |
89cdab788
|
152 |
uint32_t crc; /* CRC32 over data bytes */ |
6d0f6bcf3
|
153 |
#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT |
c609719b8
|
154 155 156 |
unsigned char flags; /* active/obsolete flags */ #endif unsigned char data[ENV_SIZE]; /* Environment data */ |
a4223b746
|
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
|
163 |
|
994bc671c
|
164 165 166 |
#ifdef ENV_IS_EMBEDDED extern env_t environment; #endif /* ENV_IS_EMBEDDED */ |
d1459f0fa
|
167 |
extern const unsigned char default_environment[]; |
27aafe988
|
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
|
176 |
|
ac77f42d0
|
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
|
181 182 183 |
# ifdef CONFIG_SYS_MMC_ENV_PART extern uint mmc_get_env_part(struct mmc *mmc); # endif |
ac77f42d0
|
184 |
#endif |
2eb1573f0
|
185 |
#ifndef DO_DEPS_ONLY |
170ab1107
|
186 187 |
#include <env_attr.h> #include <env_callback.h> |
2598090b7
|
188 |
#include <env_flags.h> |
2eb1573f0
|
189 190 191 |
#include <search.h> extern struct hsearch_data env_htab; |
b502611b5
|
192 |
/* Function that returns a character from the environment */ |
507651d61
|
193 |
unsigned char env_get_char(int); |
a8409f4f1
|
194 195 |
/* Function that returns a pointer to a value from the environment */ |
147c7169e
|
196 |
const unsigned char *env_get_addr(int); |
507651d61
|
197 |
unsigned char env_get_char_memory(int index); |
a8409f4f1
|
198 199 |
/* Function that updates CRC of the enironment */ |
507651d61
|
200 |
void env_crc_update(void); |
a8409f4f1
|
201 |
|
267541f77
|
202 203 |
/* Look up the variable from the default environment */ char *getenv_default(const char *name); |
5bb12dbd7
|
204 |
/* [re]set to the default environment */ |
ea882baf9
|
205 |
void set_default_env(const char *s); |
b64b7c3df
|
206 207 |
/* [re]set individual variables to their value in the default environment */ int set_default_vars(int nvars, char * const vars[]); |
ea882baf9
|
208 209 |
/* Import from binary representation into hash table */ int env_import(const char *buf, int check); |
5bb12dbd7
|
210 |
|
7ce1526ed
|
211 212 |
/* Export from hash table into binary representation */ int env_export(env_t *env_out); |
507651d61
|
213 |
#endif /* DO_DEPS_ONLY */ |
2eb1573f0
|
214 |
|
507651d61
|
215 |
#endif /* _ENVIRONMENT_H_ */ |