<p>Kévin Redon has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/9908">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">DFU: set stack pointer before starting main app<br><br>The stack size is fixed. The linker script puts the stack section<br>after the bss section. The initial stack pointer is not at the<br>end of the RAM (as often seen).<br>Thus the initial stack pointer address of the main application<br>is different than the one from DFU. When starting the main<br>application the stack pointer needs to be set to the new value.<br>If this is not done the main application stack may overwrite the<br>data in bss, even without exceeding the fixed stack size.<br><br>Change-Id: Ie354d603fe302d3d5bdfa9c31575411de722323b<br>---<br>M firmware/libboard/common/source/board_cstartup_gnu.c<br>1 file changed, 5 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/08/9908/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/firmware/libboard/common/source/board_cstartup_gnu.c b/firmware/libboard/common/source/board_cstartup_gnu.c</span><br><span>index 15c70dd..4b561ec 100644</span><br><span>--- a/firmware/libboard/common/source/board_cstartup_gnu.c</span><br><span>+++ b/firmware/libboard/common/source/board_cstartup_gnu.c</span><br><span>@@ -133,7 +133,11 @@</span><br><span>   void (*appReset)(void); </span><br><span> </span><br><span>         pSrc = (unsigned int *) ((unsigned char *)IFLASH_ADDR + BOARD_DFU_BOOT_SIZE); </span><br><span style="color: hsl(0, 100%, 40%);">-        SCB->VTOR = ((unsigned int)(pSrc)) | (0x0 << 7); </span><br><span style="color: hsl(120, 100%, 40%);">+      /* set vector table to application vector table (store at the beginning of the application) */ </span><br><span style="color: hsl(120, 100%, 40%);">+      SCB->VTOR = (unsigned int)(pSrc); </span><br><span style="color: hsl(120, 100%, 40%);">+      /* set stack pointer to address provided in the beginning of the application (loaded into a register first) */ </span><br><span style="color: hsl(120, 100%, 40%);">+      __asm__ volatile ("MSR msp,%0" : :"r"(*pSrc)); </span><br><span style="color: hsl(120, 100%, 40%);">+      /* start application (by jumping to the reset function which address is stored as second entry of the vector table) */ </span><br><span>     appReset = (void(*)(void))pSrc[1]; </span><br><span> </span><br><span>         g_dfu->state = DFU_STATE_appIDLE; </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/9908">change 9908</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/9908"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: simtrace2 </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ie354d603fe302d3d5bdfa9c31575411de722323b </div>
<div style="display:none"> Gerrit-Change-Number: 9908 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kévin Redon <kredon@sysmocom.de> </div>