<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/simtrace2/+/16556">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">improve shared bootloader/application memory<br><br>now both partitions (bootloader and application) use a commonly<br>defined memory location to shared the DFU state (which includes<br>the magic value to know which part to start), instead of using<br>a hard coded value.<br><br>the bootloader size has now also been restricted to 16 kB.<br>this limitation is enforced so to not be able to create larger<br>images, which could be corrupted when flashing the application.<br><br>bootloader and application flashing have been successfully tested<br>on qmod st12 and st34.<br><br>Change-Id: I204bed7e9391602672ed894decec1fc12e879275<br>---<br>M firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c<br>M firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c<br>M firmware/libboard/common/resources/sam3s4/dfu.ld<br>M firmware/libboard/common/resources/sam3s4/flash.ld<br>4 files changed, 17 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c</span><br><span>index 3ffd9b3..e95c67b 100644</span><br><span>--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c</span><br><span>+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c</span><br><span>@@ -33,8 +33,7 @@</span><br><span> #include <usb/common/dfu/usb_dfu.h></span><br><span> #include <usb/device/dfu/dfu.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* FIXME: this was used for a special ELF section which then got called</span><br><span style="color: hsl(0, 100%, 40%);">- * by DFU code and Application code, across flash partitions */</span><br><span style="color: hsl(120, 100%, 40%);">+/** specific memory location shared across bootloader and application */</span><br><span> #define __dfudata __attribute__ ((section (".dfudata")))</span><br><span> #define __dfufunc</span><br><span> </span><br><span>@@ -42,11 +41,14 @@</span><br><span> static USBDDriver usbdDriver;</span><br><span> static unsigned char if_altsettings[1];</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/** structure containing the DFU state and magic value to know if DFU or application should be started */</span><br><span> __dfudata struct dfudata _g_dfu = {</span><br><span>        .state = DFU_STATE_appIDLE,</span><br><span>  .past_manifest = 0,</span><br><span>  .total_bytes = 0,</span><br><span> };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/** variable to structure containing DFU state */</span><br><span> struct dfudata *g_dfu = &_g_dfu;</span><br><span> </span><br><span> WEAK void dfu_drv_updstatus(void)</span><br><span>diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c</span><br><span>index ac4d7df..4f772be 100644</span><br><span>--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c</span><br><span>+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c</span><br><span>@@ -36,7 +36,12 @@</span><br><span> #include <usb/common/dfu/usb_dfu.h></span><br><span> #include <usb/device/dfu/dfu.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-struct dfudata *g_dfu = (struct dfudata *) IRAM_ADDR;</span><br><span style="color: hsl(120, 100%, 40%);">+/** specific memory location shared across bootloader and application */</span><br><span style="color: hsl(120, 100%, 40%);">+#define __dfudata __attribute__ ((section (".dfudata")))</span><br><span style="color: hsl(120, 100%, 40%);">+/** structure containing the magic value to know if DFU or application should be started */</span><br><span style="color: hsl(120, 100%, 40%);">+__dfudata struct dfudata _g_dfu;</span><br><span style="color: hsl(120, 100%, 40%);">+/** variable to structure containing the magic value to know if DFU or application should be started */</span><br><span style="color: hsl(120, 100%, 40%);">+struct dfudata *g_dfu = &_g_dfu;</span><br><span> </span><br><span> /* FIXME: this was used for a special ELF section which then got called</span><br><span>  * by DFU code and Application code, across flash partitions */</span><br><span>diff --git a/firmware/libboard/common/resources/sam3s4/dfu.ld b/firmware/libboard/common/resources/sam3s4/dfu.ld</span><br><span>index e56a435..a485770 100644</span><br><span>--- a/firmware/libboard/common/resources/sam3s4/dfu.ld</span><br><span>+++ b/firmware/libboard/common/resources/sam3s4/dfu.ld</span><br><span>@@ -39,9 +39,9 @@</span><br><span> MEMORY</span><br><span> {</span><br><span>         /* reserve the first 16k (= 0x4000) for the DFU bootloader */</span><br><span style="color: hsl(0, 100%, 40%);">-   rom (rx)  : ORIGIN = 0x00404000, LENGTH = 0x0003c000 /* flash, 256K */</span><br><span style="color: hsl(0, 100%, 40%);">-  /* reserve the first 32 (= 0x20) bytes for the _g_dfu struct */</span><br><span style="color: hsl(0, 100%, 40%);">- ram (rwx) : ORIGIN = 0x20000020, LENGTH = 0x0000bfe0 /* sram, 48K */</span><br><span style="color: hsl(120, 100%, 40%);">+  rom (rx)  : ORIGIN = 0x00400000 + 16K, LENGTH = 256K - 16K /* flash, 256K */</span><br><span style="color: hsl(120, 100%, 40%);">+  /* note: dfudata will be at the start */</span><br><span style="color: hsl(120, 100%, 40%);">+      ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K /* SRAM, 48K */</span><br><span> }</span><br><span> </span><br><span> /* Section Definitions */ </span><br><span>@@ -111,6 +111,8 @@</span><br><span>     {</span><br><span>         . = ALIGN(4);</span><br><span>         _srelocate = .;</span><br><span style="color: hsl(120, 100%, 40%);">+        /* we must make sure the .dfudata is linked to start of RAM */</span><br><span style="color: hsl(120, 100%, 40%);">+        *(.dfudata .dfudata.*);</span><br><span>         *(.ramfunc .ramfunc.*);</span><br><span>         *(.data .data.*);</span><br><span>         . = ALIGN(4);</span><br><span>diff --git a/firmware/libboard/common/resources/sam3s4/flash.ld b/firmware/libboard/common/resources/sam3s4/flash.ld</span><br><span>index bdebbde..f5cdbfd 100644</span><br><span>--- a/firmware/libboard/common/resources/sam3s4/flash.ld</span><br><span>+++ b/firmware/libboard/common/resources/sam3s4/flash.ld</span><br><span>@@ -38,8 +38,8 @@</span><br><span> /* Memory Spaces Definitions */</span><br><span> MEMORY</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    rom (rx)  : ORIGIN = 0x00400000, LENGTH = 0x00040000 /* flash, 256K */</span><br><span style="color: hsl(0, 100%, 40%);">-  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0000c000 /* sram, 48K */</span><br><span style="color: hsl(120, 100%, 40%);">+  rom (rx)  : ORIGIN = 0x00400000, LENGTH = 16K /* flash, 256K, but only the first 16K should be used for the bootloader */</span><br><span style="color: hsl(120, 100%, 40%);">+     ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K /* SRAM, 48K */</span><br><span> }</span><br><span> </span><br><span> /* Section Definitions */ </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/simtrace2/+/16556">change 16556</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/c/simtrace2/+/16556"/><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-Change-Id: I204bed7e9391602672ed894decec1fc12e879275 </div>
<div style="display:none"> Gerrit-Change-Number: 16556 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: tsaitgaist <kredon@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>