* [PATCH 1/2] of: base: factor out duplication for property formatting
@ 2022-08-08 6:56 Ahmad Fatoum
2022-08-08 6:56 ` [PATCH 2/2] commands: of_dump: support limiting size of printed properties Ahmad Fatoum
2022-08-08 11:18 ` [PATCH 1/2] of: base: factor out duplication for property formatting Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-08-08 6:56 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We have the same chunk of code with minuscule difference in both
__of_print_nodes and __of_print_property. Factor it out to simplify
the follow-up commit.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/of/base.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 101b2f74c74f..ac5a14f49919 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2006,6 +2006,22 @@ int of_property_read_string_helper(const struct device_node *np,
return i <= 0 ? -ENODATA : i;
}
+static void __of_print_property_prefixed(const struct property *p, int indent,
+ const char *prefix)
+{
+ unsigned length;
+
+ printf("%s%*s%s", prefix, indent * 8, "", p->name);
+
+ length = p->length;
+ if (length) {
+ printf(" = ");
+ of_print_property(of_property_get_value(p), length);
+ }
+
+ printf(";\n");
+}
+
static int __of_print_nodes(struct device_node *node, int indent, const char *prefix)
{
struct device_node *n;
@@ -2020,14 +2036,8 @@ 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) {
- printf("%s%*s%s", prefix, (indent + 1) * 8, "", p->name);
- if (p->length) {
- printf(" = ");
- of_print_property(of_property_get_value(p), p->length);
- }
- printf(";\n");
- }
+ list_for_each_entry(p, &node->properties, list)
+ __of_print_property_prefixed(p, indent + 1, prefix);
if (ctrlc())
return -EINTR;
@@ -2049,12 +2059,7 @@ void of_print_nodes(struct device_node *node, int indent)
static void __of_print_property(struct property *p, int indent)
{
- printf("%*s%s", indent * 8, "", p->name);
- if (p->length) {
- printf(" = ");
- of_print_property(of_property_get_value(p), p->length);
- }
- printf(";\n");
+ __of_print_property_prefixed(p, indent, "");
}
void of_print_properties(struct device_node *node)
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] commands: of_dump: support limiting size of printed properties
2022-08-08 6:56 [PATCH 1/2] of: base: factor out duplication for property formatting Ahmad Fatoum
@ 2022-08-08 6:56 ` Ahmad Fatoum
2022-08-08 11:18 ` [PATCH 1/2] of: base: factor out duplication for property formatting Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-08-08 6:56 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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@pengutronix.de>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] of: base: factor out duplication for property formatting
2022-08-08 6:56 [PATCH 1/2] of: base: factor out duplication for property formatting Ahmad Fatoum
2022-08-08 6:56 ` [PATCH 2/2] commands: of_dump: support limiting size of printed properties Ahmad Fatoum
@ 2022-08-08 11:18 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-08-08 11:18 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Aug 08, 2022 at 08:56:38AM +0200, Ahmad Fatoum wrote:
> We have the same chunk of code with minuscule difference in both
> __of_print_nodes and __of_print_property. Factor it out to simplify
> the follow-up commit.
>
> No functional change.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/of/base.c | 33 +++++++++++++++++++--------------
> 1 file changed, 19 insertions(+), 14 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 101b2f74c74f..ac5a14f49919 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2006,6 +2006,22 @@ int of_property_read_string_helper(const struct device_node *np,
> return i <= 0 ? -ENODATA : i;
> }
>
> +static void __of_print_property_prefixed(const struct property *p, int indent,
> + const char *prefix)
> +{
> + unsigned length;
> +
> + printf("%s%*s%s", prefix, indent * 8, "", p->name);
> +
> + length = p->length;
> + if (length) {
> + printf(" = ");
> + of_print_property(of_property_get_value(p), length);
> + }
> +
> + printf(";\n");
> +}
> +
> static int __of_print_nodes(struct device_node *node, int indent, const char *prefix)
> {
> struct device_node *n;
> @@ -2020,14 +2036,8 @@ 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) {
> - printf("%s%*s%s", prefix, (indent + 1) * 8, "", p->name);
> - if (p->length) {
> - printf(" = ");
> - of_print_property(of_property_get_value(p), p->length);
> - }
> - printf(";\n");
> - }
> + list_for_each_entry(p, &node->properties, list)
> + __of_print_property_prefixed(p, indent + 1, prefix);
>
> if (ctrlc())
> return -EINTR;
> @@ -2049,12 +2059,7 @@ void of_print_nodes(struct device_node *node, int indent)
>
> static void __of_print_property(struct property *p, int indent)
> {
> - printf("%*s%s", indent * 8, "", p->name);
> - if (p->length) {
> - printf(" = ");
> - of_print_property(of_property_get_value(p), p->length);
> - }
> - printf(";\n");
> + __of_print_property_prefixed(p, indent, "");
> }
>
> void of_print_properties(struct device_node *node)
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-08 11:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08 6:56 [PATCH 1/2] of: base: factor out duplication for property formatting Ahmad Fatoum
2022-08-08 6:56 ` [PATCH 2/2] commands: of_dump: support limiting size of printed properties Ahmad Fatoum
2022-08-08 11:18 ` [PATCH 1/2] of: base: factor out duplication for property formatting Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox