mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/7] ARM: introduce jump_to_linux helper
Date: Wed,  9 Apr 2025 16:01:33 +0200	[thread overview]
Message-ID: <20250409140134.2079552-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250409140134.2079552-1-a.fatoum@pengutronix.de>

The upcoming FIP bootm handler should be usable on both ARM32 and ARM64
and thus we need an arch-independent way of booting a kernel with a
given device tree.

Introduce a jump_to_linux helper in <asm/boot.h> for this purpose.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/include/asm/boot.h | 28 ++++++++++++++++++++++++++++
 arch/arm/lib32/armlinux.c   | 14 +++++++-------
 arch/arm/lib64/armlinux.c   | 12 ++++++------
 3 files changed, 41 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/include/asm/boot.h

diff --git a/arch/arm/include/asm/boot.h b/arch/arm/include/asm/boot.h
new file mode 100644
index 000000000000..a75d139ed8ea
--- /dev/null
+++ b/arch/arm/include/asm/boot.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _ASM_BOOT_H_
+#define _ASM_BOOT_H_
+
+#include <linux/types.h>
+
+#ifdef CONFIG_ARM64
+static inline void jump_to_linux(const void *_kernel, phys_addr_t dtb)
+{
+	void (*kernel)(unsigned long dtb, unsigned long x1, unsigned long x2,
+		       unsigned long x3) = _kernel;
+	kernel(dtb, 0, 0, 0);
+}
+#else
+static inline void __jump_to_linux(const void *_kernel, unsigned arch,
+				   phys_addr_t params)
+{
+	void (*kernel)(int zero, unsigned arch, ulong params) = _kernel;
+	kernel(0, arch, params);
+}
+static inline void jump_to_linux(const void *_kernel, phys_addr_t dtb)
+{
+	__jump_to_linux(_kernel, ~0, dtb);
+}
+#endif
+
+#endif	/* _ASM_BOOT_H_ */
diff --git a/arch/arm/lib32/armlinux.c b/arch/arm/lib32/armlinux.c
index 0b332d23639d..56f278d3dbae 100644
--- a/arch/arm/lib32/armlinux.c
+++ b/arch/arm/lib32/armlinux.c
@@ -26,6 +26,7 @@
 #include <asm/armlinux.h>
 #include <asm/system.h>
 #include <asm/secure.h>
+#include <asm/boot.h>
 
 static struct tag *params;
 static void *armlinux_bootparams = NULL;
@@ -251,8 +252,7 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
 		 unsigned long initrd_size, void *oftree,
 		 enum arm_security_state state, void *optee)
 {
-	void (*kernel)(int zero, unsigned arch, void *params) = adr;
-	void *params = NULL;
+	phys_addr_t params = 0;
 	unsigned architecture;
 	int ret;
 
@@ -264,11 +264,11 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
 
 	if (oftree) {
 		pr_debug("booting kernel with devicetree\n");
-		params = oftree;
+		params = virt_to_phys(oftree);
 	} else {
-		params = armlinux_get_bootparams();
+		params = virt_to_phys(armlinux_get_bootparams());
 
-		if ((unsigned long)params < PAGE_SIZE)
+		if (params < PAGE_SIZE)
 			zero_page_access();
 
 		setup_tags(initrd_address, initrd_size, swap);
@@ -288,8 +288,8 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
 	}
 
 	if (optee && IS_ENABLED(CONFIG_BOOTM_OPTEE)) {
-		start_kernel_optee(optee, kernel, oftree);
+		start_kernel_optee(optee, adr, oftree);
 	} else {
-		kernel(0, architecture, params);
+		__jump_to_linux(adr, architecture, params);
 	}
 }
diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index 5feee9c24f2a..13721a71236b 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -5,18 +5,18 @@
 #include <memory.h>
 #include <init.h>
 #include <bootm.h>
+#include <asm/boot.h>
 #include <efi/efi-mode.h>
 
 static int do_bootm_linux(struct image_data *data)
 {
-	void (*fn)(unsigned long dtb, unsigned long x1, unsigned long x2,
-		       unsigned long x3);
+	void *image;
 	phys_addr_t devicetree;
 	int ret;
 
-	fn = booti_load_image(data, &devicetree);
-	if (IS_ERR(fn))
-		return PTR_ERR(fn);
+	image = booti_load_image(data, &devicetree);
+	if (IS_ERR(image))
+		return PTR_ERR(image);
 
 	if (data->dryrun)
 		return 0;
@@ -27,7 +27,7 @@ static int do_bootm_linux(struct image_data *data)
 
 	shutdown_barebox();
 
-	fn(devicetree, 0, 0, 0);
+	jump_to_linux(image, devicetree);
 
 	return -EINVAL;
 }
-- 
2.39.5




  parent reply	other threads:[~2025-04-09 14:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 1/7] fip: add struct fip_image_desc::private_data Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 2/7] fip: mark predefined toc_entries array const Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 3/7] bootm: implement UIMAGE_IS_ADDRESS_VALID helper Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 4/7] ARM: legacy: make architecture number unsigned Ahmad Fatoum
2025-04-09 14:01 ` Ahmad Fatoum [this message]
2025-04-09 14:01 ` [PATCH 6/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 7/7] ARM: stm32mp: retire non-FIP stm32mp_bbu_mmc_register_handler 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=20250409140134.2079552-6-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