Skip to contentSkip to conversation

spl: add relocation support

PATCH New Andy Yan 3 participants 7 messages Apr 29, 2019 Arm (32-bit)

lore
Share & tools
lore

Andy Yan

author
#0 lore raw

PATCH 1/2 spl: add relocation support

Some times we want to relocate spl code to dram after dram initialization or relocate spl code to a high memory to avoid code overide.

For example on Rockchip armv8 platform, we run with boot flow TPL->SPL->ATF->U-Boot.

TPL run in sram and is responsible for dram initialization. SPL run from the start address of dram and is responsible for loading ATF and U-Boot.

The case here is that the ATF load address is from 64KB of dram, which overlaps with spl code itself.

So we want to relocate spl itself to high memory to aovid this.

---

 common/spl/Kconfig | 13 +++++++++++
 common/spl/spl.c   | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
common/spl/Kconfig +13 -0
index 206c24076d..52669ce1f8 100644
@@ -189,6 +189,19 @@ config SPL_DISPLAY_PRINT
 	  banner ("U-Boot SPL ..."). This function should be provided by
 	  the board.
 
+config SPL_SKIP_RELOCATE
+	bool "Skip code relocation in SPL"
+	default y
+	help
+	  The SPL code will be relocated to a high memory if you say no here.
+	  Only ARM64 and PowerPC SPL support relocate now.
+
+config SPL_RELOC_TEXT_BASE
+	hex "Address the SPL relocate to"
+	depends on !SPL_SKIP_RELOCATE
+	help
+	  The address on the ram where the SPL relocate to.
+
 config SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 	bool "MMC raw mode: by sector"
 	default y if ARCH_SUNXI || ARCH_DAVINCI || ARCH_UNIPHIER || \
common/spl/spl.c +55 -0

85 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 2/2 arm: add spl relocation support for armv8

Relocate spl itself to a high memory.

---

 arch/arm/config.mk                |  6 ++++++
 arch/arm/cpu/armv8/start.S        |  4 ++++
 arch/arm/cpu/armv8/u-boot-spl.lds | 17 +++++++++++++++++
 arch/arm/lib/Makefile             |  2 +-
 arch/arm/lib/crt0_64.S            |  3 ++-
 5 files changed, 30 insertions(+), 2 deletions(-)
arch/arm/config.mk +6 -0
index f25603109e..7f6ad89601 100644
@@ -102,6 +102,12 @@ endif
 # needed for relocation
 LDFLAGS_u-boot += -pie
 
+ifndef CONFIG_SPL_SKIP_RELOCATE
+LDFLAGS_u-boot-spl = -pie
+else
+SPL_LDFLAGS_u-boot-spl =
+endif
+
 #
 # FIXME: binutils versions < 2.22 have a bug in the assembler where
 # branches to weak symbols can be incorrectly optimized in thumb mode
arch/arm/cpu/armv8/start.S +4 -0
index fe52166e28..a7dad3cd69 100644
@@ -35,7 +35,11 @@ _start:
 
 .globl	_TEXT_BASE
 _TEXT_BASE:
+#if defined(CONFIG_SPL_BUILD)
+	.quad   CONFIG_SPL_TEXT_BASE
+#else
 	.quad	CONFIG_SYS_TEXT_BASE
+#endif
 
 /*
  * These are defined in the linker script.
arch/arm/cpu/armv8/u-boot-spl.lds +17 -0
index ccbf359bd1..64102afc8b 100644
@@ -53,6 +53,23 @@ SECTIONS
 		*(.__end)
 	} >.sram
 
+#ifndef CONFIG_SPL_SKIP_RELOCATE
+	. = ALIGN(8);
+
+	.rel_dyn_start :
+	{
+		*(.__rel_dyn_start)
+	} >.sram
+
+	.rela.dyn : {
+		*(.rela*)
+	} >.sram
+
+	.rel_dyn_end :
+	{
+		*(.__rel_dyn_end)
+	} >.sram
+#endif
 	_image_binary_end = .;
 
 	.bss_start (NOLOAD) : {
arch/arm/lib/Makefile +1 -1
index 48ee6c3c60..f27b3fb79f 100644
@@ -21,7 +21,7 @@ else
 obj-y   += setjmp.o
 endif
 
-ifndef CONFIG_SPL_BUILD
+ifndef CONFIG_TPL_BUILD
 ifdef CONFIG_ARM64
 obj-y	+= relocate_64.o
 else
arch/arm/lib/crt0_64.S +2 -1
index d6b632aa87..e5605fe325 100644
@@ -89,7 +89,8 @@ ENTRY(_main)
 	mov	x0, #0
 	bl	board_init_f
 
-#if !defined(CONFIG_SPL_BUILD)
+#if (defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) && !defined(CONFIG_SPL_SKIP_RELOCATE)) || \
+	!defined(CONFIG_SPL_BUILD)
 /*
  * Set up intermediate environment (new sp and gd) and call
  * relocate_code(addr_moni). Trick here is that we'll return
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 arm: add spl relocation support for armv8

Hi Andy,

Quoted 2 lines · Andy Yan

Relocate spl itself to a high memory.

Please improve the commit message and explain the reason for doing this.

author
#3 lore raw

PATCH 2/2 arm: add spl relocation support for armv8

Hi Fabio:

Quoted 7 lines · Fabio Estevam

Hi Andy,

Quoted 1 line · Andy Yan

Relocate spl itself to a high memory.

Please improve the commit message and explain the reason for doing this.

The detail reason I described in [PATCH 1/2],  you are in the list.

#4 lore raw

PATCH 2/2 arm: add spl relocation support for armv8

Quoted 5 lines · Andy Yan

Hi Fabio:

Quoted 2 lines · Fabio Estevam

Hi Andy,

Quoted 7 lines
Quoted 5 lines · Andy Yan
Quoted 1 line

Relocate spl itself to a high memory.

Please improve the commit message and explain the reason for doing this.

The detail reason I described in [PATCH 1/2],  you are in the list.

Once this is committed to git, there will be no PATCH 1/2 in the git log , so the commit message should explain what this patch does.

Signature · 2 lines
Best regards,
Marek Vasut
author
#5 lore raw

PATCH 2/2 arm: add spl relocation support for armv8

Hi Marek, Fabio:

Quoted 6 lines · Marek Vasut
Quoted 5 lines · Andy Yan

Hi Fabio:

Quoted 2 lines · Fabio Estevam

Hi Andy,

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines · Andy Yan
Quoted 1 line

Relocate spl itself to a high memory.

Please improve the commit message and explain the reason for doing this.

The detail reason I described in [PATCH 1/2],  you are in the list.

Once this is committed to git, there will be no PATCH 1/2 in the git log , so the commit message should explain what this patch does.

I will add the detail in next version.

#6 lore raw

PATCH 2/2 arm: add spl relocation support for armv8

Quoted 16 lines · Andy Yan

Hi Marek, Fabio:

Quoted 13 lines · Marek Vasut
Quoted 12 lines · Andy Yan

Hi Fabio:

Quoted 9 lines · Fabio Estevam

Hi Andy,

Quoted 1 line · Andy Yan

Relocate spl itself to a high memory.

Please improve the commit message and explain the reason for doing this.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

The detail reason I described in [PATCH 1/2],  you are in the list.

Once this is committed to git, there will be no PATCH 1/2 in the git log , so the commit message should explain what this patch does.

I will add the detail in next version.

Thanks

Signature · 2 lines
Best regards,
Marek Vasut