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
This commit is contained in:
Kevin Redon 2019-12-11 16:20:14 +01:00
parent 98cf47adba
commit 198c3fb21b
4 changed files with 17 additions and 8 deletions

View File

@ -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)

View File

@ -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 */

View File

@ -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);

View File

@ -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 */