Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,210 Members 49,448 Now Online
XDA Developers Android and Mobile Development Forum

Kexec-hardboot patch

Tip us?
 
Tasssadar
Old
(Last edited by Tasssadar; 1st November 2013 at 03:57 PM.)
#1  
Tasssadar's Avatar
Recognized Developer - OP
Thanks Meter 4283
Posts: 676
Join Date: Dec 2010
Location: Brno

 
DONATE TO ME
Default Kexec-hardboot patch

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.
Another difference is that both kernels must be patched. The "host" kernel requires a full patch, the one which is being kexecd' requires only two small compatibility patches.
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:
Full kernel patch: https://gist.github.com/4558647, 4.1 kernel repo, cm 10.1 kernel repo
This is the full kernel patch. Kernels with this patch can be both "host" and "guest" kernels.
Related CONFIG options:
  • CONFIG_KEXEC=y
  • CONFIG_KEXEC_HARDBOOT=y
  • CONFIG_ATAGS_PROC=y
  • CONFIG_GROUPER_HARDBOOT_RECOVERY=n
First three options must be enabled. Last one, GROUPER_HARDBOOT_RECOVERY, specifies if the kexec call should reboot to normal mode or to recovery. This can be useful if you don't have the kernel in boot partition but only as kernel in recovery partition. You usualy want to disable this option.
Compatibility patch: https://gist.github.com/4458581
This patch only makes the kernel bootable via kexec, ie. it can't be the host kernel. This was made for Ubuntu kernel (and it was accepted), because I did not want to drag the whole patch in there. If your kernel is for Android ROMs, you should use the full patch.
Userspace kexec binary: kexec-tools.zip
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.
Usage:
Once you have the kernel patches and kexec userspace binary in place, just run following command to boot into new kernel:
Code:
Select Code
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.

Currently used by:
MultiROM - I use it to boot different kernels (eg. Ubuntu).
MOSLO - Part of Plasma Active for Nexus 7, also usefull tool for every N7 developer - read more: http://ruedigergad.com/2012/12/09/ne...ata-partition/

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.
The Following 34 Users Say Thank You to Tasssadar For This Useful Post: [ Click to Expand ]
 
Thunder07
Old
(Last edited by Thunder07; 29th July 2013 at 04:45 PM.)
#2  
Thunder07's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 1855
Posts: 1,303
Join Date: Sep 2007

 
DONATE TO ME
Hi Tasssadar,
im trying to get this to work on the HOX in order to have a shot at multiboot,
the patched applied with no problem... however on compiling i gett this error
"Adress for kexec hardboot page not defined"
ask this error naturely defined to kick in with every device beside N7 i that comment completely....
and that ended up giving me an error about KEXEC_HB_PAGE_ADDR not defined,
so i readded it, but i removed the "#if defined(CONFIG_MACH_GROUPER)"

now trying to compile it, its gets pretty close to the end... but failed with unexpected string error at line OUTPUT_ARCH(arm) in file linux/arch/arm/boot/compressed/vmlinux.lds
 
Code:
Select Code
/*
 *  linux/arch/arm/boot/compressed/vmlinux.lds.in
 *
 *  Copyright (C) 2000 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
  /DISCARD/ : {
    *(.ARM.exidx*)
    *(.ARM.extab*)
    /*
     * Discard any r/w data - this produces a link error if we have any,
     * which is required for PIC decompression.  Local data generates
     * GOTOFF relocations, which prevents it being relocated independently
     * of the text/got segments.
     */
    *(.data)
  }

  . = 0;
  _text = .;

  .text : {
    _start = .;
    *(.start)
    *(.text)
    *(.text.*)
    *(.fixup)
    *(.gnu.warning)
    *(.glue_7t)
    *(.glue_7)
  }
  .rodata : {
    *(.rodata)
    *(.rodata.*)
  }
  .piggydata : {
    *(.piggydata)
  }

  . = ALIGN(4);
  _etext = .;

  .got.plt		: { *(.got.plt) }
  _got_start = .;
  .got			: { *(.got) }
  _got_end = .;
  _edata = .;

  . = ALIGN(8);
  __bss_start = .;
  .bss			: { *(.bss) }
  _end = .;

  . = ALIGN(8);		/* the stack must be 64-bit aligned */
  .stack		: { *(.stack) }

  .stab 0		: { *(.stab) }
  .stabstr 0		: { *(.stabstr) }
  .stab.excl 0		: { *(.stab.excl) }
  .stab.exclstr 0	: { *(.stab.exclstr) }
  .stab.index 0		: { *(.stab.index) }
  .stab.indexstr 0	: { *(.stab.indexstr) }
  .comment 0		: { *(.comment) }
}

