Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[PATCH] Kexec-hardboot patch

OP Tasssadar

15th December 2013, 04:30 PM   |  #1  
Tasssadar's Avatar
OP Recognized Developer
Flag Brno
Thanks Meter: 5,077
 
720 posts
Join Date:Joined: Dec 2010
Donate to Me
More
In this post, I would like to explain what kexec-hardboot patch is.

@kernel developers: I would like to ask you to merge this patch to your kernels, because it is essential part of MultiROM - it allows me to boot any kernel without changing the boot partition. I realize that it is no small request, but the patch is not big, touches relatively stable parts of kernel and should not cause any problems. Thank you.

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.

Patches:
Kernel patch: https://gist.github.com/Tasssadar/7833796, 4.4 AOSP kernel repo
This is the kernel patch. Only the host kernel needs to be patched.
Related CONFIG options:
  • CONFIG_KEXEC=y
  • CONFIG_KEXEC_HARDBOOT=y
  • CONFIG_PROC_DEVICETREE=y
  • CONFIG_ATAGS_PROC=n # This one is turned on automatically, but it is not needed, so you can disable it.
All these options must be enabled.
Userspace kexec binary: https://github.com/Tasssadar/kexec-tools
I had to change some things in kexec userspace binary because of some kernel bugs, complete description is in that repository. You can get statically built binary at https://github.com/Tasssadar/multiro...multirom/kexec
Usage:
Once you have the kernel patches and kexec userspace binary in place, just run following command to boot into new kernel:
Code:
kexec --load-hardboot zImage --initrd=initrd.img --mem-min=0x20000000 --command-line="$(cat /proc/cmdline)" --dtb
kexec -e
Note the command line parameter - cmdline from bootloader is not added automatically, you have to put it there by yourself.

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, I've improved the patch a bit - only the host needs to be patched now and I've added support for DTB.
Last edited by Tasssadar; 18th January 2014 at 02:17 PM.
The Following 71 Users Say Thank You to Tasssadar For This Useful Post: [ View ]
15th December 2013, 05:36 PM   |  #2  
franciscofranco's Avatar
Recognized Developer
Flag Mountain View, CA
Thanks Meter: 91,040
 
16,078 posts
Join Date:Joined: Dec 2010
Donate to Me
More
Merged, thanks again for the awesome work @Tasssadar!
The Following 40 Users Say Thank You to franciscofranco For This Useful Post: [ View ]
15th December 2013, 06:47 PM   |  #3  
Senior Member
Flag daytona beach
Thanks Meter: 204
 
575 posts
Join Date:Joined: Mar 2012
Good deal.My day is getting better.
15th December 2013, 07:49 PM   |  #4  
RoyJ's Avatar
Senior Member
Flag 203
Thanks Meter: 1,988
 
3,069 posts
Join Date:Joined: Apr 2012
More
@show-p1984 would love to see this in bricked kernel too! 😁
16th December 2013, 12:38 AM   |  #5  
AndroidSlave's Avatar
Senior Member
Flag Simi Valley, California
Thanks Meter: 4,330
 
5,434 posts
Join Date:Joined: Jun 2012
More
@neobuddy89 did you see this?

Sent from Nexus 5 on Slimkat
16th December 2013, 02:42 PM   |  #6  
meethere's Avatar
Senior Member
Thanks Meter: 103
 
714 posts
Join Date:Joined: Jan 2012
thanks for the hard work.. thats awesome.
10th May 2014, 07:03 PM   |  #7  
neobuddy89's Avatar
Senior Member
Flag MSM8974
Thanks Meter: 13,657
 
3,540 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Quote:
Originally Posted by AndroidSlave

@neobuddy89 did you see this?

Sent from Nexus 5 on Slimkat

Yeah, I saw this.
The Following 3 Users Say Thank You to neobuddy89 For This Useful Post: [ View ]
10th May 2014, 07:30 PM   |  #8  
AndroidSlave's Avatar
Senior Member
Flag Simi Valley, California
Thanks Meter: 4,330
 
5,434 posts
Join Date:Joined: Jun 2012
More
Quote:
Originally Posted by neobuddy89

Yeah, I saw this.

I asked that 6 months ago


Sent from my Nexus 5 using Tapatalk
The Following 2 Users Say Thank You to AndroidSlave For This Useful Post: [ View ]
11th May 2014, 06:14 AM   |  #9  
meethere's Avatar
Senior Member
Thanks Meter: 103
 
714 posts
Join Date:Joined: Jan 2012
awesome work bro...
much needed..
12th May 2014, 02:33 PM   |  #10  
neobuddy89's Avatar
Senior Member
Flag MSM8974
Thanks Meter: 13,657
 
3,540 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Quote:
Originally Posted by AndroidSlave

I asked that 6 months ago


Sent from my Nexus 5 using Tapatalk

Yeah, I know and I saw that days back..
Enough of OT.

Post Reply Subscribe to Thread

Tags
hardboot, kexec, kexec-hardboot
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes