firmware: add crc stub to all dfu apps to ensure reliable loading

DFU flashing of apps sometimes aborts, and although rare this leads to
broken devices if no boot button or serial/jtag access exists, because
the bootloader will keep trying to start a half-flashed app that then
crashes at some point.

The easiest fix that works with existing bootloaders is to prepend a
small 512 byte stub that calculcates the crc and compares it with the
crc calculated at build time, and then either starts the actual app, or
sets the dfu flag and resets. This ensures we either have a working,
running app, or end up in the bootloader, ready to flash again.

For obvious reasons this only applies to dfu apps, and not to flash
targets like the actual bootloader itself.

Change-Id: Id6df0486c8b779889d21800dc2441b3aa9af8a5f
This commit is contained in:
Eric Wild
2021-12-06 21:48:01 +01:00
committed by laforge
parent f721e69bc1
commit cb655f9774
7 changed files with 246 additions and 28 deletions

View File

@@ -89,8 +89,14 @@ __attribute__((section(".ramfunc"), noinline, noreturn)) static void erase_first
flash_cmd(EFC_FCMD_EA, 0);
#endif
flash_wait_ready();
for (;;)
NVIC_SystemReset();
for (;;) {
/* no functon call, since NVIC_SystemReset() might not be inlined! */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB();
while (1)
;
}
}
#define MAX_USB_ITER BOARD_MCK / 72 // This should be around a second