refactor: bootloader & cmake cleanup (#5232)
This commit is contained in:
@@ -117,26 +117,8 @@ if(NOT NATIVE_BUILD)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32_drivers_w_dbg_bl>)
|
||||
endif()
|
||||
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/rtc_driver.cpp
|
||||
../common/arm/stm32/delays_driver.cpp
|
||||
../common/arm/stm32/trainer_driver.cpp
|
||||
../common/arm/stm32/flash_driver.cpp
|
||||
../common/arm/stm32/stm32_softserial_driver.cpp
|
||||
../common/arm/stm32/stm32_pulse_driver.cpp
|
||||
../common/arm/stm32/module_timer_driver.cpp
|
||||
../common/arm/stm32/stm32_switch_driver.cpp
|
||||
../common/arm/stm32/mixer_scheduler_driver.cpp
|
||||
../common/arm/stm32/pwr_driver.cpp
|
||||
../common/arm/stm32/watchdog_driver.cpp
|
||||
../common/arm/stm32/abnormal_reboot.cpp
|
||||
)
|
||||
|
||||
if(IMU)
|
||||
add_definitions(-DIMU)
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC}
|
||||
targets/common/arm/stm32/lsm6ds_driver.cpp
|
||||
)
|
||||
set(SRC ${SRC} gyro.cpp)
|
||||
endif()
|
||||
|
||||
@@ -164,10 +146,6 @@ if(DEBUG OR CLI OR USB_SERIAL)
|
||||
message("-- Adding support for USB serial")
|
||||
endif()
|
||||
|
||||
if(GVARS)
|
||||
set(GUI_SRC ${GUI_SRC} ${GVAR_SCREEN})
|
||||
endif()
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} syscalls.c)
|
||||
|
||||
set(TARGET_SRC ${TARGET_SRC} ../common/arm/stm32/cpu_id.cpp)
|
||||
|
||||
@@ -4,115 +4,23 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
AddHardwareDefTarget(${HW_DESC_JSON})
|
||||
AddHWGenTarget(${HW_DESC_JSON} hal_keys hal_keys.inc)
|
||||
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../gui/${GUI_DIR}/lcd.cpp
|
||||
../../../../../keys.cpp
|
||||
../../../../../strhelpers.cpp
|
||||
../../../../../stamp.cpp
|
||||
../../../../../syscalls.c
|
||||
../../../../../targets/${TARGET_DIR}/${LCD_DRIVER}
|
||||
../../../../../targets/${TARGET_DIR}/backlight_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/board.cpp
|
||||
../../../../../targets/${TARGET_DIR}/bootloader/boot_menu.cpp
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hal_keys.inc
|
||||
../pwr_driver.cpp
|
||||
../delays_driver.cpp
|
||||
../flash_driver.cpp
|
||||
../watchdog_driver.cpp
|
||||
../abnormal_reboot.cpp
|
||||
${RADIO_SRC_DIR}/keys.cpp
|
||||
${RADIO_SRC_DIR}/strhelpers.cpp
|
||||
${RADIO_SRC_DIR}/stamp.cpp
|
||||
${RADIO_SRC_DIR}/syscalls.c
|
||||
${RADIO_SRC_DIR}/crc.cpp
|
||||
boot.cpp
|
||||
bin_files.cpp
|
||||
)
|
||||
|
||||
if(ROTARY_ENCODER)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/common/arm/stm32/rotary_encoder_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BLUETOOTH)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/common/arm/stm32/bluetooth_driver.cpp
|
||||
)
|
||||
endif()
|
||||
)
|
||||
|
||||
if(DEBUG_SEGGER_RTT)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../thirdparty/Segger_RTT/RTT/SEGGER_RTT.c
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
|
||||
${RADIO_SRC_DIR}/thirdparty/Segger_RTT/RTT/SEGGER_RTT.c
|
||||
)
|
||||
endif()
|
||||
|
||||
if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14 OR PCB STREQUAL PL18)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../gui/colorlcd/fonts.cpp
|
||||
../../../../../gui/colorlcd/colors.cpp
|
||||
../../../../../gui/colorlcd/bitmaps.cpp
|
||||
../../../../../fonts/lvgl/lv_font_roboto_bl_16.c
|
||||
../../../../../thirdparty/libopenui/src/bitmapbuffer.cpp
|
||||
../../../../../thirdparty/libopenui/thirdparty/lz4/lz4.c
|
||||
../../../../../targets/common/arm/stm32/dma2d.cpp
|
||||
../../../../../targets/common/arm/stm32/rtc_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/diskio_spi_flash.cpp
|
||||
../../../../../targets/common/arm/stm32/spi_flash.cpp
|
||||
../../../../../drivers/frftl.cpp
|
||||
../../../../../crc.cpp
|
||||
../../../../../targets/common/arm/stm32/sdram_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/haptic_driver.cpp
|
||||
)
|
||||
|
||||
if(PCB STREQUAL PL18)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
|
||||
../../../../../targets/pl18/key_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(PCBREV STREQUAL F16)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
|
||||
../../../../../targets/horus/videoswitch_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add LVGL sources
|
||||
foreach(LVGL_FILE ${LVGL_SRC_FILES_MINIMAL})
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} ../../../../../${LVGL_FILE})
|
||||
endforeach()
|
||||
|
||||
if(NOT (PCB STREQUAL NV14 OR PCB STREQUAL PL18))
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/${TARGET_DIR}/led_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(USB_CHARGER)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/${TARGET_DIR}/usb_charger_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(DEBUG)
|
||||
set(ENABLE_BOOTLOADER_DEBUG true)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../serial.cpp
|
||||
../../../../../boards/generic_stm32/aux_ports.cpp
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../gui/common/stdlcd/fonts.cpp
|
||||
../../../../../gui/common/stdlcd/utf8.cpp
|
||||
../../../../../crc.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# TODO: this shouldn't be needed at all
|
||||
remove_definitions(-DDISK_CACHE)
|
||||
remove_definitions(-DLUA)
|
||||
@@ -121,8 +29,6 @@ remove_definitions(-DSEMIHOSTING)
|
||||
remove_definitions(-DUSB_SERIAL)
|
||||
remove_definitions(-DUSE_WATCHDOG)
|
||||
|
||||
add_definitions(-DBOOT)
|
||||
|
||||
if(NOT NO_LTO)
|
||||
message("-- Use LTO to compile bootloader")
|
||||
target_compile_options(stm32cube_ll PRIVATE -flto)
|
||||
@@ -136,10 +42,13 @@ endif()
|
||||
add_executable(bootloader EXCLUDE_FROM_ALL ${BOOTLOADER_SRC})
|
||||
add_dependencies(bootloader ${BITMAPS_TARGET})
|
||||
|
||||
target_link_options(bootloader PRIVATE
|
||||
-lm -T${LINKER_DIR}/bootloader.ld
|
||||
target_compile_definitions(bootloader PRIVATE BOOT)
|
||||
target_compile_definitions(board_bl PRIVATE BOOT)
|
||||
|
||||
target_link_options(bootloader BEFORE PRIVATE
|
||||
-T${LINKER_DIR}/bootloader.ld
|
||||
-Wl,-Map=bootloader.map,--cref,--no-warn-mismatch,--gc-sections
|
||||
--specs=nano.specs
|
||||
-lm --specs=nano.specs
|
||||
)
|
||||
|
||||
if (DEFINED TARGET_SDRAM_START)
|
||||
@@ -156,7 +65,7 @@ if (DEFINED TARGET_SDRAM_SIZE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (DEFINED ENABLE_BOOTLOADER_DEBUG)
|
||||
if (ENABLE_BOOTLOADER_DEBUG)
|
||||
target_compile_definitions(bootloader PUBLIC -DDEBUG)
|
||||
# uncomment to enable TRACE in drivers
|
||||
# target_compile_definitions(stm32_drivers_w_dbg_bl PRIVATE -DDEBUG)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_timer.h"
|
||||
#endif
|
||||
|
||||
@@ -45,19 +46,7 @@
|
||||
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
|
||||
#endif
|
||||
|
||||
#if defined(PCBXLITE)
|
||||
#define BOOTLOADER_KEYS 0x0F
|
||||
#elif defined(RADIO_MT12)
|
||||
#define BOOTLOADER_KEYS 0x06
|
||||
#else
|
||||
#define BOOTLOADER_KEYS 0x42
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_FAMILY_T20)
|
||||
#define SECONDARY_BOOTLOADER_KEYS 0x1200
|
||||
#endif
|
||||
|
||||
#define APP_START_ADDRESS (uint32_t)(FIRMWARE_ADDRESS + BOOTLOADER_SIZE)
|
||||
#define APP_START_ADDRESS (uint32_t)(FIRMWARE_ADDRESS + BOOTLOADER_SIZE)
|
||||
|
||||
#if defined(EEPROM) || defined(SPI_FLASH)
|
||||
#define MAIN_MENU_LEN 3
|
||||
@@ -70,16 +59,6 @@
|
||||
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
|
||||
#endif
|
||||
|
||||
typedef void (*voidFunction)(void);
|
||||
|
||||
#define jumpTo(addr) do { \
|
||||
SCB->VTOR = addr; \
|
||||
__set_MSP(*(__IO uint32_t*)addr); \
|
||||
uint32_t jumpAddress = *(uint32_t*)(addr + 4); \
|
||||
voidFunction jumpFn = (voidFunction)jumpAddress; \
|
||||
jumpFn(); \
|
||||
} while(0)
|
||||
|
||||
#if !defined(SIMU)
|
||||
// Bootloader marker:
|
||||
// -> used to detect valid bootloader files
|
||||
@@ -180,6 +159,7 @@ int menuFlashFile(uint32_t index, event_t event)
|
||||
|
||||
void flashWriteBlock()
|
||||
{
|
||||
// TODO: use some board provided driver instead
|
||||
uint32_t blockOffset = 0;
|
||||
#if !defined(SIMU)
|
||||
while (BlockCount) {
|
||||
@@ -205,18 +185,26 @@ void writeEepromBlock()
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
||||
typedef void (*fctptr_t)(void);
|
||||
|
||||
static __attribute__((noreturn)) void jumpTo(uint32_t addr)
|
||||
{
|
||||
__disable_irq();
|
||||
__set_MSP(*(uint32_t*)addr);
|
||||
fctptr_t reset_handler = (fctptr_t)*(uint32_t*)(addr + 4);
|
||||
reset_handler();
|
||||
while(1){}
|
||||
}
|
||||
|
||||
// Optional board hook
|
||||
__weak void boardBLInit() {}
|
||||
__weak bool boardBLStartCondition() { return false; }
|
||||
__weak void boardBLPreJump() {}
|
||||
|
||||
void bootloaderInitApp()
|
||||
{
|
||||
LL_AHB1_GRP1_EnableClock(LCD_RCC_AHB1Periph);
|
||||
#if defined(LCD_RCC_APB2Periph)
|
||||
LL_APB2_GRP1_EnableClock(LCD_RCC_APB2Periph);
|
||||
#endif
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
|
||||
|
||||
#if defined(HAVE_BOARD_BOOTLOADER_INIT)
|
||||
boardBootloaderInit();
|
||||
#endif
|
||||
boardBLInit();
|
||||
|
||||
#if defined(DEBUG_SEGGER_RTT)
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
@@ -232,22 +220,13 @@ void bootloaderInitApp()
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(RADIO_T8) || defined(RADIO_COMMANDO8)) && !defined(RADIOMASTER_RELEASE)
|
||||
// Bind button not pressed
|
||||
if ((~(KEYS_GPIO_REG_BIND->IDR) & KEYS_GPIO_PIN_BIND) == false) {
|
||||
#else
|
||||
// LHR & RHL trims not pressed simultanously
|
||||
#if defined(SECONDARY_BOOTLOADER_KEYS)
|
||||
if (readTrims() != BOOTLOADER_KEYS && readTrims() != SECONDARY_BOOTLOADER_KEYS) {
|
||||
#else
|
||||
if (readTrims() != BOOTLOADER_KEYS) {
|
||||
#endif
|
||||
#endif
|
||||
// TODO: deInit before restarting
|
||||
if (!boardBLStartCondition()) {
|
||||
// Start main application
|
||||
boardBLPreJump();
|
||||
jumpTo(APP_START_ADDRESS);
|
||||
}
|
||||
|
||||
// TODO: move all this into board specifics
|
||||
pwrOn();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(USE_HATS_AS_KEYS)
|
||||
@@ -264,8 +243,10 @@ void bootloaderInitApp()
|
||||
|
||||
TRACE("\nBootloader started :)");
|
||||
|
||||
// TODO: move BT & EEPROM into board specifics
|
||||
#if defined(BLUETOOTH)
|
||||
// we shutdown the bluetooth module now to be sure it will be detected on firmware start
|
||||
// we shutdown the bluetooth module now to be sure it will be detected on
|
||||
// firmware start
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE, false);
|
||||
#endif
|
||||
|
||||
@@ -592,4 +573,3 @@ int bootloaderMain()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user