当前位置: 首页 > news >正文

uboot学习及内核更换_incomplete

官方文档
在前面

文章目录

  • uboot常见命令学习
    • 环境变量
    • 网络控制台
    • uboot标准启动
    • 其他
  • 升级uboot或内核
    • bin和uimg以及booti和bootm的区别
    • 制作uImage
    • 更换内核
    • 更换uboot
    • 后续计划

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 0Loading Kernel Image
FDT and ATAGS support not compiled inresetting ...

后面再看

更换内核

暂时搞了这么几个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

更换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
http://www.lryc.cn/news/269987.html

相关文章:

  • KVM 自动化脚本的使用及热/冷迁移
  • Unity中Shader裁剪空间推导(在Shader中使用)
  • ES的使用(Elasticsearch)
  • 车牌识别技术,如何用python识别车牌号
  • 爬虫工作量由小到大的思维转变---<第二十五章 Scrapy开始很快,越来越慢(追溯篇)>
  • Servlet入门
  • 【C#与Redis】--高级主题--Redis 哨兵
  • linux安装python
  • 【如何破坏单例模式(详解)】
  • 什么是 SPI,它有什么用?
  • FolkMQ 新的消息中间件,v1.0.25
  • 小程序入门-登录+首页
  • React快速入门之组件
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布
  • Hadoop入门学习笔记——六、连接到Hive
  • 【K8S 基本概念】Kurbernetes的架构和核心概念
  • WPS复选框里打对号,显示小太阳或粗黑圆圈的问题解决方法
  • 对“企业数据资源相关会计处理暂行规定“的个人理解
  • JavaScript:函数隐含对象arguments/剩余参数. . .c/解构赋值
  • MFC窗体背景颜色的设置、控件白色背景问题、控件文本显示重叠问题、被父窗体背景覆盖的问题
  • c++简易AI
  • java获取两个List集合之间的交集、差集、并集
  • 轻松实现iphone截图传电脑
  • 【网络安全】upload靶场pass1-10思路
  • 共享单车之数据存储
  • Flink(十一)【状态管理】
  • 【三维目标检测/自动驾驶】IA-BEV:基于结构先验和自增强学习的实例感知三维目标检测(AAAI 2024)
  • wefew
  • Springboot整合JSP-修订版本(Springboot3.1.6+IDEA2022版本)
  • Java核心知识点1-java和c++区别、隐式和显示类型转换