uboot学习及内核更换_incomplete

官方文档
在前面

uboot常见命令学习

环境变量

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,9353@10.0.0.2/12:34:56:78:9a:bc
netconsole=@/,@192.168.3.1/

然后查看linux控制台输出:

nc -u -l -p 6666

uboot标准启动

U-Boot Standard Boot
bootdev 可保存或访问发行版的设备
bootmeth 扫描bootdev发现bootflow的方法
bootflow 描述启动方法(发行版提供)

其他

bootmenu 生成一个选单

升级uboot或内核

bin和uimg以及booti和bootm的区别

参考文章《编译生成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。

制作uImage

使用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

保存内核文件

使用fatwrite把文件写到sd卡中去:

U-Boot> help fatwrite
fatwrite - write file into a dos filesystem

Usage:
fatwrite <interface> <dev[:part]> <addr> <filename> [<bytes> [<offset>]]
    - write file 'filename' from the address 'addr' in RAM
      to 'dev' on 'interface'

具体操作:

fatwrite mmc 0:1 ${kernel_addr_r} kernel-myconfig.img 1abf200
28045824 bytes written in 4530 ms (5.9 MiB/s)

更换uboot

暂时用了个笨办法,先用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
  • 17
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值