Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,814,319 Members 51,134 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
osm0sis
Old
(Last edited by osm0sis; 19th August 2014 at 05:23 AM.)
#1  
osm0sis's Avatar
Recognized Developer / Recognized Contributor - OP
Thanks Meter 14,304
Posts: 8,361
Join Date: Mar 2012
Post [DEV][TOOL] Android Image Kitchen - Unpack/Repack Kernel Ramdisk [Win/Android/Linux]

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

Windows and Android 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 porting these over, 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-09-15
I do NOT answer technical questions via PM. Post your question in the correct thread if you want a response.





The Following 219 Users Say Thank You to osm0sis For This Useful Post: [ Click to Expand ]
 
osm0sis
Old
(Last edited by osm0sis; 19th August 2014 at 05:33 AM.)
#2  
osm0sis's Avatar
Recognized Developer / Recognized Contributor - OP
Thanks Meter 14,304
Posts: 8,361
Join Date: Mar 2012
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


Possibly Not Working Devices (need confirmation)

None at the moment!


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 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.
I do NOT answer technical questions via PM. Post your question in the correct thread if you want a response.





The Following 30 Users Say Thank You to osm0sis For This Useful Post: [ Click to Expand ]
 
dancer_69
Old
#3  
Senior Member
Thanks Meter 227
Posts: 1,875
Join Date: Jan 2007
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 User Says Thank You to dancer_69 For This Useful Post: [ Click to Expand ]
 
osm0sis
Old
(Last edited by osm0sis; 30th December 2012 at 06:14 PM.)
#4  
osm0sis's Avatar
Recognized Developer / Recognized Contributor - OP
Thanks Meter 14,304
Posts: 8,361
Join Date: Mar 2012
Quote:
Originally Posted by dancer_69 View Post
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).
I do NOT answer technical questions via PM. Post your question in the correct thread if you want a response.





The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ Click to Expand ]
 
dancer_69
Old
(Last edited by dancer_69; 30th December 2012 at 07:52 PM.)
#5  
Senior Member
Thanks Meter 227
Posts: 1,875
Join Date: Jan 2007
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 User Says Thank You to dancer_69 For This Useful Post: [ Click to Expand ]
 
trevd
Old
(Last edited by trevd; 31st December 2012 at 05:59 AM.)
#6  
Recognized Developer
Thanks Meter 1,161
Posts: 864
Join Date: Jul 2011
Location: Hull

 
DONATE TO ME
Quote:
Originally Posted by osm0sis View Post
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, 993 views)
File Type: 7z split_bootimg.7z - [Click for QR Code] (8.0 KB, 891 views)
Don't forget to click Thanks If this post has helped. It gives me a little warm feeling inside

I WILL NOT RESPOND TO PM'S REQUESTING TECHNICAL SUPPORT


Development Work: Git Hub (https://github.com/trevd) | Huawei Dongle Support : Archos G9 , Asus Nexus 7 | adb extended version ( adbx ) [Always WIP] | The No Script, No Cygwin Standalone Boot Image Utility [WIP]
Other Work : Custom framework-res.apk resources.arsc using vendor overlays | [GUIDE][HACK]Cross Compiling for OSX on Linux with AOSP

A bug report without logs is just trivia!

Code:
adb shell dmesg ; adb logcat -b system -b radio -b events -b main
The Following 7 Users Say Thank You to trevd For This Useful Post: [ Click to Expand ]
 
osm0sis
Old
(Last edited by osm0sis; 31st December 2012 at 02:10 AM.)
#7  
osm0sis's Avatar
Recognized Developer / Recognized Contributor - OP
Thanks Meter 14,304
Posts: 8,361
Join Date: Mar 2012
Quote:
Originally Posted by dancer_69 View Post
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 View Post
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.
I do NOT answer technical questions via PM. Post your question in the correct thread if you want a response.





The Following 3 Users Say Thank You to osm0sis For This Useful Post: [ Click to Expand ]
 
osm0sis
Old
(Last edited by osm0sis; 19th March 2013 at 06:22 AM.)
#8  
osm0sis's Avatar
Recognized Developer / Recognized Contributor - OP
Thanks Meter 14,304
Posts: 8,361
Join Date: Mar 2012
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.
I do NOT answer technical questions via PM. Post your question in the correct thread if you want a response.





The Following 4 Users Say Thank You to osm0sis For This Useful Post: [ Click to Expand ]
 
ZeRo2o9
Old
#9  
ZeRo2o9's Avatar
Senior Member
Thanks Meter 263
Posts: 1,305
Join Date: Feb 2011
Location: Central Cali
wow this is so helpful i spent a long time trying to mess with linux thank you!!!


Want a cool signature? Go to Team GFX Bandits!
Samsung Intercept>Droid 2>Huawei Acend 2>Evo 3D>
HTC Vivid & HTC Inspire 4g> HTC One XL> AT&T HTC One - ROM: WCX
Click Here For My HTC Vivid MIUI ROM (Discontinued)
 
Goatshocker
Old
#10  
Goatshocker's Avatar
Senior Member
Thanks Meter 408
Posts: 941
Join Date: 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.
Quick ADB Pusher v0.5 (discontinued)
--------------------------------------------------------------------
Phone(ancient junk): ZTE Blade some CM11 build
Tablet 7": Novo 7 Basic running stock HC 3.2.1
Tablet 10": ASUS Transformer TF101 16GB running Team EOS nightly (build 26)

Phone(new): HTC One S S4 running Dark Jelly S CM10 build23
Phone(junk): Xperia P running resurrection remix or Honami MW
Phone(Newest): Galaxy S4 Mini running slimKat
-----
ლ(ಠ益ಠლ) Y U NO THANK ME? ლ(ಠ益ಠლ)

The Following User Says Thank You to Goatshocker For This Useful Post: [ Click to Expand ]
Tags
kernel, ramdisk, recovery, repack, unpack
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes