mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-19 09:54:15 +01:00
PIOS: Bootloader Helper functions should sit in HAL, not duplicated in every single architecture.
This commit is contained in:
parent
192e31986d
commit
357bc369db
@ -121,6 +121,7 @@ SRC += $(PIOSCOMMON)/pios_com.c
|
||||
SRC += $(PIOSCOMMON)/pios_hmc5843.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
|
||||
## CMSIS for STM32
|
||||
SRC += $(CMSISDIR)/core_cm3.c
|
||||
|
@ -99,8 +99,6 @@ void affine_rotate(float scale[3][4], float rotation[3]);
|
||||
void calibration(float result[3], float scale[3][4], float arg[3]);
|
||||
|
||||
/* Bootloader related functions and var*/
|
||||
static uint32_t iap_calc_crc(void);
|
||||
static void read_description(uint8_t *);
|
||||
void firmwareiapobj_callback(AhrsObjHandle obj);
|
||||
volatile uint8_t reset_count=0;
|
||||
|
||||
@ -1232,6 +1230,7 @@ void firmwareiapobj_callback(AhrsObjHandle obj)
|
||||
{
|
||||
FirmwareIAPObjData firmwareIAPObj;
|
||||
FirmwareIAPObjGet(&firmwareIAPObj);
|
||||
CRC_Ini();
|
||||
if(firmwareIAPObj.ArmReset==0)
|
||||
reset_count=0;
|
||||
if(firmwareIAPObj.ArmReset==1)
|
||||
@ -1249,36 +1248,16 @@ void firmwareiapobj_callback(AhrsObjHandle obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(firmwareIAPObj.BoardType==BOARD_TYPE && firmwareIAPObj.crc!=iap_calc_crc())
|
||||
else if(firmwareIAPObj.BoardType==BOARD_TYPE && firmwareIAPObj.crc!=FLASH_crc_memory_calc())
|
||||
{
|
||||
read_description(firmwareIAPObj.Description);
|
||||
firmwareIAPObj.crc=iap_calc_crc();
|
||||
FLASH_read_description(firmwareIAPObj.Description,SIZE_OF_DESCRIPTION);
|
||||
CRC_Ini();
|
||||
firmwareIAPObj.crc=FLASH_crc_memory_calc();
|
||||
firmwareIAPObj.BoardRevision=BOARD_REVISION;
|
||||
FirmwareIAPObjSet(&firmwareIAPObj);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t iap_calc_crc(void)
|
||||
{
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
|
||||
CRC_ResetDR();
|
||||
CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2);
|
||||
return CRC_GetCRC();
|
||||
}
|
||||
static uint8_t *FLASH_If_Read(uint32_t SectorAddress)
|
||||
{
|
||||
return (uint8_t *) (SectorAddress);
|
||||
}
|
||||
static void read_description(uint8_t * array)
|
||||
{
|
||||
uint8_t x = 0;
|
||||
for (uint32_t i = START_OF_USER_CODE + SIZE_OF_CODE; i < START_OF_USER_CODE + SIZE_OF_CODE + SIZE_OF_DESCRIPTION; ++i) {
|
||||
array[x] = *FLASH_If_Read(i);
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -40,5 +40,6 @@
|
||||
#define PIOS_INCLUDE_HMC5843
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
#define PIOS_INCLUDE_EXTI
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
|
||||
#endif /* PIOS_CONFIG_H */
|
||||
|
@ -35,6 +35,7 @@
|
||||
#define PIOS_INCLUDE_SPI
|
||||
#define PIOS_INCLUDE_SYS
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
|
||||
#endif /* PIOS_CONFIG_H */
|
||||
|
@ -96,7 +96,7 @@ int main() {
|
||||
}
|
||||
PIOS_Board_Init();
|
||||
boot_status = idle;
|
||||
Fw_crc = crc_memory_calc();
|
||||
Fw_crc = FLASH_crc_memory_calc();
|
||||
PIOS_LED_On(LED1);
|
||||
while (1) {
|
||||
process_spi_request();
|
||||
@ -146,7 +146,7 @@ void process_spi_request(void) {
|
||||
|
||||
case OPAHRS_MSG_V0_REQ_FWUP_VERIFY:
|
||||
opahrs_msg_v0_init_user_tx(&user_tx_v0, OPAHRS_MSG_V0_RSP_FWUP_STATUS);
|
||||
Fw_crc = crc_memory_calc();
|
||||
Fw_crc = FLASH_crc_memory_calc();
|
||||
lfsm_user_set_tx_v0(&user_tx_v0);
|
||||
boot_status = idle;
|
||||
PIOS_LED_Off(LED1);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#ifndef PIOS_CONFIG_H
|
||||
#define PIOS_CONFIG_H
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
|
||||
#define USB_HID
|
||||
/* Enable/Disable PiOS Modules */
|
||||
#define PIOS_INCLUDE_DELAY
|
||||
@ -61,4 +62,4 @@
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
@ -459,7 +459,7 @@ uint8_t isBiggerThanAvailable(DFUTransfer type, uint32_t size) {
|
||||
uint32_t CalcFirmCRC() {
|
||||
switch (currentProgrammingDestination) {
|
||||
case Self_flash:
|
||||
return crc_memory_calc();
|
||||
return FLASH_crc_memory_calc();
|
||||
break;
|
||||
case Remote_flash_via_spi:
|
||||
return 0;
|
||||
|
@ -31,6 +31,7 @@
|
||||
#ifndef PIOS_CONFIG_H
|
||||
#define PIOS_CONFIG_H
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
|
||||
#define USB_HID
|
||||
/* Enable/Disable PiOS Modules */
|
||||
#define PIOS_INCLUDE_DELAY
|
||||
@ -64,4 +65,4 @@
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
@ -525,7 +525,7 @@ uint32_t CalcFirmCRC() {
|
||||
struct opahrs_msg_v0 rsp;
|
||||
switch (currentProgrammingDestination) {
|
||||
case Self_flash:
|
||||
return crc_memory_calc();
|
||||
return FLASH_crc_memory_calc();
|
||||
break;
|
||||
case Remote_flash_via_spi:
|
||||
PIOS_OPAHRS_bl_FwupVerify(&rsp);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#ifndef PIOS_CONFIG_H
|
||||
#define PIOS_CONFIG_H
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
|
||||
#define USB_HID
|
||||
/* Enable/Disable PiOS Modules */
|
||||
#define PIOS_INCLUDE_DELAY
|
||||
@ -61,4 +62,4 @@
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
@ -459,7 +459,7 @@ uint8_t isBiggerThanAvailable(DFUTransfer type, uint32_t size) {
|
||||
uint32_t CalcFirmCRC() {
|
||||
switch (currentProgrammingDestination) {
|
||||
case Self_flash:
|
||||
return crc_memory_calc();
|
||||
return FLASH_crc_memory_calc();
|
||||
break;
|
||||
case Remote_flash_via_spi:
|
||||
return 0;
|
||||
|
@ -67,10 +67,6 @@ static portTickType lastResetSysTime;
|
||||
// Private functions
|
||||
static void FirmwareIAPCallback(UAVObjEvent* ev);
|
||||
|
||||
static uint32_t iap_calc_crc(void);
|
||||
|
||||
static void read_description(uint8_t *);
|
||||
|
||||
FirmwareIAPObjData data;
|
||||
|
||||
static uint32_t get_time(void);
|
||||
@ -97,7 +93,7 @@ static void resetTask(UAVObjEvent *);
|
||||
int32_t FirmwareIAPInitialize()
|
||||
{
|
||||
data.BoardType= BOARD_TYPE;
|
||||
read_description(data.Description);
|
||||
FLASH_read_description(data.Description,FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM);
|
||||
PIOS_SYS_SerialNumberGetBinary(data.CPUSerial);
|
||||
data.BoardRevision= BOARD_REVISION;
|
||||
data.ArmReset=0;
|
||||
@ -131,12 +127,14 @@ 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 != iap_calc_crc()))
|
||||
CRC_Ini();
|
||||
if((data.BoardType==BOARD_TYPE)&&(data.crc != FLASH_crc_memory_calc()))
|
||||
{
|
||||
read_description(data.Description);
|
||||
FLASH_read_description(data.Description,FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM);
|
||||
PIOS_SYS_SerialNumberGetBinary(data.CPUSerial);
|
||||
data.BoardRevision=BOARD_REVISION;
|
||||
data.crc = iap_calc_crc();
|
||||
CRC_Ini();
|
||||
data.crc = FLASH_crc_memory_calc();
|
||||
FirmwareIAPObjSet( &data );
|
||||
}
|
||||
if((data.ArmReset==1)&&(iap_state!=IAP_STATE_RESETTING))
|
||||
@ -215,41 +213,6 @@ static uint32_t get_time(void)
|
||||
return TICKS2MS(ticks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Calculate the CRC value of the code in flash.
|
||||
* \param None
|
||||
* \return calculated CRC value using STM32's builtin CRC hardware
|
||||
*
|
||||
* \note
|
||||
* I copied this function as the function crc calc function in pios_bl_helper.c
|
||||
* is only included when the PIOS_BL_HELPER is defined, but this also includes
|
||||
* the flash unlock and erase functions. It is safer to only have the flash
|
||||
* functions in the bootloader.
|
||||
*
|
||||
*/
|
||||
|
||||
static uint32_t iap_calc_crc(void)
|
||||
{
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
|
||||
CRC_ResetDR();
|
||||
CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2);
|
||||
return CRC_GetCRC();
|
||||
}
|
||||
static uint8_t *FLASH_If_Read(uint32_t SectorAddress)
|
||||
{
|
||||
return (uint8_t *) (SectorAddress);
|
||||
}
|
||||
static void read_description(uint8_t * array)
|
||||
{
|
||||
uint8_t x = 0;
|
||||
for (uint32_t i = START_OF_USER_CODE + SIZE_OF_CODE; i < START_OF_USER_CODE + SIZE_OF_CODE + FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM; ++i) {
|
||||
array[x] = *FLASH_If_Read(i);
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed by event dispatcher callback to reset INS before resetting OP
|
||||
*/
|
||||
|
@ -208,6 +208,7 @@ SRC += $(PIOSCOMMON)/pios_bmp085.c
|
||||
SRC += $(PIOSCOMMON)/pios_hcsr04.c
|
||||
SRC += $(PIOSCOMMON)/pios_i2c_esc.c
|
||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
SRC += $(FLIGHTLIB)/ahrs_spi_comm.c
|
||||
SRC += $(FLIGHTLIB)/ahrs_comm_objects.c
|
||||
|
@ -66,6 +66,7 @@
|
||||
#define PIOS_INCLUDE_RTC
|
||||
#define PIOS_INCLUDE_WDG
|
||||
#define PIOS_INCLUDE_I2C_ESC
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
|
||||
/* Defaults for Logging */
|
||||
#define LOG_FILENAME "PIOS.LOG"
|
||||
|
@ -38,6 +38,7 @@ uint8_t *FLASH_If_Read(uint32_t SectorAddress)
|
||||
return (uint8_t *) (SectorAddress);
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT)
|
||||
uint8_t FLASH_Ini()
|
||||
{
|
||||
FLASH_Unlock();
|
||||
@ -70,18 +71,20 @@ uint8_t FLASH_Start()
|
||||
|
||||
return (fail == TRUE) ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t crc_memory_calc()
|
||||
uint32_t FLASH_crc_memory_calc()
|
||||
{
|
||||
CRC_ResetDR();
|
||||
CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2);
|
||||
return CRC_GetCRC();
|
||||
}
|
||||
|
||||
void read_description(uint8_t * array)
|
||||
void FLASH_read_description(uint8_t * array, uint8_t size)
|
||||
{
|
||||
uint8_t x = 0;
|
||||
for (uint32_t i = START_OF_USER_CODE + SIZE_OF_CODE; i < START_OF_USER_CODE + SIZE_OF_CODE + SIZE_OF_DESCRIPTION; ++i) {
|
||||
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) {
|
||||
array[x] = *FLASH_If_Read(i);
|
||||
++x;
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ extern uint8_t *FLASH_If_Read(uint32_t SectorAddress);
|
||||
|
||||
extern uint8_t FLASH_Ini();
|
||||
|
||||
extern uint32_t crc_memory_calc();
|
||||
extern uint32_t FLASH_crc_memory_calc();
|
||||
|
||||
extern void read_description(uint8_t * array);
|
||||
extern void FLASH_read_description(uint8_t * array, uint8_t size);
|
||||
|
||||
extern uint8_t FLASH_Start();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user