Skip to content

Commit a78553b

Browse files
committed
Shrink code by using registers for variables "length" and "address"
http://code.google.com/p/optiboot/issues/detail?id=33 Fix high-value watchdog timeouts on ATmega8 http://code.google.com/p/optiboot/issues/detail?id=38 Change "start app on bad commands" code to start the app via the watchdog timer, so that the app is always started with the chip in fully reset state. http://code.google.com/p/optiboot/issues/detail?id=37
1 parent 2a83ee5 commit a78553b

19 files changed

+2344
-2315
lines changed

bootloaders/optiboot/optiboot.c

+21-13
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ asm(" .section .version\n"
198198
#define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE))
199199
#define WATCHDOG_2S (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE))
200200
#ifndef __AVR_ATmega8__
201-
#define WATCHDOG_4S (_BV(WDE3) | _BV(WDE))
202-
#define WATCHDOG_8S (_BV(WDE3) | _BV(WDE0) | _BV(WDE))
201+
#define WATCHDOG_4S (_BV(WDP3) | _BV(WDE))
202+
#define WATCHDOG_8S (_BV(WDP3) | _BV(WDP0) | _BV(WDE))
203203
#endif
204204

205205
/* Function Prototypes */
@@ -244,8 +244,6 @@ void appStart() __attribute__ ((naked));
244244
/* These definitions are NOT zero initialised, but that doesn't matter */
245245
/* This allows us to drop the zero init code, saving us memory */
246246
#define buff ((uint8_t*)(RAMSTART))
247-
#define address (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2))
248-
#define length (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+2))
249247
#ifdef VIRTUAL_BOOT_PARTITION
250248
#define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
251249
#define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
@@ -255,6 +253,13 @@ void appStart() __attribute__ ((naked));
255253
int main(void) {
256254
uint8_t ch;
257255

256+
/*
257+
* Making these local and in registers prevents the need for initializing
258+
* them, and also saves space because code no longer stores to memory.
259+
*/
260+
register uint16_t address;
261+
register uint8_t length;
262+
258263
// After the zero init loop, this is the first code to run.
259264
//
260265
// This code makes the following assumptions:
@@ -350,7 +355,9 @@ int main(void) {
350355
uint8_t *bufPtr;
351356
uint16_t addrPtr;
352357

353-
getLen();
358+
getch(); /* getlen() */
359+
length = getch();
360+
getch();
354361

355362
// If we are in RWW section, immediately start page erase
356363
if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
@@ -415,7 +422,10 @@ int main(void) {
415422
/* Read memory block mode, length is big endian. */
416423
else if(ch == STK_READ_PAGE) {
417424
// READ PAGE - we only read flash
418-
getLen();
425+
getch(); /* getlen() */
426+
length = getch();
427+
getch();
428+
419429
verifySpace();
420430
#ifdef VIRTUAL_BOOT_PARTITION
421431
do {
@@ -575,7 +585,11 @@ void getNch(uint8_t count) {
575585
}
576586

577587
void verifySpace() {
578-
if (getch() != CRC_EOP) appStart();
588+
if (getch() != CRC_EOP) {
589+
watchdogConfig(WATCHDOG_16MS); // shorten WD timeout
590+
while (1) // and busy-loop so that WD causes
591+
; // a reset and app start.
592+
}
579593
putch(STK_INSYNC);
580594
}
581595

@@ -595,12 +609,6 @@ void flash_led(uint8_t count) {
595609
}
596610
#endif
597611

598-
uint8_t getLen() {
599-
getch();
600-
length = getch();
601-
return getch();
602-
}
603-
604612
// Watchdog functions. These are only safe with interrupts turned off.
605613
void watchdogReset() {
606614
__asm__ __volatile__ (
+28-30
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
:107E0000112484B714BE81FFE6D085E08093810001
1+
:107E0000112484B714BE81FFE3D085E08093810004
22
:107E100082E08093C00088E18093C10086E0809377
3-
:107E2000C20080E18093C4008EE0CFD0259A86E026
3+
:107E2000C20080E18093C4008EE0BCD0259A86E039
44
:107E300020E33CEF91E0309385002093840096BBD3
5-
:107E4000B09BFECF1D9AA8958150A9F7DD24D3944D
6-
:107E5000A5E0EA2EF1E1FF2EABD0813421F481E0E0
7-
:107E6000C5D083E020C0823411F484E103C085349E
8-
:107E700019F485E0BBD091C0853581F499D0082FE5
9-
:107E800010E096D090E0982F8827802B912B880FB8
10-
:107E9000991F90930102809300027EC0863529F4D9
11-
:107EA00084E0A4D080E07CD078C0843609F04EC055
12-
:107EB00087D0E0910002F091010280E7E030F807FE
13-
:107EC00018F483E087BFE895C0E0D1E071D08993D2
14-
:107ED000809102028150809302028823B9F7E091D9
15-
:107EE0000002F091010280E7E030F80718F083E02B
16-
:107EF00087BFE89575D007B600FCFDCF4091000222
17-
:107F000050910102A0E0B1E02C9130E011968C91EB
18-
:107F1000119790E0982F8827822B932B1296FA01C5
19-
:107F20000C01D7BEE89511244E5F5F4FF1E0A038F9
20-
:107F3000BF0751F7E0910002F0910102E7BEE8951A
21-
:107F400007B600FCFDCFF7BEE89527C08437B9F42B
22-
:107F500037D046D0E0910002F09101023196F093C3
23-
:107F60000102E09300023197E4918E2F19D08091A5
24-
:107F70000202815080930202882361F70EC0853788
25-
:107F800039F42ED08EE10CD085E90AD08FE08BCF6A
26-
:107F9000813511F488E019D023D080E101D05CCF85
27-
:107FA000982F8091C00085FFFCCF9093C600089564
28-
:107FB000A8958091C00087FFFCCF8091C6000895EE
29-
:107FC000F7DFF6DF80930202F3CFE0E6F0E098E11E
30-
:107FD00090838083089580E0F8DFEE27FF270994DF
31-
:107FE000E7DF803209F0F7DF84E1DACF1F93182F43
32-
:0C7FF000DFDF1150E9F7F4DF1F91089566
5+
:107E4000B09BFECF1D9AA8958150A9F799249394D1
6+
:107E5000A5E0AA2EF1E1BF2E9DD0813421F481E06E
7+
:107E6000AFD083E01FC0823411F484E103C08534B5
8+
:107E700019F485E0A5D083C0853579F48BD0E82E40
9+
:107E8000FF2488D0082F10E0102F00270E291F296B
10+
:107E9000000F111F8DD0680172C0863529F484E06F
11+
:107EA0008FD080E06FD06BC0843609F042C072D0B2
12+
:107EB00071D0082F6FD080E0C81680E7D80620F474
13+
:107EC00083E0F60187BFE895C0E0D1E063D08993F5
14+
:107ED0000C17E1F7F0E0CF16F0E7DF0620F083E0C3
15+
:107EE000F60187BFE89564D007B600FCFDCFA60178
16+
:107EF000A0E0B1E02C9130E011968C91119790E0C8
17+
:107F0000982F8827822B932B1296FA010C0197BE8B
18+
:107F1000E89511244E5F5F4FF1E0A038BF0751F79D
19+
:107F2000F601A7BEE89507B600FCFDCFB7BEE89501
20+
:107F300026C08437B1F42ED02DD0F82E2BD038D0D7
21+
:107F4000F601EF2C8F010F5F1F4F84911BD0EA9435
22+
:107F5000F801C1F70894C11CD11CFA94CF0CD11CB4
23+
:107F60000EC0853739F424D08EE10CD085E90AD0D3
24+
:107F70008FE098CF813511F488E014D019D080E1DA
25+
:107F800001D06ACF982F8091C00085FFFCCF9093DD
26+
:107F9000C6000895A8958091C00087FFFCCF80910E
27+
:107FA000C6000895E0E6F0E098E1908380830895AC
28+
:107FB000F1DF803219F088E0F5DFFFCF84E1E2CF16
29+
:107FC0001F93182FE7DF1150E9F7F2DF1F91089593
30+
:0A7FD00080E0E8DFEE27FF270994A8
3331
:027FFE0001047C
3432
:0400000300007E007B
3533
:00000001FF

0 commit comments

Comments
 (0)