[MTD][Tool]Boot.img Extraction Tool - Epic 4G Android Development

I know some people have had a need to take apart a the boot.img file that mtd roms use, and I have been curious myself, so I wrote a bash script to do the job. The format of these files is as follows:
Code:
[
zImage[
kernel,
initramfs,
???
],
header (512 bytes),
boot,
recovery,
]
This script will split out the zImage, boot, recovery, and the initramfs from inside the zimage. These are all in gzipped cpio format. All three of those will be extracted into separate folders.
Instructions for use:
IMPORTANT: run this as root so permissions are preserved
Code:
tar -xf extract_boot.tar.bz2
./extract_boot.sh -b boot.img -o output_dir
Download link:
extract_boot.tar.bz2 - 1 KB
Thanks:
supercurio: Used some of his code from kernel_repack_utils to learn how to extract the zImage.
How to rebuild:
There is a script in the EpicCM repos that can rebuild a boot.img from the zImage, boot.cpio.gz, and recovery.cpio.gz.
Link: mkshbootimg.py

Thank you. I've been looking for this.
Sent from my SPH-D700 using Tapatalk

What am I doing wrong? I've tried extracting both cm7 and stock mtd kernels using this tool on android using terminal emulator. They both say syntax error.
Sent from my SPH-D700 using Tapatalk

xboxfanj said:
What am I doing wrong? I've tried extracting both cm7 and stock mtd kernels using this tool on android using terminal emulator. They both say syntax error.
Sent from my SPH-D700 using Tapatalk
Click to expand...
Click to collapse
This is meant for Linux. Something like Fedora or Ubuntu. Its a bash script, so it may still work on a phone it you run it in bash, but I doubt it.
Sent from my SPH-D700 using xda premium

Also, I think our boot.img's are a little weird.
sent from my always aosp epic

While you were figuring this out, I was getting this ready......
https://github.com/nubecoder/create_boot.img
Kernel devs should easily be able to make some use of it.
=]

nubecoder said:
While you were figuring this out, I was getting this ready......
https://github.com/nubecoder/create_boot.img
Kernel devs should easily be able to make some use of it.
=]
Click to expand...
Click to collapse
Oh you sneaky....
sent from my always aosp epic

zman0900 said:
I know some people have had a need to take apart a the boot.img file that mtd roms use, and I have been curious myself, so I wrote a bash script to do the job. The format of these files is as follows:
Code:
[
zImage[
kernel,
initramfs,
???
],
header (512 bytes),
boot,
recovery,
]
This script will split out the zImage, boot, recovery, and the initramfs from inside the zimage. These are all in gzipped cpio format. All three of those will be extracted into separate folders.
Instructions for use:
IMPORTANT: run this as root so permissions are preserved
Code:
tar -xf extract_boot.tar.bz2
./extract_boot.sh -b boot.img -o output_dir
Download link:
extract_boot.tar.bz2 - 1 KB
Thanks:
supercurio: Used some of his code from kernel_repack_utils to learn how to extract the zImage.
How to rebuild:
There is a script in the EpicCM repos that can rebuild a boot.img from the zImage, boot.cpio.gz, and recovery.cpio.gz.
Link: mkshbootimg.py
Click to expand...
Click to collapse
okay so...
extracting = CHECK
repacking = wtf???
how are you supposed to use the code from github? i dont see a way to download it so u can use as an executable text file and copying and pasting code into the teminal doesnt work.... how do i use it?

roddygonzo17 said:
okay so...
extracting = CHECK
repacking = wtf???
how are you supposed to use the code from github? i dont see a way to download it so u can use as an executable text file and copying and pasting code into the teminal doesnt work.... how do i use it?
Click to expand...
Click to collapse
Click the raw link in the upper right. That will give you plain text. You might want to check out what nubecoder did above, it could be easier to use.
Sent from my SPH-D700 using xda premium

nubecoder said:
While you were figuring this out, I was getting this ready......
https://github.com/nubecoder/create_boot.img
Kernel devs should easily be able to make some use of it.
=]
Click to expand...
Click to collapse
Nice! I've been working on a kernel and set up a similar build system for it in my github.
Some questions: how does mkbootfs work? It seems tovtake the place of cpio -o -c. Does it automatically set up the correct file permissions and ownership? If not, how are these being set? Last, is there source somewhere?
Sent from my SPH-D700 using xda premium

So do u have to make a zimage first and then make that a boot.img? I am so confused.
Sent from my SPH-D700 using Tapatalk

xboxfanj said:
So do u have to make a zimage first and then make that a boot.img? I am so confused.
Sent from my SPH-D700 using Tapatalk
Click to expand...
Click to collapse
Yep.
sent from my always aosp epic

