<p>Kévin Redon has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/12912">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">add force DFU using magic value<br><br>if the string "DFU!" is found at the beginning of the RAM (e.g. as<br>written by the main application during USB detach), the DFU<br>bootloader will be started.<br><br>Change-Id: I298e3697c06d352a6e0f47266097844c490e1722<br>---<br>M README.md<br>M gcc/gcc/same54p20a_flash.ld<br>M usb_dfu_main.c<br>3 files changed, 26 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/12/12912/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/README.md b/README.md</span><br><span>index d6d8d69..8402b13 100644</span><br><span>--- a/README.md</span><br><span>+++ b/README.md</span><br><span>@@ -28,10 +28,16 @@</span><br><span> </span><br><span> Set the corresponding attributes in the 'DFUD_IFACE_DESCB' macro definition in the 'usb/class/dfu/device/dfudf_desc.h' file.</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+To force the DFU bootloader to start there are several possibilities:</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+* if the application following the bootloader is invalid (e.g. MSP is not in RAM)</span><br><span style="color: hsl(120, 100%, 40%);">+* if a button is pressed (the button defined in *BUTTON_FORCE_DFU*)</span><br><span style="color: hsl(120, 100%, 40%);">+* if the magic value "DFU!" (e.g. 0x44465521) is set at the start of the RAM (e.g. by the main application when performing a USB detach) </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> Compiling</span><br><span> =========</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-Use the 'Makefile' script to compile the source code using the ARM none EABI GCC cross-cimpilig toolchain:</span><br><span style="color: hsl(120, 100%, 40%);">+Use the 'Makefile' script to compile the source code using the ARM none EABI GCC cross-compiling toolchain:</span><br><span> ```</span><br><span> cd gcc</span><br><span> make</span><br><span>diff --git a/gcc/gcc/same54p20a_flash.ld b/gcc/gcc/same54p20a_flash.ld</span><br><span>index 08099d2..32ded77 100644</span><br><span>--- a/gcc/gcc/same54p20a_flash.ld</span><br><span>+++ b/gcc/gcc/same54p20a_flash.ld</span><br><span>@@ -36,7 +36,8 @@</span><br><span> MEMORY</span><br><span> {</span><br><span>   rom      (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00100000</span><br><span style="color: hsl(0, 100%, 40%);">-  ram      (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000</span><br><span style="color: hsl(120, 100%, 40%);">+  /* The first word of the RAM is used for the DFU magic */</span><br><span style="color: hsl(120, 100%, 40%);">+  ram      (rwx) : ORIGIN = 0x20000000 + 4, LENGTH = 0x00040000 - 4</span><br><span>   bkupram  (rwx) : ORIGIN = 0x47000000, LENGTH = 0x00002000</span><br><span>   qspi     (rwx) : ORIGIN = 0x04000000, LENGTH = 0x01000000</span><br><span> }</span><br><span>@@ -47,6 +48,12 @@</span><br><span> /* Section Definitions */</span><br><span> SECTIONS</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+    /* Location of the DFU magic. The application must set the magic value "DFU!" (e.g. 0x44465521) at this address to force the DFU bootloader to start (e.g. to perform a DFU detach) */</span><br><span style="color: hsl(120, 100%, 40%);">+    .dfu_magic 0x20000000 :</span><br><span style="color: hsl(120, 100%, 40%);">+    {</span><br><span style="color: hsl(120, 100%, 40%);">+        KEEP(*(.dfu_magic)) ;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     .text :</span><br><span>     {</span><br><span>         . = ALIGN(4);</span><br><span>diff --git a/usb_dfu_main.c b/usb_dfu_main.c</span><br><span>index 96032c5..81b02f8 100644</span><br><span>--- a/usb_dfu_main.c</span><br><span>+++ b/usb_dfu_main.c</span><br><span>@@ -27,6 +27,9 @@</span><br><span>  */</span><br><span> static uint32_t* application_start_address;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/** Location of the DFU magic value to force starting DFU */</span><br><span style="color: hsl(120, 100%, 40%);">+static uint32_t dfu_magic __attribute__ ((section (".dfu_magic"))) __attribute__ ((__used__));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /** Check if the bootloader is valid</span><br><span>  *  \return true if the bootloader is valid and can be run</span><br><span>  *  \remark initializes application_start_address</span><br><span>@@ -48,7 +51,14 @@</span><br><span>  */</span><br><span> static bool check_force_dfu(void)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-     return (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)); // signal is low when button is pressed</span><br><span style="color: hsl(120, 100%, 40%);">+   if (0x44465521 == dfu_magic) { // check for the magic value which can be set by the main application</span><br><span style="color: hsl(120, 100%, 40%);">+          dfu_magic = 0; // erase value so we don't stay in the DFU bootloader upon reset</span><br><span style="color: hsl(120, 100%, 40%);">+           return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)) { // signal is low when button is pressed</span><br><span style="color: hsl(120, 100%, 40%);">+              return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     return false;</span><br><span> }</span><br><span> </span><br><span> /** Check if the application is valid</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/12912">change 12912</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/12912"/><meta itemprop="name" content="View Change"/></div></div>

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