All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] spl: add relocation support
@ 2019-04-29  9:04 Andy Yan
  2019-04-29  9:06 ` [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8 Andy Yan
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Yan @ 2019-04-29  9:04 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
---

 common/spl/Kconfig | 13 +++++++++++
 common/spl/spl.c   | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 206c24076d..52669ce1f8 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -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 || \
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 88d4b8a9bf..affb65ccbd 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -12,6 +12,7 @@
 #include <dm.h>
 #include <handoff.h>
 #include <spl.h>
+#include <asm/sections.h>
 #include <asm/u-boot.h>
 #include <nand.h>
 #include <fat.h>
@@ -439,6 +440,28 @@ static int spl_common_init(bool setup_malloc)
 	return 0;
 }
 
+#if !defined(CONFIG_SPL_SKIP_RELOCATE) && !defined(CONFIG_TPL_BUILD)
+static void spl_setup_relocate(void)
+{
+	gd->relocaddr = CONFIG_SPL_RELOC_TEXT_BASE;
+	gd->new_gd = (gd_t *)gd;
+	gd->start_addr_sp = gd->relocaddr;
+	gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
+
+	gd->start_addr_sp -= gd->fdt_size;
+	gd->new_fdt = (void *)gd->start_addr_sp;
+	memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
+	gd->fdt_blob = gd->new_fdt;
+
+	gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
+}
+#else
+static void spl_setup_relocate(void)
+{
+
+}
+#endif
+
 void spl_set_bd(void)
 {
 	/*
@@ -460,6 +483,8 @@ int spl_early_init(void)
 		return ret;
 	gd->flags |= GD_FLG_SPL_EARLY_INIT;
 
+	spl_setup_relocate();
+
 	return 0;
 }
 
@@ -563,6 +588,34 @@ static int boot_from_devices(struct spl_image_info *spl_image,
 	return -ENODEV;
 }
 
+#if defined(CONFIG_DM) && !defined(CONFIG_SPL_SKIP_RELOCATE) && !defined(CONFIG_TPL_BUILD)
+static int spl_initr_dm(void)
+{
+	int ret;
+
+	/* Save the pre-reloc driver model and start a new one */
+	gd->dm_root_f = gd->dm_root;
+	gd->dm_root = NULL;
+	bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
+	ret = dm_init_and_scan(false);
+	bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
+	if (ret)
+		return ret;
+
+#if defined(CONFIG_TIMER)
+	gd->timer = NULL;
+#endif
+	serial_init();
+
+	return 0;
+}
+#else
+static int spl_initr_dm(void)
+{
+	return 0;
+}
+#endif
+
 void board_init_r(gd_t *dummy1, ulong dummy2)
 {
 	u32 spl_boot_list[] = {
@@ -577,6 +630,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 
 	debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
 
+	spl_initr_dm();
+
 	spl_set_bd();
 
 #if defined(CONFIG_SYS_SPL_MALLOC_START)
-- 
2.17.1

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

* [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8
  2019-04-29  9:04 [U-Boot] [PATCH 1/2] spl: add relocation support Andy Yan
@ 2019-04-29  9:06 ` Andy Yan
  2019-04-29 11:08   ` Fabio Estevam
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Yan @ 2019-04-29  9:06 UTC (permalink / raw)
  To: u-boot

Relocate spl itself to a high memory.

Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
---

 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(-)

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index f25603109e..7f6ad89601 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -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
diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index fe52166e28..a7dad3cd69 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -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.
diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds b/arch/arm/cpu/armv8/u-boot-spl.lds
index ccbf359bd1..64102afc8b 100644
--- a/arch/arm/cpu/armv8/u-boot-spl.lds
+++ b/arch/arm/cpu/armv8/u-boot-spl.lds
@@ -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) : {
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 48ee6c3c60..f27b3fb79f 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -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
diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
index d6b632aa87..e5605fe325 100644
--- a/arch/arm/lib/crt0_64.S
+++ b/arch/arm/lib/crt0_64.S
@@ -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
-- 
2.17.1

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

* [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8
  2019-04-29  9:06 ` [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8 Andy Yan
@ 2019-04-29 11:08   ` Fabio Estevam
  2019-04-29 11:38     ` Andy Yan
  0 siblings, 1 reply; 7+ messages in thread
From: Fabio Estevam @ 2019-04-29 11:08 UTC (permalink / raw)
  To: u-boot

Hi Andy,

On Mon, Apr 29, 2019 at 6:06 AM Andy Yan <andy.yan@rock-chips.com> wrote:
>
> Relocate spl itself to a high memory.

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

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

* [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8
  2019-04-29 11:08   ` Fabio Estevam
@ 2019-04-29 11:38     ` Andy Yan
  2019-04-29 11:46       ` Marek Vasut
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Yan @ 2019-04-29 11:38 UTC (permalink / raw)
  To: u-boot

Hi Fabio:

On 2019/4/29 下午7:08, Fabio Estevam wrote:
> Hi Andy,
>
> On Mon, Apr 29, 2019 at 6:06 AM Andy Yan <andy.yan@rock-chips.com> wrote:
>> 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.

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

* [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8
  2019-04-29 11:38     ` Andy Yan
@ 2019-04-29 11:46       ` Marek Vasut
  2019-04-29 11:58         ` Andy Yan
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Vasut @ 2019-04-29 11:46 UTC (permalink / raw)
  To: u-boot

On 4/29/19 1:38 PM, Andy Yan wrote:
> Hi Fabio:
> 
> On 2019/4/29 下午7:08, Fabio Estevam wrote:
>> Hi Andy,
>>
>> On Mon, Apr 29, 2019 at 6:06 AM Andy Yan <andy.yan@rock-chips.com> wrote:
>>> 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.

-- 
Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8
  2019-04-29 11:46       ` Marek Vasut
@ 2019-04-29 11:58         ` Andy Yan
  2019-04-29 12:07           ` Marek Vasut
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Yan @ 2019-04-29 11:58 UTC (permalink / raw)
  To: u-boot

Hi Marek, Fabio:

On 2019/4/29 下午7:46, Marek Vasut wrote:
> On 4/29/19 1:38 PM, Andy Yan wrote:
>> Hi Fabio:
>>
>> On 2019/4/29 下午7:08, Fabio Estevam wrote:
>>> Hi Andy,
>>>
>>> On Mon, Apr 29, 2019 at 6:06 AM Andy Yan <andy.yan@rock-chips.com> wrote:
>>>> 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.

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

* [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8
  2019-04-29 11:58         ` Andy Yan
@ 2019-04-29 12:07           ` Marek Vasut
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2019-04-29 12:07 UTC (permalink / raw)
  To: u-boot

On 4/29/19 1:58 PM, Andy Yan wrote:
> Hi Marek, Fabio:
> 
> On 2019/4/29 下午7:46, Marek Vasut wrote:
>> On 4/29/19 1:38 PM, Andy Yan wrote:
>>> Hi Fabio:
>>>
>>> On 2019/4/29 下午7:08, Fabio Estevam wrote:
>>>> Hi Andy,
>>>>
>>>> On Mon, Apr 29, 2019 at 6:06 AM Andy Yan <andy.yan@rock-chips.com>
>>>> wrote:
>>>>> 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.

Thanks

-- 
Best regards,
Marek Vasut

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

end of thread, other threads:[~2019-04-29 12:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-29  9:04 [U-Boot] [PATCH 1/2] spl: add relocation support Andy Yan
2019-04-29  9:06 ` [U-Boot] [PATCH 2/2] arm: add spl relocation support for armv8 Andy Yan
2019-04-29 11:08   ` Fabio Estevam
2019-04-29 11:38     ` Andy Yan
2019-04-29 11:46       ` Marek Vasut
2019-04-29 11:58         ` Andy Yan
2019-04-29 12:07           ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.