summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-06-08 15:40:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-06-09 08:41:45 +0200
commitecd7854b9c661571137802bfc831c9fb07cbe820 (patch)
tree0b332fbec74397ee2c933de5d79232fa5fa65ae4 /commands
parent2cc56260a049afc35152f04f28820b1314e8c4e3 (diff)
downloadbarebox-ecd7854b9c661571137802bfc831c9fb07cbe820.tar.gz
barebox-ecd7854b9c661571137802bfc831c9fb07cbe820.tar.xz
commands: of_diff: support applying fixups on arbitrary device trees
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> Link: https://lore.barebox.org/20230608134040.2123869-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/of_diff.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/commands/of_diff.c b/commands/of_diff.c
index ff3d46c7f5..8b19c093dd 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)