diff mbox series

[1/2] arm64: Add missing GD_FLG_SKIP_RELOC handling

Message ID 20211010215209.872181-1-marek.vasut@gmail.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series [1/2] arm64: Add missing GD_FLG_SKIP_RELOC handling | expand

Commit Message

Marek Vasut Oct. 10, 2021, 9:52 p.m. UTC
From: Marek Vasut <marek.vasut+renesas@gmail.com>

In case U-Boot enters relocation with GD_FLG_SKIP_RELOC, skip the
relocation. The code still has to set up new_gd pointer and new
stack pointer.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
 arch/arm/lib/crt0_64.S | 4 ++++
 lib/asm-offsets.c      | 3 +++
 2 files changed, 7 insertions(+)

Comments

Peng Fan (OSS) Oct. 14, 2021, 1:55 a.m. UTC | #1
On 2021/10/11 5:52, marek.vasut@gmail.com wrote:
> From: Marek Vasut <marek.vasut+renesas@gmail.com>
> 
> In case U-Boot enters relocation with GD_FLG_SKIP_RELOC, skip the
> relocation. The code still has to set up new_gd pointer and new
> stack pointer.
> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>   arch/arm/lib/crt0_64.S | 4 ++++
>   lib/asm-offsets.c      | 3 +++
>   2 files changed, 7 insertions(+)
> 
> diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
> index 680e674fa3..28c8356aee 100644
> --- a/arch/arm/lib/crt0_64.S
> +++ b/arch/arm/lib/crt0_64.S
> @@ -104,6 +104,10 @@ ENTRY(_main)
>   	bic	sp, x0, #0xf	/* 16-byte alignment for ABI compliance */
>   	ldr	x18, [x18, #GD_NEW_GD]		/* x18 <- gd->new_gd */
>   
> +	/* Skip relocation in case gd->gd_flags & GD_FLG_SKIP_RELOC */
> +	ldr	x0, [x18, #GD_FLAGS]		/* x0 <- gd->flags */

You are using new_gd, that means bit 11 needs to be set after
new_gd has been filled with gd.

I would prefer use gd, not new_gd.

Thanks,
Peng.

> +	tbnz	x0, 11, relocation_return	/* GD_FLG_SKIP_RELOC is bit 11 */
> +
>   	adr	lr, relocation_return
>   #if CONFIG_POSITION_INDEPENDENT
>   	/* Add in link-vs-runtime offset */
> diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
> index c691066332..0808cd4b0c 100644
> --- a/lib/asm-offsets.c
> +++ b/lib/asm-offsets.c
> @@ -29,6 +29,9 @@ int main(void)
>   	DEFINE(GD_SIZE, sizeof(struct global_data));
>   
>   	DEFINE(GD_BD, offsetof(struct global_data, bd));
> +
> +	DEFINE(GD_FLAGS, offsetof(struct global_data, flags));
> +
>   #if CONFIG_VAL(SYS_MALLOC_F_LEN)
>   	DEFINE(GD_MALLOC_BASE, offsetof(struct global_data, malloc_base));
>   #endif
>
Marek Vasut Oct. 15, 2021, 2 p.m. UTC | #2
On 10/14/21 3:55 AM, Peng Fan (OSS) wrote:
[...]
>> diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
>> index 680e674fa3..28c8356aee 100644
>> --- a/arch/arm/lib/crt0_64.S
>> +++ b/arch/arm/lib/crt0_64.S
>> @@ -104,6 +104,10 @@ ENTRY(_main)
>>       bic    sp, x0, #0xf    /* 16-byte alignment for ABI compliance */
>>       ldr    x18, [x18, #GD_NEW_GD]        /* x18 <- gd->new_gd */
>> +    /* Skip relocation in case gd->gd_flags & GD_FLG_SKIP_RELOC */
>> +    ldr    x0, [x18, #GD_FLAGS]        /* x0 <- gd->flags */
> 
> You are using new_gd, that means bit 11 needs to be set after
> new_gd has been filled with gd.
> 
> I would prefer use gd, not new_gd.

Both gd and newgd have GD_FLG_SKIP_RELOC set very early on, in u-boot 
that's currently done by one board in mach_cpu_init, so that should be 
no problem. Moreover, both gd and newgd flags must be identical as far 
as I can tell.
diff mbox series

Patch

diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S
index 680e674fa3..28c8356aee 100644
--- a/arch/arm/lib/crt0_64.S
+++ b/arch/arm/lib/crt0_64.S
@@ -104,6 +104,10 @@  ENTRY(_main)
 	bic	sp, x0, #0xf	/* 16-byte alignment for ABI compliance */
 	ldr	x18, [x18, #GD_NEW_GD]		/* x18 <- gd->new_gd */
 
+	/* Skip relocation in case gd->gd_flags & GD_FLG_SKIP_RELOC */
+	ldr	x0, [x18, #GD_FLAGS]		/* x0 <- gd->flags */
+	tbnz	x0, 11, relocation_return	/* GD_FLG_SKIP_RELOC is bit 11 */
+
 	adr	lr, relocation_return
 #if CONFIG_POSITION_INDEPENDENT
 	/* Add in link-vs-runtime offset */
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index c691066332..0808cd4b0c 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -29,6 +29,9 @@  int main(void)
 	DEFINE(GD_SIZE, sizeof(struct global_data));
 
 	DEFINE(GD_BD, offsetof(struct global_data, bd));
+
+	DEFINE(GD_FLAGS, offsetof(struct global_data, flags));
+
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
 	DEFINE(GD_MALLOC_BASE, offsetof(struct global_data, malloc_base));
 #endif