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-essential
sudo apt-get install libncurses5-dev

menuconfig重点会用到两个文件:“.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.114
saveenv

设置好后,使用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 menuconfig

Makefile.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 Configuration"

source命令调用其他目录下的Kconfig文件

##########顶层Kconfig代码段##########
source "arch/Kconfig"
......
source "common/Kconfig"
source "cmd/Kconfig"
source "dts/Kconfig"
source "net/Kconfig"
source "drivers/Kconfig"
source "fs/Kconfig"
source "lib/Kconfig"
source "test/Kconfig"

##以上子目录下的Kconfig文件在主菜单中生成各自的菜单项

menu/endmenu条目:menu用于生成菜单,endmenu菜单结束标志

##########顶层Kconfig代码段##########
menu "General setup"

config 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 setup

menu "Boot images"

config SUPPORT_SPL
    bool
......
......
endmenu		# Boot images

以上代码中有两个menu/endmenu代码块,这两个代码块就是两个子菜单

内核

config条目:是菜单里的具体配置项

##########顶层Kconfig代码段##########
menu "General setup"

config 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
    ......
endif
endmenu		# 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 SANDBOX

config 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 SANDBOX

config 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 architecture"

config PPC
    bool "PowerPC architecture"
    ......
config SANDBOX
    bool "Sandbox"
    ......
config SH
    bool "SuperH architecture"
    select HAVE_PRIVATE_LIBGCC

config 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
    ......
endif
endmenu		# 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 menu"

config 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”,如下图示,至此在主菜单中添加自定义菜单的功能就实现了

内核

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分