When working on Android, I found it useful to be able to unpack a boot image, replace a few files and repack it. unbootimg is the perfect complement to the mkbootimg tool that is used to create Android boot images.
unbootimg takes an Android boot image and produces all that is necessary in order to create a new image using mkbootimg. In particular it extracts the kernel command line and the addresses of the image parts, and creates a command line for mkbootimg to regenerate the image as close to the original one. It even verifies the SHA1 checks!
repack.sh are trivial shell wrappers for unbootimg that also
take care of the ramdisk packaging: cpio and gzip. They are designed to
complement, so that this would simply recreate boot.img without changes:
unpack.sh boot.img repack.sh boot.img
If you already have the AOSP repo and managed to build mkbootimg, adding unbootimg is easy.
mydroid/repo/system/core/mkbootimg. Note: it overwrites Android.mk to include unbootimg.
cd mydroid/repo . build/envsetup.sh make mkbootimg unbootimg # sadly that can't install unpack.sh and repack.sh so we need: mmm system/core/mkbootimg
mydroid/repo/out/host/linux-x86/bin in your path. Easiest way to do this is:
setpaths # this is defined by Android build system: . build/envsetup.sh
unbootimg depends (like mkbootimg) on libmincrypt for computing the SHA1, but this can easily be disabled in the source code.
# on the phone: copy the boot or recovery image, for example dd if=/dev/mtd/mtd3 of=/sdcard/recovery-backup.img # on the host: pull the backup adb pull /sdcard/recovery-backup.img . # unpack it unpack.sh recovery-backup.img # edit as you wish: # cmdline: recovery-backup.img-mk # kernel: recovery-backup.img-kernel # ramdisk: recovery-backup.img-ramdisk/ # repack it repack.sh recovery-backup.img # send to phone adb push recovery-backup.img /sdcard # flash it using flash_image