-
Notifications
You must be signed in to change notification settings - Fork 167
Description
Follow-up from #1874
Some bootloaders, due to unintended code generation, end up incrementing (positive) the main stack pointer by a number of bytes (8 for LibrePilot v6, 16 for dRonin recent releases). This causes the first few entries in the main stack to step on whatever happened to follow it in memory. In the bootloader updater this happened to be the flash partition table which caused the updater to fail. In firmware, this is the process stack (thread stacks): https://github.com/d-ronin/dRonin/blob/next/flight/PiOS/STM32F4xx/sections_chibios.ld#L127. Fortunately this is at the end of the stack of whatever thread happens to be first, so unless it completely fills it's stack it's probably only a theoretical issue (and filling stacks with the pattern used to detect stack usage happens in ChibiOS's ResetHandler, before any stack is ever used).
Suggested fix is either:
- Set MSP to correct location in
__early_inithook.. this is a bit fragile if upstream ChibiOSResetHandlerchanges, and happens to use the main stack before calling__early_init, so not the preferred option. - Change
ENTRYfunction in linker script to our own function which just sets MSP, then jumps to ChibiOSResetHandler. This is the safest and most preferred option I think. -e- Duh, do still need to edit ChibiOS sources to place our reset handler in the vector table. -_-
@mlyle, thoughts?