Skip to content

Commit

Permalink
add support for pipelined bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator committed Oct 21, 2023
1 parent 7764acd commit 9212068
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 173 deletions.
21 changes: 17 additions & 4 deletions AP_Bootloader/AP_Bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#if EXT_FLASH_SIZE_MB
#include <AP_FlashIface/AP_FlashIface_JEDEC.h>
#endif
#include <AP_CheckFirmware/AP_CheckFirmware.h>

extern "C" {
int main(void);
Expand Down Expand Up @@ -80,7 +81,11 @@ int main(void)
AFIO->MAPR = mapr | AFIO_MAPR_CAN_REMAP_REMAP2 | AFIO_MAPR_SPI3_REMAP;
#endif

#ifndef NO_FASTBOOT
#if HAL_FLASH_PROTECTION
stm32_flash_unprotect_flash();
#endif

#if AP_FASTBOOT_ENABLED
enum rtc_boot_magic m = check_fast_reboot();
bool was_watchdog = stm32_was_watchdog_reset();
if (was_watchdog) {
Expand All @@ -103,7 +108,8 @@ int main(void)
try_boot = false;
timeout = 0;
}
if (!can_check_firmware()) {
const auto ok = check_good_firmware();
if (ok != check_fw_result_t::CHECK_FW_OK) {
// bad firmware CRC, don't try and boot
timeout = 0;
try_boot = false;
Expand All @@ -123,7 +129,15 @@ int main(void)
try_boot = false;
timeout = 0;
}
#elif AP_CHECK_FIRMWARE_ENABLED
const auto ok = check_good_firmware();
if (ok != check_fw_result_t::CHECK_FW_OK) {
// bad firmware, don't try and boot
timeout = 0;
try_boot = false;
}
#endif

#if defined(HAL_GPIO_PIN_VBUS) && defined(HAL_ENABLE_VBUS_CHECK)
#if HAL_USE_SERIAL_USB == TRUE
else if (palReadLine(HAL_GPIO_PIN_VBUS) == 0) {
Expand All @@ -136,7 +150,7 @@ int main(void)
// if we fail to boot properly we want to pause in bootloader to give
// a chance to load new app code
set_fast_reboot(RTC_BOOT_OFF);
#endif
#endif // AP_FASTBOOT_ENABLED

#ifdef HAL_GPIO_PIN_STAY_IN_BOOTLOADER
// optional "stay in bootloader" pin
Expand Down Expand Up @@ -185,4 +199,3 @@ int main(void)
#endif
}


Loading

0 comments on commit 9212068

Please sign in to comment.