This guide should hopefully allow you to unpack and re-pack the 2012 Xperia kernels, which use a new .elf format.
[ Requirements: ]
Sony's mkelf.py
Python (For mkelf.py)
7-zip
[ Unpack elf: ]
1. Unpack the .elf using 7-zip, either via the GUI or command line:
Code:
7z e kernel.elf
2. This will give you 3 files:
Code:
0 - Kernel
1 - RAMDisk
2 - Resource Power Manager (RPM, Xperia S only):
2. You will need to unpack the '1' file to get the RAMDisk (It will be named 1~):
Code:
7z e 1
3. Unpack the RAMDisk:
Code:
mkdir ramdisk
7z x "1~" -o"ramdisk"
Now make your changes to the RAMDisk
[ Pack elf: ]
1. Pack the new RAMDisk (The new RAMDisk will be named '1' in the ramdisk folder):
Code:
cd ramdisk
find . | cpio -o -H newc | gzip > 1
2. Copy the kernel '0', new RAMDisk '1' (in the ramdisk folder) and RPM '2' (Xpera S only) into a new folder, along with the mkelf.py file
3. Run the Python mkelf.py (note the different instructions for Xperia P and Xperia S):
Xperia P:
Kernel should be named 0
RAMDisk should be named 1
Code:
python mkelf.py -o new_kernel.elf [email protected] [email protected],ramdisk
Xperia S:
Kernel should be named 0
RAMDisk should be named 1
Resource Power Manager (RPM) should be named 2
Code:
python mkelf.py -o new_kernel.elf [email protected] [email protected],ramdisk [email protected],rpm
This should create a new packed file called newkernel.elf
[ Boot: ]
1. Flash the new kernel
Code:
fastboot -i 0x0fce flash boot new_kernel.elf
2. Reboot the phone
Code:
fastboot -i 0x0fce reboot
Hopefully should boot into your new kernel
Open to comments and suggestions for this tutorial
Disclaimer: I accept no responsibility if this destroys your device/house/life
Source: http://developer.sonymobile.com/wp/...-archive-released-with-building-instructions/
Source: http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images
Thanks: nickholtus, DooMLoRD
Guide looks really good
Just for the record: did anyone test this?
K900 said:
Just for the record: did anyone test this?
Click to expand...
Click to collapse
Yes Nickholtus did (On his Xperia P)
And on the S? Because from what I know the P doesn't have that bug.
Will this also work for the sola?
shreyasdilip said:
Will this also work for the sola?
Click to expand...
Click to collapse
It will need different addresses for the mkelf.py. If you link me to a Sola kernel, I can update the post with it
will this work for sola
What about sola
ffaaiissaall said:
What about sola
Click to expand...
Click to collapse
Don't mean to sound an arse but did you even read the thread? Check the question two posts up from you and the response to it just one below.
K900 said:
Just for the record: did anyone test this?
Click to expand...
Click to collapse
yes i have already done lots of testing on nick's Xperia P last week
And what if i have 4 files after unpacking the kernel.elf??
i have 0,1,2,3
How to deal with this case?
norberto_ said:
And what if i have 4 files after unpacking the kernel.elf??
i have 0,1,2,3
How to deal with this case?
Click to expand...
Click to collapse
what phone and what kernel ??
Regarding testing of things, I now have a spare Xperia S if anyone wants me to try things out without the risk of messing up my main phone.
check this out
http://forum.xda-developers.com/showthread.php?p=27859098#post27859098
championswimmer said:
check this out
http://forum.xda-developers.com/showthread.php?p=27859098#post27859098
Click to expand...
Click to collapse
makes sense
Atarii said:
This guide should hopefully allow you to unpack and re-pack the 2012 Xperia kernels, which use a new .elf format.
[ Requirements: ]
Sony's mkelf.py
Python (For mkelf.py)
7-zip
[ Unpack elf: ]
1. Unpack the .elf using 7-zip, either via the GUI or command line:
Code:
7z e kernel.elf
2. This will give you 3 files:
Code:
0 - Kernel
1 - RAMDisk
2 - Resource Power Manager (RPM, Xperia S only):
2. You will need to unpack the '1' file to get the RAMDisk (It will be named 1~):
Code:
7z e 1
3. Unpack the RAMDisk:
Code:
mkdir ramdisk
7z x "1~" -o"ramdisk"
Now make your changes to the RAMDisk
[ Pack elf: ]
1. Pack the new RAMDisk (The new RAMDisk will be named '1' in the ramdisk folder):
Code:
cd ramdisk
find . | cpio -o -H newc | gzip > 1
2. Copy the kernel '0', new RAMDisk '1' (in the ramdisk folder) and RPM '2' (Xpera S only) into a new folder, along with the mkelf.py file
3. Run the Python mkelf.py (note the different instructions for Xperia P and Xperia S):
Xperia P:
Kernel should be named 0
RAMDisk should be named 1
Code:
python mkelf.py -o new_kernel.elf [email protected] [email protected],ramdisk
Xperia S:
Kernel should be named 0
RAMDisk should be named 1
Resource Power Manager (RPM) should be named 2
Code:
python mkelf.py -o new_kernel.elf [email protected] [email protected],ramdisk [email protected],rpm
This should create a new packed file called newkernel.elf
[ Boot: ]
1. Flash the new kernel
Code:
fastboot -i 0x0fce flash boot new_kernel.elf
2. Reboot the phone
Code:
fastboot -i 0x0fce reboot
Hopefully should boot into your new kernel
Open to comments and suggestions for this tutorial
Disclaimer: I accept no responsibility if this destroys your device/house/life
Source: http://developer.sonymobile.com/wp/...-archive-released-with-building-instructions/
Source: http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images
Thanks: nickholtus, DooMLoRD
Click to expand...
Click to collapse
I just unpack & repack the kernel, but it isn't work
the screen just all black
nothing displays
wzhy said:
I just unpack & repack the kernel, but it isn't work
the screen just all black
nothing displays
Click to expand...
Click to collapse
I am using Xperia acro S. I had the same problem.
@wzhy, why don't you use the following command instead.
Code:
python mkelf.py -o new_kernel.elf [email protected] [email protected],ramdisk [email protected],rpm
for unpacking the ramdisk use the method on this page (few posts above)
otherwise you will get a black screen
Hi.
whats the correct setting for Xperia U for mkelf.py ?
Thx
Nice guide but ...
I have Xperia sola
4.0.4 rom build 6.1.1.B.1.54
kernel.sin has 3 files {
kernel.elf
kernel.patinfo
kernel.header
}
kernel.elf has 4 files! {
kernel.elf.3
kernel.elf.cert
kernel.elf.Image
kernel.elf.ramdisk.gz
}
In the ram disk there is a file name kernel.elf.ramdisk
and kernel.elf.ramdisk has the ramdisk files
So how can I repack THIS?!
thanks in advance for your answer
Related
Hello guys, I have a small problem,
I wanted to change logo in ramdisk (unlocked bootloader kernel), but after everything I got black screen after trying to boot device (vibra and then black screen)
There is list what I do, maybe someone will find mistake:
1. Unpacked ftf via 7zip -> got kernel.sin and loader.sin
2. Unpacked kernel.sin via unpack-kernelsin.pl
3. Unpacked ramdisk via 7-zip
4. Renamed unpacked ramdisk to ramdisk.cpio (moved to tmp dir)
5. cpio -i -F ramdisk.cpio (in tmp dir)
6. Replaced logo and moved ramdisk.cpio to ../
7. Executed command in tmp dir: cpio -i -t -F ../ramdisk.cpio | cpio -o -H newc -O ../ramdisk_new.cpio
8. Renamed folder with new ramdisk to ramdisk~
9. Packed it via 7zip (gz,Ultra)
10. Moved to sintools and renamed gz file to ramdisk
11. Moved kernel.sin-kerne (from unpacking kernel via unpack-kernelsin.pl), and renamed it to image
12. Executed example_build.cmd from sinTools
13. Moved to flashtool, maked bundle
14. Flashed
15. Black screen : /
If someone can help, I'll be glad
I have update.img from venor of my tablet. I would like to make a custom rom and later CyanogenMod. At this moment I need to extract boot.img form update.img
mkimage -l update.img displays:
mkimage: Bad Magic Number: "update.img" is no valid image
Image Type : Davinci UBL Boot Image
UBL magic : 57464b52
Entry Point: 00010066
nr of pages: 00000401
start block: 07dd0105
start page : 290e1201
Any idea?
You can download update.img from:
https://mega.co.nz/#!XFExEDBL!OkPfQwWDp0JDzRHIg4TZQk6lt3EwEJiDfR2IyOE6p_4
mafamafa said:
I have update.img from venor of my tablet. I would like to make a custom rom and later CyanogenMod. At this moment I need to extract boot.img form update.img
mkimage -l update.img displays:
mkimage: Bad Magic Number: "update.img" is no valid image
Image Type : Davinci UBL Boot Image
UBL magic : 57464b52
Entry Point: 00010066
nr of pages: 00000401
start block: 07dd0105
start page : 290e1201
Any idea?
You can download update.img from:
https://mega.co.nz/#!XFExEDBL!OkPfQwWDp0JDzRHIg4TZQk6lt3EwEJiDfR2IyOE6p_4
Click to expand...
Click to collapse
try using ext2explore...
ext2explore didn’t show anything
mr.harsh said:
try using ext2explore...
Click to expand...
Click to collapse
Unfortunately ext2explore didn’t show anything. Any idea? Maybe somebody download the file I posted I mega.co.nz and check it?
unmkbootimg doing the job for you
mafamafa said:
Unfortunately ext2explore didn’t show anything. Any idea? Maybe somebody download the file I posted I mega.co.nz and check it?
Click to expand...
Click to collapse
There is programm called unmkbootimg. type:
unmkbootimg boot.img
will create zImage and initramfs.cpio.gz files in current directory. scripts/extract-ikconfig will give you config from kernel.
kaptorali said:
There is programm called unmkbootimg. type:
unmkbootimg boot.img
will create zImage and initramfs.cpio.gz files in current directory. scripts/extract-ikconfig will give you config from kernel.
Click to expand...
Click to collapse
Shoud I run it on my Tablet? Shoud I install something on my tablet?
mafamafa said:
Shoud I run it on my Tablet? Shoud I install something on my tablet?
Click to expand...
Click to collapse
If you have unpacked ROM and got yourromfolder/RFSFAT16_BOOT_00000000000 then all you need
>unmkbootimg yourromfolder/RFSFAT16_BOOT_00000000000
To get boot.img from tablet: install Term(terminal) (to tablet), run terminal, type:
>su
>busybox dd if=/dev/block/nandc of=/mnt/sdcard/boot.img
Copy boot.img from /mnt/sdcard/ (or other directory) to "extsd", insert to PC and run unmkbootimg
From adb shell (linux style):
>./adb start-server
In tablet turn on "usb adb debugging". Plug tablet to PC with usb. Run:
>./adb shell busybox dd if=/dev/block/nandc of=/mnt/sdcard/boot.img
>./adb pull /mnt/sdcard/boot.img boot.img
Run unmkbootimg.
mkimage -l update.img gives you header (first 64bites) of your boot.img - all right.
Also unmkbootimg type output for building (packing) new_boot.img!
mafamafa said:
Any idea?
Click to expand...
Click to collapse
$ dd if=update.img skip=1 bs=13155412 of=boot.img
I've updated unmkbootimg so it handles embedded boot images now. Download it and run it directly on your update.img
$ unmkbootimg update.img
unmkbootimg version 1.2 - Mikael Q Kuisma <[email protected]>
File update.img not a plain boot image, seeking for embedded image ... found!
Kernel size 8073252
Kernel address 0x60408000
Ramdisk size 6380372
Ramdisk address 0x62000000
Secondary size 0
Secondary address 0x60f00000
Kernel tags address 0x60088000
Flash page size 16384
Board name is ""
Command line ""
*** WARNING ****
This image is built using NON-standard mkbootimg!
OFF_KERNEL_ADDR is 0x00380100
OFF_RAMDISK_ADDR is 0x01F78100
OFF_SECOND_ADDR is 0x00E78100
Please modify mkbootimg.c using the above values to build your image.
****************
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 --base 0x60087f00 --pagesize 16384 -o new_boot.img
---------------
$ ls
initramfs.cpio.gz update.img zImage
$
Click to expand...
Click to collapse
This tutorial is used only for communication problems, I am not responsible for.
You need a cygwin environment, how to install please google.
Download the attached bin.zip file, unzip, under the cygwin/bin.
Download the attachment mkelf.zip,
The 32 systems need to download, install the 32 bit python.msi, extracted from python.exe into cygwin/bin.
1.Create a kernel folder in the user folder.
2.The kernel.elf and mkelf.py in the kernel folder.
3.Open a terminal
4.cd kernel
5.7z e kernel.elf
GB will have two files
JB will get three files
6.mkdir ramdisk
7.cd ramdisk
8.gunzip -c ../1 | cpio -i
Modify.
If you want to modify the logo.rle
Chmod 0644 logo.rle
If you want to modify the recovery, recovery and res/image.
Chmod 0750 recovery
Well, modified.
Pack
9.find . | cpio -o -H newc | gzip > 1
Copy to upper directory
10.
GB: python mkelf.py -o kernel.elf [email protected] [email protected],ramdisk
JB: python mkelf.py -o new_kernel.elf [email protected] [email protected],ramdisk [email protected],rpm
kernel
++++++
kosmos-2011 said:
++++++
Click to expand...
Click to collapse
Are you spamming or what?? Why do you post "+" everywhere??
Inviato dal mio ST25i con Tapatalk 4
Probably a reserved post :laugh:
I consider myself lucky to find this thread! I am porting a rom and have this big problem of repacking it since,2 days!
Thanks for this thread!. I will try it out within a day or two.
Sent from my XPERIA sola using xda app-developers app!
Please help me! i tried it out but I got a problem in the last step:
(In CMD)
D:\Android Kitchen\Cygwin\cygwin_packages\packages\bin>python mkelf.py -o new_kernel.elf [email protected] [email protected],[email protected],rpm
Traceback (most recent call last):
File "mkelf.py", line 158, in <module>
main(sys.argv[1:])
File "mkelf.py", line 143, in main
write_elf_header(elf, segments[0]['addr'], len(segments))
File "mkelf.py", line 68, in write_elf_header
'e_entry': long(entry, 16),
NameError: global name 'long' is not defined
D:\Android Kitchen\Cygwin\cygwin_packages\packages\bin>
Click to expand...
Click to collapse
Thanks i will test it.
A boot.img is a kernel.elf rename no?
Enviado desde mi Xperia U usando Tapatalk 2
I'm tired of asking the same question again and again but for the thousandth and the last time I'll try my best to explain y'all the jeopardy I'm in.
I'm trying to build cm-10.2 from source for Sony Xperia E (nanhu) and everything started off just fine until I had to generate the skeleton files. I decided to use the mkvendor.sh to generate em. I have no clue why, but Sony seems to be in love with .elf files. And the best part, mkvendor only works with a standard boot.img file. Since I found mkvendor.sh the only convincing option, I decided to not use the other 2 options given here.
I extracted the kernel.sin from the ftf package of the kernel I downloaded, used flashtool to in turn extract kernel.sin which produced kernel.elf. I tried two things:
1) Unpack kernel.elf (flashtool elf extractor) and then pack em into a boot.img file (Failed as I couldn't pack em because I didn;t know how to use mkbootimg)
2) Rename kernel.elf to boot.img. as suggested by a developer of CM11 for Xperia E (Worked and was also accepted by mkvendor.sh)
I used mkvendor and it said that i don't have unpackbootimg binaries. I tried to make them by using:
make -j4 out/host/linux-x86/bin/unpackbootimg
Sadly I didn't know how to proceed so I got the binary from here and copied it to /usr/bin/ and made executable using:
sudo chmod a+x /usr/bin/unpackbootimg
Rebooted and it worked but you will see below that it isn't fixed 100% but it just works. I moved on and decided to use the script again on the renamed kernel.elf file(i.e. boot.img)
This is the following error I encounter while using mkvendor:
[email protected]:~/tools/FlashTool$ cd ~/source/cm/branch/cm-10.2
[email protected]:~/source/cm/branch/cm-10.2$ ./build/tools/device/mkvendor.sh sony nanhu ~/Desktop/boot.img
Arguments: sony nanhu /home/carbogen-chemist/Desktop/boot.img
Output will be in /home/carbogen-chemist/source/cm/branch/cm-10.2/device/sony/nanhu
*** Error in `unpackbootimg': free(): invalid next size (fast): 0x09793170 ***
./build/tools/device/mkvendor.sh: line 84: 3943 Aborted (core dumped) unpackbootimg -i $BOOTIMAGEFILE > /dev/null
gzip: ../boot.img-ramdisk.gz: No such file or directory
cpio: premature end of archive
cp: cannot stat ‘/tmp/carbogen-chemist/bootimg/boot.img-zImage’: No such file or directory
Creating initial git repository.
~/source/cm/branch/cm-10.2/device/sony/nanhu ~/source/cm/branch/cm-10.2
Initialized empty Git repository in /home/carbogen-chemist/source/cm/branch/cm-10.2/device/sony/nanhu/.git/
[master (root-commit) d49b660] mkvendor.sh: Initial commit of nanhu
7 files changed, 95 insertions(+)
create mode 100644 AndroidBoard.mk
create mode 100644 AndroidProducts.mk
create mode 100644 BoardConfig.mk
create mode 100644 cm.mk
create mode 100644 device_nanhu.mk
create mode 100644 recovery.fstab
create mode 100644 system.prop
~/source/cm/branch/cm-10.2
Done!
Use the following command to set up your build environment:
lunch cm_nanhu-eng
And use the follwowing command to build a recovery:
. build/tools/device/makerecoveries.sh cm_nanhu-eng
Since the script seems to look up for boot.img-ramdisk.gz and boot.img-zImage, I decided to investigate a bit further. I renamed boot.img to kernel.elf and used flashtool elf extractor to unzip kernel.elf. I obtained four files as a result of the extraction:
1) kernel.elf.bootcmd
2) kernel.elf.cert
3) kernel.elf.Image
4) kernel.elf.ramdisk.gz
Since mkvendor needed boot.img-ramdisk.gz and boot.img-zImage, I renamed all the files:
1) kernel.elf.bootcmd >> kernel.img-bootcmd
2) kernel.elf.cert >> kernel.img-cert
3) kernel.elf.Image >> kernel.img-zImage
4) kernel.elf.ramdisk.gz >> kernel.img-ramdisk.gz
Now I repackaged them using mkelf.py script. Since I couldn't find any command specific to nanhu, I edited it to fit for the device:
python mkelf.py -o edited.elf [email protected] [email protected],ramdisk [email protected],cmdline
This command throws no error and produces edited.elf. All of the files are packed in except kernel.img-cert as I didn't know the arguments for it ([email protected]?x????????,cert). I rename the edited.elf to boot2.img.
But I get the same error as the one I get when I use the unedited kernel (boot.img)
What should I do to get out of this format abyss? Would I have better luck with mkbootimg? If so, could you point me out to a thread or tell me here itself how to use it?
Thank you all!
TheUltimateNoobist said:
I used mkvendor and it said that i don't have unpackbootimg binaries. I tried to make them by using:
make -j4 out/host/linux-x86/bin/unpackbootimg
Sadly I didn't know how to proceed so I got the binary from here and copied it to /usr/bin/ and made executable using:
sudo chmod a+x /usr/bin/unpackbootimg
Rebooted and it worked but you will see below that it isn't fixed 100% but it just works. I moved on and decided to use the script again on the renamed kernel.elf file(i.e. boot.img)
Click to expand...
Click to collapse
Fixed it myself. How did I miss that note at cyanogenmod porting?
Cd'ed to my working directory. Ran :
sudo make -j4 otatools
and grabbed unpackbootimg from WORKING_DIR/out/host/linux-x86/bin/unpackbootimg and pasted to /usr/bin
Made it executable by running:
sudo chmod a+x /usr/bin/unpackbootimg
Reboot!
It would also be very helpful if anyone could point out what the correct config for Xperia E is. (For EG >> blue_mint_defconfig is for Xperia T, semc_zeus_defconfig is for Xperia Play)
There is a file called README_Xperia, which contains the configuration names for the different phones in the kernel source can be used for. But my source doesn't contain it. So I would be very grateful if someone pointed it out!
Thank you!
TheUltimateNoobist said:
I'm tired of asking the same question again and again but for the thousandth and the last time I'll try my best to explain y'all the jeopardy I'm in.
I'm trying to build cm-10.2 from source for Sony Xperia E (nanhu) and everything started off just fine until I had to generate the skeleton files. I decided to use the mkvendor.sh to generate em. I have no clue why, but Sony seems to be in love with .elf files. And the best part, mkvendor only works with a standard boot.img file. Since I found mkvendor.sh the only convincing option, I decided to not use the other 2 options given here.
I extracted the kernel.sin from the ftf package of the kernel I downloaded, used flashtool to in turn extract kernel.sin which produced kernel.elf. I tried two things:
1) Unpack kernel.elf (flashtool elf extractor) and then pack em into a boot.img file (Failed as I couldn't pack em because I didn;t know how to use mkbootimg)
2) Rename kernel.elf to boot.img. as suggested by a developer of CM11 for Xperia E (Worked and was also accepted by mkvendor.sh)
I used mkvendor and it said that i don't have unpackbootimg binaries. I tried to make them by using:
make -j4 out/host/linux-x86/bin/unpackbootimg
Sadly I didn't know how to proceed so I got the binary from here and copied it to /usr/bin/ and made executable using:
sudo chmod a+x /usr/bin/unpackbootimg
Rebooted and it worked but you will see below that it isn't fixed 100% but it just works. I moved on and decided to use the script again on the renamed kernel.elf file(i.e. boot.img)
This is the following error I encounter while using mkvendor:
[email protected]:~/tools/FlashTool$ cd ~/source/cm/branch/cm-10.2
[email protected]:~/source/cm/branch/cm-10.2$ ./build/tools/device/mkvendor.sh sony nanhu ~/Desktop/boot.img
Arguments: sony nanhu /home/carbogen-chemist/Desktop/boot.img
Output will be in /home/carbogen-chemist/source/cm/branch/cm-10.2/device/sony/nanhu
*** Error in `unpackbootimg': free(): invalid next size (fast): 0x09793170 ***
./build/tools/device/mkvendor.sh: line 84: 3943 Aborted (core dumped) unpackbootimg -i $BOOTIMAGEFILE > /dev/null
gzip: ../boot.img-ramdisk.gz: No such file or directory
cpio: premature end of archive
cp: cannot stat ‘/tmp/carbogen-chemist/bootimg/boot.img-zImage’: No such file or directory
Creating initial git repository.
~/source/cm/branch/cm-10.2/device/sony/nanhu ~/source/cm/branch/cm-10.2
Initialized empty Git repository in /home/carbogen-chemist/source/cm/branch/cm-10.2/device/sony/nanhu/.git/
[master (root-commit) d49b660] mkvendor.sh: Initial commit of nanhu
7 files changed, 95 insertions(+)
create mode 100644 AndroidBoard.mk
create mode 100644 AndroidProducts.mk
create mode 100644 BoardConfig.mk
create mode 100644 cm.mk
create mode 100644 device_nanhu.mk
create mode 100644 recovery.fstab
create mode 100644 system.prop
~/source/cm/branch/cm-10.2
Done!
Use the following command to set up your build environment:
lunch cm_nanhu-eng
And use the follwowing command to build a recovery:
. build/tools/device/makerecoveries.sh cm_nanhu-eng
Since the script seems to look up for boot.img-ramdisk.gz and boot.img-zImage, I decided to investigate a bit further. I renamed boot.img to kernel.elf and used flashtool elf extractor to unzip kernel.elf. I obtained four files as a result of the extraction:
1) kernel.elf.bootcmd
2) kernel.elf.cert
3) kernel.elf.Image
4) kernel.elf.ramdisk.gz
Since mkvendor needed boot.img-ramdisk.gz and boot.img-zImage, I renamed all the files:
1) kernel.elf.bootcmd >> kernel.img-bootcmd
2) kernel.elf.cert >> kernel.img-cert
3) kernel.elf.Image >> kernel.img-zImage
4) kernel.elf.ramdisk.gz >> kernel.img-ramdisk.gz
Now I repackaged them using mkelf.py script. Since I couldn't find any command specific to nanhu, I edited it to fit for the device:
python mkelf.py -o edited.elf [email protected] [email protected],ramdisk [email protected],cmdline
This command throws no error and produces edited.elf. All of the files are packed in except kernel.img-cert as I didn't know the arguments for it ([email protected]?x????????,cert). I rename the edited.elf to boot2.img.
But I get the same error as the one I get when I use the unedited kernel (boot.img)
What should I do to get out of this format abyss? Would I have better luck with mkbootimg? If so, could you point me out to a thread or tell me here itself how to use it?
Thank you all!
Click to expand...
Click to collapse
Nevermind :/ Fixed it myself.
Repacked the edited files using mkbootimg.
mkbootimg --kernel kernel.img-zImage --ramdisk kernel.img-ramdisk.gz --cmdline kernel.img-bootcmd -o boot.img
Hi everyone, I didn't find a full guide for unpacking & repacking new kernel.elf, they were somehow out-dated.
so I'm here to share with you my knowledge.
First Post : Unpack kernel
Second Post : Unpack ramdisk
Third Post : Repack ramdisk
Fourth Post : Repack kernel
1st : Requirements
1) the kernel you want to unpack
2) 7z -->
Code:
sudo apt-get install p7zip
2nd : procedure
lets assume our working directory is "~/kernel" and the kernels name is "kernel.elf".
now open terminal and write down the following code.
Code:
mkdir ~/kernel
cp /path/to/file ~/kernel/kernel.elf
cd ~/kernel
7z e kernel.elf
now you will get 0, 1, 2, 3.
0 --> zImage
1 --> ramdisk
2 --> cmdline
3 --> cert
Code:
mv 0 kernel.elf-zImage
mv 1 kernel.elf-ramdisk.gz
mv 2 kernel.elf-cmdline
mv 3 kernel.elf-cert
now you have successfully unpacked the kernel.
[B]Second Post : Unpack ramdisk[/B]
1st : Requirements
1) the ramdisk we got from the first post.
2) file -->
Code:
sudo apt-get install file
3) most probably gzip -->
Code:
sudo apt-get install gzip
2nd : procedure
Code:
file -b kernel.elf-ramdisk.gz
most probably you will get "gzip compressed data".
if not read the notes at the end of this post then resume reading.
Code:
gzip -dk kernel.elf-ramdisk.gz
now you will get cpio archive "kernel.elf-ramdisk".
Code:
mkdir ramdisk
mv kernel.elf-ramdisk ramdisk
cd ramdisk
cpio -i < kernel.elf-ramdisk
rm kernel.elf-ramdisk
cd ..
now you successfully extracted the ramdisk.
3rd : notes
it seems your ramdisk isn't gzip compressed.
if you got "LZMA compressed data" from file command
then it is "lzma" compressed
lzma -->
Code:
sudo apt-get install xz-utils
to uncompress use
Code:
mv kernel.elf-ramdisk.gz kernel.elf-ramdisk.lzma
xz -dk kernel.elf-ramdisk.lzma
now you chould resume unpacking process.
Third Post : repack ramdisk
1st : Requirements
1) the ramdisk folder we extracted from second post.
2) cpio
3) the tool we used for unpacking ramdisk (gzip) (check notes for other compression types)
2nd : procedure
Code:
cd ramdisk
find|cpio -o -H newc|gzip >../kernel.elf-new_ramdisk.gz
cd ..
now you successfully repacked the ramdisk.
3rd : notes
well it is recommended to repack the ramdisk with the original ramdisk format
because other formats maybe not supported
but no problem trying other formats as long as they are supported
for lzma :
Code:
cd ramdisk
find|cpio -o -H newc|xz --format=lzma >../kernel.elf-new_ramdisk.lzma
cd ..
Fourth Post : repack kernel
1st : Requirements
1) the files we unpacked from the kernel from first post (zImage, cmdline, we won't be needing the extracted cert).
2) the ramdisk folder we repacked from third post.
3) the original kernel.elf for injecting cert.
4) mkelf.py Sony's or Doomlord's
github.com/sonyxperiadev/device-sony-lt26/blob/master/tools/mkelf.py
github.com/DooMLoRD/build_tools/blob/master/bin/mkelf.py
2nd : procedure
now we gonna repack kernel.elf (without cert yet).
Code:
mkelf.py -o kernel.elf-new [email protected] [email protected],ramdisk [email protected]
now comes the tricky part.
Code:
printf "\x04"|dd of=kernel.elf-new bs=1 seek=44 count=1 conv=notrunc 2>/dev/null
dd if=kernel.elf of=kernel.elf-dumped_cert bs=1 skip=148 count=1106 2>/dev/null
cat kernel.elf-dumped_cert|dd of=kernel.elf-new bs=1 seek=148 count=1106 conv=notrunc 2>/dev/null
rm kernel.elf-dumped_cert
now you successfully repacked the kernel .
Hi, would this method work on the Xperia GO? Would I have to change the command line arguments in order for it to work for my Xperia GO?
Hukanawa said:
Hi, would this method work on the Xperia GO? Would I have to change the command line arguments in order for it to work for my Xperia GO?
Click to expand...
Click to collapse
It would be great if you linked me to the kernel you want to unpack/repack.
Should work for Xperia GO
I grabbed the kernel "in CM11 weekly 20 for Xperia GO by XperiaSTE Team", and found the kernel structure is similar to Xperia P/U.
So yeah this guide should work for Xperia GO.
I hope this was helpful.
Very nice and helpful guide.
Worked for ARM64 kernel.elf also.