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