初始化在board_f.c,读取flash环境变量到ddr内在board_r.c
arch/arm/cpu/armv8/start.S
bl _main
arch/arm/lib/crt0_64.S
xxxx
bl board_init_f
xxxx
b board_init_r
common
board_f.c
static const init_fnc_t init_sequence_f[] = {
setup_mon_len,
arch_cpu_init, /* basic arch cpu dependent setup */
mach_cpu_init, /* SoC/machine dependent CPU setup */
initf_dm,
arch_cpu_init_dm,
#if defined(CONFIG_BOARD_EARLY_INIT_F)
board_early_init_f,
#endif
env_init, /* initialize environment */ //这里初始化环境变量
init_baud_rate, /* initialze baudrate settings */
serial_init, /* serial communications setup */
console_init_f, /* stage 1 init of console */
display_options, /* say that we are here */
display_text_info, /* show debugging info if required */
xxxx
NULL,
};
env/env.c
int env_init(void)
{
struct env_driver *drv;
int ret = -ENOENT;
int prio;
for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
if (!drv->init || !(ret = drv->init()))
env_set_inited(drv->location);
debug("%s: Environment %s init done (ret=%d)\n", __func__,
drv->name, ret);
}
if (!prio)
return -ENODEV;
if (ret == -ENOENT) {
gd->env_addr = (ulong)&default_environment[0];
gd->env_valid = ENV_VALID;
return 0;
}
return ret;
}
include/env_default.h
common
board_r.c
static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_ARCH_EARLY_INIT_R
arch_early_init_r,
#endif
power_init_board,
#ifdef CONFIG_MTD_NOR_FLASH
initr_flash,
#endif
INIT_FUNC_WATCHDOG_RESET
#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
/* initialize higher level parts of CPU like time base and timers */
cpu_init_r,
#endif
#ifdef CONFIG_CMD_SF
initr_snor,
#endif
#ifdef CONFIG_CMD_NAND
initr_nand,
#endif
#ifdef CONFIG_CMD_ONENAND
initr_onenand,
#endif
#ifdef CONFIG_MMC
initr_mmc,
#endif
initr_env, //这里重定位环境变量
xxxxx
#ifdef CONFIG_POST
initr_post,
#endif
run_main_loop,
};
static int initr_env(void)
{
/* initialize environment */
if (should_load_env())
env_relocate();
else
env_set_default(NULL, 0);
return 0;
}
env/common.c
void env_relocate(void)
{
if (gd->env_valid == ENV_INVALID) {
#if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD)
/* Environment not changable */
env_set_default(NULL, 0);
#else
bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM);
env_set_default("bad CRC", 0);
#endif
} else {
env_load(); // 这里读环境变量到DDR
}
}
env/sf.c
U_BOOT_ENV_LOCATION(sf) = {
.location = ENVL_SPI_FLASH,
ENV_NAME("SPI Flash")
.load = env_sf_load,
#ifdef CMD_SAVEENV
.save = env_save_ptr(env_sf_save),
#endif
#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
.init = env_sf_init,
#endif
};
env_sf_load
ret = spi_flash_read(env_flash,CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
ret = env_import(buf, 1);