Change in osmo-asf4-dfu[master]: add force DFU using magic value

2019-02-14 Thread Harald Welte
Harald Welte has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/12912 )

Change subject: add force DFU using magic value
..

add force DFU using magic value

if the string "DFU!" is found at the beginning of the RAM (e.g. as
written by the main application during USB detach), the DFU
bootloader will be started.

Change-Id: I298e3697c06d352a6e0f47266097844c490e1722
---
M README.md
M gcc/gcc/same54p20a_flash.ld
M usb_dfu_main.c
3 files changed, 26 insertions(+), 3 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/README.md b/README.md
index 96cf583..dd61824 100644
--- a/README.md
+++ b/README.md
@@ -28,10 +28,16 @@

 Set the corresponding attributes in the 'DFUD_IFACE_DESCB' macro definition in 
the 'usb/class/dfu/device/dfudf_desc.h' file.

+To force the DFU bootloader to start there are several possibilities:
+
+* if the application following the bootloader is invalid (e.g. MSP is not in 
RAM)
+* if a button is pressed (the button defined in *BUTTON_FORCE_DFU*)
+* 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)
+
 Compiling
 =

-Use the 'Makefile' script to compile the source code using the ARM none EABI 
GCC cross-cimpilig toolchain:
+Use the 'Makefile' script to compile the source code using the ARM none EABI 
GCC cross-compiling toolchain:
 ```
 cd gcc
 make
diff --git a/gcc/gcc/same54p20a_flash.ld b/gcc/gcc/same54p20a_flash.ld
index 08099d2..32ded77 100644
--- a/gcc/gcc/same54p20a_flash.ld
+++ b/gcc/gcc/same54p20a_flash.ld
@@ -36,7 +36,8 @@
 MEMORY
 {
   rom  (rx)  : ORIGIN = 0x, LENGTH = 0x0010
-  ram  (rwx) : ORIGIN = 0x2000, LENGTH = 0x0004
+  /* The first word of the RAM is used for the DFU magic */
+  ram  (rwx) : ORIGIN = 0x2000 + 4, LENGTH = 0x0004 - 4
   bkupram  (rwx) : ORIGIN = 0x4700, LENGTH = 0x2000
   qspi (rwx) : ORIGIN = 0x0400, LENGTH = 0x0100
 }
@@ -47,6 +48,12 @@
 /* Section Definitions */
 SECTIONS
 {
+/* 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) */
+.dfu_magic 0x2000 :
+{
+KEEP(*(.dfu_magic)) ;
+}
+
 .text :
 {
 . = ALIGN(4);
diff --git a/usb_dfu_main.c b/usb_dfu_main.c
index 96032c5..81b02f8 100644
--- a/usb_dfu_main.c
+++ b/usb_dfu_main.c
@@ -27,6 +27,9 @@
  */
 static uint32_t* application_start_address;

+/** Location of the DFU magic value to force starting DFU */
+static uint32_t dfu_magic __attribute__ ((section (".dfu_magic"))) 
__attribute__ ((__used__));
+
 /** Check if the bootloader is valid
  *  \return true if the bootloader is valid and can be run
  *  \remark initializes application_start_address
@@ -48,7 +51,14 @@
  */
 static bool check_force_dfu(void)
 {
-   return (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)); // signal is low 
when button is pressed
+   if (0x44465521 == dfu_magic) { // check for the magic value which can 
be set by the main application
+   dfu_magic = 0; // erase value so we don't stay in the DFU 
bootloader upon reset
+   return true;
+   }
+   if (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)) { // signal is low when 
button is pressed
+   return true;
+   }
+   return false;
 }

 /** Check if the application is valid

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

Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I298e3697c06d352a6e0f47266097844c490e1722
Gerrit-Change-Number: 12912
Gerrit-PatchSet: 2
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)


Change in osmo-asf4-dfu[master]: add force DFU using magic value

2019-02-14 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/12912 )

Change subject: add force DFU using magic value
..


Patch Set 2: Code-Review+2


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

Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I298e3697c06d352a6e0f47266097844c490e1722
Gerrit-Change-Number: 12912
Gerrit-PatchSet: 2
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Thu, 14 Feb 2019 21:43:27 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-asf4-dfu[master]: add force DFU using magic value

2019-02-14 Thread Kévin Redon
Kévin Redon has uploaded this change for review. ( 
https://gerrit.osmocom.org/12912


Change subject: add force DFU using magic value
..

add force DFU using magic value

if the string "DFU!" is found at the beginning of the RAM (e.g. as
written by the main application during USB detach), the DFU
bootloader will be started.

Change-Id: I298e3697c06d352a6e0f47266097844c490e1722
---
M README.md
M gcc/gcc/same54p20a_flash.ld
M usb_dfu_main.c
3 files changed, 26 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/12/12912/1

diff --git a/README.md b/README.md
index d6d8d69..8402b13 100644
--- a/README.md
+++ b/README.md
@@ -28,10 +28,16 @@

 Set the corresponding attributes in the 'DFUD_IFACE_DESCB' macro definition in 
the 'usb/class/dfu/device/dfudf_desc.h' file.

+To force the DFU bootloader to start there are several possibilities:
+
+* if the application following the bootloader is invalid (e.g. MSP is not in 
RAM)
+* if a button is pressed (the button defined in *BUTTON_FORCE_DFU*)
+* 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)
+
 Compiling
 =

-Use the 'Makefile' script to compile the source code using the ARM none EABI 
GCC cross-cimpilig toolchain:
+Use the 'Makefile' script to compile the source code using the ARM none EABI 
GCC cross-compiling toolchain:
 ```
 cd gcc
 make
