env: sf: Allow to use env_sf_init_addr() at any stage
In some cases it makes sense to use env_sf_init_addr() also in SPL mode. Allow it for boards by providing custom implementation of weak function env_sf_get_env_addr(). When this function returns NULL it signals that address is invalid, like config option CONFIG_ENV_ADDR. There is no change in default behavior or in config options. Signed-off-by: Pali Rohár <pali@kernel.org>
This commit is contained in:
parent
c70c0102af
commit
f4bf81b013
22
env/sf.c
vendored
22
env/sf.c
vendored
@ -24,10 +24,6 @@
|
|||||||
#include <dm/device-internal.h>
|
#include <dm/device-internal.h>
|
||||||
#include <u-boot/crc.h>
|
#include <u-boot/crc.h>
|
||||||
|
|
||||||
#ifndef CONFIG_SPL_BUILD
|
|
||||||
#define INITENV
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define OFFSET_INVALID (~(u32)0)
|
#define OFFSET_INVALID (~(u32)0)
|
||||||
|
|
||||||
#ifdef CONFIG_ENV_OFFSET_REDUND
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
||||||
@ -322,14 +318,15 @@ done:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_ENV_ADDR != 0x0
|
|
||||||
__weak void *env_sf_get_env_addr(void)
|
__weak void *env_sf_get_env_addr(void)
|
||||||
{
|
{
|
||||||
|
#ifndef CONFIG_SPL_BUILD
|
||||||
return (void *)CONFIG_ENV_ADDR;
|
return (void *)CONFIG_ENV_ADDR;
|
||||||
}
|
#else
|
||||||
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
|
|
||||||
/*
|
/*
|
||||||
* check if Environment on CONFIG_ENV_ADDR is valid.
|
* check if Environment on CONFIG_ENV_ADDR is valid.
|
||||||
*/
|
*/
|
||||||
@ -337,6 +334,9 @@ static int env_sf_init_addr(void)
|
|||||||
{
|
{
|
||||||
env_t *env_ptr = (env_t *)env_sf_get_env_addr();
|
env_t *env_ptr = (env_t *)env_sf_get_env_addr();
|
||||||
|
|
||||||
|
if (!env_ptr)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
|
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
|
||||||
gd->env_addr = (ulong)&(env_ptr->data);
|
gd->env_addr = (ulong)&(env_ptr->data);
|
||||||
gd->env_valid = ENV_VALID;
|
gd->env_valid = ENV_VALID;
|
||||||
@ -346,7 +346,6 @@ static int env_sf_init_addr(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_ENV_SPI_EARLY)
|
#if defined(CONFIG_ENV_SPI_EARLY)
|
||||||
/*
|
/*
|
||||||
@ -432,9 +431,10 @@ out:
|
|||||||
|
|
||||||
static int env_sf_init(void)
|
static int env_sf_init(void)
|
||||||
{
|
{
|
||||||
#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
|
int ret = env_sf_init_addr();
|
||||||
return env_sf_init_addr();
|
if (ret != -ENOENT)
|
||||||
#elif defined(CONFIG_ENV_SPI_EARLY)
|
return ret;
|
||||||
|
#ifdef CONFIG_ENV_SPI_EARLY
|
||||||
return env_sf_init_early();
|
return env_sf_init_early();
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user