also, im booted into windows now... so i can't provide the exact error.

Device: HTC One X

My Work
[AIO]One X One Click | Thunder's Online Kernel Repacker | Zeus Kernel Lighter
OTA Creator V1.1 | ARHD 9.x (Base 2.17) & CD-Tool Battery Mods | Battery Mods Creator V1.1 |APK (Game) Modder v1.0 Beta


 

SkyDragonİ AIO Team Member



If I got a euro for each thanks I received... Well... Ill have ALOT of Euros
Click Thanks Or Hit That Donate Button.
 
Tasssadar
Old
#3  
Tasssadar's Avatar
Recognized Developer - OP
Thanks Meter 4283
Posts: 676
Join Date: Dec 2010
Location: Brno

 
DONATE TO ME
I'm afraid "comment everything which doesn't work" won't work here. The KEXEC_HB_PAGE_ADDR and END_MEM is device-specific, it will most likely be different for HTC One X. You can find out what address is it supposed to be by examining /proc/iomem on your device. For example, here's memory map from grouper:
Code:
Select Code
...
80000000-be9fffff : System RAM
  80008000-808faba7 : Kernel text
  80940000-80b8228f : Kernel data
beb00000-bebfffff : ram_console
...
So, for grouper, END_MEM is 0xbe9fffff + 1 = 0xbea00000.
KEXEC_HB_PAGE_ADDR is located 1MB before console RAM, which is in this case also immediatelly after System RAM, so for grouper, it is also 0xbea00000.

Quote:
but failed with unexpected string error at line OUTPUT_ARCH(arm) in file linux/arch/arm/boot/compressed/vmlinux.lds
That doesn't seem to be related to this patch. Are you using correct cross-compiler?
The Following 3 Users Say Thank You to Tasssadar For This Useful Post: [ Click to Expand ]
 
Thunder07
Old
(Last edited by Thunder07; 29th July 2013 at 05:55 PM.)
#4  
Thunder07's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 1855
Posts: 1,303
Join Date: Sep 2007

 
DONATE TO ME
Quote:
Originally Posted by Tasssadar View Post
I'm afraid "comment everything which doesn't work" won't work here. The KEXEC_HB_PAGE_ADDR and END_MEM is device-specific, it will most likely be different for HTC One X.
i figured
but im walking you through what i did.

Quote:
You can find out what address is it supposed to be by examining /proc/iomem on your device. For example, here's memory map from grouper:
Code:
Select Code
...
80000000-be9fffff : System RAM
  80008000-808faba7 : Kernel text
  80940000-80b8228f : Kernel data
beb00000-bebfffff : ram_console
...
So, for grouper, END_MEM is 0xbe9fffff + 1 = 0xbea00000.
KEXEC_HB_PAGE_ADDR is located 1MB before console RAM, which is in this case also immediatelly after System RAM, so for grouper, it is also 0xbea00000.
Code:
Select Code
7d000000-7d003fff : tegra-udc.0
  7d000000-7d003fff : tegra-otg
    7d000000-7d003fff : tegra-udc
7d004000-7d007fff : tegra-ehci.1
80000000-beafffff : System RAM
  80008000-8094000f : Kernel text
  809a8000-810b940f : Kernel data
beb00000-bebfffff : ram_console
bec00000-beffffff : fbmem
bf000000-bf7fffff : fbmem
0xbeafffff + 1 = 0xbeb00000

grrr that would put me inside the ram_console...
aaaa would it wok if i used the address before??
7d00800

Edit:
or did your ram RAM end earlier because you set you END_MEM 0xbea00000
in that case, it works out just the same with the HOX

Quote:

That doesn't seem to be related to this patch. Are you using correct cross-compiler?
i would have guessed so, but the kernel compiled and is working before the patch.
im using the one provided by google (Android NDK r9) while it contains booth gcc 4.6/4.8 im using 4.6 (arm-linux-androideabi-)
 