diff --git a/gcc/gcc/same54p20a_flash.ld b/gcc/gcc/same54p20a_flash.ld
index 08099d2..32ded77 100644
--- a/gcc/gcc/same54p20a_flash.ld
+++ b/gcc/gcc/same54p20a_flash.ld
@@ -36,7 +36,8 @@
 MEMORY
 {
   rom  (rx)  : ORIGIN = 0x, LENGTH = 0x0010
-  ram  (rwx) : ORIGIN = 0x2000, LENGTH = 0x0004
+  /* The first word of the RAM is used for the DFU magic */
+  ram  (rwx) : ORIGIN = 0x2000 + 4, LENGTH = 0x0004 - 4
   bkupram  (rwx) : ORIGIN = 0x4700, LENGTH = 0x2000
   qspi (rwx) : ORIGIN = 0x0400, LENGTH = 0x0100
 }
@@ -47,6 +48,12 @@
 /* Section Definitions */
 SECTIONS
 {
+/* 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) */
+.dfu_magic 0x2000 :
+{
+KEEP(*(.dfu_magic)) ;
+}
+
 .text :
 {
 . = ALIGN(4);
diff --git a/usb_dfu_main.c b/usb_dfu_main.c
index 96032c5..81b02f8 100644
--- a/usb_dfu_main.c
+++ b/usb_dfu_main.c
@@ -27,6 +27,9 @@
  */
 static uint32_t* application_start_address;

+/** Location of the DFU magic value to force starting DFU */
+static uint32_t dfu_magic __attribute__ ((section (".dfu_magic"))) 
__attribute__ ((__used__));
+
 /** Check if the bootloader is valid
  *  \return true if the bootloader is valid and can be run
  *  \remark initializes application_start_address
@@ -48,7 +51,14 @@
  */
 static bool check_force_dfu(void)
 {
-   return (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)); // signal is low 
when button is pressed
+   if (0x44465521 == dfu_magic) { // check for the magic value which can 
be set by the main application
+   dfu_magic = 0; // erase value so we don't stay in the DFU 
bootloader upon reset
+   return true;
+   }
+   if (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)) { // signal is low when 
button is pressed
+   return true;
+   }
+   return false;
 }

 /** Check if the application is valid

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

Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I298e3697c06d352a6e0f47266097844c490e1722
Gerrit-Change-Number: 12912
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon