FORUMS
Remove All Ads from XDA

[DEV][TOOL] Android Image Kitchen - Unpack/Repack Kernel Ramdisk [Win/Android/Linux]

11,341 posts
Thanks Meter: 23,231
 
By osm0sis, Recognized Developer / Recognized Contributor on 30th December 2012, 03:55 PM
Post Reply Email Thread
Android Image Kitchen -- Unpack/Repack Kernel+Recovery Images, and Edit the ramdisk.

Windows ports of the necessary Linux utils for Android image (kernel/recovery) mod work:

mkbootimg, unpackbootimg: https://github.com/osm0sis/mkbootimg
mkbootfs: https://github.com/osm0sis/mkbootfs
pxa1088-mkbootimg, pxa1088-unpackbootimg: https://github.com/osm0sis/pxa1088-mkbootimg
unpackelf: https://github.com/osm0sis/unpackelf
dumpimage, mkimage: http://www.denx.de/wiki/U-Boot/WebHome
mkmtkhdr: https://github.com/osm0sis/mkmtkhdr
loki_tool: https://github.com/djrbliss/loki
futility: https://github.com/osm0sis/futility
BootSignature.jar (requires JRE 8+): https://forum.xda-developers.com/and...ified-t3600606
blobpack, blobunpack: https://github.com/AndroidRoot/BlobTools
kernel_dump: https://forum.xda-developers.com/cro...image-t3530077
bzip2, chmod, cpio, cut, dd, file, gzip, lzop, printf, tail, xz;
cygbz2-1, cygcrypto-1.0.0, cyggcc_s-1, cygiconv-2, cygintl-8, cyglzma-5, cyglzo2-2, cygmagic-1, cygssl-1.0.0, cygwin1, cygz: http://cygwin.com/
lz4: http://lz4.github.io/lz4/
magic: http://www.darwinsys.com/file/

See the Mobile Edition (AIK-mobile) initial release notes for the specifics on the native Android version.
Likewise for the Linux Edition (AIK-Linux) initial release notes.

My original intent was to have this package dependency-free, but as you can see, I did have to include Cygwin. Initially just for mkbootimg since the huaixzk standalone version wouldn't work (it wasn't loading the kernel as binary, thanks trevd); then I discovered that using the GNUWin32 cpio to unpack somehow didn't play nice with repacking the ramdisk in a usable state, so at that point I decided I might as well go Cygwin across the board. As it is, I've included the latest Cygwin-dependent executables and required libraries from their repos and built my own custom Cygwin image and ramdisk utilities built from the latest sources.

Originally only for Google Pixel/Nexus/AOSP standard boot.img files, built-in support has now expanded to Android Verified Boot (AVB)/ChromeOS/SignBlob signed boot.img files, the Samsung/Marvell PXA1088 board boot.img variant (AOSP-PXA), Loki patched boot.img files, Sony SIN signed/packaged kernel.elf extraction, Sony ELF kernel.elf files (repacked as boot.img for unlocked bootloaders), MTK headers for zImage/ramdisk, and LG Bump/Samsung SEAndroid footers for boot.img.

The main advantage here is you don't need Cygwin shell or PERL scripts. Other guides exist but none of them are universal for target device, compression and/or developed for Windows, Android ARM/x86/MIPS, and now Android ARM64/x86_64/MIPS64. With this universality in mind I've automated the whole process with batch/shell scripts.

My development work on my many projects comes out of my free time, so if you enjoy this project or anything else I've done on xda, please do hit the donate link from my profile. Thank you for your support!


Instructions

1) Unzip.
2) Either use the command-line "unpackimg <image-filename.img>", or simply drag-and-drop the image. This will split the image and unpack the ramdisk to a subdirectory.
3) Alter the ramdisk as you like.
4) The repackimg batch script requires no input and simply recombines the previously split zImage with the newly packed modified ramdisk using all the original image information (which was also split and saved).
5) The cleanup batch script resets the folder to its initial state, removing the split_img+ramdisk directories and any new packed ramdisk or image files.

There are a few optional, advanced command-line arguments for repackimg: "--original", which will cause it to repack using the original split ramdisk instead of repacking, this is useful for testing or trimming dumps; "--level" with 1-9 and possibly 0 allows changing the compression level used to repack to more closely match the original; "--avbkey" with (optionally path and) a keyname allows changing from the default AOSP testkey.

Usage is similar for the Android and Linux versions, again, just review the release notes for them.

Hopefully this is some help to someone. It's been extremely useful for me in my messing around with kernel ramdisks, which is why I created it in the first place.

Enjoy!
Questions, comments and feedback welcome.

Downloads



Credits & Thanks: All authors of the included binaries and libraries for their amazing work, as linked (or linked via GitHub) above. Peteragent5, alansj & iridaki for the general methods used in their PERL scripts and Linux guides. SuperR. & tobias.waldvogel for the general methods used in their kernel.elf unpacking scripts. _that and rayman for the general methods used to repack a working boot.blob. Chainfire for the ChromeOS and SEAndroid general methods. cybojenix for the Bump general method.

Thanks to Goatshocker for testing out things for the HTC image issues, leading to the workaround and subsequent fix, avinashrocks1990 & tajimura for testing out compression support and the large pagesize fix, civato for testing out dtb support, talich for testing out the Linux version, shoey63 for testing out Linux + ELF support, and moonbutt74 for testing out Android-x86 support. Huge thank you to trevd and Modding.MyMind/SHM for all the contributing work they've each done and support they've provided.

Disclaimer: Naturally, you take all the responsibility for what happens to your device when you start messing around with things.

Download counts:
AIK - v1.0: 1540; +HTCFix: 430. v1.5: 4718. v1.6: 3556. v1.8: 8678; +Lok2Img: 1629. v1.9: 2580. v2.0: 22886. v2.2: 20522. v2.3: 14524. v2.4: 84432; +LokiAddon: 20071. v2.5: 5004. v2.6: 9354. v2.7: 5442.
Mobile - v1.0: 311. v1.1: 265. v1.2: 302. v1.3: 100. v1.4: 486. v1.5: 224. v1.6: 3303. v1.7: 7798. v1.8: 16286. v1.9: 3800. v2.0: 5444. v2.1: 2526. v2.2: 926. v2.3: 1346. v2.4: 18426. v2.5: 2586. v2.6: 6068. v2.7: 2936.
Linux - v1.0: 75. v1.1: 208. v1.2: 233. v1.3: 112. v1.4: 421. v1.5: 173. v1.6: 1838. v1.7: 2596. v1.8: 4818. v1.9: 604; +v1.9.1: 1068. v2.0: 1836. v2.1: 1240. v2.2: 466. v2.3: 522. v2.4: 8126. v2.5: 1052. v2.6: 2018. v2.7: 1248.


XDA:DevDB Information
Android Image Kitchen, Tool/Utility for the Android General

Contributors
osm0sis
Source Code: https://github.com/osm0sis/Android-Image-Kitchen


Version Information
Status: Stable
Current Stable Version: 2.8
Stable Release Date: 2017-06-05

Created 2013-11-13
Last Updated 2017-06-07
The Following 565 Users Say Thank You to osm0sis For This Useful Post: [ View ]
 
 
30th December 2012, 04:26 PM |#2  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 23,231
 
Donate to Me
More
AIK should be universal for devices that accept Android, U-Boot and ELF format images in theory, but there is always a chance it doesn't work for your device due to image packing differences, etc. Here is a running list of confirmed working and questionably/confirmed not working devices. If your device isn't in either list odds are that it will still work fine.

Known Working Devices

Asus Nexus 7 (2012, 2013)
Asus Zenfone 2
Google Pixel (C, , XL)
Huawei Ascend Y300
Huawei Mate 8
Huawei Nexus 6P
Huawei U8800 Ideos X5
HTC Nexus 9
HTC One (M7, M8, S, X)
HTC Vivid/Raider 4G
HP Slate 21
Lenovo A706
Lenovo Vibe K5
LG G(2, 2 Mini, 3, 3 Stylus)
LG GPad (7.0, 8.3)
LG Nexus (4, 5, 5X)
LG Optimus 3D
LG Optimus 4X HD
Micromax Ninja/Bolt A27
Motorola Moto G (2013, 2014)
Motorola Moto X 2014
Motorola Nexus 6
OnePlus One
Pantech Vega Iron
Pantech Vega Secret Note
Samsung Galaxy Ace II X
Samsung Galaxy Core Mini 4G
Samsung Galaxy Mega
Samsung Galaxy Nexus
Samsung Galaxy Note (2, 3, Pro 12.2, 4)
Samsung Galaxy S(3, 4, 5)
Samsung Galaxy Star
Samsung Galaxy Tab (2 7.0, 3 10.1, 4 7.0, Pro 8.4, 4 8.0, 4 10.1, A 10.1)
Samsung Galaxy Victory
Samsung Galaxy Xcover 3
Samsung Nexus 10
Sony Xperia (Arc S, M, Neo, Neo V, Tab Z4, Z, Z1, Z5)
Spice Mi-355 Stellar Craze
Vodafone Smart Ultra 6
Xiaomi Redmi Note 3 Pro


Confirmed Not Working Devices
  • Asus Transformer Pad, Asus Zenfone 5, Lenovo K900 - different packaging using non-standard "$OS$" header. See this post.
  • HTC Desire 326G, Huawei Honor Bee, Huawei MediaPad T1 7.0 - some newer Spreadtrum devices use special image signing that adds a pre-header signature, so images will unpack/repack but most likely won't boot unless run through their internal signing tool. See this post.
  • Samsung Galaxy S (Advance, Captivate, Vibrant), Samsung Galaxy S2, Samsung Galaxy Note & Samsung Galaxy Tab - contain zImage + ramdisk but have no header instead of a standard "ANDROID!" header. See these posts.

Note: For devices requiring Loki patched images (e.g. LG G2, AT&T Samsung Galaxy S4), your device's aboot.img dump must be in the script directory to Re-Loki. (Thank you to jeboo for the original one-way Lok2Img Workaround's binary source, used prior to the official Loki Tool gaining un-Loki support).


Release Notes

Windows:
v1.0 - Dec 30, 2012 - Initial release.    
v1.5 - May 6, 2013 - Linked.
v1.6 - Sep 16, 2013 - Linked.
v1.8 - Dec 9, 2013 - Linked.
v1.9 - Jun 7, 2014 - Linked.
v2.0 - Aug 3, 2014 - Linked.
v2.2 - Mar 25, 2015 - Linked.
v2.3 - Oct 11, 2015 - Linked.
v2.4 - Feb 8, 2016 - Linked.
v2.5 - Jan 26, 2017 - Linked.
v2.6 - Feb 27, 2017 - Linked.
v2.7 - May 1, 2017 - Linked.
v2.8 - Jun 5, 2017 - Linked.

Android:
v1.0 - Mar 23, 2014 - Linked. (ARM only)
v1.1 - Apr 19, 2014 - Linked. (ARM only)
v1.2 - May 15, 2014 - Linked. (ARM only)
v1.3 - Jun 7, 2014 - Linked. (ARM, x86 with emulation)
v1.4 - Jun 17, 2014 - Linked. (ARM, x86 with emulation)
v1.5 - Aug 3, 2014 - Linked. (32bit, x64 with emulation)
v1.6 - Aug 19, 2014 - Linked. (32bit, x64 with emulation)
v1.7 - Dec 26, 2014 - Linked. (32bit, x64 with emulation)
v1.8 - Mar 25, 2015 - Linked. (32bit, x64 with emulation)    
v1.9 - Oct 11, 2015 - Linked. (32bit, x64 with emulation)
v2.0 - Dec 7, 2015 - Linked.
v2.1 - Feb 8, 2016 - Linked.
v2.2 - Mar 16, 2016 - Linked.
v2.3 - Apr 1, 2016 - Linked.
v2.4 - Apr 20, 2016 - Linked.
v2.5 - Jan 26, 2017 - Linked.
v2.6 - Feb 27, 2017 - Linked.
v2.7 - May 1, 2017 - Linked.
v2.8 - Jun 5, 2017 - Linked.