So then where's the zimage maker?
Sent from my SPH-D700 using Tapatalk

xboxfanj said:
So then where's the zimage maker?
Sent from my SPH-D700 using Tapatalk
Click to expand...
Click to collapse
You compile it yourself..
sent from my always aosp epic

nubecoder said:
While you were figuring this out, I was getting this ready......
https://github.com/nubecoder/create_boot.img
Kernel devs should easily be able to make some use of it.
=]
Click to expand...
Click to collapse
This worked after a few fixes. The script references files without the ./ prefix in several places. This caused errors for me. I'm completely sure why, but I think it's because of my shell configuration change I had to make to install the codesourcery ARM toolchain.
After fixing it, it created the boot.img jsut fine, but the resulting image was too large to flash - around 7.6MB. Either the recovery or initramfs (I'm sorry I don't remember which one right now) you supplied is much larger than the one I was using and caused the increased size.

toadlife said:
This worked after a few fixes. The script references files without the ./ prefix in several places. This caused errors for me. I'm completely sure why, but I think it's because of my shell configuration change I had to make to install the codesourcery ARM toolchain.
After fixing it, it created the boot.img jsut fine, but the resulting image was too large to flash - around 7.6MB. Either the recovery or initramfs (I'm sorry I don't remember which one right now) you supplied is much larger than the one I was using and caused the increased size.
Click to expand...
Click to collapse
I think there's a lot of unnecessary parts in that initramfs, like the res folder and binaries in sbin. I think those should only be in the recovery. Check out my working initramfs in my github https://github.com/zman0900/android_kernel_epic4g_gb_mtd/tree/master/initramfs_mtd

So do the zimages inside the boot.img not have an intramfs? And if that's the case, I can probably just use the zimage that I got when I unpacked the cm7 kernel also when I repack, right? I'm updating intramfs and I know its in boot.img, but idk about zimage. Thanks.
Sent from my SPH-D700 using Tapatalk

xboxfanj said:
So do the zimages inside the boot.img not have an intramfs? And if that's the case, I can probably just use the zimage that I got when I unpacked the cm7 kernel also when I repack, right? I'm updating intramfs and I know its in boot.img, but idk about zimage. Thanks.
Sent from my SPH-D700 using Tapatalk
Click to expand...
Click to collapse
The zImage from cm7 won't work for a tw rom!
The zImage does have an initramfs. Mtd uses a two stage boot. So the zImage contains the kernel and a small first stage initramfs. The phone loads the zImage and starts the kernel, which then runs init in the first stage. That loads the second stage initramfs from the boot.img and executes its init, which mounts filesystems and handles the rest of the boot.
Sent from my SPH-D700 using xda premium

zman0900 said:
The zImage from cm7 won't work for a tw rom!
The zImage does have an initramfs. Mtd uses a two stage boot. So the zImage contains the kernel and a small first stage initramfs. The phone loads the zImage and starts the kernel, which then runs init in the first stage. That loads the second stage initramfs from the boot.img and executes its init, which mounts filesystems and handles the rest of the boot.
Sent from my SPH-D700 using xda premium
Click to expand...
Click to collapse
LOL. I know TW and CM7 kernels aren't compatible. Thank you very much for all the information though.

Umm...the zImage for tw WILL work for cm...its just the initramfs that changes, iirc
sent from my touchwiz 4.5-ed epic

Related

[Q] Kernel Extraction

How difficult would it be to "rip" a kernel from a ROM, to use in a different ROM? Is it a matter of pulling certain files from the zip and creating and signing a new zip, or is it much more involved?
Try it and find out. It's pretty easy to find. Not all ROMs include a kernel, so try out the Andromeda one for example, which does include a kernel.
ragnarokx said:
How difficult would it be to "rip" a kernel from a ROM, to use in a different ROM? Is it a matter of pulling certain files from the zip and creating and signing a new zip, or is it much more involved?
Click to expand...
Click to collapse
ragnarokx said:
How difficult would it be to "rip" a kernel from a ROM, to use in a different ROM? Is it a matter of pulling certain files from the zip and creating and signing a new zip, or is it much more involved?
Click to expand...
Click to collapse
If the rom you want to put it in has a kernel then it is just a matter of replacing the zImage in one with the other. Then resign.
For a rom that doesnt have one it could get a little uglier but still easy. (I just use one that has a kernel in it.)
smeyerhuky said:
If the rom you want to put it in has a kernel then it is just a matter of replacing the zImage in one with the other. Then resign.
For a rom that doesnt have one it could get a little uglier but still easy. (I just use one that has a kernel in it.)
Click to expand...
Click to collapse
So all I need is the "zImage"? I don't need the "redbend_ua" or files in any other folder?
And I did want to transplant this kernel to a ROM that doesn't come with a kernel, but you're saying that's not easy to do. So what if instead of putting the kernel directly in the ROM, I take a stand-alone kernel zip, put my zImage in there, resign, and install the kernel after I install the ROM. Would that work?
[QOUTE]So all I need is the "zImage"? I don't need the "redbend_ua" or files in any other folder? [/QOUTE]
as long as the rom your using had redbend_ua then there is no need to copy it over, but its the same redbend_ua for both probably.
ragnarokx said:
So what if instead of putting the kernel directly in the ROM, I take a stand-alone kernel zip, put my zImage in there, resign, and install the kernel after I install the ROM. Would that work?
Click to expand...
Click to collapse
That is what I always do., ps I include my keyboard hack as well. Don't forget to resign...
Sent from my SPH-D700 using XDA App

zipalign?

I have been reading up on zipalign and am wondering how to do this myself. I am running stock deodexed so i know I'm not zipaligned. Although i am quite experienced in programming and i could learn how to use Android SDK, i do not have the time to do do. Is there a tool i can use to easily zipalign my apks ok my phone?
Sent from my Nexus S using XDA App
You would need an arm compiled version of zipalign. From there, it's fairly simple to do, as you could look at some of the init.d scripts I've seen for zip aligning dirs for the command needed to do what you want. A basic overview of commands used is:
Code:
zipalign 4 input.apk input-aligned.apk
mv input-aligned.apk input.apk
You can't directly zip align to the same apk name.
imnuts said:
You would need an arm compiled version of zipalign. From there, it's fairly simple to do, as you could look at some of the init.d scripts I've seen for zip aligning dirs for the command needed to do what you want. A basic overview of commands used is:
Code:
zipalign 4 input.apk input-aligned.apk
mv input-aligned.apk input.apk
You can't directly zip align to the same apk name.
Click to expand...
Click to collapse
Sorry that went way over my head i think I'll just stay where i am.
Sent from my Nexus S using XDA App
You really aren't missing much. Zip aligning is one of those things to help with performance that does so little, that you probably aren't going to notice it if it hasn't been done. Does it help? Probably. Will you notice a difference between a zip-aligned and non-aligned ROM? Probably not.

[Q] How to change Kernel of ROM Before installatio in it's zip file.

I would like to learn how one can change the kernel/modem in a ROM's zip BEFORE flashing it. I often use the Entropy Kernel after I flash a new ROM. The Kernel has a zimage file. How do I incorporate it into the zip? Same for modem file.
Thanks in advance.
NeoMustain said:
I would like to learn how one can change the kernel/modem in a ROM's zip BEFORE flashing it. I often use the Entropy Kernel after I flash a new ROM. The Kernel has a zimage file. How do I incorporate it into the zip? Same for modem file.
Thanks in advance.
Click to expand...
Click to collapse
Whats worked for me:
First get 7zip if you are on windows
Open the kernel zip with 7zip move the redbend_ua and zImage into this location (rom name here).zip/updates
For modem do the same, open up the modem zip with 7zip, and then move the modim.bin into (rom name here).zip/update
You may need to delete the redbend and zImage already in the rom, but just overwriting it with the new ones should work
Once the new kernel/modem is copied over, just put it on your sdcard and you should be able to flash it without any problems
Sent from my SAMSUNG-SGH-I997 using XDA
or just the zimage...since the ua is same...
Never tried it without doing the ua when it came to the kernel, but it does make sense since i never moved the ua when ever id move the modem
Sent from my SAMSUNG-SGH-I997 using XDA
The ua is universal on all roms... its just an installer for the modem and kernel ... no need to change it. If the rom already has it then just replace the zimage and your good.
Sent from my SAMSUNG-SGH-I997 using xda premium
I request some experienced sr. member to comeup by posting new thread covering some of topics like safely adding and removing apks, libs. Fonts, apps, wallpapers, kernel. Modem etc. in Rom's zip with little flavouring. It will help new member to start some development work.
Thanks guys ... 1 more small step
hey can anyone give instructions on fixing RIL bug...it would be so much helpful...thnx

[MOD] Disable system write protection on stock kernel

This module will disable system write protection on the stock HTC One kernel.
To make /system writeable, you must install the module and then remount /system as rw.
For example:
insmod /system/lib/modules/wp_mod.ko
mount -o remount,rw /system
You can make an init.d script to load it, or add it to the boot.img. Either way will work, but it's important that this is loaded at boot, as attempting to make changes to /system and then installing this module could corrupt the partition.
This is mainly for devs, who are free to incorporate it into their ROMs.
Unless you are an advanced user, I would wait for it to be included in your favourite ROM.
A credit and a link here so people can thank me in the OP would be much appreciated
Download:
wp_mod.ko
Source code: wp_mod.c
Awesome mate... Thanks a lot
Thanks!
Quick question, do we need to install the module manually first before I create the init script?
wp_mod.ko for 3.4.10-gddcfb8c kernel version
wow ... new version from this mod ... thx :highfive:
ok ... installed wp_mod.ko to system/lib/modules ... make a new boot.img ... restart ... modified a file in system ... restart ... but changed file back original
ok ... next try ... i found the mod is kernel depends ... hexedit the mod to my kernel version ... installed ... modified a file ... restart ... and it works now, the file is well modified
thx @flar2
attached my modified wp_mod.ko only for 3.4.10-gddcfb8c kernel-version
use the attached with cwm-recovery, its only the modified wp_mod.ko file
The module should be placed somewhere on your /system partition, because that is what is mounted early in the boot process.
Kernel modules are usually located in /system/lib/modules/ but you can put it anywhere on /system
Then you can load it with an init script using the commands I posted above. Or you can put those commands in init.rc in the boot.img. Obviously the command has to be modified to reflect the location where you copied wp_mod.ko
You have to make sure that the boot.img is set to run init.d scripts, this is also done in init.rc.
Isotopes said:
wow ... new version from this mod ... thx :highfive:
ok ... installed wp_mod.ko to system/lib/modules ... make a new boot.img ... restart ... modified a file in system ... restart ... but changed file back original
ok ... next try ... i found the mod is kernel depends ... hexedit the mod to my kernel version ... installed ... modified a file ... restart ... and it works now, the file is well modified
Click to expand...
Click to collapse
Yes, it will only load if the version info matches.
If people don't know what that means, check your kernel:
uname -a
And make sure the module has the same string:
modinfo wp_mod.ko
You can change it with a hex editor as above, make sure you only change the characters of the version string and nothing else.
Good job mate
torxx said:
Good job mate
Click to expand...
Click to collapse
Really good job can you do the same file for the kernel? Thanks in advance
wp_mod.ko for 3.4.10-g87f8d97 kernel version
nikotine81 said:
Really good job can you do the same file for the kernel? Thanks in advance
Click to expand...
Click to collapse
and now, here the wp_mod.ko for 3.4.10-g87f8d97 kernel version
use the attached with cwm-recovery, its only the modified wp_mod.ko file
Isotopes said:
and now, here the wp_mod.ko for 3.4.10-g87f8d97 kernel version
use the attached with cwm-recovery, its only the modified wp_mod.ko file
Click to expand...
Click to collapse
Thanks i will test
Isotopes said:
and now, here the wp_mod.ko for 3.4.10-g87f8d97 kernel version
use the attached with cwm-recovery, its only the modified wp_mod.ko file
Click to expand...
Click to collapse
Works fine
Thanks
Nekromantik said:
Works fine
Thanks
Click to expand...
Click to collapse
fine is the wrong word, works perfect :good::good::good:
Hi! Just wanted to add additional info. Since the kernel source is out now you could also disable write protection by changing the line in
arch/arm/configs/m7_defconfig
Click to expand...
Click to collapse
from
CONFIG_MMC_MUST_PREVENT_WP_VIOLATION=y
Click to expand...
Click to collapse
to
# CONFIG_MMC_MUST_PREVENT_WP_VIOLATION is not set
Click to expand...
Click to collapse
referencing file
arch/arm/mach-msm/emmc_partitions.c
Click to expand...
Click to collapse
code
Code:
#ifdef CONFIG_MMC_MUST_PREVENT_WP_VIOLATION
if (!strncmp(ptn->name, "system", 6))
mmc_blk_set_wp_prevention_partno((int) ptn->offset);
#endif
on
Code:
void mmc_blk_set_wp_prevention_partno(int partno)
{
sprintf(wp_prevention_partno, "mmcblk0p%d", partno);
pr_info("%s: set wp_prevention_partno to %s\n", __func__, wp_prevention_partno);
}
EXPORT_SYMBOL(mmc_blk_set_wp_prevention_partno);
from
drivers/mmc/card/block.c
Click to expand...
Click to collapse
Works great thank you
Sent from my HTC One using xda app-developers app
Riyal said:
Hi! Just wanted to add additional info. Since the kernel source is out now you could also disable write protection by changing the line in
from
to
referencing file
code
Code:
#ifdef CONFIG_MMC_MUST_PREVENT_WP_VIOLATION
if (!strncmp(ptn->name, "system", 6))
mmc_blk_set_wp_prevention_partno((int) ptn->offset);
#endif
on
Code:
void mmc_blk_set_wp_prevention_partno(int partno)
{
sprintf(wp_prevention_partno, "mmcblk0p%d", partno);
pr_info("%s: set wp_prevention_partno to %s\n", __func__, wp_prevention_partno);
}
EXPORT_SYMBOL(mmc_blk_set_wp_prevention_partno);
from
Click to expand...
Click to collapse
Thank you, I discovered this months ago: http://forum.xda-developers.com/showthread.php?t=2059411. The reason for disabling it via a module is so people can continue to use the stock kernel. There are already custom kernels for this phone, but not everyone wants a custom kernel.
flar2 said:
Thank you, I discovered this months ago: http://forum.xda-developers.com/showthread.php?t=2059411. The reason for disabling it via a module is so people can continue to use the stock kernel. There are already custom kernels for this phone, but not everyone wants a custom kernel.
Click to expand...
Click to collapse
Only custom kernel is one from you at the moment.
Have to wait for more devs now.
The base version for the source code seems to be a older base, does that make a difference?
Nekromantik said:
Only custom kernel is one from you at the moment.
Have to wait for more devs now.
The base version for the source code seems to be a older base, does that make a difference?
Click to expand...
Click to collapse
It depends on what they changed.
I thought a couple custom kernels were posted in the trick droid thread?
flar2 said:
It depends on what they changed.
I thought a couple custom kernels were posted in the trick droid thread?
Click to expand...
Click to collapse
Only saw one other one but that did not work as it had issues with calls.
flar2 said:
Thank you, I discovered this months ago: http://forum.xda-developers.com/showthread.php?t=2059411. The reason for disabling it via a module is so people can continue to use the stock kernel. There are already custom kernels for this phone, but not everyone wants a custom kernel.
Click to expand...
Click to collapse
Nice! Never had a One X phone so wasn't aware of your mods :fingers-crossed:
If you're feeling adventurous here's a kernel to try:
http://goo.im/devs/flar2/One/Bulletproof-m7-0.1.zip
I don't have this device, so I couldn't test it. It might not work.
If the installer doesn't work, take the boot.img out of the zip and flash it in fastboot.
If the kernel won't boot, please send me /proc/last_kmsg. I might have to make some adjustments to the boot.img.
Don't install this unless you want to help me out with log files, etc.

