uboot bootcmd和bootargs环境变量设置

一.官方环境变量bootcmd

bootcmd变量定义位于“include/configs/mx6ull_my_evk.h”(copy from include/configs/mx6ullevk.h )中,
#define CONFIG_BOOTCOMMAND \
	   "run findfdt;" \
	   "mmc dev ${mmcdev};" \
	   "mmc dev ${mmcdev}; if mmc rescan; then " \
		   "if run loadbootscript; then " \
			   "run bootscript; " \
		   "else " \
			   "if run loadimage; then " \
				   "run mmcboot; " \
			   "else run netboot; " \
			   "fi; " \
		   "fi; " \
	   "else run netboot; fi"
#endif

此脚本主要做四件事,
a.MMC设备查找。
b.读取zImage
c.驱动设备树
d.启动Linux.
不做分析,删除,按照我们需求改写如下

#define CONFIG_BOOTCOMMAND \
	   	"mmc dev 1;" \
	   	"fatload mmc 1:1 0x80800000 zImage;" \
	   	"fatload mmc 1:1 0x83000000 imx6ull_my_evk.dtb;" \
	 	"bootz 0x80800000-0x83000000;"
#endif

修改后重启,发现该环境变量并没有生效
在这里插入图片描述
这是因为源码中,启动时会对环境变量进行检测,如果不为空,则不更新。
我们可以在uboot使用env命令对bootargs变量恢复默认值。

=> env help
env - environment handling commands

Usage:
env default [-f] -a - [forcibly] reset default environment
env default [-f] var [...] - [forcibly] reset variable(s) to their default values
env delete [-f] var [...] - [forcibly] delete variable(s)
env edit name - edit environment variable
env exists name - tests for existence of variable
env export [-t | -b | -c] [-s size] addr [var ...] - export environment
env import [-d] [-t [-r] | -b | -c] addr [size] - import environment
env print [-a | name ...] - print environment
env run var [...] - run commands in an environment variable
env save - save environment
env set [-f] name [arg ...]

对某一变量恢复,使用

env default [-f] var [...] - [forcibly] reset variable(s) to their default values

对所有变量恢复,使用命令

env default [-f] -a - [forcibly] reset default environment

运行结果:
在这里插入图片描述

可以看到变量已经恢复。

二.官方环境变量bootargs.

bootargs由第145-147行脚本设置而来。展开后为
		mmcargs=setenv bootargs console= ttymxc0, 115200 root= /dev/mmcblk1p2 rootwait rw

uboot bootcmd和bootargs环境变量设置_第1张图片
此环境变量根据自身环境决定是否需要修改。

你可能感兴趣的:(linux)