uboot启动流程-run_main_loop 到 cmd_process处理说明一

一. uboot启动

**uboot命令模式:**uboot 启动以后会进入 3 秒倒计时,如果在 3 秒倒计时结束之前按下按下回车键,那么就会进入 uboot 的命令模式。
如果在 uboot 倒计时结束以后都没有按下回车键,就会自动启动 Linux 内 核 , 这 个 功 能 就 是 由 run_main_loop 函 数 来 完 成 的 。

二. run_main_loop函数 到 cmd_process处理

1. run_main_loop函数

run_main_loop 函 数 定 义 在 文 件 common/board_r.c 中,函数内容如下:

复制代码
static int run_main_loop(void)
{
#ifdef CONFIG_SANDBOX
	sandbox_main_loop_init();
#endif
	/* main_loop() can return to retry autoboot, if so just run it again */
	for (;;)
		main_loop();
	return 0;
}

" for (;;) "" while(1) **"**功能一样,死循环里面就一个 main_loop 函数。

2. main_loop 函数

main_loop 函数定义在 common/main.c 文件 里面。 代码如下:

复制代码
void main_loop(void)
{
	const char *s;

	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");

#ifndef CONFIG_SYS_GENERIC_BOARD
	puts("Warning: Your board does not use generic board. Please read\n");
	puts("doc/README.generic-board and take action. Boards not\n");
	puts("upgraded by the late 2014 may break or be removed.\n");
#endif

#ifdef CONFIG_VERSION_VARIABLE
	setenv("ver", version_string);  /* set version variable */
#endif /* CONFIG_VERSION_VARIABLE */

	cli_init();

	run_preboot_environment_command();

#if defined(CONFIG_UPDATE_TFTP)
	update_tftp(0UL, NULL, NULL);
#endif /* CONFIG_UPDATE_TFTP */

	s = bootdelay_process();
	if (cli_process_fdt(&s))
		cli_secure_boot_cmd(s);

	autoboot_command(s);

	cli_loop();
}

main_loop 函数中:

第 5 行,调用 bootstage_mark_name 函数,打印出启动进度。
第 13 行,如果定义了宏 CONFIG_VERSION_VARIABLE, 就会执行函数 setenv ,设置
变量 ver 的值为 version_string ,也就是设置版本号环境变量。 version_string 定义在文件
cmd/version.c 中,定义如下:

复制代码
const char __weak version_string[] = U_BOOT_VERSION_STRING;

经过搜索,一系列分析可知,Uboot打印如下:

U-Boot 2016.03 (Jul 07 2023 - 17:11:27 +0800)

相关推荐
~黄夫人~8 分钟前
Ubuntu系统快速上手命令(详细)
linux·运维·笔记·ubuntu·postgresql
发光的沙子14 分钟前
FPGA----petalinux的Ubuntu文件系统移植
linux·运维·ubuntu
lili-felicity20 分钟前
解决VMware Workstation Pro 17中Ubuntu 24.04无法复制粘贴
linux·运维·ubuntu
Lzc77421 分钟前
Linux网络的应用层自定义协议
linux·应用层自定义协议与序列化
虚伪的空想家1 小时前
HUAWEI A800I A2 aarch64架构服务器鲲鹏920开启虚拟化功能
linux·运维·服务器·显卡·npu·huawei·鲲鹏920
笨蛋少年派1 小时前
将 MapReduce 程序打成 JAR 包并在 Linux 虚拟机的 Hadoop 集群上运行
linux·jar·mapreduce
刚刚觉醒的小菜鸡1 小时前
ssh连接本地虚拟机
linux·服务器·ssh
持梦远方1 小时前
Linux之认识理解目录
linux·运维·服务器
瑶总迷弟2 小时前
使用 Docker 和 docker-compose 快速部署 openGauss
linux·数据库·云原生·eureka
BothSavage2 小时前
Ubuntu-8卡H20服务器升级nvidia驱动+cuda版本
linux·服务器·ubuntu·gpu·nvidia·cuda·nvcc