From cc59882c7f0efe34baecd6ff68e1b2053a492112 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 12 May 2017 16:23:51 -0700 Subject: restore stackpointer in vector table When using the elf file format the vector table gets linked directly to 0x0 (0x180000 for data bus/A7 bus). U-Boots bootaux command tries to be helpful and writes the start address to that location (since this was necessary for binary files which have a relocated vector table). This is not usually a problem, since we restore the stack pointer imeaditly at the beginning. However, the FreeRTOS port code relies on a complete vector table (see prvPortStartFirstTask in Source/portable/GCC/ARM_CM4F/port.c). This needs to be fixed in U-Boot: U-Boot should not write into the vector table if it is provided by the elf binary. For now, work around by restoring the stack pointer entry in the vector table in the firmware startup code. Signed-off-by: Stefan Agner --- platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S b/platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S index 328fa9b..2a97408 100644 --- a/platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S +++ b/platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S @@ -204,12 +204,18 @@ __isr_vector: .weak Reset_Handler .type Reset_Handler, %function Reset_Handler: + cpsid i /* Mask interrupts */ /* * Set stack pointer manually. Not all loading mechanism setup stack * e.g. when using elf file format with Toradex U-Boot 2016.11 */ - ldr sp,=__stack; - cpsid i /* Mask interrupts */ + ldr sp,=__stack + /* + * When the vector table above is linked to 0x00000000 and we use elf + * U-Boot overwrites the stackpointer with 0... restore it... + */ + ldr r1,=__isr_vector + str sp, [r1] #ifndef __NO_SYSTEM_INIT bl SystemInit #endif -- cgit v1.2.3