From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 08/10] bootm: make fallback to barebox internal tree optional
Date: Wed, 28 May 2025 12:50:44 +0200 [thread overview]
Message-ID: <20250528105046.3270397-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250528105046.3270397-1-a.fatoum@pengutronix.de>
barebox substituting its own device tree in place of a missing kernel
is often not what the user intended. Add a config option to disable
this, so users notice right away that they didn't supply a kernel device
tree.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/arm/lib32/bootm.c | 2 +-
arch/arm/lib32/bootu.c | 11 ++++++++---
arch/arm/lib32/bootz.c | 9 ++++++---
arch/powerpc/lib/ppclinux.c | 2 +-
common/Kconfig | 18 ++++++++++++++++++
common/bootm.c | 9 +++------
include/of.h | 25 +++++++++++++++++++++++--
7 files changed, 60 insertions(+), 16 deletions(-)
diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index 32af112ae8c8..963c83051de0 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -428,7 +428,7 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data, void **outfdt)
pr_err("unable to unflatten devicetree\n");
goto err_free;
}
- *outfdt = of_get_fixed_tree(root);
+ *outfdt = of_get_fixed_tree_for_boot(root);
if (!*outfdt) {
pr_err("Unable to get fixed tree\n");
ret = -EINVAL;
diff --git a/arch/arm/lib32/bootu.c b/arch/arm/lib32/bootu.c
index 31c3c56cc597..4b0f495aea5f 100644
--- a/arch/arm/lib32/bootu.c
+++ b/arch/arm/lib32/bootu.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
+#define pr_fmt(fmt) "bootu: " fmt
+
#include <common.h>
#include <command.h>
#include <fs.h>
@@ -24,9 +26,12 @@ static int do_bootu(int argc, char *argv[])
if (!kernel)
kernel = (void *)simple_strtoul(argv[1], NULL, 0);
-#ifdef CONFIG_OFTREE
- oftree = of_get_fixed_tree(NULL);
-#endif
+ oftree = of_get_fixed_tree_for_boot(NULL);
+ if (!oftree) {
+ pr_err("No devicetree given.\n");
+ return -EINVAL;
+ }
+
ret = of_overlay_load_firmware();
if (ret)
return ret;
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index 8e8b0d225ecf..ab275c367711 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -110,9 +110,12 @@ static int do_bootz(int argc, char *argv[])
}
printf("loaded zImage from %s with size %d\n", argv[1], end);
-#ifdef CONFIG_OFTREE
- oftree = of_get_fixed_tree(NULL);
-#endif
+ oftree = of_get_fixed_tree_for_boot(NULL);
+ if (!oftree) {
+ printf("No devicetree given.\n");
+ return -EINVAL;
+ }
+
ret = of_overlay_load_firmware();
if (ret)
return ret;
diff --git a/arch/powerpc/lib/ppclinux.c b/arch/powerpc/lib/ppclinux.c
index 6b00c2ee5756..564086482e5f 100644
--- a/arch/powerpc/lib/ppclinux.c
+++ b/arch/powerpc/lib/ppclinux.c
@@ -60,7 +60,7 @@ static int do_bootm_linux(struct image_data *data)
if (ret)
return ret;
- fdt = of_get_fixed_tree(data->of_root_node);
+ fdt = of_get_fixed_tree_for_boot(data->of_root_node);
if (!fdt) {
pr_err("bootm: No devicetree given.\n");
return -EINVAL;
diff --git a/common/Kconfig b/common/Kconfig
index 0a7d9aee3abe..da19cb8d9980 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -642,6 +642,24 @@ config BOOTM_OFTREE
-o DTS specify device tree
+config BOOTM_OFTREE_FALLBACK
+ def_bool y
+ # We intentionally don't depend on BOOTM_OFTREE, because many boards
+ # don't enable it and instead rely on OFTREE being selected...
+ depends on BOOTM && HAVE_ARCH_BOOTM_OFTREE && OFTREE
+ prompt "pass along barebox' own DT as fallback"
+ help
+ Say y here to substitute in the barebox device tree, when no kernel
+ device tree was supplied. If unsure, say n.
+
+ It's recommended to boot a kernel with the device tree that was
+ shipped with it as DT binding breakage is not an infrequent
+ occurrence.
+
+ This especially applies to A/B boot setups, where each kernel
+ should have its own DT, so fallback restores the system cleanly
+ to the old state.
+
config BOOTM_UIMAGE
def_bool y
prompt "support the legacy uImage format"
diff --git a/common/bootm.c b/common/bootm.c
index 4aebc8a66abd..b98dc2715914 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -484,14 +484,11 @@ void *bootm_get_devicetree(struct image_data *data)
}
} else {
- struct device_node *root = of_get_root_node();
-
- if (!root)
+ data->of_root_node = of_dup_root_node_for_boot();
+ if (!data->of_root_node)
return NULL;
- data->of_root_node = of_dup(root);
-
- if (bootm_verbose(data) > 1 && data->of_root_node)
+ if (bootm_verbose(data) > 1)
printf("using internal devicetree\n");
}
diff --git a/include/of.h b/include/of.h
index e46d410d3651..a9bd37fdca2f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -80,8 +80,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
struct fdt_header *fdt_get_tree(void);
-struct fdt_header *of_get_fixed_tree(const struct device_node *node);
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
@@ -325,6 +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 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);
@@ -467,6 +466,11 @@ 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)
+{
+ return NULL;
+}
+
static inline int of_set_root_node(struct device_node *node)
{
return -ENOSYS;
@@ -1354,6 +1358,23 @@ static inline struct device_node *of_find_root_node(struct device_node *node)
return node;
}
+
+static inline struct fdt_header *of_get_fixed_tree_for_boot(const struct device_node *node)
+{
+ if (!IS_ENABLED(CONFIG_BOOTM_OFTREE_FALLBACK) && !node)
+ return NULL;
+
+ return of_get_fixed_tree(node);
+}
+
+static inline struct device_node *of_dup_root_node_for_boot(void)
+{
+ if (!IS_ENABLED(CONFIG_BOOTM_OFTREE_FALLBACK))
+ return NULL;
+
+ return of_dup(of_get_root_node());
+}
+
struct of_overlay_filter {
bool (*filter_filename)(struct of_overlay_filter *, const char *filename);
bool (*filter_content)(struct of_overlay_filter *, struct device_node *);
--
2.39.5
next prev parent reply other threads:[~2025-05-28 12:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 01/10] arch: add new HAVE_ARCH_BOOTM_OFTREE symbol Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 02/10] bootm: enable CONFIG_BOOTM_OFTREE by default Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 03/10] ARM: lib32: disable ATAGS support " Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 04/10] kvx: bootm: enforce existence of device tree Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 05/10] bootm: booti: make device tree optional Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 06/10] filetype: add new file type for 0-sized files Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 07/10] bootm: have bootm_get_devicetree return NULL if passed empty DT Ahmad Fatoum
2025-05-28 10:50 ` Ahmad Fatoum [this message]
2025-05-28 10:50 ` [PATCH 09/10] commands: oftree: add option to return device tree without fixups Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 10/10] of: drop undefined fdt_get_tree declaration Ahmad Fatoum
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=20250528105046.3270397-9-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