大概内容如下:
就是启动内核:
在u-boot目录下执行"tree . -d > 1.txt",可以得到目录的结构,精简如下:
├── arch
│ ├── arm // 1. 架构相关
│ │ ├── cpu
│ │ │ ├── armv7
│ │ │ │ ├── mx6
│ │ ├── dts
│ │ │ └── include
│ │ │ └── dt-bindings -> ../../../../include/dt-bindings
│ │ ├── include
│ │ │ ├── asm
│ │ │ │ ├── arch-imx
│ │ │ │ ├── arch-imx8
│ │ │ │ ├── arch-imx8m
│ │ │ │ ├── imx-common
│ │ │ └── debug
│ │ ├── lib
│ │ ├── mach-rockchip
│ │ │ ├── rk3036
│ │ │ ├── rk3288
│ │ │ └── rk3399
│ │ ├── lib
├── board // 单板相关
│ ├── freescale
│ │ ├── common
│ │ │ └── p_corenet
│ │ ├── corenet_ds
│ │ ├── mx6ul_14x14_ddr3_arm2
│ │ ├── mx6ul_14x14_evk
│ │ ├── mx6ul_14x14_lpddr2_arm2
│ │ ├── mx6ull_ddr3_arm2
│ │ ├── mx6ullevk
├── cmd // 通用的命令
│ ├── fastboot
│ └── mvebu
├── common // 通用的
│ ├── eeprom
│ ├── init
│ └── spl
├── configs
├── disk
├── drivers // 各类驱动
├── fs // 文件系统
│ ├── cbfs
│ ├── cramfs
│ ├── ext4
│ ├── fat
│ ├── jffs2
│ ├── reiserfs
│ ├── sandbox
│ ├── ubifs
│ ├── yaffs2
│ └── zfs
├── include
├── lib // 库
├── net // 网络协议
文档:本Git仓库01_all_series_quickstart\04_嵌入式Linux应用开发基础知识\doc_pic\04.2018_Makefile
打印Makefile的规则和变量:make -p
可以把make命令规则和变量存入文件:make -p > 1.txt
然后执行vi 1.txt
,使用vi命令删除注释::g/^#/d
IMX6ULL: make mx6ull_14x14_evk_defconfig
STM32MP157: make stm32mp15_trusted_defconfig
执行过程:
分析过程:
mx6ull_14x14_evk_defconfig: scripts/kconfig/conf
$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
就是:
UBOOTVERSION=2017.03 scripts/kconfig/conf --defconfig=arch/../configs/mx6ull_14x14_evk_defconfig Kconfig
总体分析:scripts/kconfig/conf.c
更详细的配置过程:make mx6ull_14x14_evk_defconfig V=1
defconfig_file = "arch/../configs/mx6ull_14x14_evk_defconfig";
name = "Kconfig"
conf_parse(name); // 解析uboot根目录下的Kconfig文件
conf_read(defconfig_file); // 读配置文件
conf_set_all_new_symbols(def_default); // 设置new_symbols为默认值
conf_write(NULL); // 写到.config
深入分析:scripts/kconfig/conf.c
参考文档:
任一个Linux内核的Documentation\kbuild\kconfig-language.rst
https://www.rt-thread.org/document/site/programming-manual/kconfig/kconfig/
对于各类内核,只要支持menuconfig配置界面,都是使用Kconfig。
在配置界面中,可以选择、设置选项,这些设置会保存在.config文件里。
编译脚本会包含.config,根据里面的值决定编译哪些文件、怎么编译文件。
.config文件也会被转换为头文件,C程序可以从头文件中获得配置信息。
问题:
在配置界面中操作的结果保存在.config文件中,示例如下:
#
# Automatically generated file; DO NOT EDIT.
# U-Boot Configuration
#
CONFIG_CREATE_ARCH_SYMLINK=y
# CONFIG_ARC is not set
CONFIG_ARM=y
# CONFIG_AVR32 is not set
# CONFIG_BLACKFIN is not set
# CONFIG_M68K is not set
# CONFIG_MICROBLAZE is not set
# CONFIG_MIPS is not set
# CONFIG_NDS32 is not set
# CONFIG_NIOS2 is not set
# CONFIG_OPENRISC is not set
# CONFIG_PPC is not set
# CONFIG_SANDBOX is not set
# CONFIG_SH is not set
# CONFIG_SPARC is not set
# CONFIG_X86 is not set
# CONFIG_XTENSA is not set
CONFIG_SYS_ARCH="arm"
CONFIG_SYS_CPU="armv7"
CONFIG_SYS_SOC="mx6"
CONFIG_SYS_VENDOR="freescale"
CONFIG_SYS_BOARD="mx6ullevk"
CONFIG_SYS_CONFIG_NAME="mx6ullevk"
#
# ARM architecture
#
CONFIG_HAS_VBAR=y
CONFIG_HAS_THUMB2=y
CONFIG_CPU_V7=y
CONFIG_SYS_ARM_ARCH=7
CONFIG_SYS_CACHE_SHIFT_6=y
CONFIG_SYS_CACHELINE_SIZE=64
编译脚本会包含.config文件,它会根据里面的变量比如CONFIG_CPU_V7
选择u-boot特性。
在Kconfig文件中,假设配置项的名字是XXX,在.config文件中:
CONFIG_XXX
CONFIG_=ABC
,则对应的变量名为ABC_XXX
在menuconfig
界面,可以看到这个配置项:
在配置界面,使用方向箭头游走到Display information about the CPU during start up
后,可以:
输入Y,选择配置项,在.config中对应CONFIG_DISPLAY_CPUINFO=y
输入N,不选择配置项,在.config中对应# CONFIG_DISPLAY_CPUINFO is not set
上图中的配置项怎么实现的?
在common/Kconfig文件中,它对应下列代码:
上面是一个精简的例子,完整的例子可以从Linux中获得,如下:
config SGI_SNSC
bool "SGI Altix system controller communication support"
depends on (IA64_SGI_SN2 || IA64_GENERIC)
default y
help
If you have an SGI Altix and you want to enable system
controller communication from user space (you want this!),
say Y. Otherwise, say N.
解释如下:
config option
,这是Kconfig的基本entry;其他entry是用来管理config的。XXX
选项就会被选中。menuconfig
界面输入H键时,就会提示帮助信息。示例代码:rt-smart/kernel/src/Kconfig
,代码如下:
menu "Boot media"
config NOR_BOOT
bool "Support for booting from NOR flash"
depends on NOR
help
Enabling this will make a U-Boot binary that is capable of being
booted via NOR. In this case we will enable certain pinmux early
as the ROM only partially sets up pinmux. We also default to using
NOR for environment.
config NAND_BOOT
bool "Support for booting from NAND flash"
default n
help
Enabling this will make a U-Boot binary that is capable of being
booted via NAND flash. This is not a must, some SoCs need this,
some not.
config ONENAND_BOOT
bool "Support for booting from ONENAND"
default n
help
Enabling this will make a U-Boot binary that is capable of being
booted via ONENAND. This is not a must, some SoCs need this,
some not.
config QSPI_BOOT
bool "Support for booting from QSPI flash"
default n
help
Enabling this will make a U-Boot binary that is capable of being
booted via QSPI flash. This is not a must, some SoCs need this,
some not.
config SATA_BOOT
bool "Support for booting from SATA"
default n
help
Enabling this will make a U-Boot binary that is capable of being
booted via SATA. This is not a must, some SoCs need this,
some not.
config SD_BOOT
bool "Support for booting from SD/EMMC"
default n
help
Enabling this will make a U-Boot binary that is capable of being
booted via SD/EMMC. This is not a must, some SoCs need this,
some not.
config SPI_BOOT
bool "Support for booting from SPI flash"
default n
help
Enabling this will make a U-Boot binary that is capable of being
booted via SPI flash. This is not a must, some SoCs need this,
some not.
endmenu
界面如下:
解释如下:
示例代码:rt-smart/kernel/src/Kconfig
,代码如下:
config DEBUG_UART
bool "Enable an early debug UART for debugging"
help
The debug UART is intended for use very early in U-Boot to debug
problems when an ICE or other debug mechanism is not available.
choice
prompt "Select which UART will provide the debug UART"
depends on DEBUG_UART
default DEBUG_UART_NS16550
config DEBUG_UART_ALTERA_JTAGUART
bool "Altera JTAG UART"
help
Select this to enable a debug UART using the altera_jtag_uart driver.
You will need to provide parameters to make this work. The driver will
be available until the real driver model serial is running.
config DEBUG_UART_ALTERA_UART
bool "Altera UART"
help
Select this to enable a debug UART using the altera_uart driver.
You will need to provide parameters to make this work. The driver will
be available until the real driver model serial is running.
endchoice
界面如下:
在上述界面中,设置了DEBUG_UART
,才有后续的"选择菜单"。
解释如下:
menuconfig XXX
和config XXX
类似,
唯一不同的是该选项除了能设置y/m/n外,还可以实现菜单效果(能回车进入该项内部)。
示例代码:Kconfig
menuconfig EXPERT
bool "Configure standard U-Boot features (expert users)"
default y
help
This option allows certain base U-Boot options and settings
to be disabled or tweaked. This is for specialized
environments which can tolerate a "non-standard" U-Boot.
Use this only if you really know what you are doing.
if EXPERT
config SYS_MALLOC_CLEAR_ON_INIT
bool "Init with zeros the memory reserved for malloc (slow)"
default y
help
This setting is enabled by default. The reserved malloc
memory is initialized with zeros, so first malloc calls
will return the pointer to the zeroed memory. But this
slows the boot time.
It is recommended to disable it, when CONFIG_SYS_MALLOC_LEN
value, has more than few MiB, e.g. when uses bzip2 or bmp logo.
Then the boot time can be significantly reduced.
Warning:
When disabling this, please check if malloc calls, maybe
should be replaced by calloc - if one expects zeroed memory.
config TOOLS_DEBUG
bool "Enable debug information for tools"
help
Enable generation of debug information for tools such as mkimage.
This can be used for debugging purposes. With debug information
it is possible to set breakpoints on particular lines, single-step
debug through the source code, etc.
endif # EXPERT
界面如下:
menuconfig常用格式有2种:
menuconfig M
if M
config C1
config C2
endif
或:
menuconfig M
config C1
depends on M
config C2
depends on M
第1项menuconfig M
跟config M
语法是一样的,
不同之处在于menuocnfig M
后面可以跟着好几个依赖于M的config C1
、config C2
等子配置项。
在上面的menuconfig中就有if/endif
的使用,它的语法如下:
"if" <expr>
<if block>
"endif"
示例如下,只有定义了的EXPERT项,SYS_MALLOC_CLEAR_ON_INIT
等才会显示出来:
if EXPERT
config SYS_MALLOC_CLEAR_ON_INIT
bool "Init with zeros the memory reserved for malloc (slow)"
default y
help
This setting is enabled by default. The reserved malloc
memory is initialized with zeros, so first malloc calls
will return the pointer to the zeroed memory. But this
slows the boot time.
It is recommended to disable it, when CONFIG_SYS_MALLOC_LEN
value, has more than few MiB, e.g. when uses bzip2 or bmp logo.
Then the boot time can be significantly reduced.
Warning:
When disabling this, please check if malloc calls, maybe
should be replaced by calloc - if one expects zeroed memory.
config TOOLS_DEBUG
bool "Enable debug information for tools"
help
Enable generation of debug information for tools such as mkimage.
This can be used for debugging purposes. With debug information
it is possible to set breakpoints on particular lines, single-step
debug through the source code, etc.
endif # EXPERT
source 语句用于读取另一个文件中的 Kconfig 文件,
比如Kconfig
中就包含了其他Kconfig:
source "arch/Kconfig"
comment 语句出现在界面的第一行,用于定义一些提示信息,如cmd/Kconfig
:
comment "Commands"
config 100ASK
bool "test for 100ask"
default y
help
just for Kconfig test
menu "100ASK menu"
config IMX6ULL_TEST
tristate "menu test item 1 IMX6ULL"
help
just for test menu.
config STM32MP157_TEST
tristate "menu test item 2 IMX6ULLh"
help
just for test menu.
endmenu
config CHOICE_ON_100ASK
bool "Enable choice for 100ask"
help
Enable choice for 100ask
choice
prompt "choice test for 100ask"
depends on CHOICE_ON_100ASK
config CHOICE_ITEM1
bool "CHOICE_ITEM1"
help
CHOICE_ITEM1.
config CHOICE_ITEM2
bool "CHOICE_ITEM2"
help
CHOICE_ITEM2.
endchoice
menuconfig 100ASK_MENUCFG
bool "test for menuconfig of 100ask"
if 100ASK_MENUCFG
config IMX6ULL_TEST_MENUCFG
tristate "menuconfig test item 1 IMX6ULL"
help
just for test menuconfig.
config STM32MP157_MENUCFG
tristate "menuconfig test item 2 IMX6ULLh"
help
just for test menuconfig.
endif
menu "test menu"
config TEST_A
bool "TEST A"
default y
config TEST_B
bool "TEST B"
default y
endmenu
choice
prompt "test choise"
default TEST_C
config TEST_C
bool "TEST C"
default y
config TEST_D
bool "TEST D"
default y
endchoice
menuconfig TEST_MENUCONFIG
bool "test menuconfig"
default n
if TEST_MENUCONFIG
config TEST_E
bool "TEST E"
default y
config TEST_F
bool "TEST F"
default y
endif