kexec: pass initrd position in dtb
Subsystems (2)
cover kexec: pass initrd position in dtb
The main goal of this patch series is to pass initrd position to secondary kernel. To makes code clear, patch 2/3 introduce a new function to handle fdt related operations.
Without these two patches, kexec failed to work on arm.
Change from v1:
- Remove #include "libfdt_internal.h" since it is for internal use for libfdt.
Change from v2:
- Split into two logically independent patches.
- Compute memory consumption more accurate.
Change from v3:
- Introduces helpers in libfdt for memory usage computation.
Wang Nan (3):
kexec: introduce helpers for computing dtb size
kexec: introduce setup_dtb_prop to make code clear
kexec: pass initrd position by dtb
kexec/arch/arm/kexec-zImage-arm.c | 106 +++++++++++++++++++++++++++++--------- kexec/libfdt/libfdt.h | 24 +++++++++ kexec/libfdt/libfdt_internal.h | 3 -- 3 files changed, 105 insertions(+), 28 deletions(-)
Signature · 7 lines
1.8.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/3 kexec: introduce helpers for computing dtb size
This patch introduce fdt_node_len and fdt_prop_len to help for computing memory requirement when operating dtb.
--- kexec/libfdt/libfdt.h | 24 ++++++++++++++++++++++++ kexec/libfdt/libfdt_internal.h | 3 --- 2 files changed, 24 insertions(+), 3 deletions(-)
kexec/libfdt/libfdt.h +24 -0
@@ -1073,4 +1073,28 @@ int fdt_del_node(void *fdt, int nodeoffset);const char *fdt_strerror (int errval); +#define FDT_ALIGN (x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN (x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +/* +* if add a new subnode: +* see: fdt_add_subnode -> fdt_add_subnode_namelen +*/ +static inline int fdt_node_len (const char * node_name) +{ +return sizeof (struct fdt_node_header ) + +FDT_TAGALIGN (strlen (node_name) +1 ) +FDT_TAGSIZE ; +} + +/* +* if add a new prop: (assume prop_name not exist in strtab) +* see: fdt_setprop -> _fdt_add_property +*/ +static inline int fdt_prop_len (const char * prop_name,int len) +{ +return (strlen (prop_name) +1 ) + +sizeof (struct fdt_property ) + +FDT_TAGALIGN (len); +} +#endif /* _LIBFDT_H */
kexec/libfdt/libfdt_internal.h +0 -3
@@ -52,9 +52,6 @@*/ #include <fdt.h> -#define FDT_ALIGN (x, a) (((x) + (a) - 1) & ~((a) - 1)) -#define FDT_TAGALIGN (x) (FDT_ALIGN((x), FDT_TAGSIZE)) -#define FDT_CHECK_HEADER (fdt) \ { \ int err; \
Signature · 7 lines
1.8.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/3 kexec: introduce setup_dtb_prop to make code clear
In reply to Wang NanThis patch introduces setup_dtb_prop(), which is used for dtb operations. The code is extracted from zImage_arm_load, and this patch makes memory grown computation more accurate.
--- kexec/arch/arm/kexec-zImage-arm.c | 93 ++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 25 deletions(-)
kexec/arch/arm/kexec-zImage-arm.c +68 -25
@@ -216,6 +216,67 @@ 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; +off_t dtb_size; +int off; +int prop_len =0 ; +const struct fdt_property *prop; + +if ((bufp ==NULL ) || (sizep ==NULL ) || (*bufp ==NULL )) +die ("Internal error\n" ); + + dtb_buf = *bufp; + dtb_size = *sizep; + +/* check if the subnode has already exist */ + off =fdt_path_offset (dtb_buf, node_name); +if (off == -FDT_ERR_NOTFOUND ) { + dtb_size +=fdt_node_len (node_name); +fdt_set_totalsize (dtb_buf, dtb_size); + dtb_buf =xrealloc (dtb_buf, dtb_size); +if (dtb_buf ==NULL ) +die ("xrealloc failed\n" ); + off =fdt_add_subnode (dtb_buf, off, node_name); + } + +if (off <0 ) { +fprintf (stderr,"FDT: Error adding %s node.\n" , node_name); +return -1 ; + } + + prop =fdt_get_property (dtb_buf, off, prop_name, &prop_len); +if ((prop ==NULL ) && (prop_len != -FDT_ERR_NOTFOUND )) { +die ("FDT: fdt_get_property" ); + }else if (prop ==NULL ) { +/* prop_len == -FDT_ERR_NOTFOUND */ +/* prop doesn't exist */ + dtb_size +=fdt_prop_len (prop_name, len); + }else { +if (prop_len < len) + dtb_size += len - prop_len; + } + +if (fdt_totalsize (dtb_buf) < dtb_size) { +fdt_set_totalsize (dtb_buf, dtb_size); + dtb_buf =xrealloc (dtb_buf, dtb_size); +if (dtb_buf ==NULL ) +die ("xrealloc failed\n" ); + } + +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 ; + } + *bufp = dtb_buf; + *sizep = dtb_size; +return 0 ; +} +int zImage_arm_load (int argc,char **argv,const char *buf,off_t len,struct kexec_info *info) {
@@ -375,32 +436,14 @@ 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); -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); +/* +* Error should have been reported so +* directly return -1 +*/ +if (setup_dtb_prop (&dtb_buf, &dtb_length,"/chosen" , +"bootargs" , command_line, +strlen (command_line) +1 ))return -1 ; - } } }else {/*
Signature · 7 lines
1.8.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 3/3 kexec: pass initrd position by 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kexec/arch/arm/kexec-zImage-arm.c +13 -0
@@ -460,6 +460,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
Quoted 27 lines · Wang Nan
The main goal of this patch series is to pass initrd position to secondary kernel. To makes code clear, patch 2/3 introduce a new function to handle fdt related operations.
Without these two patches, kexec failed to work on arm.
Change from v1:
- Remove #include "
libfdt_internal.h" since it is for internal use for libfdt.Change from v2:
- Split into two logically independent patches.
- Compute memory consumption more accurate.Change from v3:
- Introduces helpers in libfdt for memory usage computation.
Wang Nan (3):
kexec: introduce helpers for computing dtb size
kexec: introducesetup_dtb_propto make code clear
kexec: pass initrd position by dtb
Quoted 5 lines
kexec/arch/arm/kexec-zImage-arm.c | 106 +++++++++++++++++++++++++++++--------- kexec/libfdt/libfdt.h | 24 +++++++++ kexec/libfdt/libfdt_internal.h | 3 -- 3 files changed, 105 insertions(+), 28 deletions(-)
Thanks for the update.
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
AppliedQuoted 34 lines · Dave Young
Quoted 27 lines · Wang Nan
The main goal of this patch series is to pass initrd position to secondary kernel. To makes code clear, patch 2/3 introduce a new function to handle fdt related operations.
Without these two patches, kexec failed to work on arm.
Change from v1:
- Remove #include "
libfdt_internal.h" since it is for internal use for libfdt.Change from v2:
- Split into two logically independent patches.
- Compute memory consumption more accurate.Change from v3:
- Introduces helpers in libfdt for memory usage computation.
Wang Nan (3):
kexec: introduce helpers for computing dtb size
kexec: introducesetup_dtb_propto make code clear
kexec: pass initrd position by dtbQuoted 5 lines
kexec/arch/arm/kexec-zImage-arm.c | 106 +++++++++++++++++++++++++++++--------- kexec/libfdt/libfdt.h | 24 +++++++++ kexec/libfdt/libfdt_internal.h | 3 -- 3 files changed, 105 insertions(+), 28 deletions(-)
Quoted 3 lines
Thanks for the update.
Acked-by Dave Young <[email protected]>
Thanks, applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec