uboot 环境变量初始化流程

初始化在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);
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今天6点半起床10点半睡觉和今天早晚运动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值