From b21146b8e3d956d975168540d716f2f27bd05f50 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 27 Apr 2013 00:51:52 +0200 Subject: [PATCH 01/10] OP-917 bootloader updater for F4 targets. Initial commit --- Makefile | 2 +- .../targets/common/bootloader_updater/Makefile | 11 ++++++++++- .../common/bootloader_updater/inc/pios_config.h | 2 +- flight/targets/common/bootloader_updater/main.c | 16 ++++++++++------ .../common/bootloader_updater/pios_board.c | 10 +++++++++- make/boot-defs.mk | 11 +---------- make/common-defs.mk | 15 +++++++++++++++ 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 3766182a4..c212ef8f3 100644 --- a/Makefile +++ b/Makefile @@ -197,7 +197,7 @@ export OPGCSSYNTHDIR := $(BUILD_DIR)/openpilotgcs-synthetics # Define supported board lists ALL_BOARDS := coptercontrol oplinkmini revolution osd revoproto simposix -ALL_BOARDS_BU := coptercontrol oplinkmini +ALL_BOARDS_BU := coptercontrol oplinkmini revolution osd revoproto # Short names of each board (used to display board name in parallel builds) coptercontrol_short := 'cc ' diff --git a/flight/targets/common/bootloader_updater/Makefile b/flight/targets/common/bootloader_updater/Makefile index c16e9c2e5..3914a691b 100644 --- a/flight/targets/common/bootloader_updater/Makefile +++ b/flight/targets/common/bootloader_updater/Makefile @@ -39,7 +39,6 @@ HWDEFSINC = ../../boards/$(BOARD_NAME) # Use file-extension c for "c-only"-files SRC += $(OPSYSTEM)/main.c SRC += $(OPSYSTEM)/pios_board.c - ## PIOS Hardware ifeq ($(MCU),cortex-m3) include $(PIOS)/stm32f10x/library.mk @@ -47,9 +46,19 @@ ifeq ($(MCU),cortex-m3) # Set linker-script name depending on selected submodel name LDFLAGS += -T$(LINKER_SCRIPTS_PATH)/link_$(BOARD)_memory.ld LDFLAGS += -T$(LINKER_SCRIPTS_PATH)/link_$(BOARD)_sections.ld +else +ifeq ($(MCU),cortex-m4) + include $(PIOS)/stm32f4xx/library.mk + # Set linker-script name depending on selected submodel name + LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_fw_memory.ld + LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_sections.ld + SRC += $(HWDEFSINC)/firmware/cm3_fault_handlers.c + SRC += $(HWDEFSINC)/firmware/dcc_stdio.c + else $(error Unsupported MCU for BootloaderUpdater: $(MCU)) endif +endif # List any extra directories to look for include files here. # Each directory must be seperated by a space. diff --git a/flight/targets/common/bootloader_updater/inc/pios_config.h b/flight/targets/common/bootloader_updater/inc/pios_config.h index 7741291f7..f99347f25 100644 --- a/flight/targets/common/bootloader_updater/inc/pios_config.h +++ b/flight/targets/common/bootloader_updater/inc/pios_config.h @@ -34,7 +34,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_IRQ -#define PIOS_INCLUDE_GPIO +//#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_BL_HELPER diff --git a/flight/targets/common/bootloader_updater/main.c b/flight/targets/common/bootloader_updater/main.c index b48c7ffb8..6655c4904 100644 --- a/flight/targets/common/bootloader_updater/main.c +++ b/flight/targets/common/bootloader_updater/main.c @@ -35,7 +35,9 @@ extern void PIOS_Board_Init(void); extern void FLASH_Download(); void error(int, int); - +#ifdef STM32F4XX +#define FLASH_ErasePage(x) FLASH_EraseSector((x) > 0x08000000 ? FLASH_Sector_1 : FLASH_Sector_0, VoltageRange_3) +#endif /* The ADDRESSES of the _binary_* symbols are the important * data. This is non-intuitive for _binary_size where you * might expect its value to hold the size but you'd be wrong. @@ -58,7 +60,7 @@ int main() /// Self overwrite check uint32_t base_address = SCB->VTOR; - if ((0x08000000 + embedded_image_size) > base_address) + if ((BL_BANK_BASE + embedded_image_size) > base_address) error(PIOS_LED_HEARTBEAT, 1); /// @@ -71,7 +73,7 @@ int main() */ /* Calculate how far the board_info_blob is from the beginning of the bootloader */ - uint32_t board_info_blob_offset = (uint32_t) &pios_board_info_blob - (uint32_t)0x08000000; + uint32_t board_info_blob_offset = (uint32_t) &pios_board_info_blob - (uint32_t)BL_BANK_BASE; /* Use the same offset into our embedded bootloader image */ struct pios_board_info * new_board_info_blob = (struct pios_board_info *) @@ -90,9 +92,9 @@ int main() /// Bootloader memory space erase uint32_t pageAddress; - pageAddress = 0x08000000; + pageAddress = BL_BANK_BASE; bool fail = false; - while ((pageAddress < base_address) && (fail == false)) { + while ((pageAddress < BL_BANK_BASE + BL_BANK_SIZE) && (fail == false)) { for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { if (FLASH_ErasePage(pageAddress) == FLASH_COMPLETE) { fail = false; @@ -105,6 +107,8 @@ int main() pageAddress += 2048; #elif defined (STM32F10X_MD) pageAddress += 1024; +#elif defined (STM32F4XX) + pageAddress += 0x4000; #endif } @@ -157,4 +161,4 @@ void error(int led, int code) } PIOS_DELAY_WaitmS(3000); } -} \ No newline at end of file +} diff --git a/flight/targets/common/bootloader_updater/pios_board.c b/flight/targets/common/bootloader_updater/pios_board.c index be0bc7b11..184cf56c1 100644 --- a/flight/targets/common/bootloader_updater/pios_board.c +++ b/flight/targets/common/bootloader_updater/pios_board.c @@ -34,6 +34,11 @@ * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE */ #include +#ifdef STM32F4XX +#define FLASH_ErasePage(x) FLASH_EraseSector(x,VoltageRange_3) +#define FLASH_PrefetchBuffer_Enable ENABLE +#endif + void PIOS_Board_Init(void) { const struct pios_board_info * bdinfo = &pios_board_info_blob; @@ -42,7 +47,7 @@ void PIOS_Board_Init(void) { FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ - FLASH_SetLatency(FLASH_Latency_2); + //FLASH_SetLatency(FLASH_Latency_5); /* Delay system */ PIOS_DELAY_Init(); @@ -55,5 +60,8 @@ void PIOS_Board_Init(void) { #endif /* PIOS_INCLUDE_LED */ /* Initialize the PiOS library */ +#if defined(PIOS_INCLUDE_GPIO) PIOS_GPIO_Init(); +#endif /* PIOS_INCLUDE_GPIO */ + } diff --git a/make/boot-defs.mk b/make/boot-defs.mk index 3ddb445c7..6152b39f2 100644 --- a/make/boot-defs.mk +++ b/make/boot-defs.mk @@ -107,17 +107,8 @@ EXTRA_LIBDIRS += # EXTRA_LIBS = newlib-lpc EXTRA_LIBS += -# Provide (only) the bootloader with board-specific defines -BLONLY_CDEFS += -DBOARD_TYPE=$(BOARD_TYPE) -BLONLY_CDEFS += -DBOARD_REVISION=$(BOARD_REVISION) -BLONLY_CDEFS += -DHW_TYPE=$(HW_TYPE) -BLONLY_CDEFS += -DBOOTLOADER_VERSION=$(BOOTLOADER_VERSION) -BLONLY_CDEFS += -DFW_BANK_BASE=$(FW_BANK_BASE) -BLONLY_CDEFS += -DFW_BANK_SIZE=$(FW_BANK_SIZE) -BLONLY_CDEFS += -DFW_DESC_SIZE=$(FW_DESC_SIZE) - # Compiler flags -CDEFS += $(BLONLY_CDEFS) +CDEFS += # Set linker-script name depending on selected submodel name ifeq ($(MCU),cortex-m3) diff --git a/make/common-defs.mk b/make/common-defs.mk index 0e2addebf..a054eda99 100644 --- a/make/common-defs.mk +++ b/make/common-defs.mk @@ -122,6 +122,21 @@ CFLAGS += -Wall CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. CFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) +# Provides board-specific defines +BOARD_CDEFS += -DBOARD_TYPE=$(BOARD_TYPE) +BOARD_CDEFS += -DBOARD_REVISION=$(BOARD_REVISION) +BOARD_CDEFS += -DHW_TYPE=$(HW_TYPE) +BOARD_CDEFS += -DBOOTLOADER_VERSION=$(BOOTLOADER_VERSION) +BOARD_CDEFS += -DFW_BANK_BASE=$(FW_BANK_BASE) +BOARD_CDEFS += -DFW_BANK_SIZE=$(FW_BANK_SIZE) +BOARD_CDEFS += -DFW_DESC_SIZE=$(FW_DESC_SIZE) + +BOARD_CDEFS += -DBL_BANK_BASE=$(BL_BANK_BASE) +BOARD_CDEFS += -DBL_BANK_SIZE=$(BL_BANK_SIZE) +BOARD_CDEFS += -DBL_DESC_SIZE=$(BL_DESC_SIZE) + +CDEFS += $(BOARD_CDEFS) + # FIXME: stm32f4xx library raises strict aliasing and const qualifier warnings ifneq ($(MCU),cortex-m4) CFLAGS += -Werror From 78498910cf4ba71fc035f2145a2cced0b0116046 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 27 Apr 2013 15:15:28 +0200 Subject: [PATCH 02/10] OP-917 Moved all the flash architecture related code to pios_bl_helper, get the flash addresses from board defines, major cleanup. +review OPReview --- flight/pios/inc/pios_bl_helper.h | 1 + flight/pios/stm32f10x/pios_bl_helper.c | 62 +++++--- flight/pios/stm32f10x/pios_sys.c | 3 + .../STM32F4xx/Source/osd/system_stm32f4xx.c | 2 +- .../Source/revolution/system_stm32f4xx.c | 2 +- .../Source/revoproto/system_stm32f4xx.c | 2 +- flight/pios/stm32f4xx/pios_bl_helper.c | 76 ++++++--- .../bootloader_updater/inc/pios_config.h | 1 + .../targets/common/bootloader_updater/main.c | 150 ++++++++---------- .../common/bootloader_updater/pios_board.c | 10 -- 10 files changed, 166 insertions(+), 143 deletions(-) diff --git a/flight/pios/inc/pios_bl_helper.h b/flight/pios/inc/pios_bl_helper.h index 620c6c7d9..7b527d95d 100644 --- a/flight/pios/inc/pios_bl_helper.h +++ b/flight/pios/inc/pios_bl_helper.h @@ -36,6 +36,7 @@ extern uint8_t PIOS_BL_HELPER_FLASH_Ini(); extern uint32_t PIOS_BL_HELPER_CRC_Memory_Calc(); extern void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t * array, uint8_t size); extern uint8_t PIOS_BL_HELPER_FLASH_Start(); +extern uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER(); extern void PIOS_BL_HELPER_CRC_Ini(); #endif /* PIOS_BL_HELPER_H */ diff --git a/flight/pios/stm32f10x/pios_bl_helper.c b/flight/pios/stm32f10x/pios_bl_helper.c index f8c8e1db3..7fe351e17 100644 --- a/flight/pios/stm32f10x/pios_bl_helper.c +++ b/flight/pios/stm32f10x/pios_bl_helper.c @@ -35,44 +35,66 @@ #include #include "stm32f10x_flash.h" + uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) { return (uint8_t *) (SectorAddress); } #if defined(PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT) + +static bool erase_flash(uint32_t startAddress, uint32_t endAddress); + uint8_t PIOS_BL_HELPER_FLASH_Ini() { - FLASH_Unlock(); - return 1; + FLASH_Unlock(); + return 1; } uint8_t PIOS_BL_HELPER_FLASH_Start() { - const struct pios_board_info * bdinfo = &pios_board_info_blob; - uint32_t pageAdress = bdinfo->fw_base; - uint8_t fail = FALSE; - while ((pageAdress < (bdinfo->fw_base + bdinfo->fw_size + bdinfo->desc_size)) - || (fail == TRUE)) { - for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { - if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) { - fail = FALSE; - break; - } else { - fail = TRUE; - } + const struct pios_board_info * bdinfo = &pios_board_info_blob; + uint32_t startAddress = bdinfo->fw_base; + uint32_t endAddress = bdinfo->fw_base + bdinfo->fw_size + bdinfo->desc_size; - } + bool success = erase_flash(startAddress, endAddress); + + return (success) ? 1 : 0; +} + +uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { +/// Bootloader memory space erase + uint32_t startAddress = BL_BANK_BASE; + uint32_t endAddress = BL_BANK_BASE + BL_BANK_SIZE; + + bool success = erase_flash(startAddress, endAddress); + + return (success) ? 1 : 0; +} + +static bool erase_flash(uint32_t startAddress, uint32_t endAddress) { + uint32_t pageAdress = startAddress; + uint8_t fail = FALSE; + while ((pageAdress < endAddress) + || (fail == TRUE)) { + for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { + if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) { + fail = FALSE; + break; + } else { + fail = TRUE; + } + } #ifdef STM32F10X_HD - pageAdress += 2048; + pageAdress += 2048; #elif defined (STM32F10X_MD) - pageAdress += 1024; + pageAdress += 1024; #endif - } - - return (fail == TRUE) ? 0 : 1; + } + return !fail; } + #endif uint32_t PIOS_BL_HELPER_CRC_Memory_Calc() diff --git a/flight/pios/stm32f10x/pios_sys.c b/flight/pios/stm32f10x/pios_sys.c index 5a73d338b..9d52e34eb 100644 --- a/flight/pios/stm32f10x/pios_sys.c +++ b/flight/pios/stm32f10x/pios_sys.c @@ -50,6 +50,9 @@ void PIOS_SYS_Init(void) /* Setup STM32 system (RCC, clock, PLL and Flash configuration) - CMSIS Function */ SystemInit(); + /* Init the delay system */ + PIOS_DELAY_Init(); + /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); diff --git a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/osd/system_stm32f4xx.c b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/osd/system_stm32f4xx.c index 65c30e1aa..9cb23aa19 100644 --- a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/osd/system_stm32f4xx.c +++ b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/osd/system_stm32f4xx.c @@ -392,7 +392,7 @@ static void SetSysClock(void) } /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ - FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_3WS; + FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_3WS; /* Select the main PLL as system clock source */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); diff --git a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revolution/system_stm32f4xx.c b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revolution/system_stm32f4xx.c index bb7776d4b..65da26470 100644 --- a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revolution/system_stm32f4xx.c +++ b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revolution/system_stm32f4xx.c @@ -393,7 +393,7 @@ static void SetSysClock(void) } /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ - FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; + FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_LATENCY_5WS; /* Select the main PLL as system clock source */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); diff --git a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c index bb7776d4b..f98b4a14b 100644 --- a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c +++ b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c @@ -393,7 +393,7 @@ static void SetSysClock(void) } /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ - FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; + FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; /* Select the main PLL as system clock source */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); diff --git a/flight/pios/stm32f4xx/pios_bl_helper.c b/flight/pios/stm32f4xx/pios_bl_helper.c index afa59b3e5..3458120c6 100644 --- a/flight/pios/stm32f4xx/pios_bl_helper.c +++ b/flight/pios/stm32f4xx/pios_bl_helper.c @@ -36,12 +36,16 @@ #include "stm32f4xx_flash.h" #include + uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) { return (uint8_t *) (SectorAddress); } #if defined(PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT) + +static bool erase_flash(uint32_t startAddress, uint32_t endAddress); + uint8_t PIOS_BL_HELPER_FLASH_Ini() { FLASH_Unlock(); @@ -138,35 +142,55 @@ static bool PIOS_BL_HELPER_FLASH_GetSectorInfo(uint32_t address, uint8_t * secto uint8_t PIOS_BL_HELPER_FLASH_Start() { const struct pios_board_info * bdinfo = &pios_board_info_blob; - uint32_t pageAddress = bdinfo->fw_base; - bool fail = false; - while ((pageAddress < (bdinfo->fw_base + bdinfo->fw_size + bdinfo->desc_size)) - && (fail == false)) { - uint8_t sector_number; - uint32_t sector_start; - uint32_t sector_size; - if (!PIOS_BL_HELPER_FLASH_GetSectorInfo(pageAddress, - §or_number, - §or_start, - §or_size)) { - /* We're asking for an invalid flash address */ - PIOS_Assert(0); - } - for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { - if (FLASH_EraseSector(sector_number, VoltageRange_3) == FLASH_COMPLETE) { - fail = false; - break; - } else { - fail = true; - } + uint32_t startAddress = bdinfo->fw_base; + uint32_t endAddress = bdinfo->fw_base + bdinfo->fw_size + bdinfo->desc_size; - } - /* Move to the next sector */ - pageAddress += sector_size; - } + bool success = erase_flash(startAddress, endAddress); - return (fail == true) ? 0 : 1; + return (success) ? 1 : 0; } + + +uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { +/// Bootloader memory space erase + uint32_t startAddress = BL_BANK_BASE; + uint32_t endAddress = BL_BANK_BASE + BL_BANK_SIZE; + + bool success = erase_flash(startAddress, endAddress); + + return (success) ? 1 : 0; +} + +static bool erase_flash(uint32_t startAddress, uint32_t endAddress) +{ + uint32_t pageAddress = startAddress; + bool fail = false; + while ((pageAddress < endAddress) + && (fail == false)) { + uint8_t sector_number; + uint32_t sector_start; + uint32_t sector_size; + if (!PIOS_BL_HELPER_FLASH_GetSectorInfo(pageAddress, + §or_number, + §or_start, + §or_size)) { + /* We're asking for an invalid flash address */ + PIOS_Assert(0); + } + for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { + if (FLASH_EraseSector(sector_number, VoltageRange_3) == FLASH_COMPLETE) { + fail = false; + break; + } else { + fail = true; + } + } + /* Move to the next sector */ + pageAddress += sector_size; + } + return !fail; +} + #endif uint32_t PIOS_BL_HELPER_CRC_Memory_Calc() diff --git a/flight/targets/common/bootloader_updater/inc/pios_config.h b/flight/targets/common/bootloader_updater/inc/pios_config.h index f99347f25..ce6c6fc2b 100644 --- a/flight/targets/common/bootloader_updater/inc/pios_config.h +++ b/flight/targets/common/bootloader_updater/inc/pios_config.h @@ -37,6 +37,7 @@ //#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_BL_HELPER +#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT #endif /* PIOS_CONFIG_H */ diff --git a/flight/targets/common/bootloader_updater/main.c b/flight/targets/common/bootloader_updater/main.c index 6655c4904..387d3a16c 100644 --- a/flight/targets/common/bootloader_updater/main.c +++ b/flight/targets/common/bootloader_updater/main.c @@ -29,12 +29,14 @@ #include #include #include +#include #define MAX_WRI_RETRYS 3 /* Prototype of PIOS_Board_Init() function */ extern void PIOS_Board_Init(void); extern void FLASH_Download(); void error(int, int); + #ifdef STM32F4XX #define FLASH_ErasePage(x) FLASH_EraseSector((x) > 0x08000000 ? FLASH_Sector_1 : FLASH_Sector_0, VoltageRange_3) #endif @@ -45,107 +47,87 @@ void error(int, int); extern uint32_t _binary_start; extern uint32_t _binary_end; extern uint32_t _binary_size; -const uint32_t * embedded_image_start = (uint32_t *) &(_binary_start); -const uint32_t * embedded_image_end = (uint32_t *) &(_binary_end); +const uint32_t *embedded_image_start = (uint32_t *) &(_binary_start); +const uint32_t *embedded_image_end = (uint32_t *) &(_binary_end); const uint32_t embedded_image_size = (uint32_t) &(_binary_size); int main() { - PIOS_SYS_Init(); - PIOS_Board_Init(); - PIOS_LED_On(PIOS_LED_HEARTBEAT); - PIOS_DELAY_WaitmS(3000); - PIOS_LED_Off(PIOS_LED_HEARTBEAT); + PIOS_SYS_Init(); + PIOS_Board_Init(); + PIOS_LED_On(PIOS_LED_HEARTBEAT); + PIOS_DELAY_WaitmS(3000); + PIOS_LED_Off(PIOS_LED_HEARTBEAT); - /// Self overwrite check - uint32_t base_address = SCB->VTOR; - if ((BL_BANK_BASE + embedded_image_size) > base_address) - error(PIOS_LED_HEARTBEAT, 1); - /// + /// Self overwrite check + uint32_t base_address = SCB ->VTOR; + if ((BL_BANK_BASE + embedded_image_size) > base_address) + error(PIOS_LED_HEARTBEAT, 1); + /// - /* - * Make sure the bootloader we're carrying is for the same - * board type and board revision as the one we're running on. - * - * Assume the bootloader in flash and the bootloader contained in - * the updater both carry a board_info_blob at the end of the image. - */ + /* + * Make sure the bootloader we're carrying is for the same + * board type and board revision as the one we're running on. + * + * Assume the bootloader in flash and the bootloader contained in + * the updater both carry a board_info_blob at the end of the image. + */ - /* Calculate how far the board_info_blob is from the beginning of the bootloader */ - uint32_t board_info_blob_offset = (uint32_t) &pios_board_info_blob - (uint32_t)BL_BANK_BASE; + /* Calculate how far the board_info_blob is from the beginning of the bootloader */ + uint32_t board_info_blob_offset = (uint32_t) &pios_board_info_blob - (uint32_t) BL_BANK_BASE; - /* Use the same offset into our embedded bootloader image */ - struct pios_board_info * new_board_info_blob = (struct pios_board_info *) - ((uint32_t)embedded_image_start + board_info_blob_offset); + /* Use the same offset into our embedded bootloader image */ + struct pios_board_info *new_board_info_blob = (struct pios_board_info *) ((uint32_t) embedded_image_start + board_info_blob_offset); - /* Compare the two board info blobs to make sure they're for the same HW revision */ - if ((pios_board_info_blob.magic != new_board_info_blob->magic) || - (pios_board_info_blob.board_type != new_board_info_blob->board_type) || - (pios_board_info_blob.board_rev != new_board_info_blob->board_rev)) { - error(PIOS_LED_HEARTBEAT, 2); - } + /* Compare the two board info blobs to make sure they're for the same HW revision */ + if ((pios_board_info_blob.magic != new_board_info_blob->magic) || + (pios_board_info_blob.board_type != new_board_info_blob->board_type) || + (pios_board_info_blob.board_rev != new_board_info_blob->board_rev)) { + error(PIOS_LED_HEARTBEAT, 2); + } - /* Embedded bootloader looks like it's the right one for this HW, proceed... */ + /* Embedded bootloader looks like it's the right one for this HW, proceed... */ - FLASH_Unlock(); + FLASH_Unlock(); - /// Bootloader memory space erase - uint32_t pageAddress; - pageAddress = BL_BANK_BASE; - bool fail = false; - while ((pageAddress < BL_BANK_BASE + BL_BANK_SIZE) && (fail == false)) { - for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { - if (FLASH_ErasePage(pageAddress) == FLASH_COMPLETE) { - fail = false; - break; - } else { - fail = true; - } - } -#ifdef STM32F10X_HD - pageAddress += 2048; -#elif defined (STM32F10X_MD) - pageAddress += 1024; -#elif defined (STM32F4XX) - pageAddress += 0x4000; -#endif - } + bool fail; - if (fail == true) - error(PIOS_LED_HEARTBEAT, 3); + fail = (PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() != 1); + if (fail == true){ + error(PIOS_LED_HEARTBEAT, 3); + } + /// + /// Bootloader programing + for (uint32_t offset = 0; offset < embedded_image_size / sizeof(uint32_t); ++offset) { + bool result = false; + PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); + for (uint8_t retry = 0; retry < MAX_WRI_RETRYS; ++retry) { + if (result == false) { + result = (FLASH_ProgramWord(0x08000000 + (offset * 4), embedded_image_start[offset]) == FLASH_COMPLETE); + } + } + if (result == false) { + error(PIOS_LED_HEARTBEAT, 4); + } + } + /// + for (uint8_t x = 0; x < 3; ++x) { + PIOS_LED_On(PIOS_LED_HEARTBEAT); + PIOS_DELAY_WaitmS(1000); + PIOS_LED_Off(PIOS_LED_HEARTBEAT); + PIOS_DELAY_WaitmS(1000); + } - /// - /// Bootloader programing - for (uint32_t offset = 0; offset < embedded_image_size / sizeof(uint32_t); ++offset) { - bool result = false; - PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); - for (uint8_t retry = 0; retry < MAX_WRI_RETRYS; ++retry) { - if (result == false) { - result = (FLASH_ProgramWord(0x08000000 + (offset * 4), embedded_image_start[offset]) - == FLASH_COMPLETE) ? true : false; - } - } - if (result == false) - error(PIOS_LED_HEARTBEAT, 4); - } - /// - for (uint8_t x = 0; x < 3; ++x) { - PIOS_LED_On(PIOS_LED_HEARTBEAT); - PIOS_DELAY_WaitmS(1000); - PIOS_LED_Off(PIOS_LED_HEARTBEAT); - PIOS_DELAY_WaitmS(1000); - } + /// Invalidate the bootloader updater so we won't run + /// the update again on the next power cycle. + FLASH_ProgramWord(base_address, 0); + FLASH_Lock(); - /// Invalidate the bootloader updater so we won't run - /// the update again on the next power cycle. - FLASH_ProgramWord(base_address, 0); - FLASH_Lock(); - - for (;;) { - PIOS_DELAY_WaitmS(1000); - } + for (;;) { + PIOS_DELAY_WaitmS(1000); + } } diff --git a/flight/targets/common/bootloader_updater/pios_board.c b/flight/targets/common/bootloader_updater/pios_board.c index 184cf56c1..fe68d66aa 100644 --- a/flight/targets/common/bootloader_updater/pios_board.c +++ b/flight/targets/common/bootloader_updater/pios_board.c @@ -36,22 +36,12 @@ #include #ifdef STM32F4XX #define FLASH_ErasePage(x) FLASH_EraseSector(x,VoltageRange_3) -#define FLASH_PrefetchBuffer_Enable ENABLE #endif void PIOS_Board_Init(void) { const struct pios_board_info * bdinfo = &pios_board_info_blob; - /* Enable Prefetch Buffer */ - FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); - - /* Flash 2 wait state */ - //FLASH_SetLatency(FLASH_Latency_5); - - /* Delay system */ - PIOS_DELAY_Init(); - /* LEDs */ #if defined(PIOS_INCLUDE_LED) const struct pios_led_cfg * led_cfg = PIOS_BOARD_HW_DEFS_GetLedCfg(bdinfo->board_rev); From 9f56fe9a1e96a08c17d9e7bc9ae966af20e73342 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 28 Apr 2013 10:14:50 +0200 Subject: [PATCH 03/10] OP-917 Makefiles cleanup. Get rid of ALL_BOARDS_BU as not all boards have one +review OPReview-456 --- Makefile | 4 +--- flight/targets/common/bootloader_updater/Makefile | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c212ef8f3..b7d31c35b 100644 --- a/Makefile +++ b/Makefile @@ -197,7 +197,6 @@ export OPGCSSYNTHDIR := $(BUILD_DIR)/openpilotgcs-synthetics # Define supported board lists ALL_BOARDS := coptercontrol oplinkmini revolution osd revoproto simposix -ALL_BOARDS_BU := coptercontrol oplinkmini revolution osd revoproto # Short names of each board (used to display board name in parallel builds) coptercontrol_short := 'cc ' @@ -211,13 +210,12 @@ simposix_short := 'posx' # all other platforms. ifneq ($(UNAME), Linux) ALL_BOARDS := $(filter-out simposix, $(ALL_BOARDS)) - ALL_BOARDS_BU := $(filter-out simposix, $(ALL_BOARDS_BU)) endif # Start out assuming that we'll build fw, bl and bu for all boards FW_BOARDS := $(ALL_BOARDS) BL_BOARDS := $(ALL_BOARDS) -BU_BOARDS := $(ALL_BOARDS_BU) +BU_BOARDS := $(ALL_BOARDS) EF_BOARDS := $(ALL_BOARDS) # SimPosix doesn't have a BL, BU or EF target so we need to diff --git a/flight/targets/common/bootloader_updater/Makefile b/flight/targets/common/bootloader_updater/Makefile index 3914a691b..cd420779c 100644 --- a/flight/targets/common/bootloader_updater/Makefile +++ b/flight/targets/common/bootloader_updater/Makefile @@ -46,8 +46,7 @@ ifeq ($(MCU),cortex-m3) # Set linker-script name depending on selected submodel name LDFLAGS += -T$(LINKER_SCRIPTS_PATH)/link_$(BOARD)_memory.ld LDFLAGS += -T$(LINKER_SCRIPTS_PATH)/link_$(BOARD)_sections.ld -else -ifeq ($(MCU),cortex-m4) +else ifeq ($(MCU),cortex-m4) include $(PIOS)/stm32f4xx/library.mk # Set linker-script name depending on selected submodel name LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_fw_memory.ld @@ -58,7 +57,6 @@ ifeq ($(MCU),cortex-m4) else $(error Unsupported MCU for BootloaderUpdater: $(MCU)) endif -endif # List any extra directories to look for include files here. # Each directory must be seperated by a space. From 41ecc09c3fe8882c2d28f7e8f1180c732781e417 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 28 Apr 2013 10:19:08 +0200 Subject: [PATCH 04/10] OP-917 Various review fixes: -Fixed casing for PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER -fixed wrong condition in f1 bl_helper -other cosmetic changes and use of stdbool in f1 pios_bl_helper -remove now unused macros +review OPReview-456 --- flight/pios/inc/pios_bl_helper.h | 2 +- flight/pios/stm32f10x/pios_bl_helper.c | 25 +++++++++---------- flight/pios/stm32f4xx/pios_bl_helper.c | 10 +++----- .../bootloader_updater/inc/pios_config.h | 1 - .../targets/common/bootloader_updater/main.c | 7 ++---- .../common/bootloader_updater/pios_board.c | 4 --- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/flight/pios/inc/pios_bl_helper.h b/flight/pios/inc/pios_bl_helper.h index 7b527d95d..3a0c6bdb0 100644 --- a/flight/pios/inc/pios_bl_helper.h +++ b/flight/pios/inc/pios_bl_helper.h @@ -36,7 +36,7 @@ extern uint8_t PIOS_BL_HELPER_FLASH_Ini(); extern uint32_t PIOS_BL_HELPER_CRC_Memory_Calc(); extern void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t * array, uint8_t size); extern uint8_t PIOS_BL_HELPER_FLASH_Start(); -extern uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER(); +extern uint8_t PIOS_BL_HELPER_FLASH_Erase_Bootloader(); extern void PIOS_BL_HELPER_CRC_Ini(); #endif /* PIOS_BL_HELPER_H */ diff --git a/flight/pios/stm32f10x/pios_bl_helper.c b/flight/pios/stm32f10x/pios_bl_helper.c index 7fe351e17..0c2d7b7d9 100644 --- a/flight/pios/stm32f10x/pios_bl_helper.c +++ b/flight/pios/stm32f10x/pios_bl_helper.c @@ -28,13 +28,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "pios.h" +#include #ifdef PIOS_INCLUDE_BL_HELPER #include -#include "stm32f10x_flash.h" - +#include +#include uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) { @@ -62,7 +62,7 @@ uint8_t PIOS_BL_HELPER_FLASH_Start() return (success) ? 1 : 0; } -uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { +uint8_t PIOS_BL_HELPER_FLASH_Erase_Bootloader() { /// Bootloader memory space erase uint32_t startAddress = BL_BANK_BASE; uint32_t endAddress = BL_BANK_BASE + BL_BANK_SIZE; @@ -73,23 +73,22 @@ uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { } static bool erase_flash(uint32_t startAddress, uint32_t endAddress) { - uint32_t pageAdress = startAddress; - uint8_t fail = FALSE; - while ((pageAdress < endAddress) - || (fail == TRUE)) { + uint32_t pageAddress = startAddress; + uint8_t fail = false; + while ((pageAddress < endAddress) && (fail == false)) { for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { - if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) { - fail = FALSE; + if (FLASH_ErasePage(pageAddress) == FLASH_COMPLETE) { + fail = false; break; } else { - fail = TRUE; + fail = true; } } #ifdef STM32F10X_HD - pageAdress += 2048; + pageAddress += 2048; #elif defined (STM32F10X_MD) - pageAdress += 1024; + pageAddress += 1024; #endif } return !fail; diff --git a/flight/pios/stm32f4xx/pios_bl_helper.c b/flight/pios/stm32f4xx/pios_bl_helper.c index 3458120c6..562587819 100644 --- a/flight/pios/stm32f4xx/pios_bl_helper.c +++ b/flight/pios/stm32f4xx/pios_bl_helper.c @@ -28,15 +28,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "pios.h" +#include #ifdef PIOS_INCLUDE_BL_HELPER #include -#include "stm32f4xx_flash.h" +#include #include - uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) { return (uint8_t *) (SectorAddress); @@ -151,7 +150,7 @@ uint8_t PIOS_BL_HELPER_FLASH_Start() } -uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { +uint8_t PIOS_BL_HELPER_FLASH_Erase_Bootloader() { /// Bootloader memory space erase uint32_t startAddress = BL_BANK_BASE; uint32_t endAddress = BL_BANK_BASE + BL_BANK_SIZE; @@ -165,8 +164,7 @@ static bool erase_flash(uint32_t startAddress, uint32_t endAddress) { uint32_t pageAddress = startAddress; bool fail = false; - while ((pageAddress < endAddress) - && (fail == false)) { + while ((pageAddress < endAddress) && (fail == false)) { uint8_t sector_number; uint32_t sector_start; uint32_t sector_size; diff --git a/flight/targets/common/bootloader_updater/inc/pios_config.h b/flight/targets/common/bootloader_updater/inc/pios_config.h index ce6c6fc2b..9fbd71501 100644 --- a/flight/targets/common/bootloader_updater/inc/pios_config.h +++ b/flight/targets/common/bootloader_updater/inc/pios_config.h @@ -34,7 +34,6 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_IRQ -//#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_BL_HELPER #define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT diff --git a/flight/targets/common/bootloader_updater/main.c b/flight/targets/common/bootloader_updater/main.c index 387d3a16c..4a55a7aed 100644 --- a/flight/targets/common/bootloader_updater/main.c +++ b/flight/targets/common/bootloader_updater/main.c @@ -37,9 +37,6 @@ extern void PIOS_Board_Init(void); extern void FLASH_Download(); void error(int, int); -#ifdef STM32F4XX -#define FLASH_ErasePage(x) FLASH_EraseSector((x) > 0x08000000 ? FLASH_Sector_1 : FLASH_Sector_0, VoltageRange_3) -#endif /* The ADDRESSES of the _binary_* symbols are the important * data. This is non-intuitive for _binary_size where you * might expect its value to hold the size but you'd be wrong. @@ -93,7 +90,7 @@ int main() bool fail; - fail = (PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() != 1); + fail = (PIOS_BL_HELPER_FLASH_Erase_Bootloader() != 1); if (fail == true){ error(PIOS_LED_HEARTBEAT, 3); @@ -105,7 +102,7 @@ int main() PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); for (uint8_t retry = 0; retry < MAX_WRI_RETRYS; ++retry) { if (result == false) { - result = (FLASH_ProgramWord(0x08000000 + (offset * 4), embedded_image_start[offset]) == FLASH_COMPLETE); + result = (FLASH_ProgramWord(BL_BANK_BASE + (offset * 4), embedded_image_start[offset]) == FLASH_COMPLETE); } } if (result == false) { diff --git a/flight/targets/common/bootloader_updater/pios_board.c b/flight/targets/common/bootloader_updater/pios_board.c index fe68d66aa..accc300f9 100644 --- a/flight/targets/common/bootloader_updater/pios_board.c +++ b/flight/targets/common/bootloader_updater/pios_board.c @@ -34,10 +34,6 @@ * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE */ #include -#ifdef STM32F4XX -#define FLASH_ErasePage(x) FLASH_EraseSector(x,VoltageRange_3) -#endif - void PIOS_Board_Init(void) { const struct pios_board_info * bdinfo = &pios_board_info_blob; From 19e374e8d175038818031e4cabe900307d0aae1f Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sun, 28 Apr 2013 15:35:28 +0300 Subject: [PATCH 05/10] OP-917: Minor fix for indents and spacing --- Makefile | 2 +- flight/targets/common/bootloader_updater/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b7d31c35b..c502b84b4 100644 --- a/Makefile +++ b/Makefile @@ -209,7 +209,7 @@ simposix_short := 'posx' # SimPosix only builds on Linux so drop it from the list for # all other platforms. ifneq ($(UNAME), Linux) - ALL_BOARDS := $(filter-out simposix, $(ALL_BOARDS)) + ALL_BOARDS := $(filter-out simposix, $(ALL_BOARDS)) endif # Start out assuming that we'll build fw, bl and bu for all boards diff --git a/flight/targets/common/bootloader_updater/Makefile b/flight/targets/common/bootloader_updater/Makefile index cd420779c..66b6530ed 100644 --- a/flight/targets/common/bootloader_updater/Makefile +++ b/flight/targets/common/bootloader_updater/Makefile @@ -47,13 +47,13 @@ ifeq ($(MCU),cortex-m3) LDFLAGS += -T$(LINKER_SCRIPTS_PATH)/link_$(BOARD)_memory.ld LDFLAGS += -T$(LINKER_SCRIPTS_PATH)/link_$(BOARD)_sections.ld else ifeq ($(MCU),cortex-m4) - include $(PIOS)/stm32f4xx/library.mk + include $(PIOS)/stm32f4xx/library.mk + # Set linker-script name depending on selected submodel name LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_fw_memory.ld LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_sections.ld SRC += $(HWDEFSINC)/firmware/cm3_fault_handlers.c SRC += $(HWDEFSINC)/firmware/dcc_stdio.c - else $(error Unsupported MCU for BootloaderUpdater: $(MCU)) endif From 1eef6a7f066198cdc7c3dcf84b930ff6d599bed8 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Tue, 30 Apr 2013 18:26:25 +0200 Subject: [PATCH 06/10] OP-917 Extended the program flash size to 3 128k sectors for F4 targets +review OPReview-456 --- flight/targets/boards/osd/board-info.mk | 4 ++-- flight/targets/boards/revolution/board-info.mk | 4 ++-- flight/targets/boards/revoproto/board-info.mk | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flight/targets/boards/osd/board-info.mk b/flight/targets/boards/osd/board-info.mk index 3e707366c..b1b35c8fc 100644 --- a/flight/targets/boards/osd/board-info.mk +++ b/flight/targets/boards/osd/board-info.mk @@ -1,6 +1,6 @@ BOARD_TYPE := 0x05 BOARD_REVISION := 0x01 -BOOTLOADER_VERSION := 0x04 +BOOTLOADER_VERSION := 0x05 HW_TYPE := 0x00 MCU := cortex-m4 @@ -20,7 +20,7 @@ BL_BANK_SIZE := 0x00008000 # Should include BD_INFO region # Leave the remaining 16KB and 64KB sectors for other uses FW_BANK_BASE := 0x08020000 # Start of firmware flash -FW_BANK_SIZE := 0x00040000 # Should include FW_DESC_SIZE +FW_BANK_SIZE := 0x00060000 # Should include FW_DESC_SIZE FW_DESC_SIZE := 0x00000064 diff --git a/flight/targets/boards/revolution/board-info.mk b/flight/targets/boards/revolution/board-info.mk index feee44d4e..e36dab087 100644 --- a/flight/targets/boards/revolution/board-info.mk +++ b/flight/targets/boards/revolution/board-info.mk @@ -1,6 +1,6 @@ BOARD_TYPE := 0x09 BOARD_REVISION := 0x03 -BOOTLOADER_VERSION := 0x04 +BOOTLOADER_VERSION := 0x05 HW_TYPE := 0x00 MCU := cortex-m4 @@ -19,7 +19,7 @@ BL_BANK_SIZE := 0x00008000 # Should include BD_INFO region # Leave the remaining 16KB and 64KB sectors for other uses FW_BANK_BASE := 0x08020000 # Start of firmware flash -FW_BANK_SIZE := 0x00040000 # Should include FW_DESC_SIZE +FW_BANK_SIZE := 0x00060000 # Should include FW_DESC_SIZE FW_DESC_SIZE := 0x00000064 diff --git a/flight/targets/boards/revoproto/board-info.mk b/flight/targets/boards/revoproto/board-info.mk index 1e247d4d5..e95ecd360 100644 --- a/flight/targets/boards/revoproto/board-info.mk +++ b/flight/targets/boards/revoproto/board-info.mk @@ -1,6 +1,6 @@ BOARD_TYPE := 0x09 BOARD_REVISION := 0x02 -BOOTLOADER_VERSION := 0x04 +BOOTLOADER_VERSION := 0x05 HW_TYPE := 0x00 MCU := cortex-m4 @@ -19,7 +19,7 @@ BL_BANK_SIZE := 0x00008000 # Should include BD_INFO region # Leave the remaining 16KB and 64KB sectors for other uses FW_BANK_BASE := 0x08020000 # Start of firmware flash -FW_BANK_SIZE := 0x00040000 # Should include FW_DESC_SIZE +FW_BANK_SIZE := 0x00060000 # Should include FW_DESC_SIZE FW_DESC_SIZE := 0x00000064 From e1fdc41d7f0eaffde257327a0b41761561699aeb Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Wed, 1 May 2013 01:03:27 +0200 Subject: [PATCH 07/10] OP-917 add Bootloader support for IRQStack to reside in CCSRAM +review OPReview-456 --- flight/targets/boards/osd/bootloader/main.c | 6 +++++- flight/targets/boards/revolution/bootloader/main.c | 6 +++++- flight/targets/boards/revoproto/bootloader/main.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/flight/targets/boards/osd/bootloader/main.c b/flight/targets/boards/osd/bootloader/main.c index b6b8fe83f..82878dfbd 100644 --- a/flight/targets/boards/osd/bootloader/main.c +++ b/flight/targets/boards/osd/bootloader/main.c @@ -170,7 +170,11 @@ void jump_to_app() { const struct pios_board_info * bdinfo = &pios_board_info_blob; PIOS_LED_On(PIOS_LED_HEARTBEAT); - if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + // Look at cm3_vectors struct in startup. In a fw image the first uint32_t contains the address of the top of irqstack + uint32_t fwIrqStackBase = (*(__IO uint32_t*) bdinfo->fw_base) & 0xFFFE0000; + // Check for the two possible irqstack locations (sram or core coupled sram) + if ( fwIrqStackBase == 0x20000000 || fwIrqStackBase == 0x10000000) { + /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); diff --git a/flight/targets/boards/revolution/bootloader/main.c b/flight/targets/boards/revolution/bootloader/main.c index 5689ede26..db02ff0ad 100644 --- a/flight/targets/boards/revolution/bootloader/main.c +++ b/flight/targets/boards/revolution/bootloader/main.c @@ -174,7 +174,11 @@ void jump_to_app() { const struct pios_board_info * bdinfo = &pios_board_info_blob; PIOS_LED_On(PIOS_LED_HEARTBEAT); - if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + // Look at cm3_vectors struct in startup. In a fw image the first uint32_t contains the address of the top of irqstack + uint32_t fwIrqStackBase = (*(__IO uint32_t*) bdinfo->fw_base) & 0xFFFE0000; + // Check for the two possible irqstack locations (sram or core coupled sram) + if ( fwIrqStackBase == 0x20000000 || fwIrqStackBase == 0x10000000) { + /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); diff --git a/flight/targets/boards/revoproto/bootloader/main.c b/flight/targets/boards/revoproto/bootloader/main.c index 5689ede26..1f364abba 100644 --- a/flight/targets/boards/revoproto/bootloader/main.c +++ b/flight/targets/boards/revoproto/bootloader/main.c @@ -174,7 +174,11 @@ void jump_to_app() { const struct pios_board_info * bdinfo = &pios_board_info_blob; PIOS_LED_On(PIOS_LED_HEARTBEAT); - if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + // Look at cm3_vectors struct in startup. In a fw image the first uint32_t contains the address of the top of irqstack + uint32_t fwIrqStackBase = (*(__IO uint32_t*) bdinfo->fw_base) & 0xFFFE0000; + // Check for the two possible irqstack locations (sram or core coupled sram) + if ( fwIrqStackBase == 0x20000000 || fwIrqStackBase == 0x10000000) { + /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); From d79887d22382396d22a9ce7397146cdd293db896 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Wed, 1 May 2013 01:11:17 +0200 Subject: [PATCH 08/10] OP-917 relocate IRQStack to CCSRAM +review OPReview-456 --- flight/pios/stm32f4xx/link_stm32f4xx_sections.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/pios/stm32f4xx/link_stm32f4xx_sections.ld b/flight/pios/stm32f4xx/link_stm32f4xx_sections.ld index c6701fb19..7171f6be6 100644 --- a/flight/pios/stm32f4xx/link_stm32f4xx_sections.ld +++ b/flight/pios/stm32f4xx/link_stm32f4xx_sections.ld @@ -83,7 +83,7 @@ SECTIONS _irq_stack_end = . ; *(.irqstack) _irq_stack_top = . ; - } > SRAM + } > CCSRAM /* From 37a0d2c99e7bbadcbe75e8c03d4b417b0b9c09b2 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Wed, 1 May 2013 01:14:30 +0200 Subject: [PATCH 09/10] OP-917 included a "compatibility" linker script used by the bootloader updater to ensure its compatibility with previous bootloader versions +review OPReview-456 --- flight/pios/stm32f4xx/library.mk | 3 + .../link_stm32f4xx_sections_compat.ld | 176 ++++++++++++++++++ .../common/bootloader_updater/Makefile | 4 +- 3 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 flight/pios/stm32f4xx/link_stm32f4xx_sections_compat.ld diff --git a/flight/pios/stm32f4xx/library.mk b/flight/pios/stm32f4xx/library.mk index 231ee1561..24f6d7947 100644 --- a/flight/pios/stm32f4xx/library.mk +++ b/flight/pios/stm32f4xx/library.mk @@ -10,6 +10,9 @@ LINKER_SCRIPTS_APP = $(PIOS_DEVLIB)link_stm32f4xx_fw_memory.ld \ $(PIOS_DEVLIB)link_stm32f4xx_sections.ld LINKER_SCRIPTS_BL = $(PIOS_DEVLIB)link_stm32f4xx_bl_memory.ld \ $(PIOS_DEVLIB)link_stm32f4xx_sections.ld +# _compat linker script are aimed at bootloader updater to guarantee to be compatible with earlier bootloaders. +LINKER_SCRIPTS_COMPAT = $(PIOS_DEVLIB)link_stm32f4xx_fw_memory.ld \ + $(PIOS_DEVLIB)link_stm32f4xx_sections_compat.ld # Compiler options implied by the F4xx CDEFS += -DSTM32F4XX diff --git a/flight/pios/stm32f4xx/link_stm32f4xx_sections_compat.ld b/flight/pios/stm32f4xx/link_stm32f4xx_sections_compat.ld new file mode 100644 index 000000000..c6701fb19 --- /dev/null +++ b/flight/pios/stm32f4xx/link_stm32f4xx_sections_compat.ld @@ -0,0 +1,176 @@ + +/* Section Definitions */ +SECTIONS +{ + /* + * Vectors, code and constant data. + */ + .text : + { + PROVIDE (pios_isr_vector_table_base = .); + KEEP(*(.cpu_vectors)) /* CPU exception vectors */ + KEEP(*(.io_vectors)) /* I/O interrupt vectors */ + *(.text .text.* .gnu.linkonce.t.*) + *(.glue_7t) *(.glue_7) + *(.rodata .rodata* .gnu.linkonce.r.*) + } > FLASH + + /* + * Init section for UAVObjects. + */ + .initcalluavobj.init : + { + . = ALIGN(4); + __uavobj_initcall_start = .; + KEEP(*(.initcalluavobj.init)) + . = ALIGN(4); + __uavobj_initcall_end = .; + } >FLASH + + /* + * Module init section section + */ + .initcallmodule.init : + { + . = ALIGN(4); + __module_initcall_start = .; + KEEP(*(.initcallmodule.init)) + . = ALIGN(4); + __module_initcall_end = .; + } >FLASH + + /* + * C++ exception handling. + */ + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + .ARM.exidx : + { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > FLASH + + /* + * Markers for the end of the 'text' section and the in-flash start of + * non-constant data + */ + . = ALIGN(4); + _etext = .; + _sidata = .; + + /* + * Board info structure, normally only generated by the bootloader but can + * be read by the application. + */ + PROVIDE(pios_board_info_blob = ORIGIN(BD_INFO)); + .boardinfo : + { + . = ALIGN(4); + KEEP(*(.boardinfo)) + . = ALIGN(ORIGIN(BD_INFO)+LENGTH(BD_INFO)); + } > BD_INFO + + /* + * Place the IRQ/bootstrap stack at the bottom of SRAM so that an overflow + * results in a hard fault. + */ + .istack (NOLOAD) : + { + . = ALIGN(4); + _irq_stack_end = . ; + *(.irqstack) + _irq_stack_top = . ; + } > SRAM + + + /* + * Non-const initialised data. + */ + .data : AT (_sidata) + { + . = ALIGN(4); + _sdata = .; + *(.data .data.*) + . = ALIGN(4); + _edata = . ; + } > SRAM + + /* + * Uninitialised data (BSS + commons). + */ + .bss (NOLOAD) : + { + _sbss = . ; + *(.bss .bss.*) + *(COMMON) + _ebss = . ; + PROVIDE ( _end = _ebss ) ; + } > SRAM + + /* + * The heap consumes the remainder of the SRAM. + */ + .heap (NOLOAD) : + { + . = ALIGN(4); + _sheap = . ; + + /* + * This allows us to declare an object or objects up to the minimum acceptable + * heap size and receive a linker error if the space available for the heap is + * not sufficient. + */ + *(.heap) + + /* extend the heap up to the top of SRAM */ + . = ORIGIN(SRAM) + LENGTH(SRAM) - ABSOLUTE(_sheap); + _eheap = .; + } > SRAM + + /* + * 'Fast' memory goes in the CCM SRAM + */ + .fast (NOLOAD) : + { + _sfast = . ; + *(.fast) + _efast = . ; + } > CCSRAM + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } +} diff --git a/flight/targets/common/bootloader_updater/Makefile b/flight/targets/common/bootloader_updater/Makefile index 66b6530ed..a7fc4d066 100644 --- a/flight/targets/common/bootloader_updater/Makefile +++ b/flight/targets/common/bootloader_updater/Makefile @@ -51,7 +51,9 @@ else ifeq ($(MCU),cortex-m4) # Set linker-script name depending on selected submodel name LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_fw_memory.ld - LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_sections.ld + # Using the _compat ld script ensure that the bootloader updated is compiled with irqstack in sram + # This allow to be used with bootloader earlier than rel5 + LDFLAGS += -T$(PIOS_DEVLIB)/link_stm32f4xx_sections_compat.ld SRC += $(HWDEFSINC)/firmware/cm3_fault_handlers.c SRC += $(HWDEFSINC)/firmware/dcc_stdio.c else From 5a2c53804f2610f3e27378257956cf9d274ac5aa Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 5 May 2013 15:15:44 +0200 Subject: [PATCH 10/10] OP-917 Make reboot over telemetry link works. UserDFU timeouts to the user application when no USB connection is found. +review OPReview-456 --- flight/targets/boards/coptercontrol/bootloader/main.c | 3 +-- flight/targets/boards/revolution/bootloader/main.c | 3 +-- flight/targets/boards/revoproto/bootloader/main.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/flight/targets/boards/coptercontrol/bootloader/main.c b/flight/targets/boards/coptercontrol/bootloader/main.c index 0b392193a..d603ea145 100644 --- a/flight/targets/boards/coptercontrol/bootloader/main.c +++ b/flight/targets/boards/coptercontrol/bootloader/main.c @@ -156,8 +156,7 @@ int main() { if (stopwatch > 50 * 1000 * 1000) stopwatch = 0; - if ((stopwatch > 6 * 1000 * 1000) && (DeviceState - == BLidle)) + if ((stopwatch > 6 * 1000 * 1000) && ((DeviceState == BLidle) || (DeviceState == DFUidle && !USB_connected))) JumpToApp = TRUE; processRX(); diff --git a/flight/targets/boards/revolution/bootloader/main.c b/flight/targets/boards/revolution/bootloader/main.c index db02ff0ad..b1e408c6a 100644 --- a/flight/targets/boards/revolution/bootloader/main.c +++ b/flight/targets/boards/revolution/bootloader/main.c @@ -161,8 +161,7 @@ int main() { if (stopwatch > 50 * 1000 * 1000) stopwatch = 0; - if ((stopwatch > 6 * 1000 * 1000) && (DeviceState - == BLidle)) + if ((stopwatch > 6 * 1000 * 1000) && ((DeviceState == BLidle) || (DeviceState == DFUidle && !USB_connected))) JumpToApp = true; processRX(); diff --git a/flight/targets/boards/revoproto/bootloader/main.c b/flight/targets/boards/revoproto/bootloader/main.c index 1f364abba..6d1ab5bf9 100644 --- a/flight/targets/boards/revoproto/bootloader/main.c +++ b/flight/targets/boards/revoproto/bootloader/main.c @@ -161,8 +161,7 @@ int main() { if (stopwatch > 50 * 1000 * 1000) stopwatch = 0; - if ((stopwatch > 6 * 1000 * 1000) && (DeviceState - == BLidle)) + if ((stopwatch > 6 * 1000 * 1000) && ((DeviceState == BLidle) || (DeviceState == DFUidle && !USB_connected))) JumpToApp = true; processRX();