Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP osm0sis

30th December 2012, 04:55 PM   |  #1  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Thanks Meter: 14,929
 
8,618 posts
Join Date:Joined: Mar 2012
More
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:

unpackbootimg, mkbootimg: https://github.com/osm0sis/mkbootimg/
mkbootfs: https://github.com/osm0sis/mkbootfs/
bzip2, cpio, cut, file, gzip, lzop, xz;
cygbz2-1, cyggcc_s-1, cygiconv-2, cygintl-8, cyglzma-5, cyglzo2-2, cygmagic-1, cygwin1, cygz: http://cygwin.com/
lz4: http://code.google.com/p/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 unpackbootimg, mkbootimg, and mkbootfs executables from the latest CM and AOSP sources.

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, or Android ARM/x86/MIPS. With this universality in mind I've automated the whole process with batch/shell scripts.


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 is an optional command-line argument, "--original", for repackimg which will cause it to repack using the original split ramdisk instead of repacking, this is useful for testing or trimming dumps.

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.



Credits & Thanks: All authors of the included binaries and libraries for their amazing work, as linked above. Peteragent5, alansj & iridaki for the general methods used in their PERL scripts and Linux guides. 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, shoey63 + talich for testing out the Linux version, and moonbutt74 for testing out Android-x86 support. Huge thank you to trevd and Modding.MyMind 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.
Mobile - v1.0: 311. v1.1: 265. v1.2: 302. v1.3: 100. v1.4: 486. v1.5: 224.
Linux - v1.0: 75. v1.1: 208. v1.2: 233. v1.3: 112. v1.4: 421. v1.5: 173.


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

Contributors
osm0sis

Version Information
Status: Stable
Current Stable Version: 2.0
Stable Release Date: 2014-08-03

Created 2013-11-13
Last Updated 2014-10-06
Last edited by osm0sis; 19th August 2014 at 06:23 AM.
The Following 260 Users Say Thank You to osm0sis For This Useful Post: [ View ]
30th December 2012, 05:26 PM   |  #2  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Thanks Meter: 14,929
 
8,618 posts
Join Date:Joined: Mar 2012
More
AIK should be universal for devices that accept Android 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)
Huawei Ascend Y300
Huawei U8800 Ideos X5
HTC One (M8, S, X)
HTC Vivid/Raider 4G
Lenovo A706
LG Nexus (4, 5)
LG Optimus 4X HD
Micromax Ninja/Bolt A27
Pantech Vega Secret Note
Samsung Galaxy Ace II X
Samsung Galaxy Mega
Samsung Galaxy Nexus
Samsung Galaxy Note (2, 3)
Samsung Galaxy S(3, 4)
Samsung Galaxy Tab (2 7.0, 3 10.1, Pro 8.4)
Samsung Nexus 10
Sony Xperia (Arc S, Neo V)
Spice Mi-355 Stellar Craze


Confirmed Not Working Devices

Alps A5ENZE & Qmobile Noir A7 - MTK uses what looks like a regular image but has weird section header "labels" that break ramdisk decompression. See this post.
Samsung Galaxy S (Advance, Captivate, Vibrant), Samsung Galaxy S2 & Samsung Galaxy Note - contain zImage + ramdisk but have no header instead of a standard "ANDROID!" header. See these posts.
Samsung Galaxy Core Mini 4G & Samsung Galaxy Tab 4 7.0 - Samsung has altered the standard header, swapping some values (including pagesize) around, breaking unpacking entirely. See this post.
Sony Xperia (P, U) - different packaging using non-standard, Linux "ELF" header. See this post.


Requiring Loki Add-on

LG G2, AT&T Samsung Galaxy S4

Any images that have been "Loki-fied" to circumvent bootloader protections prior to distribution do not unpack correctly. See these posts.

Use the Loki Add-On attached in the OP to convert the Loki image to Android standard. Uses the latest official Loki Tool, which I've compiled for Cygwin from PhilZ's updated source. Unzip it overtop of the normal AIK folder. Repacked images must be re-Loki'd before flashing. Usage is UnLokImg, UnpackImg, Edit ramdisk, RepackImg, ReLokImg. Note: Your device's aboot.img dump must be in the script directory to Re-Loki.

There are also flashable zips which re-Loki, available for modification as mentioned in this post and here, but the new Loki Add-On is an all-in-one solution. (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

Win32:
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.

ARM/x86/MIPS:
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.
v1.6 - Aug 19, 2014 - Linked.

Linux:
v1.0 - Apr 11, 2014 - Linked.
v1.1 - Apr 19, 2014 - Linked.
v1.2 - May 15, 2014 - Linked.
v1.3 - Jun 7, 2014 - Linked.
v1.4 - Jun 17, 2014 - Linked.
v1.5 - Aug 3, 2014 - Linked.
v1.6 - Aug 19, 2014 - 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.
Last edited by osm0sis; 11th October 2014 at 05:48 PM.
The Following 34 Users Say Thank You to osm0sis For This Useful Post: [ View ]
30th December 2012, 06:03 PM   |  #3  
Senior Member
Thanks Meter: 233
 
1,895 posts
Join Date:Joined: Jan 2007
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 ]
30th December 2012, 06:05 PM   |  #4  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Thanks Meter: 14,929
 
8,618 posts
Join Date:Joined: Mar 2012
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).
Last edited by osm0sis; 30th December 2012 at 07:14 PM.
The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ View ]
30th December 2012, 08:12 PM   |  #5  
Senior Member
Thanks Meter: 233
 
1,895 posts
Join Date:Joined: Jan 2007
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.
Last edited by dancer_69; 30th December 2012 at 08:52 PM.
The Following User Says Thank You to dancer_69 For This Useful Post: [ View ]
30th December 2012, 09:06 PM   |  #6  
Recognized Developer
Flag Hull
Thanks Meter: 1,193
 
876 posts
Join Date:Joined: Jul 2011
Donate to Me
More
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, 1211 views)
File Type: 7z split_bootimg.7z - [Click for QR Code] (8.0 KB, 1067 views)
Last edited by trevd; 31st December 2012 at 06:59 AM.
The Following 7 Users Say Thank You to trevd For This Useful Post: [ View ]
30th December 2012, 09:07 PM   |  #7  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Thanks Meter: 14,929
 
8,618 posts
Join Date:Joined: Mar 2012
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.
Last edited by osm0sis; 31st December 2012 at 03:10 AM.
The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ View ]
31st December 2012, 06:19 PM   |  #8  
osm0sis's Avatar
OP Recognized Developer / Recognized Contributor
Thanks Meter: 14,929
 
8,618 posts
Join Date:Joined: Mar 2012
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.
Last edited by osm0sis; 19th March 2013 at 07:22 AM.
The Following 4 Users Say Thank You to osm0sis For This Useful Post: [ View ]
5th January 2013, 05:45 PM   |  #9  
ZeRo2o9's Avatar
Senior Member
Flag Central Cali
Thanks Meter: 271
 
1,343 posts
Join Date:Joined: Feb 2011
More
wow this is so helpful i spent a long time trying to mess with linux thank you!!!
5th January 2013, 07:40 PM   |  #10  
Goatshocker's Avatar
Senior Member
Thanks Meter: 410
 
941 posts
Join Date:Joined: Oct 2010
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 ]
Post Reply Subscribe to Thread

Tags
kernel, ramdisk, recovery, repack, unpack
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes