Post Reply

[TOOL] Boot.img tools [unpack, repack, ramdisk]

OP CNexus

11th June 2013, 03:00 AM   |  #1  
CNexus's Avatar
OP Recognized Contributor
Flag /home/cnexus/android
Thanks Meter: 13,625
 
9,037 posts
Join Date:Joined: May 2012
Donate to Me
More
I have not seen this posted anywhere, so I thought I would post it here. This is NOT purely my work, and I do not take credit for it as such.

Included in the attached ZIP are the following files:
  • boot_info - prints information about the boot.img passed to it, including the base address and ramdisk address. This tool prints out everything needed to repack the boot.img correctly.
  • split_boot - More commonly known as split_bootimg.pl, this rips apart the boot.img to extract the ramdisk and zImage. It has been modified by me to split the boot.img into a separate folder (specified by the file name of the boot.img passed to it) and to extract the ramdisk into a sub-folder as well (extracts the cpio from the gz and then extracts the actual files from the cpio archive)
  • unpack_ramdisk - unpacks the given ramdisk file.
    Code:
    Usage: unpack_ramdisk <ramdiskFile>
  • repack_ramdisk - repacks the ramdisk from the given directory (found online and modified slightly to take a directory)
    Code:
    Usage: repack_ramdisk <ramdiskDirectory> [outputFile]
  • mkbootimg - mkbootimg binary that creates a boot.img file from the given ramdisk and zImage. Updated to a version compiled by me to support the --ramdiskaddr option (ramdisk address) so that even nonstandard boot.img's can be repacked correctly (Use with boot_info for best results).
  • umkbootimg - included for convenience. Not made by me. Original thread here.
  • unpack - wrapper script made by me for the umkbootimg binary^ to unpack the boot.img into a separate directory and then unpack the ramdisk into a sub-directory.

Note: These tools were made for Linux. They may also work on Cygwin, but I have not personally tested them.

ANYONE is free to use / modify / kang these files as they see fit. No need to ever ask or do anything more than download.

Enjoy.
Attached Files
File Type: zip bootimg_tools.zip - [Click for QR Code] (16.9 KB, 14865 views)
File Type: zip bootimg_tools_7.8.13.zip - [Click for QR Code] (282.3 KB, 22955 views)
Last edited by CNexus; 8th July 2013 at 01:35 PM.
The Following 92 Users Say Thank You to CNexus For This Useful Post: [ View ]
11th June 2013, 03:17 AM   |  #2  
CNexus's Avatar
OP Recognized Contributor
Flag /home/cnexus/android
Thanks Meter: 13,625
 
9,037 posts
Join Date:Joined: May 2012
Donate to Me
More
UPDATE: If you downloaded, please redownload. There was an error with my repack_ramdisk script, but it's fixed now.
The Following 7 Users Say Thank You to CNexus For This Useful Post: [ View ]
8th July 2013, 01:25 PM   |  #3  
CNexus's Avatar
OP Recognized Contributor
Flag /home/cnexus/android
Thanks Meter: 13,625
 
9,037 posts
Join Date:Joined: May 2012
Donate to Me
More
Updated tools with a new boot_info script, also added my own mkbootimg binary compiled with the ramdisk address option.

Boot_info now displays the following information:
Commandline
Pagesize
Base address
Ramdisk address.

Which is everything you need to make a functional boot.img, even when the original boot.img is packed with a non-standard mkbootimg (ie, the ramdisk offset is different than the normal offset).
The Following 9 Users Say Thank You to CNexus For This Useful Post: [ View ]
29th July 2013, 05:19 AM   |  #4  
slicingtaco's Avatar
Senior Member
Flag C:\Earth\USA\California\Freakmont
Thanks Meter: 318
 
901 posts
Join Date:Joined: May 2012
More
How exactly do we use these files to unpack and repack?
I've tried running the scripts with chmod at 755 but it doesn't work.
I am i missing something?
The Following 2 Users Say Thank You to slicingtaco For This Useful Post: [ View ]
29th July 2013, 11:03 AM   |  #5  
CNexus's Avatar
OP Recognized Contributor
Flag /home/cnexus/android
Thanks Meter: 13,625
 
9,037 posts
Join Date:Joined: May 2012
Donate to Me
More
All the scripts must be in a folder in your path (~/bin for example)

Then it should work, because they call on each other. I keep all of them in my ~/bin folder, but they can be anywhere in your PATH

Sent from my buttered S3
Last edited by CNexus; 29th July 2013 at 11:15 AM.
The Following 4 Users Say Thank You to CNexus For This Useful Post: [ View ]
8th October 2013, 10:41 AM   |  #6  
twins.7's Avatar
Senior Member
Thanks Meter: 67
 
325 posts
Join Date:Joined: Nov 2010
if Android Magic Word not found at offset 0, it fail.
The Following User Says Thank You to twins.7 For This Useful Post: [ View ]
8th October 2013, 10:59 AM   |  #7  
CNexus's Avatar
OP Recognized Contributor
Flag /home/cnexus/android
Thanks Meter: 13,625
 
9,037 posts
Join Date:Joined: May 2012
Donate to Me
More
Quote:
Originally Posted by twins.7

if Android Magic Word not found at offset 0, it fail.

No, if you use unmkbootimg instead split_boot, it also finds embedded images.
The Following 2 Users Say Thank You to CNexus For This Useful Post: [ View ]
8th October 2013, 11:17 AM   |  #8  
twins.7's Avatar
Senior Member
Thanks Meter: 67
 
325 posts
Join Date:Joined: Nov 2010
Quote:
Originally Posted by CNexus

No, if you use unmkbootimg instead split_boot, it also finds embedded images.

OK, it work. But .... sorry to much complain

My boot.img has magic word in offset 2048. so it mean, there is additional header in first 2048 byte.
umkbootimg succesfully extract embedded boot.img, but in repacking, I lost the first 2048 byte, because magic header placed in offset 0.

Actually, what is the additional header for? really asking...

I fail to fastboot flash if the image have no additional header.
And it will fail to verify, if the additional header is wrong. or is it called signed boot.img?
If I change the content of boot.img, I can't flash it to device. It always said verify fail. I though, the additional header has CRC or hash or anything.

If you have spare time and want to help me, I'll post my image
The Following User Says Thank You to twins.7 For This Useful Post: [ View ]
8th October 2013, 02:34 PM   |  #9  
KineichiNxt's Avatar
Member
Flag Jakarta,indonesia
Thanks Meter: 188
 
77 posts
Join Date:Joined: Oct 2013
More
Thanks for this tools

Send from my AMOI N828 using Xda Premium
8th October 2013, 03:55 PM   |  #10  
CNexus's Avatar
OP Recognized Contributor
Flag /home/cnexus/android
Thanks Meter: 13,625
 
9,037 posts
Join Date:Joined: May 2012
Donate to Me
More
Quote:
Originally Posted by twins.7

OK, it work. But .... sorry to much complain

My boot.img has magic word in offset 2048. so it mean, there is additional header in first 2048 byte.
umkbootimg succesfully extract embedded boot.img, but in repacking, I lost the first 2048 byte, because magic header placed in offset 0.

Actually, what is the additional header for? really asking...

I fail to fastboot flash if the image have no additional header.
And it will fail to verify, if the additional header is wrong. or is it called signed boot.img?
If I change the content of boot.img, I can't flash it to device. It always said verify fail. I though, the additional header has CRC or hash or anything.

If you have spare time and want to help me, I'll post my image

I'm not sure. No tool will work for all devices, and since I've never had a device that has this special packing, it would be best if you asked one of your kernel devs for help unpacking/repacking

The Following User Says Thank You to CNexus For This Useful Post: [ View ]
Post Reply Subscribe to Thread

Tags
boot.img, boot.img modify, boot.img splitting, ramdisk, split boot.img
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Software and Hacking General [Developers Only] by ThreadRank