[UB]Xperia Z1 kexec patch v1 [18/01/14]

Search This thread

krabappel2548

Inactive Recognized Developer
Nov 15, 2011
6,444
16,111
Lommel
== Warning!! ==
This is at your own risk and only for unlocked bootloaders, don't try this on a locked bootloader device!!
I'm not responsible for damage to your device!

== Info ==
In this post, I would like to explain what kexec-hardboot patch is.

@kernel developers: Feel free to add my patch into your kernels, the patch can be found on my github: Kexec commits. You can just cherry-pick the commits, but I'll update my kernel repo with a new branch so the patch will be only 1 commit.​

== What is kexec? ==
It is syscall of Linux kernel, which allows you to boot another Linux kernel without restarting the device - "Linux boots itself". The functionality is equivalent to fastboot -c *cmdline* boot zImage initrd.img, but without PC and fastboot. It is fairly known thing, so more info at wikipedia and man kexec.
Standard kexec call unfortunatelly does not work on Nexus 4. It freezes somewhere, and it is very difficult to find out where - probably some of the drivers are not shut down/re-initialized properly, it is a commong thing among Android devices, which is why kexec-hardboot was made.​

== What is the difference between normal and hardboot exec? ==
Kexec-hardboot patch adds a real device restart to that process, so that all the drivers can be properly reinitialized. It stores new kernel to RAM, reboots the device as usual, and kernel from boot partition immediately jumps to the one which was stored to RAM before reboot.
Unlike grouper's kexec-hardboot patch, this one only requires the host kernel to be patched. This is one of the improvements I made, and I think it is pretty significant.
To sumarize the process:
  1. kexec --load-hardboot.... is called and kernel it loaded into RAM.
  2. kexec -e is called. Special info is written to memory (to area which is not overwritten on reboot) and the device is rebooted.
  3. After reboot, very early in the boot process, kernel checks if that special info is present in RAM and if so, it loads new kernel from RAM and jumps to it.
  4. Kexecd' kernel starts and boots.
For more info, read the original thread.​

== Instructions: ==
1) Download all required files:
- The host kernel
- the kexec binary
- Kexec script
- kernel files you want to kexec-hardboot

2) Then you need to fastboot flash the host kernel:
Code:
fastboot flash boot stock-290-TWRP-kexec.img

3) Put kexec binary, kexec.sh, initrd.img and zImage-dtb inside cache

4) Fire up adb and insert the following commands:
Code:
adb shell
su
cd cache
chmod 0755 kexec
sh ./kexec.sh

== Downloads: ==
- Host kernel 4.3 290 with TWRP: Sony 290 kexec host kernel
- kexec binary: kexec binary
- CM kernel to hardboot as test: cm test files
- kexec script: kexec script

== Authors: ==
This patch was made by Mike Kasick for Samsung Epic 4G. Since that, it was ported to several devices, one of them is Asus Transformer TF201 - I used patch from TF201 and modified it a bit (basically just changed few SoC specific constants). People at #ubuntu-arm helped me out with that, thanks.
For hammerhead, Tassadar improved the patch a bit - only the host needs to be patched now and Tassadar added support for DTB.
Last but not least for Xperia Z1 and Z Ultra I ported the patch to our sony 4.3 kernel sources. But most work was done by the awesome other devs :)

XDA:DevDB Information
[UB]Xperia Z1, ZU kexec patch v1 [18/01/14], a Tool/Utility for the Sony Xperia Z1

Contributors
krabappel2548

Version Information
Status: Testing
Current Stable Version: V1 and future versio
Stable Release Date: 2014-01-18

Created 2014-01-18
Last Updated 2014-01-18
 
Last edited:

krabappel2548

Inactive Recognized Developer
Nov 15, 2011
6,444
16,111
Lommel
Purpose of this kexec patch?
Now I have this working, I'm going to work on a multiboot solution for people with unlocked bootloaders.

Other kernel developers
I have my sources on github. If you wanna make a host kernel with kexec patch, feel free to use my patches on github:
https://github.com/Krabappel2548/android_kernel_sony_msm8974-kexec/commits/master

trying another kernel then cm to kexec boot:
When you compile the kernel don't take the zIamge, but the zImage-dtb from arch/arm/boot.
kexec needs the zImage with dtb appended to it. This is just the way it works.

Also don't forget to take the right ramdisk for the kernel and call it initrd.img.
 
Last edited:

B1nny

XDA Portal Team / Retired Forum Moderator
May 18, 2008
1,131
850
Awesome work man! Also glad to see another thread of yours on XDA. :) Keep the good work up!
 

krabappel2548

Inactive Recognized Developer
Nov 15, 2011
6,444
16,111
Lommel
Thx, did anyone tried it? I'd like to have confirmation it works, then I can make multiboot :)

Sent from my C6903 using xda app-developers app
 

DooMLoRD

