Skip to contentSkip to conversation

arm: s5p4418: fix relocation

PATCH In review Stefan Bosch 3 participants 8 messages Jan 26, 2024 – Mar 4, 2024 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v3 cover arm: s5p4418: fix relocation

Fix relocation of u-boot for s5p4418-SoC. I.e. use __image_copy_start instead of _start to calculate the monitor length. Furthermore use an adapted version of relocate_vectors for the s5p4418-SoC. Background:
The header (NSIH) used by the 2nd-bootloader (included at the begin of u-boot.bin) is not loaded into RAM. Therefore _start has to be after the header and therefore is not equal to __image_copy_start which is at the begin of the header.

Changes in v3:
- MICROBLAZE has not built anymore. Therefore do change calculation of gd->mon_len for ARCH_NEXELL only. This makes sure that MICROBLAZE and other ARM-boards are not affected.

Changes in v2:
- Cosmetic: Fix spelling mistake in commit message

Stefan Bosch (2):
common: board_f: change calculation of gd->mon_len to fix s5p4418
reloc
arm: s5p4418: fix relocation of vectors

 arch/arm/cpu/armv7/s5p4418/Makefile   |  3 +++
 arch/arm/cpu/armv7/s5p4418/relocate.S | 24 ++++++++++++++++++++++++
 common/board_f.c                      |  4 +++-
 3 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/cpu/armv7/s5p4418/relocate.S
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/2 common: board_f: change calculation of gd->mon_len to fix s5p4418 reloc

ARCH_NEXELL: Change calculation of monitor length (gd->mon_len) to fix relocation at boards with s5p4418-SoC (ARCH_NEXELL). At s5p4418, _start is after the header (NSIH). Therefore the monitor length has to be calculated using __image_copy_start instead of _start in order the whole monitor code is relocated.

---

Changes in v3:
- MICROBLAZE has not built anymore. Therefore do change calculation of gd->mon_len for ARCH_NEXELL only. This makes sure that MICROBLAZE and other ARM-boards are not affected.

Changes in v2:
- Cosmetic: Fix spelling mistake in commit message

 common/board_f.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common/board_f.c +3 -1
index d4d7d01f8f..73297fc1b2 100644
@@ -282,7 +282,9 @@ static int init_func_i2c(void)
 
 static int setup_mon_len(void)
 {
-#if defined(__ARM__) || defined(__MICROBLAZE__)
+#if defined(CONFIG_ARCH_NEXELL)
+	gd->mon_len = (ulong)__bss_end - (ulong)__image_copy_start;
+#elif defined(__ARM__) || defined(__MICROBLAZE__)
 	gd->mon_len = (ulong)__bss_end - (ulong)_start;
 #elif defined(CONFIG_SANDBOX) && !defined(__riscv)
 	gd->mon_len = (ulong)_end - (ulong)_init;
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v3 1/2] common: board_f: change calculation of gd->mon_len to fix s5p4418 reloc

Quoted 7 lines · Stefan Bosch

ARCH_NEXELL: Change calculation of monitor length (gd->mon_len) to fix relocation at boards with s5p4418-SoC (ARCH_NEXELL). At s5p4418, _start is after the header (NSIH). Therefore the monitor length has to be calculated using __image_copy_start instead of _start in order the whole monitor code is relocated.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v3 2/2 arm: s5p4418: fix relocation of vectors

In reply to Stefan Bosch

The header (NSIH) used for the s5p4418-SoC is not loaded into RAM by the 2nd-bootloader, see boot0.h. Therefore, use an adapted version of relocate_vectors which relocates the vectors after the header (at _start) instead of the 'dummy'-vectors at the start of the header (at __image_copy_start).

---

(no changes since v1)

 arch/arm/cpu/armv7/s5p4418/Makefile   |  3 +++
 arch/arm/cpu/armv7/s5p4418/relocate.S | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 arch/arm/cpu/armv7/s5p4418/relocate.S
arch/arm/cpu/armv7/s5p4418/Makefile +3 -0
index 321b257b6d..58042581c4 100644
@@ -2,5 +2,8 @@
 #
 # (C) Copyright 2016 Nexell
 # Hyunseok, Jung <[email protected]>
+#
+# Copyright (C) 2023  Stefan Bosch <[email protected]>
 
 obj-y += cpu.o
+obj-y += relocate.o
arch/arm/cpu/armv7/s5p4418/relocate.S new file +24 -0
new file mode 100644
index 0000000000..d6e76adceb
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ *  relocate - S5P4418 specific relocation for ARM U-Boot
+ *
+ *  Copyright (c) 2013  Albert ARIBAUD <[email protected]>
+ *  Copyright (C) 2023  Stefan Bosch <[email protected]>
+ */
+
+#include <asm-offsets.h>
+#include <asm/assembler.h>
+#include <linux/linkage.h>
+
+ENTRY(relocate_vectors)
+
+	/*
+	 * The s5p4418 SoC has the security extensions, so use VBAR to relocate
+	 * the exception vectors.
+	 */
+	ldr	r0, [r9, #GD_RELOCADDR]	/* r0 = gd->relocaddr */
+	add	r0, #0x400			/* vectors are after NSIH + 0x200 */
+	mcr	p15, 0, r0, c12, c0, 0	/* Set VBAR */
+	ret	lr
+
+ENDPROC(relocate_vectors)
Signature · 1 line
2.17.1
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH v3 2/2] arm: s5p4418: fix relocation of vectors

Hi,

2024년 1월 26일 (금) 21:53, Stefan Bosch <[email protected]>님이 작성:

Quoted 64 lines

The header (NSIH) used for the s5p4418-SoC is not loaded into RAM by the 2nd-bootloader, see boot0.h. Therefore, use an adapted version of relocate_vectors which relocates the vectors after the header (at _start) instead of the 'dummy'-vectors at the start of the header (at __image_copy_start).

---

(no changes since v1)

 arch/arm/cpu/armv7/s5p4418/Makefile   |  3 +++
 arch/arm/cpu/armv7/s5p4418/relocate.S | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 arch/arm/cpu/armv7/s5p4418/relocate.S
arch/arm/cpu/armv7/s5p4418/Makefile +3 -0
index 321b257b6d..58042581c4 100644
@@ -2,5 +2,8 @@
 #
 # (C) Copyright 2016 Nexell
 # Hyunseok, Jung <[email protected]>
+#
+# Copyright (C) 2023  Stefan Bosch <[email protected]>
 
 obj-y += cpu.o
+obj-y += relocate.o
arch/arm/cpu/armv7/s5p4418/relocate.S new file +16 -0
new file mode 100644
index 0000000000..d6e76adceb
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ *  relocate - S5P4418 specific relocation for ARM U-Boot
+ *
+ *  Copyright (c) 2013  Albert ARIBAUD <[email protected]>
+ *  Copyright (C) 2023  Stefan Bosch <[email protected]>
+ */
+
+#include <asm-offsets.h>
+#include <asm/assembler.h>
+#include <linux/linkage.h>
+
+ENTRY(relocate_vectors)
+
+       /*
+        * The s5p4418 SoC has the security extensions, so use VBAR to

relocate

arch/arm/cpu/armv7/s5p4418/relocate.S new file +9 -1
+        * the exception vectors.
+        */
+       ldr     r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
+       add     r0, #0x400                      /* vectors are after NSIH
+ 0x200 */
+       mcr     p15, 0, r0, c12, c0, 0  /* Set VBAR */
+       ret     lr
+
+ENDPROC(relocate_vectors)
--
Quoted 2 lines

2.17.1

Thanks.
Minkyu Kang.

#5 lore raw

Re: [PATCH v3 2/2] arm: s5p4418: fix relocation of vectors

In reply to Stefan Bosch
Quoted 8 lines · Stefan Bosch

The header (NSIH) used for the s5p4418-SoC is not loaded into RAM by the 2nd-bootloader, see boot0.h. Therefore, use an adapted version of relocate_vectors which relocates the vectors after the header (at _start) instead of the 'dummy'-vectors at the start of the header (at __image_copy_start).

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#6 lore raw
In reply to Stefan Bosch

Hi, Tom.

Could you please pick this patchset up?

2024년 1월 27일 (토) 05:03, Stefan Bosch <[email protected]>님이 작성:

Quoted 22 lines

Fix relocation of u-boot for s5p4418-SoC. I.e. use __image_copy_start instead of _start to calculate the monitor length. Furthermore use an adapted version of relocate_vectors for the s5p4418-SoC. Background:
The header (NSIH) used by the 2nd-bootloader (included at the begin of u-boot.bin) is not loaded into RAM. Therefore _start has to be after the header and therefore is not equal to __image_copy_start which is at the begin of the header.

Changes in v3:
- MICROBLAZE has not built anymore. Therefore do change calculation of gd->mon_len for ARCH_NEXELL only. This makes sure that MICROBLAZE and other ARM-boards are not affected.

Changes in v2:
- Cosmetic: Fix spelling mistake in commit message

Stefan Bosch (2):
common: board_f: change calculation of gd->mon_len to fix s5p4418
reloc
arm: s5p4418: fix relocation of vectors

Quoted 9 lines
 arch/arm/cpu/armv7/s5p4418/Makefile   |  3 +++
 arch/arm/cpu/armv7/s5p4418/relocate.S | 24 ++++++++++++++++++++++++
 common/board_f.c                      |  4 +++-
 3 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/cpu/armv7/s5p4418/relocate.S

--
2.17.1

Thanks.
Minkyu Kang.

#7 lore raw
Quoted 3 lines · Minkyu Kang

Hi, Tom.

Could you please pick this patchset up?

Aren't there other patches you could pick up as well for a PR? I can pull this directly otherwise if not.

Signature · 1 line
Tom