From 9e61bd70f3f794fc8849a004ca13208de98d8225 Mon Sep 17 00:00:00 2001 From: Bluebie Date: Fri, 5 Oct 2012 10:12:08 +1000 Subject: Improved upgrade mechanism - now it should actually work! I've successfully upgraded from 1.02 to 1.03 and 1.03 to 1.03. Haven't tested earlier versions of micronucleus or other bootloaders not based on USBaspLoader-tiny85 --- upgrade/upgrade.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'upgrade/upgrade.c') diff --git a/upgrade/upgrade.c b/upgrade/upgrade.c index 3d54acf..dc5d449 100644 --- a/upgrade/upgrade.c +++ b/upgrade/upgrade.c @@ -37,7 +37,11 @@ void write_page(uint16_t address, uint16_t words[SPM_PAGESIZE / 2]); int main(void) { - delay(100); // milliseconds + pinsOff(0xFF); // pull down all pins + outputs(0xFF); // all to ground - force usb disconnect + delay(250); // milliseconds + inputs(0xFF); // let them float + delay(250); cli(); secure_interrupt_vector_table(); // reset our vector table to it's original state @@ -58,7 +62,7 @@ void secure_interrupt_vector_table(void) { // wipe out any interrupt hooks the bootloader rewrote int i = 0; - while (i < 15) { + while (i < SPM_PAGESIZE / 2) { table[0] = 0xFFFF; i++; } @@ -140,6 +144,7 @@ void write_page(uint16_t address, uint16_t words[SPM_PAGESIZE / 2]) { // beep for a quarter of a second void beep(void) { outputs(pin(0) | pin(1)); + pinOff(1); byte i = 0; while (i < 250) { @@ -151,15 +156,12 @@ void beep(void) { } } + ////////////// Add padding to start of program so no program code could reasonably be erased while program is running // this never needs to be called - avr-gcc stuff happening: http://www.nongnu.org/avr-libc/user-manual/mem_sections.html -void PadStartOfProgram (void) __attribute__ ((naked)) __attribute__ ((section (".init0"))); -void PushMagicWord (void) { - // 32 words of nop - a whole page's worth - asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); +volatile void FakeISR (void) __attribute__ ((naked)) __attribute__ ((section (".init0"))); +volatile void FakeISR (void) { + // 16 nops to pad out first section of program + asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); - asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); - asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); } - - -- cgit v1.2.3