Inactive Recognized Developer
Jul 27, 2010
13,187
39,710
Pune
@krabappel2548

tested the cm-test kernel!

working well :)

kernel boots


now testing if it can boot my kernel for stock rom

tested my kernel... boots but takes a VERY long time for the initial boot-up (bootlogo)...

but its great work!
 
Last edited:

DooMLoRD

Inactive Recognized Developer
Jul 27, 2010
13,187
39,710
Pune

it will multiboot tomorrow (today), if i get time ;)



ok so I had implemented something similar about 3 years back on the Xperia X10 (phew its been that long ;) )

Boot Manager for Xperia X10

doom-bootmenu-1.2-1.jpg


I can create a similar interface for the Z1 and other devices...

my idea is to make this "base kernel" into a bootloader from which we can select the kernel we want to boot by default and also have ability to select a different kernel to boot into...
 
Last edited:

Destroyedbeauty

Senior Member
Apr 16, 2012
2,299
712
31
Sundsvall
Yes it's possible, but first I'll make it for Z1 ;)

Sent from my C6903 using xda app-developers app

I am wondering one thing, that was achieved on the X10 back in 2010 (2011?) by master developer @goroh_kun, if it is possible on the Z1 and additional Xperia 2012 / 2013 / future 2014 devices.. Check down below!

No one here that has thought about getting around the bootloader and bypass the security check on locked bootloaders, so custom kernels can be booted w/o any hassles on LB?

Just something that crossed my mind..
 
Last edited:

Rekoil

Senior Member
May 17, 2008
1,143
497
Göteborg
www.idroidproject.org
I am wondering one thing, that was achieved on the X10 back in 2010 (2011?) by master developer @goroh_kun, if it is possible on the Z1 and additional Xperia 2012 / 2013 / future 2014 devices.. Check down below!

No one here that has thought about getting around the bootloader and bypass the security check on locked bootloaders, so custom kernels can be booted w/o any hassles on LB?

Just something that crossed my mind..

With root it is theoretically possible to patch a live kernel to allow kexecing another kernel, but this is tricky stuff and certainly not something I can figure out. There is hope for you, just not very much. May I humbly suggest you (and/or everyone else applicable) do some market research in the future and buy from a place where you get an unlockable bootloader?
 

Destroyedbeauty

Senior Member
Apr 16, 2012
2,299
712
31
Sundsvall
With root it is theoretically possible to patch a live kernel to allow kexecing another kernel, but this is tricky stuff and certainly not something I can figure out. There is hope for you, just not very much. May I humbly suggest you (and/or everyone else applicable) do some market research in the future and buy from a place where you get an unlockable bootloader?

My bootloader is already unlocked and loaded with Doomkernel, so this is not a problem for me..

Rather, I am speaking towards those people that is on fully BL-locked phones and that only can root their phones (and not more than so) if it's any hope for them to get custom kernels working on LB by cracking / hacking / bypassing the bootloader signature key check and make those kernels bootable?

Like achieved on the X10.. Wasn't KEXEC used back here also?

Sent from my C6903 using XDA Premium 4 mobile app
 

Rekoil

Senior Member
May 17, 2008
1,143
497
Göteborg
www.idroidproject.org
My bootloader is already unlocked and loaded with Doomkernel, so this is not a problem for me..

Rather, I am speaking towards those people that is on fully BL-locked phones and that only can root their phones (and not more than so) if it's any hope for them to get custom kernels working on LB by cracking / hacking / bypassing the bootloader signature key check and make those kernels bootable?

Like achieved on the X10.. Wasn't KEXEC used back here also?

Sent from my C6903 using XDA Premium 4 mobile app

It was... but from my understanding the signed kernel on the X10 allowed kernel modules to be loaded post-boot, as far as I know the stock kernel on the Z1 doesn't allow this, making it much harder to achieve kexec functionality on a locked bootloader.
 

Destroyedbeauty

Senior Member
Apr 16, 2012
2,299
712
31
Sundsvall
It was... but from my understanding the signed kernel on the X10 allowed kernel modules to be loaded post-boot, as far as I know the stock kernel on the Z1 doesn't allow this, making it much harder to achieve kexec functionality on a locked bootloader.

Nothing is impossible with the proper support and patience.

Sent from my C6903 using XDA Premium 4 mobile app
 

Rekoil

Senior Member
May 17, 2008
1,143
497
Göteborg
www.idroidproject.org
Nothing is impossible with the proper support and patience.

Sent from my C6903 using XDA Premium 4 mobile app

You are right of course, but still bloody difficult and at the same time not something that is strictly necessary since the option exists to get a device with an unlockable bootloader (unlike back on the Xperia X10 where all devices were locked). I wouldn't hold my breath.

Sent from my Xperia Z1 using Tapatalk
 

