uboot图形化配置及其原理

uboot图形化配置及其原理
uboot可以通过 mx6ull_xxx_defconfig和 mx6ull_xxx_emmc.h文件来配置;另外还有一种配置uboot的方法,就是图形化配置
1.uboot图形化配置
1.1 图形化配置简介
uboot或 linux内核可以通过输入“make menuconfig”命令来打开图形化配置界面,menuconfig是一套图形化的配置工具,需要 ncurses库支持。 ncurses库提供零一系列的 api函数供调用者生成基于文本的图形界面,因此需要先在 ubuntu中安装 ncurses库
sudo apt-get install build-essentialsudo apt-get install libncurses5-devmenuconfig重点会用到两个文件:“.config”和“kconfig”,.config文件保存着uboot的配置项,使用 menuconfig配置完 uboot后该文件会被更新; kconfig文件是图形界面的描述文件,即描述界面应该有什么内容,很多目录下都会有kconfig文件
1.2 uboot图形化配置体验
在打开图形化配置界面前,需要先对 uboot进行一次默认配置。 之后使用“make menuconfig”命令打开图形化界面,打开后的界面如下示:
主界面上方的英文就是简单的操作说明,操作方法如下:
通过向上和向下按键选择要配置的菜单,“enter按键进入
选中后按y键会将相应的代码编译进uboot中,菜单前面变为
选中后按n键会取消编译相应的代码
选中后按m键会将相应的代码编译为模块,菜单前面变为
按两下esc键退出,也就是返回到上一级
按下?“ 键查看选中菜单的帮助信息
按下”/键打开搜索框,可在搜索框输入要搜索的内容
在配置界面下方有五个按钮,其功能如下:
select:选中按钮,和enter按键功能相同
exit:退出按钮,和esc按键功能相同
help:帮助按钮,查看选中菜单的帮助信息
save:保存按钮,保存修改后的配置文件
load:加载按钮,加载指定的配置文件
下面以使能dns命令为例,介绍如何通过图形化界面来配置uboot
进入command line interface配置项
进入network commands网络相关命令配置项
选中dns,按下y键将其编译到uboot中
按两下esc键退出,如果有修改项目,在退出主界面时会提示是否需要保存
保存后可在uboot源码中的.config文件中发现多了config_cmd_dns=y这一行
使用make arch=arm cross_compile=arm-linux-gnueabihf- -j16命令编译 uboot
注意:此时不能用脚本来编译,因为脚本文件在编译之前会清理工程,会删除掉.config文件,导致通过图形化界面配置的所有选项都被删除
编译完成烧写到sd卡后,重启开发板进入uboot命令模式,设置dns服务器的ip地址
setenv dnsip 114.114.114.114saveenv设置好后,使用dns命令即可查看百度官网的ip地址
dns www.baidu.com
2.menuconfig图形化配置原理
2.1 make menuconfig过程分析
当输入make menuconfig以后会匹配到顶层makefile中的如下代码:
%config: scripts_basic outputmakefile force $(q)$(make) $(build)=scripts/kconfig $@#其中build=-f ./scripts/makefile.build obj###将上面第二行的规则展开后:@make -f ./scripts/makefile.build obj=scripts/kconfig menuconfigmakefile.build会读取scripts/kconfig/makefile中的内容,在scripts/kconfig/makefile中有如下代码:
menuconfig: $(obj)/mconf $< $(silent) $(kconfig)#silent是这是静默编译的###展开后###menuconfig: scripts/kconfig/mconf scripts/kconfig/mconfkconfig目标menuconfig依赖scripts/kconfig/mconf,因此scripts/kconfig/mconf.c文件会被编译,生成mconf可执行文件;目标menuconfig对应的规则为scripts/kconfig/mconfkconfig, 也就是说mconf会调用uboot根目录下的kconfig文件开始构建图形配置界面
2.2 kconfig语法简介
对于kconfig语法不需要太深入的去研究,了解其原理即可。 打开uboot根目录下的顶层kconfig,以这个文件为例来简单学习一下kconfig语法
mainmenu:主菜单
##########顶层kconfig代码段##########mainmenu u-boot $ubootversion configurationsource命令调用其他目录下的kconfig文件
##########顶层kconfig代码段##########source arch/kconfig......source common/kconfigsource cmd/kconfigsource dts/kconfigsource net/kconfigsource drivers/kconfigsource fs/kconfigsource lib/kconfigsource test/kconfig##以上子目录下的kconfig文件在主菜单中生成各自的菜单项menu/endmenu条目:menu用于生成菜单,endmenu菜单结束标志
##########顶层kconfig代码段##########menu general setupconfig localversion string local version - append to u-boot release help append an extra string to the end of your u-boot version. this will show up on your boot log, for example. the string you set here will be appended after the contents of any files with a filename matching localversion* in your object and source tree, in that order. your total string can be a maximum of 64 characters.............endmenu # general setupmenu boot imagesconfig support_spl bool............endmenu # boot images以上代码中有两个menu/endmenu代码块,这两个代码块就是两个子菜单
config条目:是菜单里的具体配置项
##########顶层kconfig代码段##########menu general setupconfig localversion string local version - append to u-boot release help ......config localversion_auto bool automatically append version information to the version string default y #表示该配置项默认值是y,即默认被选中 help #表示帮助信息,告知配置项的含义,按下h或?会弹出help的内容 ......config cc_optimize_for_size bool optimize for size default y help ......config sys_malloc_f bool enable malloc() pool before relocation default y if dm help ......config sys_malloc_f_len hex size of malloc() pool before relocation depends on sys_malloc_f default 0x400 help ......menuconfig expert bool configure standard u-boot features (expert users) default y help ......if expert config sys_malloc_clear_on_init bool init with zeros the memory reserved for malloc (slow) default y help ......endifendmenu # general setup以上可看出,在menu/endmenu代码块中有大量的config xxx代码块(config条目)。 若使能了xxx功能,就会在 .config文件中生成 config_xxx
常用的三种变量类型:bool、tristate和string
– bool,有两种值,y和n
– tristate,有三种值,y、n和m
– string,用来存储本地字符串
depends on和select
########## arch/kconfig代码段 ##########config sys_generic_board bool depends on have_generic_board#depends on依赖:依赖项选中后,被依赖项才能被选中choice prompt architecture select default sandboxconfig arc bool arc architecture select have_private_libgcc select have_generic_board select sys_generic_board select support_of_control#select方向依赖,“arc”被选择后,四个select也会被选中choice/endchoice:定义一组可选择项,将多个类似配置项组合在一起,供用户单选或多选
########## arch/kconfig代码段 ##########choice prompt architecture select default sandboxconfig arc bool arc architecture ......config arm bool arm architecture ......config avr32 bool avr32 architecture ......config blackfin bool blackfin architecture ......config m68k bool m68000 architecture ......config microblaze bool microblaze architecture ......config mips bool mips architecture ......config nds32 bool nds32 architecture ......config nios2 bool nios ii architecture ......config openrisc bool openrisc architectureconfig ppc bool powerpc architecture ......config sandbox bool sandbox ......config sh bool superh architecture select have_private_libgccconfig sparc bool sparc architecture ......config x86 bool x86 architecture ......endchoice
menuconfig:和menu类似,但是menuconfig是带选项的菜单,其一般用法如下
menuconfig modules #定义一个可选的菜单modules bool 菜单if modules #只有选中了,if里面的内容才会显示......endif # modules##########顶层kconfig代码段##########menu general setup......menuconfig expert bool configure standard u-boot features (expert users) default y help ......if expert config sys_malloc_clear_on_init bool init with zeros the memory reserved for malloc (slow) default y help ......endifendmenu # general setup以上代码实现了一个带选项的菜单expert,只有被选中了,if/endif里的内容才会显示出来
comment:用于在图形化界面中显示一行注释
########## drviers/mtd/nand/kconfig代码段##########config nand_arasan bool configure arasan nand help this enables nand driver support for arasan nand flash controller. this uses the hardware ecc for read and write operations.comment generic nand options #标注了一行注释
3.添加自定义菜单
图形化配置工具的主要工作就是在.config文件里生成前缀为“config_”变量,这些变量一般都有值(y/m/n),在uboot源码里会根据这些变量来决定编译哪个文件。 下面介绍如何添加一个自已的自定义菜单,自定义菜单要求:
在主界面中添加名为“my test menu”菜单项,菜单内部有一个配置项
配置项为“my_testconfig”,处于菜单“my test menu”中
配置项的变量类型为bool,默认值为y
配置项菜单名字为“this is my test config”
配置项的帮助内容为“this is a empty config, just for testing!”
完成以上菜单要求,只需要在顶层kconfig文件末尾加上如下代码即可
menu my test menuconfig my_testconfig bool this is my test config default y help this is a empty config,just for test!endmenu #my test menu添加完成后,打开图形化配置界面,可见主菜单最后面出现一个名为“my test menu”的子菜单
进入子菜单如下图示,可见配置项菜单名字
按下help按键打开帮助文档,如下图示
打开.config文件,可以发现“config_my_testconfig=y”,如下图示,至此在主菜单中添加自定义菜单的功能就实现了

芯片滤波器设计实战指南
五款经典运放电路分享
商务部公布今年双11全网销售额 相比阿里多近600个亿
罗德与施瓦茨FPH手持式频谱分析仪提供44GHz测量频率
10 个增加 UNIX/Linux Shell 脚本趣味的工具
uboot图形化配置及其原理
整流电路的作用
首款支持最新蓝牙5.0功能的磁带录音机问世
3D视觉传感器——包装和物流案例分析(机器人拾取放)
学生党蓝牙耳机,千元内性价比蓝牙耳机推荐
华为AM08小天鹅蓝牙音箱怎么样 值不值得买
就目前的人类自动化发展水平 机器人在十年之内大量代替人类势在必行
如何玩转永磁无刷直流电机控制?
广西智能电网三年行动计划推进为农村智能电网建设迈出了实质性步伐
什么是扣肉(酷睿)
噪声驱动声音发生器电路原理图讲解
存储技术正在不断的演变与进化
深圳2023光明科学城智能传感器加速营正式启动
OPPO可公布多项自动驾驶技术专利
输入电抗器和输出电抗器的区别和联系