3
为了在嵌入式设备上启动Linux内核,我必须用特殊的标头标记内核。用于标记内核的程序仅由32位二进制制造商提供。这非常烦人,因为我必须在我的64位系统上安装数百兆字节的库,才能标记少量字节的内核。这是内核是如何标记:用C程序编写头文件?
$./mkimage -f kernel.cfg -d zImage_without_header zImage
kernel.cfg:
##########################################################
#ENCINFO.CFG
#
# information and command for encode the Linux zImage
##########################################################
# Magic number for the ImageHeader, use this to seach start of the Image Header
#
MAGIC_NUMBER 0x27051956
#operation system type
OS_TYPE linux
#cpu architecture type
CPU_ARCH arm
#image type
IMAGE_TYPE kernel
#compress type
COMPRESS_TYPE gzip
#
DATALOAD_ADDRESS 0x00008000
#
ENTRY_ADDRESS 0x00008000
#image name string
IMAGE_NAME kernel.img
#model name string
MODEL_NAME DNS-313
# version string
VERSION 1.00b18
# mac address string
MAC_ADDRESS FF-FF-FF-FF-FF-FF
#the beginning offset of writing header
START_OFFSET 0x00
#the end offset of writing header
END_OFFSET 0xFF
#whether overwrite
OVERWRITE n
的mkimage生成的二进制是从可从例如mkimage生成不同Debian存储库,那个不会为我的设备工作。我试图创建一个1MB文件和标签它显示标题:从最后的命令
$dd if=/dev/zero bs=1k count=1024 of=zImage_without_header
$./mkimage -f kernel.cfg -d zImage_without_header zImage
输出:
Magic Number: 27051956
Image Name: kernel.img
Created: Wed May 2 17:40:43 2012
Image Type: ARM Linux Kernel Image (gzip compressed)
Data Size: 1048576 Bytes = 1024.00 kB = 1.00 MB
Load Address: 0x00008000
Entry Point: 0x00008000
Model Name: DNS-313
Version : 1.00b18
Mac Address: ff:ff:ff:ff:ff:ff
从最后一个命令输出
$hexdump -C zImage
:
00000000 27 05 19 56 [2c 83 53 d5] 4f a1 [55 7b 00 10 00 00] |'..V,.S.O.U{....|
00000010 00 00 80 00 00 00 80 00 [a7 38 ea 1c] 05 02 02 01 |.........8......|
00000020 6b 65 72 6e 65 6c 2e 69 6d 67 00 00 00 00 00 00 |kernel.img......|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000040 44 4e 53 2d 33 31 33 00 00 00 00 00 00 00 00 00 |DNS-313.........|
00000050 31 2e 30 30 62 31 38 00 00 00 00 00 00 00 00 00 |1.00b18.........|
00000060 ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00100060
内核应该始终标记为像上面的标题,因为我不需要改变任何东西。括号内的数值似乎会在文件大小变化时发生变化,但我不知道如何。
我认为可以用一个小型C程序完成同样的事情,但是我不确定从哪里开始以及如何实现?
欢迎任何建议或想法。
请求来自制造商的mkimage的来源。虽然我认为他们可以在技术上拒绝,但这将是一个非常糟糕的主意。 – Joshua
似乎很可能某些或所有变化的值是校验和。在你自己创建头之前,你需要知道它们是什么。 –
'4f a1 55 7b'是一个时间戳(5月2日@ 15:40:43 GMT)。其中两个“未知数”是校验和。如果你的引导程序是u-boot,应该是这些字段:http://www.linux-m32r.org/public/codefestweek2008/takata/qemu-0.9.1/html/d1/d14/structuboot__image__header__t.html – indiv