Remove All Ads from XDA

Kexec-hardboot patch

818 posts
Thanks Meter: 6,168
Post Reply Email Thread
In this post, I would like to explain what kexec-hardboot patch is and also bring it to light a bit more since until now, it was only burried in MultiROM thread.

@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 7. 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.

Kernel patch:, 4.3 AOSP kernel repo, cm 10.2 kernel repo
This is the kernel patch. Only the host kernel needs to be patched.
Related CONFIG options:
All these options must be enabled.
Userspace kexec binary:
That ZIP file contains kexec source, patches and README. It is from the original patch from Mike Kasick. It also contains precompiled, statically linked kexec binary, so you probably just want to use that.
Once you have the kernel patches and kexec userspace binary in place, just run following command to boot into new kernel:
kexec --load-hardboot zImage --initrd=initrd.img --mem-min=0x85000000 --command-line="$(cat /proc/cmdline)"
kexec -e
Note the command line parameter - cmdline from bootloader is not added automatically, you have to put it there by yourself.

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 flo, I've improved the patch a bit - only the host needs to be patched now and I also fixed a bug with /proc/atags not reading all tags.
The Following 9 Users Say Thank You to Tasssadar For This Useful Post: [ View ] Gift Tasssadar Ad-Free
25th September 2013, 10:32 PM |#2  
Tasssadar's Avatar
OP Inactive Recognized Developer
Flag Brno
Thanks Meter: 6,168
Donate to Me
The patch was updated with commit in repositories and on gist.

The reason is that my initial ramdisk address was not compatible with all kernels, and changing it resulted in a problem to appear on CM kernel - it just crashes on kexec-hardboot call. AOSP kernel worked just fine after the change, but I applied the patch just to be sure. Sorry about this, I didn't expect the patch to change at all, but it happened :/ I really hope this is the last time.

@ayysir originaly made this change, thanks.
The Following 2 Users Say Thank You to Tasssadar For This Useful Post: [ View ] Gift Tasssadar Ad-Free
31st March 2014, 02:24 PM |#3  
@Tasssadar I would like to port your kexec-hardboot patch on my device which has a Qualcomm MSM7225A chipset with a locked bootloader. How do I locate the memory addresses in adb shell to boot the kernel? Thanks. I'm currently using Fedora 64-bit on my computer.
Post Reply Subscribe to Thread

hardboot, kexec, kexec hardboot

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes