Skip to content

Commit 4c07381

Browse files
author
Bogdan Marinescu
committed
A few changes for ARMCC compatibility
- "(uint32_t)APPLICATION_ADDRESS + 4" simply suppresses an warning from the compiler (related to doing arithmetic on void* pointers). - "applicationResetHandler" is now static, to avoid placing it on the stack, since it is used after the stack pointer is set to the application's stack pointer. - while(1) is needed for armcc. Without it, armcc insists to jump to the application's entry point only *after* restoring the context of "forwardControlToApplication": 806c: f380 8808 msr MSP, r0 8070: 481d ldr r0, [pc, ARMmbed#116] ; (80e8 <forwardControlToApplication+0xe8>) 8072: 6004 str r4, [r0, #0] 8074: 6828 ldr r0, [r5, #0] 8076: e8bd 4070 ldmia.w sp!, {r4, r5, r6, lr} ==> context restore 807a: 4700 bx r0 ==> jump to application This changes the application's initial stack pointer. Because of this, the cloud client example doesn't start anymore when concatenated with the bootloader. With "while(1);" in place, we get the right behaviour: 806a: f380 8808 msr MSP, r0 806e: 481d ldr r0, [pc, ARMmbed#116] ; (80e4 <forwardControlToApplication+0xe4>) 8070: 6004 str r4, [r0, #0] 8072: 6828 ldr r0, [r5, #0] 8074: 4780 blx r0 ==> jump to application Tested with armcc 5.03 update 3. Also tested that the GCC compilation still works with these changes in place.
1 parent 637b734 commit 4c07381

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

source/bootloader_platform.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ void forwardControlToApplication(void)
5656
tr_info(buffer);
5757
#endif
5858

59-
uint32_t JumpAddress = *(const uint32_t *)(APPLICATION_ADDRESS + 4);
59+
uint32_t JumpAddress = *(const uint32_t *)((uint32_t)APPLICATION_ADDRESS + 4);
6060
typedef void (*pFunction)(void);
61-
pFunction applicationResetHandler = (pFunction)JumpAddress;
61+
static pFunction applicationResetHandler;
62+
applicationResetHandler = (pFunction)JumpAddress;
6263

6364
tr_info("application's jump address: %lx", JumpAddress);
6465
tr_info("application's stack address: %lx", *(const uint32_t *)APPLICATION_ADDRESS);
@@ -82,5 +83,8 @@ void forwardControlToApplication(void)
8283
#endif
8384

8485
applicationResetHandler(); /* Jump to application. */
86+
87+
/* Since we're jumping to the application above, this function doesn't return */
88+
while(1);
8589
}
8690
#endif /* #ifdef TARGET_LIKE_ARM */

0 commit comments

Comments
 (0)