mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/4] mvebu: get initial position of register window from image header
Date: Sat, 25 Feb 2017 21:52:39 +0100	[thread overview]
Message-ID: <20170225205242.18106-2-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20170225205242.18106-1-u.kleine-koenig@pengutronix.de>

A problem when using 2nd stage booting on mvebu is that the first bootloader
already switched the register window location from 0xd0000000 to
0xf1000000 by writing to 0xd0000080. When the second bootloader also
tries to do this switch it writes to the wrong location resulting in an
exception and so a boot failure.

For this reason the base address of the register window is passed in the
barebox header and picked up from there by early code. In a further
patch bootm is taught to put the actual position of the window there for
the second bootloader to finally make second stage booting work.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/Kconfig                                   |  1 +
 arch/arm/mach-mvebu/common.c                       |  6 +--
 .../arm/mach-mvebu/include/mach/barebox-arm-head.h | 54 ++++++++++++++++++++++
 arch/arm/mach-mvebu/include/mach/common.h          | 17 +++++++
 4 files changed, 75 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-mvebu/include/mach/barebox-arm-head.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3e8ccf7661c4..c61d1dc6a82e 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -123,6 +123,7 @@ config ARCH_MVEBU
 	select GPIOLIB
 	select HAS_DEBUG_LL
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select HAVE_MACH_ARM_HEAD
 	select HAVE_PBL_MULTI_IMAGES
 	select HW_HAS_PCI
 	select MVEBU_MBUS
diff --git a/arch/arm/mach-mvebu/common.c b/arch/arm/mach-mvebu/common.c
index 7534d8dd019e..06bfb7261544 100644
--- a/arch/arm/mach-mvebu/common.c
+++ b/arch/arm/mach-mvebu/common.c
@@ -180,14 +180,14 @@ mem_initcall(mvebu_meminit);
  * safely later on, as the remap register itself is within the
  * internal registers.
  */
-#define MVEBU_BOOTUP_INT_REG_BASE	0xd0000000
 #define MVEBU_BRIDGE_REG_BASE		0x20000
 #define DEVICE_INTERNAL_BASE_ADDR	(MVEBU_BRIDGE_REG_BASE + 0x80)
 
 static void mvebu_remap_registers(void)
 {
-	writel(MVEBU_REMAP_INT_REG_BASE,
-	       IOMEM(MVEBU_BOOTUP_INT_REG_BASE) + DEVICE_INTERNAL_BASE_ADDR);
+	void __iomem *base = mvebu_get_initial_int_reg_base();
+
+	writel(MVEBU_REMAP_INT_REG_BASE, base + DEVICE_INTERNAL_BASE_ADDR);
 }
 
 void __naked __noreturn dove_barebox_entry(void *boarddata)
diff --git a/arch/arm/mach-mvebu/include/mach/barebox-arm-head.h b/arch/arm/mach-mvebu/include/mach/barebox-arm-head.h
new file mode 100644
index 000000000000..3035f40ddf3b
--- /dev/null
+++ b/arch/arm/mach-mvebu/include/mach/barebox-arm-head.h
@@ -0,0 +1,54 @@
+#include <linux/stringify.h>
+#include <mach/common.h>
+
+static inline void __barebox_arm_head(void)
+{
+	__asm__ __volatile__ (
+#ifdef CONFIG_THUMB2_BAREBOX
+		".arm\n"
+		"adr r9, 1f + 1\n"
+		"bx r9\n"
+		".thumb\n"
+		"1:\n"
+		"bl 2f\n"
+		".rept 10\n"
+		"1: b 1b\n"
+		".endr\n"
+#else
+		"b 2f\n"
+		"1: b 1b\n"
+		"1: b 1b\n"
+		"1: b 1b\n"
+		"1: b 1b\n"
+		"1: b 1b\n"
+		"1: b 1b\n"
+		"1: b 1b\n"
+#endif
+		".asciz \"barebox\"\n"
+		".word _text\n"				/* text base. If copied there,
+							 * barebox can skip relocation
+							 */
+		".word _barebox_image_size\n"		/* image size to copy */
+
+		/*
+		 * The following entry (at offset 0x30) is the only intended
+		 * difference to the original arm __barebox_arm_head. This value
+		 * holds the address of the internal register window when the
+		 * image is started. If the window is not at the reset default
+		 * position any more the caller can pass the actual value here.
+		 */
+		".word " __stringify(MVEBU_BOOTUP_INT_REG_BASE) "\n"
+		".rept 7\n"
+		".word 0x55555555\n"
+		".endr\n"
+		"2:\n"
+	);
+}
+
+static inline void barebox_arm_head(void)
+{
+	__barebox_arm_head();
+	__asm__ __volatile__ (
+		"b barebox_arm_reset_vector\n"
+	);
+}
diff --git a/arch/arm/mach-mvebu/include/mach/common.h b/arch/arm/mach-mvebu/include/mach/common.h
index 3cc1bf71c0f7..529eb61cfd9a 100644
--- a/arch/arm/mach-mvebu/include/mach/common.h
+++ b/arch/arm/mach-mvebu/include/mach/common.h
@@ -18,6 +18,23 @@
 #ifndef __MACH_COMMON_H__
 #define __MACH_COMMON_H__
 
+#include <asm/sections.h>
+#include <asm/unaligned.h>
+
+#define MVEBU_BOOTUP_INT_REG_BASE	0xd0000000
 #define MVEBU_REMAP_INT_REG_BASE	0xf1000000
 
+/* #including <asm/barebox-arm.h> yields a circle, so we need a forward decl */
+uint32_t get_runtime_offset(void);
+
+static inline void __iomem *mvebu_get_initial_int_reg_base(void)
+{
+#ifdef __PBL__
+	u32 base = __get_unaligned_le32(_text - get_runtime_offset() + 0x30);
+	return (void __force __iomem *)base;
+#else
+	return (void __force __iomem *)MVEBU_REMAP_INT_REG_BASE;
+#endif
+}
+
 #endif
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2017-02-25 20:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-25 20:52 [PATCH 0/4] mvebu: Make 2nd-stage booting possible Uwe Kleine-König
2017-02-25 20:52 ` Uwe Kleine-König [this message]
2017-02-25 20:52 ` [PATCH 2/4] filetype: Add image type for boot images used on Armada 370 and XP Uwe Kleine-König
2017-02-25 20:52 ` [PATCH 3/4] kwbimage_v1: add support to boot a mvebu image Uwe Kleine-König
2017-02-25 20:52 ` [PATCH 4/4] mvebu: netgear-rn2120: make use of mvebu_get_initial_int_reg_base Uwe Kleine-König
2017-02-28  6:59 ` [PATCH 0/4] mvebu: Make 2nd-stage booting possible Sascha Hauer
2017-02-28 16:06   ` Uwe Kleine-König

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=20170225205242.18106-2-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@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