Uboot基础
(使用的uboot 版本:u-boot-2016.07-rc1
)
1. make 命令
详细命令可以使用 make help
或者文件 README 获取:
➜ u-boot-2016.05 make help
Cleaning targets:
clean - Remove most generated files but keep the config
mrproper - Remove all generated files + config + various backup files
distclean - mrproper + remove editor backup and patch files
Configuration targets:
config - Update current config utilising a line-oriented program
nconfig - Update current config utilising a ncurses menu based program
menuconfig - Update current config utilising a menu based program
xconfig - Update current config utilising a QT based front-end
gconfig - Update current config utilising a GTK based front-end
oldconfig - Update current config utilising a provided .config as base
localmodconfig - Update current config disabling modules not loaded
localyesconfig - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
defconfig - New config with default from ARCH supplied defconfig
savedefconfig - Save current config as ./defconfig (minimal config)
allnoconfig - New config where all options are answered with no
allyesconfig - New config where all options are accepted with yes
allmodconfig - New config selecting modules when possible
alldefconfig - New config with all symbols set to default
randconfig - New config with random answer to all options
listnewconfig - List new options
olddefconfig - Same as silentoldconfig but sets new symbols to their default value
Other generic targets:
all - Build all necessary images depending on configuration
* u-boot - Build the bare u-boot
dir/ - Build all files in dir and below
dir/file.[oisS] - Build specified target only
dir/file.lst - Build specified mixed source/assembly target only
(requires a recent binutils and recent build (System.map))
tags/ctags - Generate ctags file for editors
etags - Generate etags file for editors
cscope - Generate cscope index
ubootrelease - Output the release version string (use with make -s)
ubootversion - Output the version stored in Makefile (use with make -s)
Static analysers
checkstack - Generate a list of stack hogs
Documentation targets:
U-Boot bootloader internal documentation in different formats:
htmldocs - HTML
pdfdocs - PDF
psdocs - Postscript
xmldocs - XML DocBook
mandocs - man pages
installmandocs - install man pages generated by mandocs
cleandocs - clean all generated DocBook files
make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build
make V=2 [targets] 2 => give reason for rebuild of target
make O=dir [targets] Locate all output files in "dir", including .config
make C=1 [targets] Check all c source with $CHECK (sparse by default)
make C=2 [targets] Force check of all c source with $CHECK
make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections
make W=n [targets] Enable extra gcc checks, n=1,2,3 where
1: warnings which may be relevant and do not occur too often
2: warnings which occur quite often but may still be relevant
3: more obscure warnings, can most likely be ignored
Multiple levels can be combined with W=12 or W=123
Execute "make" or "make all" to build all targets marked with [*]
For further info see the ./README file
其实常用到的命令就 4 个: make xxx_defconfig
、 make clean
、 make mrproper
、 make -j N
, 注意:
- 如果不是编译 x86 的 uboot,还需要显式的指出 ARCH
和 CROSS_COMPILE
, 可以在执行 make 时附带 ARCH=xxx CROSS_COMPILE=yyy
编译,也可以设置环境变量(export ARCH=xxx
)。
- xxx_defconfig 和你的目标板有关,比如 beaglebone black 的配置文件是 am335x_boneblack_defconfig,具体的配置文件名称可以在目录 configs
(新版 uboot)或者文件 boards.cfg
(旧版 uboot) 下找到。
1.1. make menuconfig
新版的 u-boot 可以像 kernel 一样使用 menuconfig 配置参数(最新版的一定可以)
make menuconfig
效果图:
.config - U-Boot 2016.05 Configuration
──────────────────────────────────────────────────────────────────────────────
┌───────────────────── U-Boot 2016.05 Configuration ──────────────────────┐
│ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty │
│ submenus ----). Highlighted letters are hotkeys. Pressing <Y> │
│ includes, <N> excludes, <M> modularizes features. Press <Esc><Esc> to │
│ exit, <?> for Help, </> for Search. Legend: [*] built-in [ ] │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Architecture select (ARM architecture) ---> │ │
│ │ ARM architecture ---> │ │
│ │ General setup ---> │ │
│ │ Boot images ---> │ │
│ │ Boot timing ---> │ │
│ └────┴(+)─────────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────────────┤
│ <Select> < Exit > < Help > < Save > < Load > │
└─────────────────────────────────────────────────────────────────────────┘
注意,终端最小得是 80*19 大小。
1.2. sandbox 镜像
如果没有合适的运行环境(开发板)运行 uboot 镜像,可以编译 sandbox 版的 uboot , 这样就可以想运行程序一样运行 uboot 镜像 :
make sandbox_defconfig
make
./u-boot -d u-boot.dtb
(type 'reset' to exit U-Boot)
启动后和普通的 uboot 一样 :
➜ u-boot-2016.07-rc2 ./u-boot -d u-boot.dtb
U-Boot 2016.07-rc2 (Jul 02 2016 - 11:11:15 +0800)
DRAM: 128 MiB
MMC:
Using default environment
In: cros-ec-keyb
Out: vidconsole
Err: vidconsole
SCSI: Net: eth0: eth@10002000, eth1: eth@80000000, eth5: eth@90000000
IDE: Bus 0: not available
=>
注意编译 sandbox 版的 uboot 需要主机支持 sdl ,ubuntu 下 sudo apt-get install libsdl1.2-dev
即可。
1.2.1. test
执行脚本 ./test/py/test.py --bd sandbox --build -k ut_dm -v
可以测试 driver model 。
注意: 1. 测试程序依赖 python 2.7 和 pytest ,需要手动安装;
- 执行时要保证 uboot 没有被编译过(可以用
make mrproer
清理一下),否则会报错。
执行结果:
➜ u-boot-2016.07-rc2 ./test/py/test.py --bd sandbox --build -k ut_dm -v
+make O=/workspace/repos/src/u-boot-2016.07-rc2/build-sandbox -s sandbox_defconfig
+make O=/workspace/repos/src/u-boot-2016.07-rc2/build-sandbox -s -j8
In file included from tools/common/image-fit.c:1:
../tools/../common/image-fit.c:1691:39: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
^ ~~~~~~~~~~~~
../tools/../common/image-fit.c:1691:39: note: use '|' for a bitwise operation
os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
^~
|
1 warning generated.
===================== WARNING ======================
This board uses CONFIG_DM_I2C_COMPAT. Please remove
(possibly in a subsequent patch in your series)
before sending patches to the mailing list.
====================================================
===================================================================== test session starts =====================================================================
platform linux2 -- Python 2.7.11+, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 -- /usr/bin/python
cachedir: .cache
rootdir: /workspace/repos/src/u-boot-2016.07-rc2, inifile:
collected 206 items
test/py/tests/test_ut.py::test_ut_dm_init PASSED
test/py/tests/test_ut.py::test_ut[ut_dm_adc_bind] PASSED
test/py/tests/test_ut.py::test_ut[ut_dm_adc_multi_channel_conversion] PASSED
test/py/tests/test_ut.py::test_ut[ut_dm_adc_multi_channel_shot] PASSED
test/py/tests/test_ut.py::test_ut[ut_dm_adc_single_channel_conversion] PASSED
test/py/tests/test_ut.py::test_ut[ut_dm_adc_single_channel_shot] PASSED
...
(test 实现后续补充,可以借鉴到一般的嵌入式软件开发测试)
2. 添加自定义的开发板配置文件
按照 xxx_defconfig
这样的名称在 configs 目录下创建文件即可。
(in progress)