diff options
author | patrickmt <40182064+patrickmt@users.noreply.github.com> | 2018-09-28 22:34:56 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-09-28 23:09:53 -0400 |
commit | daf0cc60bff54be948c923cdc40aa80b82a27f6d (patch) | |
tree | 121de3f118e7fbc325eb79d23e3dc58c95b99e76 | |
parent | 20a10bd0846d502069203419f57e36fd7467df5e (diff) | |
download | qmk_firmware-daf0cc60bff54be948c923cdc40aa80b82a27f6d.tar.gz qmk_firmware-daf0cc60bff54be948c923cdc40aa80b82a27f6d.zip |
CTRL keyboard bootloader_jump support
Adds support for CTRL keyboards to enter bootloader via bootloader_jump()
-rw-r--r-- | lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld | 3 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/bootloader.c | 32 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/md_bootloader.h | 7 | ||||
-rw-r--r-- | tmk_core/protocol/arm_atsam/startup.c | 11 |
4 files changed, 38 insertions, 15 deletions
diff --git a/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld b/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld index 35db61971..1c6354786 100644 --- a/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld +++ b/lib/arm_atsam/packs/atmel/SAMD51_DFP/1.0.70/gcc/gcc/samd51j18a_flash.ld | |||
@@ -51,6 +51,9 @@ HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : DEFINED(__heap_size__) ? __heap_siz | |||
51 | _srom = ORIGIN(rom); | 51 | _srom = ORIGIN(rom); |
52 | _lrom = LENGTH(rom); | 52 | _lrom = LENGTH(rom); |
53 | _erom = ORIGIN(rom) + LENGTH(rom); | 53 | _erom = ORIGIN(rom) + LENGTH(rom); |
54 | _sram = ORIGIN(ram); | ||
55 | _lram = LENGTH(ram); | ||
56 | _eram = ORIGIN(ram) + LENGTH(ram); | ||
54 | 57 | ||
55 | /* Section Definitions */ | 58 | /* Section Definitions */ |
56 | SECTIONS | 59 | SECTIONS |
diff --git a/tmk_core/common/arm_atsam/bootloader.c b/tmk_core/common/arm_atsam/bootloader.c index 9701a6219..ba71bfeb0 100644 --- a/tmk_core/common/arm_atsam/bootloader.c +++ b/tmk_core/common/arm_atsam/bootloader.c | |||
@@ -16,25 +16,27 @@ | |||
16 | 16 | ||
17 | #include "bootloader.h" | 17 | #include "bootloader.h" |
18 | #include "samd51j18a.h" | 18 | #include "samd51j18a.h" |
19 | #include "md_bootloader.h" | ||
19 | 20 | ||
20 | //Set watchdog timer to reset. Directs the bootloader to stay in programming mode. | 21 | //Set watchdog timer to reset. Directs the bootloader to stay in programming mode. |
21 | void bootloader_jump(void) | 22 | void bootloader_jump(void) { |
22 | { | 23 | #ifdef KEYBOARD_massdrop_ctrl |
23 | //Keyboards released with certain bootloader can not enter bootloader from app until workaround is created | 24 | //CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method. |
24 | uint8_t ver_no_jump[] = "v2.18Jun 22 2018 17:28:08"; | 25 | uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; //The version to match (NULL terminated by compiler) |
25 | uint8_t *ver_check = ver_no_jump; | 26 | uint8_t *ver_check = ver_ram_method; //Pointer to version match string for traversal |
26 | uint8_t *boot_check = (uint8_t *)0x21A0; | 27 | uint8_t *ver_rom = (uint8_t *)0x21A0; //Pointer to address in ROM where this specific bootloader version would exist |
27 | while (*ver_check && *boot_check == *ver_check) | 28 | |
28 | { | 29 | while (*ver_check && *ver_rom == *ver_check) { //While there are check version characters to match and bootloader's version matches check's version |
29 | ver_check++; | 30 | ver_check++; //Move check version pointer to next character |
30 | boot_check++; | 31 | ver_rom++; //Move ROM version pointer to next character |
31 | } | 32 | } |
32 | if (!*ver_check) | 33 | |
33 | { | 34 | if (!*ver_check) { //If check version pointer is NULL, all characters have matched |
34 | //Version match | 35 | *MAGIC_ADDR = BOOTLOADER_MAGIC; //Set magic number into RAM |
35 | //Software workaround would go here | 36 | NVIC_SystemReset(); //Perform system reset |
36 | return; //No software restart method implemented... must use hardware reset button | 37 | while (1) {} //Won't get here |
37 | } | 38 | } |
39 | #endif | ||
38 | 40 | ||
39 | WDT->CTRLA.bit.ENABLE = 0; | 41 | WDT->CTRLA.bit.ENABLE = 0; |
40 | while (WDT->SYNCBUSY.bit.ENABLE) {} | 42 | while (WDT->SYNCBUSY.bit.ENABLE) {} |
diff --git a/tmk_core/protocol/arm_atsam/md_bootloader.h b/tmk_core/protocol/arm_atsam/md_bootloader.h index 1316876c8..956145c31 100644 --- a/tmk_core/protocol/arm_atsam/md_bootloader.h +++ b/tmk_core/protocol/arm_atsam/md_bootloader.h | |||
@@ -7,6 +7,13 @@ extern uint32_t _erom; | |||
7 | 7 | ||
8 | #define BOOTLOADER_SERIAL_MAX_SIZE 20 //DO NOT MODIFY! | 8 | #define BOOTLOADER_SERIAL_MAX_SIZE 20 //DO NOT MODIFY! |
9 | 9 | ||
10 | #ifdef KEYBOARD_massdrop_ctrl | ||
11 | //WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support | ||
12 | extern uint32_t _eram; | ||
13 | #define BOOTLOADER_MAGIC 0x3B9ACA00 | ||
14 | #define MAGIC_ADDR (uint32_t *)(&_eram - 4) | ||
15 | #endif | ||
16 | |||
10 | #ifdef MD_BOOTLOADER | 17 | #ifdef MD_BOOTLOADER |
11 | 18 | ||
12 | #define MCU_HZ 48000000 | 19 | #define MCU_HZ 48000000 |
diff --git a/tmk_core/protocol/arm_atsam/startup.c b/tmk_core/protocol/arm_atsam/startup.c index a62d02f1c..f29fac179 100644 --- a/tmk_core/protocol/arm_atsam/startup.c +++ b/tmk_core/protocol/arm_atsam/startup.c | |||
@@ -28,6 +28,7 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "samd51.h" | 30 | #include "samd51.h" |
31 | #include "md_bootloader.h" | ||
31 | 32 | ||
32 | /* Initialize segments */ | 33 | /* Initialize segments */ |
33 | extern uint32_t _sfixed; | 34 | extern uint32_t _sfixed; |
@@ -500,6 +501,16 @@ const DeviceVectors exception_table = { | |||
500 | */ | 501 | */ |
501 | void Reset_Handler(void) | 502 | void Reset_Handler(void) |
502 | { | 503 | { |
504 | #ifdef KEYBOARD_massdrop_ctrl | ||
505 | /* WARNING: This is only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support */ | ||
506 | if (*MAGIC_ADDR == BOOTLOADER_MAGIC) { | ||
507 | /* At this point, the bootloader's memory is initialized properly, so undo the jump to here, then jump back */ | ||
508 | *MAGIC_ADDR = 0x00000000; /* Change value to prevent potential bootloader entrance loop */ | ||
509 | __set_MSP(0x20008818); /* MSP according to bootloader */ | ||
510 | SCB->VTOR = 0x00000000; /* Vector table back to bootloader's */ | ||
511 | asm("bx %0"::"r"(0x00001267)); /* Jump past bootloader RCAUSE check using THUMB */ | ||
512 | } | ||
513 | #endif | ||
503 | uint32_t *pSrc, *pDest; | 514 | uint32_t *pSrc, *pDest; |
504 | 515 | ||
505 | /* Initialize the relocate segment */ | 516 | /* Initialize the relocate segment */ |