FIT images can have properties with very long values. Make it possible to use of_dump to inspect them by adding a -P option that restricts how much of the value is printed. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- commands/devinfo.c | 2 +- commands/of_dump.c | 15 +++++++++++---- common/bootm.c | 2 +- common/image-fit.c | 2 +- drivers/of/base.c | 37 ++++++++++++++++++++----------------- include/of.h | 4 ++-- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/commands/devinfo.c b/commands/devinfo.c index 32fd55ebd515..e171ecc62c66 100644 --- a/commands/devinfo.c +++ b/commands/devinfo.c @@ -104,7 +104,7 @@ static int do_devinfo(int argc, char *argv[]) #ifdef CONFIG_OFDEVICE if (dev->device_node) { printf("Device node: %s\n", dev->device_node->full_name); - of_print_nodes(dev->device_node, 0); + of_print_nodes(dev->device_node, 0, ~0); } #endif } diff --git a/commands/of_dump.c b/commands/of_dump.c index 6f36b3151458..c2ca8485cd5d 100644 --- a/commands/of_dump.c +++ b/commands/of_dump.c @@ -39,9 +39,10 @@ static int do_of_dump(int argc, char *argv[]) char *dtbfile = NULL; size_t size; const char *nodename; + unsigned maxpropsize = ~0; int names_only = 0, properties_only = 0; - while ((opt = getopt(argc, argv, "Ff:np")) > 0) { + while ((opt = getopt(argc, argv, "Ff:npP:")) > 0) { switch (opt) { case 'f': dtbfile = optarg; @@ -55,6 +56,11 @@ static int do_of_dump(int argc, char *argv[]) case 'p': properties_only = 1; break; + case 'P': + ret = kstrtouint(optarg, 0, &maxpropsize); + if (ret) + return ret; + break; default: return COMMAND_ERROR_USAGE; } @@ -120,9 +126,9 @@ static int do_of_dump(int argc, char *argv[]) if (names_only && !properties_only) of_print_nodenames(node); else if (properties_only && !names_only) - of_print_properties(node); + of_print_properties(node, maxpropsize); else - of_print_nodes(node, 0); + of_print_nodes(node, 0, maxpropsize); out: if (of_free) @@ -137,12 +143,13 @@ BAREBOX_CMD_HELP_OPT ("-f dtb", "work on dtb instead of internal devicetree") BAREBOX_CMD_HELP_OPT ("-F", "return fixed devicetree") BAREBOX_CMD_HELP_OPT ("-n", "Print node names only, no properties") BAREBOX_CMD_HELP_OPT ("-p", "Print properties only, no child nodes") +BAREBOX_CMD_HELP_OPT ("-P len", "print only len property bytes") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(of_dump) .cmd = do_of_dump, BAREBOX_CMD_DESC("dump devicetree nodes") - BAREBOX_CMD_OPTS("[-fFnp] [NODE]") + BAREBOX_CMD_OPTS("[-fFnpP] [NODE]") BAREBOX_CMD_GROUP(CMD_GRP_MISC) BAREBOX_CMD_COMPLETE(devicetree_file_complete) BAREBOX_CMD_HELP(cmd_of_dump_help) diff --git a/common/bootm.c b/common/bootm.c index 269a40beafa1..0c1d28d8ebaf 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -461,7 +461,7 @@ int bootm_load_devicetree(struct image_data *data, void *fdt, of_print_cmdline(data->of_root_node); if (bootm_verbose(data) > 1) - of_print_nodes(data->of_root_node, 0); + of_print_nodes(data->of_root_node, 0, ~0); return 0; } diff --git a/common/image-fit.c b/common/image-fit.c index a410632d7019..507a857cadb4 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -641,7 +641,7 @@ static int fit_config_verify_signature(struct fit_handle *handle, struct device_ for_each_child_of_node(conf_node, sig_node) { if (handle->verbose) - of_print_nodes(sig_node, 0); + of_print_nodes(sig_node, 0, ~0); ret = fit_verify_signature(sig_node, handle->fit); if (ret < 0) return ret; diff --git a/drivers/of/base.c b/drivers/of/base.c index ac5a14f49919..2247b5a1a348 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2007,22 +2007,25 @@ int of_property_read_string_helper(const struct device_node *np, } static void __of_print_property_prefixed(const struct property *p, int indent, - const char *prefix) + unsigned maxpropsize, const char *prefix) { unsigned length; printf("%s%*s%s", prefix, indent * 8, "", p->name); - length = p->length; + length = min_t(unsigned, p->length, maxpropsize); if (length) { printf(" = "); of_print_property(of_property_get_value(p), length); } + if (length != p->length) + printf(" /* %u more bytes omitted */", p->length - length); printf(";\n"); } -static int __of_print_nodes(struct device_node *node, int indent, const char *prefix) +static int __of_print_nodes(struct device_node *node, int indent, + unsigned maxpropsize, const char *prefix) { struct device_node *n; struct property *p; @@ -2037,13 +2040,13 @@ static int __of_print_nodes(struct device_node *node, int indent, const char *pr printf("%s%*s%s%s\n", prefix, indent * 8, "", node->name, node->name ? " {" : "{"); list_for_each_entry(p, &node->properties, list) - __of_print_property_prefixed(p, indent + 1, prefix); + __of_print_property_prefixed(p, indent + 1, maxpropsize, prefix); if (ctrlc()) return -EINTR; list_for_each_entry(n, &node->children, parent_list) { - ret = __of_print_nodes(n, indent + 1, prefix); + ret = __of_print_nodes(n, indent + 1, maxpropsize, prefix); if (ret) return ret; } @@ -2052,22 +2055,22 @@ static int __of_print_nodes(struct device_node *node, int indent, const char *pr return 0; } -void of_print_nodes(struct device_node *node, int indent) +void of_print_nodes(struct device_node *node, int indent, unsigned maxpropsize) { - __of_print_nodes(node, indent, NULL); + __of_print_nodes(node, indent, maxpropsize, NULL); } -static void __of_print_property(struct property *p, int indent) +static void __of_print_property(struct property *p, int indent, unsigned maxpropsize) { - __of_print_property_prefixed(p, indent, ""); + __of_print_property_prefixed(p, indent, maxpropsize, ""); } -void of_print_properties(struct device_node *node) +void of_print_properties(struct device_node *node, unsigned maxpropsize) { struct property *prop; list_for_each_entry(prop, &node->properties, list) - __of_print_property(prop, 0); + __of_print_property(prop, 0, maxpropsize); } static int __of_print_parents(struct device_node *node) @@ -2135,7 +2138,7 @@ int of_diff(struct device_node *a, struct device_node *b, int indent) continue; of_print_parents(a, &printed); printf("- "); - __of_print_property(ap, indent); + __of_print_property(ap, indent, ~0); continue; } @@ -2145,9 +2148,9 @@ int of_diff(struct device_node *a, struct device_node *b, int indent) continue; of_print_parents(a, &printed); printf("- "); - __of_print_property(ap, indent); + __of_print_property(ap, indent, ~0); printf("+ "); - __of_print_property(bp, indent); + __of_print_property(bp, indent, ~0); } } @@ -2159,7 +2162,7 @@ int of_diff(struct device_node *a, struct device_node *b, int indent) continue; of_print_parents(a, &printed); printf("+ "); - __of_print_property(bp, indent); + __of_print_property(bp, indent, ~0); } } @@ -2172,7 +2175,7 @@ int of_diff(struct device_node *a, struct device_node *b, int indent) if (silent) continue; of_print_parents(a, &printed); - __of_print_nodes(ca, indent, "- "); + __of_print_nodes(ca, indent, ~0, "- "); } } @@ -2182,7 +2185,7 @@ int of_diff(struct device_node *a, struct device_node *b, int indent) if (silent) continue; of_print_parents(a, &printed); - __of_print_nodes(cb, indent, "+ "); + __of_print_nodes(cb, indent, ~0, "+ "); } } diff --git a/include/of.h b/include/of.h index 3c5f14e167c5..4aadbb7edb49 100644 --- a/include/of.h +++ b/include/of.h @@ -105,8 +105,8 @@ static inline const void *of_property_get_value(const struct property *pp) void of_print_property(const void *data, int len); void of_print_cmdline(struct device_node *root); -void of_print_nodes(struct device_node *node, int indent); -void of_print_properties(struct device_node *node); +void of_print_nodes(struct device_node *node, int indent, unsigned maxpropsize); +void of_print_properties(struct device_node *node, unsigned maxpropsize); int of_diff(struct device_node *a, struct device_node *b, int indent); int of_probe(void); int of_parse_dtb(struct fdt_header *fdt); -- 2.30.2