mkimage工具将zImage转换为uImage

11 篇文章 0 订阅
5 篇文章 1 订阅

正常引导的内核文件
[root@wtstb ~]# mount /dev/sda1 /mnt/
[root@wtstb ~]# file /mnt/hi_kernel.bin
/mnt/hi_kernel.bin: u-boot legacy uImage, Linux-3.18.24_s40, Linux/ARM, OS Kernel Image (Not compressed), 7243096 bytes, Sun Mar 15 16:37:31 2020, Load Address: 0x02000000, Entry Point: 0x02000000, Header CRC: 0xC1CAA0CA, Data CRC: 0xB6071F47
ARCH生成的内核文件
[root@wtstb ~]# file /boot/zImage
/boot/zImage: ARM OpenFirmware FORTH Dictionary, Text length: -509607936 bytes, Data length: -509607936 bytes, Text Relocation Table length: -369098747 bytes, Data Relocation Table length: 24061976 bytes, Entry Point: 0x00000000, BSS length: 7406192 bytes

参考语法
mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file…] image
man mkimage 进一步获取帮助,逐一填写命令
获取正常文件信息
-l [uimage file name]
mkimage lists the information contained in the header of an existing U-Boot image.
[root@wtstb ~]# mkimage /mnt/hi_kernel.bin -l
Image Name: Linux-3.18.24_s40
Created: Mon Mar 16 00:37:31 2020
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 7243096 Bytes = 7073.34 KiB = 6.91 MiB
Load Address: 02000000
Entry Point: 02000000

-A [architecture]
Set architecture. Pass -h as the architecture to see the list of supported architectures.
[root@wtstb ~]# mkimage -A h

Invalid architecture, supported are:
alpha Alpha
arc ARC
arm ARM
arm64 AArch64
avr32 AVR32
blackfin Blackfin
ia64 IA64
invalid Invalid ARCH
m68k M68K
microblaze MicroBlaze
mips MIPS
mips64 MIPS 64 Bit
nds32 NDS32
nios2 NIOS II
or1k OpenRISC 1000
powerpc PowerPC
riscv RISC-V
s390 IBM S390
sandbox Sandbox
sh SuperH
sparc SPARC
sparc64 SPARC 64 Bit
x86 Intel x86
x86_64 AMD x86_64
xtensa Xtensa

-O [os]
Set operating system. bootm command of u-boot changes boot method by os type. Pass -h as the OS to see the list of supported OS.

[root@wtstb ~]# mkimage -O -h

Invalid operating system, supported are:
4_4bsd 4_4BSD
arm-trusted-firmware ARM Trusted Firmware
dell Dell
efi EFI Firmware
esix Esix
freebsd FreeBSD
integrity INTEGRITY
invalid Invalid OS
irix Irix
linux Linux
lynxos LynxOS
ncr NCR
netbsd NetBSD
openbsd OpenBSD
openrtos OpenRTOS
opensbi RISC-V OpenSBI
ose Enea OSE
plan9 Plan 9
psos pSOS
qnx QNX
rtems RTEMS
sco SCO
solaris Solaris
svr4 SVR4
tee Trusted Execution Environment
u-boot U-Boot
vxworks VxWorks

-T [image type]
Set image type. Pass -h as the image to see the list of supported image type.
[root@wtstb ~]# mkimage -T -h

Invalid image type, supported are:
aisimage Davinci AIS image
atmelimage ATMEL ROM-Boot Image
copro Coprocessor Image
filesystem Filesystem Image
firmware Firmware
firmware_ivt Firmware with HABv4 IVT
flat_dt Flat Device Tree
fpga FPGA Image
gpimage TI Keystone SPL Image
imx8image NXP i.MX8 Boot Image
imx8mimage NXP i.MX8M Boot Image
imximage Freescale i.MX Boot Image
invalid Invalid Image
kernel Kernel Image
kernel_noload Kernel Image (no loading done)
kwbimage Kirkwood Boot Image
lpc32xximage LPC32XX Boot Image
mtk_image MediaTek BootROM loadable Image
multi Multi-File Image
mxsimage Freescale MXS Boot Image
omapimage TI OMAP SPL With GP CH
pblimage Freescale PBL Boot Image
pmmc TI Power Management Micro-Controller Firmware
ramdisk RAMDisk Image
rkimage Rockchip Boot Image
rksd Rockchip SD Boot Image
rkspi Rockchip SPI Boot Image
script Script
socfpgaimage Altera SoCFPGA CV/AV preloader
socfpgaimage_v1 Altera SoCFPGA A10 preloader
standalone Standalone Program
stm32image STMicroelectronics STM32 Image
tee Trusted Execution Environment Image
ublimage Davinci UBL image
vybridimage Vybrid Boot Image
x86_setup x86 setup.bin
zynqimage Xilinx Zynq Boot Image
zynqmpbif Xilinx ZynqMP Boot Image (bif)
zynqmpimage Xilinx ZynqMP Boot Image

-C [compression type]
Set compression type. Pass -h as the compression to see the list of supported compression type.
[root@wtstb ~]# mkimage -C -h

Invalid compression, supported are:
bzip2 bzip2 compressed
gzip gzip compressed
lz4 lz4 compressed
lzma lzma compressed
lzo lzo compressed
none uncompressed
zstd zstd compressed
···· 弯路:安装一个工具readelf来读取文件信息
[root@wtstb ~]# pacman -S elfutils 这个不对,但binutils会依赖此包
参考案例:UBUNTU readelf的安装 https://blog.csdn.net/weixin_34221112/article/details/85993028
[root@wtstb ~]# pacman -S binutils
验证一下 [root@wtstb ~]# pacman -Ql binutils |grep “/bin/”
[root@wtstb ~]# readelf -h zImage
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
····
先暂定为none吧

-a [load address]
Set load address with a hex number.
对应mkimage /mnt/hi_kernel.bin -l
Load Address: 02000000

-e [entry point]
Set entry point with a hex number.
对应mkimage /mnt/hi_kernel.bin -l
Entry Point: 02000000

-n [image name]
Set image name to ‘image name’.
随便取一个名字,比如archLinuxArm

-d [image data file]
Use image data from ‘image data file’.
需要添加消息头的内核文件,zImage

拷贝一份来测试
[root@wtstb ~]# cp /boot/zImage .
[root@wtstb ~]# mkimage -A arm -O linux -T kernel -C none -a 02000000 -e 02000000 -n archLinuxArm -d zImage uImage
Image Name: archLinuxArm
Created: Sat Mar 20 14:45:13 2021
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 7406192 Bytes = 7232.61 KiB = 7.06 MiB
Load Address: 02000000
Entry Point: 02000000
替换原有正常的kernel测试
先备份
[root@wtstb ~]# mv /mnt/hi_kernel.bin /mnt/hi_kernel.bin.bakok
替换
[root@wtstb ~]# mv ./uImage /mnt/hi_kernel.bin
重启
[root@wtstb ~]# reboot

果然,无法正常启动。
检查之前收集的ubuntu16.img和debian.img镜像,通过mount挂载查看,boot目录下都没有dts文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值