mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/3] ARM: pass handoff data from PBL to proper
Date: Tue, 30 Apr 2024 12:53:10 +0200	[thread overview]
Message-ID: <20240430105310.3149242-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240430105310.3149242-1-s.hauer@pengutronix.de>

Use newly introduced handoff data to pass data from PBL to barebox
proper. This will allow us later to pass more SoC and/or board specific
data from PBL to barebox proper.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/start.c      | 53 ++++++++++++---------------------------
 arch/arm/cpu/uncompress.c | 33 +++++++++++++++++++++---
 2 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index c13e93c243..b9dbe1f2fb 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -21,6 +21,7 @@
 #include <asm/mmu.h>
 #include <linux/kasan.h>
 #include <memory.h>
+#include <handoff-data.h>
 #include <uncompress.h>
 #include <compressed-dtb.h>
 #include <malloc.h>
@@ -38,10 +39,9 @@ static unsigned long barebox_boarddata_size;
 
 const struct barebox_boarddata *barebox_get_boarddata(void)
 {
-	if (!barebox_boarddata || !blob_is_arm_boarddata(barebox_boarddata))
-		return NULL;
+	size_t size;
 
-	return barebox_boarddata;
+	return handoff_data_get_entry(HANDOFF_DATA_BOARDDATA, &size);
 }
 
 u32 barebox_arm_machine(void)
@@ -56,19 +56,24 @@ void *barebox_arm_boot_dtb(void)
 	int ret = 0;
 	struct barebox_boarddata_compressed_dtb *compressed_dtb;
 	static void *boot_dtb;
+	void *blob;
+	size_t size;
 
 	if (boot_dtb)
 		return boot_dtb;
 
-	if (barebox_boarddata && blob_is_fdt(barebox_boarddata)) {
-		pr_debug("%s: using barebox_boarddata\n", __func__);
-		return barebox_boarddata;
-	}
+	blob = handoff_data_get_entry(HANDOFF_DATA_INTERNAL_DT, &size);
+	if (blob)
+		return blob;
+
+	blob = handoff_data_get_entry(HANDOFF_DATA_INTERNAL_DT_Z, &size);
+	if (!blob)
+		return NULL;
 
-	if (!fdt_blob_can_be_decompressed(barebox_boarddata))
+	if (!fdt_blob_can_be_decompressed(blob))
 		return NULL;
 
-	compressed_dtb = barebox_boarddata;
+	compressed_dtb = blob;
 
 	pr_debug("%s: using compressed_dtb\n", __func__);
 
