[PATCH 09/10] commands: oftree: add option to return device tree without fixups
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed May 28 03:50:45 PDT 2025
When extracting the barebox device tree to use as argument to bootm when
BOOTM_OFTREE_FALLBACK is disabled, we will not want to apply fixups
twice, so add to oftree a -S option that just flattens the barebox
device tree as-is.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
commands/Kconfig | 8 ++++----
commands/oftree.c | 14 +++++++++-----
common/oftree.c | 22 ++++++++++++----------
include/of.h | 14 ++++++++++++--
4 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/commands/Kconfig b/commands/Kconfig
index 0f3155d123ab..7b84ef70e875 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2530,13 +2530,13 @@ config CMD_OFTREE
help
oftree - handle device trees
- Usage: oftree [-lspf] [DTB]
+ Usage: oftree [-lsSp]
Options:
- -l Load DTB to internal device tree
- -s save internal device tree to DTB
+ -l <DTB> Load <DTB> to internal device tree
+ -s <DTB> save internal device tree with fixups to <DTB>
+ -S <DTB> save internal device tree without fixups to <DTB>
-p probe devices from stored device tree
- -f free stored device tree
config CMD_TIME
bool "time"
diff --git a/commands/oftree.c b/commands/oftree.c
index 3adc660a77e0..b172aee9e074 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -32,13 +32,13 @@ static int do_oftree(int argc, char *argv[])
{
struct fdt_header *fdt = NULL;
int opt;
- int probe = 0;
+ int probe = 0, fixup = 0;
char *load = NULL;
char *save = NULL;
int ret;
struct device_node *root;
- while ((opt = getopt(argc, argv, "pfl:s:")) > 0) {
+ while ((opt = getopt(argc, argv, "pfl:s:S:")) > 0) {
switch (opt) {
case 'l':
load = optarg;
@@ -52,6 +52,9 @@ static int do_oftree(int argc, char *argv[])
}
break;
case 's':
+ fixup = 1;
+ fallthrough;
+ case 'S':
save = optarg;
break;
}
@@ -61,7 +64,7 @@ static int do_oftree(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
if (save) {
- fdt = of_get_fixed_tree(NULL);
+ fdt = of_get_flattened_tree(NULL, fixup);
if (!fdt) {
printf("no devicetree available\n");
ret = -EINVAL;
@@ -102,14 +105,15 @@ static int do_oftree(int argc, char *argv[])
BAREBOX_CMD_HELP_START(oftree)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-l <DTB>", "Load <DTB> to internal devicetree")
-BAREBOX_CMD_HELP_OPT ("-s <DTB>", "save internal devicetree to <DTB>")
+BAREBOX_CMD_HELP_OPT ("-s <DTB>", "save internal devicetree after fixups to <DTB>")
+BAREBOX_CMD_HELP_OPT ("-S <DTB>", "save internal devicetree without fixups to <DTB>")
BAREBOX_CMD_HELP_OPT ("-p", "probe devices from stored device tree")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(oftree)
.cmd = do_oftree,
BAREBOX_CMD_DESC("handle device trees")
- BAREBOX_CMD_OPTS("[-lsp]")
+ BAREBOX_CMD_OPTS("[-lsSp]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_HELP(cmd_oftree_help)
BAREBOX_CMD_END
diff --git a/common/oftree.c b/common/oftree.c
index b9a854c786f6..58e96c39d897 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -413,15 +413,14 @@ void of_fix_tree(struct device_node *node)
}
/*
- * Get the fixed fdt. This function uses the fdt input pointer
+ * Get the fdt. This function uses the fdt input pointer
* if provided or the barebox internal devicetree if not.
- * It increases the size of the tree and applies the registered
- * fixups.
*/
-struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+struct fdt_header *of_get_flattened_tree(const struct device_node *node,
+ bool fixup)
{
struct fdt_header *fdt = NULL;
- struct device_node *np;
+ struct device_node *np = NULL;
if (!node) {
node = of_get_root_node();
@@ -429,16 +428,19 @@ struct fdt_header *of_get_fixed_tree(const struct device_node *node)
return NULL;
}
- np = of_dup(node);
+ if (fixup)
+ node = np = of_dup(node);
- if (!np)
+ if (!node)
return NULL;
- of_fix_tree(np);
+ if (fixup)
+ of_fix_tree(np);
- fdt = of_flatten_dtb(np);
+ fdt = of_flatten_dtb((struct device_node *)node);
- of_delete_node(np);
+ if (fixup)
+ of_delete_node(np);
return fdt;
}
diff --git a/include/of.h b/include/of.h
index a9bd37fdca2f..f08ac8ccca69 100644
--- a/include/of.h
+++ b/include/of.h
@@ -323,7 +323,7 @@ extern const char *of_parse_phandle_and_get_alias_from(struct device_node *root,
int index);
extern struct device_node *of_get_root_node(void);
-extern struct fdt_header *of_get_fixed_tree(const struct device_node *node);
+extern struct fdt_header *of_get_flattened_tree(const struct device_node *node, bool fixup);
extern int of_set_root_node(struct device_node *node);
extern int barebox_register_of(struct device_node *root);
extern int barebox_register_fdt(const void *dtb);
@@ -466,7 +466,7 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
-static inline struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+static inline struct fdt_header *of_get_flattened_tree(const struct device_node *node, bool fixup)
{
return NULL;
}
@@ -1358,6 +1358,16 @@ static inline struct device_node *of_find_root_node(struct device_node *node)
return node;
}
+/*
+ * Get the fixed fdt. This function uses the fdt input pointer
+ * if provided or the barebox internal devicetree if not.
+ * It increases the size of the tree and applies the registered
+ * fixups.
+ */
+static inline struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+{
+ return of_get_flattened_tree(node, true);
+}
static inline struct fdt_header *of_get_fixed_tree_for_boot(const struct device_node *node)
{
--
2.39.5
More information about the barebox
mailing list