Tasssadar
Old
#5  
Tasssadar's Avatar
Recognized Developer - OP
Thanks Meter 4283
Posts: 676
Join Date: Dec 2010
Location: Brno

 
DONATE TO ME
The patch will move ram_console 1MB further, see https://gist.github.com/Tasssadar/45...boot-diff-L387 . You'll have to modify this part of the patch, it will be in different file for your device.
The Following User Says Thank You to Tasssadar For This Useful Post: [ Click to Expand ]
 
Thunder07
Old
(Last edited by Thunder07; 29th July 2013 at 06:08 PM.)
#6  
Thunder07's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 1855
Posts: 1,303
Join Date: Sep 2007

 
DONATE TO ME
Quote:
Originally Posted by Tasssadar View Post
The patch will move ram_console 1MB further, see https://gist.github.com/Tasssadar/45...boot-diff-L387 . You'll have to modify this part of the patch, it will be in different file for your device.
HOX is also a Tegra 3 device... so im guessing i wont need to touch a thing?
also note... that iomem provided is from an unpatched kernel (as i cant compile a patched one)

also,
im currently on freenode #htc-one-x
if you dont mind joining.
 
Tasssadar
Old
(Last edited by Tasssadar; 16th August 2013 at 09:42 AM.)
#7  
Tasssadar's Avatar
Recognized Developer - OP
Thanks Meter 4283
Posts: 676
Join Date: Dec 2010
Location: Brno

 
DONATE TO ME
I've been looking through the kexec-hardboot patch these last few days, trying to actually understand it instead of just blindly porting it and after several hours of messing with assembler with no means to debug it, I've managed to remove the need for guest kernel to be patched. This is not really useful for grouper, since thanks to multirom and accepting kernel devs, nearly every third-party kernel has the proper patches. But, if I'll port multirom to some other device (hello, flo), it will be very useful

To know more see the changes in this commit, but you'll probably need to understand how the patch does things: https://github.com/Tasssadar/android...46c4e528c5c30b

@mkasick: Could you please look over this? I'm afraid there's some good reason why you didn't do this in the first place, like rewriting some part of memory which shouldn't be rewritten or something like that. Thank you.
The Following 3 Users Say Thank You to Tasssadar For This Useful Post: [ Click to Expand ]
 
Thunder07
Old
(Last edited by Thunder07; 17th August 2013 at 08:21 PM.)
#8  
Thunder07's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 1855
Posts: 1,303
Join Date: Sep 2007

 
DONATE TO ME
Quote:
Originally Posted by Tasssadar View Post
I've been looking through the kexec-hardboot patch these last few days, trying to actually understand it instead of just blindly porting it and after several hours of messing with assembler with no means to debug it, I've managed to remove the need for guest kernel to be patched. This is not really useful for grouper, since thanks to multirom and accepting kernel devs, nearly every third-party kernel has the proper patches. But, if I'll port multirom to some other device (hello, flo), it will be very useful

To know more see the changes in this commit, but you'll probably need to understand how the patch does things: https://github.com/Tasssadar/android...46c4e528c5c30b

@mkasick: Could you please look over this? I'm afraid there's some good reason why you didn't do this in the first place, like rewriting some part of memory which shouldn't be rewritten or something like that. Thank you.
Perfect timing, just finished my last exam

Edit:
Also, this applies on top of the original patch right??

Edit2:
i can't seem to get it to kexec boot, but i didn't do much testing, maybe 2morrow night!

Edit3:
fixed, it was a problem with min-addr,
changed it to 0x82000000 and it worked
 
thewisenerd
Old
#9  
Senior Member
Thanks Meter 2258
Posts: 1,064
Join Date: Sep 2012
Question One more question...

TEGRA_PMC_BASE is also device specific, ain't it???
So, for a Qualcomm device, what should I be using? I am guessing it is MSM_RPM_BASE, which I got from here: http://forum.xda-developers.com/show...86&postcount=7
join #pico for a chat!
 
Tasssadar
Old
#10  
Tasssadar's Avatar
Recognized Developer - OP
Thanks Meter 4283
Posts: 676
Join Date: Dec 2010
Location: Brno

 
DONATE TO ME
Yes, it is SoC-specific. This is using some special register to reset the chip, I'm not sure if that is available on msm chips - probably yes, but in some different form. Your best chance is to examine restart sequence in arch/arm/mach-msm/restart.c and port it to assembler.

Tags
hardboot, kexec, kexec-hardboot, multirom
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes