As I tried instructions to install Linux on Amlogic S905 Android TV boxes yesterday, I wanted to extract kernel.img file found in Android firmware, but Google did not help that much until I found mkboot part of mkbootimg_tools scripts. But first let’s see how kernel.img is created… Google provide a Python script called mkbootimg that combine the kernel image (e,.g. zImage), a rootfs/ramdisk and the device tree (DTB) file with a command line that looks like:
1 |
./mkbootimg --base=0 --kernel_offset=0x01080000 --kernel ${KERNEL} --ramdisk_offset=0x01000000 --ramdisk ./${ROOTFS} --second ${DTBFILE} --output ./kernel.img |
However, AFAIK the company does not provide a “unmkbootimg” script, and mkbootimg can only be used to create kernel.img, not decompile it. But that’s what mkboot does, and it works for kernel.img and recovery.img. Let’s retrieve the necessary files first:
1 |
git clone https://github.com/xiaolu/mkbootimg_tools |
mkboot is a bash script so we can use it right away:
1 2 3 4 5 6 7 8 9 10 11 |
cd mkbootimg_tools ./mkboot <Unpack and repack boot.img tool> ---------------------------------------------------------------------- Not enough parameters or parameter error! unpack boot.img & decompress ramdisk: mkboot [img] [output dir] mkboot boot.img boot20130905 Use the unpacked directory repack boot.img(img_info): mkboot [unpacked dir] [newbootfile] mkboot boot20130905 newboot.img |
So it can be used both for unpacking and repacking kernel.img to/from the output directory. Let’s run the command […]