测试可以用dtb设备树工具编译还原uImage镜像为源码。 U-Boot 的 FIT (Flattened Image Tree) 镜像编译过程
FIT uImage的编译过程很简单,根据实际情况,编写image source file之后(假设名称为kernel_fdt.its),在命令行使用mkimage工具编译即可:
$ mkimage -f kernel_fdt.its kernel_fdt.itb
这里提到的源文件格式为:
kernel@2 {undefined
description = "2.6.23-denx";
data = /incbin/("./2.6.23-denx.bin.gz");
type = "kernel";
arch = "ppc";
os = "linux";
compression = "gzip";
load = <00000000>;
entry = <00000000>;
hash@1 {undefined
algo = "sha1";
};
};
其中的data变量 可以为文件,也可以直接写16进制,或2进制字符。
以下是什么文件,用途是什么:/dts-v1/; / { timestamp = <0x5fc8824d>; description = "ecube image file"; #address-cells = <0x01>; #size-cells = <0x00>; images { kernel@1 { description = "Linux kernel for ecbue"; data=[]; type = "kernel"; arch = "arm64"; os = "linux"; compression = "lz4"; load = <0x280000>; entry = <0x280000>; hash@1 { value = <0x45e1af7d 0x2c3312a7 0x8c335b1a 0x1a36d3bf 0xf86af70e 0x292dd302 0x7a74d41 0xbde26786>; algo = "sha256"; }; }; fdt@1 { description = "FTD for ecube"; data = <0xd00dfeed 0x15d3>; type = "flat_dt"; arch = "arm64"; compression = "none"; hash@1 { value = <0x723ede22 0x48170a60 0x8c2f7a66 0xc775a078 0xe1e18348 0xa3fac2a5 0x1a918ff2 0xa6787aac>; algo = "sha256"; }; }; ramdisk@1 { description = "Ramdisk for ecube"; data = []; type = "ramdisk"; arch = "arm64"; os = "linux"; load = <0x00>; entry = <0x00>; compression = "gzip"; hash@1 { value = <0xc7b0f970 0x88025076 0xcd532773 0x43af5e00 0x91c16a3 0xc2c7a515 0x2576afdf 0x5d6e8cdd>; algo = "sha256"; }; }; }; configurations { default = "conf@1"; conf@1 { description = "Boot kernel with FDT blob"; kernel = "kernel@1"; fdt = "fdt@1"; ramdisk = "ramdisk@1"; signature { hashed-strings = <0x00 0x9a>; hashed-nodes = "/\0/configurations/conf@1\0/images/kernel@1\0/images/kernel@1/hash@1\0/images/ramdisk@1\0/images/ramdisk@1/hash@1\0/images/fdt@1\0/images/fdt@1/hash@1"; timestamp = <0x5fc8824d>; comment = "ecube sign"; signer-version = "2017.09-gabfd553-dirty"; signer-name = "mkimage"; value = <0xbfebdd06 0x22b0a952 0x2dfc0f03 0xd86438c7 0x691aaaf2 0x48643c36 0x3a9ac57d 0x154dfc32 0xceac0b75 0x57a5974a 0x68c8ddd2 0xd1395d66 0xcb9e28ff 0x414885f9 0x17f3e727 0xe05c8ce6 0xf1f67368 0x55e99ec8 0xea2dd642 0xc8358c37 0xc10f8d4c 0xaf9e46dc 0xd1d07934 0xde76806c 0x1116b68f 0x4c40f198 0xecd789eb 0x6366e8ac 0xacd0d1c9 0x10eee8f 0x3f1436f5 0x1586fe0f 0xc0181b1f 0xdd261067 0xe07aee51 0x112ab02e 0xa0ca0206 0x83270ad3 0xe5488eaa 0x304fa9ee 0xec424ffa 0x266d0cdc 0xbebb9107 0x771edd1 0x1c2a7532 0x982f781c 0xc2331798 0xfa5487f3 0x4ea4bede 0x18a02153 0xb33d8758 0x32c33afc 0xc7087041 0x3981674e 0x709d3424 0x60ffd4ae 0xc349e970 0x34826d78 0x6c5b64f6 0x714192df 0x9dfba85c 0x7d65b81d 0x7500d420 0x427f127c>; algo = "sha256,rsa2048"; key-name-hint = "dev"; sign-images = "kernel\0ramdisk\0fdt"; }; }; }; };
Image文件生成后,也可以使用mkimage命令查看它的信息:
$ mkimage -l kernel.itb
最后,我们可以使用dfu工具将生成的.idb文件,下载的memory的某个地址(没有特殊要求,例如0x100000),然后使用bootm命令即可启动,步骤包括:
1)使用iminfo命令,查看memory中存在的images和configurations。
2)使用bootm命令,执行默认配置,或者指定配置。
uImage格式镜像的引导命令为:
使用默认配置启动的话,可以直接使用bootm:
bootm 0x100000
选择其它配置的话,可以指定配置名:
bootm 0x100000#config@2
mkimage 是 U-Boot 提供的一个工具,用于制作可启动映像文件,以下是常见的安装方法:基于 Debian 的系统(如 Ubuntu)
-
使用命令安装 :直接在终端输入
sudo apt-get install u-boot-tools -y,系统会自动下载并安装mkimage工具及相关依赖。 -
通过编译 U-Boot 源码获取 :下载 U-Boot 源码并解压,进入解压后的目录,执行
make命令进行编译,编译成功后,tools目录下会生成mkimage工具。
基于 RPM 的系统(如 CentOS、Fedora)
-
CentOS :执行
sudo yum install uboot-tools命令来安装。 -
Fedora :使用
sudo dnf install uboot-tools命令进行安装。
Arch Linux 及其衍生发行版
执行
sudo pacman -S uboot-tools 命令安装。iminfo 安装,测试不在uboot-tools软件包内-
从 U-Boot 官方网站或其他可信的镜像站点下载 U-Boot 的源码包。
-
解压源码 :使用命令如
tar -zxvf u-boot-x.x.tar.gz解压下载的源码包。 -
进入源码目录并编译 :进入解压后的源码目录,执行
make命令编译。编译完成后,在tools目录下即可找到生成的iminfo可执行文件。 -
安装到系统路径(可选) :可以将生成的
iminfo文件复制到系统路径,如/usr/local/bin,以便在任意位置使用。
-
使用
binwalk分析boot0.img文件:binwalk boot0.img这将显示文件中的可能的嵌入内容,如内核和设备树文件的偏移等。 -
根据
binwalk的分析结果,提取内核和设备树文件。例如,如果发现 kernel 在偏移0x80处,可以使用以下命令提取:dd if=boot0.img of=kernel.bin bs=1 skip=128如果发现 dtb 文件在偏移0x8000处:dd if=boot0.img of=dtb.dtb bs=1 skip=32768
浙公网安备 33010602011771号