Change in osmo-asf4-dfu[master]: add specific board support, including sysmoOCTSIM

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

Change subject: add specific board support, including sysmoOCTSIM
..

add specific board support, including sysmoOCTSIM

the board specific definitions should be coded when particular
environment variable/marco is defined.
this macro name is provided by the makefile in the BOARD variable.
this allows to compile the bootloader for specific devices.
see README for more information.
the board definition for the sysmoOCTSIM is also added.

Change-Id: Ie51a3af7c77ba76ac40570b871f31fd527fb255b
---
M README.md
M atmel_start_pins.h
M config/usbd_config.h
M driver_init.c
M driver_init.h
M gcc/Makefile
M usb_dfu_main.c
M usb_start.c
8 files changed, 109 insertions(+), 14 deletions(-)

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



diff --git a/README.md b/README.md
index 031bc27..58833aa 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,22 @@
 This is an implementation of the DFU mode of the [USB DFU Device Class 
Specification](https://usb.org/document-library/device-firmware-upgrade-11-new-version-31-aug-2004)
 for the Microchip SAM D5x/E5x micro-controller.
 It is meant to be used as bootloader to allow flashing the main application 
over USB.

-The code has been developed for the Microchip [SAM E54 Xplained 
Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNo/ATSAME54-XPRO)
 development board using a [SAM 
E54](https://www.microchip.com/wwwproducts/en/ATSAME54P20A) micro-controller.
+The code has been developed using a [SAM 
E54](https://www.microchip.com/wwwproducts/en/ATSAME54P20A) micro-controller.
 It should work on any chip of the SAM D5x/E5x device family by replacing the 
corresponding device-specific definitions (usually including the chip name in 
the file name).

 The code uses the [Atmel START](https://start.atmel.com/) ASFv4 library.

+Board
+=
+
+The code can be compiled for specific boards:
+
+- Microchip [SAM E54 Xplained 
Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNo/ATSAME54-XPRO)
 development board, named *SAME54_XPLAINED_PRO*
+- sysmocom sysmoOCTSIM, name *SYSMOOCTSIM*
+
+The board name can be set in 'gcc/Makefile' *BOARD* variable, or provided 
while compiling (e.g. `make BOARD=SAME54_XPLAINED_PRO`).
+*SAME54_XPLAINED_PRO* is the default value.
+
 USB DFU
 ===

@@ -26,13 +37,14 @@
 make
 ```

+The board name can be set in 'gcc/Makefile' *BOARD* variable, or provided 
while compiling (e.g. `make BOARD=SAME54_XPLAINED_PRO`).
+*SAME54_XPLAINED_PRO* is the default value.
+
 The resulting firmware binary is `AtmelStart.bin`.

 Flashing
 

-To flash the bootloader you can either use the [edbg 
tool](https://github.com/ataradov/edbg) over the EDBG interface of the SAM E54 
Xplained Pro development board, or OpenICD with any SWJ adapter.
-
 The USB DFU bootloader should be flashed in a protected area of the flash 
memory to prevent for erasing it, as specified in data sheet section 25.6.2 
Memory Organization.
 The bootloader size is configured in the NVM user configuration BOOTPROT 
field, as specified in data sheet section 25.6.9 NVM User Configuration.
 The bit position of the BOOTPROT field is documented in data sheet section 9.4 
NVM User Page Mapping.
@@ -43,8 +55,26 @@
 EDBG
 

+To flash the bootloader using the [edbg 
tool](https://github.com/ataradov/edbg) over the EDBG interface of the SAM E54 
Xplained Pro development board.
+
 To flash the USB DFU bootloader, perform the following actions:
 * remove reserved bootloader space so we can erase it: `edbg --target 
atmel_cm4v2 --fuse wv,29:26,15`
 * erase the whole flash: `edbg --target atmel_cm4v2 --fuse v,29:26,15 --erase`
 * program the bootloader: `edbg --target atmel_cm4v2 --fuse v,29:26,15 
--program --verify --file AtmelStart.bin`
 * reserve bootloader space: `edbg --target atmel_cm4v2 --fuse wv,29:26,13`
+
+SWJ
+---
+
+The bootloader can also be flashed over SWJ (e.g. JTAG or SWD).
+You need to perform the following actions:
+
+* remove reserved bootloader space so we can erase it (and reset MCU for 
change to be effective)
+* erase the whole flash
+* program the bootloader
+* reserve bootloader space
+
+Using OpenOCD (with the [SAM E54 patch](http://openocd.zylin.com/#/c/4272/)) 
and a ST-LINK/V2 SWD adapter, run the following command:
+
+`openocd --file interface/stlink.cfg --command "transport select hla_swd" 
--command "set CHIPNAME same54" --command "set CPUTAPID 0x2ba01477" --file 
target/atsame5x.cfg --command "init" --command "reset halt" --command "atsame5 
bootloader 0" --command "flash erase_sector 0 0 last" --command "reset halt" 
--command "program ./AtmelStart.bin" --command "atsame5 bootloader 16384"  
--command "reset run" --command "shutdown"`
+
diff --git a/atmel_start_pins.h b/atmel_start_pins.h
index 86e1dfb..220a7b5 100644
--- a/atmel_start_pins.h
+++ 

Change in osmo-asf4-dfu[master]: add specific board support, including sysmoOCTSIM

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

Change subject: add specific board support, including sysmoOCTSIM
..


Patch Set 1: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/12910
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: Ie51a3af7c77ba76ac40570b871f31fd527fb255b
Gerrit-Change-Number: 12910
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Thu, 14 Feb 2019 21:42:59 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in osmo-asf4-dfu[master]: add specific board support, including sysmoOCTSIM

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


Change subject: add specific board support, including sysmoOCTSIM
..

add specific board support, including sysmoOCTSIM

the board specific definitions should be coded when particular
environment variable/marco is defined.
this macro name is provided by the makefile in the BOARD variable.
this allows to compile the bootloader for specific devices.
see README for more information.
the board definition for the sysmoOCTSIM is also added.

Change-Id: Ie51a3af7c77ba76ac40570b871f31fd527fb255b
---
M README.md
M atmel_start_pins.h
M config/usbd_config.h
M driver_init.c
M driver_init.h
M gcc/Makefile
M usb_dfu_main.c
M usb_start.c
8 files changed, 109 insertions(+), 14 deletions(-)



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

diff --git a/README.md b/README.md
index 031bc27..58833aa 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,22 @@
 This is an implementation of the DFU mode of the [USB DFU Device Class 
Specification](https://usb.org/document-library/device-firmware-upgrade-11-new-version-31-aug-2004)
 for the Microchip SAM D5x/E5x micro-controller.
 It is meant to be used as bootloader to allow flashing the main application 
over USB.

-The code has been developed for the Microchip [SAM E54 Xplained 
Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNo/ATSAME54-XPRO)
 development board using a [SAM 
E54](https://www.microchip.com/wwwproducts/en/ATSAME54P20A) micro-controller.
+The code has been developed using a [SAM 
E54](https://www.microchip.com/wwwproducts/en/ATSAME54P20A) micro-controller.
 It should work on any chip of the SAM D5x/E5x device family by replacing the 
corresponding device-specific definitions (usually including the chip name in 
the file name).

 The code uses the [Atmel START](https://start.atmel.com/) ASFv4 library.

+Board
+=
+
+The code can be compiled for specific boards:
+
+- Microchip [SAM E54 Xplained 
Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNo/ATSAME54-XPRO)
 development board, named *SAME54_XPLAINED_PRO*
+- sysmocom sysmoOCTSIM, name *SYSMOOCTSIM*
+
+The board name can be set in 'gcc/Makefile' *BOARD* variable, or provided 
while compiling (e.g. `make BOARD=SAME54_XPLAINED_PRO`).
+*SAME54_XPLAINED_PRO* is the default value.
+
 USB DFU
 ===

@@ -26,13 +37,14 @@
 make
 ```

+The board name can be set in 'gcc/Makefile' *BOARD* variable, or provided 
while compiling (e.g. `make BOARD=SAME54_XPLAINED_PRO`).
+*SAME54_XPLAINED_PRO* is the default value.
+
 The resulting firmware binary is `AtmelStart.bin`.

 Flashing
 

-To flash the bootloader you can either use the [edbg 
tool](https://github.com/ataradov/edbg) over the EDBG interface of the SAM E54 
Xplained Pro development board, or OpenICD with any SWJ adapter.
-
 The USB DFU bootloader should be flashed in a protected area of the flash 
memory to prevent for erasing it, as specified in data sheet section 25.6.2 
Memory Organization.
 The bootloader size is configured in the NVM user configuration BOOTPROT 
field, as specified in data sheet section 25.6.9 NVM User Configuration.
 The bit position of the BOOTPROT field is documented in data sheet section 9.4 
NVM User Page Mapping.
@@ -43,8 +55,26 @@
 EDBG
 

+To flash the bootloader using the [edbg 
tool](https://github.com/ataradov/edbg) over the EDBG interface of the SAM E54 
Xplained Pro development board.
+
 To flash the USB DFU bootloader, perform the following actions:
 * remove reserved bootloader space so we can erase it: `edbg --target 
atmel_cm4v2 --fuse wv,29:26,15`
 * erase the whole flash: `edbg --target atmel_cm4v2 --fuse v,29:26,15 --erase`
 * program the bootloader: `edbg --target atmel_cm4v2 --fuse v,29:26,15 
--program --verify --file AtmelStart.bin`
 * reserve bootloader space: `edbg --target atmel_cm4v2 --fuse wv,29:26,13`
+
+SWJ
+---
+
+The bootloader can also be flashed over SWJ (e.g. JTAG or SWD).
+You need to perform the following actions:
+
+* remove reserved bootloader space so we can erase it (and reset MCU for 
change to be effective)
+* erase the whole flash
+* program the bootloader
+* reserve bootloader space
+
+Using OpenOCD (with the [SAM E54 patch](http://openocd.zylin.com/#/c/4272/)) 
and a ST-LINK/V2 SWD adapter, run the following command:
+
+`openocd --file interface/stlink.cfg --command "transport select hla_swd" 
--command "set CHIPNAME same54" --command "set CPUTAPID 0x2ba01477" --file 
target/atsame5x.cfg --command "init" --command "reset halt" --command "atsame5 
bootloader 0" --command "flash erase_sector 0 0 last" --command "reset halt" 
--command "program ./AtmelStart.bin" --command "atsame5 bootloader 16384"  
--command "reset run" --command "shutdown"`
+
diff --git a/atmel_start_pins.h b/atmel_start_pins.h
index 86e1dfb..220a7b5 100644
--- a/atmel_start_pins.h
+++