[Galaxy Note 8.0 (Tablet) Android Development] Phil_Suz:
Hi,

No access to dev subforum. Admin, please can you move it ?

This article can be usefull for developpers on other devices where kexec-hardboot does not work.

This derivated method could be an alternative.

This post follow this one http://xdaforums.com/showthread.php?t=2558783 to give details about kernel patch to add this fonctionnality.

To understand the method used by mkasick, you can read this thread : http://xdaforums.com/showthread.php?t=1266827. You can read also Tassadar explaination post here : http://xdaforums.com/showthread.php?t=2104706

The important information is that, after a reboot, a part of the memory is not erased and then can be used to store data.

On stock distrib, this feature is used to keep previous kernel messages and make them readable from userspace in /proc/last_kmsg.

The kexec-harboot method was to use this feature to store kernel and initrd (and atags param) in a part of memory that will survice a reboot.

kexec comes in to part : a kernel syscall and a userspace programm.

On regular PC with Linux distrib, usually, when we want to restart quickly to another kernel, we do two steps :

- a first call to kexec program from userspace to load kernel/initrd into memory : kexec syscall is called and store all pages anywhere in free virtual pages. kexec kernel keep an index to know how to reorder all the pages to put them in real physical destination, when it will be time to jump to the new kernel.

- a second call to kexec (kexec -e) from userspace to switch to the new kernel : kexec syscall prepare the shutdown of all internal stuff ( flushing memory cache in TLB, disabling MMU, reseting cpu... ). At the very end of the process, just before jumping to the new kernel, all pages previously stored everywhere in memory are relocated to there final destination. This relocation process is done after mmu disabled. Just after relocation, new kernel is ready and kexec jump to first entry.

This process did not work well on android devices because some internal devices where not properly shutdown. That's why mkasick had the brilliant idea to store the new kernel in non flushed memory after reboot.

kexec-hardboot change the last action of kexec (jump to new kernel) by a reboot. After reboot (all internal devices are in a proper state), the second part of the patch verify if a kexec kernel has been previously loaded and if yes, jump to it, instead of the regular one.

( atags copy is also done there ).

I tried to apply this method on our Galaxy Note 8, everything was fine (reboot asm code, hardboot patch) except one blocking issue : the disable MMU code in kernel for our exynos4412 seems to not work well and hangs the system.

To solve this issue my idea was the following : If kexec can not do all the stuff and especially the relocation stuff, just do it by yourself : Instead off calling first time kexec to load kernel in non contigus virtual pages and creates index for relocation, we will write a userspace procedure to load directly the kernel at the physical final destination.

The only prerequisite will be to reserve enough physical memory at boot time. In the attached kernel patch, I reserve 32M of memory but, theorically, 8M could be enough for roms booting ( 8M limitation of boot.img block device).

Reserving more space is usable in case we want to play with bigger initrd. A lot of more memory can be reserved if needed.

To conclude, the method is as follow :

- Patch kernel to add hardboot patch

- Patch kernel to add Memory reservation at boot time ( bootmem allocator )

- Replace all kexec work by a userspace program to load kernel/initrd/atags directly to destination
​

I think this method can be applied easily to almost all android devices, as far as they support /proc/last_kmsg.

References/credits :

mkasic

: kexec-hardboot creator

Tassadar

: multirom creator - nice kexec-hardboot explainations​

Philippe,