Skip to content

Commit

Permalink
core: chibios: bootloader: use integer pointers as volatile (qmk#13450)
Browse files Browse the repository at this point in the history
This prevents gcc from incorrectly trying to validate array bounds.

```
tmk_core/common/chibios/bootloader.c: error: '__builtin_memcpy' offset [0, 21] is out of the bounds [0, 0] [-Werror=array-bounds]
  107 |     __builtin_memcpy((void *) VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578#c16
Fixes qmk#12925
  • Loading branch information
t-8ch authored and nhongooi committed Dec 5, 2021
1 parent 48db952 commit 252b0f2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tmk_core/common/chibios/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void enter_bootloader_mode_if_requested(void) {
# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
__attribute__((weak)) void bootloader_jump(void) {
__builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
void *volatile vbat = (void *)VBAT;
__builtin_memcpy(vbat, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
// request reset
SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
}
Expand Down

0 comments on commit 252b0f2

Please sign in to comment.