[G2 Original Android Development] patrik.KT:
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 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.

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 Tasssadar made, and I think it is pretty significant.

To sumarize the process:

kexec --load-hardboot.... is called and kernel it loaded into RAM.

kexec -e is called. Special info is written to memory (to area which is not overwritten on reboot) and the device is rebooted.

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.

Kexecd' kernel starts and boots.

For more info, read the original thread.

Patches:

Kernel patch: https://gist.github.com/PatrikKT/50faf32e8931d51c0c9a,

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/multirom/blob/master/install_zip/prebuilt-installer/multirom/kexec​

Usage:

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=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 - he used patch from TF201 and modified it a bit (basically just changed few SoC specific constants). People at #ubuntu-arm helped him out with that, thanks.

For hammerhead, he has improved the patch a bit - only the host needs to be patched now and he has added support for DTB.

This thread was used as a template Credits to [MENTION=3418703]Tasssadar[/MENTION] for his Nexus 5 patch