From 4d64fd8faa8b1a0ceb9019446ba6915aaf1812ea Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 9 Mar 2013 11:22:27 +0900 Subject: Add bootmagic.c and fix bootloader_jump --- common/bootloader.c | 100 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 23 deletions(-) (limited to 'common/bootloader.c') diff --git a/common/bootloader.c b/common/bootloader.c index 6e04efbbda..77fa1b30a7 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -1,15 +1,16 @@ +#include +#include #include #include +#include #include #include "bootloader.h" -/* Start Bootloader from Application - * See - * http://www.pjrc.com/teensy/jump_to_bootloader.html - * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html - */ +#ifdef PROTOCOL_LUFA +#include +#endif + -// TODO: support usbasp /* Boot Section Size in bytes * Teensy halfKay 512 * Atmel DFU loader 4096 @@ -18,28 +19,82 @@ #ifndef BOOT_SIZE #define BOOT_SIZE 512 #endif - #define FLASH_SIZE (FLASHEND + 1) -#define BOOTLOADER_START (FLASHEND - BOOT_SIZE) +#define BOOTLOADER_START (FLASH_SIZE - BOOT_SIZE) + +/* + * Entering the Bootloader via Software + * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html + */ +#define BOOTLOADER_RESET_KEY 0xB007B007 +uint32_t reset_key __attribute__ ((section (".noinit"))); + +/* initialize MCU status by watchdog reset */ void bootloader_jump(void) { +#ifdef PROTOCOL_LUFA + USB_Disable(); cli(); + _delay_ms(2000); +#endif - // - //Teensy - // -#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) - // disable watchdog, if enabled - // disable all peripherals +#ifdef PROTOCOL_PJRC + cli(); UDCON = 1; - USBCON = (1< Date: Sun, 10 Mar 2013 15:05:28 +0900 Subject: Fix watchdog in bootloader jump - disable watchdog after watchdog reset - clear WDRF after watchdog reset --- common/bootloader.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'common/bootloader.c') diff --git a/common/bootloader.c b/common/bootloader.c index 77fa1b30a7..023220414b 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -11,15 +11,16 @@ #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 */ #ifndef BOOT_SIZE #define BOOT_SIZE 512 #endif -#define FLASH_SIZE (FLASHEND + 1) +#define FLASH_SIZE (FLASHEND + 1L) #define BOOTLOADER_START (FLASH_SIZE - BOOT_SIZE) @@ -58,13 +59,15 @@ void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, sec void bootloader_jump_after_watchdog_reset(void) { if ((MCUSR & (1< Date: Sun, 10 Mar 2013 15:36:07 +0900 Subject: Add BOOTLOADER_SIZE and remove BOOT_SIZE - define BOOTLOADER_SIZE in config.h instead of Makefile --- common/bootloader.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'common/bootloader.c') diff --git a/common/bootloader.c b/common/bootloader.c index 023220414b..f9802d36c5 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -12,16 +12,18 @@ /* Boot Section Size in *BYTEs* - * Teensy halfKay 512 - * Teensy++ halfKay 1024 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 + * 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 +#warn To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. #endif + #define FLASH_SIZE (FLASHEND + 1L) -#define BOOTLOADER_START (FLASH_SIZE - BOOT_SIZE) +#define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) /* -- cgit v1.2.3 From fe2230cf60efdc5dafb85356e54b8b87cd52c3a3 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 11 Mar 2013 13:32:46 +0900 Subject: Add default value to BOOTLOADER_SIZE --- common/bootloader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common/bootloader.c') diff --git a/common/bootloader.c b/common/bootloader.c index f9802d36c5..43a7e47ce2 100644 --- a/common/bootloader.c +++ b/common/bootloader.c @@ -19,7 +19,8 @@ * USBaspLoader 2048 */ #ifndef BOOTLOADER_SIZE -#warn To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#define BOOTLOADER_SIZE 4096 #endif #define FLASH_SIZE (FLASHEND + 1L) -- cgit v1.2.3