Skip to contentSkip to conversation

arm: fix exception vectors

PATCH New Luca Ellero 3 participants 7 messages Dec 29, 2014 – Jan 20, 2015 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: fix exception vectors

After relocation, exception vectors still point to the old code (not relocated). This patch fixes them.

---
 arch/arm/lib/relocate.S |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm/lib/relocate.S +15 -0
index 92f5314..4186344 100644
@@ -76,6 +76,21 @@ copy_loop:
 	blo	copy_loop
 
 	/*
+	 * fix exception vectors
+	 */
+	ldr r2, =_undefined_instruction
+	ldr r3, =_fiq
+	add	r2, r2, r4
+	add	r3, r3, r4
+fix_exceptions:
+	ldr r0, [r2]
+	add	r0, r0, r4
+	str	r0, [r2]
+	cmp r2,r3
+	add r2, #4
+	blo fix_exceptions
+
+	/*
 	 * fix .rel.dyn relocations
 	 */
 	ldr	r2, =__rel_dyn_start	/* r2 <- SRC &__rel_dyn_start */
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 arm: fix exception vectors

Hello Luca,

Quoted 37 lines · Luca Ellero

After relocation, exception vectors still point to the old code (not relocated). This patch fixes them.

---
 arch/arm/lib/relocate.S |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm/lib/relocate.S +15 -0
index 92f5314..4186344 100644
@@ -76,6 +76,21 @@ copy_loop:
 	blo	copy_loop
 
 	/*
+	 * fix exception vectors
+	 */
+	ldr r2, =_undefined_instruction
+	ldr r3, =_fiq
+	add	r2, r2, r4
+	add	r3, r3, r4
+fix_exceptions:
+	ldr r0, [r2]
+	add	r0, r0, r4
+	str	r0, [r2]
+	cmp r2,r3
+	add r2, #4
+	blo fix_exceptions
+
+	/*
 	 * fix .rel.dyn relocations
 	 */
 	ldr	r2, =__rel_dyn_start	/* r2 <- SRC &__rel_dyn_start */
Signature · 1 line
1.7.10.4

There is already a mechanism to relocate vectors (do a git grep for 'relocate_vectors' which takes into account various ISA and SoC cases.

Can you describe the use case which you are encountering?

Amicalement,

Signature · 1 line
Albert.
#2 lore raw

PATCH 1/1 arm: fix exception vectors

Hi Albert,

Quoted 45 lines · Albert ARIBAUD

Hello Luca,

Quoted 35 lines · Luca Ellero

After relocation, exception vectors still point to the old code (not relocated). This patch fixes them.

---
  arch/arm/lib/relocate.S |   15 +++++++++++++++
  1 file changed, 15 insertions(+)
arch/arm/lib/relocate.S +15 -1
index 92f5314..4186344 100644
@@ -76,6 +76,21 @@ copy_loop:
  	blo	copy_loop
 
  	/*
+	 * fix exception vectors
+	 */
+	ldr r2, =_undefined_instruction
+	ldr r3, =_fiq
+	add	r2, r2, r4
+	add	r3, r3, r4
+fix_exceptions:
+	ldr r0, [r2]
+	add	r0, r0, r4
+	str	r0, [r2]
+	cmp r2,r3
+	add r2, #4
+	blo fix_exceptions
+
+	/*
  	 * fix .rel.dyn relocations
  	 */
  	ldr	r2, =__rel_dyn_start	/* r2 <- SRC &__rel_dyn_start */
--
Quoted 2 lines

1.7.10.4

There is already a mechanism to relocate vectors (do a git grep for 'relocate_vectors' which takes into account various ISA and SoC cases.

Quoted 1 line

Can you describe the use case which you are encountering?

As far as I can see the mechanism to relocate vectors is implemented only on iMX25/27 and involves high vectors address (0xFFFFxxxx).

The problem is that, after relocation, U-Boot doesn't fix the vector table addresses, they still point to the old addresses (before relocation). This is wrong and this patch fixes them to point to the new addresses.

I had to use this patch trying to implement IRQ support for a Freescale iMX6 board. iMX6 does not provide RAM at the high vectors address and trying to access them leads to errors, so I couldn't use them.

Regards

Signature · 4 lines
Luca Ellero

E-mail: luca.ellero at brickedbrain.com
Internet: www.brickedbrain.com
#3 lore raw

PATCH 1/1 arm: fix exception vectors

Hello Luca,

Quoted 48 lines · Luca Ellero

Hi Albert,

Quoted 45 lines · Albert ARIBAUD

Hello Luca,

Quoted 35 lines · Luca Ellero

After relocation, exception vectors still point to the old code (not relocated). This patch fixes them.

---
  arch/arm/lib/relocate.S |   15 +++++++++++++++
  1 file changed, 15 insertions(+)
arch/arm/lib/relocate.S +15 -1
index 92f5314..4186344 100644
@@ -76,6 +76,21 @@ copy_loop:
  	blo	copy_loop
 
  	/*
+	 * fix exception vectors
+	 */
+	ldr r2, =_undefined_instruction
+	ldr r3, =_fiq
+	add	r2, r2, r4
+	add	r3, r3, r4
+fix_exceptions:
+	ldr r0, [r2]
+	add	r0, r0, r4
+	str	r0, [r2]
+	cmp r2,r3
+	add r2, #4
+	blo fix_exceptions
+
+	/*
  	 * fix .rel.dyn relocations
  	 */
  	ldr	r2, =__rel_dyn_start	/* r2 <- SRC &__rel_dyn_start */
--
Quoted 2 lines

1.7.10.4

There is already a mechanism to relocate vectors (do a git grep for 'relocate_vectors' which takes into account various ISA and SoC cases.

Quoted 4 lines
Quoted 1 line

Can you describe the use case which you are encountering?

As far as I can see the mechanism to relocate vectors is implemented only on iMX25/27 and involves high vectors address (0xFFFFxxxx).

You are correct that the mechanism is /used/ only by mx25 and mx27.

However, it has been introduced to support /all/ SoCs (or even boards), not only mx25, mx27, and /all/ exception vector handling scenarios, not only high vectors addresses.

Actually, the standard high and low address is handled by default, and mx25 and mx27 are cases where this default is overriden /because/ high or low vector addresses are *unapplicable* for them due to their memory mapping.

Quoted 3 lines

The problem is that, after relocation, U-Boot doesn't fix the vector table addresses, they still point to the old addresses (before relocation). This is wrong and this patch fixes them to point to the new addresses.

You are right about the problem, and this problem is exactly what the relocate_vectors mechanism is here to fix -- exactly the same problem mx25 and mx27 had before we fixed it (quite recently actually, as it was done mid-November, between 2015.01-rc1 and 2015.01-rc1 rc2).

Quoted 3 lines

I had to use this patch trying to implement IRQ support for a Freescale iMX6 board. iMX6 does not provide RAM at the high vectors address and trying to access them leads to errors, so I couldn't use them.

This is *exactly* the case where you should define your own version of relocate_vectors (probably at SoC level).

Quoted 4 lines

Regards

Signature · 1 line
Luca Ellero

Amicalement,

Signature · 1 line
Albert.
#4 lore raw

PATCH 1/1 arm: fix exception vectors

Hi Albert,

Quoted 77 lines · Albert ARIBAUD

Hello Luca,

Quoted 48 lines · Luca Ellero

Hi Albert,

Quoted 45 lines · Albert ARIBAUD

Hello Luca,

Quoted 35 lines · Luca Ellero

After relocation, exception vectors still point to the old code (not relocated). This patch fixes them.

---
   arch/arm/lib/relocate.S |   15 +++++++++++++++
   1 file changed, 15 insertions(+)
arch/arm/lib/relocate.S +15 -1
index 92f5314..4186344 100644
@@ -76,6 +76,21 @@ copy_loop:
   	blo	copy_loop
 
   	/*
+	 * fix exception vectors
+	 */
+	ldr r2, =_undefined_instruction
+	ldr r3, =_fiq
+	add	r2, r2, r4
+	add	r3, r3, r4
+fix_exceptions:
+	ldr r0, [r2]
+	add	r0, r0, r4
+	str	r0, [r2]
+	cmp r2,r3
+	add r2, #4
+	blo fix_exceptions
+
+	/*
   	 * fix .rel.dyn relocations
   	 */
   	ldr	r2, =__rel_dyn_start	/* r2 <- SRC &__rel_dyn_start */
--
Quoted 2 lines

1.7.10.4

There is already a mechanism to relocate vectors (do a git grep for 'relocate_vectors' which takes into account various ISA and SoC cases.

Quoted 4 lines
Quoted 1 line

Can you describe the use case which you are encountering?

As far as I can see the mechanism to relocate vectors is implemented only on iMX25/27 and involves high vectors address (0xFFFFxxxx).

You are correct that the mechanism is /used/ only by mx25 and mx27.

However, it has been introduced to support /all/ SoCs (or even boards), not only mx25, mx27, and /all/ exception vector handling scenarios, not only high vectors addresses.

Actually, the standard high and low address is handled by default, and mx25 and mx27 are cases where this default is overriden /because/ high or low vector addresses are *unapplicable* for them due to their memory mapping.

Quoted 3 lines

The problem is that, after relocation, U-Boot doesn't fix the vector table addresses, they still point to the old addresses (before relocation). This is wrong and this patch fixes them to point to the new addresses.

You are right about the problem, and this problem is exactly what the relocate_vectors mechanism is here to fix -- exactly the same problem mx25 and mx27 had before we fixed it (quite recently actually, as it was done mid-November, between 2015.01-rc1 and 2015.01-rc1 rc2).

Quoted 7 lines
Quoted 3 lines

I had to use this patch trying to implement IRQ support for a Freescale iMX6 board. iMX6 does not provide RAM at the high vectors address and trying to access them leads to errors, so I couldn't use them.

This is *exactly* the case where you should define your own version of relocate_vectors (probably at SoC level).

Ok, I will try to implement it as you suggested.
Thank you
regards
Luca

Signature · 4 lines
Luca Ellero

E-mail: luca.ellero at brickedbrain.com
Internet: www.brickedbrain.com
#5 lore raw

PATCH 1/1 arm: fix exception vectors

In reply to Albert ARIBAUD
Quoted 5 lines

On Mon, 19 Jan 2015 11:11:34 +0100, Luca Ellero

Quoted 2 lines

As far as I can see the mechanism to relocate vectors is implemented only on iMX25/27 and involves high vectors address (0xFFFFxxxx).

Quoted 17 lines · albert.u.boot at aribaud.net

You are correct that the mechanism is /used/ only by mx25 and mx27.

However, it has been introduced to support /all/ SoCs (or even boards), not only mx25, mx27, and /all/ exception vector handling scenarios, not only high vectors addresses.

Actually, the standard high and low address is handled by default, and mx25 and mx27 are cases where this default is overriden /because/ high or low vector addresses are *unapplicable* for them due to their memory mapping.

On Mon, 19 Jan 2015 11:11:34 +0100, Luca Ellero

Quoted 4 lines

The problem is that, after relocation, U-Boot doesn't fix the vector table addresses, they still point to the old addresses (before relocation). This is wrong and this patch fixes them to point to the new addresses.

Quoted 11 lines · albert.u.boot at aribaud.net

You are right about the problem, and this problem is exactly what the relocate_vectors mechanism is here to fix -- exactly the same problem mx25 and mx27 had before we fixed it (quite recently actually, as it was done mid-November, between 2015.01-rc1 and 2015.01-rc1 rc2).

On Mon, 19 Jan 2015 11:11:34 +0100, Luca Ellero

Quoted 4 lines

I had to use this patch trying to implement IRQ support for a Freescale iMX6 board. iMX6 does not provide RAM at the high vectors address and trying to access them leads to errors, so I couldn't use them.

Quoted 2 lines · albert.u.boot at aribaud.net

This is *exactly* the case where you should define your own version of relocate_vectors (probably at SoC level).

A key difference is the ARM CPU architecture version. The ARMv7/Cortex on the imx6 will support vector table 'remaps'. Currently I see,

#ifdef CONFIG_HAS_VBAR
        /*
         * If the ARM processor has the security extensions,
         * use VBAR to relocate the exception vectors.
         */
        ldr     r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
        mcr     p15, 0, r0, c12, c0, 0  /* Set VBAR */

#else

This should be available for the CPUs, but I don't see this symbol besides a 'Kconfig'. There are three versions on the Cortex, but the VBAR (whether secure or not) is the the correct one.

At least in theory, this code if activated should work for the iMx6 and an override of the 'weak' relocate vectors is not needed. I think trying to use the 'VBAR' is the correct way to go?

Fwiw,
Bill Pringlemeir.

#6 lore raw

PATCH 1/1 arm: fix exception vectors

Hello Bill,

Quoted 57 lines · Bill Pringlemeir
Quoted 5 lines

On Mon, 19 Jan 2015 11:11:34 +0100, Luca Ellero

Quoted 2 lines

As far as I can see the mechanism to relocate vectors is implemented only on iMX25/27 and involves high vectors address (0xFFFFxxxx).

Quoted 17 lines · albert.u.boot at aribaud.net

You are correct that the mechanism is /used/ only by mx25 and mx27.

However, it has been introduced to support /all/ SoCs (or even boards), not only mx25, mx27, and /all/ exception vector handling scenarios, not only high vectors addresses.

Actually, the standard high and low address is handled by default, and mx25 and mx27 are cases where this default is overriden /because/ high or low vector addresses are *unapplicable* for them due to their memory mapping.

On Mon, 19 Jan 2015 11:11:34 +0100, Luca Ellero

Quoted 4 lines

The problem is that, after relocation, U-Boot doesn't fix the vector table addresses, they still point to the old addresses (before relocation). This is wrong and this patch fixes them to point to the new addresses.

Quoted 11 lines · albert.u.boot at aribaud.net

You are right about the problem, and this problem is exactly what the relocate_vectors mechanism is here to fix -- exactly the same problem mx25 and mx27 had before we fixed it (quite recently actually, as it was done mid-November, between 2015.01-rc1 and 2015.01-rc1 rc2).

On Mon, 19 Jan 2015 11:11:34 +0100, Luca Ellero

Quoted 4 lines

I had to use this patch trying to implement IRQ support for a Freescale iMX6 board. iMX6 does not provide RAM at the high vectors address and trying to access them leads to errors, so I couldn't use them.

Quoted 2 lines · albert.u.boot at aribaud.net

This is *exactly* the case where you should define your own version of relocate_vectors (probably at SoC level).

A key difference is the ARM CPU architecture version. The ARMv7/Cortex on the imx6 will support vector table 'remaps'. Currently I see,

#ifdef CONFIG_HAS_VBAR
        /*
         * If the ARM processor has the security extensions,
         * use VBAR to relocate the exception vectors.
         */
        ldr     r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
        mcr     p15, 0, r0, c12, c0, 0  /* Set VBAR */

#else

Quoted 7 lines

This should be available for the CPUs, but I don't see this symbol besides a 'Kconfig'. There are three versions on the Cortex, but the VBAR (whether secure or not) is the the correct one.

At least in theory, this code if activated should work for the iMx6 and an override of the 'weak' relocate vectors is not needed. I think trying to use the 'VBAR' is the correct way to go?

Possibly, though one should take into account the fact that the SoC design around the armv7 core (and the associated ROM code) might or might not allow changing the VBAR. Best is to look up the i.MX6 technical specs, especially the chapter on exceptions. If no specific indication is given that changing VBAR is forbidden, then yes, one should rely on CONFIG_HAS_VBAR (which should be set for all ARMv7-based targets).

Quoted 2 lines

Fwiw,
Bill Pringlemeir.

Amicalement,

Signature · 1 line
Albert.