diff --git a/common/board_r.c b/common/board_r.c index cd79e97bae..818543446b 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -32,6 +32,7 @@ #endif #include #include +#include #ifdef CONFIG_BITBANGMII #include #endif @@ -435,6 +436,7 @@ static int initr_mmc(void) } #endif +#if !defined(CONFIG_USING_KERNEL_DTB) || !defined(CONFIG_ENV_IS_NOWHERE) /* * Tell if it's OK to load the environment early in boot. * @@ -473,6 +475,44 @@ static int initr_env(void) return 0; } +#endif + +#ifdef CONFIG_USING_KERNEL_DTB +static int initr_env_nowhere(void) +{ +#if defined(CONFIG_NEEDS_MANUAL_RELOC) + env_reloc(); + env_htab.change_ok += gd->reloc_off; +#endif + set_default_env(NULL); + + return 0; +} + +#if !defined(CONFIG_ENV_IS_NOWHERE) +static int initr_env_switch(void) +{ + ALLOC_CACHE_ALIGN_BUFFER(env_t, env_nowhere, 1); + int ret; + + /* Export nowhere env for late use */ + ret = env_export(env_nowhere); + if (ret) { + printf("%s: export nowhere env fail, ret=%d\n", __func__, ret); + return -EINVAL; + } + + /* Destroy nowhere env and import storage env */ + initr_env(); + + /* Append/override nowhere env to storage env */ + himport_r(&env_htab, (char *)env_nowhere->data, ENV_SIZE, '\0', + H_NOCLEAR, 0, 0, NULL); + + return 0; +} +#endif /* CONFIG_ENV_IS_NOWHERE */ +#endif /* CONFIG_USING_KERNEL_DTB */ #ifdef CONFIG_SYS_BOOTPARAMS_LEN static int initr_malloc_bootparams(void) @@ -738,12 +778,27 @@ static init_fnc_t init_sequence_r[] = { #ifdef CONFIG_DM initr_dm, #endif + +/* + * kernel dtb must depends on nowhere to detect boot storage media + * and initialize it. + */ #ifdef CONFIG_USING_KERNEL_DTB - initr_env, + initr_env_nowhere, #endif + #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) board_init, /* Setup chipselects */ #endif + +/* + * Now that storage has been initialized in board_init(), we could switch env + * from nowhere to storage, i.e. CONFIG_ENV_IS_IN_xxx=y. + */ +#if defined(CONFIG_USING_KERNEL_DTB) && !defined(CONFIG_ENV_IS_NOWHERE) + initr_env_switch, +#endif + /* * TODO: printing of the clock inforamtion of the board is now * implemented as part of bdinfo command. Currently only support for