summaryrefslogtreecommitdiff
path: root/env/sf.c
diff options
context:
space:
mode:
authorAshish Kumar <Ashish.Kumar@nxp.com>2017-12-14 17:37:08 +0530
committerYork Sun <york.sun@nxp.com>2018-01-17 10:30:54 -0800
commitb500c92b70e8e103ca75f95e4b0e97d92dddf185 (patch)
tree7ec8ef86ba73f647ad4869efe8dfa67188958674 /env/sf.c
parent134200a5efffcbba56bdb6954d5b3527ea1fa09c (diff)
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>
Diffstat (limited to 'env/sf.c')
-rw-r--r--env/sf.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/env/sf.c b/env/sf.c
index e51b1ae189..a2e4c93631 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -34,6 +34,7 @@
#ifndef CONFIG_SPL_BUILD
#define CMD_SAVEENV
+#define INITENV
#endif
#ifdef CONFIG_ENV_OFFSET_REDUND
@@ -348,6 +349,23 @@ out:
}
#endif
+#if defined(INITENV) && defined(CONFIG_ENV_ADDR)
+static int env_sf_init(void)
+{
+ env_t *env_ptr = (env_t *)(CONFIG_ENV_ADDR);
+
+ if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
+ gd->env_addr = (ulong)&(env_ptr->data);
+ gd->env_valid = 1;
+ } else {
+ gd->env_addr = (ulong)&default_environment[0];
+ gd->env_valid = 1;
+ }
+
+ return 0;
+}
+#endif
+
U_BOOT_ENV_LOCATION(sf) = {
.location = ENVL_SPI_FLASH,
ENV_NAME("SPI Flash")
@@ -355,4 +373,7 @@ U_BOOT_ENV_LOCATION(sf) = {
#ifdef CMD_SAVEENV
.save = env_save_ptr(env_sf_save),
#endif
+#if defined(INITENV) && defined(CONFIG_ENV_ADDR)
+ .init = env_sf_init,
+#endif
};