]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - common/bootloader.c
Updates to CUB's layout
[tmk_firmware.git] / common / bootloader.c
index 77fa1b30a721f26d54281267a928cd35e2bf17a5..cda295b1811e92f90baea342084b37a07139bcc1 100644 (file)
 #endif
 
 
-/* Boot Section Size in bytes
- * Teensy halfKay   512
- * Atmel DFU loader 4096
- * LUFA bootloader  4096
+/* Boot Section Size in *BYTEs*
+ *   Teensy   halfKay    512
+ *   Teensy++ halfKay    1024
+ *   Atmel DFU loader    4096
+ *   LUFA bootloader     4096
+ *   USBaspLoader        2048
  */
-#ifndef BOOT_SIZE
-#define BOOT_SIZE 512
+#ifndef BOOTLOADER_SIZE
+#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h.
+#define BOOTLOADER_SIZE     4096
 #endif
-#define FLASH_SIZE          (FLASHEND + 1)
-#define BOOTLOADER_START    (FLASH_SIZE - BOOT_SIZE)
+
+#define FLASH_SIZE          (FLASHEND + 1L)
+#define BOOTLOADER_START    (FLASH_SIZE - BOOTLOADER_SIZE)
 
 
 /* 
@@ -58,14 +62,17 @@ void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, sec
 void bootloader_jump_after_watchdog_reset(void)
 {
     if ((MCUSR & (1<<WDRF)) && reset_key == BOOTLOADER_RESET_KEY) {
+        reset_key = 0;
 
-        #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
-        // This makes custom USBasploader come up.
+        // My custom USBasploader requires this to come up.
         MCUSR = 0;
-        #endif
 
-        reset_key = 0;
-        ((void (*)(void))BOOTLOADER_START)();
+        // Seems like Teensy halfkay loader requires clearing WDRF and disabling watchdog.
+        MCUSR &= ~(1<<WDRF);
+        wdt_disable();
+
+        // This is compled into 'icall', address should be in word unit, not byte.
+        ((void (*)(void))(BOOTLOADER_START/2))();
     }
 }
 
@@ -135,7 +142,7 @@ void bootloader_jump(void) {
     ADCSRA = 0; TWCR = 0; UCSR0B = 0;
 #endif
 
-    // start Bootloader
-    ((void (*)(void))BOOTLOADER_START)();
+    // This is compled into 'icall', address should be in word unit, not byte.
+    ((void (*)(void))(BOOTLOADER_START/2))();
 }
-#endif     
+#endif