Change in simtrace2[master]: DFU: set stack pointer before starting main app

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Sat Jul 7 13:28:52 UTC 2018


Kévin Redon has uploaded this change for review. ( https://gerrit.osmocom.org/9908


Change subject: DFU: set stack pointer before starting main app
......................................................................

DFU: set stack pointer before starting main app

The stack size is fixed. The linker script puts the stack section
after the bss section. The initial stack pointer is not at the
end of the RAM (as often seen).
Thus the initial stack pointer address of the main application
is different than the one from DFU. When starting the main
application the stack pointer needs to be set to the new value.
If this is not done the main application stack may overwrite the
data in bss, even without exceeding the fixed stack size.

Change-Id: Ie354d603fe302d3d5bdfa9c31575411de722323b
---
M firmware/libboard/common/source/board_cstartup_gnu.c
1 file changed, 5 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/08/9908/1

diff --git a/firmware/libboard/common/source/board_cstartup_gnu.c b/firmware/libboard/common/source/board_cstartup_gnu.c
index 15c70dd..4b561ec 100644
--- a/firmware/libboard/common/source/board_cstartup_gnu.c
+++ b/firmware/libboard/common/source/board_cstartup_gnu.c
@@ -133,7 +133,11 @@
 	void (*appReset)(void);
 
 	pSrc = (unsigned int *) ((unsigned char *)IFLASH_ADDR + BOARD_DFU_BOOT_SIZE);
-	SCB->VTOR = ((unsigned int)(pSrc)) | (0x0 << 7);
+	/* set vector table to application vector table (store at the beginning of the application) */
+	SCB->VTOR = (unsigned int)(pSrc);
+	/* set stack pointer to address provided in the beginning of the application (loaded into a register first) */
+	__asm__ volatile ("MSR msp,%0" : :"r"(*pSrc));
+	/* start application (by jumping to the reset function which address is stored as second entry of the vector table) */
 	appReset = (void(*)(void))pSrc[1];
 
 	g_dfu->state = DFU_STATE_appIDLE;

-- 
To view, visit https://gerrit.osmocom.org/9908
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie354d603fe302d3d5bdfa9c31575411de722323b
Gerrit-Change-Number: 9908
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180707/9a6da38e/attachment.htm>


More information about the gerrit-log mailing list