Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 15e5a1a | 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 | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 79fd214 | 2019-08-01 09:46:43 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 9 | #include <env_internal.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Simon Glass | c06c1be | 2020-05-10 11:40:08 -0600 | [diff] [blame] | 13 | #include <linux/bug.h> |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Siva Durga Prasad Paladugu | 75c6579 | 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 | 33afa93 | 2019-06-29 11:36:19 +0200 | [diff] [blame] | 32 | if (entry->erase) |
| 33 | entry->erase += gd->reloc_off; |
Siva Durga Prasad Paladugu | 75c6579 | 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 | b7da89a | 2018-01-23 21:16:51 +0100 | [diff] [blame] | 40 | static struct env_driver *_env_driver_lookup(enum env_location loc) |
Simon Glass | 15e5a1a | 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 | 520cf80 | 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 | a44849a | 2019-01-04 09:34:24 +0000 | [diff] [blame] | 81 | #ifdef CONFIG_ENV_IS_IN_SATA |
| 82 | ENVL_ESATA, |
| 83 | #endif |
Maxime Ripard | 520cf80 | 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 | 2131c5e | 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 | 13ac85a | 2020-06-24 09:27:25 +0200 | [diff] [blame] | 107 | BUILD_BUG_ON(ENVL_COUNT > BITS_PER_LONG); |
Maxime Ripard | 2131c5e | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 108 | |
| 109 | gd->env_has_init |= BIT(location); |
| 110 | } |
| 111 | |
Maxime Ripard | fd3158e | 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 | 8944875 | 2018-01-23 21:17:02 +0100 | [diff] [blame] | 119 | * This is overridable by boards if they need to. |
Maxime Ripard | fd3158e | 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 | 8944875 | 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 | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 131 | { |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 132 | if (prio >= ARRAY_SIZE(env_locations)) |
| 133 | return ENVL_UNKNOWN; |
Maxime Ripard | 520cf80 | 2018-01-23 21:16:58 +0100 | [diff] [blame] | 134 | |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 135 | return env_locations[prio]; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 136 | } |
| 137 | |
Maxime Ripard | fd3158e | 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 | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 152 | { |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 153 | enum env_location loc = env_get_location(op, prio); |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 154 | struct env_driver *drv; |
| 155 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 156 | if (loc == ENVL_UNKNOWN) |
| 157 | return NULL; |
| 158 | |
Maxime Ripard | b7da89a | 2018-01-23 21:16:51 +0100 | [diff] [blame] | 159 | drv = _env_driver_lookup(loc); |
Simon Glass | 15e5a1a | 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 | |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 169 | int env_load(void) |
| 170 | { |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 171 | struct env_driver *drv; |
Sam Protsenko | 239f312 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 172 | int best_prio = -1; |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 173 | int prio; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 174 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 175 | for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) { |
| 176 | int ret; |
| 177 | |
Maxime Ripard | 2131c5e | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 178 | if (!env_has_inited(drv->location)) |
| 179 | continue; |
| 180 | |
Maxime Ripard | 185402a | 2018-01-23 21:16:54 +0100 | [diff] [blame] | 181 | printf("Loading Environment from %s... ", drv->name); |
Sam Protsenko | 051dfd8 | 2018-07-30 19:19:26 +0300 | [diff] [blame] | 182 | /* |
| 183 | * In error case, the error message must be printed during |
| 184 | * drv->load() in some underlying API, and it must be exactly |
| 185 | * one message. |
| 186 | */ |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 187 | ret = drv->load(); |
Sam Protsenko | 239f312 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 188 | if (!ret) { |
Maxime Ripard | 185402a | 2018-01-23 21:16:54 +0100 | [diff] [blame] | 189 | printf("OK\n"); |
Patrick Delaunay | a639f4e | 2020-07-28 11:51:17 +0200 | [diff] [blame] | 190 | gd->env_load_prio = prio; |
| 191 | |
Marek Vasut | a7b8267 | 2020-07-07 20:51:38 +0200 | [diff] [blame] | 192 | #if !CONFIG_IS_ENABLED(ENV_APPEND) |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 193 | return 0; |
Marek Vasut | a7b8267 | 2020-07-07 20:51:38 +0200 | [diff] [blame] | 194 | #endif |
Sam Protsenko | 239f312 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 195 | } else if (ret == -ENOMSG) { |
| 196 | /* Handle "bad CRC" case */ |
| 197 | if (best_prio == -1) |
| 198 | best_prio = prio; |
| 199 | } else { |
| 200 | debug("Failed (%d)\n", ret); |
Sam Protsenko | 051dfd8 | 2018-07-30 19:19:26 +0300 | [diff] [blame] | 201 | } |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 202 | } |
| 203 | |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 204 | /* |
| 205 | * In case of invalid environment, we set the 'default' env location |
Sam Protsenko | 239f312 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 206 | * to the best choice, i.e.: |
| 207 | * 1. Environment location with bad CRC, if such location was found |
| 208 | * 2. Otherwise use the location with highest priority |
| 209 | * |
| 210 | * This way, next calls to env_save() will restore the environment |
| 211 | * at the right place. |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 212 | */ |
Sam Protsenko | 239f312 | 2019-01-18 21:19:04 +0200 | [diff] [blame] | 213 | if (best_prio >= 0) |
| 214 | debug("Selecting environment with bad CRC\n"); |
| 215 | else |
| 216 | best_prio = 0; |
Patrick Delaunay | a639f4e | 2020-07-28 11:51:17 +0200 | [diff] [blame] | 217 | |
| 218 | gd->env_load_prio = best_prio; |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 219 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 220 | return -ENODEV; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 221 | } |
| 222 | |
Patrick Delaunay | 748e42e | 2020-07-28 11:51:20 +0200 | [diff] [blame] | 223 | int env_reload(void) |
| 224 | { |
| 225 | struct env_driver *drv; |
| 226 | |
| 227 | drv = env_driver_lookup(ENVOP_LOAD, gd->env_load_prio); |
| 228 | if (drv) { |
| 229 | int ret; |
| 230 | |
| 231 | printf("Loading Environment from %s... ", drv->name); |
| 232 | |
| 233 | if (!env_has_inited(drv->location)) { |
| 234 | printf("not initialized\n"); |
| 235 | return -ENODEV; |
| 236 | } |
| 237 | |
| 238 | ret = drv->load(); |
| 239 | if (ret) |
| 240 | printf("Failed (%d)\n", ret); |
| 241 | else |
| 242 | printf("OK\n"); |
| 243 | |
| 244 | if (!ret) |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | return -ENODEV; |
| 249 | } |
| 250 | |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 251 | int env_save(void) |
| 252 | { |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 253 | struct env_driver *drv; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 254 | |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 255 | drv = env_driver_lookup(ENVOP_SAVE, gd->env_load_prio); |
| 256 | if (drv) { |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 257 | int ret; |
Maxime Ripard | 3c0b2e5 | 2018-01-23 21:16:50 +0100 | [diff] [blame] | 258 | |
Patrick Delaunay | 65bbec2 | 2020-06-24 10:17:50 +0200 | [diff] [blame] | 259 | printf("Saving Environment to %s... ", drv->name); |
| 260 | if (!drv->save) { |
| 261 | printf("not possible\n"); |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 262 | return -ENODEV; |
Patrick Delaunay | 65bbec2 | 2020-06-24 10:17:50 +0200 | [diff] [blame] | 263 | } |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 264 | |
Patrick Delaunay | 65bbec2 | 2020-06-24 10:17:50 +0200 | [diff] [blame] | 265 | if (!env_has_inited(drv->location)) { |
| 266 | printf("not initialized\n"); |
Nicholas Faustini | a8a17f8 | 2018-07-23 10:01:07 +0200 | [diff] [blame] | 267 | return -ENODEV; |
Patrick Delaunay | 65bbec2 | 2020-06-24 10:17:50 +0200 | [diff] [blame] | 268 | } |
Maxime Ripard | 2131c5e | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 269 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 270 | ret = drv->save(); |
Maxime Ripard | 185402a | 2018-01-23 21:16:54 +0100 | [diff] [blame] | 271 | if (ret) |
| 272 | printf("Failed (%d)\n", ret); |
| 273 | else |
| 274 | printf("OK\n"); |
| 275 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 276 | if (!ret) |
| 277 | return 0; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 278 | } |
| 279 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 280 | return -ENODEV; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 281 | } |
| 282 | |
Frank Wunderlich | 33afa93 | 2019-06-29 11:36:19 +0200 | [diff] [blame] | 283 | int env_erase(void) |
| 284 | { |
| 285 | struct env_driver *drv; |
| 286 | |
| 287 | drv = env_driver_lookup(ENVOP_ERASE, gd->env_load_prio); |
| 288 | if (drv) { |
| 289 | int ret; |
| 290 | |
| 291 | if (!drv->erase) |
| 292 | return -ENODEV; |
| 293 | |
| 294 | if (!env_has_inited(drv->location)) |
| 295 | return -ENODEV; |
| 296 | |
| 297 | printf("Erasing Environment on %s... ", drv->name); |
| 298 | ret = drv->erase(); |
| 299 | if (ret) |
| 300 | printf("Failed (%d)\n", ret); |
| 301 | else |
| 302 | printf("OK\n"); |
| 303 | |
| 304 | if (!ret) |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | return -ENODEV; |
| 309 | } |
| 310 | |
Simon Glass | 36d8581 | 2017-08-03 12:22:05 -0600 | [diff] [blame] | 311 | int env_init(void) |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 312 | { |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 313 | struct env_driver *drv; |
Simon Glass | d40d804 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 314 | int ret = -ENOENT; |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 315 | int prio; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 316 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 317 | for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) { |
Maxime Ripard | 2131c5e | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 318 | if (!drv->init || !(ret = drv->init())) |
| 319 | env_set_inited(drv->location); |
Heiko Schocher | 8ba7b61 | 2020-11-03 15:22:36 +0100 | [diff] [blame] | 320 | if (ret == -ENOENT) |
| 321 | env_set_inited(drv->location); |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 322 | |
Maxime Ripard | 2131c5e | 2018-01-23 21:16:59 +0100 | [diff] [blame] | 323 | debug("%s: Environment %s init done (ret=%d)\n", __func__, |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 324 | drv->name, ret); |
| 325 | } |
| 326 | |
Felix.Vietmeyer@jila.colorado.edu | d0f9106 | 2021-04-20 20:04:26 -0600 | [diff] [blame^] | 327 | if (!prio) { |
| 328 | gd->env_addr = (ulong)&default_environment[0]; |
| 329 | gd->env_valid = ENV_INVALID; |
| 330 | |
| 331 | return 0; |
| 332 | } |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 333 | |
Simon Glass | d40d804 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 334 | if (ret == -ENOENT) { |
| 335 | gd->env_addr = (ulong)&default_environment[0]; |
Felix.Vietmeyer@jila.colorado.edu | d0f9106 | 2021-04-20 20:04:26 -0600 | [diff] [blame^] | 336 | gd->env_valid = ENV_INVALID; |
Simon Glass | d40d804 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 337 | |
| 338 | return 0; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 339 | } |
| 340 | |
Maxime Ripard | fd3158e | 2018-01-23 21:16:52 +0100 | [diff] [blame] | 341 | return ret; |
Simon Glass | 15e5a1a | 2017-08-03 12:22:00 -0600 | [diff] [blame] | 342 | } |
Patrick Delaunay | a59f7ec | 2020-07-28 11:51:21 +0200 | [diff] [blame] | 343 | |
| 344 | int env_select(const char *name) |
| 345 | { |
| 346 | struct env_driver *drv; |
| 347 | const int n_ents = ll_entry_count(struct env_driver, env_driver); |
| 348 | struct env_driver *entry; |
| 349 | int prio; |
| 350 | bool found = false; |
| 351 | |
| 352 | printf("Select Environment on %s: ", name); |
| 353 | |
| 354 | /* search ENV driver by name */ |
| 355 | drv = ll_entry_start(struct env_driver, env_driver); |
| 356 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 357 | if (!strcmp(entry->name, name)) { |
| 358 | found = true; |
| 359 | break; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (!found) { |
| 364 | printf("driver not found\n"); |
| 365 | return -ENODEV; |
| 366 | } |
| 367 | |
| 368 | /* search priority by driver */ |
| 369 | for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) { |
| 370 | if (entry->location == env_get_location(ENVOP_LOAD, prio)) { |
| 371 | /* when priority change, reset the ENV flags */ |
| 372 | if (gd->env_load_prio != prio) { |
| 373 | gd->env_load_prio = prio; |
| 374 | gd->env_valid = ENV_INVALID; |
| 375 | gd->flags &= ~GD_FLG_ENV_DEFAULT; |
| 376 | } |
| 377 | printf("OK\n"); |
| 378 | return 0; |
| 379 | } |
| 380 | } |
| 381 | printf("priority not found\n"); |
| 382 | |
| 383 | return -ENODEV; |
| 384 | } |