* [PATCH 0/3] make dtb from 1st stage loader available in barebox
@ 2024-12-09 14:28 Sascha Hauer
2024-12-09 14:28 ` [PATCH 1/3] fdt: Add function to check if a pointer contains a fdt Sascha Hauer
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-09 14:28 UTC (permalink / raw)
To: open list:BAREBOX
When barebox is chainloaded from another bootloader it usually gets
passed a device tree from the previous bootloader. While this external
device tree is normally not used by barebox, its contents can still be
interesting, so store the device tree at /external-devicetree when
found. This needs board support to pass the external device tree in
handoff data, i.e. a board has to call
handoff_data_add(HANDOFF_DATA_EXTERNAL_DT, dtb, size);
This series adds beagleplay support for this feature as an example.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Sascha Hauer (3):
fdt: Add function to check if a pointer contains a fdt
store external device tree as file
ARM: beagleplay: put external device tree into handoff data
arch/arm/boards/beagleplay/lowlevel.c | 14 ++++++++++----
common/startup.c | 8 ++++++++
include/compressed-dtb.h | 24 ++++++++++++++++++++++++
3 files changed, 42 insertions(+), 4 deletions(-)
---
base-commit: 873b572763d38ab4100d218d0a3614f79b596077
change-id: 20241209-ext-dt-handoff-0594e0ae33b2
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] fdt: Add function to check if a pointer contains a fdt
2024-12-09 14:28 [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
@ 2024-12-09 14:28 ` Sascha Hauer
2024-12-09 14:28 ` [PATCH 2/3] store external device tree as file Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-09 14:28 UTC (permalink / raw)
To: open list:BAREBOX
When barebox is started 2nd stage from another barebox or U-Boot it
usually gets a device tree passed in a register. We can't rely on this
though, so before assuming a pointer has a device tree we need to
perform some basic checks for being in a certain range, is sufficiently
aligned and actually contains a device tree.
This adds a function performing these checks.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/compressed-dtb.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/include/compressed-dtb.h b/include/compressed-dtb.h
index 3359d1ee11..cc5fbb2769 100644
--- a/include/compressed-dtb.h
+++ b/include/compressed-dtb.h
@@ -3,6 +3,7 @@
#define COMPRESSED_DTB_H_
#include <linux/types.h>
+#include <linux/sizes.h>
#include <asm/unaligned.h>
struct barebox_boarddata_compressed_dtb {
@@ -31,4 +32,27 @@ static inline bool blob_is_fdt(const void *blob)
return get_unaligned_be32(blob) == FDT_MAGIC;
}
+static inline bool blob_is_valid_fdt_ptr(const void *blob, unsigned long mem_start,
+ unsigned long mem_size, unsigned int *fdt_size)
+{
+ unsigned long dtb = (unsigned long)blob;
+ unsigned int size;
+
+ if (!IS_ALIGNED(dtb, 4))
+ return false;
+ if (dtb < mem_start || dtb >= mem_start + mem_size)
+ return false;
+ if (!blob_is_fdt(blob))
+ return false;
+
+ size = be32_to_cpup(blob + 4);
+ if (size > SZ_2M || dtb + size > mem_start + mem_size)
+ return false;
+
+ if (fdt_size)
+ *fdt_size = size;
+
+ return true;
+}
+
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] store external device tree as file
2024-12-09 14:28 [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
2024-12-09 14:28 ` [PATCH 1/3] fdt: Add function to check if a pointer contains a fdt Sascha Hauer
@ 2024-12-09 14:28 ` Sascha Hauer
2024-12-09 14:28 ` [PATCH 3/3] ARM: beagleplay: put external device tree into handoff data Sascha Hauer
2024-12-16 8:31 ` [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-09 14:28 UTC (permalink / raw)
To: open list:BAREBOX
When barebox is chainloaded from another bootloader it usually gets
passed a device tree from the previous bootloader. While this external
device tree is normally not used by barebox, its contents can still be
interesting, so store the device tree at /external-devicetree when
found. This needs board support to pass the external device tree in
handoff data, i.e. a board has to call
handoff_data_add(HANDOFF_DATA_EXTERNAL_DT, dtb, size);
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/startup.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/common/startup.c b/common/startup.c
index b311b77418..abdc0c2db0 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -40,6 +40,8 @@
#include <net.h>
#include <efi/efi-mode.h>
#include <bselftest.h>
+#include <pbl/handoff-data.h>
+#include <libfile.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
@@ -246,6 +248,8 @@ static int run_init(void)
struct stat s;
glob_t g;
int i, ret;
+ size_t size;
+ void *ext_dtb;
setenv("PATH", "/env/bin");
export("PATH");
@@ -289,6 +293,10 @@ static int run_init(void)
globfree(&g);
}
+ ext_dtb = handoff_data_get_entry(HANDOFF_DATA_EXTERNAL_DT, &size);
+ if (ext_dtb)
+ write_file("/external-devicetree", ext_dtb, size);
+
/* source matching script in /env/bmode/ */
bmode = reboot_mode_get();
if (bmode) {
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] ARM: beagleplay: put external device tree into handoff data
2024-12-09 14:28 [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
2024-12-09 14:28 ` [PATCH 1/3] fdt: Add function to check if a pointer contains a fdt Sascha Hauer
2024-12-09 14:28 ` [PATCH 2/3] store external device tree as file Sascha Hauer
@ 2024-12-09 14:28 ` Sascha Hauer
2024-12-16 8:31 ` [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-09 14:28 UTC (permalink / raw)
To: open list:BAREBOX
Pass the dtb from 1st stage loader to barebox using handoff data.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/beagleplay/lowlevel.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/arch/arm/boards/beagleplay/lowlevel.c b/arch/arm/boards/beagleplay/lowlevel.c
index 9d76dbd0a2..228484bf4e 100644
--- a/arch/arm/boards/beagleplay/lowlevel.c
+++ b/arch/arm/boards/beagleplay/lowlevel.c
@@ -5,21 +5,27 @@
#include <asm/barebox-arm.h>
#include <debug_ll.h>
#include <pbl.h>
+#include <pbl/handoff-data.h>
+#include <compressed-dtb.h>
/* Called from assembly */
-void beagleplay(void);
+void beagleplay(void *dtb);
-static noinline void beagleplay_continue(void)
+static noinline void beagleplay_continue(void *dtb)
{
unsigned long membase, memsize;
extern char __dtb_k3_am625_beagleplay_start[];
+ unsigned int size;
fdt_find_mem(__dtb_k3_am625_beagleplay_start, &membase, &memsize);
+ if (blob_is_valid_fdt_ptr(dtb, membase, memsize, &size))
+ handoff_data_add(HANDOFF_DATA_EXTERNAL_DT, dtb, size);
+
barebox_arm_entry(membase, memsize, __dtb_k3_am625_beagleplay_start);
}
-void beagleplay(void)
+void beagleplay(void *dtb)
{
putc_ll('>');
@@ -29,5 +35,5 @@ void beagleplay(void)
setup_c();
- beagleplay_continue();
+ beagleplay_continue(dtb);
}
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] make dtb from 1st stage loader available in barebox
2024-12-09 14:28 [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
` (2 preceding siblings ...)
2024-12-09 14:28 ` [PATCH 3/3] ARM: beagleplay: put external device tree into handoff data Sascha Hauer
@ 2024-12-16 8:31 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-16 8:31 UTC (permalink / raw)
To: open list:BAREBOX, Sascha Hauer
On Mon, 09 Dec 2024 15:28:10 +0100, Sascha Hauer wrote:
> When barebox is chainloaded from another bootloader it usually gets
> passed a device tree from the previous bootloader. While this external
> device tree is normally not used by barebox, its contents can still be
> interesting, so store the device tree at /external-devicetree when
> found. This needs board support to pass the external device tree in
> handoff data, i.e. a board has to call
> handoff_data_add(HANDOFF_DATA_EXTERNAL_DT, dtb, size);
> This series adds beagleplay support for this feature as an example.
>
> [...]
Applied, thanks!
[1/3] fdt: Add function to check if a pointer contains a fdt
https://git.pengutronix.de/cgit/barebox/commit/?id=abcd32a3e85f (link may not be stable)
[2/3] store external device tree as file
https://git.pengutronix.de/cgit/barebox/commit/?id=78c3e4145aa6 (link may not be stable)
[3/3] ARM: beagleplay: put external device tree into handoff data
https://git.pengutronix.de/cgit/barebox/commit/?id=0e62b0b1ecb2 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-16 8:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-09 14:28 [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
2024-12-09 14:28 ` [PATCH 1/3] fdt: Add function to check if a pointer contains a fdt Sascha Hauer
2024-12-09 14:28 ` [PATCH 2/3] store external device tree as file Sascha Hauer
2024-12-09 14:28 ` [PATCH 3/3] ARM: beagleplay: put external device tree into handoff data Sascha Hauer
2024-12-16 8:31 ` [PATCH 0/3] make dtb from 1st stage loader available in barebox Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox