summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-02-15 14:59:24 +1100
committerDamien George <damien.p.george@gmail.com>2019-02-15 15:09:54 +1100
commit3d0c31e60ed6fe5a104bf282cbe42caca3150146 (patch)
tree9b62476e61183b319c2742af0937dc3de1eb66ac
parentff04b78ffda4273c9bfde67524f5233ccc9bab4d (diff)
stm32/mboot: Move some BSS vars to new section that isn't zeroed out.
Zeroing out data on startup takes time and is not necessary for certain variables. So provide a declaration for such variables and use it.
-rw-r--r--ports/stm32/mboot/fsload.c2
-rw-r--r--ports/stm32/mboot/main.c5
-rw-r--r--ports/stm32/mboot/mboot.h3
-rw-r--r--ports/stm32/mboot/stm32_generic.ld11
4 files changed, 16 insertions, 5 deletions
diff --git a/ports/stm32/mboot/fsload.c b/ports/stm32/mboot/fsload.c
index 5e7d96842..64eb2a3a5 100644
--- a/ports/stm32/mboot/fsload.c
+++ b/ports/stm32/mboot/fsload.c
@@ -42,7 +42,7 @@ typedef struct _gz_stream_t {
uint8_t dict[DICT_SIZE];
} gz_stream_t;
-static gz_stream_t gz_stream;
+static gz_stream_t gz_stream SECTION_NOZERO_BSS;
static int gz_stream_read_src(TINF_DATA *tinf) {
UINT n;
diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c
index 0d39b7153..aaad61cf5 100644
--- a/ports/stm32/mboot/main.c
+++ b/ports/stm32/mboot/main.c
@@ -754,7 +754,7 @@ typedef struct _dfu_state_t {
uint8_t buf[DFU_XFER_SIZE] __attribute__((aligned(4)));
} dfu_state_t;
-static dfu_state_t dfu_state;
+static dfu_state_t dfu_state SECTION_NOZERO_BSS;
static void dfu_init(void) {
dfu_state.status = DFU_STATUS_IDLE;
@@ -1070,7 +1070,7 @@ static const USBD_ClassTypeDef pyb_usbdd_class = {
pyb_usbdd_GetDeviceQualifierDescriptor,
};
-static pyb_usbdd_obj_t pyb_usbdd;
+static pyb_usbdd_obj_t pyb_usbdd SECTION_NOZERO_BSS;
static int pyb_usbdd_detect_port(void) {
#if MBOOT_USB_AUTODETECT_PORT
@@ -1096,6 +1096,7 @@ static int pyb_usbdd_detect_port(void) {
static void pyb_usbdd_init(pyb_usbdd_obj_t *self, int phy_id) {
self->started = false;
+ self->tx_pending = false;
USBD_HandleTypeDef *usbd = &self->hUSBDDevice;
usbd->id = phy_id;
usbd->dev_state = USBD_STATE_DEFAULT;
diff --git a/ports/stm32/mboot/mboot.h b/ports/stm32/mboot/mboot.h
index f3b8f1ec8..54b3dc729 100644
--- a/ports/stm32/mboot/mboot.h
+++ b/ports/stm32/mboot/mboot.h
@@ -27,6 +27,9 @@
#include <stdint.h>
#include <stddef.h>
+// Use this to tag global static data in RAM that doesn't need to be zeroed on startup
+#define SECTION_NOZERO_BSS __attribute__((section(".nozero_bss")))
+
#define ELEM_DATA_START (&_estack)
#define ELEM_DATA_MAX (ELEM_DATA_START + 1024)
diff --git a/ports/stm32/mboot/stm32_generic.ld b/ports/stm32/mboot/stm32_generic.ld
index 4b1522e7b..0504d6d6a 100644
--- a/ports/stm32/mboot/stm32_generic.ld
+++ b/ports/stm32/mboot/stm32_generic.ld
@@ -53,18 +53,25 @@ SECTIONS
_edata = .;
} >RAM AT> FLASH_BL
- /* Uninitialized data section */
+ /* Zeroed-out data section */
.bss :
{
. = ALIGN(4);
_sbss = .;
*(.bss*)
*(COMMON)
-
. = ALIGN(4);
_ebss = .;
} >RAM
+ /* Uninitialized data section */
+ .nozero_bss (NOLOAD) :
+ {
+ . = ALIGN(4);
+ *(.nozero_bss*)
+ . = ALIGN(4);
+ } >RAM
+
/* this just checks there is enough RAM for the stack */
.stack :
{