From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] commands: of_dump: implement -p for printing properties only
Date: Thu, 27 May 2021 14:44:06 +0200 [thread overview]
Message-ID: <20210527124406.22121-1-a.fatoum@pengutronix.de> (raw)
Some boards rewrite root node properties like compatible and
serial-number. Checking them can be annoying, because the properties
have usually long scrolled by, by the time the device tree was
completely dumped. Add a -p option to print only properties.
-p -n (print only node names AND only properties) is interpreted
to cancel each other out, so the whole device tree is dumped normally.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/of_dump.c | 14 ++++++++++----
drivers/of/base.c | 8 ++++++++
include/of.h | 1 +
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/commands/of_dump.c b/commands/of_dump.c
index 6792af3afc31..2089c07ef79b 100644
--- a/commands/of_dump.c
+++ b/commands/of_dump.c
@@ -36,9 +36,9 @@ static int do_of_dump(int argc, char *argv[])
char *dtbfile = NULL;
size_t size;
const char *nodename;
- int names_only = 0;
+ int names_only = 0, properties_only = 0;
- while ((opt = getopt(argc, argv, "Ff:n")) > 0) {
+ while ((opt = getopt(argc, argv, "Ff:np")) > 0) {
switch (opt) {
case 'f':
dtbfile = optarg;
@@ -49,6 +49,9 @@ static int do_of_dump(int argc, char *argv[])
case 'n':
names_only = 1;
break;
+ case 'p':
+ properties_only = 1;
+ break;
default:
return COMMAND_ERROR_USAGE;
}
@@ -111,8 +114,10 @@ static int do_of_dump(int argc, char *argv[])
goto out;
}
- if (names_only)
+ if (names_only && !properties_only)
of_print_nodenames(node);
+ else if (properties_only && !names_only)
+ of_print_properties(node);
else
of_print_nodes(node, 0);
@@ -128,12 +133,13 @@ BAREBOX_CMD_HELP_TEXT("Options:")
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_END
BAREBOX_CMD_START(of_dump)
.cmd = do_of_dump,
BAREBOX_CMD_DESC("dump devicetree nodes")
- BAREBOX_CMD_OPTS("[-fFn] [NODE]")
+ BAREBOX_CMD_OPTS("[-fFnp] [NODE]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_COMPLETE(devicetree_file_complete)
BAREBOX_CMD_HELP(cmd_of_dump_help)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6fe02649ee53..e103eed90af1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2002,6 +2002,14 @@ static void __of_print_property(struct property *p, int indent)
printf(";\n");
}
+void of_print_properties(struct device_node *node)
+{
+ struct property *prop;
+
+ list_for_each_entry(prop, &node->properties, list)
+ __of_print_property(prop, 0);
+}
+
static int __of_print_parents(struct device_node *node)
{
int indent, i;
diff --git a/include/of.h b/include/of.h
index 645f429bdeed..55e6bff8689e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -105,6 +105,7 @@ 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_diff(struct device_node *a, struct device_node *b, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2021-05-27 12:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-27 12:44 Ahmad Fatoum [this message]
2021-05-31 7:01 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210527124406.22121-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox