Browse Source

Issue 47: remove the automatic setting of SOFT_UART
also commit the "diecimila" .hex and .lst files, which are still
old in the repository.

Bill Westfield 13 years ago
parent
commit
856ae041e6

+ 20 - 0
optiboot/bootloaders/optiboot/optiboot.c

@@ -132,6 +132,11 @@
 /**********************************************************/
 /* Edit History:					  */
 /*							  */
+/* 4.4 WestfW: remove automatic soft_uart detect (didn't  */
+/*             know what it was doing or why.)  Added a   */
+/*             check of the calculated BRG value instead. */
+/*             Version stays 4.4; existing binaries are   */
+/*             not changed.                               */
 /* 4.4 WestfW: add initialization of address to keep      */
 /*             the compiler happy.  Change SC'ed targets. */
 /*             Return the SW version via READ PARAM       */
@@ -188,12 +193,27 @@ asm("  .section .version\n"
 #endif
 #endif
 
+#if 0
 /* Switch in soft UART for hard baud rates */
+/*
+ * I don't understand what this was supposed to accomplish, where the
+ * constant "280" came from, or why automatically (and perhaps unexpectedly)
+ * switching to a soft uart is a good thing, so I'm undoing this in favor
+ * of a range check using the same calc used to config the BRG...
+ */
 #if (F_CPU/BAUD_RATE) > 280 // > 57600 for 16MHz
 #ifndef SOFT_UART
 #define SOFT_UART
 #endif
 #endif
+#else // 0
+#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
+#error Unachievable baud rate (too slow) BAUD_RATE 
+#endif // baud rate slow check
+#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
+#error Unachievable baud rate (too fast) BAUD_RATE 
+#endif // baud rate fastn check
+#endif
 
 /* Watchdog settings */
 #define WATCHDOG_OFF    (0)

+ 0 - 34
optiboot/bootloaders/optiboot/optiboot_diecimila.hex

@@ -1,34 +0,0 @@
-:103E000084B714BE81FFE6D085E08093810082E014
-:103E10008093C00088E18093C10086E08093C20057
-:103E200080E18093C4008EE0CFD0259A86E020E325
-:103E30003CEF91E0309385002093840096BBB09BCB
-:103E4000FECF1D9AA8958150A9F7DD24D394A5E053
-:103E5000EA2EF1E1FF2EABD0813421F481E0C5D010
-:103E600083E020C0823411F484E103C0853419F466
-:103E700085E0BBD091C0853581F499D0082F10E042
-:103E800096D090E0982F8827802B912B880F991F30
-:103E900090930102809300027EC0863529F484E06D
-:103EA000A4D080E07CD078C0843609F04EC087D0A2
-:103EB000E0910002F091010288E3E030F80718F485
-:103EC00083E087BFE895C0E0D1E071D0899380910D
-:103ED00002028150809302028823B9F7E091000228
-:103EE000F091010288E3E030F80718F083E087BF23
-:103EF000E89575D007B600FCFDCF409100025091C7
-:103F00000102A0E0B1E02C9130E011968C91119764
-:103F100090E0982F8827822B932B1296FA010C01A0
-:103F2000D7BEE89511244E5F5F4FF1E0A038BF0780
-:103F300051F7E0910002F0910102E7BEE89507B663
-:103F400000FCFDCFF7BEE89527C08437B9F437D021
-:103F500046D0E0910002F09101023196F093010207
-:103F6000E09300023197E4918E2F19D080910202E4
-:103F7000815080930202882361F70EC0853739F49F
-:103F80002ED08EE10CD084E90AD086E08BCF81352B
-:103F900011F488E019D023D080E101D05CCF982FB4
-:103FA0008091C00085FFFCCF9093C6000895A8952E
-:103FB0008091C00087FFFCCF8091C6000895F7DF95
-:103FC000F6DF80930202F3CFE0E6F0E098E1908321
-:103FD0008083089580E0F8DFEE27FF270994E7DF6C
-:103FE000803209F0F7DF84E1DACF1F93182FDFDF8B
-:0A3FF0001150E9F7F4DF1F91089566
-:0400000300003E00BB
-:00000001FF

+ 308 - 262
optiboot/bootloaders/optiboot/optiboot_diecimila.lst

@@ -3,25 +3,27 @@ optiboot_diecimila.elf:     file format elf32-avr
 
 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
-  0 .text         000001fa  00003e00  00003e00  00000054  2**1
+  0 .text         000001f4  00003e00  00003e00  00000054  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
-  1 .debug_aranges 00000028  00000000  00000000  0000024e  2**0
+  1 .version      00000002  00003ffe  00003ffe  00000248  2**0
+                  CONTENTS, READONLY
+  2 .debug_aranges 00000028  00000000  00000000  0000024a  2**0
                   CONTENTS, READONLY, DEBUGGING
-  2 .debug_pubnames 0000006a  00000000  00000000  00000276  2**0
+  3 .debug_pubnames 0000005f  00000000  00000000  00000272  2**0
                   CONTENTS, READONLY, DEBUGGING
-  3 .debug_info   00000284  00000000  00000000  000002e0  2**0
+  4 .debug_info   000002a8  00000000  00000000  000002d1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  4 .debug_abbrev 000001ae  00000000  00000000  00000564  2**0
+  5 .debug_abbrev 00000178  00000000  00000000  00000579  2**0
                   CONTENTS, READONLY, DEBUGGING
-  5 .debug_line   000003e4  00000000  00000000  00000712  2**0
+  6 .debug_line   0000046b  00000000  00000000  000006f1  2**0
                   CONTENTS, READONLY, DEBUGGING
-  6 .debug_frame  00000090  00000000  00000000  00000af8  2**2
+  7 .debug_frame  00000080  00000000  00000000  00000b5c  2**2
                   CONTENTS, READONLY, DEBUGGING
-  7 .debug_str    00000141  00000000  00000000  00000b88  2**0
+  8 .debug_str    00000143  00000000  00000000  00000bdc  2**0
                   CONTENTS, READONLY, DEBUGGING
-  8 .debug_loc    000001e1  00000000  00000000  00000cc9  2**0
+  9 .debug_loc    000002d8  00000000  00000000  00000d1f  2**0
                   CONTENTS, READONLY, DEBUGGING
-  9 .debug_ranges 00000068  00000000  00000000  00000eaa  2**0
+ 10 .debug_ranges 00000078  00000000  00000000  00000ff7  2**0
                   CONTENTS, READONLY, DEBUGGING
 
 Disassembly of section .text:
@@ -33,266 +35,293 @@ Disassembly of section .text:
 
 /* main program starts here */
 int main(void) {
-    3e00:	84 b7       	in	r24, 0x34	; 52
-
-  uint8_t ch;
+    3e00:	11 24       	eor	r1, r1
+#ifdef __AVR_ATmega8__
+  SP=RAMEND;  // This is done by hardware reset
+#endif
 
   // Adaboot no-wait mod
   ch = MCUSR;
+    3e02:	84 b7       	in	r24, 0x34	; 52
   MCUSR = 0;
-    3e02:	14 be       	out	0x34, r1	; 52
+    3e04:	14 be       	out	0x34, r1	; 52
   if (!(ch & _BV(EXTRF))) appStart();
-    3e04:	81 ff       	sbrs	r24, 1
-    3e06:	e6 d0       	rcall	.+460    	; 0x3fd4 <appStart>
+    3e06:	81 ff       	sbrs	r24, 1
+    3e08:	f0 d0       	rcall	.+480    	; 0x3fea <appStart>
 
 #if LED_START_FLASHES > 0
   // Set up Timer 1 for timeout counter
   TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
-    3e08:	85 e0       	ldi	r24, 0x05	; 5
-    3e0a:	80 93 81 00 	sts	0x0081, r24
+    3e0a:	85 e0       	ldi	r24, 0x05	; 5
+    3e0c:	80 93 81 00 	sts	0x0081, r24
   UCSRA = _BV(U2X); //Double speed mode USART
   UCSRB = _BV(RXEN) | _BV(TXEN);  // enable Rx & Tx
   UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);  // config USART; 8N1
   UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
 #else
   UCSR0A = _BV(U2X0); //Double speed mode USART0
-    3e0e:	82 e0       	ldi	r24, 0x02	; 2
-    3e10:	80 93 c0 00 	sts	0x00C0, r24
+    3e10:	82 e0       	ldi	r24, 0x02	; 2
+    3e12:	80 93 c0 00 	sts	0x00C0, r24
   UCSR0B = _BV(RXEN0) | _BV(TXEN0);
-    3e14:	88 e1       	ldi	r24, 0x18	; 24
-    3e16:	80 93 c1 00 	sts	0x00C1, r24
+    3e16:	88 e1       	ldi	r24, 0x18	; 24
+    3e18:	80 93 c1 00 	sts	0x00C1, r24
   UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
-    3e1a:	86 e0       	ldi	r24, 0x06	; 6
-    3e1c:	80 93 c2 00 	sts	0x00C2, r24
+    3e1c:	86 e0       	ldi	r24, 0x06	; 6
+    3e1e:	80 93 c2 00 	sts	0x00C2, r24
   UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
-    3e20:	80 e1       	ldi	r24, 0x10	; 16
-    3e22:	80 93 c4 00 	sts	0x00C4, r24
+    3e22:	80 e1       	ldi	r24, 0x10	; 16
+    3e24:	80 93 c4 00 	sts	0x00C4, r24
 #endif
 #endif
 
   // Set up watchdog to trigger after 500ms
   watchdogConfig(WATCHDOG_1S);
-    3e26:	8e e0       	ldi	r24, 0x0E	; 14
-    3e28:	cf d0       	rcall	.+414    	; 0x3fc8 <watchdogConfig>
+    3e28:	8e e0       	ldi	r24, 0x0E	; 14
+    3e2a:	c9 d0       	rcall	.+402    	; 0x3fbe <watchdogConfig>
 
   /* Set LED pin as output */
   LED_DDR |= _BV(LED);
-    3e2a:	25 9a       	sbi	0x04, 5	; 4
-    3e2c:	86 e0       	ldi	r24, 0x06	; 6
+    3e2c:	25 9a       	sbi	0x04, 5	; 4
+    3e2e:	86 e0       	ldi	r24, 0x06	; 6
 }
 
 #if LED_START_FLASHES > 0
 void flash_led(uint8_t count) {
   do {
     TCNT1 = -(F_CPU/(1024*16));
-    3e2e:	20 e3       	ldi	r18, 0x30	; 48
-    3e30:	3c ef       	ldi	r19, 0xFC	; 252
+    3e30:	20 e3       	ldi	r18, 0x30	; 48
+    3e32:	3c ef       	ldi	r19, 0xFC	; 252
     TIFR1 = _BV(TOV1);
-    3e32:	91 e0       	ldi	r25, 0x01	; 1
+    3e34:	91 e0       	ldi	r25, 0x01	; 1
 }
 
 #if LED_START_FLASHES > 0
 void flash_led(uint8_t count) {
   do {
     TCNT1 = -(F_CPU/(1024*16));
-    3e34:	30 93 85 00 	sts	0x0085, r19
-    3e38:	20 93 84 00 	sts	0x0084, r18
+    3e36:	30 93 85 00 	sts	0x0085, r19
+    3e3a:	20 93 84 00 	sts	0x0084, r18
     TIFR1 = _BV(TOV1);
-    3e3c:	96 bb       	out	0x16, r25	; 22
+    3e3e:	96 bb       	out	0x16, r25	; 22
     while(!(TIFR1 & _BV(TOV1)));
-    3e3e:	b0 9b       	sbis	0x16, 0	; 22
-    3e40:	fe cf       	rjmp	.-4      	; 0x3e3e <main+0x3e>
+    3e40:	b0 9b       	sbis	0x16, 0	; 22
+    3e42:	fe cf       	rjmp	.-4      	; 0x3e40 <main+0x40>
 #ifdef __AVR_ATmega8__
     LED_PORT ^= _BV(LED);
 #else
     LED_PIN |= _BV(LED);
-    3e42:	1d 9a       	sbi	0x03, 5	; 3
-  return getch();
+    3e44:	1d 9a       	sbi	0x03, 5	; 3
 }
+#endif
 
 // Watchdog functions. These are only safe with interrupts turned off.
 void watchdogReset() {
   __asm__ __volatile__ (
-    3e44:	a8 95       	wdr
+    3e46:	a8 95       	wdr
     LED_PORT ^= _BV(LED);
 #else
     LED_PIN |= _BV(LED);
 #endif
     watchdogReset();
   } while (--count);
-    3e46:	81 50       	subi	r24, 0x01	; 1
-    3e48:	a9 f7       	brne	.-22     	; 0x3e34 <main+0x34>
-    /* get character from UART */
-    ch = getch();
-
-    if(ch == STK_GET_PARAMETER) {
-      // GET PARAMETER returns a generic 0x03 reply - enough to keep Avrdude happy
-      getNch(1);
-    3e4a:	dd 24       	eor	r13, r13
-    3e4c:	d3 94       	inc	r13
+    3e48:	81 50       	subi	r24, 0x01	; 1
+    3e4a:	a9 f7       	brne	.-22     	; 0x3e36 <main+0x36>
+    3e4c:	cc 24       	eor	r12, r12
+    3e4e:	dd 24       	eor	r13, r13
+      ch = SPM_PAGESIZE / 2;
+      do {
+        uint16_t a;
+        a = *bufPtr++;
+        a |= (*bufPtr++) << 8;
         __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
+    3e50:	88 24       	eor	r8, r8
+    3e52:	83 94       	inc	r8
         addrPtr += 2;
       } while (--ch);
-      
+
       // Write from programming buffer
       __boot_page_write_short((uint16_t)(void*)address);
-    3e4e:	a5 e0       	ldi	r26, 0x05	; 5
-    3e50:	ea 2e       	mov	r14, r26
+    3e54:	b5 e0       	ldi	r27, 0x05	; 5
+    3e56:	ab 2e       	mov	r10, r27
       boot_spm_busy_wait();
 
 #if defined(RWWSRE)
       // Reenable read access to flash
       boot_rww_enable();
-    3e52:	f1 e1       	ldi	r31, 0x11	; 17
-    3e54:	ff 2e       	mov	r15, r31
+    3e58:	a1 e1       	ldi	r26, 0x11	; 17
+    3e5a:	9a 2e       	mov	r9, r26
+      do *bufPtr++ = getch();
+      while (--length);
+
+      // If we are in NRWW section, page erase has to be delayed until now.
+      // Todo: Take RAMPZ into account
+      if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
+    3e5c:	f3 e0       	ldi	r31, 0x03	; 3
+    3e5e:	bf 2e       	mov	r11, r31
 #endif
 
   /* Forever loop */
   for (;;) {
     /* get character from UART */
     ch = getch();
-    3e56:	ab d0       	rcall	.+342    	; 0x3fae <getch>
+    3e60:	a2 d0       	rcall	.+324    	; 0x3fa6 <getch>
 
     if(ch == STK_GET_PARAMETER) {
-    3e58:	81 34       	cpi	r24, 0x41	; 65
-    3e5a:	21 f4       	brne	.+8      	; 0x3e64 <main+0x64>
-      // GET PARAMETER returns a generic 0x03 reply - enough to keep Avrdude happy
-      getNch(1);
-    3e5c:	81 e0       	ldi	r24, 0x01	; 1
-    3e5e:	c5 d0       	rcall	.+394    	; 0x3fea <getNch>
-      putch(0x03);
-    3e60:	83 e0       	ldi	r24, 0x03	; 3
-    3e62:	20 c0       	rjmp	.+64     	; 0x3ea4 <main+0xa4>
+    3e62:	81 34       	cpi	r24, 0x41	; 65
+    3e64:	61 f4       	brne	.+24     	; 0x3e7e <main+0x7e>
+      unsigned char which = getch();
+    3e66:	9f d0       	rcall	.+318    	; 0x3fa6 <getch>
+    3e68:	08 2f       	mov	r16, r24
+      verifySpace();
+    3e6a:	af d0       	rcall	.+350    	; 0x3fca <verifySpace>
+      if (which == 0x82) {
+    3e6c:	02 38       	cpi	r16, 0x82	; 130
+    3e6e:	11 f0       	breq	.+4      	; 0x3e74 <main+0x74>
+	/*
+	 * Send optiboot version as "minor SW version"
+	 */
+	putch(OPTIBOOT_MINVER);
+      } else if (which == 0x81) {
+    3e70:	01 38       	cpi	r16, 0x81	; 129
+    3e72:	11 f4       	brne	.+4      	; 0x3e78 <main+0x78>
+	  putch(OPTIBOOT_MAJVER);
+    3e74:	84 e0       	ldi	r24, 0x04	; 4
+    3e76:	01 c0       	rjmp	.+2      	; 0x3e7a <main+0x7a>
+      } else {
+	/*
+	 * GET PARAMETER returns a generic 0x03 reply for
+         * other parameters - enough to keep Avrdude happy
+	 */
+	putch(0x03);
+    3e78:	83 e0       	ldi	r24, 0x03	; 3
+    3e7a:	8d d0       	rcall	.+282    	; 0x3f96 <putch>
+    3e7c:	89 c0       	rjmp	.+274    	; 0x3f90 <main+0x190>
+      }
     }
     else if(ch == STK_SET_DEVICE) {
-    3e64:	82 34       	cpi	r24, 0x42	; 66
-    3e66:	11 f4       	brne	.+4      	; 0x3e6c <main+0x6c>
+    3e7e:	82 34       	cpi	r24, 0x42	; 66
+    3e80:	11 f4       	brne	.+4      	; 0x3e86 <main+0x86>
       // SET DEVICE is ignored
       getNch(20);
-    3e68:	84 e1       	ldi	r24, 0x14	; 20
-    3e6a:	03 c0       	rjmp	.+6      	; 0x3e72 <main+0x72>
+    3e82:	84 e1       	ldi	r24, 0x14	; 20
+    3e84:	03 c0       	rjmp	.+6      	; 0x3e8c <main+0x8c>
     }
     else if(ch == STK_SET_DEVICE_EXT) {
-    3e6c:	85 34       	cpi	r24, 0x45	; 69
-    3e6e:	19 f4       	brne	.+6      	; 0x3e76 <main+0x76>
+    3e86:	85 34       	cpi	r24, 0x45	; 69
+    3e88:	19 f4       	brne	.+6      	; 0x3e90 <main+0x90>
       // SET DEVICE EXT is ignored
       getNch(5);
-    3e70:	85 e0       	ldi	r24, 0x05	; 5
-    3e72:	bb d0       	rcall	.+374    	; 0x3fea <getNch>
-    3e74:	91 c0       	rjmp	.+290    	; 0x3f98 <main+0x198>
+    3e8a:	85 e0       	ldi	r24, 0x05	; 5
+    3e8c:	a6 d0       	rcall	.+332    	; 0x3fda <getNch>
+    3e8e:	80 c0       	rjmp	.+256    	; 0x3f90 <main+0x190>
     }
     else if(ch == STK_LOAD_ADDRESS) {
-    3e76:	85 35       	cpi	r24, 0x55	; 85
-    3e78:	81 f4       	brne	.+32     	; 0x3e9a <main+0x9a>
+    3e90:	85 35       	cpi	r24, 0x55	; 85
+    3e92:	79 f4       	brne	.+30     	; 0x3eb2 <main+0xb2>
       // LOAD ADDRESS
       uint16_t newAddress;
       newAddress = getch();
-    3e7a:	99 d0       	rcall	.+306    	; 0x3fae <getch>
+    3e94:	88 d0       	rcall	.+272    	; 0x3fa6 <getch>
       newAddress = (newAddress & 0xff) | (getch() << 8);
-    3e7c:	08 2f       	mov	r16, r24
-    3e7e:	10 e0       	ldi	r17, 0x00	; 0
-    3e80:	96 d0       	rcall	.+300    	; 0x3fae <getch>
-    3e82:	90 e0       	ldi	r25, 0x00	; 0
-    3e84:	98 2f       	mov	r25, r24
-    3e86:	88 27       	eor	r24, r24
-    3e88:	80 2b       	or	r24, r16
-    3e8a:	91 2b       	or	r25, r17
+    3e96:	e8 2e       	mov	r14, r24
+    3e98:	ff 24       	eor	r15, r15
+    3e9a:	85 d0       	rcall	.+266    	; 0x3fa6 <getch>
+    3e9c:	08 2f       	mov	r16, r24
+    3e9e:	10 e0       	ldi	r17, 0x00	; 0
+    3ea0:	10 2f       	mov	r17, r16
+    3ea2:	00 27       	eor	r16, r16
+    3ea4:	0e 29       	or	r16, r14
+    3ea6:	1f 29       	or	r17, r15
 #ifdef RAMPZ
       // Transfer top bit to RAMPZ
       RAMPZ = (newAddress & 0x8000) ? 1 : 0;
 #endif
       newAddress += newAddress; // Convert from word address to byte address
-    3e8c:	88 0f       	add	r24, r24
-    3e8e:	99 1f       	adc	r25, r25
+    3ea8:	00 0f       	add	r16, r16
+    3eaa:	11 1f       	adc	r17, r17
       address = newAddress;
-    3e90:	90 93 01 02 	sts	0x0201, r25
-    3e94:	80 93 00 02 	sts	0x0200, r24
-    3e98:	7e c0       	rjmp	.+252    	; 0x3f96 <main+0x196>
       verifySpace();
+    3eac:	8e d0       	rcall	.+284    	; 0x3fca <verifySpace>
+    3eae:	68 01       	movw	r12, r16
+    3eb0:	6f c0       	rjmp	.+222    	; 0x3f90 <main+0x190>
     }
     else if(ch == STK_UNIVERSAL) {
-    3e9a:	86 35       	cpi	r24, 0x56	; 86
-    3e9c:	29 f4       	brne	.+10     	; 0x3ea8 <main+0xa8>
+    3eb2:	86 35       	cpi	r24, 0x56	; 86
+    3eb4:	21 f4       	brne	.+8      	; 0x3ebe <main+0xbe>
       // UNIVERSAL command is ignored
       getNch(4);
-    3e9e:	84 e0       	ldi	r24, 0x04	; 4
-    3ea0:	a4 d0       	rcall	.+328    	; 0x3fea <getNch>
+    3eb6:	84 e0       	ldi	r24, 0x04	; 4
+    3eb8:	90 d0       	rcall	.+288    	; 0x3fda <getNch>
       putch(0x00);
-    3ea2:	80 e0       	ldi	r24, 0x00	; 0
-    3ea4:	7c d0       	rcall	.+248    	; 0x3f9e <putch>
-    3ea6:	78 c0       	rjmp	.+240    	; 0x3f98 <main+0x198>
+    3eba:	80 e0       	ldi	r24, 0x00	; 0
+    3ebc:	de cf       	rjmp	.-68     	; 0x3e7a <main+0x7a>
     }
     /* Write memory, length is big endian and is in bytes */
     else if(ch == STK_PROG_PAGE) {
-    3ea8:	84 36       	cpi	r24, 0x64	; 100
-    3eaa:	09 f0       	breq	.+2      	; 0x3eae <main+0xae>
-    3eac:	4e c0       	rjmp	.+156    	; 0x3f4a <main+0x14a>
+    3ebe:	84 36       	cpi	r24, 0x64	; 100
+    3ec0:	09 f0       	breq	.+2      	; 0x3ec4 <main+0xc4>
+    3ec2:	40 c0       	rjmp	.+128    	; 0x3f44 <main+0x144>
       // PROGRAM PAGE - we support flash programming only, not EEPROM
       uint8_t *bufPtr;
       uint16_t addrPtr;
 
-      getLen();
-    3eae:	87 d0       	rcall	.+270    	; 0x3fbe <getLen>
+      getch();			/* getlen() */
+    3ec4:	70 d0       	rcall	.+224    	; 0x3fa6 <getch>
+      length = getch();
+    3ec6:	6f d0       	rcall	.+222    	; 0x3fa6 <getch>
+    3ec8:	08 2f       	mov	r16, r24
+      getch();
+    3eca:	6d d0       	rcall	.+218    	; 0x3fa6 <getch>
 
       // If we are in RWW section, immediately start page erase
       if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
-    3eb0:	e0 91 00 02 	lds	r30, 0x0200
-    3eb4:	f0 91 01 02 	lds	r31, 0x0201
-    3eb8:	88 e3       	ldi	r24, 0x38	; 56
-    3eba:	e0 30       	cpi	r30, 0x00	; 0
-    3ebc:	f8 07       	cpc	r31, r24
-    3ebe:	18 f4       	brcc	.+6      	; 0x3ec6 <main+0xc6>
-    3ec0:	83 e0       	ldi	r24, 0x03	; 3
-    3ec2:	87 bf       	out	0x37, r24	; 55
-    3ec4:	e8 95       	spm
-    3ec6:	c0 e0       	ldi	r28, 0x00	; 0
-    3ec8:	d1 e0       	ldi	r29, 0x01	; 1
-      
+    3ecc:	80 e0       	ldi	r24, 0x00	; 0
+    3ece:	c8 16       	cp	r12, r24
+    3ed0:	88 e3       	ldi	r24, 0x38	; 56
+    3ed2:	d8 06       	cpc	r13, r24
+    3ed4:	18 f4       	brcc	.+6      	; 0x3edc <main+0xdc>
+    3ed6:	f6 01       	movw	r30, r12
+    3ed8:	b7 be       	out	0x37, r11	; 55
+    3eda:	e8 95       	spm
+    3edc:	c0 e0       	ldi	r28, 0x00	; 0
+    3ede:	d1 e0       	ldi	r29, 0x01	; 1
+
       // While that is going on, read in page contents
       bufPtr = buff;
       do *bufPtr++ = getch();
-    3eca:	71 d0       	rcall	.+226    	; 0x3fae <getch>
-    3ecc:	89 93       	st	Y+, r24
+    3ee0:	62 d0       	rcall	.+196    	; 0x3fa6 <getch>
+    3ee2:	89 93       	st	Y+, r24
       while (--length);
-    3ece:	80 91 02 02 	lds	r24, 0x0202
-    3ed2:	81 50       	subi	r24, 0x01	; 1
-    3ed4:	80 93 02 02 	sts	0x0202, r24
-    3ed8:	88 23       	and	r24, r24
-    3eda:	b9 f7       	brne	.-18     	; 0x3eca <main+0xca>
+    3ee4:	0c 17       	cp	r16, r28
+    3ee6:	e1 f7       	brne	.-8      	; 0x3ee0 <main+0xe0>
 
       // If we are in NRWW section, page erase has to be delayed until now.
       // Todo: Take RAMPZ into account
       if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
-    3edc:	e0 91 00 02 	lds	r30, 0x0200
-    3ee0:	f0 91 01 02 	lds	r31, 0x0201
-    3ee4:	88 e3       	ldi	r24, 0x38	; 56
-    3ee6:	e0 30       	cpi	r30, 0x00	; 0
-    3ee8:	f8 07       	cpc	r31, r24
-    3eea:	18 f0       	brcs	.+6      	; 0x3ef2 <main+0xf2>
-    3eec:	83 e0       	ldi	r24, 0x03	; 3
-    3eee:	87 bf       	out	0x37, r24	; 55
-    3ef0:	e8 95       	spm
+    3ee8:	f0 e0       	ldi	r31, 0x00	; 0
+    3eea:	cf 16       	cp	r12, r31
+    3eec:	f8 e3       	ldi	r31, 0x38	; 56
+    3eee:	df 06       	cpc	r13, r31
+    3ef0:	18 f0       	brcs	.+6      	; 0x3ef8 <main+0xf8>
+    3ef2:	f6 01       	movw	r30, r12
+    3ef4:	b7 be       	out	0x37, r11	; 55
+    3ef6:	e8 95       	spm
 
       // Read command terminator, start reply
       verifySpace();
-    3ef2:	75 d0       	rcall	.+234    	; 0x3fde <verifySpace>
-      
+    3ef8:	68 d0       	rcall	.+208    	; 0x3fca <verifySpace>
+
       // If only a partial page is to be programmed, the erase might not be complete.
       // So check that here
       boot_spm_busy_wait();
-    3ef4:	07 b6       	in	r0, 0x37	; 55
-    3ef6:	00 fc       	sbrc	r0, 0
-    3ef8:	fd cf       	rjmp	.-6      	; 0x3ef4 <main+0xf4>
-      }
-#endif
-
-      // Copy buffer into programming buffer
-      bufPtr = buff;
-      addrPtr = (uint16_t)(void*)address;
-    3efa:	40 91 00 02 	lds	r20, 0x0200
-    3efe:	50 91 01 02 	lds	r21, 0x0201
+    3efa:	07 b6       	in	r0, 0x37	; 55
+    3efc:	00 fc       	sbrc	r0, 0
+    3efe:	fd cf       	rjmp	.-6      	; 0x3efa <main+0xfa>
+    3f00:	a6 01       	movw	r20, r12
     3f02:	a0 e0       	ldi	r26, 0x00	; 0
     3f04:	b1 e0       	ldi	r27, 0x01	; 1
+      bufPtr = buff;
+      addrPtr = (uint16_t)(void*)address;
       ch = SPM_PAGESIZE / 2;
       do {
         uint16_t a;
@@ -323,7 +352,7 @@ int main(void) {
         __boot_page_fill_short((uint16_t)(void*)addrPtr,a);
     3f1c:	fa 01       	movw	r30, r20
     3f1e:	0c 01       	movw	r0, r24
-    3f20:	d7 be       	out	0x37, r13	; 55
+    3f20:	87 be       	out	0x37, r8	; 55
     3f22:	e8 95       	spm
     3f24:	11 24       	eor	r1, r1
         addrPtr += 2;
@@ -334,136 +363,159 @@ int main(void) {
     3f2c:	a0 38       	cpi	r26, 0x80	; 128
     3f2e:	bf 07       	cpc	r27, r31
     3f30:	51 f7       	brne	.-44     	; 0x3f06 <main+0x106>
-      
+
       // Write from programming buffer
       __boot_page_write_short((uint16_t)(void*)address);
-    3f32:	e0 91 00 02 	lds	r30, 0x0200
-    3f36:	f0 91 01 02 	lds	r31, 0x0201
-    3f3a:	e7 be       	out	0x37, r14	; 55
-    3f3c:	e8 95       	spm
+    3f32:	f6 01       	movw	r30, r12
+    3f34:	a7 be       	out	0x37, r10	; 55
+    3f36:	e8 95       	spm
       boot_spm_busy_wait();
-    3f3e:	07 b6       	in	r0, 0x37	; 55
-    3f40:	00 fc       	sbrc	r0, 0
-    3f42:	fd cf       	rjmp	.-6      	; 0x3f3e <main+0x13e>
+    3f38:	07 b6       	in	r0, 0x37	; 55
+    3f3a:	00 fc       	sbrc	r0, 0
+    3f3c:	fd cf       	rjmp	.-6      	; 0x3f38 <main+0x138>
 
 #if defined(RWWSRE)
       // Reenable read access to flash
       boot_rww_enable();
-    3f44:	f7 be       	out	0x37, r15	; 55
-    3f46:	e8 95       	spm
-    3f48:	27 c0       	rjmp	.+78     	; 0x3f98 <main+0x198>
+    3f3e:	97 be       	out	0x37, r9	; 55
+    3f40:	e8 95       	spm
+    3f42:	26 c0       	rjmp	.+76     	; 0x3f90 <main+0x190>
 #endif
 
     }
     /* Read memory block mode, length is big endian.  */
     else if(ch == STK_READ_PAGE) {
-    3f4a:	84 37       	cpi	r24, 0x74	; 116
-    3f4c:	b9 f4       	brne	.+46     	; 0x3f7c <main+0x17c>
+    3f44:	84 37       	cpi	r24, 0x74	; 116
+    3f46:	b1 f4       	brne	.+44     	; 0x3f74 <main+0x174>
       // READ PAGE - we only read flash
-      getLen();
-    3f4e:	37 d0       	rcall	.+110    	; 0x3fbe <getLen>
+      getch();			/* getlen() */
+    3f48:	2e d0       	rcall	.+92     	; 0x3fa6 <getch>
+      length = getch();
+    3f4a:	2d d0       	rcall	.+90     	; 0x3fa6 <getch>
+    3f4c:	f8 2e       	mov	r15, r24
+      getch();
+    3f4e:	2b d0       	rcall	.+86     	; 0x3fa6 <getch>
+
       verifySpace();
-    3f50:	46 d0       	rcall	.+140    	; 0x3fde <verifySpace>
+    3f50:	3c d0       	rcall	.+120    	; 0x3fca <verifySpace>
+    3f52:	f6 01       	movw	r30, r12
+    3f54:	ef 2c       	mov	r14, r15
         putch(result);
         address++;
       }
       while (--length);
 #else
       do putch(pgm_read_byte_near(address++));
-    3f52:	e0 91 00 02 	lds	r30, 0x0200
-    3f56:	f0 91 01 02 	lds	r31, 0x0201
-    3f5a:	31 96       	adiw	r30, 0x01	; 1
-    3f5c:	f0 93 01 02 	sts	0x0201, r31
-    3f60:	e0 93 00 02 	sts	0x0200, r30
-    3f64:	31 97       	sbiw	r30, 0x01	; 1
-    3f66:	e4 91       	lpm	r30, Z+
-    3f68:	8e 2f       	mov	r24, r30
-    3f6a:	19 d0       	rcall	.+50     	; 0x3f9e <putch>
+    3f56:	8f 01       	movw	r16, r30
+    3f58:	0f 5f       	subi	r16, 0xFF	; 255
+    3f5a:	1f 4f       	sbci	r17, 0xFF	; 255
+    3f5c:	84 91       	lpm	r24, Z+
+    3f5e:	1b d0       	rcall	.+54     	; 0x3f96 <putch>
       while (--length);
-    3f6c:	80 91 02 02 	lds	r24, 0x0202
-    3f70:	81 50       	subi	r24, 0x01	; 1
-    3f72:	80 93 02 02 	sts	0x0202, r24
-    3f76:	88 23       	and	r24, r24
-    3f78:	61 f7       	brne	.-40     	; 0x3f52 <main+0x152>
-    3f7a:	0e c0       	rjmp	.+28     	; 0x3f98 <main+0x198>
+    3f60:	ea 94       	dec	r14
+    3f62:	f8 01       	movw	r30, r16
+    3f64:	c1 f7       	brne	.-16     	; 0x3f56 <main+0x156>
+#define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
+#define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
+#endif
+
+/* main program starts here */
+int main(void) {
+    3f66:	08 94       	sec
+    3f68:	c1 1c       	adc	r12, r1
+    3f6a:	d1 1c       	adc	r13, r1
+    3f6c:	fa 94       	dec	r15
+    3f6e:	cf 0c       	add	r12, r15
+    3f70:	d1 1c       	adc	r13, r1
+    3f72:	0e c0       	rjmp	.+28     	; 0x3f90 <main+0x190>
 #endif
 #endif
     }
 
     /* Get device signature bytes  */
     else if(ch == STK_READ_SIGN) {
-    3f7c:	85 37       	cpi	r24, 0x75	; 117
-    3f7e:	39 f4       	brne	.+14     	; 0x3f8e <main+0x18e>
+    3f74:	85 37       	cpi	r24, 0x75	; 117
+    3f76:	39 f4       	brne	.+14     	; 0x3f86 <main+0x186>
       // READ SIGN - return what Avrdude wants to hear
       verifySpace();
-    3f80:	2e d0       	rcall	.+92     	; 0x3fde <verifySpace>
+    3f78:	28 d0       	rcall	.+80     	; 0x3fca <verifySpace>
       putch(SIGNATURE_0);
-    3f82:	8e e1       	ldi	r24, 0x1E	; 30
-    3f84:	0c d0       	rcall	.+24     	; 0x3f9e <putch>
+    3f7a:	8e e1       	ldi	r24, 0x1E	; 30
+    3f7c:	0c d0       	rcall	.+24     	; 0x3f96 <putch>
       putch(SIGNATURE_1);
-    3f86:	84 e9       	ldi	r24, 0x94	; 148
-    3f88:	0a d0       	rcall	.+20     	; 0x3f9e <putch>
+    3f7e:	84 e9       	ldi	r24, 0x94	; 148
+    3f80:	0a d0       	rcall	.+20     	; 0x3f96 <putch>
       putch(SIGNATURE_2);
-    3f8a:	86 e0       	ldi	r24, 0x06	; 6
-    3f8c:	8b cf       	rjmp	.-234    	; 0x3ea4 <main+0xa4>
+    3f82:	86 e0       	ldi	r24, 0x06	; 6
+    3f84:	7a cf       	rjmp	.-268    	; 0x3e7a <main+0x7a>
     }
     else if (ch == 'Q') {
-    3f8e:	81 35       	cpi	r24, 0x51	; 81
-    3f90:	11 f4       	brne	.+4      	; 0x3f96 <main+0x196>
+    3f86:	81 35       	cpi	r24, 0x51	; 81
+    3f88:	11 f4       	brne	.+4      	; 0x3f8e <main+0x18e>
       // Adaboot no-wait mod
       watchdogConfig(WATCHDOG_16MS);
-    3f92:	88 e0       	ldi	r24, 0x08	; 8
-    3f94:	19 d0       	rcall	.+50     	; 0x3fc8 <watchdogConfig>
+    3f8a:	88 e0       	ldi	r24, 0x08	; 8
+    3f8c:	18 d0       	rcall	.+48     	; 0x3fbe <watchdogConfig>
       verifySpace();
     }
     else {
       // This covers the response to commands like STK_ENTER_PROGMODE
       verifySpace();
-    3f96:	23 d0       	rcall	.+70     	; 0x3fde <verifySpace>
+    3f8e:	1d d0       	rcall	.+58     	; 0x3fca <verifySpace>
     }
     putch(STK_OK);
-    3f98:	80 e1       	ldi	r24, 0x10	; 16
-    3f9a:	01 d0       	rcall	.+2      	; 0x3f9e <putch>
-    3f9c:	5c cf       	rjmp	.-328    	; 0x3e56 <main+0x56>
+    3f90:	80 e1       	ldi	r24, 0x10	; 16
+    3f92:	01 d0       	rcall	.+2      	; 0x3f96 <putch>
+    3f94:	65 cf       	rjmp	.-310    	; 0x3e60 <main+0x60>
 
-00003f9e <putch>:
+00003f96 <putch>:
   }
 }
 
 void putch(char ch) {
-    3f9e:	98 2f       	mov	r25, r24
+    3f96:	98 2f       	mov	r25, r24
 #ifndef SOFT_UART
   while (!(UCSR0A & _BV(UDRE0)));
-    3fa0:	80 91 c0 00 	lds	r24, 0x00C0
-    3fa4:	85 ff       	sbrs	r24, 5
-    3fa6:	fc cf       	rjmp	.-8      	; 0x3fa0 <putch+0x2>
+    3f98:	80 91 c0 00 	lds	r24, 0x00C0
+    3f9c:	85 ff       	sbrs	r24, 5
+    3f9e:	fc cf       	rjmp	.-8      	; 0x3f98 <putch+0x2>
   UDR0 = ch;
-    3fa8:	90 93 c6 00 	sts	0x00C6, r25
+    3fa0:	90 93 c6 00 	sts	0x00C6, r25
       [uartBit] "I" (UART_TX_BIT)
     :
       "r25"
   );
 #endif
 }
-    3fac:	08 95       	ret
-
-00003fae <getch>:
-  return getch();
-}
+    3fa4:	08 95       	ret
 
-// Watchdog functions. These are only safe with interrupts turned off.
-void watchdogReset() {
-  __asm__ __volatile__ (
-    3fae:	a8 95       	wdr
+00003fa6 <getch>:
       [uartBit] "I" (UART_RX_BIT)
     :
       "r25"
 );
 #else
-  while(!(UCSR0A & _BV(RXC0)));
-    3fb0:	80 91 c0 00 	lds	r24, 0x00C0
-    3fb4:	87 ff       	sbrs	r24, 7
-    3fb6:	fc cf       	rjmp	.-8      	; 0x3fb0 <getch+0x2>
+  while(!(UCSR0A & _BV(RXC0)))
+    3fa6:	80 91 c0 00 	lds	r24, 0x00C0
+    3faa:	87 ff       	sbrs	r24, 7
+    3fac:	fc cf       	rjmp	.-8      	; 0x3fa6 <getch>
+    ;
+  if (!(UCSR0A & _BV(FE0))) {
+    3fae:	80 91 c0 00 	lds	r24, 0x00C0
+    3fb2:	84 fd       	sbrc	r24, 4
+    3fb4:	01 c0       	rjmp	.+2      	; 0x3fb8 <getch+0x12>
+}
+#endif
+
+// Watchdog functions. These are only safe with interrupts turned off.
+void watchdogReset() {
+  __asm__ __volatile__ (
+    3fb6:	a8 95       	wdr
+       * don't care that an invalid char is returned...)
+       */
+    watchdogReset();
+  }
+  
   ch = UDR0;
     3fb8:	80 91 c6 00 	lds	r24, 0x00C6
   LED_PIN |= _BV(LED);
@@ -474,79 +526,73 @@ void watchdogReset() {
 }
     3fbc:	08 95       	ret
 
-00003fbe <getLen>:
-  } while (--count);
-}
-#endif
-
-uint8_t getLen() {
-  getch();
-    3fbe:	f7 df       	rcall	.-18     	; 0x3fae <getch>
-  length = getch();
-    3fc0:	f6 df       	rcall	.-20     	; 0x3fae <getch>
-    3fc2:	80 93 02 02 	sts	0x0202, r24
-  return getch();
-}
-    3fc6:	f3 cf       	rjmp	.-26     	; 0x3fae <getch>
-
-00003fc8 <watchdogConfig>:
+00003fbe <watchdogConfig>:
     "wdr\n"
   );
 }
 
 void watchdogConfig(uint8_t x) {
   WDTCSR = _BV(WDCE) | _BV(WDE);
-    3fc8:	e0 e6       	ldi	r30, 0x60	; 96
-    3fca:	f0 e0       	ldi	r31, 0x00	; 0
-    3fcc:	98 e1       	ldi	r25, 0x18	; 24
-    3fce:	90 83       	st	Z, r25
+    3fbe:	e0 e6       	ldi	r30, 0x60	; 96
+    3fc0:	f0 e0       	ldi	r31, 0x00	; 0
+    3fc2:	98 e1       	ldi	r25, 0x18	; 24
+    3fc4:	90 83       	st	Z, r25
   WDTCSR = x;
-    3fd0:	80 83       	st	Z, r24
+    3fc6:	80 83       	st	Z, r24
 }
-    3fd2:	08 95       	ret
-
-00003fd4 <appStart>:
-
-void appStart() {
-  watchdogConfig(WATCHDOG_OFF);
-    3fd4:	80 e0       	ldi	r24, 0x00	; 0
-    3fd6:	f8 df       	rcall	.-16     	; 0x3fc8 <watchdogConfig>
-  __asm__ __volatile__ (
-    3fd8:	ee 27       	eor	r30, r30
-    3fda:	ff 27       	eor	r31, r31
-    3fdc:	09 94       	ijmp
+    3fc8:	08 95       	ret
 
-00003fde <verifySpace>:
+00003fca <verifySpace>:
   do getch(); while (--count);
   verifySpace();
 }
 
 void verifySpace() {
-  if (getch() != CRC_EOP) appStart();
-    3fde:	e7 df       	rcall	.-50     	; 0x3fae <getch>
-    3fe0:	80 32       	cpi	r24, 0x20	; 32
-    3fe2:	09 f0       	breq	.+2      	; 0x3fe6 <verifySpace+0x8>
-    3fe4:	f7 df       	rcall	.-18     	; 0x3fd4 <appStart>
+  if (getch() != CRC_EOP) {
+    3fca:	ed df       	rcall	.-38     	; 0x3fa6 <getch>
+    3fcc:	80 32       	cpi	r24, 0x20	; 32
+    3fce:	19 f0       	breq	.+6      	; 0x3fd6 <verifySpace+0xc>
+    watchdogConfig(WATCHDOG_16MS);    // shorten WD timeout
+    3fd0:	88 e0       	ldi	r24, 0x08	; 8
+    3fd2:	f5 df       	rcall	.-22     	; 0x3fbe <watchdogConfig>
+    3fd4:	ff cf       	rjmp	.-2      	; 0x3fd4 <verifySpace+0xa>
+    while (1)			      // and busy-loop so that WD causes
+      ;				      //  a reset and app start.
+  }
   putch(STK_INSYNC);
-    3fe6:	84 e1       	ldi	r24, 0x14	; 20
+    3fd6:	84 e1       	ldi	r24, 0x14	; 20
 }
-    3fe8:	da cf       	rjmp	.-76     	; 0x3f9e <putch>
+    3fd8:	de cf       	rjmp	.-68     	; 0x3f96 <putch>
 
-00003fea <getNch>:
+00003fda <getNch>:
     ::[count] "M" (UART_B_VALUE)
   );
 }
 #endif
 
 void getNch(uint8_t count) {
-    3fea:	1f 93       	push	r17
-    3fec:	18 2f       	mov	r17, r24
+    3fda:	1f 93       	push	r17
+    3fdc:	18 2f       	mov	r17, r24
   do getch(); while (--count);
-    3fee:	df df       	rcall	.-66     	; 0x3fae <getch>
-    3ff0:	11 50       	subi	r17, 0x01	; 1
-    3ff2:	e9 f7       	brne	.-6      	; 0x3fee <getNch+0x4>
+    3fde:	e3 df       	rcall	.-58     	; 0x3fa6 <getch>
+    3fe0:	11 50       	subi	r17, 0x01	; 1
+    3fe2:	e9 f7       	brne	.-6      	; 0x3fde <getNch+0x4>
   verifySpace();
-    3ff4:	f4 df       	rcall	.-24     	; 0x3fde <verifySpace>
+    3fe4:	f2 df       	rcall	.-28     	; 0x3fca <verifySpace>
+}
+    3fe6:	1f 91       	pop	r17
+    3fe8:	08 95       	ret
+
+00003fea <appStart>:
+  WDTCSR = _BV(WDCE) | _BV(WDE);
+  WDTCSR = x;
 }
-    3ff6:	1f 91       	pop	r17
-    3ff8:	08 95       	ret
+
+void appStart() {
+  watchdogConfig(WATCHDOG_OFF);
+    3fea:	80 e0       	ldi	r24, 0x00	; 0
+    3fec:	e8 df       	rcall	.-48     	; 0x3fbe <watchdogConfig>
+  __asm__ __volatile__ (
+    3fee:	ee 27       	eor	r30, r30
+    3ff0:	ff 27       	eor	r31, r31
+    3ff2:	09 94       	ijmp