Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 4bfd1f5 | 2019-08-01 09:46:43 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | f3998fd | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 9 | #include <env_internal.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Simon Glass | eb41d8a | 2020-05-10 11:40:08 -0600 | [diff] [blame] | 13 | #include <linux/bug.h> |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Siva Durga Prasad Paladugu | 7bcdf19 | 2018-04-13 07:57:21 +0200 | [diff] [blame] | 17 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 18 | void env_fix_drivers(void) |
| 19 | { |
| 20 | struct env_driver *drv; |
| 21 | const int n_ents = ll_entry_count(struct env_driver, env_driver); |
| 22 | struct env_driver *entry; |
| 23 | |
| 24 | drv = ll_entry_start(struct env_driver, env_driver); |
| 25 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 26 | if (entry->name) |
| 27 | entry->name += gd->reloc_off; |
| 28 | if (entry->load) |
| 29 | entry->load += gd->reloc_off; |
| 30 | if (entry->save) |
| 31 | entry->save += gd->reloc_off; |
Frank Wunderlich | cd121bd | 2019-06-29 11:36:19 +0200 | [diff] [blame] | 32 | if (entry->erase) |
| 33 | entry->erase += gd->reloc_off; |
Siva Durga Prasad Paladugu | 7bcdf19 | 2018-04-13 07:57:21 +0200 | [diff] [blame] | 34 | if (entry->init) |
| 35 | entry->init += gd->reloc_off; |
| 36 | } |
| 37 | } |
| 38 | #endif |
| 39 | |
Maxime Ripard | 52746c4 | 2018-01-23 21:16:51 +0100 | [diff] [blame] | 40 | static struct env_driver *_env_driver_lookup(enum env_location loc) |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 41 | { |
| 42 | struct env_driver *drv; |
| 43 | const int n_ents = ll_entry_count(struct env_driver, env_driver); |
| 44 | struct env_driver *entry; |
| 45 | |
| 46 | drv = ll_entry_start(struct env_driver, env_driver); |
| 47 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 48 | if (loc == entry->location) |
| 49 | return entry; |
| 50 | } |
| 51 | |
| 52 | /* Not found */ |
| 53 | return NULL; |
| 54 | } |
| 55 | |
Maxime Ripard | 7d714a2 | 2018-01-23 21:16:58 +0100 | [diff] [blame] | 56 | static enum env_location env_locations[] = { |
| 57 | #ifdef CONFIG_ENV_IS_IN_EEPROM |
| 58 | ENVL_EEPROM, |
| 59 | #endif |
| 60 | #ifdef CONFIG_ENV_IS_IN_EXT4 |
| 61 | ENVL_EXT4, |
| 62 | #endif |
| 63 | #ifdef CONFIG_ENV_IS_IN_FAT |
| 64 | ENVL_FAT, |
| 65 | #endif |
| 66 | #ifdef CONFIG_ENV_IS_IN_FLASH |
| 67 | ENVL_FLASH, |
| 68 | #endif |
| 69 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 70 | ENVL_MMC, |
| 71 | #endif |
| 72 | #ifdef CONFIG_ENV_IS_IN_NAND |
| 73 | ENVL_NAND, |
| 74 | #endif |
| 75 | #ifdef CONFIG_ENV_IS_IN_NVRAM |
| 76 | ENVL_NVRAM, |
| 77 | #endif |
| 78 | #ifdef CONFIG_ENV_IS_IN_REMOTE |
| 79 | ENVL_REMOTE, |
| 80 | #endif |
Ye Li | 9a6a311 | 2019-01-04 09:34:24 +0000 | [diff] [blame] | 81 | #ifdef CONFIG_ENV_IS_IN_SATA |
| 82 | ENVL_ESATA, |
| 83 | #endif |
Maxime Ripard | 7d714a2 | 2018-01-23 21:16:58 +0100 | [diff] [blame] | 84 | #ifdef CONFIG_ENV_IS_IN_SPI_FLASH |
| 85 | ENVL_SPI_FLASH, |
| 86 | #endif |
| 87 | #ifdef CONFIG_ENV_IS_IN_UBI |
| 88 | ENVL_UBI, |
| 89 | #endif |
| 90 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 91 | ENVL_NOWHERE, |
| 92 | #endif |
| 93 | }; |
| 94 | |
Maxime Ripard | 1d44608 | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 95 | static bool env_has_inited(enum env_location location) |
| 96 | { |
| 97 | return gd->env_has_init & BIT(location); |
| 98 | } |
| 99 | |
| 100 | static void env_set_inited(enum env_location location) |
| 101 | { |
| 102 | /* |
| 103 | * We're using a 32-bits bitmask stored in gd (env_has_init) |
| 104 | * using the above enum value as the bit index. We need to |
| 105 | * make sure that we're not overflowing it. |
| 106 | */ |
Patrick Delaunay | d5a6a5a | 2020-06-24 09:27:25 +0200 | [diff] [blame] | 107 | BUILD_BUG_ON(ENVL_COUNT > BITS_PER_LONG); |
Maxime Ripard | 1d44608 | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 108 | |
| 109 | gd->env_has_init |= BIT(location); |
| 110 | } |
| 111 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 112 | /** |
| 113 | * env_get_location() - Returns the best env location for a board |
| 114 | * @op: operations performed on the environment |
| 115 | * @prio: priority between the multiple environments, 0 being the |
| 116 | * highest priority |
| 117 | * |
| 118 | * This will return the preferred environment for the given priority. |
Maxime Ripard | 40c08a6 | 2018-01-23 21:17:02 +0100 | [diff] [blame] | 119 | * This is overridable by boards if they need to. |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 120 | * |
| 121 | * All implementations are free to use the operation, the priority and |
| 122 | * any other data relevant to their choice, but must take into account |
| 123 | * the fact that the lowest prority (0) is the most important location |
| 124 | * in the system. The following locations should be returned by order |
| 125 | * of descending priorities, from the highest to the lowest priority. |
| 126 | * |
| 127 | * Returns: |
| 128 | * an enum env_location value on success, a negative error code otherwise |
| 129 | */ |
Maxime Ripard | 40c08a6 | 2018-01-23 21:17:02 +0100 | [diff] [blame] | 130 | __weak enum env_location env_get_location(enum env_operation op, int prio) |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 131 | { |
Nicholas Faustini | d30ba23 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 132 | if (prio >= ARRAY_SIZE(env_locations)) |
| 133 | return ENVL_UNKNOWN; |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 134 | |
Nicholas Faustini | d30ba23 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 135 | return env_locations[prio]; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 136 | } |
| 137 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * env_driver_lookup() - Finds the most suited environment location |
| 141 | * @op: operations performed on the environment |
| 142 | * @prio: priority between the multiple environments, 0 being the |
| 143 | * highest priority |
| 144 | * |
| 145 | * This will try to find the available environment with the highest |
| 146 | * priority in the system. |
| 147 | * |
| 148 | * Returns: |
| 149 | * NULL on error, a pointer to a struct env_driver otherwise |
| 150 | */ |
| 151 | static struct env_driver *env_driver_lookup(enum env_operation op, int prio) |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 152 | { |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 153 | enum env_location loc = env_get_location(op, prio); |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 154 | struct env_driver *drv; |
| 155 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 156 | if (loc == ENVL_UNKNOWN) |
| 157 | return NULL; |
| 158 | |
Maxime Ripard | 52746c4 | 2018-01-23 21:16:51 +0100 | [diff] [blame] | 159 | drv = _env_driver_lookup(loc); |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 160 | if (!drv) { |
| 161 | debug("%s: No environment driver for location %d\n", __func__, |
| 162 | loc); |
| 163 | return NULL; |
| 164 | } |
| 165 | |
| 166 | return drv; |
| 167 | } |
| 168 | |
Goldschmidt Simon | b2cdef4 | 2018-02-09 20:23:17 +0000 | [diff] [blame] | 169 | __weak int env_get_char_spec(int index) |
| 170 | { |
| 171 | return *(uchar *)(gd->env_addr + index); |
| 172 | } |
| 173 | |
Simon Glass | a69d0f6 | 2017-08-03 12:22:06 -0600 | [diff] [blame] | 174 | int env_get_char(int index) |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 175 | { |
Simon Glass | 2d7cb5b | 2017-08-20 04:45:15 -0600 | [diff] [blame] | 176 | if (gd->env_valid == ENV_INVALID) |
Simon Glass | a69d0f6 | 2017-08-03 12:22:06 -0600 | [diff] [blame] | 177 | return default_environment[index]; |
Goldschmidt Simon | b2cdef4 | 2018-02-09 20:23:17 +0000 | [diff] [blame] | 178 | else |
| 179 | return env_get_char_spec(index); |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | int env_load(void) |
| 183 | { |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 184 | struct env_driver *drv; |
Sam Protsenko | 293a172 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 185 | int best_prio = -1; |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 186 | int prio; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 187 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 188 | for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) { |
| 189 | int ret; |
| 190 | |
Maxime Ripard | 1d44608 | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 191 | if (!env_has_inited(drv->location)) |
| 192 | continue; |
| 193 | |
Maxime Ripard | 3574ba0 | 2018-01-23 21:16:54 +0100 | [diff] [blame] | 194 | printf("Loading Environment from %s... ", drv->name); |
Sam Protsenko | 13bbfb4 | 2018-07-30 19:19:26 +0300 | [diff] [blame] | 195 | /* |
| 196 | * In error case, the error message must be printed during |
| 197 | * drv->load() in some underlying API, and it must be exactly |
| 198 | * one message. |
| 199 | */ |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 200 | ret = drv->load(); |
Sam Protsenko | 293a172 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 201 | if (!ret) { |
Maxime Ripard | 3574ba0 | 2018-01-23 21:16:54 +0100 | [diff] [blame] | 202 | printf("OK\n"); |
Patrick Delaunay | 6d8d840 | 2020-07-28 11:51:17 +0200 | [diff] [blame] | 203 | gd->env_load_prio = prio; |
| 204 | |
Marek Vasut | 47f3b1f | 2020-07-07 20:51:38 +0200 | [diff] [blame] | 205 | #if !CONFIG_IS_ENABLED(ENV_APPEND) |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 206 | return 0; |
Marek Vasut | 47f3b1f | 2020-07-07 20:51:38 +0200 | [diff] [blame] | 207 | #endif |
Sam Protsenko | 293a172 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 208 | } else if (ret == -ENOMSG) { |
| 209 | /* Handle "bad CRC" case */ |
| 210 | if (best_prio == -1) |
| 211 | best_prio = prio; |
| 212 | } else { |
| 213 | debug("Failed (%d)\n", ret); |
Sam Protsenko | 13bbfb4 | 2018-07-30 19:19:26 +0300 | [diff] [blame] | 214 | } |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 215 | } |
| 216 | |
Nicholas Faustini | d30ba23 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 217 | /* |
| 218 | * In case of invalid environment, we set the 'default' env location |
Sam Protsenko | 293a172 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 219 | * to the best choice, i.e.: |
| 220 | * 1. Environment location with bad CRC, if such location was found |
| 221 | * 2. Otherwise use the location with highest priority |
| 222 | * |
| 223 | * This way, next calls to env_save() will restore the environment |
| 224 | * at the right place. |
Nicholas Faustini | d30ba23 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 225 | */ |
Sam Protsenko | 293a172 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 226 | if (best_prio >= 0) |
| 227 | debug("Selecting environment with bad CRC\n"); |
| 228 | else |
| 229 | best_prio = 0; |
Patrick Delaunay | 6d8d840 | 2020-07-28 11:51:17 +0200 | [diff] [blame] | 230 | |
| 231 | gd->env_load_prio = best_prio; |
Nicholas Faustini | d30ba23 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 232 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 233 | return -ENODEV; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 234 | } |
| 235 | |
Patrick Delaunay | 0115dd3 | 2020-07-28 11:51:20 +0200 | [diff] [blame] | 236 | int env_reload(void) |
| 237 | { |
| 238 | struct env_driver *drv; |
| 239 | |
| 240 | drv = env_driver_lookup(ENVOP_LOAD, gd->env_load_prio); |
| 241 | if (drv) { |
| 242 | int ret; |
| 243 | |
| 244 | printf("Loading Environment from %s... ", drv->name); |
| 245 | |
| 246 | if (!env_has_inited(drv->location)) { |
| 247 | printf("not initialized\n"); |
| 248 | return -ENODEV; |
| 249 | } |
| 250 | |
| 251 | ret = drv->load(); |
| 252 | if (ret) |
| 253 | printf("Failed (%d)\n", ret); |
| 254 | else |
| 255 | printf("OK\n"); |
| 256 | |
| 257 | if (!ret) |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | return -ENODEV; |
| 262 | } |
| 263 | |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 264 | int env_save(void) |
| 265 | { |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 266 | struct env_driver *drv; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 267 | |
Nicholas Faustini | d30ba23 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 268 | drv = env_driver_lookup(ENVOP_SAVE, gd->env_load_prio); |
| 269 | if (drv) { |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 270 | int ret; |
Maxime Ripard | 9c24dfb | 2018-01-23 21:16:50 +0100 | [diff] [blame] | 271 | |
Maxime Ripard | 9efac3c | 2018-01-23 21:16:53 +0100 | [diff] [blame] | 272 | printf("Saving Environment to %s... ", drv->name); |
Patrick Delaunay | 8968288 | 2020-06-24 10:17:50 +0200 | [diff] [blame] | 273 | if (!drv->save) { |
| 274 | printf("not possible\n"); |
| 275 | return -ENODEV; |
| 276 | } |
| 277 | |
| 278 | if (!env_has_inited(drv->location)) { |
| 279 | printf("not initialized\n"); |
| 280 | return -ENODEV; |
| 281 | } |
| 282 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 283 | ret = drv->save(); |
Maxime Ripard | 3574ba0 | 2018-01-23 21:16:54 +0100 | [diff] [blame] | 284 | if (ret) |
| 285 | printf("Failed (%d)\n", ret); |
| 286 | else |
| 287 | printf("OK\n"); |
| 288 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 289 | if (!ret) |
| 290 | return 0; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 291 | } |
| 292 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 293 | return -ENODEV; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 294 | } |
| 295 | |
Frank Wunderlich | cd121bd | 2019-06-29 11:36:19 +0200 | [diff] [blame] | 296 | int env_erase(void) |
| 297 | { |
| 298 | struct env_driver *drv; |
| 299 | |
| 300 | drv = env_driver_lookup(ENVOP_ERASE, gd->env_load_prio); |
| 301 | if (drv) { |
| 302 | int ret; |
| 303 | |
| 304 | if (!drv->erase) |
| 305 | return -ENODEV; |
| 306 | |
| 307 | if (!env_has_inited(drv->location)) |
| 308 | return -ENODEV; |
| 309 | |
| 310 | printf("Erasing Environment on %s... ", drv->name); |
| 311 | ret = drv->erase(); |
| 312 | if (ret) |
| 313 | printf("Failed (%d)\n", ret); |
| 314 | else |
| 315 | printf("OK\n"); |
| 316 | |
| 317 | if (!ret) |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | return -ENODEV; |
| 322 | } |
| 323 | |
Simon Glass | 6eeae42 | 2017-08-03 12:22:05 -0600 | [diff] [blame] | 324 | int env_init(void) |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 325 | { |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 326 | struct env_driver *drv; |
Simon Glass | 7938822 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 327 | int ret = -ENOENT; |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 328 | int prio; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 329 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 330 | for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) { |
Maxime Ripard | 1d44608 | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 331 | if (!drv->init || !(ret = drv->init())) |
| 332 | env_set_inited(drv->location); |
Heiko Schocher | 46ce9e7 | 2020-11-03 15:22:36 +0100 | [diff] [blame] | 333 | if (ret == -ENOENT) |
| 334 | env_set_inited(drv->location); |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 335 | |
Maxime Ripard | 1d44608 | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 336 | debug("%s: Environment %s init done (ret=%d)\n", __func__, |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 337 | drv->name, ret); |
| 338 | } |
| 339 | |
| 340 | if (!prio) |
| 341 | return -ENODEV; |
| 342 | |
Simon Glass | 7938822 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 343 | if (ret == -ENOENT) { |
| 344 | gd->env_addr = (ulong)&default_environment[0]; |
Tom Rini | eeba55c | 2017-08-19 22:27:57 -0400 | [diff] [blame] | 345 | gd->env_valid = ENV_VALID; |
Simon Glass | 7938822 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 346 | |
| 347 | return 0; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 348 | } |
| 349 | |
Maxime Ripard | 8a3a7e2 | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 350 | return ret; |
Simon Glass | c9d728d | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 351 | } |
Patrick Delaunay | a97d22e | 2020-07-28 11:51:21 +0200 | [diff] [blame] | 352 | |
| 353 | int env_select(const char *name) |
| 354 | { |
| 355 | struct env_driver *drv; |
| 356 | const int n_ents = ll_entry_count(struct env_driver, env_driver); |
| 357 | struct env_driver *entry; |
| 358 | int prio; |
| 359 | bool found = false; |
| 360 | |
| 361 | printf("Select Environment on %s: ", name); |
| 362 | |
| 363 | /* search ENV driver by name */ |
| 364 | drv = ll_entry_start(struct env_driver, env_driver); |
| 365 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 366 | if (!strcmp(entry->name, name)) { |
| 367 | found = true; |
| 368 | break; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | if (!found) { |
| 373 | printf("driver not found\n"); |
| 374 | return -ENODEV; |
| 375 | } |
| 376 | |
| 377 | /* search priority by driver */ |
| 378 | for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) { |
| 379 | if (entry->location == env_get_location(ENVOP_LOAD, prio)) { |
| 380 | /* when priority change, reset the ENV flags */ |
| 381 | if (gd->env_load_prio != prio) { |
| 382 | gd->env_load_prio = prio; |
| 383 | gd->env_valid = ENV_INVALID; |
| 384 | gd->flags &= ~GD_FLG_ENV_DEFAULT; |
| 385 | } |
| 386 | printf("OK\n"); |
| 387 | return 0; |
| 388 | } |
| 389 | } |
| 390 | printf("priority not found\n"); |
| 391 | |
| 392 | return -ENODEV; |
| 393 | } |