[PATCH 25/78] ARM: Add function to return offset to global variables

Sascha Hauer s.hauer at pengutronix.de
Fri Mar 16 05:53:01 PDT 2018


ARM and aarch64 differ in the way global variables are addressed. This
adds a function which abstracts the differences.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/cpu/start-pbl.c           |  4 ++--
 arch/arm/cpu/uncompress.c          |  2 +-
 arch/arm/include/asm/barebox-arm.h | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/start-pbl.c b/arch/arm/cpu/start-pbl.c
index 68b2bbf6fb..73c27429da 100644
--- a/arch/arm/cpu/start-pbl.c
+++ b/arch/arm/cpu/start-pbl.c
@@ -60,8 +60,8 @@ __noreturn void barebox_single_pbl_start(unsigned long membase,
 	/* Get offset between linked address and runtime address */
 	offset = get_runtime_offset();
 
-	pg_start = (uint32_t)&input_data + offset;
-	pg_end = (uint32_t)&input_data_end + offset;
+	pg_start = (uint32_t)&input_data + global_variable_offset();
+	pg_end = (uint32_t)&input_data_end + global_variable_offset();
 	pg_len = pg_end - pg_start;
 	uncompressed_len = get_unaligned((const u32 *)(pg_start + pg_len - 4));
 
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index b600c1e7ec..37845b2259 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -51,7 +51,7 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
 	void *pg_start;
 	unsigned long pc = get_pc();
 
-	image_end = (void *)&image_end_marker + get_runtime_offset();
+	image_end = (void *)&image_end_marker + global_variable_offset();
 
 	if (IS_ENABLED(CONFIG_PBL_RELOCATABLE)) {
 		/*
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 1dccb8965e..9fc8afbe7d 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -44,6 +44,20 @@ extern char __exceptions_start[], __exceptions_stop[];
 void board_init_lowlevel(void);
 unsigned long get_runtime_offset(void);
 
+/* global_variable_offset() - Access global variables when not running at link address
+ *
+ * Get the offset of global variables when not running at the address we are
+ * linked at. ARM uses absolute addresses, so we must add the runtime offset
+ * whereas aarch64 uses PC relative addresses, so nothing must be done here.
+ */
+static inline unsigned long global_variable_offset(void)
+{
+	if (IS_ENABLED(CONFIG_CPU_32))
+		return get_runtime_offset();
+	else
+		return 0;
+}
+
 void setup_c(void);
 void relocate_to_current_adr(void);
 void relocate_to_adr(unsigned long target);
-- 
2.16.1




More information about the barebox mailing list