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 3ffd9b31..e95c67b2 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 #include -/* 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 ac4d7dff..4f772be6 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 #include -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 e56a435a..a485770f 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 bdebbdee..f5cdbfda 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 */