@@ -167,34 +172,6 @@ __noreturn __prereloc void barebox_non_pbl_start(unsigned long membase,
 	arm_barebox_size = barebox_size;
 	malloc_end = barebox_base;
 
-	if (boarddata) {
-		uint32_t totalsize = 0;
-		const char *name;
-
-		if (blob_is_fdt(boarddata)) {
-			totalsize = get_unaligned_be32(boarddata + 4);
-			name = "DTB";
-		} else if (blob_is_compressed_fdt(boarddata)) {
-			struct barebox_boarddata_compressed_dtb *bd = boarddata;
-			totalsize = bd->datalen + sizeof(*bd);
-			name = "Compressed DTB";
-		} else if (blob_is_arm_boarddata(boarddata)) {
-			totalsize = sizeof(struct barebox_arm_boarddata);
-			name = "machine type";
-		}
-
-		if (totalsize) {
-			unsigned long mem = arm_mem_boarddata(membase, endmem,
-							      totalsize);
-			pr_debug("found %s in boarddata, copying to 0x%08lx\n",
-				 name, mem);
-			barebox_boarddata = memcpy((void *)mem, boarddata,
-						   totalsize);
-			barebox_boarddata_size = totalsize;
-			malloc_end = mem;
-		}
-	}
-
 	/*
 	 * Maximum malloc space is the Kconfig value if given
 	 * or 1GB.
@@ -216,6 +193,8 @@ __noreturn __prereloc void barebox_non_pbl_start(unsigned long membase,
 
 	mem_malloc_init((void *)malloc_start, (void *)malloc_end - 1);
 
+	handoff_data_set(boarddata);
+
 	if (IS_ENABLED(CONFIG_BOOTM_OPTEE))
 		of_add_reserve_entry(endmem - OPTEE_SIZE, endmem - 1);
 
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index aa1a49bfc9..a29703e760 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -10,6 +10,7 @@
 #include <init.h>
 #include <linux/sizes.h>
 #include <pbl.h>
+#include <handoff-data.h>
 #include <asm/barebox-arm.h>
 #include <asm/barebox-arm-head.h>
 #include <asm-generic/memory_layout.h>
@@ -18,6 +19,7 @@
 #include <asm/cache.h>
 #include <asm/mmu.h>
 #include <asm/unaligned.h>
+#include <compressed-dtb.h>
 
 #include <debug_ll.h>
 
@@ -29,6 +31,22 @@ unsigned long free_mem_end_ptr;
 extern unsigned char input_data[];
 extern unsigned char input_data_end[];
 
+static void add_handoff_data(void *boarddata)
+{
+	if (blob_is_fdt(boarddata)) {
+		handoff_data_add(HANDOFF_DATA_INTERNAL_DT, boarddata,
+				 get_unaligned_be32(boarddata + 4));
+	} else if (blob_is_compressed_fdt(boarddata)) {
+		struct barebox_boarddata_compressed_dtb *bd = boarddata;
+
+		handoff_data_add(HANDOFF_DATA_INTERNAL_DT_Z, boarddata,
+				 bd->datalen + sizeof(*bd));
+	} else if (blob_is_arm_boarddata(boarddata)) {
+		handoff_data_add(HANDOFF_DATA_BOARDDATA, boarddata,
+				 sizeof(struct barebox_arm_boarddata));
+	}
+}
+
 void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 				  void *boarddata)
 {
@@ -38,6 +56,7 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	unsigned long barebox_base;
 	void *pg_start, *pg_end;
 	unsigned long pc = get_pc();
+	void *handoff_data;
 
 	/* piggy data is not relocated, so determine the bounds now */
 	pg_start = runtime_address(input_data);
@@ -56,9 +75,6 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	pg_len = pg_end - pg_start;
 	uncompressed_len = get_unaligned((const u32 *)(pg_start + pg_len - 4));
 
-	barebox_base = arm_mem_barebox_image(membase, endmem,
-					     uncompressed_len + MAX_BSS_SIZE);
-
 	setup_c();
 
 	pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize);
@@ -69,11 +85,20 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	free_mem_ptr = arm_mem_early_malloc(endmem);
 	free_mem_end_ptr = arm_mem_early_malloc_end(endmem);
 
+	barebox_base = arm_mem_barebox_image(membase, endmem,
+					     uncompressed_len + MAX_BSS_SIZE + handoff_data_size());
+
+	handoff_data = (void *)barebox_base + uncompressed_len + MAX_BSS_SIZE;
+
 	pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
 			pg_start, pg_len, barebox_base, uncompressed_len);
 
 	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
 
+	add_handoff_data(boarddata);
+
+	handoff_data_move(handoff_data);
+
 	sync_caches_for_execution();
 
 	if (IS_ENABLED(CONFIG_THUMB2_BAREBOX))
@@ -86,5 +111,5 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 	if (IS_ENABLED(CONFIG_CPU_V7) && boot_cpu_mode() == HYP_MODE)
 		armv7_switch_to_hyp();
 
-	barebox(membase, memsize, boarddata);
+	barebox(membase, memsize, handoff_data);
 }
-- 
2.39.2




  parent reply	other threads:[~2024-04-30 10:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 10:53 [PATCH 0/3] add PBL handoff-data support Sascha Hauer
2024-04-30 10:53 ` [PATCH 1/3] ARM: move blob_is_arm_boarddata() to include Sascha Hauer
2024-05-02 14:21   ` Ahmad Fatoum
2024-04-30 10:53 ` [PATCH 2/3] add handoff-data support Sascha Hauer
2024-04-30 10:53 ` Sascha Hauer [this message]
2024-05-07  7:35 ` [PATCH 0/3] add PBL " Sascha Hauer

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=20240430105310.3149242-4-s.hauer@pengutronix.de \
    --to=s.hauer@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