aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2019-12-11 16:20:14 +0100
committerKévin Redon <kredon@sysmocom.de>2019-12-11 16:35:31 +0100
commit198c3fb21b3daa0cc21165a511b9b9eb0cc7105b (patch)
treecdce60d0a29f6a037025fa1146ad780321aef4f7
parent98cf47adbae22ec138346c10e0e82c6bb23a0cd6 (diff)
improve shared bootloader/application memory
now both partitions (bootloader and application) use a commonly defined memory location to shared the DFU state (which includes the magic value to know which part to start), instead of using a hard coded value. the bootloader size has now also been restricted to 16 kB. this limitation is enforced so to not be able to create larger images, which could be corrupted when flashing the application. bootloader and application flashing have been successfully tested on qmod st12 and st34. Change-Id: I204bed7e9391602672ed894decec1fc12e879275
-rw-r--r--firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c6
-rw-r--r--firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c7
-rw-r--r--firmware/libboard/common/resources/sam3s4/dfu.ld8
-rw-r--r--firmware/libboard/common/resources/sam3s4/flash.ld4
4 files changed, 17 insertions, 8 deletions
diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c
index 3ffd9b3..e95c67b 100644
--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c
+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_driver.c
@@ -33,8 +33,7 @@
#include <usb/common/dfu/usb_dfu.h>
#include <usb/device/dfu/dfu.h>
-/* FIXME: this was used for a special ELF section which then got called
- * by DFU code and Application code, across flash partitions */
+/** specific memory location shared across bootloader and application */
#define __dfudata __attribute__ ((section (".dfudata")))
#define __dfufunc
@@ -42,11 +41,14 @@
static USBDDriver usbdDriver;
static unsigned char if_altsettings[1];
+/** structure containing the DFU state and magic value to know if DFU or application should be started */
__dfudata struct dfudata _g_dfu = {
.state = DFU_STATE_appIDLE,
.past_manifest = 0,
.total_bytes = 0,
};
+
+/** variable to structure containing DFU state */
struct dfudata *g_dfu = &_g_dfu;
WEAK void dfu_drv_updstatus(void)
diff --git a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c
index ac4d7df..4f772be 100644
--- a/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c
+++ b/firmware/atmel_softpack_libraries/usb/device/dfu/dfu_runtime.c
@@ -36,7 +36,12 @@
#include <usb/common/dfu/usb_dfu.h>
#include <usb/device/dfu/dfu.h>
-struct dfudata *g_dfu = (struct dfudata *) IRAM_ADDR;
+/** specific memory location shared across bootloader and application */
+#define __dfudata __attribute__ ((section (".dfudata")))
+/** structure containing the magic value to know if DFU or application should be started */
+__dfudata struct dfudata _g_dfu;
+/** variable to structure containing the magic value to know if DFU or application should be started */
+struct dfudata *g_dfu = &_g_dfu;
/* FIXME: this was used for a special ELF section which then got called
* by DFU code and Application code, across flash partitions */
diff --git a/firmware/libboard/common/resources/sam3s4/dfu.ld b/firmware/libboard/common/resources/sam3s4/dfu.ld
index e56a435..a485770 100644
--- a/firmware/libboard/common/resources/sam3s4/dfu.ld
+++ b/firmware/libboard/common/resources/sam3s4/dfu.ld
@@ -39,9 +39,9 @@ SEARCH_DIR(.)
MEMORY
{
/* reserve the first 16k (= 0x4000) for the DFU bootloader */
- rom (rx) : ORIGIN = 0x00404000, LENGTH = 0x0003c000 /* flash, 256K */
- /* reserve the first 32 (= 0x20) bytes for the _g_dfu struct */
- ram (rwx) : ORIGIN = 0x20000020, LENGTH = 0x0000bfe0 /* sram, 48K */
+ rom (rx) : ORIGIN = 0x00400000 + 16K, LENGTH = 256K - 16K /* flash, 256K */
+ /* note: dfudata will be at the start */
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K /* SRAM, 48K */
}
/* Section Definitions */
@@ -111,6 +111,8 @@ SECTIONS
{
. = ALIGN(4);
_srelocate = .;
+ /* we must make sure the .dfudata is linked to start of RAM */
+ *(.dfudata .dfudata.*);
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
diff --git a/firmware/libboard/common/resources/sam3s4/flash.ld b/firmware/libboard/common/resources/sam3s4/flash.ld
index bdebbde..f5cdbfd 100644
--- a/firmware/libboard/common/resources/sam3s4/flash.ld
+++ b/firmware/libboard/common/resources/sam3s4/flash.ld
@@ -38,8 +38,8 @@ SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
- rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00040000 /* flash, 256K */
- ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0000c000 /* sram, 48K */
+ rom (rx) : ORIGIN = 0x00400000, LENGTH = 16K /* flash, 256K, but only the first 16K should be used for the bootloader */
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K /* SRAM, 48K */
}
/* Section Definitions */