diff options
Diffstat (limited to 'commands/of_diff.c')
-rw-r--r-- | commands/of_diff.c | 82 |
1 files changed, 31 insertions, 51 deletions
diff --git a/commands/of_diff.c b/commands/of_diff.c index 8ef006dea8..623b033c73 100644 --- a/commands/of_diff.c +++ b/commands/of_diff.c @@ -1,10 +1,7 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * of_diff.c - compare device tree files - * - * Copyright (c) 2019 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix - * - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: © 2019 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + +/* of_diff.c - compare device tree files */ #include <common.h> #include <fs.h> @@ -19,74 +16,57 @@ static struct device_node *get_tree(const char *filename, struct device_node *root) { struct device_node *node; - void *fdt; - size_t size; - int ret; if (!strcmp(filename, "-")) { - node = of_get_root_node(); - if (!node) - return ERR_PTR(-ENOENT); - - return of_copy_node(NULL, node); + node = of_dup(root) ?: ERR_PTR(-ENOENT); + if (IS_ERR(node)) + printf("Cannot duplicate live tree: %pe\n", node); + } else if (!strcmp(filename, "+")) { + return NULL; + } else { + node = of_read_file(filename); } - if (!strcmp(filename, "+")) { - node = of_get_root_node(); - if (!node) - return ERR_PTR(-ENOENT); + return node; +} - node = of_copy_node(NULL, root); +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; - } - - ret = read_file_2(filename, &size, &fdt, FILESIZE_MAX); - if (ret) - return ERR_PTR(ret); - - node = of_unflatten_dtb(fdt); - - free(fdt); - return node; } static int do_of_diff(int argc, char *argv[]) { - int ret = 0; + int ret = COMMAND_ERROR; struct device_node *a, *b, *root; - if (argc < 3) + if (argc != 3) return COMMAND_ERROR_USAGE; root = of_get_root_node(); a = get_tree(argv[1], root); b = get_tree(argv[2], root); - if (IS_ERR(a)) { - printf("Cannot read %s: %s\n", argv[1], strerrorp(a)); - ret = COMMAND_ERROR; - a = NULL; - goto out; - } + if (!a && !b) + return COMMAND_ERROR_USAGE; - if (IS_ERR(b)) { - printf("Cannot read %s: %s\n", argv[2], strerrorp(b)); - ret = COMMAND_ERROR; - b = NULL; - goto out; - } + if (!a) + a = get_tree_fixed(b); + if (!b) + b = get_tree_fixed(a); - of_diff(a, b, 0); + if (!IS_ERR(a) && !IS_ERR(b)) + ret = of_diff(a, b, 0) ? COMMAND_ERROR : COMMAND_SUCCESS; - ret = 0; -out: - if (a && a != root) + if (!IS_ERR(a) && a != root) of_delete_node(a); - if (b && b != root) + if (!IS_ERR(b) && b != root) of_delete_node(b); return ret; @@ -96,7 +76,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) |