Commit e1caa5841e8a9bc0ee658bdacae0519fa28e1e6a

Authored by York Sun
Committed by Tom Rini
1 parent 32fe36574e

env: Fix env_load_location

Commit 7d714a24d725 ("env: Support multiple environments") added
static variable env_load_location. When saving environmental
variables, this variable is presumed to have the value set before.
In case the value was set before relocation and U-Boot runs from a
NOR flash, this variable wasn't writable. This causes failure when
saving the environment. To save this location, global data must be
used instead.

Signed-off-by: York Sun <york.sun@nxp.com>
CC: Maxime Ripard <maxime.ripard@free-electrons.com>

Showing 3 changed files with 5 additions and 6 deletions Inline Diff

1 /* 1 /*
2 * Copyright (C) 2017 Google, Inc 2 * Copyright (C) 2017 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org> 3 * Written by Simon Glass <sjg@chromium.org>
4 * 4 *
5 * SPDX-License-Identifier: GPL-2.0+ 5 * SPDX-License-Identifier: GPL-2.0+
6 */ 6 */
7 7
8 #include <common.h> 8 #include <common.h>
9 #include <environment.h> 9 #include <environment.h>
10 10
11 DECLARE_GLOBAL_DATA_PTR; 11 DECLARE_GLOBAL_DATA_PTR;
12 12
13 static struct env_driver *_env_driver_lookup(enum env_location loc) 13 static struct env_driver *_env_driver_lookup(enum env_location loc)
14 { 14 {
15 struct env_driver *drv; 15 struct env_driver *drv;
16 const int n_ents = ll_entry_count(struct env_driver, env_driver); 16 const int n_ents = ll_entry_count(struct env_driver, env_driver);
17 struct env_driver *entry; 17 struct env_driver *entry;
18 18
19 drv = ll_entry_start(struct env_driver, env_driver); 19 drv = ll_entry_start(struct env_driver, env_driver);
20 for (entry = drv; entry != drv + n_ents; entry++) { 20 for (entry = drv; entry != drv + n_ents; entry++) {
21 if (loc == entry->location) 21 if (loc == entry->location)
22 return entry; 22 return entry;
23 } 23 }
24 24
25 /* Not found */ 25 /* Not found */
26 return NULL; 26 return NULL;
27 } 27 }
28 28
29 static enum env_location env_locations[] = { 29 static enum env_location env_locations[] = {
30 #ifdef CONFIG_ENV_IS_IN_EEPROM 30 #ifdef CONFIG_ENV_IS_IN_EEPROM
31 ENVL_EEPROM, 31 ENVL_EEPROM,
32 #endif 32 #endif
33 #ifdef CONFIG_ENV_IS_IN_EXT4 33 #ifdef CONFIG_ENV_IS_IN_EXT4
34 ENVL_EXT4, 34 ENVL_EXT4,
35 #endif 35 #endif
36 #ifdef CONFIG_ENV_IS_IN_FAT 36 #ifdef CONFIG_ENV_IS_IN_FAT
37 ENVL_FAT, 37 ENVL_FAT,
38 #endif 38 #endif
39 #ifdef CONFIG_ENV_IS_IN_FLASH 39 #ifdef CONFIG_ENV_IS_IN_FLASH
40 ENVL_FLASH, 40 ENVL_FLASH,
41 #endif 41 #endif
42 #ifdef CONFIG_ENV_IS_IN_MMC 42 #ifdef CONFIG_ENV_IS_IN_MMC
43 ENVL_MMC, 43 ENVL_MMC,
44 #endif 44 #endif
45 #ifdef CONFIG_ENV_IS_IN_NAND 45 #ifdef CONFIG_ENV_IS_IN_NAND
46 ENVL_NAND, 46 ENVL_NAND,
47 #endif 47 #endif
48 #ifdef CONFIG_ENV_IS_IN_NVRAM 48 #ifdef CONFIG_ENV_IS_IN_NVRAM
49 ENVL_NVRAM, 49 ENVL_NVRAM,
50 #endif 50 #endif
51 #ifdef CONFIG_ENV_IS_IN_REMOTE 51 #ifdef CONFIG_ENV_IS_IN_REMOTE
52 ENVL_REMOTE, 52 ENVL_REMOTE,
53 #endif 53 #endif
54 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH 54 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
55 ENVL_SPI_FLASH, 55 ENVL_SPI_FLASH,
56 #endif 56 #endif
57 #ifdef CONFIG_ENV_IS_IN_UBI 57 #ifdef CONFIG_ENV_IS_IN_UBI
58 ENVL_UBI, 58 ENVL_UBI,
59 #endif 59 #endif
60 #ifdef CONFIG_ENV_IS_NOWHERE 60 #ifdef CONFIG_ENV_IS_NOWHERE
61 ENVL_NOWHERE, 61 ENVL_NOWHERE,
62 #endif 62 #endif
63 }; 63 };
64 64
65 static enum env_location env_load_location = ENVL_UNKNOWN;
66
67 static bool env_has_inited(enum env_location location) 65 static bool env_has_inited(enum env_location location)
68 { 66 {
69 return gd->env_has_init & BIT(location); 67 return gd->env_has_init & BIT(location);
70 } 68 }
71 69
72 static void env_set_inited(enum env_location location) 70 static void env_set_inited(enum env_location location)
73 { 71 {
74 /* 72 /*
75 * We're using a 32-bits bitmask stored in gd (env_has_init) 73 * We're using a 32-bits bitmask stored in gd (env_has_init)
76 * using the above enum value as the bit index. We need to 74 * using the above enum value as the bit index. We need to
77 * make sure that we're not overflowing it. 75 * make sure that we're not overflowing it.
78 */ 76 */
79 BUILD_BUG_ON(ARRAY_SIZE(env_locations) > BITS_PER_LONG); 77 BUILD_BUG_ON(ARRAY_SIZE(env_locations) > BITS_PER_LONG);
80 78
81 gd->env_has_init |= BIT(location); 79 gd->env_has_init |= BIT(location);
82 } 80 }
83 81
84 /** 82 /**
85 * env_get_location() - Returns the best env location for a board 83 * env_get_location() - Returns the best env location for a board
86 * @op: operations performed on the environment 84 * @op: operations performed on the environment
87 * @prio: priority between the multiple environments, 0 being the 85 * @prio: priority between the multiple environments, 0 being the
88 * highest priority 86 * highest priority
89 * 87 *
90 * This will return the preferred environment for the given priority. 88 * This will return the preferred environment for the given priority.
91 * This is overridable by boards if they need to. 89 * This is overridable by boards if they need to.
92 * 90 *
93 * All implementations are free to use the operation, the priority and 91 * All implementations are free to use the operation, the priority and
94 * any other data relevant to their choice, but must take into account 92 * any other data relevant to their choice, but must take into account
95 * the fact that the lowest prority (0) is the most important location 93 * the fact that the lowest prority (0) is the most important location
96 * in the system. The following locations should be returned by order 94 * in the system. The following locations should be returned by order
97 * of descending priorities, from the highest to the lowest priority. 95 * of descending priorities, from the highest to the lowest priority.
98 * 96 *
99 * Returns: 97 * Returns:
100 * an enum env_location value on success, a negative error code otherwise 98 * an enum env_location value on success, a negative error code otherwise
101 */ 99 */
102 __weak enum env_location env_get_location(enum env_operation op, int prio) 100 __weak enum env_location env_get_location(enum env_operation op, int prio)
103 { 101 {
104 switch (op) { 102 switch (op) {
105 case ENVOP_GET_CHAR: 103 case ENVOP_GET_CHAR:
106 case ENVOP_INIT: 104 case ENVOP_INIT:
107 case ENVOP_LOAD: 105 case ENVOP_LOAD:
108 if (prio >= ARRAY_SIZE(env_locations)) 106 if (prio >= ARRAY_SIZE(env_locations))
109 return ENVL_UNKNOWN; 107 return ENVL_UNKNOWN;
110 108
111 env_load_location = env_locations[prio]; 109 gd->env_load_location = env_locations[prio];
112 return env_load_location; 110 return gd->env_load_location;
113 111
114 case ENVOP_SAVE: 112 case ENVOP_SAVE:
115 return env_load_location; 113 return gd->env_load_location;
116 } 114 }
117 115
118 return ENVL_UNKNOWN; 116 return ENVL_UNKNOWN;
119 } 117 }
120 118
121 119
122 /** 120 /**
123 * env_driver_lookup() - Finds the most suited environment location 121 * env_driver_lookup() - Finds the most suited environment location
124 * @op: operations performed on the environment 122 * @op: operations performed on the environment
125 * @prio: priority between the multiple environments, 0 being the 123 * @prio: priority between the multiple environments, 0 being the
126 * highest priority 124 * highest priority
127 * 125 *
128 * This will try to find the available environment with the highest 126 * This will try to find the available environment with the highest
129 * priority in the system. 127 * priority in the system.
130 * 128 *
131 * Returns: 129 * Returns:
132 * NULL on error, a pointer to a struct env_driver otherwise 130 * NULL on error, a pointer to a struct env_driver otherwise
133 */ 131 */
134 static struct env_driver *env_driver_lookup(enum env_operation op, int prio) 132 static struct env_driver *env_driver_lookup(enum env_operation op, int prio)
135 { 133 {
136 enum env_location loc = env_get_location(op, prio); 134 enum env_location loc = env_get_location(op, prio);
137 struct env_driver *drv; 135 struct env_driver *drv;
138 136
139 if (loc == ENVL_UNKNOWN) 137 if (loc == ENVL_UNKNOWN)
140 return NULL; 138 return NULL;
141 139
142 drv = _env_driver_lookup(loc); 140 drv = _env_driver_lookup(loc);
143 if (!drv) { 141 if (!drv) {
144 debug("%s: No environment driver for location %d\n", __func__, 142 debug("%s: No environment driver for location %d\n", __func__,
145 loc); 143 loc);
146 return NULL; 144 return NULL;
147 } 145 }
148 146
149 return drv; 147 return drv;
150 } 148 }
151 149
152 int env_get_char(int index) 150 int env_get_char(int index)
153 { 151 {
154 struct env_driver *drv; 152 struct env_driver *drv;
155 int prio; 153 int prio;
156 154
157 if (gd->env_valid == ENV_INVALID) 155 if (gd->env_valid == ENV_INVALID)
158 return default_environment[index]; 156 return default_environment[index];
159 157
160 for (prio = 0; (drv = env_driver_lookup(ENVOP_GET_CHAR, prio)); prio++) { 158 for (prio = 0; (drv = env_driver_lookup(ENVOP_GET_CHAR, prio)); prio++) {
161 int ret; 159 int ret;
162 160
163 if (!drv->get_char) 161 if (!drv->get_char)
164 continue; 162 continue;
165 163
166 if (!env_has_inited(drv->location)) 164 if (!env_has_inited(drv->location))
167 continue; 165 continue;
168 166
169 ret = drv->get_char(index); 167 ret = drv->get_char(index);
170 if (!ret) 168 if (!ret)
171 return 0; 169 return 0;
172 170
173 debug("%s: Environment %s failed to load (err=%d)\n", __func__, 171 debug("%s: Environment %s failed to load (err=%d)\n", __func__,
174 drv->name, ret); 172 drv->name, ret);
175 } 173 }
176 174
177 return -ENODEV; 175 return -ENODEV;
178 } 176 }
179 177
180 int env_load(void) 178 int env_load(void)
181 { 179 {
182 struct env_driver *drv; 180 struct env_driver *drv;
183 int prio; 181 int prio;
184 182
185 for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) { 183 for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) {
186 int ret; 184 int ret;
187 185
188 if (!drv->load) 186 if (!drv->load)
189 continue; 187 continue;
190 188
191 if (!env_has_inited(drv->location)) 189 if (!env_has_inited(drv->location))
192 continue; 190 continue;
193 191
194 printf("Loading Environment from %s... ", drv->name); 192 printf("Loading Environment from %s... ", drv->name);
195 ret = drv->load(); 193 ret = drv->load();
196 if (ret) 194 if (ret)
197 printf("Failed (%d)\n", ret); 195 printf("Failed (%d)\n", ret);
198 else 196 else
199 printf("OK\n"); 197 printf("OK\n");
200 198
201 if (!ret) 199 if (!ret)
202 return 0; 200 return 0;
203 } 201 }
204 202
205 return -ENODEV; 203 return -ENODEV;
206 } 204 }
207 205
208 int env_save(void) 206 int env_save(void)
209 { 207 {
210 struct env_driver *drv; 208 struct env_driver *drv;
211 int prio; 209 int prio;
212 210
213 for (prio = 0; (drv = env_driver_lookup(ENVOP_SAVE, prio)); prio++) { 211 for (prio = 0; (drv = env_driver_lookup(ENVOP_SAVE, prio)); prio++) {
214 int ret; 212 int ret;
215 213
216 if (!drv->save) 214 if (!drv->save)
217 continue; 215 continue;
218 216
219 if (!env_has_inited(drv->location)) 217 if (!env_has_inited(drv->location))
220 continue; 218 continue;
221 219
222 printf("Saving Environment to %s... ", drv->name); 220 printf("Saving Environment to %s... ", drv->name);
223 ret = drv->save(); 221 ret = drv->save();
224 if (ret) 222 if (ret)
225 printf("Failed (%d)\n", ret); 223 printf("Failed (%d)\n", ret);
226 else 224 else
227 printf("OK\n"); 225 printf("OK\n");
228 226
229 if (!ret) 227 if (!ret)
230 return 0; 228 return 0;
231 } 229 }
232 230
233 return -ENODEV; 231 return -ENODEV;
234 } 232 }
235 233
236 int env_init(void) 234 int env_init(void)
237 { 235 {
238 struct env_driver *drv; 236 struct env_driver *drv;
239 int ret = -ENOENT; 237 int ret = -ENOENT;
240 int prio; 238 int prio;
241 239
242 for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) { 240 for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
243 if (!drv->init || !(ret = drv->init())) 241 if (!drv->init || !(ret = drv->init()))
244 env_set_inited(drv->location); 242 env_set_inited(drv->location);
245 243
246 debug("%s: Environment %s init done (ret=%d)\n", __func__, 244 debug("%s: Environment %s init done (ret=%d)\n", __func__,
247 drv->name, ret); 245 drv->name, ret);
248 } 246 }
249 247
250 if (!prio) 248 if (!prio)
251 return -ENODEV; 249 return -ENODEV;
252 250
253 if (ret == -ENOENT) { 251 if (ret == -ENOENT) {
254 gd->env_addr = (ulong)&default_environment[0]; 252 gd->env_addr = (ulong)&default_environment[0];
255 gd->env_valid = ENV_VALID; 253 gd->env_valid = ENV_VALID;
256 254
257 return 0; 255 return 0;
258 } 256 }
259 257
260 return ret; 258 return ret;
261 } 259 }
262 260
include/asm-generic/global_data.h
1 /* 1 /*
2 * Copyright (c) 2012 The Chromium OS Authors. 2 * Copyright (c) 2012 The Chromium OS Authors.
3 * (C) Copyright 2002-2010 3 * (C) Copyright 2002-2010
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * 5 *
6 * SPDX-License-Identifier: GPL-2.0+ 6 * SPDX-License-Identifier: GPL-2.0+
7 */ 7 */
8 8
9 #ifndef __ASM_GENERIC_GBL_DATA_H 9 #ifndef __ASM_GENERIC_GBL_DATA_H
10 #define __ASM_GENERIC_GBL_DATA_H 10 #define __ASM_GENERIC_GBL_DATA_H
11 /* 11 /*
12 * The following data structure is placed in some memory which is 12 * The following data structure is placed in some memory which is
13 * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or 13 * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
14 * some locked parts of the data cache) to allow for a minimum set of 14 * some locked parts of the data cache) to allow for a minimum set of
15 * global variables during system initialization (until we have set 15 * global variables during system initialization (until we have set
16 * up the memory controller so that we can use RAM). 16 * up the memory controller so that we can use RAM).
17 * 17 *
18 * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t) 18 * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t)
19 * 19 *
20 * Each architecture has its own private fields. For now all are private 20 * Each architecture has its own private fields. For now all are private
21 */ 21 */
22 22
23 #ifndef __ASSEMBLY__ 23 #ifndef __ASSEMBLY__
24 #include <membuff.h> 24 #include <membuff.h>
25 #include <linux/list.h> 25 #include <linux/list.h>
26 26
27 typedef struct global_data { 27 typedef struct global_data {
28 bd_t *bd; 28 bd_t *bd;
29 unsigned long flags; 29 unsigned long flags;
30 unsigned int baudrate; 30 unsigned int baudrate;
31 unsigned long cpu_clk; /* CPU clock in Hz! */ 31 unsigned long cpu_clk; /* CPU clock in Hz! */
32 unsigned long bus_clk; 32 unsigned long bus_clk;
33 /* We cannot bracket this with CONFIG_PCI due to mpc5xxx */ 33 /* We cannot bracket this with CONFIG_PCI due to mpc5xxx */
34 unsigned long pci_clk; 34 unsigned long pci_clk;
35 unsigned long mem_clk; 35 unsigned long mem_clk;
36 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 36 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
37 unsigned long fb_base; /* Base address of framebuffer mem */ 37 unsigned long fb_base; /* Base address of framebuffer mem */
38 #endif 38 #endif
39 #if defined(CONFIG_POST) 39 #if defined(CONFIG_POST)
40 unsigned long post_log_word; /* Record POST activities */ 40 unsigned long post_log_word; /* Record POST activities */
41 unsigned long post_log_res; /* success of POST test */ 41 unsigned long post_log_res; /* success of POST test */
42 unsigned long post_init_f_time; /* When post_init_f started */ 42 unsigned long post_init_f_time; /* When post_init_f started */
43 #endif 43 #endif
44 #ifdef CONFIG_BOARD_TYPES 44 #ifdef CONFIG_BOARD_TYPES
45 unsigned long board_type; 45 unsigned long board_type;
46 #endif 46 #endif
47 unsigned long have_console; /* serial_init() was called */ 47 unsigned long have_console; /* serial_init() was called */
48 #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) 48 #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
49 unsigned long precon_buf_idx; /* Pre-Console buffer index */ 49 unsigned long precon_buf_idx; /* Pre-Console buffer index */
50 #endif 50 #endif
51 unsigned long env_addr; /* Address of Environment struct */ 51 unsigned long env_addr; /* Address of Environment struct */
52 unsigned long env_valid; /* Environment valid? enum env_valid */ 52 unsigned long env_valid; /* Environment valid? enum env_valid */
53 unsigned long env_has_init; /* Bitmask of boolean of struct env_location offsets */ 53 unsigned long env_has_init; /* Bitmask of boolean of struct env_location offsets */
54 int env_load_location;
54 55
55 unsigned long ram_top; /* Top address of RAM used by U-Boot */ 56 unsigned long ram_top; /* Top address of RAM used by U-Boot */
56 unsigned long relocaddr; /* Start address of U-Boot in RAM */ 57 unsigned long relocaddr; /* Start address of U-Boot in RAM */
57 phys_size_t ram_size; /* RAM size */ 58 phys_size_t ram_size; /* RAM size */
58 unsigned long mon_len; /* monitor len */ 59 unsigned long mon_len; /* monitor len */
59 unsigned long irq_sp; /* irq stack pointer */ 60 unsigned long irq_sp; /* irq stack pointer */
60 unsigned long start_addr_sp; /* start_addr_stackpointer */ 61 unsigned long start_addr_sp; /* start_addr_stackpointer */
61 unsigned long reloc_off; 62 unsigned long reloc_off;
62 struct global_data *new_gd; /* relocated global data */ 63 struct global_data *new_gd; /* relocated global data */
63 64
64 #ifdef CONFIG_DM 65 #ifdef CONFIG_DM
65 struct udevice *dm_root; /* Root instance for Driver Model */ 66 struct udevice *dm_root; /* Root instance for Driver Model */
66 struct udevice *dm_root_f; /* Pre-relocation root instance */ 67 struct udevice *dm_root_f; /* Pre-relocation root instance */
67 struct list_head uclass_root; /* Head of core tree */ 68 struct list_head uclass_root; /* Head of core tree */
68 #endif 69 #endif
69 #ifdef CONFIG_TIMER 70 #ifdef CONFIG_TIMER
70 struct udevice *timer; /* Timer instance for Driver Model */ 71 struct udevice *timer; /* Timer instance for Driver Model */
71 #endif 72 #endif
72 73
73 const void *fdt_blob; /* Our device tree, NULL if none */ 74 const void *fdt_blob; /* Our device tree, NULL if none */
74 void *new_fdt; /* Relocated FDT */ 75 void *new_fdt; /* Relocated FDT */
75 unsigned long fdt_size; /* Space reserved for relocated FDT */ 76 unsigned long fdt_size; /* Space reserved for relocated FDT */
76 #ifdef CONFIG_OF_LIVE 77 #ifdef CONFIG_OF_LIVE
77 struct device_node *of_root; 78 struct device_node *of_root;
78 #endif 79 #endif
79 struct jt_funcs *jt; /* jump table */ 80 struct jt_funcs *jt; /* jump table */
80 char env_buf[32]; /* buffer for env_get() before reloc. */ 81 char env_buf[32]; /* buffer for env_get() before reloc. */
81 #ifdef CONFIG_TRACE 82 #ifdef CONFIG_TRACE
82 void *trace_buff; /* The trace buffer */ 83 void *trace_buff; /* The trace buffer */
83 #endif 84 #endif
84 #if defined(CONFIG_SYS_I2C) 85 #if defined(CONFIG_SYS_I2C)
85 int cur_i2c_bus; /* current used i2c bus */ 86 int cur_i2c_bus; /* current used i2c bus */
86 #endif 87 #endif
87 #ifdef CONFIG_SYS_I2C_MXC 88 #ifdef CONFIG_SYS_I2C_MXC
88 void *srdata[10]; 89 void *srdata[10];
89 #endif 90 #endif
90 unsigned int timebase_h; 91 unsigned int timebase_h;
91 unsigned int timebase_l; 92 unsigned int timebase_l;
92 #if CONFIG_VAL(SYS_MALLOC_F_LEN) 93 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
93 unsigned long malloc_base; /* base address of early malloc() */ 94 unsigned long malloc_base; /* base address of early malloc() */
94 unsigned long malloc_limit; /* limit address */ 95 unsigned long malloc_limit; /* limit address */
95 unsigned long malloc_ptr; /* current address */ 96 unsigned long malloc_ptr; /* current address */
96 #endif 97 #endif
97 #ifdef CONFIG_PCI 98 #ifdef CONFIG_PCI
98 struct pci_controller *hose; /* PCI hose for early use */ 99 struct pci_controller *hose; /* PCI hose for early use */
99 phys_addr_t pci_ram_top; /* top of region accessible to PCI */ 100 phys_addr_t pci_ram_top; /* top of region accessible to PCI */
100 #endif 101 #endif
101 #ifdef CONFIG_PCI_BOOTDELAY 102 #ifdef CONFIG_PCI_BOOTDELAY
102 int pcidelay_done; 103 int pcidelay_done;
103 #endif 104 #endif
104 struct udevice *cur_serial_dev; /* current serial device */ 105 struct udevice *cur_serial_dev; /* current serial device */
105 struct arch_global_data arch; /* architecture-specific data */ 106 struct arch_global_data arch; /* architecture-specific data */
106 #ifdef CONFIG_CONSOLE_RECORD 107 #ifdef CONFIG_CONSOLE_RECORD
107 struct membuff console_out; /* console output */ 108 struct membuff console_out; /* console output */
108 struct membuff console_in; /* console input */ 109 struct membuff console_in; /* console input */
109 #endif 110 #endif
110 #ifdef CONFIG_DM_VIDEO 111 #ifdef CONFIG_DM_VIDEO
111 ulong video_top; /* Top of video frame buffer area */ 112 ulong video_top; /* Top of video frame buffer area */
112 ulong video_bottom; /* Bottom of video frame buffer area */ 113 ulong video_bottom; /* Bottom of video frame buffer area */
113 #endif 114 #endif
114 #ifdef CONFIG_BOOTSTAGE 115 #ifdef CONFIG_BOOTSTAGE
115 struct bootstage_data *bootstage; /* Bootstage information */ 116 struct bootstage_data *bootstage; /* Bootstage information */
116 struct bootstage_data *new_bootstage; /* Relocated bootstage info */ 117 struct bootstage_data *new_bootstage; /* Relocated bootstage info */
117 #endif 118 #endif
118 #ifdef CONFIG_LOG 119 #ifdef CONFIG_LOG
119 int log_drop_count; /* Number of dropped log messages */ 120 int log_drop_count; /* Number of dropped log messages */
120 int default_log_level; /* For devices with no filters */ 121 int default_log_level; /* For devices with no filters */
121 struct list_head log_head; /* List of struct log_device */ 122 struct list_head log_head; /* List of struct log_device */
122 int log_fmt; /* Mask containing log format info */ 123 int log_fmt; /* Mask containing log format info */
123 #endif 124 #endif
124 } gd_t; 125 } gd_t;
125 #endif 126 #endif
126 127
127 #ifdef CONFIG_BOARD_TYPES 128 #ifdef CONFIG_BOARD_TYPES
128 #define gd_board_type() gd->board_type 129 #define gd_board_type() gd->board_type
129 #else 130 #else
130 #define gd_board_type() 0 131 #define gd_board_type() 0
131 #endif 132 #endif
132 133
133 /* 134 /*
134 * Global Data Flags - the top 16 bits are reserved for arch-specific flags 135 * Global Data Flags - the top 16 bits are reserved for arch-specific flags
135 */ 136 */
136 #define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */ 137 #define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */
137 #define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */ 138 #define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */
138 #define GD_FLG_SILENT 0x00004 /* Silent mode */ 139 #define GD_FLG_SILENT 0x00004 /* Silent mode */
139 #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */ 140 #define GD_FLG_POSTFAIL 0x00008 /* Critical POST test failed */
140 #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */ 141 #define GD_FLG_POSTSTOP 0x00010 /* POST seqeunce aborted */
141 #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ 142 #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */
142 #define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ 143 #define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */
143 #define GD_FLG_ENV_READY 0x00080 /* Env. imported into hash table */ 144 #define GD_FLG_ENV_READY 0x00080 /* Env. imported into hash table */
144 #define GD_FLG_SERIAL_READY 0x00100 /* Pre-reloc serial console ready */ 145 #define GD_FLG_SERIAL_READY 0x00100 /* Pre-reloc serial console ready */
145 #define GD_FLG_FULL_MALLOC_INIT 0x00200 /* Full malloc() is ready */ 146 #define GD_FLG_FULL_MALLOC_INIT 0x00200 /* Full malloc() is ready */
146 #define GD_FLG_SPL_INIT 0x00400 /* spl_init() has been called */ 147 #define GD_FLG_SPL_INIT 0x00400 /* spl_init() has been called */
147 #define GD_FLG_SKIP_RELOC 0x00800 /* Don't relocate */ 148 #define GD_FLG_SKIP_RELOC 0x00800 /* Don't relocate */
148 #define GD_FLG_RECORD 0x01000 /* Record console */ 149 #define GD_FLG_RECORD 0x01000 /* Record console */
149 #define GD_FLG_ENV_DEFAULT 0x02000 /* Default variable flag */ 150 #define GD_FLG_ENV_DEFAULT 0x02000 /* Default variable flag */
150 #define GD_FLG_SPL_EARLY_INIT 0x04000 /* Early SPL init is done */ 151 #define GD_FLG_SPL_EARLY_INIT 0x04000 /* Early SPL init is done */
151 #define GD_FLG_LOG_READY 0x08000 /* Log system is ready for use */ 152 #define GD_FLG_LOG_READY 0x08000 /* Log system is ready for use */
152 153
153 #endif /* __ASM_GENERIC_GBL_DATA_H */ 154 #endif /* __ASM_GENERIC_GBL_DATA_H */
154 155
include/environment.h
1 /* 1 /*
2 * (C) Copyright 2002 2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 * 4 *
5 * SPDX-License-Identifier: GPL-2.0+ 5 * SPDX-License-Identifier: GPL-2.0+
6 */ 6 */
7 7
8 #ifndef _ENVIRONMENT_H_ 8 #ifndef _ENVIRONMENT_H_
9 #define _ENVIRONMENT_H_ 9 #define _ENVIRONMENT_H_
10 10
11 #include <linux/kconfig.h> 11 #include <linux/kconfig.h>
12 12
13 /************************************************************************** 13 /**************************************************************************
14 * 14 *
15 * The "environment" is stored as a list of '\0' terminated 15 * The "environment" is stored as a list of '\0' terminated
16 * "name=value" strings. The end of the list is marked by a double 16 * "name=value" strings. The end of the list is marked by a double
17 * '\0'. New entries are always added at the end. Deleting an entry 17 * '\0'. New entries are always added at the end. Deleting an entry
18 * shifts the remaining entries to the front. Replacing an entry is a 18 * shifts the remaining entries to the front. Replacing an entry is a
19 * combination of deleting the old value and adding the new one. 19 * combination of deleting the old value and adding the new one.
20 * 20 *
21 * The environment is preceded by a 32 bit CRC over the data part. 21 * The environment is preceded by a 32 bit CRC over the data part.
22 * 22 *
23 *************************************************************************/ 23 *************************************************************************/
24 24
25 #if defined(CONFIG_ENV_IS_IN_FLASH) 25 #if defined(CONFIG_ENV_IS_IN_FLASH)
26 # ifndef CONFIG_ENV_ADDR 26 # ifndef CONFIG_ENV_ADDR
27 # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) 27 # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
28 # endif 28 # endif
29 # ifndef CONFIG_ENV_OFFSET 29 # ifndef CONFIG_ENV_OFFSET
30 # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE) 30 # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
31 # endif 31 # endif
32 # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND) 32 # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
33 # define CONFIG_ENV_ADDR_REDUND \ 33 # define CONFIG_ENV_ADDR_REDUND \
34 (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND) 34 (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
35 # endif 35 # endif
36 # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE) 36 # if defined(CONFIG_ENV_SECT_SIZE) || defined(CONFIG_ENV_SIZE)
37 # ifndef CONFIG_ENV_SECT_SIZE 37 # ifndef CONFIG_ENV_SECT_SIZE
38 # define CONFIG_ENV_SECT_SIZE CONFIG_ENV_SIZE 38 # define CONFIG_ENV_SECT_SIZE CONFIG_ENV_SIZE
39 # endif 39 # endif
40 # ifndef CONFIG_ENV_SIZE 40 # ifndef CONFIG_ENV_SIZE
41 # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE 41 # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
42 # endif 42 # endif
43 # else 43 # else
44 # error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined" 44 # error "Both CONFIG_ENV_SECT_SIZE and CONFIG_ENV_SIZE undefined"
45 # endif 45 # endif
46 # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND) 46 # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
47 # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE 47 # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE
48 # endif 48 # endif
49 # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \ 49 # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
50 (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= \ 50 (CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= \
51 (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) 51 (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)
52 # define ENV_IS_EMBEDDED 52 # define ENV_IS_EMBEDDED
53 # endif 53 # endif
54 # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) 54 # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
55 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 55 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT
56 # endif 56 # endif
57 # ifdef CONFIG_ENV_IS_EMBEDDED 57 # ifdef CONFIG_ENV_IS_EMBEDDED
58 # error "do not define CONFIG_ENV_IS_EMBEDDED in your board config" 58 # error "do not define CONFIG_ENV_IS_EMBEDDED in your board config"
59 # error "it is calculated automatically for you" 59 # error "it is calculated automatically for you"
60 # endif 60 # endif
61 #endif /* CONFIG_ENV_IS_IN_FLASH */ 61 #endif /* CONFIG_ENV_IS_IN_FLASH */
62 62
63 #if defined(CONFIG_ENV_IS_IN_MMC) 63 #if defined(CONFIG_ENV_IS_IN_MMC)
64 # ifdef CONFIG_ENV_OFFSET_REDUND 64 # ifdef CONFIG_ENV_OFFSET_REDUND
65 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 65 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT
66 # endif 66 # endif
67 #endif 67 #endif
68 68
69 #if defined(CONFIG_ENV_IS_IN_NAND) 69 #if defined(CONFIG_ENV_IS_IN_NAND)
70 # if defined(CONFIG_ENV_OFFSET_OOB) 70 # if defined(CONFIG_ENV_OFFSET_OOB)
71 # ifdef CONFIG_ENV_OFFSET_REDUND 71 # ifdef CONFIG_ENV_OFFSET_REDUND
72 # error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB" 72 # error "CONFIG_ENV_OFFSET_REDUND is not supported when CONFIG_ENV_OFFSET_OOB"
73 # error "is set" 73 # error "is set"
74 # endif 74 # endif
75 extern unsigned long nand_env_oob_offset; 75 extern unsigned long nand_env_oob_offset;
76 # define CONFIG_ENV_OFFSET nand_env_oob_offset 76 # define CONFIG_ENV_OFFSET nand_env_oob_offset
77 # else 77 # else
78 # ifndef CONFIG_ENV_OFFSET 78 # ifndef CONFIG_ENV_OFFSET
79 # error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND" 79 # error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_NAND"
80 # endif 80 # endif
81 # ifdef CONFIG_ENV_OFFSET_REDUND 81 # ifdef CONFIG_ENV_OFFSET_REDUND
82 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 82 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT
83 # endif 83 # endif
84 # endif /* CONFIG_ENV_OFFSET_OOB */ 84 # endif /* CONFIG_ENV_OFFSET_OOB */
85 # ifndef CONFIG_ENV_SIZE 85 # ifndef CONFIG_ENV_SIZE
86 # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND" 86 # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_NAND"
87 # endif 87 # endif
88 #endif /* CONFIG_ENV_IS_IN_NAND */ 88 #endif /* CONFIG_ENV_IS_IN_NAND */
89 89
90 #if defined(CONFIG_ENV_IS_IN_UBI) 90 #if defined(CONFIG_ENV_IS_IN_UBI)
91 # ifndef CONFIG_ENV_UBI_PART 91 # ifndef CONFIG_ENV_UBI_PART
92 # error "Need to define CONFIG_ENV_UBI_PART when using CONFIG_ENV_IS_IN_UBI" 92 # error "Need to define CONFIG_ENV_UBI_PART when using CONFIG_ENV_IS_IN_UBI"
93 # endif 93 # endif
94 # ifndef CONFIG_ENV_UBI_VOLUME 94 # ifndef CONFIG_ENV_UBI_VOLUME
95 # error "Need to define CONFIG_ENV_UBI_VOLUME when using CONFIG_ENV_IS_IN_UBI" 95 # error "Need to define CONFIG_ENV_UBI_VOLUME when using CONFIG_ENV_IS_IN_UBI"
96 # endif 96 # endif
97 # if defined(CONFIG_ENV_UBI_VOLUME_REDUND) 97 # if defined(CONFIG_ENV_UBI_VOLUME_REDUND)
98 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT 98 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT
99 # endif 99 # endif
100 # ifndef CONFIG_ENV_SIZE 100 # ifndef CONFIG_ENV_SIZE
101 # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_UBI" 101 # error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_UBI"
102 # endif 102 # endif
103 # ifndef CONFIG_CMD_UBI 103 # ifndef CONFIG_CMD_UBI
104 # error "Need to define CONFIG_CMD_UBI when using CONFIG_ENV_IS_IN_UBI" 104 # error "Need to define CONFIG_CMD_UBI when using CONFIG_ENV_IS_IN_UBI"
105 # endif 105 # endif
106 #endif /* CONFIG_ENV_IS_IN_UBI */ 106 #endif /* CONFIG_ENV_IS_IN_UBI */
107 107
108 /* Embedded env is only supported for some flash types */ 108 /* Embedded env is only supported for some flash types */
109 #ifdef CONFIG_ENV_IS_EMBEDDED 109 #ifdef CONFIG_ENV_IS_EMBEDDED
110 # if !defined(CONFIG_ENV_IS_IN_FLASH) && \ 110 # if !defined(CONFIG_ENV_IS_IN_FLASH) && \
111 !defined(CONFIG_ENV_IS_IN_NAND) && \ 111 !defined(CONFIG_ENV_IS_IN_NAND) && \
112 !defined(CONFIG_ENV_IS_IN_ONENAND) && \ 112 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
113 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) 113 !defined(CONFIG_ENV_IS_IN_SPI_FLASH)
114 # error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type" 114 # error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type"
115 # endif 115 # endif
116 #endif 116 #endif
117 117
118 /* 118 /*
119 * For the flash types where embedded env is supported, but it cannot be 119 * For the flash types where embedded env is supported, but it cannot be
120 * calculated automatically (i.e. NAND), take the board opt-in. 120 * calculated automatically (i.e. NAND), take the board opt-in.
121 */ 121 */
122 #if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED) 122 #if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED)
123 # define ENV_IS_EMBEDDED 123 # define ENV_IS_EMBEDDED
124 #endif 124 #endif
125 125
126 /* The build system likes to know if the env is embedded */ 126 /* The build system likes to know if the env is embedded */
127 #ifdef DO_DEPS_ONLY 127 #ifdef DO_DEPS_ONLY
128 # ifdef ENV_IS_EMBEDDED 128 # ifdef ENV_IS_EMBEDDED
129 # ifndef CONFIG_ENV_IS_EMBEDDED 129 # ifndef CONFIG_ENV_IS_EMBEDDED
130 # define CONFIG_ENV_IS_EMBEDDED 130 # define CONFIG_ENV_IS_EMBEDDED
131 # endif 131 # endif
132 # endif 132 # endif
133 #endif 133 #endif
134 134
135 #include "compiler.h" 135 #include "compiler.h"
136 136
137 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 137 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
138 # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1) 138 # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
139 139
140 # define ACTIVE_FLAG 1 140 # define ACTIVE_FLAG 1
141 # define OBSOLETE_FLAG 0 141 # define OBSOLETE_FLAG 0
142 #else 142 #else
143 # define ENV_HEADER_SIZE (sizeof(uint32_t)) 143 # define ENV_HEADER_SIZE (sizeof(uint32_t))
144 #endif 144 #endif
145 145
146 #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) 146 #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
147 147
148 typedef struct environment_s { 148 typedef struct environment_s {
149 uint32_t crc; /* CRC32 over data bytes */ 149 uint32_t crc; /* CRC32 over data bytes */
150 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 150 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
151 unsigned char flags; /* active/obsolete flags */ 151 unsigned char flags; /* active/obsolete flags */
152 #endif 152 #endif
153 unsigned char data[ENV_SIZE]; /* Environment data */ 153 unsigned char data[ENV_SIZE]; /* Environment data */
154 } env_t; 154 } env_t;
155 155
156 #ifdef ENV_IS_EMBEDDED 156 #ifdef ENV_IS_EMBEDDED
157 extern env_t environment; 157 extern env_t environment;
158 #endif /* ENV_IS_EMBEDDED */ 158 #endif /* ENV_IS_EMBEDDED */
159 159
160 extern const unsigned char default_environment[]; 160 extern const unsigned char default_environment[];
161 extern env_t *env_ptr; 161 extern env_t *env_ptr;
162 162
163 #if defined(CONFIG_NEEDS_MANUAL_RELOC) 163 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
164 extern void env_reloc(void); 164 extern void env_reloc(void);
165 #endif 165 #endif
166 166
167 #ifdef CONFIG_ENV_IS_IN_MMC 167 #ifdef CONFIG_ENV_IS_IN_MMC
168 #include <mmc.h> 168 #include <mmc.h>
169 169
170 extern int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr); 170 extern int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr);
171 # ifdef CONFIG_SYS_MMC_ENV_PART 171 # ifdef CONFIG_SYS_MMC_ENV_PART
172 extern uint mmc_get_env_part(struct mmc *mmc); 172 extern uint mmc_get_env_part(struct mmc *mmc);
173 # endif 173 # endif
174 #endif 174 #endif
175 175
176 #ifndef DO_DEPS_ONLY 176 #ifndef DO_DEPS_ONLY
177 177
178 #include <env_attr.h> 178 #include <env_attr.h>
179 #include <env_callback.h> 179 #include <env_callback.h>
180 #include <env_flags.h> 180 #include <env_flags.h>
181 #include <search.h> 181 #include <search.h>
182 182
183 /* Value for environment validity */ 183 /* Value for environment validity */
184 enum env_valid { 184 enum env_valid {
185 ENV_INVALID, /* No valid environment */ 185 ENV_INVALID, /* No valid environment */
186 ENV_VALID, /* First or only environment is valid */ 186 ENV_VALID, /* First or only environment is valid */
187 ENV_REDUND, /* Redundant environment is valid */ 187 ENV_REDUND, /* Redundant environment is valid */
188 }; 188 };
189 189
190 enum env_location { 190 enum env_location {
191 ENVL_UNKNOWN,
191 ENVL_EEPROM, 192 ENVL_EEPROM,
192 ENVL_EXT4, 193 ENVL_EXT4,
193 ENVL_FAT, 194 ENVL_FAT,
194 ENVL_FLASH, 195 ENVL_FLASH,
195 ENVL_MMC, 196 ENVL_MMC,
196 ENVL_NAND, 197 ENVL_NAND,
197 ENVL_NVRAM, 198 ENVL_NVRAM,
198 ENVL_ONENAND, 199 ENVL_ONENAND,
199 ENVL_REMOTE, 200 ENVL_REMOTE,
200 ENVL_SPI_FLASH, 201 ENVL_SPI_FLASH,
201 ENVL_UBI, 202 ENVL_UBI,
202 ENVL_NOWHERE, 203 ENVL_NOWHERE,
203 204
204 ENVL_COUNT, 205 ENVL_COUNT,
205 ENVL_UNKNOWN,
206 }; 206 };
207 207
208 /* value for the various operations we want to perform on the env */ 208 /* value for the various operations we want to perform on the env */
209 enum env_operation { 209 enum env_operation {
210 ENVOP_GET_CHAR, /* we want to call the get_char function */ 210 ENVOP_GET_CHAR, /* we want to call the get_char function */
211 ENVOP_INIT, /* we want to call the init function */ 211 ENVOP_INIT, /* we want to call the init function */
212 ENVOP_LOAD, /* we want to call the load function */ 212 ENVOP_LOAD, /* we want to call the load function */
213 ENVOP_SAVE, /* we want to call the save function */ 213 ENVOP_SAVE, /* we want to call the save function */
214 }; 214 };
215 215
216 struct env_driver { 216 struct env_driver {
217 const char *name; 217 const char *name;
218 enum env_location location; 218 enum env_location location;
219 219
220 /** 220 /**
221 * get_char() - Read a character from the environment 221 * get_char() - Read a character from the environment
222 * 222 *
223 * This method is optional. If not provided, a default implementation 223 * This method is optional. If not provided, a default implementation
224 * will read from gd->env_addr. 224 * will read from gd->env_addr.
225 * 225 *
226 * @index: Index of character to read (0=first) 226 * @index: Index of character to read (0=first)
227 * @return character read, or -ve on error 227 * @return character read, or -ve on error
228 */ 228 */
229 int (*get_char)(int index); 229 int (*get_char)(int index);
230 230
231 /** 231 /**
232 * load() - Load the environment from storage 232 * load() - Load the environment from storage
233 * 233 *
234 * This method is optional. If not provided, no environment will be 234 * This method is optional. If not provided, no environment will be
235 * loaded. 235 * loaded.
236 * 236 *
237 * @return 0 if OK, -ve on error 237 * @return 0 if OK, -ve on error
238 */ 238 */
239 int (*load)(void); 239 int (*load)(void);
240 240
241 /** 241 /**
242 * save() - Save the environment to storage 242 * save() - Save the environment to storage
243 * 243 *
244 * This method is required for 'saveenv' to work. 244 * This method is required for 'saveenv' to work.
245 * 245 *
246 * @return 0 if OK, -ve on error 246 * @return 0 if OK, -ve on error
247 */ 247 */
248 int (*save)(void); 248 int (*save)(void);
249 249
250 /** 250 /**
251 * init() - Set up the initial pre-relocation environment 251 * init() - Set up the initial pre-relocation environment
252 * 252 *
253 * This method is optional. 253 * This method is optional.
254 * 254 *
255 * @return 0 if OK, -ENOENT if no initial environment could be found, 255 * @return 0 if OK, -ENOENT if no initial environment could be found,
256 * other -ve on error 256 * other -ve on error
257 */ 257 */
258 int (*init)(void); 258 int (*init)(void);
259 }; 259 };
260 260
261 /* Declare a new environment location driver */ 261 /* Declare a new environment location driver */
262 #define U_BOOT_ENV_LOCATION(__name) \ 262 #define U_BOOT_ENV_LOCATION(__name) \
263 ll_entry_declare(struct env_driver, __name, env_driver) 263 ll_entry_declare(struct env_driver, __name, env_driver)
264 264
265 /* Declare the name of a location */ 265 /* Declare the name of a location */
266 #ifdef CONFIG_CMD_SAVEENV 266 #ifdef CONFIG_CMD_SAVEENV
267 #define ENV_NAME(_name) .name = _name, 267 #define ENV_NAME(_name) .name = _name,
268 #else 268 #else
269 #define ENV_NAME(_name) 269 #define ENV_NAME(_name)
270 #endif 270 #endif
271 271
272 #ifdef CONFIG_CMD_SAVEENV 272 #ifdef CONFIG_CMD_SAVEENV
273 #define env_save_ptr(x) x 273 #define env_save_ptr(x) x
274 #else 274 #else
275 #define env_save_ptr(x) NULL 275 #define env_save_ptr(x) NULL
276 #endif 276 #endif
277 277
278 extern struct hsearch_data env_htab; 278 extern struct hsearch_data env_htab;
279 279
280 /* Function that updates CRC of the enironment */ 280 /* Function that updates CRC of the enironment */
281 void env_crc_update(void); 281 void env_crc_update(void);
282 282
283 /* Look up the variable from the default environment */ 283 /* Look up the variable from the default environment */
284 char *env_get_default(const char *name); 284 char *env_get_default(const char *name);
285 285
286 /* [re]set to the default environment */ 286 /* [re]set to the default environment */
287 void set_default_env(const char *s); 287 void set_default_env(const char *s);
288 288
289 /* [re]set individual variables to their value in the default environment */ 289 /* [re]set individual variables to their value in the default environment */
290 int set_default_vars(int nvars, char * const vars[]); 290 int set_default_vars(int nvars, char * const vars[]);
291 291
292 /* Import from binary representation into hash table */ 292 /* Import from binary representation into hash table */
293 int env_import(const char *buf, int check); 293 int env_import(const char *buf, int check);
294 294
295 /* Export from hash table into binary representation */ 295 /* Export from hash table into binary representation */
296 int env_export(env_t *env_out); 296 int env_export(env_t *env_out);
297 297
298 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT 298 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
299 /* Select and import one of two redundant environments */ 299 /* Select and import one of two redundant environments */
300 int env_import_redund(const char *buf1, int buf1_status, 300 int env_import_redund(const char *buf1, int buf1_status,
301 const char *buf2, int buf2_status); 301 const char *buf2, int buf2_status);
302 #endif 302 #endif
303 303
304 /** 304 /**
305 * env_get_char() - Get a character from the early environment 305 * env_get_char() - Get a character from the early environment
306 * 306 *
307 * This reads from the pre-relocation environemnt 307 * This reads from the pre-relocation environemnt
308 * 308 *
309 * @index: Index of character to read (0 = first) 309 * @index: Index of character to read (0 = first)
310 * @return character read, or -ve on error 310 * @return character read, or -ve on error
311 */ 311 */
312 int env_get_char(int index); 312 int env_get_char(int index);
313 313
314 /** 314 /**
315 * env_load() - Load the environment from storage 315 * env_load() - Load the environment from storage
316 * 316 *
317 * @return 0 if OK, -ve on error 317 * @return 0 if OK, -ve on error
318 */ 318 */
319 int env_load(void); 319 int env_load(void);
320 320
321 /** 321 /**
322 * env_save() - Save the environment to storage 322 * env_save() - Save the environment to storage
323 * 323 *
324 * @return 0 if OK, -ve on error 324 * @return 0 if OK, -ve on error
325 */ 325 */
326 int env_save(void); 326 int env_save(void);
327 327
328 #endif /* DO_DEPS_ONLY */ 328 #endif /* DO_DEPS_ONLY */
329 329
330 #endif /* _ENVIRONMENT_H_ */ 330 #endif /* _ENVIRONMENT_H_ */