Skip to content

Instantly share code, notes, and snippets.

@matthijskooijman
Last active August 29, 2015 14:12
Show Gist options
  • Save matthijskooijman/887c7a328f6cb3b7a225 to your computer and use it in GitHub Desktop.
Save matthijskooijman/887c7a328f6cb3b7a225 to your computer and use it in GitHub Desktop.
--- a/firmware/bootloader/src/main.c
+++ b/firmware/bootloader/src/main.c
@@ -727,6 +727,7 @@ int main(void)
unsigned char *p = msgBuffer+10;
unsigned int data;
address_t tempAddress;
+ PORTE |= 1;
if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
{
--- /dev/fd/63 2014-12-31 11:58:25.791065349 +0100
+++ /dev/fd/62 2014-12-31 11:58:25.795065378 +0100
@@ -1,5 +1,5 @@
-orig.elf: file format elf32-avr
+bootloader.elf: file format elf32-avr
Disassembly of section .text:
@@ -174,8 +174,8 @@
12 e0 ldi r17, 0x02 ; 2
a0 e0 ldi r26, 0x00 ; 0
b2 e0 ldi r27, 0x02 ; 2
- e6 e8 ldi r30, 0x86 ; 134
- f5 ee ldi r31, 0xE5 ; 229
+ e2 e3 ldi r30, 0x32 ; 50
+ f6 ee ldi r31, 0xE6 ; 230
03 e0 ldi r16, 0x03 ; 3
0b bf out 0x3b, r16 ; 59
xx xx rjmp ; <__do_copy_data+0x....>
@@ -257,7 +257,7 @@
df 93 push r29
cd b7 in r28, 0x3d ; 61
de b7 in r29, 0x3e ; 62
- cd 51 subi r28, 0x1D ; 29
+ c0 52 subi r28, 0x20 ; 32
d1 40 sbci r29, 0x01 ; 1
0f b6 in r0, 0x3f ; 63
f8 94 cli
@@ -326,21 +326,25 @@
unsigned char isLeave = 0;
unsigned char isTimeout = 0;
unsigned char badMessage = 0;
- 41 2c mov r4, r1
+ c2 5e subi r28, 0xE2 ; 226
+ de 4f sbci r29, 0xFE ; 254
+ 18 82 st Y, r1
+ ce 51 subi r28, 0x1E ; 30
+ d1 40 sbci r29, 0x01 ; 1
{
address_t address = 0;
unsigned char msgParseState;
unsigned int ii = 0;
unsigned char checksum = 0;
unsigned char seqNum = 0;
- 51 2c mov r5, r1
+ 21 2c mov r2, r1
int main(void)
{
address_t address = 0;
unsigned char msgParseState;
unsigned int ii = 0;
unsigned char checksum = 0;
- 31 2c mov r3, r1
+ d1 2c mov r13, r1
//*****************************************************************************
int main(void)
{
@@ -355,47 +359,47 @@
int main(void)
{
address_t address = 0;
- c1 2c mov r12, r1
- d1 2c mov r13, r1
- 76 01 movw r14, r12
+ 41 2c mov r4, r1
+ 51 2c mov r5, r1
+ 32 01 movw r6, r4
for(;;) {
boot_state=0;
boot_timer=0;
isLeave=0;
isTimeout=0;
- 30 e0 ldi r19, 0x00 ; 0
+ 20 e0 ldi r18, 0x00 ; 0
asm volatile ("nop"); // wait until port has changed
for(;;) {
boot_state=0;
boot_timer=0;
- 40 e0 ldi r20, 0x00 ; 0
- 50 e0 ldi r21, 0x00 ; 0
- ba 01 movw r22, r20
+ 80 e0 ldi r24, 0x00 ; 0
+ 90 e0 ldi r25, 0x00 ; 0
+ dc 01 movw r26, r24
_delay_ms(0.040);
boot_timer++;
if (boot_timer > boot_timeout)
{
isTimeout = 1;
boot_state = 1; // get us out, this is incremented to 2 below
- 80 e0 ldi r24, 0x00 ; 0
- 90 e0 ldi r25, 0x00 ; 0
+ 60 e0 ldi r22, 0x00 ; 0
+ 70 e0 ldi r23, 0x00 ; 0
//************************************************************************
static int Serial_Available(void)
{
return(UART_STATUS_REG & (1 << UART_RECEIVE_COMPLETE)); // wait for data
- 20 91 c0 00 lds r18, 0x00C0
+ e0 91 c0 00 lds r30, 0x00C0
boot_timer=0;
isLeave=0;
isTimeout=0;
while (boot_state==0)
{
while ((!(Serial_Available())) && (boot_state == 0)) // wait for data
- 27 ff sbrs r18, 7
+ e7 ff sbrs r30, 7
xx xx rjmp ; <main+0x....>
for(;;) {
boot_state=0;
@@ -403,6 +407,7 @@
isLeave=0;
isTimeout=0;
while (boot_state==0)
+ cb 01 movw r24, r22
01 96 adiw r24, 0x01 ; 1
}
}
@@ -421,7 +426,8 @@
while (boot_state==0)
{
while ((!(Serial_Available())) && (boot_state == 0)) // wait for data
- 00 97 sbiw r24, 0x00 ; 0
+ 61 15 cp r22, r1
+ 71 05 cpc r23, r1
xx xx brne ; <main+0x....>
#else
//round up by default
@@ -429,30 +435,29 @@
#endif
__builtin_avr_delay_cycles(__ticks_dc);
- 25 ed ldi r18, 0xD5 ; 213
- 2a 95 dec r18
+ 35 ed ldi r19, 0xD5 ; 213
+ 3a 95 dec r19
xx xx brne ; <main+0x....>
00 00 nop
{
_delay_ms(0.040);
boot_timer++;
- 4f 5f subi r20, 0xFF ; 255
- 5f 4f sbci r21, 0xFF ; 255
- 6f 4f sbci r22, 0xFF ; 255
- 7f 4f sbci r23, 0xFF ; 255
+ 01 96 adiw r24, 0x01 ; 1
+ a1 1d adc r26, r1
+ b1 1d adc r27, r1
if (boot_timer > boot_timeout)
- 41 31 cpi r20, 0x11 ; 17
- a7 e2 ldi r26, 0x27 ; 39
- 5a 07 cpc r21, r26
- 61 05 cpc r22, r1
- 71 05 cpc r23, r1
+ 81 31 cpi r24, 0x11 ; 17
+ 47 e2 ldi r20, 0x27 ; 39
+ 94 07 cpc r25, r20
+ a1 05 cpc r26, r1
+ b1 05 cpc r27, r1
xx xx brcs ; <main+0x....>
{
isTimeout = 1;
- 31 e0 ldi r19, 0x01 ; 1
+ 21 e0 ldi r18, 0x01 ; 1
boot_state = 1; // get us out, this is incremented to 2 below
- 81 e0 ldi r24, 0x01 ; 1
- 90 e0 ldi r25, 0x00 ; 0
+ 61 e0 ldi r22, 0x01 ; 1
+ 70 e0 ldi r23, 0x00 ; 0
xx xx rjmp ; <main+0x....>
{
// c = recchar();
@@ -460,7 +465,7 @@
}
switch (msgParseState)
- 61 30 cpi r22, 0x01 ; 1
+ 11 30 cpi r17, 0x01 ; 1
xx xx brne ; <main+0x....>
xx xx rjmp ; <main+0x....>
xx xx brcs ; <main+0x....>
@@ -477,20 +482,32 @@
else
{
if (badMessage++ > 5) { isTimeout = 1; } // isLeave is now a forced boot to main app
- 81 e0 ldi r24, 0x01 ; 1
- 84 0d add r24, r4
- e5 e0 ldi r30, 0x05 ; 5
- e4 15 cp r30, r4
- xx xx brcc ; <main+0x....>
+ c2 5e subi r28, 0xE2 ; 226
+ de 4f sbci r29, 0xFE ; 254
+ 88 81 ld r24, Y
+ ce 51 subi r28, 0x1E ; 30
+ d1 40 sbci r29, 0x01 ; 1
+ 8f 5f subi r24, 0xFF ; 255
+ c2 5e subi r28, 0xE2 ; 226
+ de 4f sbci r29, 0xFE ; 254
+ 28 81 ld r18, Y
+ ce 51 subi r28, 0x1E ; 30
+ d1 40 sbci r29, 0x01 ; 1
+ c2 5e subi r28, 0xE2 ; 226
+ de 4f sbci r29, 0xFE ; 254
+ 88 83 st Y, r24
+ ce 51 subi r28, 0x1E ; 30
+ d1 40 sbci r29, 0x01 ; 1
+ 26 30 cpi r18, 0x06 ; 6
+ xx xx brcs ; <main+0x....>
xx xx rjmp ; <main+0x....>
- 48 2e mov r4, r24
{
/*
* Collect received bytes to a complete message
*/
msgParseState = ST_START;
while ((msgParseState != ST_PROCESS) && (!isLeave) && (!isTimeout))
- 21 10 cpse r2, r1
+ 31 10 cpse r3, r1
xx xx rjmp ; <main+0x....>
80 e0 ldi r24, 0x00 ; 0
90 e0 ldi r25, 0x00 ; 0
@@ -508,8 +525,8 @@
uint32_t count = 0;
while (!(UART_STATUS_REG & (1 << UART_RECEIVE_COMPLETE)))
- 40 91 c0 00 lds r20, 0x00C0
- 47 ff sbrs r20, 7
+ e0 91 c0 00 lds r30, 0x00C0
+ e7 ff sbrs r30, 7
xx xx rjmp ; <main+0x....>
{
*timedout = 1;
@@ -518,23 +535,23 @@
}
return UART_DATA_REG;
80 91 c6 00 lds r24, 0x00C6
- 21 2c mov r2, r1
+ 31 2c mov r3, r1
{
// c = recchar();
c = recchar_timeout(&isTimeout);
}
switch (msgParseState)
- 63 30 cpi r22, 0x03 ; 3
+ 13 30 cpi r17, 0x03 ; 3
xx xx brne ; <main+0x....>
xx xx rjmp ; <main+0x....>
xx xx brcs ; <main+0x....>
- 65 30 cpi r22, 0x05 ; 5
+ 15 30 cpi r17, 0x05 ; 5
xx xx brne ; <main+0x....>
xx xx rjmp ; <main+0x....>
xx xx brcc ; <main+0x....>
xx xx rjmp ; <main+0x....>
- 66 30 cpi r22, 0x06 ; 6
+ 16 30 cpi r17, 0x06 ; 6
xx xx breq ; <main+0x....>
xx xx rjmp ; <main+0x....>
msgParseState = ST_GET_CHECK;
@@ -543,7 +560,7 @@
case ST_GET_CHECK:
if ( c == checksum )
- 83 11 cpse r24, r3
+ 8d 11 cpse r24, r13
xx xx rjmp ; <main+0x....>
/*
@@ -608,7 +625,7 @@
9e 83 std Y+6, r25 ; 0x06
msgBuffer[6] = STATUS_CMD_OK;
1f 82 std Y+7, r1 ; 0x07
- 91 2c mov r9, r1
+ c1 2c mov r12, r1
{
answerByte = 0; // for all others command are not implemented, return dummy value for AVRDUDE happy <Worapoht>
}
@@ -617,99 +634,100 @@
msgLength = 7;
07 e0 ldi r16, 0x07 ; 7
10 e0 ldi r17, 0x00 ; 0
- break;
}
/*
* Now send answer message back
*/
+ sendchar(MESSAGE_START);
8b e1 ldi r24, 0x1B ; 27
xx xx rcall ; <sendchar>
- sendchar(MESSAGE_START);
checksum = MESSAGE_START^0;
- 85 2d mov r24, r5
- xx xx rcall ; <sendchar>
sendchar(seqNum);
+ 82 2d mov r24, r2
+ xx xx rcall ; <sendchar>
checksum ^= seqNum;
c = ((msgLength>>8)&0xFF);
+ sendchar(c);
80 e0 ldi r24, 0x00 ; 0
xx xx rcall ; <sendchar>
- sendchar(c);
checksum ^= c;
c = msgLength&0x00FF;
+ sendchar(c);
80 2f mov r24, r16
xx xx rcall ; <sendchar>
- sendchar(c);
checksum ^= c;
+ sendchar(TOKEN);
8e e0 ldi r24, 0x0E ; 14
xx xx rcall ; <sendchar>
- c = ((msgLength>>8)&0xFF);
sendchar(c);
checksum ^= c;
c = msgLength&0x00FF;
sendchar(c);
- 95 e1 ldi r25, 0x15 ; 21
- 39 2e mov r3, r25
- 35 24 eor r3, r5
checksum ^= c;
+ 95 e1 ldi r25, 0x15 ; 21
+ d9 2e mov r13, r25
+ d2 24 eor r13, r2
sendchar(TOKEN);
- 30 26 eor r3, r16
- fe 01 movw r30, r28
- 31 96 adiw r30, 0x01 ; 1
- 3f 01 movw r6, r30
checksum ^= TOKEN;
+ d0 26 eor r13, r16
+ 9e 01 movw r18, r28
+ 2f 5f subi r18, 0xFF ; 255
+ 3f 4f sbci r19, 0xFF ; 255
+ 79 01 movw r14, r18
p = msgBuffer;
while ( msgLength )
{
- f3 01 movw r30, r6
- 81 90 ld r8, Z+
- 3f 01 movw r6, r30
c = *p++;
- 88 2d mov r24, r8
- xx xx rcall ; <sendchar>
+ f7 01 movw r30, r14
+ 91 90 ld r9, Z+
+ 7f 01 movw r14, r30
sendchar(c);
- 38 24 eor r3, r8
+ 89 2d mov r24, r9
+ xx xx rcall ; <sendchar>
checksum ^=c;
+ d9 24 eor r13, r9
+ msgLength--;
01 50 subi r16, 0x01 ; 1
11 09 sbc r17, r1
- checksum ^= c;
sendchar(TOKEN);
checksum ^= TOKEN;
p = msgBuffer;
+ while ( msgLength )
01 15 cp r16, r1
11 05 cpc r17, r1
xx xx brne ; <main+0x....>
- {
c = *p++;
sendchar(c);
checksum ^=c;
msgLength--;
}
- 83 2d mov r24, r3
- xx xx rcall ; <sendchar>
sendchar(checksum);
- 53 94 inc r5
+ 8d 2d mov r24, r13
+ xx xx rcall ; <sendchar>
+ seqNum++;
+ 23 94 inc r2
}
if (boot_state==1) // enter serial bootloader
{
//* main loop
while ((!isLeave) && (!isTimeout))
- 91 10 cpse r9, r1
+ c1 10 cpse r12, r1
xx xx rjmp ; <main+0x....>
80 e0 ldi r24, 0x00 ; 0
90 e0 ldi r25, 0x00 ; 0
- 32 2d mov r19, r2
- 33 23 and r19, r19
+ 23 2d mov r18, r3
+ 22 23 and r18, r18
xx xx breq ; <main+0x....>
@@ -717,23 +735,23 @@
boot_state=0;
boot_timer=0;
isLeave=0;
- 20 e0 ldi r18, 0x00 ; 0
+ 60 e0 ldi r22, 0x00 ; 0
xx xx rjmp ; <main+0x....>
- 32 2d mov r19, r2
- 21 e0 ldi r18, 0x01 ; 1
- seqNum++;
+ 23 2d mov r18, r3
+ 61 e0 ldi r22, 0x01 ; 1
}
}
+ boot_rww_enable(); // enable application section so we can read from it
81 e1 ldi r24, 0x11 ; 17
80 93 57 00 sts 0x0057, r24
e8 95 spm
- boot_rww_enable(); // enable application section so we can read from it
unsigned int data;
#if (FLASHEND > 0x10000)
+ data = pgm_read_word_far(0); //* get the first word of the user program
80 e0 ldi r24, 0x00 ; 0
90 e0 ldi r25, 0x00 ; 0
dc 01 movw r26, r24
@@ -741,33 +759,33 @@
fc 01 movw r30, r24
87 91 elpm r24, Z+
96 91 elpm r25, Z
- data = pgm_read_word_far(0); //* get the first word of the user program
#else
data = pgm_read_word_near(0); //* get the first word of the user program
#endif
- 21 11 cpse r18, r1
+ if ((isLeave) || (isTimeout && (data != 0xffff))) //* require valid flash address on timeout
+ 61 11 cpse r22, r1
xx xx rjmp ; <main+0x....>
- 33 23 and r19, r19
+ 22 23 and r18, r18
xx xx brne ; <main+0x....>
xx xx rjmp ; <main+0x....>
01 96 adiw r24, 0x01 ; 1
xx xx brne ; <main+0x....>
xx xx rjmp ; <main+0x....>
- if ((isLeave) || (isTimeout && (data != 0xffff))) //* require valid flash address on timeout
{
- 00 00 nop
asm volatile ("nop"); // wait until port has changed
+ 00 00 nop
/*
* Now leave bootloader
*/
+ UART_STATUS_REG &= 0xfd;
80 91 c0 00 lds r24, 0x00C0
8d 7f andi r24, 0xFD ; 253
80 93 c0 00 sts 0x00C0, r24
- UART_STATUS_REG &= 0xfd;
+ asm("jmp 0000");
xx xx xx xx jmp ; <__heap_end>
xx xx rjmp ; <main+0x....>
}
@@ -777,8 +795,8 @@
//* main loop
while ((!isLeave) && (!isTimeout))
60 e0 ldi r22, 0x00 ; 0
- 20 e0 ldi r18, 0x00 ; 0
- 30 e0 ldi r19, 0x00 ; 0
+ 70 e0 ldi r23, 0x00 ; 0
+ 10 e0 ldi r17, 0x00 ; 0
xx xx rjmp ; <main+0x....>
01 97 sbiw r24, 0x01 ; 1
a1 09 sbc r26, r1
@@ -796,8 +814,8 @@
xx xx rjmp ; <main+0x....>
{
*timedout = 1;
- 22 24 eor r2, r2
- 23 94 inc r2
+ 33 24 eor r3, r3
+ 33 94 inc r3
return 0; // NULL character
80 e0 ldi r24, 0x00 ; 0
xx xx rjmp ; <main+0x....>
@@ -807,21 +825,21 @@
seqNum = c;
msgParseState = ST_MSG_SIZE_1;
checksum ^= c;
- 38 26 eor r3, r24
+ d8 26 eor r13, r24
else
{
msgParseState = ST_START;
}
#endif
break;
- 58 2e mov r5, r24
+ 28 2e mov r2, r24
break;
case ST_GET_SEQ_NUM:
#ifdef _FIX_ISSUE_505_
seqNum = c;
msgParseState = ST_MSG_SIZE_1;
- 62 e0 ldi r22, 0x02 ; 2
+ 12 e0 ldi r17, 0x02 ; 2
else
{
msgParseState = ST_START;
@@ -832,37 +850,37 @@
case ST_MSG_SIZE_1:
msgLength = c<<8;
- 28 2f mov r18, r24
- 30 e0 ldi r19, 0x00 ; 0
- 32 2f mov r19, r18
- 22 27 eor r18, r18
+ 68 2f mov r22, r24
+ 70 e0 ldi r23, 0x00 ; 0
+ 76 2f mov r23, r22
+ 66 27 eor r22, r22
msgParseState = ST_MSG_SIZE_2;
checksum ^= c;
- 38 26 eor r3, r24
+ d8 26 eor r13, r24
#endif
break;
case ST_MSG_SIZE_1:
msgLength = c<<8;
msgParseState = ST_MSG_SIZE_2;
- 63 e0 ldi r22, 0x03 ; 3
+ 13 e0 ldi r17, 0x03 ; 3
checksum ^= c;
break;
xx xx rjmp ; <main+0x....>
case ST_MSG_SIZE_2:
msgLength |= c;
- 28 2b or r18, r24
+ 68 2b or r22, r24
msgParseState = ST_GET_TOKEN;
checksum ^= c;
- 38 26 eor r3, r24
+ d8 26 eor r13, r24
checksum ^= c;
break;
case ST_MSG_SIZE_2:
msgLength |= c;
msgParseState = ST_GET_TOKEN;
- 64 e0 ldi r22, 0x04 ; 4
+ 14 e0 ldi r17, 0x04 ; 4
checksum ^= c;
break;
xx xx rjmp ; <main+0x....>
@@ -875,7 +893,7 @@
{
msgParseState = ST_GET_DATA;
checksum ^= c;
- 38 26 eor r3, r24
+ d8 26 eor r13, r24
ii = 0;
a1 2c mov r10, r1
b1 2c mov r11, r1
@@ -885,7 +903,7 @@
if ( c == TOKEN )
{
msgParseState = ST_GET_DATA;
- 65 e0 ldi r22, 0x05 ; 5
+ 15 e0 ldi r17, 0x05 ; 5
xx xx rjmp ; <main+0x....>
msgParseState = ST_START;
}
@@ -893,24 +911,23 @@
case ST_GET_DATA:
msgBuffer[ii++] = c;
- a5 01 movw r20, r10
- 4f 5f subi r20, 0xFF ; 255
- 5f 4f sbci r21, 0xFF ; 255
- e1 e0 ldi r30, 0x01 ; 1
- f0 e0 ldi r31, 0x00 ; 0
- ec 0f add r30, r28
- fd 1f adc r31, r29
- ea 0d add r30, r10
- fb 1d adc r31, r11
- 80 83 st Z, r24
+ f5 01 movw r30, r10
+ 31 96 adiw r30, 0x01 ; 1
+ a1 e0 ldi r26, 0x01 ; 1
+ b0 e0 ldi r27, 0x00 ; 0
+ ac 0f add r26, r28
+ bd 1f adc r27, r29
+ aa 0d add r26, r10
+ bb 1d adc r27, r11
+ 8c 93 st X, r24
checksum ^= c;
- 38 26 eor r3, r24
+ d8 26 eor r13, r24
if (ii == msgLength )
- 42 17 cp r20, r18
- 53 07 cpc r21, r19
+ e6 17 cp r30, r22
+ f7 07 cpc r31, r23
xx xx brne ; <main+0x....>
xx xx rjmp ; <main+0x....>
- 5a 01 movw r10, r20
+ 5f 01 movw r10, r30
xx xx rjmp ; <main+0x....>
{
/*
@@ -918,7 +935,7 @@
*/
msgParseState = ST_START;
while ((msgParseState != ST_PROCESS) && (!isLeave) && (!isTimeout))
- 67 30 cpi r22, 0x07 ; 7
+ 17 30 cpi r17, 0x07 ; 7
xx xx breq ; <main+0x....>
xx xx rjmp ; <main+0x....>
xx xx rjmp ; <main+0x....>
@@ -972,7 +989,7 @@
82 e3 ldi r24, 0x32 ; 50
8b 87 std Y+11, r24 ; 0x0b
break;
- 91 2c mov r9, r1
+ c1 2c mov r12, r1
}
}
break;
@@ -1003,8 +1020,8 @@
case CMD_LEAVE_PROGMODE_ISP:
isLeave = 1;
- 99 24 eor r9, r9
- 93 94 inc r9
+ cc 24 eor r12, r12
+ c3 94 inc r12
xx xx rjmp ; <main+0x....>
/*
@@ -1012,7 +1029,7 @@
*/
switch (msgBuffer[0])
- 91 2c mov r9, r1
+ c1 2c mov r12, r1
xx xx rjmp ; <main+0x....>
else
{
@@ -1113,7 +1130,7 @@
8b 83 std Y+3, r24 ; 0x03
}
break;
- 91 2c mov r9, r1
+ c1 2c mov r12, r1
break;
default:
value = 0;
@@ -1141,22 +1158,23 @@
#if defined(RAMPZ)
address = ( ((address_t)(msgBuffer[1])<<24)|((address_t)(msgBuffer[2])<<16)|((address_t)(msgBuffer[3])<<8)|(msgBuffer[4]) )<<1;
8a 81 ldd r24, Y+2 ; 0x02
- cb 80 ldd r12, Y+3 ; 0x03
- d1 2c mov r13, r1
- e1 2c mov r14, r1
- f1 2c mov r15, r1
- 76 01 movw r14, r12
- dd 24 eor r13, r13
- cc 24 eor r12, r12
- f8 2a or r15, r24
+ 2b 81 ldd r18, Y+3 ; 0x03
+ 42 2f mov r20, r18
+ 50 e0 ldi r21, 0x00 ; 0
+ 60 e0 ldi r22, 0x00 ; 0
+ 70 e0 ldi r23, 0x00 ; 0
+ 3a 01 movw r6, r20
+ 55 24 eor r5, r5
+ 44 24 eor r4, r4
+ 78 2a or r7, r24
8d 81 ldd r24, Y+5 ; 0x05
- c8 2a or r12, r24
+ 48 2a or r4, r24
8c 81 ldd r24, Y+4 ; 0x04
- d8 2a or r13, r24
- cc 0c add r12, r12
- dd 1c adc r13, r13
- ee 1c adc r14, r14
- ff 1c adc r15, r15
+ 58 2a or r5, r24
+ 44 0c add r4, r4
+ 55 1c adc r5, r5
+ 66 1c adc r6, r6
+ 77 1c adc r7, r7
xx xx rjmp ; <main+0x....>
msgBuffer[1] = STATUS_CMD_OK;
break;
@@ -1164,127 +1182,197 @@
case CMD_PROGRAM_FLASH_ISP:
{
unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2];
- 8a 81 ldd r24, Y+2 ; 0x02
- 90 e0 ldi r25, 0x00 ; 0
- 98 2f mov r25, r24
- 88 27 eor r24, r24
- 2b 81 ldd r18, Y+3 ; 0x03
- 82 2b or r24, r18
+ 0a 81 ldd r16, Y+2 ; 0x02
+ 10 e0 ldi r17, 0x00 ; 0
+ 10 2f mov r17, r16
+ 00 27 eor r16, r16
+ 8b 81 ldd r24, Y+3 ; 0x03
+ 08 2b or r16, r24
+ unsigned char *p = msgBuffer+10;
+ unsigned int data;
address_t tempAddress;
PORTE |= 1;
+ 70 9a sbi 0x0e, 0 ; 14
if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
+ 89 81 ldd r24, Y+1 ; 0x01
+ 83 31 cpi r24, 0x13 ; 19
+ xx xx breq ; <main+0x....>
+ xx xx rjmp ; <main+0x....>
{
// erase only main section (bootloader protection)
- 80 fd sbrc r24, 0
+ if ((!(size % 2)) && (!(address % SPM_PAGESIZE)) && (size <= SPM_PAGESIZE) && (address + size <= APP_END))
+ 00 fd sbrc r16, 0
xx xx rjmp ; <main+0x....>
- b7 01 movw r22, r14
- a6 01 movw r20, r12
- 55 27 eor r21, r21
- 66 27 eor r22, r22
- 77 27 eor r23, r23
- 45 2b or r20, r21
- 46 2b or r20, r22
- 47 2b or r20, r23
- xx xx breq ; <main+0x....>
+ 41 10 cpse r4, r1
xx xx rjmp ; <main+0x....>
- 81 30 cpi r24, 0x01 ; 1
+ 01 30 cpi r16, 0x01 ; 1
f1 e0 ldi r31, 0x01 ; 1
- 9f 07 cpc r25, r31
+ 1f 07 cpc r17, r31
xx xx brcs ; <main+0x....>
xx xx rjmp ; <main+0x....>
- b7 01 movw r22, r14
- a6 01 movw r20, r12
- 48 0f add r20, r24
- 59 1f adc r21, r25
- 61 1d adc r22, r1
- 71 1d adc r23, r1
- 41 30 cpi r20, 0x01 ; 1
- 50 4e sbci r21, 0xE0 ; 224
- 63 40 sbci r22, 0x03 ; 3
- 71 05 cpc r23, r1
+ d3 01 movw r26, r6
+ c2 01 movw r24, r4
+ 80 0f add r24, r16
+ 91 1f adc r25, r17
+ a1 1d adc r26, r1
+ b1 1d adc r27, r1
+ 81 30 cpi r24, 0x01 ; 1
+ 90 4e sbci r25, 0xE0 ; 224
+ a3 40 sbci r26, 0x03 ; 3
+ b1 05 cpc r27, r1
xx xx brcs ; <main+0x....>
xx xx rjmp ; <main+0x....>
- if ((!(size % 2)) && (!(address % SPM_PAGESIZE)) && (size <= SPM_PAGESIZE) && (address + size <= APP_END))
{
- 23 e0 ldi r18, 0x03 ; 3
- f6 01 movw r30, r12
- e0 92 5b 00 sts 0x005B, r14
- 20 93 57 00 sts 0x0057, r18
- e8 95 spm
boot_page_erase(address); // Perform page erase
+ 83 e0 ldi r24, 0x03 ; 3
+ f2 01 movw r30, r4
+ 60 92 5b 00 sts 0x005B, r6
+ 80 93 57 00 sts 0x0057, r24
+ e8 95 spm
+ boot_spm_busy_wait(); // Wait until the memory is erased.
07 b6 in r0, 0x37 ; 55
00 fc sbrc r0, 0
xx xx rjmp ; <main+0x....>
- b7 01 movw r22, r14
- a6 01 movw r20, r12
- boot_spm_busy_wait(); // Wait until the memory is erased.
+ d3 01 movw r26, r6
+ c2 01 movw r24, r4
/* Write FLASH */
tempAddress = address;
do {
data = 0xffcf; // rjmp .-2
- a1 e0 ldi r26, 0x01 ; 1
+ boot_page_fill(tempAddress,data);
+ 41 e0 ldi r20, 0x01 ; 1
2f ec ldi r18, 0xCF ; 207
3f ef ldi r19, 0xFF ; 255
09 01 movw r0, r18
- fa 01 movw r30, r20
- 60 93 5b 00 sts 0x005B, r22
- a0 93 57 00 sts 0x0057, r26
+ fc 01 movw r30, r24
+ a0 93 5b 00 sts 0x005B, r26
+ 40 93 57 00 sts 0x0057, r20
e8 95 spm
11 24 eor r1, r1
- boot_page_fill(tempAddress,data);
- 4e 5f subi r20, 0xFE ; 254
- 5f 4f sbci r21, 0xFF ; 255
- 6f 4f sbci r22, 0xFF ; 255
- 7f 4f sbci r23, 0xFF ; 255
tempAddress = tempAddress + 2; // Select next word in memory
- 02 97 sbiw r24, 0x02 ; 2
+ 02 96 adiw r24, 0x02 ; 2
+ a1 1d adc r26, r1
+ b1 1d adc r27, r1
size -= 2; // Reduce number of bytes to write by two
- 00 97 sbiw r24, 0x00 ; 0
- xx xx brne ; <main+0x....>
+ 02 50 subi r16, 0x02 ; 2
+ 11 09 sbc r17, r1
} while (size); // Loop until all bytes written
+ 01 15 cp r16, r1
+ 11 05 cpc r17, r1
+ xx xx brne ; <main+0x....>
+ boot_page_write(address);
85 e0 ldi r24, 0x05 ; 5
- f6 01 movw r30, r12
- e0 92 5b 00 sts 0x005B, r14
+ f2 01 movw r30, r4
+ 60 92 5b 00 sts 0x005B, r6
80 93 57 00 sts 0x0057, r24
e8 95 spm
- boot_page_write(address);
+ boot_spm_busy_wait();
07 b6 in r0, 0x37 ; 55
00 fc sbrc r0, 0
xx xx rjmp ; <main+0x....>
- boot_spm_busy_wait();
+ boot_rww_enable(); // Re-enable the RWW section
81 e1 ldi r24, 0x11 ; 17
80 93 57 00 sts 0x0057, r24
e8 95 spm
- boot_rww_enable(); // Re-enable the RWW section
-
+ xx xx rjmp ; <main+0x....>
+ }
+ }
+ else
+ {
+ //* issue 543, this should work, It has not been tested.
+ uint16_t ii = address >> 1;
+ 73 01 movw r14, r6
+ 62 01 movw r12, r4
+ f6 94 lsr r15
+ e7 94 ror r14
+ d7 94 ror r13
+ c7 94 ror r12
+ 9e 01 movw r18, r28
+ 25 5f subi r18, 0xF5 ; 245
+ 3f 4f sbci r19, 0xFF ; 255
+ /* write EEPROM */
+ while (size) {
+ 81 2c mov r8, r1
+ 91 2c mov r9, r1
+ 80 16 cp r8, r16
+ 91 06 cpc r9, r17
+ xx xx breq ; <main+0x....>
+ eeprom_write_byte((uint8_t*)ii, *p++);
+ f9 01 movw r30, r18
+ 61 91 ld r22, Z+
+ 9f 01 movw r18, r30
+ c4 01 movw r24, r8
+ 8c 0d add r24, r12
+ 9d 1d adc r25, r13
+ c1 5e subi r28, 0xE1 ; 225
+ de 4f sbci r29, 0xFE ; 254
+ e8 83 st Y, r30
+ cf 51 subi r28, 0x1F ; 31
+ d1 40 sbci r29, 0x01 ; 1
+ c0 5e subi r28, 0xE0 ; 224
+ de 4f sbci r29, 0xFE ; 254
+ 38 83 st Y, r19
+ c0 52 subi r28, 0x20 ; 32
+ d1 40 sbci r29, 0x01 ; 1
+ xx xx rcall ; <__eewr_byte_EEPROM_SUFFIX>
+ ff ef ldi r31, 0xFF ; 255
+ 8f 1a sub r8, r31
+ 9f 0a sbc r9, r31
+ c0 5e subi r28, 0xE0 ; 224
+ de 4f sbci r29, 0xFE ; 254
+ 38 81 ld r19, Y
+ c0 52 subi r28, 0x20 ; 32
+ d1 40 sbci r29, 0x01 ; 1
+ c1 5e subi r28, 0xE1 ; 225
+ de 4f sbci r29, 0xFE ; 254
+ 28 81 ld r18, Y
+ cf 51 subi r28, 0x1F ; 31
+ d1 40 sbci r29, 0x01 ; 1
+ xx xx rjmp ; <main+0x....>
+ c4 01 movw r24, r8
+ a0 e0 ldi r26, 0x00 ; 0
+ b0 e0 ldi r27, 0x00 ; 0
+ 88 0f add r24, r24
+ 99 1f adc r25, r25
+ aa 1f adc r26, r26
+ bb 1f adc r27, r27
+ 48 0e add r4, r24
+ 59 1e adc r5, r25
+ 6a 1e adc r6, r26
+ 7b 1e adc r7, r27
+ address+=2; // Select next EEPROM byte
+ ii++;
+ size--;
+ }
msgLength = 2;
+ msgBuffer[1] = STATUS_CMD_OK;
1a 82 std Y+2, r1 ; 0x02
xx xx rjmp ; <main+0x....>
- }
}
break;
default:
msgLength = 2;
+ msgBuffer[1] = STATUS_CMD_FAILED;
80 ec ldi r24, 0xC0 ; 192
8a 83 std Y+2, r24 ; 0x02
- msgBuffer[1] = STATUS_CMD_FAILED;
- 91 2c mov r9, r1
- msgBuffer[1] = STATUS_CMD_OK;
+ break;
+ c1 2c mov r12, r1
}
}
break;
default:
+ msgLength = 2;
02 e0 ldi r16, 0x02 ; 2
10 e0 ldi r17, 0x00 ; 0
- msgLength = 2;
msgBuffer[1] = STATUS_CMD_FAILED;
+ break;
xx xx rjmp ; <main+0x....>
{
case ST_START:
@@ -1293,23 +1381,22 @@
msgParseState = ST_GET_SEQ_NUM;
checksum = MESSAGE_START^0;
8b e1 ldi r24, 0x1B ; 27
- 38 2e mov r3, r24
+ d8 2e mov r13, r24
switch (msgParseState)
{
case ST_START:
if ( c == MESSAGE_START )
{
msgParseState = ST_GET_SEQ_NUM;
- 61 e0 ldi r22, 0x01 ; 1
+ 11 e0 ldi r17, 0x01 ; 1
xx xx rjmp ; <main+0x....>
checksum = MESSAGE_START^0;
}
else
{
if (badMessage++ > 5) { isTimeout = 1; } // isLeave is now a forced boot to main app
- 48 2e mov r4, r24
- 22 24 eor r2, r2
- 23 94 inc r2
+ 33 24 eor r3, r3
+ 33 94 inc r3
xx xx rjmp ; <main+0x....>
checksum ^= c;
ii = 0;
@@ -1317,18 +1404,36 @@
else
{
msgParseState = ST_START;
- 60 e0 ldi r22, 0x00 ; 0
+ 10 e0 ldi r17, 0x00 ; 0
xx xx rjmp ; <main+0x....>
- 59 01 movw r10, r18
+ 5b 01 movw r10, r22
case ST_GET_DATA:
msgBuffer[ii++] = c;
checksum ^= c;
if (ii == msgLength )
{
msgParseState = ST_GET_CHECK;
- 66 e0 ldi r22, 0x06 ; 6
+ 16 e0 ldi r17, 0x06 ; 6
xx xx rjmp ; <main+0x....>
+<__eewr_byte_EEPROM_SUFFIX>:
+ 26 2f mov r18, r22
+
+<__eewr_r18_EEPROM_SUFFIX>:
+ f9 99 sbic 0x1f, 1 ; 31
+ xx xx rjmp ; <__eewr_r18_EEPROM_SUFFIX>
+ 1f ba out 0x1f, r1 ; 31
+ 92 bd out 0x22, r25 ; 34
+ 81 bd out 0x21, r24 ; 33
+ 20 bd out 0x20, r18 ; 32
+ 0f b6 in r0, 0x3f ; 63
+ f8 94 cli
+ fa 9a sbi 0x1f, 2 ; 31
+ f9 9a sbi 0x1f, 1 ; 31
+ 0f be out 0x3f, r0 ; 63
+ 01 96 adiw r24, 0x01 ; 1
+ 08 95 ret
+
<_exit>:
f8 94 cli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment