mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4] handoff-data: some update
@ 2024-10-30 11:30 Sascha Hauer
  2024-10-30 11:30 ` [PATCH 1/4] handoff_data: add handoff_data_add_dt() Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-10-30 11:30 UTC (permalink / raw)
  To: open list:BAREBOX

This series has some misc updates for the handoff-data support

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Sascha Hauer (4):
      handoff_data: add handoff_data_add_dt()
      ARM: i.MX93: add destination argument to imx93_romapi_load_image()
      handoff-data: set flags of moved handoff data entry
      handoff-data: add protection against multiple invocation

 arch/arm/boards/tqma93xx/lowlevel.c |  1 -
 arch/arm/cpu/uncompress.c           | 18 ++----------------
 arch/arm/mach-imx/atf.c             |  2 ++
 arch/arm/mach-imx/romapi.c          | 11 +++++------
 include/mach/imx/romapi.h           |  2 +-
 include/pbl/handoff-data.h          |  6 ++++++
 pbl/handoff-data.c                  | 16 ++++++++++++++++
 7 files changed, 32 insertions(+), 24 deletions(-)
---
base-commit: e55e492573e33823f25935ee00fe7fa7bf2c5c90
change-id: 20241030-handoff-data-db33a379d622

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] handoff_data: add handoff_data_add_dt()
  2024-10-30 11:30 [PATCH 0/4] handoff-data: some update Sascha Hauer
@ 2024-10-30 11:30 ` Sascha Hauer
  2024-10-30 11:30 ` [PATCH 2/4] ARM: i.MX93: add destination argument to imx93_romapi_load_image() Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-10-30 11:30 UTC (permalink / raw)
  To: open list:BAREBOX

Factor out a handoff_data_add_dt() from the existing ARM code in case a
board wants to set the fdt directly in board code rather than passing it
in the boarddata pointer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/uncompress.c  | 18 ++----------------
 include/pbl/handoff-data.h |  2 ++
 pbl/handoff-data.c         | 15 +++++++++++++++
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index 8f916359b3..ac1462b7b1 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -31,21 +31,6 @@ 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 (!boarddata)
-		return;
-	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));
-	}
-}
-
 void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 				  void *boarddata)
 {
@@ -82,7 +67,8 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
 		mmu_early_enable(membase, memsize);
 
 	/* Add handoff data now, so arm_mem_barebox_image takes it into account */
-	add_handoff_data(boarddata);
+	if (boarddata)
+		handoff_data_add_dt(boarddata);
 
 	barebox_base = arm_mem_barebox_image(membase, endmem,
 					     uncompressed_len, NULL);
diff --git a/include/pbl/handoff-data.h b/include/pbl/handoff-data.h
index d475bdd694..eac3b9bf3e 100644
--- a/include/pbl/handoff-data.h
+++ b/include/pbl/handoff-data.h
@@ -51,4 +51,6 @@ static inline size_t handoff_data_size(void)
 	return __handoff_data_size(NULL);
 }
 
+void handoff_data_add_dt(void *fdt);
+
 #endif /* __PBL_HANDOFF_DATA_H */
diff --git a/pbl/handoff-data.c b/pbl/handoff-data.c
index 7453c9c82c..17b0512132 100644
--- a/pbl/handoff-data.c
+++ b/pbl/handoff-data.c
@@ -4,6 +4,8 @@
 #include <init.h>
 #include <linux/list.h>
 #include <memory.h>
+#include <fdt.h>
+#include <compressed-dtb.h>
 
 static struct handoff_data *handoff_data = (void *)-1;
 
@@ -160,6 +162,19 @@ int handoff_data_show(void)
 	return 0;
 }
 
+void handoff_data_add_dt(void *fdt)
+{
+	if (blob_is_fdt(fdt)) {
+		handoff_data_add(HANDOFF_DATA_INTERNAL_DT, fdt,
+				 get_unaligned_be32(fdt + 4));
+	} else if (blob_is_compressed_fdt(fdt)) {
+		struct barebox_boarddata_compressed_dtb *bd = fdt;
+
+		handoff_data_add(HANDOFF_DATA_INTERNAL_DT_Z, fdt,
+				 bd->datalen + sizeof(*bd));
+	}
+}
+
 static const char *handoff_data_entry_name(struct handoff_data_entry *hde)
 {
 	static char name[sizeof("handoff 12345678")];

-- 
2.39.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] ARM: i.MX93: add destination argument to imx93_romapi_load_image()
  2024-10-30 11:30 [PATCH 0/4] handoff-data: some update Sascha Hauer
  2024-10-30 11:30 ` [PATCH 1/4] handoff_data: add handoff_data_add_dt() Sascha Hauer
