[Miscellaneous Android Development] jcadduono:
There's already a few different boot image repacking tools out there but I've been trying to teach myself C and it seemed like a good starting point.

I built on the existing mkbootimg header file (and yes, a few functions from the original mkbootimg) and made my way to where it is now.

It's now part of the Kali NetHunter installer and no-verity-opt-encrypt, so I consider it at least somewhat stable. I suppose eventually I'll try to import it into TWRP so we don't need to flash SuperSU/no-verity-opt-encrypt and it will give you an option on boot to turn off forced encryption/verity.

Anyways, it builds for both Windows, Linux, and Android. That's nice, isn't it?

Windows: https://build.nethunter.com/possibly-the-coolest-things/bootimg (bootimg.exe, 41.5 KB)

Linux/Android/Source: https://github.com/jcadduono/android_external_libbootimg

It clearly needs a new name, as the current one conflicts with, well, a few of the other pretty similar projects.

But I just figured I'd share it because I wasted a few days coding it.

Oh and I want you to find flaws. Break it!

It has a built in kernel command line parser too, so you can set individual arguments on the cmdline. (useless but cool)

When modifying or creating an image, it's a good idea to add --hash to arguments to build the board hash.

You can verify a hash of an image with bootimg v boot.img --hash to see if it's intact.

It follows the rule of sha1((kernel+size)+(ramdisk+size)+(second+size)+(dt+size)).

Note that this can produce differing hashes from tools that don't hash an empty dt. (ex. mkbootimg)

jc@gallifrey:~$ bootimg -H
Usage: ./bootimg [xcuvvf] [args...]

Modes:
-x, --unpack - unpack an Android boot image
-c, --create - create an Android boot image
-u, --update - update an Android boot image
-v, -vv, --verbose - print boot image details
-H, --help - print usage information

Options: (set value only for create/update mode)
[ -k, --kernel "kernel" ]
[ -r, --ramdisk "ramdisk" ]
[ -s, --second "second" ]
[ -d, --dt "dt.img" ]
[ -m, --board "board magic" ]
[ -os, --os_version "A.B.C" ]
[ -pl, --patch_level "YYYY-MM-DD" ]
[ -l, --cmdline "boot cmdline" ]
[ -a, --arg "cmdline" "value" ]
[ -p, --pagesize <size> ]
[ -b, --base <hex> ]
[ -ko, --kernel_offset <hex> ]
[ -ro, --ramdisk_offset <hex> ]
[ -so, --second_offset <hex> ]
[ -to, --tags_offset <hex> ]
[ -h, --hash ]

Options for MediaTek devices:
[ -km, --kernel_mtk "KERNEL" ]
[ -rm, --ramdisk_mtk "ROOTFS" ]
[ -sm, --second_mtk "SECOND" ]
[ -dm, --dt_mtk "DTIMAGE" ]

Unpack:
-i, --input "boot.img"
-o, --output "directory"
Create:
-o, --output "boot.img"
-i, --input "directory"
Update:
-i, --input "boot.img"
[ -o, --output "boot.img" ]

To remove an item from the image, specify ! as its value.

jc@gallifrey:~/build/twrp/genzip/out$ bootimg xv twrp-3.0.2-0-beta14-h918.img beta14
BOARD_CMDLINE "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 user_debug=31 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff androidboot.hardware=elsa androidboot.bootdevice=624000.ufshc androidboot.selinux=permissive"
BOARD_PAGESIZE 4096
BOARD_BASE 0x80000000
BOARD_KERNEL_OFFSET 0x00008000
BOARD_RAMDISK_OFFSET 0x02200000
BOARD_SECOND_OFFSET 0x00F00000
BOARD_TAGS_OFFSET 0x00000100
BOARD_KERNEL_SIZE 18892835
BOARD_RAMDISK_SIZE 6856510
BOARD_HASH 0xe08fb56fedb51376e95ba28441b48c147d870a75
jc@gallifrey:~/build/twrp/genzip/out$ bootimg cvv twrp-beta14.img beta14 --hash
Found second: beta14/twrp-3.0.2-0-beta14-h918.img-second
Found ramdisk_offset: beta14/twrp-3.0.2-0-beta14-h918.img-ramdisk_offset
Found pagesize: beta14/twrp-3.0.2-0-beta14-h918.img-pagesize
Found dt: beta14/twrp-3.0.2-0-beta14-h918.img-dt
Found second_offset: beta14/twrp-3.0.2-0-beta14-h918.img-second_offset
Found base: beta14/twrp-3.0.2-0-beta14-h918.img-base
Found kernel: beta14/twrp-3.0.2-0-beta14-h918.img-kernel
Found kernel_offset: beta14/twrp-3.0.2-0-beta14-h918.img-kernel_offset
Found tags_offset: beta14/twrp-3.0.2-0-beta14-h918.img-tags_offset
Found cmdline: beta14/twrp-3.0.2-0-beta14-h918.img-cmdline
Found board: beta14/twrp-3.0.2-0-beta14-h918.img-board
Found ramdisk: beta14/twrp-3.0.2-0-beta14-h918.img-ramdisk
BOARD_MAGIC ""
BOARD_CMDLINE "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 user_debug=31 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff androidboot.hardware=elsa androidboot.bootdevice=624000.ufshc androidboot.selinux=permissive"
BOARD_PAGESIZE 4096
BOARD_BASE 0x80000000
BOARD_KERNEL_OFFSET 0x00008000
BOARD_RAMDISK_OFFSET 0x02200000
BOARD_SECOND_OFFSET 0x00F00000
BOARD_TAGS_OFFSET 0x00000100
BOARD_KERNEL_SIZE 18892835
BOARD_RAMDISK_SIZE 6856510
BOARD_SECOND_SIZE 0
BOARD_DT_SIZE 0
BOARD_HASH 0xe08fb56fedb51376e95ba28441b48c147d870a75
jc@gallifrey:~/build/twrp/genzip/out$ bootimg uv twrp-beta14.img --arg androidboot.selinux enforcing --hash
BOARD_CMDLINE "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 user_debug=31 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff androidboot.hardware=elsa androidboot.bootdevice=624000.ufshc androidboot.selinux=enforcing"

XDA:DevDB Information

bootimg, Tool/Utility for all devices (see above for details)

Contributors

jcadduono

Version Information

Status: Stable

Current Stable Version: 1.1

Stable Release Date: 2017-12-22

Created 2016-11-05

Last Updated 2017-12-22