From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] commands: of_diff: support applying fixups on arbitrary device trees
Date: Thu, 8 Jun 2023 15:40:44 +0200 [thread overview]
Message-ID: <20230608134040.2123869-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230608134040.2123869-1-a.fatoum@pengutronix.de>
of_diff - + is quite useful to find what fixups barebox would apply to
its own device tree. But for some cases, like barebox-state or OP-TEE
reservations, the nodes that would be fixed up into the kernel device
tree already exist within the barebox device tree and wouldn't be shown
by of_diff - +. To make them visible, let's redefine +:
- Previously, it always meant the fixed up barebox DT
- Now, it means the other DT with fixups applied
That way, of_diff - + continues to work, but kernel DTs can now be
diffed against their fixed up version by doing:
of_diff /mnt/tftp/afa-oftree-myboard +
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/of_diff.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/commands/of_diff.c b/commands/of_diff.c
index ff3d46c7f530..8b19c093ddab 100644
--- a/commands/of_diff.c
+++ b/commands/of_diff.c
@@ -17,15 +17,10 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro
{
struct device_node *node;
- if (!root)
- root = ERR_PTR(-ENOENT);
-
if (!strcmp(filename, "-")) {
- node = of_dup(root);
+ node = of_dup(root) ?: ERR_PTR(-ENOENT);
} else if (!strcmp(filename, "+")) {
- node = of_dup(root);
- if (!IS_ERR(node))
- of_fix_tree(node);
+ return NULL;
} else {
node = of_read_file(filename);
}
@@ -36,6 +31,17 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro
return node;
}
+static struct device_node *get_tree_fixed(const struct device_node *root)
+{
+ struct device_node *node;
+
+ node = of_dup(root);
+ if (!IS_ERR(node))
+ of_fix_tree(node);
+
+ return node;
+}
+
static int do_of_diff(int argc, char *argv[])
{
int ret = COMMAND_ERROR;
@@ -48,6 +54,14 @@ static int do_of_diff(int argc, char *argv[])
a = get_tree(argv[1], root);
b = get_tree(argv[2], root);
+ if (!a && !b)
+ return COMMAND_ERROR_USAGE;
+
+ if (!a)
+ a = get_tree_fixed(b);
+ if (!b)
+ b = get_tree_fixed(a);
+
if (!IS_ERR(a) && !IS_ERR(b))
ret = of_diff(a, b, 0) ? COMMAND_ERROR : COMMAND_SUCCESS;
@@ -63,7 +77,7 @@ BAREBOX_CMD_HELP_START(of_diff)
BAREBOX_CMD_HELP_TEXT("This command prints a diff between two given device trees.")
BAREBOX_CMD_HELP_TEXT("The device trees are given as dtb files or:")
BAREBOX_CMD_HELP_TEXT("'-' to compare against the barebox live tree, or")
-BAREBOX_CMD_HELP_TEXT("'+' to compare against the fixed barebox live tree")
+BAREBOX_CMD_HELP_TEXT("'+' to compare against the other device tree after fixups")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(of_diff)
--
2.39.2
next prev parent reply other threads:[~2023-06-08 13:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 13:40 [PATCH 0/3] " Ahmad Fatoum
2023-06-08 13:40 ` [PATCH 1/3] of: change superfluous of_fix_tree int return type to void Ahmad Fatoum
2023-06-08 13:40 ` [PATCH 2/3] commands: of_diff: simplify error handling Ahmad Fatoum
2023-06-13 11:48 ` Johannes Zink
2023-06-08 13:40 ` Ahmad Fatoum [this message]
2023-06-09 6:41 ` [PATCH 0/3] commands: of_diff: support applying fixups on arbitrary device trees 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=20230608134040.2123869-4-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