Dual boot ICS as secondary

Hey guys , I've been trying to make a kernel for ICS to make it work as secondary on external partition but for some reason it doesn't work , I make it for cm10 or 10.1 it works fine but with ICS , it doesn't work.
Can someone make it so I can look into it and understand ?
Sent from my LG-P920 using xda premium
boltthrower56 said:
Hey guys , I've been trying to make a kernel for ICS to make it work as secondary on external partition but for some reason it doesn't work , I make it for cm10 or 10.1 it works fine but with ICS , it doesn't work.
Can someone make it so I can look into it and understand ?
Sent from my LG-P920 using xda premium
Click to expand...
Click to collapse
wen berni did not made that probably is not so easy.
btw... how did you extract the zImage form CM10 and CM10.1 boot.img file?
I tryed different tools but all end up with no zImage. How did you do that?
p-vlad said:
wen berni did not made that probably is not so easy.
btw... how did you extract the zImage form CM10 and CM10.1 boot.img file?
I tryed different tools but all end up with no zImage. How did you do that?
Click to expand...
Click to collapse
Follow Samno's GB Guide it works for CM10 boot.img
p-vlad said:
wen berni did not made that probably is not so easy.
btw... how did you extract the zImage form CM10 and CM10.1 boot.img file?
I tryed different tools but all end up with no zImage. How did you do that?
Click to expand...
Click to collapse
Probably not easy , yes.
I extracted the image using samno's guide , there is a bootimg.pl or something like that , it extracts and separates the boot.img into kernel and ramdisk. You need a linux distro for that by the way. I use Kubuntu.
I modified init.rc , the mtd partitions only system , data and cache... then the updater-script of course.
But no luck.
It packs okay , i extracted a boot.img and without any modifications i repacked it , then flashed it , works.
I did dual-boot from Cm10 as my secondary but i have class 4 card and it's very slow.
I don't use other functions too much to sacrifice that amount of performance since i use cm10 all the time.
I may have tried a hundred different things except for creating the whole partition table in my external.

Categories

Resources