官方文档
在前面
Environment Variables环境变量
autostart 如果值为yes,则会在以下命令后自动执行bootm加载镜像
bootelf - Boot from an ELF image in memory
bootp - boot image via network using BOOTP/TFTP protocol
dhcp - boot image via network using DHCP/TFTP protocol
diskboot - boot from ide device
nboot - boot from NAND device
nfs - boot image via network using NFS protocol
rarpboot - boot image via network using RARP/TFTP protocol
scsiboot - boot from SCSI device
tftpboot - boot image via network using TFTP protocol
usbboot - boot from USB device
bootcmd 用户不进bootshell自动执行的命令
bootargs 传递给操作系统或镜像的参数
bootfile tftp时的镜像名
ipaddr tftpboot用到的ip地址
serverip tftpboot用到的tftp服务器地址
Network console
uboot启用network console
需要设置CONFIG_NETCONSOLE=y以启用特性。
使用方法:
使用ncip设置目的地址和端口号(默认6666),比如你的服务器ip是192.168.1.1:
=> setenv nc 'setenv stdout nc;setenv stdin nc'
=> setenv ncip 192.168.1.1
=> saveenv
=> run nc
在主机侧,使用脚本来访问控制台:
tools/netconsole <ip> [port]
主机侧也可以使用主机名
参考《【调试】netconsole的使用》
linux启用network console
如果想开启这个功能,需要内核编译支持,我这里的选项默认是:
CONFIG_NETCONSOLE=m
CONFIG_NETCONSOLE_DYNAMIC=n
如果将netconsole编译进内核自动加载,还需要在内核启动参数中传递进去。格式如下:
netconsole=[src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
例子:
netconsole=4444@10.0.0.1/eth1,[email protected]/12:34:56:78:9a:bc
netconsole=@/,@192.168.3.1/
然后查看linux控制台输出:
nc -u -l -p 6666
U-Boot Standard Boot
bootdev 可保存或访问发行版的设备
bootmeth 扫描bootdev发现bootflow的方法
bootflow 描述启动方法(发行版提供)
bootmenu 生成一个选单
参考文章《编译生成uImage过程——mips平台》
uboot.bin是U-boot bootloader的二进制文件。
uImage是一个小内核映像,带有Uboot的修改头,使U-boot能够加载此内核映像uboot.bin是U-boot bootloader的二进制文件。
uImage是一个小内核映像,带有Uboot的修改头,使U-boot能够加载此内核映像
booti和bootm命令的区别
bootz是启动zImage,而bootm是启动uImage,其中booti专门用来启动ARM64的kernel image。
使用uboot的tools目录下的mkimage命令可以创建用于uboot的镜像,即uImage。
先加下这个命令:
$ sudo update-alternatives --install /usr/bin/mkimage mkimage /home/wsl/project/raspberry_pi/u-boot/tools/mkimage 10
常见参数
Usage: ./mkimage [-T type] -l image
-l ==> list image header information
-T ==> parse image file as 'type'
-q ==> quiet
./mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-R ==> set second image name to 'name'
-d ==> use image data from 'datafile'
-x ==> set XIP (execute in place)
-s ==> create an image with no data
-v ==> verbose
./mkimage [-D dtc_options] [-f fit-image.its|-f auto|-f auto-conf|-F] [-b <dtb> [-b <dtb>]] [-E] [-B size] [-i <ramdisk.cpio.gz>] fit-image
<dtb> file is used with -f auto, it may occur multiple times.
-D => set all options for device tree compiler
-f => input filename for FIT source
-i => input filename for ramdisk file
-E => place data outside of the FIT structure
-B => align size in hex for FIT structure and header
-b => append the device tree binary to the FIT
-t => update the timestamp in the FIT
Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]
-k => set directory containing private keys
-K => write public keys to this .dtb file
-g => set key name hint
-G => use this signing key (in lieu of -k)
-c => add comment in signature node
-F => re-sign existing FIT image
-p => place external data at a static position
-r => mark keys used as 'required' in dtb
-N => openssl engine to use for signing
-o => algorithm to use for signing
./mkimage -V ==> print version information and exit
Use '-T list' to see a list of available image types
Long options are available; read the man page for details
参考《uboot-tool工具命令mkimage详解uboot-tool工具命令mkimage详解》,一个典型的生成命令如下:
mkimage -A arm64 -O linux -T kernel -a 0x00080000 -e 0x00080040 -C none -n kernel-myconfig -d arch/arm64/boot/Image kernel.uImage
比较关键的是-e参数,-e 指定映象运行的入口点地址,这个地址就是-a参数指定的值加上0x40(因为前面有个mkimage添加的0x40个字节的头),关于参数,这里还有一份更全的文档可以参考。
使用上述命令后,内核无法启动,报错:
Working FDT set to 0
Loading Kernel Image
FDT and ATAGS support not compiled in
resetting ...
后面再看
暂时搞了这么几个env,可以用来运行
booti_kernel=booti ${kernel_addr_r} - ${fdt_addr}
dhcp_get_kernel=dhcp ${kernel_addr_r} kernel-myconfig.img
dhcpboot=run dhcp_get_kernel;run booti_kernel
fat_get_kernel=fatload mmc 0:1 ${kernel_addr_r} kernel-myconfig.img
fatboot=run fat_get_kernel;run booti_kernel
暂时用了个笨办法,先用dhcp把u-boot.bin取过来,然后用fatwrite写到boot分区,然后reset重新启动
看是否能较方便的一次性更换内核,设备树,模块等。
一个自定义的uboot环境变量
HWID=TS-SG5036FX:02:04:01:0E:101:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
ID=000000000000000000
appauto=1
baudrate=115200
boardmodel=RTL9311_6x8214QF_1x8218E_4XGE_24GF_8GE_4XF
boot_flag=0
bootargs=mem=512M console=ttyS0,115200 rd_start=0x82000000 rd_size=0xd00000 root=/dev/ram0 rw init=/linuxrc
bootcmd=boota
bootdelay=1
bootflag=0
da=tftp 0x81000000 boot.bin.img; flwrite
dh_keyboard=0
dr=tftp 0x81000000 krootfs.bin.img; flwrite
drb=tftp 0x81000000 krootfs_backup.bin.img; flwrite
ethact=rtl9310#0
ethaddr=20:23:04:19:13:38
fileaddr=81000000
filesize=D74F38
gatewayip=172.14.48.1
ipaddr=172.14.49.120
ledModeInitSkip=0
netmask=255.255.255.0
serverip=10.33.7.176
stderr=serial
stdin=serial
stdout=serial
tk=tftp 0x81000000 krootfs.bin.img; bootm 0x81000000
up=tftp 0x81000000 update.img; flwrite