From 3d0c31e60ed6fe5a104bf282cbe42caca3150146 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 15 Feb 2019 14:59:24 +1100 Subject: [PATCH] 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. --- ports/stm32/mboot/fsload.c | 2 +- ports/stm32/mboot/main.c | 5 +++-- ports/stm32/mboot/mboot.h | 3 +++ ports/stm32/mboot/stm32_generic.ld | 11 +++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ports/stm32/mboot/fsload.c b/ports/stm32/mboot/fsload.c index 5e7d968425..64eb2a3a5b 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 0d39b7153b..aaad61cf54 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 f3b8f1ec8f..54b3dc7298 100644 --- a/ports/stm32/mboot/mboot.h +++ b/ports/stm32/mboot/mboot.h @@ -27,6 +27,9 @@ #include #include +// 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 4b1522e7ba..0504d6d6ae 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 : {