[Note Edge General] AlaskaLinuxUser:
Post #7. Kernel - How to break down and make boot images.

Post #7. Kernel - How to break down and make boot images.

Breaking down a boot image:

Okay, so first things first, STEP 1: downloads!

Download these things:

http://www.mediafire.com/download/zl80gh0t310trla/unpack-bootimg.pl

http://www.mediafire.com/download/xdmd278n17gm58h/unmkbootimg

http://www.mediafire.com/download/byf0tw4ga2mqtw0/repack-bootimg.pl

http://www.mediafire.com/download/7cmi548pzetc6c4/mkbootimg

And download your boot image that you want to break down, if you have not already.

I am using Linux, Ubuntu 14.04. I did this previously from Debian Wheezy, so any Linux should work. You can also use a VM, virtualbox, etc. if you are on a Windows computer.

STEP 2: Unzip!

Go ahead and unzip the zipfile if you are breaking down a flashable kernel zip that you downloaded. Preferably in its very own folder. For my work, I made a folder called "playground" in my home directory to play around in. I will reference the "playground" meaning the main folder with everything in it. Now, in the playground, make a new folder called "bootimage". In the playground folder, copy the boot.img file to the bootimage folder.

STEP 3: Tools setup!

Copy the downloaded above tools into a new folder called "tools" in the playground folder. Open a terminal here and give these files executable permissions and copy them again to the bootimage folder:

$ cd ~/playground/tools
$ chmod 777 ./*
$ cp ./ ../bootimage

We copy this twice so we have backups of the tools in case we delete them accidentally.

STEP 4: Unpack the boot image!

Open a terminal and go to the bootimage folder, and start typing:

$ cd ~/playground/boot.img
$ ./unmkbootimg ./boot.img

You will see some output in the terminal that looks *kind of* like this:

$ ./unmkbootimg ./boot.img
unmkbootimg version 1.2 - Mikael Q Kuisma <kuisma@ping.se>
Kernel size 2992704
Kernel address 0x10008000
Ramdisk size 2196028
Ramdisk address 0x11000000
Secondary size 0
Secondary address 0x10f00000
Kernel tags address 0x10000100
Flash page size 2048
Board name is ""
Command line ""
This image is built using standard mkbootimg
Extracting kernel to file zImage ...
Extracting root filesystem to file initramfs.cpio.gz ...
All done.
---------------
To recompile this image, use:
mkbootimg --kernel zImage --ramdisk initramfs.cpio.gz -o new_boot.img
---------------

Whatever it says, copy and paste it, hand type it, screenshot, whatever it takes, write the output down, because this is the key to re-making your boot image!

Then, you can unpack it like so:

$ ./unpack-bootimg.pl ./boot.img

You should see something *like* this:

$ ./unpack-bootimg.pl ./boot.img
kernel written to ./boot.img-kernel.gz
ramdisk written to ./boot.img-ramdisk.cpio.gz
7607 blocks

extracted ramdisk contents to directory ./boot.img-ramdisk/

You will now have folders and files to play with!

Make changes to your boot image:

Now is the time to change any files you want, such as delete the kernel and put yours in instead, etc. I can not tell you much about this, since I don't know what you are doing in your boot image. Here is an example of me turning a Captivate glide cell phone into a Debian "laptop":

http://xdaforums.com/captivate-glide/general/samsung-captivate-glide-debian-chatter-t3233807

Re-pack the boot.img:

Okay, so you have made your changes, now it is time to put it back together. Go back to your playground folder.

$ cd ~/playground/bootimage
$ rm initramfs.cpio.gz
$ cd ./boot.img-ramdisk/
$ sudo su
<enter your password>
# find . | cpio --quiet -H newc -o | gzip > ../initramfs.cpio.gz
# cd ..
# mkbootimg --kernel zImage --ramdisk initramfs.cpio.gz --base 0x0 --cmdline 'console=ttyS1,115200n8 androidboot.selinux=permissive' -o new_boot.img

Note that the last part, "mkbootimg" needs to be all the stuff I told you to write down when you broke down your boot image, or it needs to be the new command line you want your boot image to use. The new_boot.img is your newly created boot image file, which you should rename boot.img, after you remove your old boot.img file from the folder.

-With heimdall, heimdall-frontend, or Odin, flash the new_boot.img to the boot partition of your phone, or make it flashable per Post #5 or Post #6.