Commit c5d548a9f881b2268f1d81dab9cd329ae336607e
Committed by
Tom Rini
1 parent
5a04264ecf
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
env: common: accept flags on reset to default env
The function set_default_env() sets the hashtable flags for import_r(). Formally set_default_env() doesn't accept flags from its callers. In practice the caller can (un)set the H_INTERACTIVE flag, but it has to be done using the first character of the function's string argument. Other flags like H_FORCE can't be set by the caller. Change the function to accept flags argument. The benefits are: 1. The caller will have to explicitly set the H_INTERACTIVE flag, instead of un-setting it using a special char in a string. 2. Add the ability to propagate flags from the caller to himport(), especially the H_FORCE flag from do_env_default() in nvedit.c that currently gets ignored for "env default -a -f" commands. 3. Flags and messages will not be coupled together. A caller will be able to set flags without passing a string and vice versa. Please note: The propagation of H_FORCE from do_env_default() does not introduce any functional changes, because currently himport_r() is set to destroy the old environment regardless if H_FORCE flag is set or not. More changes are needed to utilize the propagation of H_FORCE. Signed-off-by: Yaniv Levinsky <yaniv.levinsky@compulab.co.il> Acked-by: Igor Grinberg <grinberg@compulab.co.il>
Showing 13 changed files with 35 additions and 38 deletions Side-by-side Diff
arch/arm/mach-imx/mx6/opos6ul.c
cmd/nvedit.c
... | ... | @@ -802,7 +802,8 @@ |
802 | 802 | debug("Final value for argc=%d\n", argc); |
803 | 803 | if (all && (argc == 0)) { |
804 | 804 | /* Reset the whole environment */ |
805 | - set_default_env("## Resetting to default environment\n"); | |
805 | + set_default_env("## Resetting to default environment\n", | |
806 | + env_flag); | |
806 | 807 | return 0; |
807 | 808 | } |
808 | 809 | if (!all && (argc > 0)) { |
common/board_r.c
common/spl/spl_dfu.c
env/common.c
... | ... | @@ -58,22 +58,18 @@ |
58 | 58 | return ret_val; |
59 | 59 | } |
60 | 60 | |
61 | -void set_default_env(const char *s) | |
61 | +void set_default_env(const char *s, int flags) | |
62 | 62 | { |
63 | - int flags = 0; | |
64 | - | |
65 | 63 | if (sizeof(default_environment) > ENV_SIZE) { |
66 | 64 | puts("*** Error - default environment is too large\n\n"); |
67 | 65 | return; |
68 | 66 | } |
69 | 67 | |
70 | 68 | if (s) { |
71 | - if (*s == '!') { | |
69 | + if ((flags & H_INTERACTIVE) == 0) { | |
72 | 70 | printf("*** Warning - %s, " |
73 | - "using default environment\n\n", | |
74 | - s + 1); | |
71 | + "using default environment\n\n", s); | |
75 | 72 | } else { |
76 | - flags = H_INTERACTIVE; | |
77 | 73 | puts(s); |
78 | 74 | } |
79 | 75 | } else { |
... | ... | @@ -117,7 +113,7 @@ |
117 | 113 | memcpy(&crc, &ep->crc, sizeof(crc)); |
118 | 114 | |
119 | 115 | if (crc32(0, ep->data, ENV_SIZE) != crc) { |
120 | - set_default_env("!bad CRC"); | |
116 | + set_default_env("bad CRC", 0); | |
121 | 117 | return -EIO; |
122 | 118 | } |
123 | 119 | } |
... | ... | @@ -130,7 +126,7 @@ |
130 | 126 | |
131 | 127 | pr_err("Cannot import environment: errno = %d\n", errno); |
132 | 128 | |
133 | - set_default_env("!import failed"); | |
129 | + set_default_env("import failed", 0); | |
134 | 130 | |
135 | 131 | return -EIO; |
136 | 132 | } |
... | ... | @@ -155,7 +151,7 @@ |
155 | 151 | } |
156 | 152 | |
157 | 153 | if (buf1_read_fail && buf2_read_fail) { |
158 | - set_default_env("!bad env area"); | |
154 | + set_default_env("bad env area", 0); | |
159 | 155 | return -EIO; |
160 | 156 | } else if (!buf1_read_fail && buf2_read_fail) { |
161 | 157 | gd->env_valid = ENV_VALID; |
... | ... | @@ -171,7 +167,7 @@ |
171 | 167 | tmp_env2->crc; |
172 | 168 | |
173 | 169 | if (!crc1_ok && !crc2_ok) { |
174 | - set_default_env("!bad CRC"); | |
170 | + set_default_env("bad CRC", 0); | |
175 | 171 | return -EIO; |
176 | 172 | } else if (crc1_ok && !crc2_ok) { |
177 | 173 | gd->env_valid = ENV_VALID; |
178 | 174 | |
... | ... | @@ -233,10 +229,10 @@ |
233 | 229 | if (gd->env_valid == ENV_INVALID) { |
234 | 230 | #if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD) |
235 | 231 | /* Environment not changable */ |
236 | - set_default_env(NULL); | |
232 | + set_default_env(NULL, 0); | |
237 | 233 | #else |
238 | 234 | bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM); |
239 | - set_default_env("!bad CRC"); | |
235 | + set_default_env("bad CRC", 0); | |
240 | 236 | #endif |
241 | 237 | } else { |
242 | 238 | env_load(); |
env/ext4.c
env/fat.c
env/mmc.c
... | ... | @@ -155,19 +155,19 @@ |
155 | 155 | static const char *init_mmc_for_env(struct mmc *mmc) |
156 | 156 | { |
157 | 157 | if (!mmc) |
158 | - return "!No MMC card found"; | |
158 | + return "No MMC card found"; | |
159 | 159 | |
160 | 160 | #if CONFIG_IS_ENABLED(BLK) |
161 | 161 | struct udevice *dev; |
162 | 162 | |
163 | 163 | if (blk_get_from_parent(mmc->dev, &dev)) |
164 | - return "!No block device"; | |
164 | + return "No block device"; | |
165 | 165 | #else |
166 | 166 | if (mmc_init(mmc)) |
167 | - return "!MMC init failed"; | |
167 | + return "MMC init failed"; | |
168 | 168 | #endif |
169 | 169 | if (mmc_set_env_part(mmc)) |
170 | - return "!MMC partition switch failed"; | |
170 | + return "MMC partition switch failed"; | |
171 | 171 | |
172 | 172 | return NULL; |
173 | 173 | } |
... | ... | @@ -298,7 +298,7 @@ |
298 | 298 | fini_mmc_for_env(mmc); |
299 | 299 | err: |
300 | 300 | if (ret) |
301 | - set_default_env(errmsg); | |
301 | + set_default_env(errmsg, 0); | |
302 | 302 | |
303 | 303 | #endif |
304 | 304 | return ret; |
... | ... | @@ -339,7 +339,7 @@ |
339 | 339 | fini_mmc_for_env(mmc); |
340 | 340 | err: |
341 | 341 | if (ret) |
342 | - set_default_env(errmsg); | |
342 | + set_default_env(errmsg, 0); | |
343 | 343 | #endif |
344 | 344 | return ret; |
345 | 345 | } |
env/nand.c
... | ... | @@ -327,7 +327,7 @@ |
327 | 327 | tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); |
328 | 328 | if (tmp_env1 == NULL || tmp_env2 == NULL) { |
329 | 329 | puts("Can't allocate buffers for environment\n"); |
330 | - set_default_env("!malloc() failed"); | |
330 | + set_default_env("malloc() failed", 0); | |
331 | 331 | ret = -EIO; |
332 | 332 | goto done; |
333 | 333 | } |
334 | 334 | |
... | ... | @@ -366,14 +366,14 @@ |
366 | 366 | if (mtd && !get_nand_env_oob(mtd, &nand_env_oob_offset)) { |
367 | 367 | printf("Found Environment offset in OOB..\n"); |
368 | 368 | } else { |
369 | - set_default_env("!no env offset in OOB"); | |
369 | + set_default_env("no env offset in OOB", 0); | |
370 | 370 | return; |
371 | 371 | } |
372 | 372 | #endif |
373 | 373 | |
374 | 374 | ret = readenv(CONFIG_ENV_OFFSET, (u_char *)buf); |
375 | 375 | if (ret) { |
376 | - set_default_env("!readenv() failed"); | |
376 | + set_default_env("readenv() failed", 0); | |
377 | 377 | return -EIO; |
378 | 378 | } |
379 | 379 |
env/sata.c
env/sf.c
... | ... | @@ -60,7 +60,7 @@ |
60 | 60 | ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, |
61 | 61 | 0, 0, &new); |
62 | 62 | if (ret) { |
63 | - set_default_env("!spi_flash_probe_bus_cs() failed"); | |
63 | + set_default_env("spi_flash_probe_bus_cs() failed", 0); | |
64 | 64 | return ret; |
65 | 65 | } |
66 | 66 | |
... | ... | @@ -72,7 +72,7 @@ |
72 | 72 | CONFIG_ENV_SPI_CS, |
73 | 73 | CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); |
74 | 74 | if (!env_flash) { |
75 | - set_default_env("!spi_flash_probe() failed"); | |
75 | + set_default_env("spi_flash_probe() failed", 0); | |
76 | 76 | return -EIO; |
77 | 77 | } |
78 | 78 | } |
... | ... | @@ -173,7 +173,7 @@ |
173 | 173 | tmp_env2 = (env_t *)memalign(ARCH_DMA_MINALIGN, |
174 | 174 | CONFIG_ENV_SIZE); |
175 | 175 | if (!tmp_env1 || !tmp_env2) { |
176 | - set_default_env("!malloc() failed"); | |
176 | + set_default_env("malloc() failed", 0); | |
177 | 177 | ret = -EIO; |
178 | 178 | goto out; |
179 | 179 | } |
... | ... | @@ -268,7 +268,7 @@ |
268 | 268 | |
269 | 269 | buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); |
270 | 270 | if (!buf) { |
271 | - set_default_env("!malloc() failed"); | |
271 | + set_default_env("malloc() failed", 0); | |
272 | 272 | return -EIO; |
273 | 273 | } |
274 | 274 | |
... | ... | @@ -279,7 +279,7 @@ |
279 | 279 | ret = spi_flash_read(env_flash, |
280 | 280 | CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf); |
281 | 281 | if (ret) { |
282 | - set_default_env("!spi_flash_read() failed"); | |
282 | + set_default_env("spi_flash_read() failed", 0); | |
283 | 283 | goto err_read; |
284 | 284 | } |
285 | 285 |
env/ubi.c
... | ... | @@ -114,7 +114,7 @@ |
114 | 114 | if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { |
115 | 115 | printf("\n** Cannot find mtd partition \"%s\"\n", |
116 | 116 | CONFIG_ENV_UBI_PART); |
117 | - set_default_env(NULL); | |
117 | + set_default_env(NULL, 0); | |
118 | 118 | return -EIO; |
119 | 119 | } |
120 | 120 | |
121 | 121 | |
... | ... | @@ -151,14 +151,14 @@ |
151 | 151 | if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { |
152 | 152 | printf("\n** Cannot find mtd partition \"%s\"\n", |
153 | 153 | CONFIG_ENV_UBI_PART); |
154 | - set_default_env(NULL); | |
154 | + set_default_env(NULL, 0); | |
155 | 155 | return -EIO; |
156 | 156 | } |
157 | 157 | |
158 | 158 | if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) { |
159 | 159 | printf("\n** Unable to read env from %s:%s **\n", |
160 | 160 | CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME); |
161 | - set_default_env(NULL); | |
161 | + set_default_env(NULL, 0); | |
162 | 162 | return -EIO; |
163 | 163 | } |
164 | 164 |
include/environment.h
... | ... | @@ -272,7 +272,7 @@ |
272 | 272 | char *env_get_default(const char *name); |
273 | 273 | |
274 | 274 | /* [re]set to the default environment */ |
275 | -void set_default_env(const char *s); | |
275 | +void set_default_env(const char *s, int flags); | |
276 | 276 | |
277 | 277 | /* [re]set individual variables to their value in the default environment */ |
278 | 278 | int set_default_vars(int nvars, char * const vars[], int flags); |