Two patches for kexec for arm
Subsystems (3)
cover Two patches for kexec for arm
Hi Dave and Simon,
Sorry for the long delay. We have discussed kexec on arm at January this year:
http://lists.infradead.org/pipermail/kexec/2014-February/011031.html
I rewrite 2 patches and tested on QEMU, both crash dump and normal kexec is okay (kernel is 3.10.33). Please check.
The first patch makes initrd to be loaded at page boundary.
The second patch passes kernel command line and initrd infomation through dtb.
Without these two patches kexec, failed to work on arm.
I tested using following commands:
Start qemu:
$ qemu-system-arm -kernel $KERNEL_PATH -M versatilepb -initrd $INITRD_PATH \
-no-reboot -show-cursor -vnc 0.0.0.0:0 -machine type=vexpress-a9 \
-cpu cortex-a9 -m 512 --append "console=ttyAMA0 \
ip=192.168.7.2::192.168.7.1:255.255.255.0 mem=512M highres=off \
rdinit=/sbin/init crashkernel=72M@0x70000000" -serial stdioCrash dump case:
$ kexec -p /zImage -d -t zImage --dtb=/vexpress-v2p-ca9-512m.dtb \
--initrd=/initrd.cpio.gz \
--command-line="maxcpus=1 console=ttyAMA0 highres=off \
rdinit=/sbin/init"
$ echo c > /proc/sysrq-triggerkexec case:
$ kexec -f /zImage -d -t zImage --dtb=/vexpress-v2p-ca9-512m.dtb \
--initrd=initrd.cpio.gz --command-line="maxcpus=1 console=ttyAMA0 \
highres=off rdinit=/sbin/init"Kernel configuration is based on arch/arm/configs/vexpress_defconfig, with CONFIG_KEXEC selected.
Because we use only 512m memory, related dtb must be modified (in crash dump case, it is no problem because memory size is clamped by command line, but it is essential in normal kexec case). I haven't check atags.
vexpress-v2p-ca9-512m.dtb is generated by arch/arm/boot/dts/vexpress-v2p-ca9.dts with following patch:
vexpress-v2p-ca9-512m.dts renamed from vexpress-v2p-ca9.dts +1 -1
@@ -64,7 +64,7 @@ memory@60000000 { device_type = "memory"; - reg = <0x60000000 0x40000000>; + reg = <0x60000000 0x20000000>; }; clcd@10020000 {
WangNan (2):
kexec: align initrd when no --image-size passed
kexec: pass initrd position in dtb
kexec/arch/arm/kexec-zImage-arm.c | 88 +++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 27 deletions(-)
Signature · 7 lines
1.8.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/2 kexec: align initrd when no --image-size passed
Before this patch, when no --image-size passed, initrd_base is caculated using base + len * 4, which is unaligned, and unable to pass check in add_segment_phys_virt():
if (base & (pagesize -1)) {
die("Base address: 0x%lx is not page aligned\n", base);
}This patch also uses getpagesize() instead of hard encoded 4096.
--- kexec/arch/arm/kexec-zImage-arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kexec/arch/arm/kexec-zImage-arm.c +2 -2
@@ -347,11 +347,11 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,/* If the image size was passed as command line argument, * use that value for determining the address for initrd, * atags and dtb images. page-align the given length.*/ - initrd_base = base +_ALIGN (kexec_arm_image_size,4096 ); + initrd_base = base +_ALIGN (kexec_arm_image_size,getpagesize ()); }else {/* Otherwise, assume the maximum kernel compression ratio * is 4, and just to be safe, place ramdisk after that */ - initrd_base = base + len *4 ; + initrd_base = base +_ALIGN (len *4 ,getpagesize ()); }if (use_atags) {
Signature · 7 lines
1.8.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] kexec: align initrd when no --image-size passed
Quoted 39 lines · Wang Nan
Before this patch, when no --image-size passed,
initrd_baseis caculated using base + len * 4, which is unaligned, and unable to pass check inadd_segment_phys_virt():if (base & (pagesize -1)) { die("Base address: 0x%lx is not page aligned\n", base); }This patch also uses
getpagesize()instead of hard encoded 4096.Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kexec/arch/arm/kexec-zImage-arm.c +2
-2@@ -347,11 +347,11 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,/* If the image size was passed as command line argument, * use that value for determining the address for initrd, * atags and dtb images. page-align the given length.*/ - initrd_base = base +_ALIGN (kexec_arm_image_size,4096 ); + initrd_base = base +_ALIGN (kexec_arm_image_size,getpagesize ()); }else {/* Otherwise, assume the maximum kernel compression ratio * is 4, and just to be safe, place ramdisk after that */ - initrd_base = base + len *4 ; + initrd_base = base +_ALIGN (len *4 ,getpagesize ()); }if (use_atags) {Signature · 1 line
1.8.4
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
AppliedRe: [PATCH 1/2] kexec: align initrd when no --image-size passed
Quoted 36 lines · Dave Young
Quoted 35 lines · Wang Nan
Before this patch, when no --image-size passed,
initrd_baseis caculated using base + len * 4, which is unaligned, and unable to pass check inadd_segment_phys_virt():if (base & (pagesize -1)) { die("Base address: 0x%lx is not page aligned\n", base); }This patch also uses
getpagesize()instead of hard encoded 4096.Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kexec/arch/arm/kexec-zImage-arm.c +2
-2@@ -347,11 +347,11 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,/* If the image size was passed as command line argument, * use that value for determining the address for initrd, * atags and dtb images. page-align the given length.*/ - initrd_base = base +_ALIGN (kexec_arm_image_size,4096 ); + initrd_base = base +_ALIGN (kexec_arm_image_size,getpagesize ()); }else {/* Otherwise, assume the maximum kernel compression ratio * is 4, and just to be safe, place ramdisk after that */ - initrd_base = base + len *4 ; + initrd_base = base +_ALIGN (len *4 ,getpagesize ()); }
Quoted 6 lines
Quoted 4 lines
kexec/arch/arm/kexec-zImage-arm.c +0
-0if (use_atags) {Signature · 1 line
1.8.4Acked-by Dave Young <[email protected]>
Thanks, applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/2 kexec: pass initrd position in dtb
In reply to Wang NanThis patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.
--- kexec/arch/arm/kexec-zImage-arm.c | 84 +++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 25 deletions(-)
kexec/arch/arm/kexec-zImage-arm.c +59 -25
@@ -20,6 +20,7 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" +#include "libfdt_internal.h" #define BOOT_PARAMS_SIZE 1536
@@ -216,6 +217,47 @@ int atag_arm_load(struct kexec_info *info, unsigned long base,return 0 ; } +static int setup_dtb_prop (char **bufp,off_t *sizep,const char *node_name, +const char *prop_name,const void *val,int len) +{ +char *dtb_buf; +int off; + +if ((bufp ==NULL ) || (sizep ==NULL ) || (*bufp ==NULL )) +die ("Internal error\n" ); + + dtb_buf = *bufp; + + *sizep =fdt_totalsize (*bufp) +FDT_TAGSIZE + len + +FDT_TAGALIGN (strlen (node_name) +1 ) + +FDT_TAGALIGN (strlen (prop_name) +1 ) + +sizeof (struct fdt_property ); + + dtb_buf =xrealloc (dtb_buf, *sizep); +if (dtb_buf ==NULL ) +die ("xrealloc failed\n" ); + *bufp = dtb_buf; + +fdt_set_totalsize (dtb_buf, *sizep); + +/* check if the subnode already exists */ + off =fdt_path_offset (dtb_buf, node_name); + +if (off == -FDT_ERR_NOTFOUND ) + off =fdt_add_subnode (dtb_buf, off, node_name); +if (off <0 ) { +fprintf (stderr,"FDT: Error adding %s node.\n" , node_name); +return -1 ; + } +if (fdt_setprop (dtb_buf, off, prop_name, + val, len) !=0 ) { +fprintf (stderr,"FDT: Error setting %s/%s property.\n" , + node_name, prop_name); +return -1 ; + } +return 0 ; +} +int zImage_arm_load (int argc,char **argv,const char *buf,off_t len,struct kexec_info *info) {
@@ -375,32 +417,11 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, }if (command_line) { -const char *node_name ="/chosen" ; -const char *prop_name ="bootargs" ; -int off; - - dtb_length =fdt_totalsize (dtb_buf) +1024 + -strlen (command_line); - dtb_buf =xrealloc (dtb_buf, dtb_length); -fdt_set_totalsize (dtb_buf, dtb_length); - -/* check if a /choosen subnode already exists */ - off =fdt_path_offset (dtb_buf, node_name); - -if (off == -FDT_ERR_NOTFOUND ) - off =fdt_add_subnode (dtb_buf, off, node_name); - -if (off <0 ) { -fprintf (stderr,"FDT: Error adding %s node.\n" , node_name); +/* Error should have been reported */ +if (setup_dtb_prop (&dtb_buf, &dtb_length,"/chosen" , +"bootargs" , command_line, +strlen (command_line) +1 ))return -1 ; - } - -if (fdt_setprop (dtb_buf, off, prop_name, - command_line,strlen (command_line) +1 ) !=0 ) { -fprintf (stderr,"FDT: Error setting %s/%s property.\n" , - node_name, prop_name); -return -1 ; - } } }else {/*
@@ -417,6 +438,19 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,if (ramdisk) {add_segment (info, ramdisk_buf, initrd_size, initrd_base, initrd_size); + +unsigned long start, end; + start =cpu_to_be32 ((unsigned long )(initrd_base)); + end =cpu_to_be32 ((unsigned long )(initrd_base + initrd_size)); + +if (setup_dtb_prop (&dtb_buf, &dtb_length,"/chosen" , +"linux,initrd-start" , &start, +sizeof (start))) +return -1 ; +if (setup_dtb_prop (&dtb_buf, &dtb_length,"/chosen" , +"linux,initrd-end" , &end, +sizeof (end))) +return -1 ; }/* Stick the dtb at the end of the initrd and page
Signature · 7 lines
1.8.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] kexec: pass initrd position in dtb
Quoted 16 lines · Wang Nan
This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.
Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 84 +++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 25 deletions(-)kexec/arch/arm/kexec-zImage-arm.c +0
-0
kexec/arch/arm/kexec-zImage-arm.c line 23
Quoted 4 lines
kexec/arch/arm/kexec-zImage-arm.c +1
-0@@ -20,6 +20,7 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" +#include "libfdt_internal.h"
I guess it's for the FDT_TAGALIGN and FDT_TAGSIZE? libfdt_internal.h should be used as internal header for libfdt, a better way is adding another patch which move these 2 macros to fdt.h
Otherwise I'm fine with this patch.
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] kexec: pass initrd position in dtb
Quoted 12 lines · Dave Young
Quoted 11 lines · Wang Nan
This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.
Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 84 +++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 25 deletions(-)
Quoted 13 lines
kexec/arch/arm/kexec-zImage-arm.c line 23
Quoted 9 lines
kexec/arch/arm/kexec-zImage-arm.c +1
-0@@ -20,6 +20,7 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" +#include "libfdt_internal.h" I guess it's for the
FDT_TAGALIGNandFDT_TAGSIZE?libfdt_internal.hshould be used as internal header for libfdt, a better way is adding another patch which move these 2 macros tofdt.h
Or moving your new function setup_dtb_prop to libfdt, I'm not sure if it works on other arch though.
Quoted 2 lines
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] kexec: pass initrd position in dtb
Quoted 27 lines · Dave Young
Quoted 12 lines · Dave Young
Quoted 11 lines · Wang Nan
This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.
Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 84 +++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 25 deletions(-)Quoted 13 lines
kexec/arch/arm/kexec-zImage-arm.c line 23
Quoted 9 lines
kexec/arch/arm/kexec-zImage-arm.c +1
-0@@ -20,6 +20,7 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" +#include "libfdt_internal.h" I guess it's for the
FDT_TAGALIGNandFDT_TAGSIZE?libfdt_internal.hshould be used as internal header for libfdt, a better way is adding another patch which move these 2 macros tofdt.h
Quoted 5 lines
Or moving your new function
setup_dtb_propto libfdt, I'm not sure if it works on other arch though.Quoted 2 lines
Thanks
Dave
What about following midification (FDT_TAGSIZE is in fdt.h)? I'll send it formally if you agree this one.
kexec/arch/arm/kexec-zImage-arm.c +2 -3
@@ -20,7 +20,6 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" -#include "libfdt_internal.h" #define BOOT_PARAMS_SIZE 1536
@@ -229,8 +228,8 @@ static int setup_dtb_prop(char **bufp, off_t *sizep, const char *node_name, dtb_buf = *bufp; *sizep =fdt_totalsize (*bufp) +FDT_TAGSIZE + len + -FDT_TAGALIGN (strlen (node_name) +1 ) + -FDT_TAGALIGN (strlen (prop_name) +1 ) + +_ALIGN (strlen (node_name) +1 ,FDT_TAGSIZE ) + +_ALIGN (strlen (prop_name) +1 ,FDT_TAGSIZE ) +sizeof (struct fdt_property ); dtb_buf =xrealloc (dtb_buf, *sizep);
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] kexec: pass initrd position in dtb
Quoted 52 lines · Wang Nan
Quoted 27 lines · Dave Young
Quoted 12 lines · Dave Young
Quoted 11 lines · Wang Nan
This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.
Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 84 +++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 25 deletions(-)Quoted 13 lines
kexec/arch/arm/kexec-zImage-arm.c line 23
Quoted 9 lines
kexec/arch/arm/kexec-zImage-arm.c +1
-0@@ -20,6 +20,7 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" +#include "libfdt_internal.h" I guess it's for the
FDT_TAGALIGNandFDT_TAGSIZE?libfdt_internal.hshould be used as internal header for libfdt, a better way is adding another patch which move these 2 macros tofdt.hQuoted 5 lines
Or moving your new function
setup_dtb_propto libfdt, I'm not sure if it works on other arch though.Quoted 2 lines
Thanks
DaveWhat about following midification (
FDT_TAGSIZEis infdt.h)? I'll send it formally if you agree this one.kexec/arch/arm/kexec-zImage-arm.c +0
-1@@ -20,7 +20,6 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" -#include "libfdt_internal.h" #define BOOT_PARAMS_SIZE 1536
kexec/arch/arm/kexec-zImage-arm.c static int setup_dtb_prop(char **bufp, off_t *sizep, const char *node_name, · line 235
Quoted 10 lines
kexec/arch/arm/kexec-zImage-arm.c +2
-2@@ -229,8 +228,8 @@ static int setup_dtb_prop(char **bufp, off_t *sizep, const char *node_name, dtb_buf = *bufp; *sizep =fdt_totalsize (*bufp) +FDT_TAGSIZE + len + -FDT_TAGALIGN (strlen (node_name) +1 ) + -FDT_TAGALIGN (strlen (prop_name) +1 ) + +_ALIGN (strlen (node_name) +1 ,FDT_TAGSIZE ) + +_ALIGN (strlen (prop_name) +1 ,FDT_TAGSIZE ) +sizeof (struct fdt_property ); dtb_buf =xrealloc (dtb_buf, *sizep);
Looks good...
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] kexec: pass initrd position in dtb
In reply to Wang NanQuoted 31 lines · Wang Nan
Quoted 30 lines · Dave Young
Quoted 12 lines · Dave Young
Quoted 11 lines · Wang Nan
This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.
Signed-off-by Wang Nan <[email protected]>Cc Simon Horman <[email protected]>Cc Dave Young <[email protected]>Cc Geng Hui <[email protected]>--- kexec/arch/arm/kexec-zImage-arm.c | 84 +++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 25 deletions(-)Quoted 13 lines
kexec/arch/arm/kexec-zImage-arm.c line 23
Quoted 9 lines
kexec/arch/arm/kexec-zImage-arm.c +1
-0@@ -20,6 +20,7 @@#include "kexec-arm.h" #include "../../fs2dt.h" #include "crashdump-arm.h" +#include "libfdt_internal.h" I guess it's for the
FDT_TAGALIGNandFDT_TAGSIZE?libfdt_internal.hshould be used as internal header for libfdt, a better way is adding another patch which move these 2 macros tofdt.hOr moving your new function
setup_dtb_propto libfdt, I'm not sure if it works on other arch though.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Thanks
DaveWhat about following midification (
FDT_TAGSIZEis infdt.h)? I'll send it formally if you agree this one.
Another problem is this patch is doing 2 things:
* add a new function and use it for cmdline prop
* append initrd prop
So please split it to 2 patches.
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec