From 898292fcdb1be6c20ec735045c8e4386738290ac Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 20 Oct 2012 15:22:54 +0200 Subject: [PATCH 1/2] added (fake) firmware version information to simposix --- flight/Modules/FirmwareIAP/firmwareiap.c | 11 +++ flight/PiOS.posix/inc/pios_bl_helper.h | 46 ++++++++++++ flight/PiOS.posix/inc/pios_board_info.h | 24 +++++++ flight/PiOS.posix/inc/pios_iap.h | 45 ++++++++++++ flight/PiOS.posix/inc/pios_sys.h | 85 +++++++++++++---------- flight/PiOS.posix/pios.h | 7 ++ flight/PiOS.posix/posix/pios_bl_helper.c | 53 ++++++++++++++ flight/PiOS.posix/posix/pios_board_info.c | 20 ++++++ flight/PiOS.posix/posix/pios_iap.c | 69 ++++++++++++++++++ flight/PiOS.posix/posix/pios_sys.c | 32 ++++++--- flight/SimPosix/Makefile | 16 ++++- flight/SimPosix/System/inc/pios_config.h | 2 + make/boards/simposix/board-info.mk | 10 +-- 13 files changed, 368 insertions(+), 52 deletions(-) create mode 100644 flight/PiOS.posix/inc/pios_bl_helper.h create mode 100644 flight/PiOS.posix/inc/pios_board_info.h create mode 100644 flight/PiOS.posix/inc/pios_iap.h create mode 100644 flight/PiOS.posix/posix/pios_bl_helper.c create mode 100644 flight/PiOS.posix/posix/pios_board_info.c create mode 100644 flight/PiOS.posix/posix/pios_iap.c diff --git a/flight/Modules/FirmwareIAP/firmwareiap.c b/flight/Modules/FirmwareIAP/firmwareiap.c index 0a88046b8..d0c8d3876 100644 --- a/flight/Modules/FirmwareIAP/firmwareiap.c +++ b/flight/Modules/FirmwareIAP/firmwareiap.c @@ -108,6 +108,17 @@ int32_t FirmwareIAPInitialize() return 0; } +/** + * Initialise the module, called on startup + * \returns 0 on success or -1 if initialisation failed + */ +int32_t FirmwareIAPStart(void) +{ + /* nothing, no running task */ + return 0; +} + + /*! * \brief FirmwareIAPCallback - callback function for firmware IAP requests * \param[in] ev - pointer objevent diff --git a/flight/PiOS.posix/inc/pios_bl_helper.h b/flight/PiOS.posix/inc/pios_bl_helper.h new file mode 100644 index 000000000..e2e9e694e --- /dev/null +++ b/flight/PiOS.posix/inc/pios_bl_helper.h @@ -0,0 +1,46 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_BOOTLOADER Functions + * @brief HAL code to interface to the OpenPilot AHRS module + * @{ + * + * @file pios_bl_helper.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Bootloader Helper Functions + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_BL_HELPER_H_ +#define PIOS_BL_HELPER_H_ + +extern uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress); + +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 void PIOS_BL_HELPER_CRC_Ini(); + +#endif /* PIOS_BL_HELPER_H_ */ diff --git a/flight/PiOS.posix/inc/pios_board_info.h b/flight/PiOS.posix/inc/pios_board_info.h new file mode 100644 index 000000000..3ff7aa886 --- /dev/null +++ b/flight/PiOS.posix/inc/pios_board_info.h @@ -0,0 +1,24 @@ +#ifndef PIOS_BOARD_INFO_H +#define PIOS_BOARD_INFO_H + +#include /* uint* */ + +#define PIOS_BOARD_INFO_BLOB_MAGIC 0xBDBDBDBD + +struct pios_board_info { + uint32_t magic; + uint8_t board_type; + uint8_t board_rev; + uint8_t bl_rev; + uint8_t hw_type; + uint32_t fw_base; + uint32_t fw_size; + uint32_t desc_base; + uint32_t desc_size; + uint32_t ee_base; + uint32_t ee_size; +} __attribute__((packed)); + +extern const struct pios_board_info pios_board_info_blob; + +#endif /* PIOS_BOARD_INFO_H */ diff --git a/flight/PiOS.posix/inc/pios_iap.h b/flight/PiOS.posix/inc/pios_iap.h new file mode 100644 index 000000000..d9b41170b --- /dev/null +++ b/flight/PiOS.posix/inc/pios_iap.h @@ -0,0 +1,45 @@ +/*! + * @File iap.h + * @Brief Header file for the In-Application-Programming Module + * + * Created on: Sep 6, 2010 + * Author: joe + */ + +#ifndef PIOS_IAP_H_ +#define PIOS_IAP_H_ + + +/**************************************************************************************** + * Header files + ****************************************************************************************/ + +/***************************************************************************************** + * Public Definitions/Macros + ****************************************************************************************/ +#if defined(STM32F4XX) +#define MAGIC_REG_1 RTC_BKP_DR1 +#define MAGIC_REG_2 RTC_BKP_DR2 +#define IAP_BOOTCOUNT RTC_BKP_DR3 +#else +#define MAGIC_REG_1 BKP_DR1 +#define MAGIC_REG_2 BKP_DR2 +#define IAP_BOOTCOUNT BKP_DR3 +#endif + +/**************************************************************************************** + * Public Functions + ****************************************************************************************/ +void PIOS_IAP_Init(void); +uint32_t PIOS_IAP_CheckRequest( void ); +void PIOS_IAP_SetRequest1(void); +void PIOS_IAP_SetRequest2(void); +void PIOS_IAP_ClearRequest(void); +uint16_t PIOS_IAP_ReadBootCount(void); +void PIOS_IAP_WriteBootCount(uint16_t); + +/**************************************************************************************** + * Public Data + ****************************************************************************************/ + +#endif /* PIOS_IAP_H_ */ diff --git a/flight/PiOS.posix/inc/pios_sys.h b/flight/PiOS.posix/inc/pios_sys.h index 4e71b54a0..7f183a892 100644 --- a/flight/PiOS.posix/inc/pios_sys.h +++ b/flight/PiOS.posix/inc/pios_sys.h @@ -1,35 +1,50 @@ -/** - ****************************************************************************** - * - * @file pios_sys.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * Parts by Thorsten Klose (tk@midibox.org) - * @brief System and hardware Init functions header. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PIOS_SYS_H -#define PIOS_SYS_H - -/* Public Functions */ -extern void PIOS_SYS_Init(void); -extern int32_t PIOS_SYS_Reset(void); -extern int32_t PIOS_SYS_SerialNumberGet(char *str); - -#endif /* PIOS_SYS_H */ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_SYS System Functions + * @brief PIOS System Initialization code + * @{ + * + * @file pios_sys.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Thorsten Klose (tk@midibox.org) + * @brief System and hardware Init functions header. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_SYS_H +#define PIOS_SYS_H + +#define PIOS_SYS_SERIAL_NUM_BINARY_LEN 12 +#define PIOS_SYS_SERIAL_NUM_ASCII_LEN (PIOS_SYS_SERIAL_NUM_BINARY_LEN * 2) + +/* Public Functions */ +extern void PIOS_SYS_Init(void); +extern int32_t PIOS_SYS_Reset(void); +extern uint32_t PIOS_SYS_getCPUFlashSize(void); +extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t array[PIOS_SYS_SERIAL_NUM_BINARY_LEN]); +extern int32_t PIOS_SYS_SerialNumberGet(char str[PIOS_SYS_SERIAL_NUM_ASCII_LEN+1]); + +#endif /* PIOS_SYS_H */ + +/** + * @} + * @} + */ diff --git a/flight/PiOS.posix/pios.h b/flight/PiOS.posix/pios.h index 8e96fa092..28e896835 100644 --- a/flight/PiOS.posix/pios.h +++ b/flight/PiOS.posix/pios.h @@ -68,6 +68,13 @@ #include #include +#if defined(PIOS_INCLUDE_IAP) +#include +#endif +#if defined(PIOS_INCLUDE_BL_HELPER) +#include +#endif + #define NELEMENTS(x) (sizeof(x) / sizeof(*(x))) #endif /* PIOS_H */ diff --git a/flight/PiOS.posix/posix/pios_bl_helper.c b/flight/PiOS.posix/posix/pios_bl_helper.c new file mode 100644 index 000000000..a7920e5d2 --- /dev/null +++ b/flight/PiOS.posix/posix/pios_bl_helper.c @@ -0,0 +1,53 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_BOOTLOADER Functions + * @brief HAL code to interface to the OpenPilot AHRS module + * @{ + * + * @file pios_bl_helper.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @brief Bootloader Helper Functions + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Project Includes */ +#include "pios.h" +#if defined(PIOS_INCLUDE_BL_HELPER) +#include + +uint32_t PIOS_BL_HELPER_CRC_Memory_Calc() +{ + return 0; +} + +extern const struct fw_version_info fw_version_blob; +void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t * array, uint8_t size) +{ + uint8_t * desc = (uint8_t *) &fw_version_blob; + for (uint32_t i = 0; i < size; i++) { + array[i] = desc[i]; + } +} + +void PIOS_BL_HELPER_CRC_Ini() +{ +} +#endif diff --git a/flight/PiOS.posix/posix/pios_board_info.c b/flight/PiOS.posix/posix/pios_board_info.c new file mode 100644 index 000000000..c273a881d --- /dev/null +++ b/flight/PiOS.posix/posix/pios_board_info.c @@ -0,0 +1,20 @@ +#include +#include + +#include "pios_board_info.h" + +const struct pios_board_info pios_board_info_blob = { + .magic = PIOS_BOARD_INFO_BLOB_MAGIC, + .board_type = BOARD_TYPE, + .board_rev = BOARD_REVISION, + .bl_rev = BOOTLOADER_VERSION, + .hw_type = HW_TYPE, + .fw_base = FW_BANK_BASE, + .fw_size = FW_BANK_SIZE - FW_DESC_SIZE, + .desc_base = FW_BANK_BASE + FW_BANK_SIZE - FW_DESC_SIZE, + .desc_size = FW_DESC_SIZE, +#ifdef EE_BANK_BASE + .ee_base = EE_BANK_BASE, + .ee_size = EE_BANK_SIZE, +#endif +}; diff --git a/flight/PiOS.posix/posix/pios_iap.c b/flight/PiOS.posix/posix/pios_iap.c new file mode 100644 index 000000000..be5b19536 --- /dev/null +++ b/flight/PiOS.posix/posix/pios_iap.c @@ -0,0 +1,69 @@ +/*! + * @File iap.c + * @Brief + * + * Created on: Sep 6, 2010 + * Author: joe + */ + + +/**************************************************************************************** + * Header files + ****************************************************************************************/ +#include + +/*! + * \brief PIOS_IAP_Init - performs required initializations for iap module. + * \param none. + * \return none. + * \retval none. + * + * Created: Sep 8, 2010 10:10:48 PM by joe + */ +void PIOS_IAP_Init( void ) +{ + +} + +/*! + * \brief Determines if an In-Application-Programming request has been made. + * \param *comm - Which communication stream to use for the IAP (USB, Telemetry, I2C, SPI, etc) + * \return TRUE - if correct sequence found, along with 'comm' updated. + * FALSE - Note that 'comm' will have an invalid comm identifier. + * \retval + * + */ +uint32_t PIOS_IAP_CheckRequest( void ) +{ + + return false; +} + + + +/*! + * \brief Sets the 1st word of the request sequence. + * \param n/a + * \return n/a + * \retval + */ +void PIOS_IAP_SetRequest1(void) +{ +} + +void PIOS_IAP_SetRequest2(void) +{ +} + +void PIOS_IAP_ClearRequest(void) +{ +} + +uint16_t PIOS_IAP_ReadBootCount(void) +{ + return 0; +} + +void PIOS_IAP_WriteBootCount (uint16_t boot_count) +{ +} diff --git a/flight/PiOS.posix/posix/pios_sys.c b/flight/PiOS.posix/posix/pios_sys.c index 85cdc9727..6b685f6fe 100644 --- a/flight/PiOS.posix/posix/pios_sys.c +++ b/flight/PiOS.posix/posix/pios_sys.c @@ -110,6 +110,23 @@ int32_t PIOS_SYS_Reset(void) return -1; } +/** +* Returns the serial number as a string +* param[out] uint8_t pointer to a string which can store at least 12 bytes +* (12 bytes returned for STM32) +* return < 0 if feature not supported +*/ +int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array) +{ + /* Stored in the so called "electronic signature" */ + for (int i = 0; i < PIOS_SYS_SERIAL_NUM_BINARY_LEN; ++i) { + array[i] = 0xff; + } + + /* No error */ + return 0; +} + /** * Returns the serial number as a string * param[out] str pointer to a string which can store at least 32 digits + zero terminator! @@ -118,19 +135,12 @@ int32_t PIOS_SYS_Reset(void) */ int32_t PIOS_SYS_SerialNumberGet(char *str) { - int i; - /* Stored in the so called "electronic signature" */ - for(i=0; i<24; ++i) { - //uint8_t b = MEM8(0x1ffff7e8 + (i/2)); - //if( !(i & 1) ) - //b >>= 4; - //b &= 0x0f; - - //str[i] = ((b > 9) ? ('A'-10) : '0') + b; - str[i]='6'; + int i; + for (i = 0; i < PIOS_SYS_SERIAL_NUM_ASCII_LEN; ++i) { + str[i] = 'F'; } - str[i] = 0; + str[i] = '\0'; /* No error */ return 0; diff --git a/flight/SimPosix/Makefile b/flight/SimPosix/Makefile index 9e24125ee..2bdbc2066 100644 --- a/flight/SimPosix/Makefile +++ b/flight/SimPosix/Makefile @@ -55,6 +55,7 @@ FLASH_TOOL = OPENOCD MODULES = ManualControl Stabilization GPS MODULES += CameraStab MODULES += Telemetry +MODULES += FirmwareIAP #MODULES += OveroSync PYMODULES = #FlightPlan @@ -242,6 +243,19 @@ EXTRA_LIBS = # 0 = turn off optimization. s = optimize for size. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) + +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) + +# Since we are simulating all this firmware the code needs to know what the BL would +# normally contain +CFLAGS += $(BLONLY_CDEFS) + ifeq ($(DEBUG),YES) CFLAGS += -O0 CFLAGS += -DGENERAL_COV @@ -370,7 +384,7 @@ ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) ALLSRCBASE = $(notdir $(basename $(ALLSRC))) # Define all object files. -ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE))) +ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE) $(TARGET).bin.firmwareinfo )) # Define all listing files (used for make clean). LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) diff --git a/flight/SimPosix/System/inc/pios_config.h b/flight/SimPosix/System/inc/pios_config.h index d4add3666..c2413f6c0 100644 --- a/flight/SimPosix/System/inc/pios_config.h +++ b/flight/SimPosix/System/inc/pios_config.h @@ -84,6 +84,8 @@ #define PIOS_INCLUDE_PPM #define PIOS_INCLUDE_PWM //#define PIOS_INCLUDE_GCSRCVR +#define PIOS_INCLUDE_IAP +#define PIOS_INCLUDE_BL_HELPER #define PIOS_INCLUDE_SETTINGS #define PIOS_INCLUDE_FLASH diff --git a/make/boards/simposix/board-info.mk b/make/boards/simposix/board-info.mk index 4a637a53d..c60452f33 100644 --- a/make/boards/simposix/board-info.mk +++ b/make/boards/simposix/board-info.mk @@ -13,12 +13,12 @@ OPENOCD_JTAG_CONFIG := OPENOCD_CONFIG := # Note: These must match the values in link_$(BOARD)_memory.ld -#BL_BANK_BASE := 0x08000000 # Start of bootloader flash -#BL_BANK_SIZE := 0x00008000 # Should include BD_INFO region -#FW_BANK_BASE := 0x08008000 # Start of firmware flash -#FW_BANK_SIZE := 0x00038000 # Should include FW_DESC_SIZE +BL_BANK_BASE := 0x08000000 # Start of bootloader flash +BL_BANK_SIZE := 0x00008000 # Should include BD_INFO region +FW_BANK_BASE := 0x08008000 # Start of firmware flash +FW_BANK_SIZE := 0x00038000 # Should include FW_DESC_SIZE -#FW_DESC_SIZE := 0x00000064 +FW_DESC_SIZE := 0x00000064 OSCILLATOR_FREQ := 8000000 SYSCLK_FREQ := 168000000 From 1fe41c7a67ed6b8957f3a231646e80e6391a3dd1 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sat, 20 Oct 2012 16:07:16 +0200 Subject: [PATCH 2/2] circular dependency on firmwareinfo due to checksum of firmware required to link firmware - fixed by creating checksum of uavobject inittialization object file instead --- flight/SimPosix/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flight/SimPosix/Makefile b/flight/SimPosix/Makefile index 2bdbc2066..7244068a0 100644 --- a/flight/SimPosix/Makefile +++ b/flight/SimPosix/Makefile @@ -384,7 +384,7 @@ ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) ALLSRCBASE = $(notdir $(basename $(ALLSRC))) # Define all object files. -ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE) $(TARGET).bin.firmwareinfo )) +ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE) uavobjectsinit.o.firmwareinfo )) # Define all listing files (used for make clean). LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) @@ -440,6 +440,8 @@ $(OUTDIR)/$(TARGET).bin.o: $(OUTDIR)/$(TARGET).bin $(eval $(call OPFW_TEMPLATE,$(OUTDIR)/$(TARGET).bin,$(BOARD_TYPE),$(BOARD_REVISION))) +$(eval $(call OPFW_TEMPLATE,$(OUTDIR)/uavobjectsinit.o,$(BOARD_TYPE),$(BOARD_REVISION))) + # Add jtag targets (program and wipe) $(eval $(call JTAG_TEMPLATE,$(OUTDIR)/$(TARGET).bin,$(FW_BANK_BASE),$(FW_BANK_SIZE),$(OPENOCD_JTAG_CONFIG),$(OPENOCD_CONFIG)))