@ 2024-10-30 11:30 ` Sascha Hauer
  2024-10-30 11:30 ` [PATCH 3/4] handoff-data: set flags of moved handoff data entry Sascha Hauer
  2024-10-30 11:30 ` [PATCH 4/4] handoff-data: add protection against multiple invocation Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-10-30 11:30 UTC (permalink / raw)
  To: open list:BAREBOX

Pass the destination address to imx93_romapi_load_image() rather
than hardcoding the destination to MX93_ATF_BL33_BASE_ADDR.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/tqma93xx/lowlevel.c |  1 -
 arch/arm/mach-imx/atf.c             |  2 ++
 arch/arm/mach-imx/romapi.c          | 11 +++++------
 include/mach/imx/romapi.h           |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boards/tqma93xx/lowlevel.c b/arch/arm/boards/tqma93xx/lowlevel.c
index 14733d52a3..cc5101a1a3 100644
--- a/arch/arm/boards/tqma93xx/lowlevel.c
+++ b/arch/arm/boards/tqma93xx/lowlevel.c
@@ -81,7 +81,6 @@ static noinline void tqma93xx_continue(void)
 			break;
 		}
 
-		imx93_romapi_load_image();
 		imx93_load_and_start_image_via_tfa();
 	}
 
diff --git a/arch/arm/mach-imx/atf.c b/arch/arm/mach-imx/atf.c
index 8b80460268..f4ba07bf06 100644
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -395,6 +395,8 @@ void __noreturn imx93_load_and_start_image_via_tfa(void)
 	imx_set_cpu_type(IMX_CPU_IMX93);
 	imx93_init_scratch_space(true);
 
+	imx93_romapi_load_image(bl33);
+
 	/*
 	 * On completion the TF-A will jump to MX93_ATF_BL33_BASE_ADDR
 	 * in EL2. Copy the image there, but replace the PBL part of
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index 0f1555abad..155e706437 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -173,13 +173,12 @@ static int imx_romapi_boot_device_seekable(struct rom_api *rom_api)
 	return seekable;
 }
 
-int imx93_romapi_load_image(void)
+int imx93_romapi_load_image(void *adr)
 {
 	struct rom_api *rom_api = (void *)0x1980;
 	int ret;
 	int seekable;
 	uint32_t offset, image_offset;
-	void *bl33 = (void *)MX93_ATF_BL33_BASE_ADDR;
 	struct flash_header_v3 *fh;
 
 	OPTIMIZER_HIDE_VAR(rom_api);
@@ -190,7 +189,7 @@ int imx93_romapi_load_image(void)
 
 	if (!seekable) {
 		int align_size = ALIGN(barebox_pbl_size, 1024) - barebox_pbl_size;
-		void *pbl_size_aligned = bl33 + ALIGN(barebox_pbl_size, 1024);
+		void *pbl_size_aligned = adr + ALIGN(barebox_pbl_size, 1024);
 
 		/*
 		 * The USB protocol uploads in chunks of 1024 bytes. This means
@@ -209,11 +208,11 @@ int imx93_romapi_load_image(void)
 
 	pr_debug("%s: IVT offset on boot device: 0x%08x\n", __func__, offset);
 
-	ret = imx_romapi_load_seekable(rom_api, bl33, offset, 4096);
+	ret = imx_romapi_load_seekable(rom_api, adr, offset, 4096);
 	if (ret)
 		return ret;
 
-	fh = bl33;
+	fh = adr;
 
 	if (fh->tag != 0x87) {
 		pr_err("Invalid IVT header: 0x%02x, expected 0x87\n", fh->tag);
@@ -228,7 +227,7 @@ int imx93_romapi_load_image(void)
 	 * We assume the first image in the first container is the barebox image,
 	 * which is what the imx9image call in images/Makefile.imx generates.
 	 */
-	ret = imx_romapi_load_seekable(rom_api, bl33, offset + image_offset, barebox_image_size);
+	ret = imx_romapi_load_seekable(rom_api, adr, offset + image_offset, barebox_image_size);
 	if (ret)
 		return ret;
 
diff --git a/include/mach/imx/romapi.h b/include/mach/imx/romapi.h
index e26b98097d..9967a2a4c3 100644
--- a/include/mach/imx/romapi.h
+++ b/include/mach/imx/romapi.h
@@ -38,7 +38,7 @@ enum boot_dev_type_e {
 /* Below functions only load and don't start the image */
 int imx8mp_romapi_load_image(void *bl33);
 int imx8mn_romapi_load_image(void *bl33);
-int imx93_romapi_load_image(void);
+int imx93_romapi_load_image(void *adr);
 
 /* only call after DRAM has been configured */
 void imx8m_save_bootrom_log(void);

-- 
2.39.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] handoff-data: set flags of moved handoff data entry
  2024-10-30 11:30 [PATCH 0/4] handoff-data: some update Sascha Hauer
  2024-10-30 11:30 ` [PATCH 1/4] handoff_data: add handoff_data_add_dt() Sascha Hauer
  2024-10-30 11:30 ` [PATCH 2/4] ARM: i.MX93: add destination argument to imx93_romapi_load_image() Sascha Hauer
@ 2024-10-30 11:30 ` Sascha Hauer
  2024-10-30 11:30 ` [PATCH 4/4] handoff-data: add protection against multiple invocation Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-10-30 11:30 UTC (permalink / raw)
  To: open list:BAREBOX

When moving handoff data around we have to initialize the flags field
of the moved entry.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 pbl/handoff-data.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pbl/handoff-data.c b/pbl/handoff-data.c
index 17b0512132..a0a04cad0c 100644
--- a/pbl/handoff-data.c
+++ b/pbl/handoff-data.c
@@ -115,6 +115,7 @@ void handoff_data_move(void *dest)
 
 		newde->size = hde->size;
 		newde->cookie = hde->cookie;
+		newde->flags = hde->flags;
 		list_add_tail(&newde->list, &hdnew->entries);
 	}
 

-- 
2.39.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] handoff-data: add protection against multiple invocation
  2024-10-30 11:30 [PATCH 0/4] handoff-data: some update Sascha Hauer
                   ` (2 preceding siblings ...)
  2024-10-30 11:30 ` [PATCH 3/4] handoff-data: set flags of moved handoff data entry Sascha Hauer
@ 2024-10-30 11:30 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-10-30 11:30 UTC (permalink / raw)
  To: open list:BAREBOX

handoff_data_add_flags() passes statically allocated structs as handoff
data, thus we cannot allow it to be called multiple times as that would
reuse the same data. Add a BUG_ON() to catch this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/pbl/handoff-data.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/pbl/handoff-data.h b/include/pbl/handoff-data.h
index eac3b9bf3e..bc1d403380 100644
--- a/include/pbl/handoff-data.h
+++ b/include/pbl/handoff-data.h
@@ -28,6 +28,10 @@ struct handoff_data_entry {
 #define handoff_data_add_flags(_cookie, _data, _size, _flags)		\
 	do {								\
 		static struct handoff_data_entry hde __section(.data);	\
+									\
+		/* using static data, do not invoke multiple times */	\
+		BUG_ON(hde.cookie); 					\
+									\
 		hde.cookie = _cookie;					\
 		hde.data = _data;					\
 		hde.size = _size;					\

-- 
2.39.5




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-30 11:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-30 11:30 [PATCH 0/4] handoff-data: some update Sascha Hauer
2024-10-30 11:30 ` [PATCH 1/4] handoff_data: add handoff_data_add_dt() Sascha Hauer
2024-10-30 11:30 ` [PATCH 2/4] ARM: i.MX93: add destination argument to imx93_romapi_load_image() Sascha Hauer
2024-10-30 11:30 ` [PATCH 3/4] handoff-data: set flags of moved handoff data entry Sascha Hauer
2024-10-30 11:30 ` [PATCH 4/4] handoff-data: add protection against multiple invocation Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox