一、背景
长虹电视部分海思平台并没有boot分区,使用的不是Android标准的boot.img。使用的是kernel分区,无法使用网上的boot解包工具解包打包。
二、kernel分区文件分析
WinHex打开kernel image,可以看到开头是常规的kernel image header。0x644d5241是kernel的Magic number,kernel text offset=0x80000,image size=0x1723000。注意到此处的image size是大于kernel文件大小的。对比了其他的纯内核image,header也是大于生成文件大小的。可能与对齐有关。
一般ramdisk是cpio.gz格式,文件头是0x1F8B08。搜索这个16进制数,此处可能就是ramdisk的起始地址。
三、分割image,解包
我是在Ubuntu下操作的,Windows也可以使用其他工具将从1F8B0800内容开始分割成两段。前面一部分就是kernel,后一部分就是ramdisk。
mkdir kernel_ramdisk
cd kernel_ramdisk
gzip -d -c ../kernel_ramdisk.cpio.gz | cpio -i -d -m
成功解压出ramdisk。
修改ramdisk...
重新打包ramdisk
./mkbootimg_tools/mkbootfs kernel_ramdisk/ | gzip -n -f > new_kernel_ramdisk
重新打包后发现新的ramdisk比原来的小了很多,原因是我们分隔出来的ramdisk尾部包含了很多垃圾数据,并不属于ramdisk的内容,当解压为cpio时,这些数据就已丢弃,重新打包也不会再包含这些数据。暂不清楚这些数据是否有实际的意义,只能看重新打包固件后能否开机来验证了。
注:ramdisk解包打包可以借助原来的boot解包工具,里面包含了ramdisk解包打包的工具和指令。
四、重新打包kernel+ramdisk
提取出kernel,18523632就是0x11AA5F0
dd if=78M_30M-kernel bs=1 count=18523632 of=kernel
制作一个空文件,大小30M(大于kernel+ramdisk之和小于分区大小)
dd if=/dev/zero of=new_kernel bs=1M count=30
合并kernel和新的ramdisk
dd if=kernel of=new_kernel conv=notrunc
dd if=new_kernel_ramdisk.cpio.gz of=new_kernel bs=1 seek=18523632 conv=notrunc
五、刷机验证
待验证
如果无法开机,可能ramdisk后面的数据也是有用的,可以打包时仅替换ramdisk试试
dd if=new_kernel_ramdisk.cpio.gz of=78M_30M-kernel bs=1 seek=18523632 conv=notrunc
注意:18523632要根据你的固件包ramdisk位置做调整,每个包都不一样。recovery分区和kernel分区解包打包方法一样。