目录
本文主要基于XLY-stm32mp157-STY分析,uboot启动内核前的准备工作分析,重点讲解启动uboot后如何启动内核过程。下图为uboot启动过程。
下面主要讲解的是进入main_loop循环后的启动分析。
进入main_loop后,读取到变量bootcmd。bootcmd为自动启动时执行的命令,在日常开发过程中只需要修改此部分内容就可以满足日常开发所用。
接下来主要讲解一下此命令具体内容。
启动命令:bootcmd
概念图如下:
我们使用的示例为STM32MP157-STY,则 bootcmd 的启动命令为 bootcmd_stm32mp。
bootcmd_stm32mp=echo "Boot over ${boot_device}${boot_instance}!";if test ${boot_device} = serial || test ${boot_device} = usb;then stm32prog ${boot_device} ${boot_instance}; else run env_check;if test ${boot_device} = mmc;then env set boot_targets "mmc${boot_instance}"; fi;if test ${boot_device} = nand || test ${boot_device} = spi-nand ;then env set boot_targets ubifs0; fi;if test ${boot_device} = nor;then env set boot_targets mmc0; fi;run distro_bootcmd;fi;
因为存储的命令行看起来不符合我们日常开发所用的格式,特意展开为以下命令,这样就符合我们日常开发所用格式。看起来就会很清晰。
bootcmd_stm32mp=
echo "Boot over ${boot_device}${boot_instance}!"; // boot_device:设备名称,boot_instance:设备号,本例为mmc1启动
if test ${boot_device} = serial || test ${boot_device} = usb;then //检测到USB或者serial连接,则执行stm32prog。使用usb下载工具。
stm32prog ${boot_device} ${boot_instance};
else
run env_check;
if test ${boot_device} = mmc;then
env set boot_targets "mmc${boot_instance}"; //设置boot_targets参数为mmc启动,设备号为boot_instance,本例为mmc1。
fi;
if test ${boot_device} = nand || test ${boot_device} = spi-nand ;then
env set boot_targets ubifs0; //若boot_device为spi-nand时,设置boot_targets参数为ubifs0,此为固态存储设备启动。
fi;
if test ${boot_device} = nor;then
env set boot_targets mmc0; //若boot_device为nor时,设置boot_targets参数为mmc0启动,SD卡启动。
fi;
run distro_bootcmd;
fi;
一、env_check
env_check=env exists env_ver || env set env_ver ${ver};if env info -p -d -q; then env save; fi;if test "$env_ver