Commit b500c92b70e8e103ca75f95e4b0e97d92dddf185
Committed by
York Sun
1 parent
134200a5ef
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
env: sf: Add support for env init for QSPI-NOR
ENV variables can now be used before relocation. Signed-off-by: Ashish Kumar <Ashish.Kumar@nxp.com> Reviewed-by: York Sun <york.sun@nxp.com>
Showing 1 changed file with 21 additions and 0 deletions Side-by-side Diff
env/sf.c
... | ... | @@ -34,6 +34,7 @@ |
34 | 34 | |
35 | 35 | #ifndef CONFIG_SPL_BUILD |
36 | 36 | #define CMD_SAVEENV |
37 | +#define INITENV | |
37 | 38 | #endif |
38 | 39 | |
39 | 40 | #ifdef CONFIG_ENV_OFFSET_REDUND |
40 | 41 | |
... | ... | @@ -348,12 +349,32 @@ |
348 | 349 | } |
349 | 350 | #endif |
350 | 351 | |
352 | +#if defined(INITENV) && defined(CONFIG_ENV_ADDR) | |
353 | +static int env_sf_init(void) | |
354 | +{ | |
355 | + env_t *env_ptr = (env_t *)(CONFIG_ENV_ADDR); | |
356 | + | |
357 | + if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { | |
358 | + gd->env_addr = (ulong)&(env_ptr->data); | |
359 | + gd->env_valid = 1; | |
360 | + } else { | |
361 | + gd->env_addr = (ulong)&default_environment[0]; | |
362 | + gd->env_valid = 1; | |
363 | + } | |
364 | + | |
365 | + return 0; | |
366 | +} | |
367 | +#endif | |
368 | + | |
351 | 369 | U_BOOT_ENV_LOCATION(sf) = { |
352 | 370 | .location = ENVL_SPI_FLASH, |
353 | 371 | ENV_NAME("SPI Flash") |
354 | 372 | .load = env_sf_load, |
355 | 373 | #ifdef CMD_SAVEENV |
356 | 374 | .save = env_save_ptr(env_sf_save), |
375 | +#endif | |
376 | +#if defined(INITENV) && defined(CONFIG_ENV_ADDR) | |
377 | + .init = env_sf_init, | |
357 | 378 | #endif |
358 | 379 | }; |