Top Liked Posts

  • There are no posts matching your filters.
  • 16
    == Warning!! ==
    This is at your own risk and only for unlocked bootloaders, don't try this on a locked bootloader device!!
    I'm not responsible for damage to your device!

    == Info ==
    In this post, I would like to explain what kexec-hardboot patch is.

    @kernel developers: Feel free to add my patch into your kernels, the patch can be found on my github: Kexec commits. You can just cherry-pick the commits, but I'll update my kernel repo with a new branch so the patch will be only 1 commit.​

    == What is kexec? ==
    It is syscall of Linux kernel, which allows you to boot another Linux kernel without restarting the device - "Linux boots itself". The functionality is equivalent to fastboot -c *cmdline* boot zImage initrd.img, but without PC and fastboot. It is fairly known thing, so more info at wikipedia and man kexec.
    Standard kexec call unfortunatelly does not work on Nexus 4. It freezes somewhere, and it is very difficult to find out where - probably some of the drivers are not shut down/re-initialized properly, it is a commong thing among Android devices, which is why kexec-hardboot was made.​

    == What is the difference between normal and hardboot exec? ==
    Kexec-hardboot patch adds a real device restart to that process, so that all the drivers can be properly reinitialized. It stores new kernel to RAM, reboots the device as usual, and kernel from boot partition immediately jumps to the one which was stored to RAM before reboot.
    Unlike grouper's kexec-hardboot patch, this one only requires the host kernel to be patched. This is one of the improvements I made, and I think it is pretty significant.
    To sumarize the process:
    1. kexec --load-hardboot.... is called and kernel it loaded into RAM.
    2. kexec -e is called. Special info is written to memory (to area which is not overwritten on reboot) and the device is rebooted.
    3. After reboot, very early in the boot process, kernel checks if that special info is present in RAM and if so, it loads new kernel from RAM and jumps to it.
    4. Kexecd' kernel starts and boots.
    For more info, read the original thread.​

    == Instructions: ==
    1) Download all required files:
    - The host kernel
    - the kexec binary
    - Kexec script
    - kernel files you want to kexec-hardboot

    2) Then you need to fastboot flash the host kernel:
    Code:
    fastboot flash boot stock-290-TWRP-kexec.img

    3) Put kexec binary, kexec.sh, initrd.img and zImage-dtb inside cache

    4) Fire up adb and insert the following commands:
    Code:
    adb shell
    su
    cd cache
    chmod 0755 kexec
    sh ./kexec.sh

    == Downloads: ==
    - Host kernel 4.3 290 with TWRP: Sony 290 kexec host kernel
    - kexec binary: kexec binary
    - CM kernel to hardboot as test: cm test files
    - kexec script: kexec script

    == Authors: ==
    This patch was made by Mike Kasick for Samsung Epic 4G. Since that, it was ported to several devices, one of them is Asus Transformer TF201 - I used patch from TF201 and modified it a bit (basically just changed few SoC specific constants). People at #ubuntu-arm helped me out with that, thanks.
    For hammerhead, Tassadar improved the patch a bit - only the host needs to be patched now and Tassadar added support for DTB.
    Last but not least for Xperia Z1 and Z Ultra I ported the patch to our sony 4.3 kernel sources. But most work was done by the awesome other devs :)

    XDA:DevDB Information
    [UB]Xperia Z1, ZU kexec patch v1 [18/01/14], a Tool/Utility for the Sony Xperia Z1

    Contributors
    krabappel2548

    Version Information
    Status: Testing
    Current Stable Version: V1 and future versio
    Stable Release Date: 2014-01-18

    Created 2014-01-18
    Last Updated 2014-01-18
    10
    Purpose of this kexec patch?
    Now I have this working, I'm going to work on a multiboot solution for people with unlocked bootloaders.

    Other kernel developers
    I have my sources on github. If you wanna make a host kernel with kexec patch, feel free to use my patches on github:
    https://github.com/Krabappel2548/android_kernel_sony_msm8974-kexec/commits/master

    trying another kernel then cm to kexec boot:
    When you compile the kernel don't take the zIamge, but the zImage-dtb from arch/arm/boot.
    kexec needs the zImage with dtb appended to it. This is just the way it works.

    Also don't forget to take the right ramdisk for the kernel and call it initrd.img.
    10
    uploadfromtaptalk1390296884649.jpg

    Sent from my C6903 using xda app-developers app
    7
    Is this similar to boot manager done by @letama in the Xperia S section?

    Sent from my C6903 using XDA Premium 4 mobile app

    I'm working on a modified twrp + a multirom manager, so basically the modified twrp allows you to just install a rom.zip as second rom and then the multirom manager would let you choose which rom to boot. Quite simple when I can get it working :p
    6
    Any news on multirom / multiboot? Would love to see this (well, who wouldn't?). Just asking as a month ago it was nearly/already/..? working.

    I kinda abandoned it since I had a busy month, but I'll try to complete it soon.

    Sent from my C6903 using xda app-developers app