Browse Source

Add dkinzer patch to pass reset cause to app in R2
http://code.google.com/p/optiboot/issues/detail?id=66

westfw 12 years ago
parent
commit
ff7e147b73

+ 9 - 3
optiboot/bootloaders/optiboot/optiboot.c

@@ -146,6 +146,7 @@
 /*							  */
 /* Jan 2013						  */
 /* 4.6 WestfW/dkinzer: use autoincrement lpm for read     */
+/* 4.6 WestfW/dkinzer: pass reset cause to app in R2      */
 /* Mar 2012                                               */
 /* 4.5 WestfW: add infrastructure for non-zero UARTS.     */
 /* 4.5 WestfW: fix SIGNATURE_2 for m644 (bad in avr-libc) */
@@ -279,7 +280,7 @@ void watchdogConfig(uint8_t x);
 #ifdef SOFT_UART
 void uartDelay() __attribute__ ((naked));
 #endif
-void appStart() __attribute__ ((naked));
+void appStart(uint8_t rstFlags) __attribute__ ((naked));
 
 /*
  * NRWW memory
@@ -392,7 +393,7 @@ int main(void) {
   // Adaboot no-wait mod
   ch = MCUSR;
   MCUSR = 0;
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
 
 #if LED_START_FLASHES > 0
   // Set up Timer 1 for timeout counter
@@ -755,7 +756,12 @@ void watchdogConfig(uint8_t x) {
   WDTCSR = x;
 }
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+
   watchdogConfig(WATCHDOG_OFF);
   __asm__ __volatile__ (
 #ifdef VIRTUAL_BOOT_PARTITION

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_atmega328.hex

@@ -27,8 +27,8 @@
 :107FA000C00084FD01C0A8958091C6000895E0E658
 :107FB000F0E098E1908380830895EDDF803219F03E
 :107FC00088E0F5DFFFCF84E1DECF1F93182FE3DFDA
-:107FD0001150E9F7F2DF1F91089580E0E8DFEE2706
-:047FE000FF270994DA
+:107FD0001150E9F7F2DF1F910895282E80E0E7DFC6
+:067FE000EE27FF270994C3
 :027FFE00060477
 :0400000300007E007B
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_atmega328.lst

@@ -3,27 +3,27 @@ optiboot_atmega328.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e4  00007e00  00007e00  00000054  2**1
+  0 .text         000001e6  00007e00  00007e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00007ffe  00007ffe  00000238  2**0
+  1 .version      00000002  00007ffe  00007ffe  0000023a  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023c  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000264  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002c1  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c3  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053f  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000557  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000468  00000000  00000000  000006aa  2**0
+  6 .debug_line   00000470  00000000  00000000  000006c2  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b14  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b34  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b94  2**0
+  8 .debug_str    00000131  00000000  00000000  00000bb4  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cbc  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000ce5  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f0f  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f4b  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     7e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     7e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     7e06:	81 ff       	sbrs	r24, 1
     7e08:	e8 d0       	rcall	.+464    	; 0x7fda <appStart>
 
@@ -568,15 +568,18 @@ void getNch(uint8_t count) {
     7fd8:	08 95       	ret
 
 00007fda <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    7fda:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    7fda:	80 e0       	ldi	r24, 0x00	; 0
-    7fdc:	e8 df       	rcall	.-48     	; 0x7fae <watchdogConfig>
+    7fdc:	80 e0       	ldi	r24, 0x00	; 0
+    7fde:	e7 df       	rcall	.-50     	; 0x7fae <watchdogConfig>
   __asm__ __volatile__ (
-    7fde:	ee 27       	eor	r30, r30
-    7fe0:	ff 27       	eor	r31, r31
-    7fe2:	09 94       	ijmp
+    7fe0:	ee 27       	eor	r30, r30
+    7fe2:	ff 27       	eor	r31, r31
+    7fe4:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_atmega328_pro_8MHz.hex

@@ -27,8 +27,8 @@
 :107FA000C00084FD01C0A8958091C6000895E0E658
 :107FB000F0E098E1908380830895EDDF803219F03E
 :107FC00088E0F5DFFFCF84E1DECF1F93182FE3DFDA
-:107FD0001150E9F7F2DF1F91089580E0E8DFEE2706
-:047FE000FF270994DA
+:107FD0001150E9F7F2DF1F910895282E80E0E7DFC6
+:067FE000EE27FF270994C3
 :027FFE00060477
 :0400000300007E007B
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_atmega328_pro_8MHz.lst

@@ -3,27 +3,27 @@ optiboot_atmega328_pro_8MHz.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e4  00007e00  00007e00  00000054  2**1
+  0 .text         000001e6  00007e00  00007e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00007ffe  00007ffe  00000238  2**0
+  1 .version      00000002  00007ffe  00007ffe  0000023a  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023c  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000264  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002c1  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c3  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053f  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000557  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000468  00000000  00000000  000006aa  2**0
+  6 .debug_line   00000470  00000000  00000000  000006c2  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b14  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b34  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b94  2**0
+  8 .debug_str    00000131  00000000  00000000  00000bb4  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cbc  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000ce5  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f0f  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f4b  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     7e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     7e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     7e06:	81 ff       	sbrs	r24, 1
     7e08:	e8 d0       	rcall	.+464    	; 0x7fda <appStart>
 
@@ -568,15 +568,18 @@ void getNch(uint8_t count) {
     7fd8:	08 95       	ret
 
 00007fda <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    7fda:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    7fda:	80 e0       	ldi	r24, 0x00	; 0
-    7fdc:	e8 df       	rcall	.-48     	; 0x7fae <watchdogConfig>
+    7fdc:	80 e0       	ldi	r24, 0x00	; 0
+    7fde:	e7 df       	rcall	.-50     	; 0x7fae <watchdogConfig>
   __asm__ __volatile__ (
-    7fde:	ee 27       	eor	r30, r30
-    7fe0:	ff 27       	eor	r31, r31
-    7fe2:	09 94       	ijmp
+    7fe0:	ee 27       	eor	r30, r30
+    7fe2:	ff 27       	eor	r31, r31
+    7fe4:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_atmega644p.hex

@@ -27,8 +27,8 @@
 :10FDA000C00084FD01C0A8958091C6000895E0E6DA
 :10FDB000F0E098E1908380830895EDDF803219F0C0
 :10FDC00088E0F5DFFFCF84E1DECF1F93182FE3DF5C
-:10FDD0001150E9F7F2DF1F91089580E0E8DFEE2788
-:04FDE000FF2709945C
+:10FDD0001150E9F7F2DF1F910895282E80E0E7DF48
+:06FDE000EE27FF27099445
 :02FFFE000604F7
 :040000030000FC00FD
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_atmega644p.lst

@@ -3,27 +3,27 @@ optiboot_atmega644p.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e4  0000fc00  0000fc00  00000054  2**1
+  0 .text         000001e6  0000fc00  0000fc00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  0000fffe  0000fffe  00000238  2**0
+  1 .version      00000002  0000fffe  0000fffe  0000023a  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023c  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000264  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002c1  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c3  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053f  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000557  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000468  00000000  00000000  000006aa  2**0
+  6 .debug_line   00000470  00000000  00000000  000006c2  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b14  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b34  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b94  2**0
+  8 .debug_str    00000131  00000000  00000000  00000bb4  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cbc  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000ce5  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f0f  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f4b  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     fc02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     fc04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     fc06:	81 ff       	sbrs	r24, 1
     fc08:	e8 d0       	rcall	.+464    	; 0xfdda <appStart>
 
@@ -568,15 +568,18 @@ void getNch(uint8_t count) {
     fdd8:	08 95       	ret
 
 0000fdda <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    fdda:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    fdda:	80 e0       	ldi	r24, 0x00	; 0
-    fddc:	e8 df       	rcall	.-48     	; 0xfdae <watchdogConfig>
+    fddc:	80 e0       	ldi	r24, 0x00	; 0
+    fdde:	e7 df       	rcall	.-50     	; 0xfdae <watchdogConfig>
   __asm__ __volatile__ (
-    fdde:	ee 27       	eor	r30, r30
-    fde0:	ff 27       	eor	r31, r31
-    fde2:	09 94       	ijmp
+    fde0:	ee 27       	eor	r30, r30
+    fde2:	ff 27       	eor	r31, r31
+    fde4:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_lilypad.hex

@@ -27,8 +27,8 @@
 :103FA00084FD01C0A8958091C6000895E0E6F0E088
 :103FB00098E1908380830895EDDF803219F088E0E6
 :103FC000F5DFFFCF84E1DECF1F93182FE3DF115021
-:103FD000E9F7F2DF1F91089580E0E8DFEE27FF2781
-:023FE000099442
+:103FD000E9F7F2DF1F910895282E80E0E7DFEE2752
+:043FE000FF2709941A
 :023FFE000604B7
 :0400000300003E00BB
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_lilypad.lst

@@ -3,27 +3,27 @@ optiboot_lilypad.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e2  00003e00  00003e00  00000054  2**1
+  0 .text         000001e4  00003e00  00003e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00003ffe  00003ffe  00000236  2**0
+  1 .version      00000002  00003ffe  00003ffe  00000238  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  00000238  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000260  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002bf  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053d  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000555  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000460  00000000  00000000  000006a8  2**0
+  6 .debug_line   00000468  00000000  00000000  000006c0  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b08  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b28  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b88  2**0
+  8 .debug_str    00000131  00000000  00000000  00000ba8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cb0  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000cd9  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f03  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f3f  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     3e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     3e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     3e06:	81 ff       	sbrs	r24, 1
     3e08:	e7 d0       	rcall	.+462    	; 0x3fd8 <appStart>
 
@@ -567,15 +567,18 @@ void getNch(uint8_t count) {
     3fd6:	08 95       	ret
 
 00003fd8 <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    3fd8:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    3fd8:	80 e0       	ldi	r24, 0x00	; 0
-    3fda:	e8 df       	rcall	.-48     	; 0x3fac <watchdogConfig>
+    3fda:	80 e0       	ldi	r24, 0x00	; 0
+    3fdc:	e7 df       	rcall	.-50     	; 0x3fac <watchdogConfig>
   __asm__ __volatile__ (
-    3fdc:	ee 27       	eor	r30, r30
-    3fde:	ff 27       	eor	r31, r31
-    3fe0:	09 94       	ijmp
+    3fde:	ee 27       	eor	r30, r30
+    3fe0:	ff 27       	eor	r31, r31
+    3fe2:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_lilypad_resonator.hex

@@ -27,8 +27,8 @@
 :103FA00084FD01C0A8958091C6000895E0E6F0E088
 :103FB00098E1908380830895EDDF803219F088E0E6
 :103FC000F5DFFFCF84E1DECF1F93182FE3DF115021
-:103FD000E9F7F2DF1F91089580E0E8DFEE27FF2781
-:023FE000099442
+:103FD000E9F7F2DF1F910895282E80E0E7DFEE2752
+:043FE000FF2709941A
 :023FFE000604B7
 :0400000300003E00BB
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_lilypad_resonator.lst

@@ -3,27 +3,27 @@ optiboot_lilypad_resonator.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e2  00003e00  00003e00  00000054  2**1
+  0 .text         000001e4  00003e00  00003e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00003ffe  00003ffe  00000236  2**0
+  1 .version      00000002  00003ffe  00003ffe  00000238  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  00000238  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000260  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002bf  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053d  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000555  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000460  00000000  00000000  000006a8  2**0
+  6 .debug_line   00000468  00000000  00000000  000006c0  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b08  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b28  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b88  2**0
+  8 .debug_str    00000131  00000000  00000000  00000ba8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cb0  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000cd9  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f03  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f3f  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     3e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     3e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     3e06:	81 ff       	sbrs	r24, 1
     3e08:	e7 d0       	rcall	.+462    	; 0x3fd8 <appStart>
 
@@ -567,15 +567,18 @@ void getNch(uint8_t count) {
     3fd6:	08 95       	ret
 
 00003fd8 <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    3fd8:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    3fd8:	80 e0       	ldi	r24, 0x00	; 0
-    3fda:	e8 df       	rcall	.-48     	; 0x3fac <watchdogConfig>
+    3fda:	80 e0       	ldi	r24, 0x00	; 0
+    3fdc:	e7 df       	rcall	.-50     	; 0x3fac <watchdogConfig>
   __asm__ __volatile__ (
-    3fdc:	ee 27       	eor	r30, r30
-    3fde:	ff 27       	eor	r31, r31
-    3fe0:	09 94       	ijmp
+    3fde:	ee 27       	eor	r30, r30
+    3fe0:	ff 27       	eor	r31, r31
+    3fe2:	09 94       	ijmp

+ 2 - 1
optiboot/bootloaders/optiboot/optiboot_luminet.hex

@@ -35,7 +35,8 @@
 :101F20008795F7CF08959EE09A95F1F7089598E187
 :101F300091BD81BD0895E8DF803219F088E0F7DFB8
 :101F4000FFCF84E1D2CF1F93182FDEDF1150E9F7C6
-:101F5000F2DF1F91089580E0EADFE4E0FF270994B3
+:101F5000F2DF1F910895282E80E0E9DFE4E0FF27FB
+:021F60000994E2
 :021EFE000604D8
 :0400000300001D00DC
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_luminet.lst

@@ -3,27 +3,27 @@ optiboot_luminet.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         00000260  00001d00  00001d00  00000054  2**1
+  0 .text         00000262  00001d00  00001d00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00001efe  00001efe  000002b4  2**0
+  1 .version      00000002  00001efe  00001efe  000002b6  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  000002b6  2**0
+  2 .debug_aranges 00000028  00000000  00000000  000002b8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000006d  00000000  00000000  000002de  2**0
+  3 .debug_pubnames 0000006d  00000000  00000000  000002e0  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   000002bc  00000000  00000000  0000034b  2**0
+  4 .debug_info   000002d2  00000000  00000000  0000034d  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 00000176  00000000  00000000  00000607  2**0
+  5 .debug_abbrev 00000176  00000000  00000000  0000061f  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   000004b8  00000000  00000000  0000077d  2**0
+  6 .debug_line   000004c0  00000000  00000000  00000795  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000090  00000000  00000000  00000c38  2**2
+  7 .debug_frame  00000090  00000000  00000000  00000c58  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000149  00000000  00000000  00000cc8  2**0
+  8 .debug_str    00000152  00000000  00000000  00000ce8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    000002a1  00000000  00000000  00000e11  2**0
+  9 .debug_loc    000002b4  00000000  00000000  00000e3a  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000098  00000000  00000000  000010b2  2**0
+ 10 .debug_ranges 00000098  00000000  00000000  000010ee  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     1d02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     1d04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     1d06:	81 ff       	sbrs	r24, 1
     1d08:	26 d1       	rcall	.+588    	; 0x1f56 <appStart>
 
@@ -641,15 +641,18 @@ void getNch(uint8_t count) {
     1f54:	08 95       	ret
 
 00001f56 <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    1f56:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    1f56:	80 e0       	ldi	r24, 0x00	; 0
-    1f58:	ea df       	rcall	.-44     	; 0x1f2e <watchdogConfig>
+    1f58:	80 e0       	ldi	r24, 0x00	; 0
+    1f5a:	e9 df       	rcall	.-46     	; 0x1f2e <watchdogConfig>
   __asm__ __volatile__ (
-    1f5a:	e4 e0       	ldi	r30, 0x04	; 4
-    1f5c:	ff 27       	eor	r31, r31
-    1f5e:	09 94       	ijmp
+    1f5c:	e4 e0       	ldi	r30, 0x04	; 4
+    1f5e:	ff 27       	eor	r31, r31
+    1f60:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_pro_16MHz.hex

@@ -27,8 +27,8 @@
 :103FA00084FD01C0A8958091C6000895E0E6F0E088
 :103FB00098E1908380830895EDDF803219F088E0E6
 :103FC000F5DFFFCF84E1DECF1F93182FE3DF115021
-:103FD000E9F7F2DF1F91089580E0E8DFEE27FF2781
-:023FE000099442
+:103FD000E9F7F2DF1F910895282E80E0E7DFEE2752
+:043FE000FF2709941A
 :023FFE000604B7
 :0400000300003E00BB
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_pro_16MHz.lst

@@ -3,27 +3,27 @@ optiboot_pro_16MHz.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e2  00003e00  00003e00  00000054  2**1
+  0 .text         000001e4  00003e00  00003e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00003ffe  00003ffe  00000236  2**0
+  1 .version      00000002  00003ffe  00003ffe  00000238  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  00000238  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000260  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002bf  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053d  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000555  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000460  00000000  00000000  000006a8  2**0
+  6 .debug_line   00000468  00000000  00000000  000006c0  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b08  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b28  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b88  2**0
+  8 .debug_str    00000131  00000000  00000000  00000ba8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cb0  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000cd9  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f03  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f3f  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     3e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     3e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     3e06:	81 ff       	sbrs	r24, 1
     3e08:	e7 d0       	rcall	.+462    	; 0x3fd8 <appStart>
 
@@ -567,15 +567,18 @@ void getNch(uint8_t count) {
     3fd6:	08 95       	ret
 
 00003fd8 <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    3fd8:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    3fd8:	80 e0       	ldi	r24, 0x00	; 0
-    3fda:	e8 df       	rcall	.-48     	; 0x3fac <watchdogConfig>
+    3fda:	80 e0       	ldi	r24, 0x00	; 0
+    3fdc:	e7 df       	rcall	.-50     	; 0x3fac <watchdogConfig>
   __asm__ __volatile__ (
-    3fdc:	ee 27       	eor	r30, r30
-    3fde:	ff 27       	eor	r31, r31
-    3fe0:	09 94       	ijmp
+    3fde:	ee 27       	eor	r30, r30
+    3fe0:	ff 27       	eor	r31, r31
+    3fe2:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_pro_20mhz.hex

@@ -27,8 +27,8 @@
 :103FA00084FD01C0A8958091C6000895E0E6F0E088
 :103FB00098E1908380830895EDDF803219F088E0E6
 :103FC000F5DFFFCF84E1DECF1F93182FE3DF115021
-:103FD000E9F7F2DF1F91089580E0E8DFEE27FF2781
-:023FE000099442
+:103FD000E9F7F2DF1F910895282E80E0E7DFEE2752
+:043FE000FF2709941A
 :023FFE000604B7
 :0400000300003E00BB
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_pro_20mhz.lst

@@ -3,27 +3,27 @@ optiboot_pro_20mhz.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e2  00003e00  00003e00  00000054  2**1
+  0 .text         000001e4  00003e00  00003e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00003ffe  00003ffe  00000236  2**0
+  1 .version      00000002  00003ffe  00003ffe  00000238  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  00000238  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000260  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002bf  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053d  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000555  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000460  00000000  00000000  000006a8  2**0
+  6 .debug_line   00000468  00000000  00000000  000006c0  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b08  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b28  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b88  2**0
+  8 .debug_str    00000131  00000000  00000000  00000ba8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cb0  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000cd9  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f03  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f3f  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     3e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     3e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     3e06:	81 ff       	sbrs	r24, 1
     3e08:	e7 d0       	rcall	.+462    	; 0x3fd8 <appStart>
 
@@ -567,15 +567,18 @@ void getNch(uint8_t count) {
     3fd6:	08 95       	ret
 
 00003fd8 <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    3fd8:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    3fd8:	80 e0       	ldi	r24, 0x00	; 0
-    3fda:	e8 df       	rcall	.-48     	; 0x3fac <watchdogConfig>
+    3fda:	80 e0       	ldi	r24, 0x00	; 0
+    3fdc:	e7 df       	rcall	.-50     	; 0x3fac <watchdogConfig>
   __asm__ __volatile__ (
-    3fdc:	ee 27       	eor	r30, r30
-    3fde:	ff 27       	eor	r31, r31
-    3fe0:	09 94       	ijmp
+    3fde:	ee 27       	eor	r30, r30
+    3fe0:	ff 27       	eor	r31, r31
+    3fe2:	09 94       	ijmp

+ 2 - 2
optiboot/bootloaders/optiboot/optiboot_pro_8MHz.hex

@@ -27,8 +27,8 @@
 :103FA00084FD01C0A8958091C6000895E0E6F0E088
 :103FB00098E1908380830895EDDF803219F088E0E6
 :103FC000F5DFFFCF84E1DECF1F93182FE3DF115021
-:103FD000E9F7F2DF1F91089580E0E8DFEE27FF2781
-:023FE000099442
+:103FD000E9F7F2DF1F910895282E80E0E7DFEE2752
+:043FE000FF2709941A
 :023FFE000604B7
 :0400000300003E00BB
 :00000001FF

+ 24 - 21
optiboot/bootloaders/optiboot/optiboot_pro_8MHz.lst

@@ -3,27 +3,27 @@ optiboot_pro_8MHz.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001e2  00003e00  00003e00  00000054  2**1
+  0 .text         000001e4  00003e00  00003e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .version      00000002  00003ffe  00003ffe  00000236  2**0
+  1 .version      00000002  00003ffe  00003ffe  00000238  2**0
                   CONTENTS, READONLY
-  2 .debug_aranges 00000028  00000000  00000000  00000238  2**0
+  2 .debug_aranges 00000028  00000000  00000000  0000023a  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_pubnames 0000005f  00000000  00000000  00000260  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000262  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_info   0000027e  00000000  00000000  000002bf  2**0
+  4 .debug_info   00000294  00000000  00000000  000002c1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_abbrev 0000016b  00000000  00000000  0000053d  2**0
+  5 .debug_abbrev 0000016b  00000000  00000000  00000555  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_line   00000460  00000000  00000000  000006a8  2**0
+  6 .debug_line   00000468  00000000  00000000  000006c0  2**0
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_frame  00000080  00000000  00000000  00000b08  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b28  2**2
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_str    00000128  00000000  00000000  00000b88  2**0
+  8 .debug_str    00000131  00000000  00000000  00000ba8  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_loc    00000253  00000000  00000000  00000cb0  2**0
+  9 .debug_loc    00000266  00000000  00000000  00000cd9  2**0
                   CONTENTS, READONLY, DEBUGGING
- 10 .debug_ranges 00000078  00000000  00000000  00000f03  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000f3f  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -45,7 +45,7 @@ int main(void) {
     3e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
     3e04:	14 be       	out	0x34, r1	; 52
-  if (!(ch & _BV(EXTRF))) appStart();
+  if (!(ch & _BV(EXTRF))) appStart(ch);
     3e06:	81 ff       	sbrs	r24, 1
     3e08:	e7 d0       	rcall	.+462    	; 0x3fd8 <appStart>
 
@@ -567,15 +567,18 @@ void getNch(uint8_t count) {
     3fd6:	08 95       	ret
 
 00003fd8 <appStart>:
-  WDTCSR = _BV(WDCE) | _BV(WDE);
-  WDTCSR = x;
-}
 
-void appStart() {
+void appStart(uint8_t rstFlags) {
+  // save the reset flags in the designated register
+  //  This can be saved in a main program by putting code in .init0 (which
+  //  executes before normal c init code) to save R2 to a global variable.
+  __asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
+    3fd8:	28 2e       	mov	r2, r24
+
   watchdogConfig(WATCHDOG_OFF);
-    3fd8:	80 e0       	ldi	r24, 0x00	; 0
-    3fda:	e8 df       	rcall	.-48     	; 0x3fac <watchdogConfig>
+    3fda:	80 e0       	ldi	r24, 0x00	; 0
+    3fdc:	e7 df       	rcall	.-50     	; 0x3fac <watchdogConfig>
   __asm__ __volatile__ (
-    3fdc:	ee 27       	eor	r30, r30
-    3fde:	ff 27       	eor	r31, r31
-    3fe0:	09 94       	ijmp
+    3fde:	ee 27       	eor	r30, r30
+    3fe0:	ff 27       	eor	r31, r31
+    3fe2:	09 94       	ijmp