dt-ops: Add helper API to dump fdt blob
Subsystems (2)
PATCH 1/2 dt-ops: Add helper API to dump fdt blob
At several occasions it would be useful to dump the fdt blob being passed to the second (kexec/kdump) kernel when '-d' flag is specified while invoking kexec/kdump.
This allows one to look at the device-tree fields that is being passed to the secondary kernel and accordingly debug issues.
This can be specially useful for the arm64 case, where kexec_load() or kdump passes important information like 'linux,usable-memory' ranges to the second kernel, and the correctness of the ranges can be verified by looking at the device-tree dump with '-d' flag specified.
--- kexec/dt-ops.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ kexec/dt-ops.h | 1 + 2 files changed, 134 insertions(+)
kexec/dt-ops.c +133 -0
@@ -8,6 +8,10 @@#include "kexec.h" #include "dt-ops.h" +#define ALIGN (x, a) (((x) + ((a) - 1)) & ~((a) - 1)) +#define PALIGN (p, a) ((void *)(ALIGN((unsigned long)(p), (a)))) +#define GET_CELL (p) (p += 4, *((const uint32_t *)(p-4))) +static const char n_chosen[] ="/chosen" ;static const char p_bootargs[] ="bootargs" ;
@@ -143,3 +147,132 @@ int dtb_delete_property(char *dtb, const char *node, const char *prop)return result; } + +static uint64_t is_printable_string (const void * data,uint64_t len) +{ +const char *s = data; +const char *ss; + +/* Check for zero length strings */ +if (len ==0 ) { +return 0 ; + } + +/* String must be terminated with a '\0' */ +if (s[len -1 ] !='\0' ) { +return 0 ; + } + + ss = s; +while (*s) { + s++; + } + +/* Traverse till we hit a '\0' or reach 'len' */ +if (*s !='\0' || (s +1 - ss) < len) { +return 0 ; + } + +return 1 ; +} + +static void print_data (const char * data,uint64_t len) +{ +uint64_t i; +const char *p = data; + +/* Check for non-zero length */ +if (len ==0 ) +return ; + +if (is_printable_string (data, len)) { +dbgprintf (" = \"%s\"" , (const char *)data); + }else if ((len %4 ) ==0 ) { +dbgprintf (" = <" ); +for (i =0 ; i < len; i +=4 ) { +dbgprintf ("0x%08x%s" , +fdt32_to_cpu (GET_CELL (p)), + i < (len -4 ) ?" " :"" ); + } +dbgprintf (">" ); + }else { +dbgprintf (" = [" ); +for (i =0 ; i < len; i++) +dbgprintf ("%02x%s" , *p++, + i < len -1 ?" " :"" ); +dbgprintf ("]" ); + } +} + +void dump_fdt (void * fdt) +{ +struct fdt_header *bph; +const char * p_struct; +const char * p_strings; +const char * p; +const char * s; +const char * t; +uint32_t off_dt; +uint32_t off_str; +uint32_t tag; +uint64_t sz; +uint64_t depth; +uint64_t shift; +uint32_t version; + + depth =0 ; + shift =4 ; + + bph = fdt; + off_dt =fdt32_to_cpu (bph->off_dt_struct); + off_str =fdt32_to_cpu (bph->off_dt_strings); + p_struct = (const char *)fdt + off_dt; + p_strings = (const char *)fdt + off_str; + version =fdt32_to_cpu (bph->version); + + p = p_struct; +while ((tag =fdt32_to_cpu (GET_CELL (p))) !=FDT_END ) { + +if (tag ==FDT_BEGIN_NODE ) { + s = p; + p =PALIGN (p +strlen (s) +1 ,4 ); + +if (*s =='\0' ) + s ="/" ; + +dbgprintf ("%*s%s {\n" , (int )(depth * shift)," " , s); + + depth++; +continue ; + } + +if (tag ==FDT_END_NODE ) { + depth--; + +dbgprintf ("%*s};\n" , (int )(depth * shift)," " ); +continue ; + } + +if (tag ==FDT_NOP ) { +dbgprintf ("%*s// [NOP]\n" , (int )(depth * shift)," " ); +continue ; + } + +if (tag !=FDT_PROP ) { +dbgprintf ("%*s ** Unknown tag 0x%08x\n" , + (int )(depth * shift)," " , tag); +break ; + } + sz =fdt32_to_cpu (GET_CELL (p)); + s = p_strings +fdt32_to_cpu (GET_CELL (p)); +if (version <16 && sz >=8 ) + p =PALIGN (p,8 ); + t = p; + + p =PALIGN (p + sz,4 ); + +dbgprintf ("%*s%s" , (int )(depth * shift)," " , s); +print_data (t, sz); +dbgprintf (";\n" ); + } +}
kexec/dt-ops.h +1 -0
@@ -9,5 +9,6 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node, const char *prop, const void *value, int value_len);int dtb_delete_property (char *dtb,const char *node,const char *prop); +void dump_fdt (void *fdt) ;#endif
Signature · 7 lines
2.7.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/2 kexec-arm64: Add functionality to dump 2nd dtb
Since during the arm64 kexec_load()/kdump invocation, the dtb is passed to the second kernel, it is sometimes useful to dump the dtb contents (to verify the correctness of the same).
This patch adds this feature which is enabled when '-d' flag is used with kexec command line invocation.
Merge with 2nd patch
--- kexec/arch/arm64/kexec-arm64.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kexec/arch/arm64/kexec-arm64.c +3 -1
@@ -471,12 +471,14 @@ static int setup_2nd_dtb(struct dtb *dtb, char *command_line, int on_crash) result = -EINVAL ; goto on_error; } - +fdt_pack (new_buf); dtb->buf = new_buf; dtb->size =fdt_totalsize (new_buf); } +dbgprintf ("%s: found %s\n" , __func__, dtb->path); +dump_fdt (dtb->buf);dump_reservemap (dtb);
Signature · 7 lines
2.7.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] kexec-arm64: Add functionality to dump 2nd dtb
Quoted 38 lines · Bhupesh Sharma
Since during the arm64 kexec_load()/kdump invocation, the dtb is passed to the second kernel, it is sometimes useful to dump the dtb contents (to verify the correctness of the same).
This patch adds this feature which is enabled when '-d' flag is used with kexec command line invocation.
Signed-off-by Bhupesh Sharma <[email protected]>Merge with 2nd patch
Signed-off-by Bhupesh Sharma <[email protected]>--- kexec/arch/arm64/kexec-arm64.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kexec/arch/arm64/kexec-arm64.c +3
-2@@ -471,12 +471,14 @@ static int setup_2nd_dtb(struct dtb *dtb, char *command_line, int on_crash) result = -EINVAL ; goto on_error; } - +fdt_pack (new_buf); dtb->buf = new_buf; dtb->size =fdt_totalsize (new_buf); } +dbgprintf ("%s: found %s\n" , __func__, dtb->path); +dump_fdt (dtb->buf);dump_reservemap (dtb); --
Quoted 2 lines
2.7.4
Kindly ignore this version. It seems it had some issue before I sent it out. I will send a revised version shortly.
regards,
Bhupesh
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 180 lines · Bhupesh Sharma
At several occasions it would be useful to dump the fdt blob being passed to the second (kexec/kdump) kernel when '-d' flag is specified while invoking kexec/kdump.
This allows one to look at the device-tree fields that is being passed to the secondary kernel and accordingly debug issues.
This can be specially useful for the arm64 case, where
kexec_load()or kdump passes important information like 'linux,usable-memory' ranges to the second kernel, and the correctness of the ranges can be verified by looking at the device-tree dump with '-d' flag specified.Signed-off-by Bhupesh Sharma <[email protected]>--- kexec/dt-ops.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ kexec/dt-ops.h | 1 + 2 files changed, 134 insertions(+)kexec/dt-ops.c +133
-0@@ -8,6 +8,10 @@#include "kexec.h" #include "dt-ops.h" +#define ALIGN (x, a) (((x) + ((a) - 1)) & ~((a) - 1)) +#define PALIGN (p, a) ((void *)(ALIGN((unsigned long)(p), (a)))) +#define GET_CELL (p) (p += 4, *((const uint32_t *)(p-4))) +static const char n_chosen[] ="/chosen" ;static const char p_bootargs[] ="bootargs" ;@@ -143,3 +147,132 @@ int dtb_delete_property(char *dtb, const char *node, const char *prop)return result; } + +static uint64_t is_printable_string (const void * data,uint64_t len) +{ +const char *s = data; +const char *ss; + +/* Check for zero length strings */ +if (len ==0 ) { +return 0 ; + } + +/* String must be terminated with a '\0' */ +if (s[len -1 ] !='\0' ) { +return 0 ; + } + + ss = s; +while (*s) { + s++; + } + +/* Traverse till we hit a '\0' or reach 'len' */ +if (*s !='\0' || (s +1 - ss) < len) { +return 0 ; + } + +return 1 ; +} + +static void print_data (const char * data,uint64_t len) +{ +uint64_t i; +const char *p = data; + +/* Check for non-zero length */ +if (len ==0 ) +return ; + +if (is_printable_string (data, len)) { +dbgprintf (" = \"%s\"" , (const char *)data); + }else if ((len %4 ) ==0 ) { +dbgprintf (" = <" ); +for (i =0 ; i < len; i +=4 ) { +dbgprintf ("0x%08x%s" , +fdt32_to_cpu (GET_CELL (p)), + i < (len -4 ) ?" " :"" ); + } +dbgprintf (">" ); + }else { +dbgprintf (" = [" ); +for (i =0 ; i < len; i++) +dbgprintf ("%02x%s" , *p++, + i < len -1 ?" " :"" ); +dbgprintf ("]" ); + } +} + +void dump_fdt (void * fdt) +{ +struct fdt_header *bph; +const char * p_struct; +const char * p_strings; +const char * p; +const char * s; +const char * t; +uint32_t off_dt; +uint32_t off_str; +uint32_t tag; +uint64_t sz; +uint64_t depth; +uint64_t shift; +uint32_t version; + + depth =0 ; + shift =4 ; + + bph = fdt; + off_dt =fdt32_to_cpu (bph->off_dt_struct); + off_str =fdt32_to_cpu (bph->off_dt_strings); + p_struct = (const char *)fdt + off_dt; + p_strings = (const char *)fdt + off_str; + version =fdt32_to_cpu (bph->version); + + p = p_struct; +while ((tag =fdt32_to_cpu (GET_CELL (p))) !=FDT_END ) { + +if (tag ==FDT_BEGIN_NODE ) { + s = p; + p =PALIGN (p +strlen (s) +1 ,4 ); + +if (*s =='\0' ) + s ="/" ; + +dbgprintf ("%*s%s {\n" , (int )(depth * shift)," " , s); + + depth++; +continue ; + } + +if (tag ==FDT_END_NODE ) { + depth--; + +dbgprintf ("%*s};\n" , (int )(depth * shift)," " ); +continue ; + } + +if (tag ==FDT_NOP ) { +dbgprintf ("%*s// [NOP]\n" , (int )(depth * shift)," " ); +continue ; + } + +if (tag !=FDT_PROP ) { +dbgprintf ("%*s ** Unknown tag 0x%08x\n" , + (int )(depth * shift)," " , tag); +break ; + } + sz =fdt32_to_cpu (GET_CELL (p)); + s = p_strings +fdt32_to_cpu (GET_CELL (p)); +if (version <16 && sz >=8 ) + p =PALIGN (p,8 ); + t = p; + + p =PALIGN (p + sz,4 ); + +dbgprintf ("%*s%s" , (int )(depth * shift)," " , s); +print_data (t, sz); +dbgprintf (";\n" ); + } +}kexec/dt-ops.h +1
-1@@ -9,5 +9,6 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node, const char *prop, const void *value, int value_len);int dtb_delete_property (char *dtb,const char *node,const char *prop); +void dump_fdt (void *fdt) ;#endif --
Quoted 2 lines
2.7.4
Kindly ignore this version. It seems it had some issue before I sent it out. I will send a revised version shortly.
regards,
Bhupesh
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec