diff --git a/flight/AHRS/ahrs.c b/flight/AHRS/ahrs.c index 57f9e11e2..830245572 100644 --- a/flight/AHRS/ahrs.c +++ b/flight/AHRS/ahrs.c @@ -33,6 +33,7 @@ /* OpenPilot Includes */ #include "ahrs.h" +#include #include "pios.h" #include "ahrs_timer.h" #include "ahrs_spi_comm.h" @@ -1228,6 +1229,8 @@ void homelocation_callback(AhrsObjHandle obj) void firmwareiapobj_callback(AhrsObjHandle obj) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; + FirmwareIAPObjData firmwareIAPObj; FirmwareIAPObjGet(&firmwareIAPObj); if(firmwareIAPObj.ArmReset==0) @@ -1235,7 +1238,7 @@ void firmwareiapobj_callback(AhrsObjHandle obj) if(firmwareIAPObj.ArmReset==1) { - if((firmwareIAPObj.BoardType==BOARD_TYPE) || (firmwareIAPObj.BoardType==0xFF)) + if((firmwareIAPObj.BoardType==bdinfo->board_type) || (firmwareIAPObj.BoardType==0xFF)) { ++reset_count; @@ -1247,11 +1250,11 @@ void firmwareiapobj_callback(AhrsObjHandle obj) } } } - else if(firmwareIAPObj.BoardType==BOARD_TYPE && firmwareIAPObj.crc!=PIOS_BL_HELPER_CRC_Memory_Calc()) + else if(firmwareIAPObj.BoardType==bdinfo->board_type && firmwareIAPObj.crc!=PIOS_BL_HELPER_CRC_Memory_Calc()) { - PIOS_BL_HELPER_FLASH_Read_Description(firmwareIAPObj.Description,SIZE_OF_DESCRIPTION); + PIOS_BL_HELPER_FLASH_Read_Description(firmwareIAPObj.Description,bdinfo->desc_size); firmwareIAPObj.crc=PIOS_BL_HELPER_CRC_Memory_Calc(); - firmwareIAPObj.BoardRevision=BOARD_REVISION; + firmwareIAPObj.BoardRevision=bdinfo->board_rev; FirmwareIAPObjSet(&firmwareIAPObj); } } diff --git a/flight/Bootloaders/AHRS/Makefile b/flight/Bootloaders/AHRS/Makefile index 3c9fa9615..10f184f96 100644 --- a/flight/Bootloaders/AHRS/Makefile +++ b/flight/Bootloaders/AHRS/Makefile @@ -199,6 +199,13 @@ CDEFS = -DSTM32F10X_$(MODEL) CDEFS += -DUSE_STDPERIPH_DRIVER CDEFS += -DUSE_$(BOARD) +# 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 += -DSTART_OF_USER_CODE=$(START_OF_FW_CODE) + # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER @@ -233,8 +240,9 @@ CFLAGS += -O$(OPT) ifeq ($(DEBUG),NO) CFLAGS += -fdata-sections -ffunction-sections endif -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) +CFLAGS += $(BLONLY_CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. CFLAGS += -mapcs-frame @@ -256,7 +264,7 @@ CONLYFLAGS += $(CSTANDARD) # Assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlns: create listing -ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) diff --git a/flight/Bootloaders/AHRS/main.c b/flight/Bootloaders/AHRS/main.c index 30915cef0..c7da0d439 100644 --- a/flight/Bootloaders/AHRS/main.c +++ b/flight/Bootloaders/AHRS/main.c @@ -33,6 +33,7 @@ /* OpenPilot Includes */ #include "ahrs_bl.h" +#include #include "pios_opahrs_proto.h" #include "bl_fsm.h" /* lfsm_state */ #include "stm32f10x_flash.h" @@ -108,6 +109,7 @@ static struct opahrs_msg_v0 link_rx_v0; static struct opahrs_msg_v0 user_tx_v0; static struct opahrs_msg_v0 user_rx_v0; void process_spi_request(void) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; bool msg_to_process = FALSE; PIOS_IRQ_Disable(); @@ -166,15 +168,15 @@ void process_spi_request(void) { break; case OPAHRS_MSG_V0_REQ_MEM_MAP: opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_MEM_MAP); - user_tx_v0.payload.user.v.rsp.mem_map.density = HW_TYPE; + user_tx_v0.payload.user.v.rsp.mem_map.density = bdinfo->hw_type; user_tx_v0.payload.user.v.rsp.mem_map.rw_flags = (BOARD_READABLE | (BOARD_WRITABLA << 1)); user_tx_v0.payload.user.v.rsp.mem_map.size_of_code_memory - = SIZE_OF_CODE; + = bdinfo->fw_size; user_tx_v0.payload.user.v.rsp.mem_map.size_of_description - = SIZE_OF_DESCRIPTION; + = bdinfo->desc_size; user_tx_v0.payload.user.v.rsp.mem_map.start_of_user_code - = START_OF_USER_CODE; + = bdinfo->fw_base; lfsm_user_set_tx_v0(&user_tx_v0); break; case OPAHRS_MSG_V0_REQ_SERIAL: @@ -192,7 +194,7 @@ void process_spi_request(void) { PIOS_LED_On(LED1); opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_FWUP_STATUS); if (!(user_rx_v0.payload.user.v.req.fwup_data.adress - < START_OF_USER_CODE)) { + < bdinfo->fw_base)) { for (uint8_t x = 0; x < user_rx_v0.payload.user.v.req.fwup_data.size; ++x) { if (FLASH_ProgramWord( @@ -250,13 +252,10 @@ void process_spi_request(void) { return; } void jump_to_app() { - //while(TRUE) - //{ - // PIOS_LED_Toggle(LED1); - // PIOS_DELAY_WaitmS(1000); - //} + const struct pios_board_info * bdinfo = &pios_board_info_blob; + PIOS_LED_On(LED1); - if (((*(__IO uint32_t*) START_OF_USER_CODE) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); @@ -265,10 +264,10 @@ void jump_to_app() { //_SetCNTR(0); // clear interrupt mask //_SetISTR(0); // clear all requests - JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4); + JumpAddress = *(__IO uint32_t*) (bdinfo->fw_base + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ - __set_MSP(*(__IO uint32_t*) START_OF_USER_CODE); + __set_MSP(*(__IO uint32_t*) bdinfo->fw_base); Jump_To_Application(); } else { boot_status = jump_failed; diff --git a/flight/Bootloaders/CopterControl/Makefile b/flight/Bootloaders/CopterControl/Makefile index f19898d07..fe83ceb66 100644 --- a/flight/Bootloaders/CopterControl/Makefile +++ b/flight/Bootloaders/CopterControl/Makefile @@ -252,6 +252,13 @@ ifeq ($(ENABLE_AUX_UART), YES) CDEFS += -DPIOS_ENABLE_AUX_UART endif +# 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 += -DSTART_OF_USER_CODE=$(START_OF_FW_CODE) + # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER @@ -287,8 +294,9 @@ ifeq ($(DEBUG),NO) CFLAGS += -ffunction-sections endif -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) +CFLAGS += $(BLONLY_CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. CFLAGS += -mapcs-frame @@ -308,7 +316,7 @@ CONLYFLAGS += $(CSTANDARD) # Assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlns: create listing -ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) diff --git a/flight/Bootloaders/CopterControl/main.c b/flight/Bootloaders/CopterControl/main.c index 23a8f16c1..67f6a4c32 100644 --- a/flight/Bootloaders/CopterControl/main.c +++ b/flight/Bootloaders/CopterControl/main.c @@ -27,6 +27,7 @@ */ /* Bootloader Includes */ #include +#include #include "stopwatch.h" #include "op_dfu.h" #include "usb_lib.h" @@ -163,7 +164,9 @@ int main() { } void jump_to_app() { - if (((*(__IO uint32_t*) START_OF_USER_CODE) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + const struct pios_board_info * bdinfo = &pios_board_info_blob; + + if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); @@ -171,10 +174,10 @@ void jump_to_app() { RCC_APB1PeriphResetCmd(0xffffffff, DISABLE); _SetCNTR(0); // clear interrupt mask _SetISTR(0); // clear all requests - JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4); + JumpAddress = *(__IO uint32_t*) (bdinfo->fw_base + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ - __set_MSP(*(__IO uint32_t*) START_OF_USER_CODE); + __set_MSP(*(__IO uint32_t*) bdinfo->fw_base); Jump_To_Application(); } else { DeviceState = failed_jump; diff --git a/flight/Bootloaders/CopterControl/op_dfu.c b/flight/Bootloaders/CopterControl/op_dfu.c index 854c7cb71..834c29339 100644 --- a/flight/Bootloaders/CopterControl/op_dfu.c +++ b/flight/Bootloaders/CopterControl/op_dfu.c @@ -30,6 +30,7 @@ #include "pios.h" #include "op_dfu.h" #include "pios_bl_helper.h" +#include //programmable devices Device devicesTable[10]; uint8_t numberOfDevices = 0; @@ -382,16 +383,18 @@ void processComand(uint8_t *xReceive_Buffer) { return; } void OPDfuIni(uint8_t discover) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; Device dev; + dev.programmingType = Self_flash; dev.readWriteFlags = (BOARD_READABLE | (BOARD_WRITABLA << 1)); - dev.startOfUserCode = START_OF_USER_CODE; - dev.sizeOfCode = SIZE_OF_CODE; - dev.sizeOfDescription = SIZE_OF_DESCRIPTION; - dev.BL_Version = BOOTLOADER_VERSION; + dev.startOfUserCode = bdinfo->fw_base; + dev.sizeOfCode = bdinfo->fw_size; + dev.sizeOfDescription = bdinfo->desc_size; + dev.BL_Version = bdinfo->bl_rev; dev.FW_Crc = CalcFirmCRC(); - dev.devID = (BOARD_TYPE << 8) | BOARD_REVISION; - dev.devType = HW_TYPE; + dev.devID = (bdinfo->board_type << 8) | (bdinfo->board_rev); + dev.devType = bdinfo->hw_type; numberOfDevices = 1; devicesTable[0] = dev; if (discover) { diff --git a/flight/Bootloaders/OpenPilot/Makefile b/flight/Bootloaders/OpenPilot/Makefile index e7804b536..23b3ffa8b 100644 --- a/flight/Bootloaders/OpenPilot/Makefile +++ b/flight/Bootloaders/OpenPilot/Makefile @@ -255,6 +255,13 @@ ifeq ($(ENABLE_AUX_UART), YES) CDEFS += -DPIOS_ENABLE_AUX_UART endif +# 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 += -DSTART_OF_USER_CODE=$(START_OF_FW_CODE) + # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER @@ -292,6 +299,7 @@ endif CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) +CFLAGS += $(BLONLY_CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. CFLAGS += -mapcs-frame diff --git a/flight/Bootloaders/OpenPilot/main.c b/flight/Bootloaders/OpenPilot/main.c index 4766caf41..3ed5a80aa 100644 --- a/flight/Bootloaders/OpenPilot/main.c +++ b/flight/Bootloaders/OpenPilot/main.c @@ -27,6 +27,7 @@ */ /* Bootloader Includes */ #include +#include #include "pios_opahrs.h" #include "stopwatch.h" #include "op_dfu.h" @@ -216,7 +217,9 @@ int main() { } void jump_to_app() { - if (((*(__IO uint32_t*) START_OF_USER_CODE) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + const struct pios_board_info * bdinfo = &pios_board_info_blob; + + if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); @@ -225,10 +228,10 @@ void jump_to_app() { _SetCNTR(0); // clear interrupt mask _SetISTR(0); // clear all requests - JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4); + JumpAddress = *(__IO uint32_t*) (bdinfo->fw_base + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ - __set_MSP(*(__IO uint32_t*) START_OF_USER_CODE); + __set_MSP(*(__IO uint32_t*) bdinfo->fw_base); Jump_To_Application(); } else { DeviceState = failed_jump; diff --git a/flight/Bootloaders/OpenPilot/op_dfu.c b/flight/Bootloaders/OpenPilot/op_dfu.c index 77b4c2c59..e15d8596b 100644 --- a/flight/Bootloaders/OpenPilot/op_dfu.c +++ b/flight/Bootloaders/OpenPilot/op_dfu.c @@ -30,6 +30,7 @@ #include "pios.h" #include "op_dfu.h" #include "pios_bl_helper.h" +#include #include "pios_opahrs.h" #include "ssp.h" /* Private typedef -----------------------------------------------------------*/ @@ -447,16 +448,18 @@ void processComand(uint8_t *xReceive_Buffer) { return; } void OPDfuIni(uint8_t discover) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; Device dev; + dev.programmingType = Self_flash; dev.readWriteFlags = (BOARD_READABLE | (BOARD_WRITABLA << 1)); - dev.startOfUserCode = START_OF_USER_CODE; - dev.sizeOfCode = SIZE_OF_CODE; - dev.sizeOfDescription = SIZE_OF_DESCRIPTION; - dev.BL_Version = BOOTLOADER_VERSION; + dev.startOfUserCode = bdinfo->fw_base; + dev.sizeOfCode = bdinfo->fw_size; + dev.sizeOfDescription = bdinfo->desc_size; + dev.BL_Version = bdinfo->bl_rev; dev.FW_Crc = CalcFirmCRC(); - dev.devID = (BOARD_TYPE << 8) | BOARD_REVISION; - dev.devType = HW_TYPE; + dev.devID = (bdinfo->board_type << 8) | (bdinfo->board_rev); + dev.devType = bdinfo->hw_type; numberOfDevices = 1; devicesTable[0] = dev; if (discover) { diff --git a/flight/Bootloaders/PipXtreme/Makefile b/flight/Bootloaders/PipXtreme/Makefile index f502a43c2..dd4a1ce43 100644 --- a/flight/Bootloaders/PipXtreme/Makefile +++ b/flight/Bootloaders/PipXtreme/Makefile @@ -251,6 +251,13 @@ ifeq ($(ENABLE_AUX_UART), YES) CDEFS += -DPIOS_ENABLE_AUX_UART endif +# 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)C +BLONLY_CDEFS += -DSTART_OF_USER_CODE=$(START_OF_FW_CODE) + # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER @@ -286,8 +293,9 @@ ifeq ($(DEBUG),NO) CFLAGS += -ffunction-sections endif -CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += -mcpu=$(MCU) CFLAGS += $(CDEFS) +CFLAGS += $(BLONLY_CDEFS) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. CFLAGS += -mapcs-frame @@ -307,7 +315,7 @@ CONLYFLAGS += $(CSTANDARD) # Assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlns: create listing -ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp ASFLAGS += $(ADEFS) ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) diff --git a/flight/Bootloaders/PipXtreme/main.c b/flight/Bootloaders/PipXtreme/main.c index a8eb5bcc6..d1568d163 100644 --- a/flight/Bootloaders/PipXtreme/main.c +++ b/flight/Bootloaders/PipXtreme/main.c @@ -27,6 +27,7 @@ */ /* Bootloader Includes */ #include +#include #include "stopwatch.h" #include "op_dfu.h" #include "usb_lib.h" @@ -170,7 +171,9 @@ int main() { } void jump_to_app() { - if (((*(__IO uint32_t*) START_OF_USER_CODE) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ + const struct pios_board_info * bdinfo = &pios_board_info_blob; + + if (((*(__IO uint32_t*) bdinfo->fw_base) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */ FLASH_Lock(); RCC_APB2PeriphResetCmd(0xffffffff, ENABLE); RCC_APB1PeriphResetCmd(0xffffffff, ENABLE); @@ -179,10 +182,10 @@ void jump_to_app() { _SetCNTR(0); // clear interrupt mask _SetISTR(0); // clear all requests - JumpAddress = *(__IO uint32_t*) (START_OF_USER_CODE + 4); + JumpAddress = *(__IO uint32_t*) (bdinfo->fw_base + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ - __set_MSP(*(__IO uint32_t*) START_OF_USER_CODE); + __set_MSP(*(__IO uint32_t*) bdinfo->fw_base); Jump_To_Application(); } else { DeviceState = failed_jump; diff --git a/flight/Bootloaders/PipXtreme/op_dfu.c b/flight/Bootloaders/PipXtreme/op_dfu.c index c413c31ba..fa0281d52 100644 --- a/flight/Bootloaders/PipXtreme/op_dfu.c +++ b/flight/Bootloaders/PipXtreme/op_dfu.c @@ -30,6 +30,7 @@ #include "pios.h" #include "op_dfu.h" #include "pios_bl_helper.h" +#include /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ @@ -414,16 +415,18 @@ void processComand(uint8_t *xReceive_Buffer) { return; } void OPDfuIni(uint8_t discover) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; Device dev; + dev.programmingType = Self_flash; dev.readWriteFlags = (BOARD_READABLE | (BOARD_WRITABLA << 1)); - dev.startOfUserCode = START_OF_USER_CODE; - dev.sizeOfCode = SIZE_OF_CODE; - dev.sizeOfDescription = SIZE_OF_DESCRIPTION; - dev.BL_Version = BOOTLOADER_VERSION; + dev.startOfUserCode = bdinfo->fw_base; + dev.sizeOfCode = bdinfo->fw_size; + dev.sizeOfDescription = bdinfo->desc_size; + dev.BL_Version = bdinfo->bl_rev; dev.FW_Crc = CalcFirmCRC(); - dev.devID = (BOARD_TYPE << 8) | BOARD_REVISION; - dev.devType = HW_TYPE; + dev.devID = (bdinfo->board_type << 8) | (bdinfo->board_rev); + dev.devType = bdinfo->hw_type; numberOfDevices = 1; devicesTable[0] = dev; if (discover) { diff --git a/flight/Modules/FirmwareIAP/firmwareiap.c b/flight/Modules/FirmwareIAP/firmwareiap.c index 11e8721fd..395ed960f 100644 --- a/flight/Modules/FirmwareIAP/firmwareiap.c +++ b/flight/Modules/FirmwareIAP/firmwareiap.c @@ -27,6 +27,7 @@ #include #include "pios.h" +#include #include "openpilot.h" #include "firmwareiap.h" #include "firmwareiapobj.h" @@ -90,10 +91,12 @@ static void resetTask(UAVObjEvent *); int32_t FirmwareIAPInitialize() { - data.BoardType= BOARD_TYPE; + const struct pios_board_info * bdinfo = &pios_board_info_blob; + + data.BoardType= bdinfo->board_type; PIOS_BL_HELPER_FLASH_Read_Description(data.Description,FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM); PIOS_SYS_SerialNumberGetBinary(data.CPUSerial); - data.BoardRevision= BOARD_REVISION; + data.BoardRevision= bdinfo->board_rev; data.ArmReset=0; data.crc = 0; FirmwareIAPObjSet( &data ); @@ -112,6 +115,7 @@ int32_t FirmwareIAPInitialize() static uint8_t iap_state = IAP_STATE_READY; static void FirmwareIAPCallback(UAVObjEvent* ev) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; static uint32_t last_time = 0; uint32_t this_time; uint32_t delta; @@ -125,11 +129,11 @@ static void FirmwareIAPCallback(UAVObjEvent* ev) this_time = get_time(); delta = this_time - last_time; last_time = this_time; - if((data.BoardType==BOARD_TYPE)&&(data.crc != PIOS_BL_HELPER_CRC_Memory_Calc())) + if((data.BoardType==bdinfo->board_type)&&(data.crc != PIOS_BL_HELPER_CRC_Memory_Calc())) { PIOS_BL_HELPER_FLASH_Read_Description(data.Description,FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM); PIOS_SYS_SerialNumberGetBinary(data.CPUSerial); - data.BoardRevision=BOARD_REVISION; + data.BoardRevision=bdinfo->board_rev; data.crc = PIOS_BL_HELPER_CRC_Memory_Calc(); FirmwareIAPObjSet( &data ); } diff --git a/flight/PiOS/Boards/STM32103CB_AHRS.h b/flight/PiOS/Boards/STM32103CB_AHRS.h index a1c4907b0..d17799ada 100644 --- a/flight/PiOS/Boards/STM32103CB_AHRS.h +++ b/flight/PiOS/Boards/STM32103CB_AHRS.h @@ -64,23 +64,6 @@ TIM8 | | | | //------------------------ // BOOTLOADER_SETTINGS //------------------------ -//#define FUNC_ID 2 -//#define HW_VERSION 69 - -#define BOOTLOADER_VERSION 0 -#define BOARD_TYPE 0x02 -#define BOARD_REVISION 0x01 -//#define HW_VERSION (BOARD_TYPE << 8) | BOARD_REVISION - -#define MEM_SIZE 0x20000 //128K -#define SIZE_OF_DESCRIPTION 100 -#define START_OF_USER_CODE (uint32_t)0x08002000 -#define SIZE_OF_CODE (uint32_t)(MEM_SIZE-(START_OF_USER_CODE-0x08000000)-SIZE_OF_DESCRIPTION) -#ifdef STM32F10X_HD - #define HW_TYPE 0 //0=high_density 1=medium_density; -#elif STM32F10X_MD - #define HW_TYPE 1 //0=high_density 1=medium_density; -#endif #define BOARD_READABLE TRUE #define BOARD_WRITABLA TRUE #define MAX_DEL_RETRYS 3 diff --git a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h index fcc868090..f26bd9c1c 100644 --- a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h @@ -60,21 +60,6 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 //------------------------ // BOOTLOADER_SETTINGS //------------------------ -//#define FUNC_ID 2 -//#define HW_VERSION 69 - -#define BOOTLOADER_VERSION 0 -#define BOARD_TYPE 0x04 -#define BOARD_REVISION 0x01 -#define MEM_SIZE 0x20000 //128K -#define SIZE_OF_DESCRIPTION 100 -#define START_OF_USER_CODE (uint32_t)0x08003000 -#define SIZE_OF_CODE (uint32_t)(MEM_SIZE-(START_OF_USER_CODE-0x08000000)-SIZE_OF_DESCRIPTION) -#ifdef STM32F10X_HD - #define HW_TYPE 0 //0=high_density 1=medium_density; -#elif STM32F10X_MD - #define HW_TYPE 1 //0=high_density 1=medium_density; -#endif #define BOARD_READABLE TRUE #define BOARD_WRITABLA TRUE #define MAX_DEL_RETRYS 3 diff --git a/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h b/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h index 6811bfad5..7114c2871 100644 --- a/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h @@ -58,18 +58,6 @@ TIM4 | STOPWATCH | //------------------------ // BOOTLOADER_SETTINGS //------------------------ -#define BOOTLOADER_VERSION 0 -#define BOARD_TYPE 0x03 -#define BOARD_REVISION 0x01 -#define MEM_SIZE (0x20000 - 0x00400) // 128K - 1K (reserved for config data) -#define SIZE_OF_DESCRIPTION 100 -#define START_OF_USER_CODE (uint32_t)0x08003000 -#define SIZE_OF_CODE (uint32_t)(MEM_SIZE-(START_OF_USER_CODE-0x08000000)-SIZE_OF_DESCRIPTION) -#ifdef STM32F10X_HD - #define HW_TYPE 0 //0=high_density 1=medium_density; -#elif STM32F10X_MD - #define HW_TYPE 1 //0=high_density 1=medium_density; -#endif #define BOARD_READABLE TRUE #define BOARD_WRITABLA TRUE #define MAX_DEL_RETRYS 3 diff --git a/flight/PiOS/Boards/STM3210E_INS.h b/flight/PiOS/Boards/STM3210E_INS.h index 5efb04a36..3229de344 100644 --- a/flight/PiOS/Boards/STM3210E_INS.h +++ b/flight/PiOS/Boards/STM3210E_INS.h @@ -69,25 +69,6 @@ TIM8 | | | | //------------------------ // BOOTLOADER_SETTINGS //------------------------ - -//#define FUNC_ID 1 -//#define HW_VERSION 01 - -#define BOOTLOADER_VERSION 0 -#define BOARD_TYPE 0x05 // INS board -#define BOARD_REVISION 0x01 // Beta version -//#define HW_VERSION (BOARD_TYPE << 8) | BOARD_REVISION - -#define MEM_SIZE 524288 //512K -#define SIZE_OF_DESCRIPTION (uint8_t) 100 -#define START_OF_USER_CODE (uint32_t)0x08005000//REMEMBER SET ALSO IN link_stm32f10x_HD_BL.ld -#define SIZE_OF_CODE (uint32_t) (MEM_SIZE-(START_OF_USER_CODE-0x08000000)-SIZE_OF_DESCRIPTION) - -#ifdef STM32F10X_HD - #define HW_TYPE 0 //0=high_density 1=medium_density; -#elif STM32F10X_MD - #define HW_TYPE 1 //0=high_density 1=medium_density; -#endif #define BOARD_READABLE TRUE #define BOARD_WRITABLA TRUE #define MAX_DEL_RETRYS 3 diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index b987ab600..58e3fb077 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -68,25 +68,6 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8 //------------------------ // BOOTLOADER_SETTINGS //------------------------ - -//#define FUNC_ID 1 -//#define HW_VERSION 01 - -#define BOOTLOADER_VERSION 0 -#define BOARD_TYPE 0x01 // OpenPilot board -#define BOARD_REVISION 0x01 // Beta version -//#define HW_VERSION (BOARD_TYPE << 8) | BOARD_REVISION - -#define MEM_SIZE 524288 //512K -#define SIZE_OF_DESCRIPTION (uint8_t) 100 -#define START_OF_USER_CODE (uint32_t)0x08005000//REMEMBER SET ALSO IN link_stm32f10x_HD_BL.ld -#define SIZE_OF_CODE (uint32_t) (MEM_SIZE-(START_OF_USER_CODE-0x08000000)-SIZE_OF_DESCRIPTION) - -#ifdef STM32F10X_HD - #define HW_TYPE 0 //0=high_density 1=medium_density; -#elif STM32F10X_MD - #define HW_TYPE 1 //0=high_density 1=medium_density; -#endif #define BOARD_READABLE TRUE #define BOARD_WRITABLA TRUE #define MAX_DEL_RETRYS 3 diff --git a/flight/PiOS/Common/pios_bl_helper.c b/flight/PiOS/Common/pios_bl_helper.c index 545a008c6..967c3c7e6 100644 --- a/flight/PiOS/Common/pios_bl_helper.c +++ b/flight/PiOS/Common/pios_bl_helper.c @@ -31,6 +31,7 @@ /* Project Includes */ #include "pios.h" #if defined(PIOS_INCLUDE_BL_HELPER) +#include #include "stm32f10x_flash.h" uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) @@ -47,10 +48,10 @@ uint8_t PIOS_BL_HELPER_FLASH_Ini() uint8_t PIOS_BL_HELPER_FLASH_Start() { - uint32_t pageAdress; - pageAdress = START_OF_USER_CODE; + const struct pios_board_info * bdinfo = &pios_board_info_blob; + uint32_t pageAdress = bdinfo->fw_base; uint8_t fail = FALSE; - while ((pageAdress < START_OF_USER_CODE + SIZE_OF_CODE + SIZE_OF_DESCRIPTION) + 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) { @@ -75,17 +76,20 @@ uint8_t PIOS_BL_HELPER_FLASH_Start() uint32_t PIOS_BL_HELPER_CRC_Memory_Calc() { + const struct pios_board_info * bdinfo = &pios_board_info_blob; + PIOS_BL_HELPER_CRC_Ini(); CRC_ResetDR(); - CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2); + CRC_CalcBlockCRC((uint32_t *) bdinfo->fw_base, (bdinfo->fw_size) >> 2); return CRC_GetCRC(); } void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t * array, uint8_t size) { + const struct pios_board_info * bdinfo = &pios_board_info_blob; uint8_t x = 0; - if (size>SIZE_OF_DESCRIPTION) size = SIZE_OF_DESCRIPTION; - for (uint32_t i = START_OF_USER_CODE + SIZE_OF_CODE; i < START_OF_USER_CODE + SIZE_OF_CODE + size; ++i) { + if (size > bdinfo->desc_size) size = bdinfo->desc_size; + for (uint32_t i = bdinfo->fw_base + bdinfo->fw_size; i < bdinfo->fw_base + bdinfo->fw_size + size; ++i) { array[x] = *PIOS_BL_HELPER_FLASH_If_Read(i); ++x; }