Linux:
v1.0 - Apr 11, 2014 - Linked. (x86 only)
v1.1 - Apr 19, 2014 - Linked. (x86 only)
v1.2 - May 15, 2014 - Linked. (x86 only)
v1.3 - Jun 7, 2014 - Linked. (x86 only)
v1.4 - Jun 17, 2014 - Linked. (x86 only)
v1.5 - Aug 3, 2014 - Linked. (x86 only)
v1.6 - Aug 19, 2014 - Linked. (x86 only)
v1.7 - Dec 26, 2014 - Linked.
v1.8 - Mar 25, 2015 - Linked.
v1.9 - Oct 11, 2015 - Linked.
v2.0 - Dec 7, 2015 - Linked.
v2.1 - Feb 8, 2016 - Linked.
v2.2 - Mar 16, 2016 - Linked.
v2.3 - Apr 1, 2016 - Linked.
v2.4 - Apr 20, 2016 - Linked.
v2.5 - Jan 26, 2017 - Linked.
v2.6 - Feb 27, 2017 - Linked.
v2.7 - May 1, 2017 - Linked.
v2.8 - Jun 5, 2017 - Linked.



Everyone please let me know if AIK works for your devices or if you encounter any problems, so I can make these lists more comprehensive.

If you are reporting a problem with your device, please clearly state your device name and model/variant as well as provide a link to the image file.






















The Following 107 Users Say Thank You to osm0sis For This Useful Post: [ View ]
30th December 2012, 05:03 PM |#3  
Senior Member
Thanks Meter: 245
 
More
I just tried it with a recovery.img. I don't get any errors on unpacking/repacking process, but how to get the repacked recovery.img? When I run the repackimg.bat, I don't get any error, but it doesn't generate a new recovery.img.
The Following 2 Users Say Thank You to dancer_69 For This Useful Post: [ View ] Gift dancer_69 Ad-Free
30th December 2012, 05:05 PM |#4  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 23,231
 
Donate to Me
More
Quote:
Originally Posted by dancer_69

I just tried it with a recovery.img. I don't get any errors on unpacking/repacking process, but how to get the repacked recovery.img? When I run the repackimg.bat, I don't get any error, but it doesn't generate a new recovery.img.

Was the image in the same directory as the batch files? If so then PM me a link to the image, if not, copy it in and try again.

Edit: Thanks! It was the --cmdline variable throwing up an error when it wasn't empty. Reuploaded version should now work properly for images with cmdlines (like TWRP).
The Following 9 Users Say Thank You to osm0sis For This Useful Post: [ View ]
30th December 2012, 07:12 PM |#5  
Senior Member
Thanks Meter: 245
 
More
Thanks, seems that works fine now.

EDIT:

Generates new-image.img, but this recovery is unbootable. I tested it with the same recovery.img, without to change anything, just unpack/repack. The generated image is unbootable. Device just stuck on boot logo.
The Following 2 Users Say Thank You to dancer_69 For This Useful Post: [ View ] Gift dancer_69 Ad-Free
30th December 2012, 08:06 PM |#6  
Quote:
Originally Posted by osm0sis

Android Image Kitchen -- Unpack/Repack Kernel+Recovery Images, and Edit the ramdisk.

My initial intention with this was to gather Windows ports of the necessary Linux utils for Android image (kernel/recovery) mod work with as few dependencies (like Cygwin, etc.) as possible. Here's what I ended up with:

unpackbootimg - http://github.com/huaixzk/android_win_tool/
mkbootfs, mkbootimg - http://forum.xda-developers.com/showthread.php?t=443994
cpio, gzip, libiconv2, libintl3 - http://gnuwin32.sourceforge.net/
cygwin1 - http://cygwin.com/

As you can see, in the end I did have to include Cygwin for mkbootimg since the huaixzk standalone version doesn't appear to work for some reason. I've left a note with the author and will update the package to remove Cygwin if he ever fixes the issue. As it is, I've included the cygwin1.dll as it's the only one required, and grabbed the working Cygwin-dependent executable from another thread.

Hi Buddy,

I like what you're doing here, cygwin dependencies are no good........ native on whatever platform you're using is the way to go.... with that in mind here's a mkbootimg compiled from the aosp source tree.using the MIN_GW toolchain, not a cygwin in sight

not tested it but should be alright for you.......I think I'll finish the job and smash it althought into one tool, saving f***king about., it'll will come in useful on linux too
Attached Files
File Type: 7z mkbootimg_windows_new.7z - [Click for QR Code] (10.8 KB, 3787 views)
File Type: 7z split_bootimg.7z - [Click for QR Code] (8.0 KB, 3313 views)
The Following 12 Users Say Thank You to trevd For This Useful Post: [ View ]
30th December 2012, 08:07 PM |#7  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 23,231
 
Donate to Me
More
Quote:
Originally Posted by dancer_69

Thanks, seems that works fine now.

EDIT:

Generates new-image.img, but this recovery is unbootable. I tested it with the same recovery.img, without to change anything, just unpack/repack. The generated image is unbootable. Device just stuck on boot logo.

Crap. I'll take it down for now and do some testing. Might be a few days. Things were working over here with the few images I'd tried before. Maybe I messed something up once the scripts got more robust. Batch is an ugly way to do things.

Thanks for the help testing.

Quote:
Originally Posted by trevd

Hi Buddy,

I like what you're doing here, cygwin dependencies are no good........ native on whatever platform you're using is the way to go.... with that in mind here's a mkbootimg compiled from the aosp source tree.using the MIN_GW toolchain, not a cygwin in sight

not tested it but should be alright for you.......I think I'll finish the job and smash it althought into one tool, saving f***king about., it'll will come in useful on linux too

Thanks bro! I'll throw that in with the new (hopefully working) version.

And hey go ahead and finish the job if you like. Coding is better than scripting so I'd be happy to get a mod to remove this thread once something better comes along.
The Following 4 Users Say Thank You to osm0sis For This Useful Post: [ View ]
31st December 2012, 05:19 PM |#8  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 23,231
 
Donate to Me
More
Alright people, sorry about those initial issues. OP updated with the new, fully working, v1.0. There was just some craziness in the one before with cpio not behaving like it should.

It's all Cygwin for now but trevd has been great and offered to port some things over properly while weeding out the issues, so expect a new release, completely dependency free and automated as always in the coming months, all thanks to him.
The Following 5 Users Say Thank You to osm0sis For This Useful Post: [ View ]
5th January 2013, 04:45 PM |#9  
ZeRo2o9's Avatar
Senior Member
Flag Central Cali
Thanks Meter: 310
 
More
wow this is so helpful i spent a long time trying to mess with linux thank you!!!
5th January 2013, 06:40 PM |#10  
Goatshocker's Avatar
Senior Member
Thanks Meter: 419
 
More
Hm, doesnt seem to work for me. I unpacked boot.img, repacked it (didnt change anything) and then flashed it with fastboot - resulted in a bootloop.
The boot.img before unpack/repack boots fine.
The Following User Says Thank You to Goatshocker For This Useful Post: [ View ] Gift Goatshocker Ad-Free
5th January 2013, 06:54 PM |#11  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 23,231
 
Donate to Me
More
Quote:
Originally Posted by Goatshocker

Hm, doesnt seem to work for me. I unpacked boot.img, repacked it (didnt change anything) and then flashed it with fastboot - resulted in a bootloop.
The boot.img before unpack/repack boots fine.

Interesting. Worked for both dancer_69 and myself. Device info and image in PM please.
Post Reply Subscribe to Thread

Tags
kernel, ramdisk, recovery, repack, unpack

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes