1 /* Name: spminterface.h
2 * Project: USBaspLoader
3 * Author: Stephan Baerwolf
4 * Creation Date: 2012-08-01
5 * Copyright: (c) 2013 by Stephan Baerwolf
6 * License: GNU GPL v2 (see License.txt)
10 #ifndef SPMINTERFACE_H_f70ba6adf7624275947e859bdbff0599
11 #define SPMINTERFACE_H_f70ba6adf7624275947e859bdbff0599
14 * spminterface.h offers a lightweight interface by inserting
15 * an small machine-subroutine into the bootsection. (right
16 * after the interrupt-vector-table)
17 * This subroutine can be called by normal code in order to
18 * enable it to program the flash (and depending on BLB11-lockbit
19 * also the bootsection itself). Since SPM-calls from RWW-sections
20 * will fail to work. The routine will be called "bootloader__do_spm".
21 * Its principle assembler-code is depicted below (real code is a
22 * little machinedependend).
23 * Interfaces will be the 8-bit registers r10..r13, for details
24 * also see below. As also the pageaddress-registes (Z and rampZ)
25 * are interfaced via different registers, it is possible to call
26 * this routine via indirect call (icall).
27 * Traditionally it is also possible to rcall, therefore you can
28 * define "bootloader__do_spm" for your normal code via defsym at
30 * Example for an atmega8: "-Wl,--defsym=transfer_point=0x1826"
31 * (since BOOTLOADER_ADDRESS is 0x1800 and there are
32 * 2x19 = 38 = 0x26 byte for interrupts)
36 ;disable interrupts (if enabled) before calling!
37 ;you may also want to disable wdt, since this routine may busy-loop
38 ;==================================================================
40 ;#if HAVE_SPMINTEREFACE_MAGICVALUE
41 ;magicvalue in r23:r22:r21:r20
43 ;spmcr (spmcrval determines SPM action) will be register: r18
44 ;MCU dependend RA(MPZ should be transfered within register: r11
45 ;lo8(Z) should be transfered within register: r12
46 ;hi8(Z) should be transfered within register: r13
47 ;( as definition of SPM low8bit of dataword are stored within r0 )
48 ;( as definition of SPM hi8bit of dataword are stored within r1 )
51 ;temp0 will be register: r11
52 ;temp1 will be register: r12
53 ;temp2 will be register: r13
54 ;spmcrval (r18) may also be changed due to rww reenable-phase r18
55 ;Z (r31:r30) wil be changed during operation
58 ;==================================================================
59 ; TODO: waitA and waitB could be merged to subroutine saving 2 opc
60 ;==================================================================
61 ;<magicvalue specific code (not depicted here)>
62 ;load pageaddress (Z) from (r11:)r13:12 since it may was used for icall
67 waitA: ;check for pending SPM complete
72 out SPMCR, spmcrval ;SPM timed sequence
75 waitB: ;check for previous SPM complete
80 ;avoid crash of userapplication
81 ldi spmcrval, ((1<<RWWSRE) | (1<<SPMEN))
92 #include "bootloaderconfig.h"
97 * This MACRO commands the linker to place correspondig
98 * data on the top of the firmware. (Right after the
99 * interrupt-vector-table)
100 * This is necessary to always locate the
101 * "bootloader__do_spm" for example at 0x1826, even if
102 * there are existing PROGMEM within the firmware...
104 #define BOOTLIBLINK __attribute__ ((section (".vectors") ))
107 #ifndef funcaddr___bootloader__do_spm
108 #if (defined(BOOTLOADER_ADDRESS)) && (!(defined(NEW_BOOTLOADER_ADDRESS)))
109 #if HAVE_SPMINTEREFACE
110 #define funcaddr___bootloader__do_spm (&bootloader__do_spm)
113 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) || defined (__AVR_ATmega8HVA__)
114 #define funcaddr___bootloader__do_spm 0x1826
115 #elif defined (__AVR_ATmega16__)
116 #define funcaddr___bootloader__do_spm 0x3854
117 #elif defined (__AVR_ATmega32__)
118 #define funcaddr___bootloader__do_spm 0x7054
119 #elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega88P__) || defined (__AVR_ATmega88A__) || defined (__AVR_ATmega88PA__)
120 #define funcaddr___bootloader__do_spm 0x1834
121 #elif defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__)
122 #define funcaddr___bootloader__do_spm 0x387c
123 #elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__) || defined (__AVR_ATmega168A__) || defined (__AVR_ATmega168PA__)
124 #define funcaddr___bootloader__do_spm 0x3868
125 #elif defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324PA__)
126 #define funcaddr___bootloader__do_spm 0x707c
127 #elif defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
128 #define funcaddr___bootloader__do_spm 0x7068
129 #elif defined (__AVR_ATmega640__)
130 #define funcaddr___bootloader__do_spm 0xe0e4
131 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
132 #define funcaddr___bootloader__do_spm 0xe07c
133 #elif defined (__AVR_ATmega128__)
134 #define funcaddr___bootloader__do_spm 0x1e08c
135 #elif defined (__AVR_ATmega1280__)
136 #define funcaddr___bootloader__do_spm 0x1e0e4
137 #elif defined (__AVR_ATmega1281__)
138 #define funcaddr___bootloader__do_spm 0x1e0cc
139 #elif defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
140 #define funcaddr___bootloader__do_spm 0x1e08c
141 #elif defined (__AVR_ATmega2560__)
142 #define funcaddr___bootloader__do_spm 0x3e0e4
143 #elif defined (__AVR_ATmega2561__)
144 #define funcaddr___bootloader__do_spm 0x3e0cc
146 #error "unknown MCU - where is bootloader__do_spm located?"
149 #if defined(_VECTORS_SIZE)
150 #if (funcaddr___bootloader__do_spm != (BOOTLOADER_ADDRESS+_VECTORS_SIZE))
151 #error "bootloader__do_spm is not located after interrupts - sth. is very wrong here!"
160 #define SPMEN SELFPRGEN
164 * Call the "bootloader__do_spm"-function, located within the BLS via comfortable C-interface
165 * During operation code will block - disable or reset watchdog before call.
167 * ATTANTION: Since the underlying "bootloader__do_spm" will automatically reenable the
168 * rww-section, only one way to program the flash will work.
169 * (First erase the page, then fill temp. buffer, finally program...)
170 * Since unblocking rww-section erases the temp. pagebuffer (which happens
171 * after a page-erase), first programming this buffer does not help !!
173 * REMEMBER: interrupts have to be disabled! (otherwise code may crash non-deterministic)
176 #if HAVE_SPMINTEREFACE_MAGICVALUE
177 #define __do_spm_Ex __do_spm_Ex_magic
179 #define __do_spm_Ex __do_spm_Ex_
182 #if (defined(EIND) && ((FLASHEND)>131071))
184 * Huge flash version using eicall (and EIND)
186 #define __do_spm_Ex_(flash_wordaddress, spmcrval, dataword, ___bootloader__do_spm__ptr) \
192 "mov r13, %B[flashaddress]\n\t" \
193 "mov r12, %A[flashaddress]\n\t" \
194 "mov r11, %C[flashaddress]\n\t" \
196 /* prepare the EIND for following eicall */ \
197 "in r18, %[eind]\n\t" \
199 "ldi r18, %[spmfuncaddrEIND]\n\t" \
200 "out %[eind], r18\n\t" \
202 /* also load the spmcrval */ \
203 "mov r18, %[spmcrval]\n\t" \
206 "mov r1, %B[data]\n\t" \
207 "mov r0, %A[data]\n\t" \
209 /* finally call the bootloader-function */ \
212 "out %[eind], r1\n\t" \
215 * bootloader__do_spm should change spmcrval (r18) to \
216 * "((1<<RWWSRE) | (1<<SPMEN))" in case of success \
218 "cpi r18, %[spmret]\n\t" \
219 /* loop infitinte if not so, most likely we called an bootloader__do_spm \
220 * with wrong magic! To avoid calls to wrong initialized pages, better crash here... \
229 : [flashaddress] "r" (flash_wordaddress), \
230 [spmfunctionaddress] "z" ((uint16_t)(___bootloader__do_spm__ptr)), \
231 [spmfuncaddrEIND] "M" ((uint8_t)(___bootloader__do_spm__ptr>>16)), \
232 [eind] "I" (_SFR_IO_ADDR(EIND)), \
233 [spmcrval] "r" (spmcrval), \
234 [data] "r" (dataword), \
235 [spmret] "M" ((1<<RWWSRE) | (1<<SPMEN)) \
236 : "r0","r1","r11","r12","r13","r18" \
240 #define __do_spm_Ex_magic(flash_wordaddress, spmcrval, dataword, ___bootloader__do_spm__ptr) \
246 "ldi r23, %[magicD] \n\t" \
247 "ldi r22, %[magicC] \n\t" \
248 "ldi r21, %[magicB] \n\t" \
249 "ldi r20, %[magicA] \n\t" \
251 "mov r13, %B[flashaddress]\n\t" \
252 "mov r12, %A[flashaddress]\n\t" \
253 "mov r11, %C[flashaddress]\n\t" \
255 /* prepare the EIND for following eicall */ \
256 "in r18, %[eind]\n\t" \
258 "ldi r18, %[spmfuncaddrEIND]\n\t" \
259 "out %[eind], r18\n\t" \
261 /* also load the spmcrval */ \
262 "mov r18, %[spmcrval]\n\t" \
265 "mov r1, %B[data]\n\t" \
266 "mov r0, %A[data]\n\t" \
268 /* finally call the bootloader-function */ \
271 "out %[eind], r1\n\t" \
274 * bootloader__do_spm should change spmcrval (r18) to \
275 * "((1<<RWWSRE) | (1<<SPMEN))" in case of success \
277 "cpi r18, %[spmret]\n\t" \
278 /* loop infitinte if not so, most likely we called an bootloader__do_spm \
279 * with wrong magic! To avoid calls to wrong initialized pages, better crash here... \
288 : [flashaddress] "r" (flash_wordaddress), \
289 [spmfunctionaddress] "z" ((uint16_t)(___bootloader__do_spm__ptr)), \
290 [spmfuncaddrEIND] "M" ((uint8_t)(___bootloader__do_spm__ptr>>16)), \
291 [eind] "I" (_SFR_IO_ADDR(EIND)), \
292 [spmcrval] "r" (spmcrval), \
293 [data] "r" (dataword), \
294 [spmret] "M" ((1<<RWWSRE) | (1<<SPMEN)), \
295 [magicD] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>>24)&0xff), \
296 [magicC] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>>16)&0xff), \
297 [magicB] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>> 8)&0xff), \
298 [magicA] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>> 0)&0xff) \
299 : "r0","r1","r11","r12","r13","r18","r20","r21","r22","r23" \
306 * Normal version for devices with <=128KiB flash (using icall)
308 #if ((FLASHEND)>131071)
309 #error "Using inappropriate code for device with more than 128kib flash"
312 #define __do_spm_Ex_(flash_wordaddress, spmcrval, dataword, ___bootloader__do_spm__ptr) \
318 "mov r13, %B[flashaddress]\n\t" \
319 "mov r12, %A[flashaddress]\n\t" \
320 "mov r11, %C[flashaddress]\n\t" \
322 /* also load the spmcrval */ \
323 "mov r18, %[spmcrval]\n\t" \
326 "mov r1, %B[data]\n\t" \
327 "mov r0, %A[data]\n\t" \
329 /* finally call the bootloader-function */ \
333 * bootloader__do_spm should change spmcrval (r18) to \
334 * "((1<<RWWSRE) | (1<<SPMEN))" in case of success \
336 "cpi r18, %[spmret]\n\t" \
337 /* loop infitinte if not so, most likely we called an bootloader__do_spm \
338 * with wrong magic! To avoid calls to wrong initialized pages, better crash here... \
347 : [flashaddress] "r" (flash_wordaddress), \
348 [spmfunctionaddress] "z" ((uint16_t)(___bootloader__do_spm__ptr)), \
349 [spmcrval] "r" (spmcrval), \
350 [data] "r" (dataword), \
351 [spmret] "M" ((1<<RWWSRE) | (1<<SPMEN)) \
352 : "r0","r1","r11","r12","r13","r18" \
356 #define __do_spm_Ex_magic(flash_wordaddress, spmcrval, dataword, ___bootloader__do_spm__ptr) \
362 "ldi r23, %[magicD] \n\t" \
363 "ldi r22, %[magicC] \n\t" \
364 "ldi r21, %[magicB] \n\t" \
365 "ldi r20, %[magicA] \n\t" \
367 "mov r13, %B[flashaddress]\n\t" \
368 "mov r12, %A[flashaddress]\n\t" \
369 "mov r11, %C[flashaddress]\n\t" \
371 /* also load the spmcrval */ \
372 "mov r18, %[spmcrval]\n\t" \
375 "mov r1, %B[data]\n\t" \
376 "mov r0, %A[data]\n\t" \
378 /* finally call the bootloader-function */ \
382 * bootloader__do_spm should change spmcrval (r18) to \
383 * "((1<<RWWSRE) | (1<<SPMEN))" in case of success \
385 "cpi r18, %[spmret]\n\t" \
386 /* loop infitinte if not so, most likely we called an bootloader__do_spm \
387 * with wrong magic! To avoid calls to wrong initialized pages, better crash here... \
396 : [flashaddress] "r" (flash_wordaddress), \
397 [spmfunctionaddress] "z" ((uint16_t)(___bootloader__do_spm__ptr)), \
398 [spmcrval] "r" (spmcrval), \
399 [data] "r" (dataword), \
400 [spmret] "M" ((1<<RWWSRE) | (1<<SPMEN)), \
401 [magicD] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>>24)&0xff), \
402 [magicC] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>>16)&0xff), \
403 [magicB] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>> 8)&0xff), \
404 [magicA] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>> 0)&0xff) \
405 : "r0","r1","r11","r12","r13","r18","r20","r21","r22","r23" \
410 #if (!(defined(BOOTLOADER_ADDRESS))) || (defined(NEW_BOOTLOADER_ADDRESS))
411 void do_spm(const uint32_t flash_byteaddress
, const uint8_t spmcrval
, const uint16_t dataword
) {
412 __do_spm_Ex(flash_byteaddress
, spmcrval
, dataword
, funcaddr___bootloader__do_spm
>> 1);
416 #if HAVE_SPMINTEREFACE_NORETMAGIC
417 #define bootloader__do_spm_magic_exitstrategy(a) (0xf7f9)
419 #define bootloader__do_spm_magic_exitstrategy(a) (a)
422 #if (HAVE_SPMINTEREFACE) && (defined(BOOTLOADER_ADDRESS)) && (!(defined(NEW_BOOTLOADER_ADDRESS)))
425 * insert architecture dependend "bootloader_do_spm"-code
427 * try to make this array as big as possible
428 * (so bootloader always uses 2kbytes flash)
430 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) || defined (__AVR_ATmega8HVA__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
432 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) || defined (__AVR_ATmega8HVA__)
433 #if (BOOTLOADER_ADDRESS != 0x1800)
434 #error BOOTLOADER_ADDRESS!=0x1800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
436 #elif defined (__AVR_ATmega16__)
437 #if (BOOTLOADER_ADDRESS != 0x3800)
438 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
440 #elif defined (__AVR_ATmega32__)
441 #if (BOOTLOADER_ADDRESS != 0x7000)
442 #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
445 #error undefined device selection - this should not happen!
448 //assume SPMCR==0x37, SPMEN==0x0, RWWSRE=0x4, RWWSB=0x6
449 #if HAVE_SPMINTEREFACE_MAGICVALUE
450 const uint16_t bootloader__do_spm
[23] BOOTLIBLINK
= {
451 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
452 bootloader__do_spm_magic_exitstrategy(0xf4a1), // brne +20
453 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
454 bootloader__do_spm_magic_exitstrategy(0xf491), // brne +18
455 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
456 bootloader__do_spm_magic_exitstrategy(0xf481), // brne +16
457 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
458 bootloader__do_spm_magic_exitstrategy(0xf471), // brne +14
460 const uint16_t bootloader__do_spm
[15] BOOTLIBLINK
= {
462 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
463 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
467 00001826 <bootloader__do_spm>:
468 1828: ec 2d mov r30, r12
469 182a: fd 2d mov r31, r13
472 182c: b7 b6 in r11, 0x37 ; 55
473 182e: b0 fc sbrc r11, 0
474 1830: fd cf rjmp .-6 ; 0x182c <waitA>
475 1832: 27 bf out 0x37, r18 ; 55
479 1836: b7 b6 in r11, 0x37 ; 55
480 1838: b0 fc sbrc r11, 0
481 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
482 183c: 21 e1 ldi r18, 0x11 ; 17
483 183e: b7 b6 in r11, 0x37 ; 55
484 1840: b6 fc sbrc r11, 6
485 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
493 #elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega48P__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega88P__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__)
495 #if defined (__AVR_ATmega88__) || defined (__AVR_ATmega88P__)
496 #if (BOOTLOADER_ADDRESS != 0x1800)
497 #error BOOTLOADER_ADDRESS!=0x1800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
499 #elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__)
500 #if (BOOTLOADER_ADDRESS != 0x3800)
501 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
504 #error undefined device selection - this should not happen!
507 //assume SPMCR:=SPMCSR==0x37, SPMEN:=SELFPRGEN==0x0, RWWSRE=0x4, RWWSB=0x6
508 #if HAVE_SPMINTEREFACE_MAGICVALUE
509 const uint16_t bootloader__do_spm
[23] BOOTLIBLINK
= {
510 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
511 bootloader__do_spm_magic_exitstrategy(0xf4a1), // brne +20
512 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
513 bootloader__do_spm_magic_exitstrategy(0xf491), // brne +18
514 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
515 bootloader__do_spm_magic_exitstrategy(0xf481), // brne +16
516 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
517 bootloader__do_spm_magic_exitstrategy(0xf471), // brne +14
519 const uint16_t bootloader__do_spm
[15] BOOTLIBLINK
= {
521 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
522 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
525 00001826 <bootloader__do_spm>:
526 1828: ec 2d mov r30, r12
527 182a: fd 2d mov r31, r13
530 182c: b7 b6 in r11, 0x37 ; 55
531 182e: b0 fc sbrc r11, 0
532 1830: fd cf rjmp .-6 ; 0x182c <waitA>
533 1832: 27 bf out 0x37, r18 ; 55
537 1836: b7 b6 in r11, 0x37 ; 55
538 1838: b0 fc sbrc r11, 0
539 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
540 183c: 21 e1 ldi r18, 0x11 ; 17
541 183e: b7 b6 in r11, 0x37 ; 55
542 1840: b6 fc sbrc r11, 6
543 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
551 #elif defined (__AVR_ATmega48A__) || defined (__AVR_ATmega48PA__) || defined (__AVR_ATmega88A__) || defined (__AVR_ATmega88PA__) || defined (__AVR_ATmega168A__) || defined (__AVR_ATmega168PA__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
553 #if defined (__AVR_ATmega88A__) || defined (__AVR_ATmega88PA__)
554 #if (BOOTLOADER_ADDRESS != 0x1800)
555 #error BOOTLOADER_ADDRESS!=0x1800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
557 #elif defined (__AVR_ATmega168A__) || defined (__AVR_ATmega168PA__)
558 #if (BOOTLOADER_ADDRESS != 0x3800)
559 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
561 #elif defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
562 #if (BOOTLOADER_ADDRESS != 0x7000)
563 #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
566 #error undefined device selection - this should not happen!
569 //assume SPMCR:=SPMCSR==0x37, SPMEN:=SELFPRGEN==0x0, RWWSRE=0x4, RWWSB=0x6
570 #if HAVE_SPMINTEREFACE_MAGICVALUE
571 const uint16_t bootloader__do_spm
[23] BOOTLIBLINK
= {
572 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
573 bootloader__do_spm_magic_exitstrategy(0xf4a1), // brne +20
574 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
575 bootloader__do_spm_magic_exitstrategy(0xf491), // brne +18
576 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
577 bootloader__do_spm_magic_exitstrategy(0xf481), // brne +16
578 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
579 bootloader__do_spm_magic_exitstrategy(0xf471), // brne +14
581 const uint16_t bootloader__do_spm
[15] BOOTLIBLINK
= {
583 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
584 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
587 00001826 <bootloader__do_spm>:
588 1828: ec 2d mov r30, r12
589 182a: fd 2d mov r31, r13
592 182c: b7 b6 in r11, 0x37 ; 55
593 182e: b0 fc sbrc r11, 0
594 1830: fd cf rjmp .-6 ; 0x182c <waitA>
595 1832: 27 bf out 0x37, r18 ; 55
599 1836: b7 b6 in r11, 0x37 ; 55
600 1838: b0 fc sbrc r11, 0
601 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
602 183c: 21 e1 ldi r18, 0x11 ; 17
603 183e: b7 b6 in r11, 0x37 ; 55
604 1840: b6 fc sbrc r11, 6
605 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
613 #elif defined (__AVR_ATmega128__)
615 #if defined (__AVR_ATmega128__)
616 #if (BOOTLOADER_ADDRESS != 0x1E000)
617 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
620 #error undefined device selection - this should not happen!
623 //assume SPMCR:=SPMCSR==0x68, SPMEN==0x0, RWWSRE=0x4, RWWSB=0x6 and rampZ=0x3b
624 #if HAVE_SPMINTEREFACE_MAGICVALUE
625 const uint16_t bootloader__do_spm
[28] BOOTLIBLINK
= {
626 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
627 bootloader__do_spm_magic_exitstrategy(0xf4c9), // brne +21+4
628 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
629 bootloader__do_spm_magic_exitstrategy(0xf4b9), // brne +19+4
630 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
631 bootloader__do_spm_magic_exitstrategy(0xf4a9), // brne +17+4
632 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
633 bootloader__do_spm_magic_exitstrategy(0xf499), // brne +15+4
635 const uint16_t bootloader__do_spm
[20] BOOTLIBLINK
= {
637 0xbebb, 0x2dec, 0x2dfd, 0x90b0, 0x0068, 0xfcb0, 0xcffc, 0x9320, 0x0068,
638 0x95e8, 0x90b0, 0x0068, 0xfcb0, 0xcffc, 0xe121, 0x90b0, 0x0068, 0xfcb6,
642 0001e08c <bootloader__do_spm>:
643 1e08c: bb be out 0x3b, r11 ; 59
644 1e08e: ec 2d mov r30, r12
645 1e090: fd 2d mov r31, r13
648 1e092: b0 90 68 00 lds r11, 0x0068
649 1e096: b0 fc sbrc r11, 0
650 1e098: fc cf rjmp .-8 ; 0x1e092 <waitA>
651 1e09a: 20 93 68 00 sts 0x0068, r18
655 1e0a0: b0 90 68 00 lds r11, 0x0068
656 1e0a4: b0 fc sbrc r11, 0
657 1e0a6: fc cf rjmp .-8 ; 0x1e0a0 <waitB>
658 1e0a8: 21 e1 ldi r18, 0x11 ; 17
659 1e0aa: b0 90 68 00 lds r11, 0x0068
660 1e0ae: b6 fc sbrc r11, 6
661 1e0b0: f0 cf rjmp .-32 ; 0x1e092 <waitA>
669 #elif defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__) || defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324PA__) || defined (__AVR_ATmega640__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__) || defined (__AVR_ATmega1280__) || defined (__AVR_ATmega1281__) || defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__) || defined (__AVR_ATmega2560__) || defined (__AVR_ATmega2561__)
671 #if defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__)
672 #if (BOOTLOADER_ADDRESS != 0x3800)
673 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
675 #elif defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324PA__)
676 #if (BOOTLOADER_ADDRESS != 0x7000)
677 #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
679 #elif defined (__AVR_ATmega640__)
680 #if (BOOTLOADER_ADDRESS != 0xE000)
681 #error BOOTLOADER_ADDRESS!=0xE000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
683 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
684 #if (BOOTLOADER_ADDRESS != 0xE000)
685 #error BOOTLOADER_ADDRESS!=0xE000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
687 #elif defined (__AVR_ATmega1280__)
688 #if (BOOTLOADER_ADDRESS != 0x1E000)
689 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
691 #elif defined (__AVR_ATmega1281__)
692 #if (BOOTLOADER_ADDRESS != 0x1E000)
693 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
695 #elif defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
696 #if (BOOTLOADER_ADDRESS != 0x1E000)
697 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
699 #elif defined (__AVR_ATmega2560__)
700 #if (BOOTLOADER_ADDRESS != 0x3E000)
701 #error BOOTLOADER_ADDRESS!=0x3E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
703 #elif defined (__AVR_ATmega2561__)
704 #if (BOOTLOADER_ADDRESS != 0x3E000)
705 #error BOOTLOADER_ADDRESS!=0x3E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
708 #error undefined device selection - this should not happen!
711 //assume SPMCR:=SPCSR==0x37, SPMEN==0x0, RWWSRE=0x4, RWWSB=0x6 and rampZ=0x3b
712 #if HAVE_SPMINTEREFACE_MAGICVALUE
713 const uint16_t bootloader__do_spm
[24] BOOTLIBLINK
= {
714 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
715 bootloader__do_spm_magic_exitstrategy(0xf4a9), // brne +21
716 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
717 bootloader__do_spm_magic_exitstrategy(0xf499), // brne +19
718 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
719 bootloader__do_spm_magic_exitstrategy(0xf489), // brne +17
720 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
721 bootloader__do_spm_magic_exitstrategy(0xf479), // brne +15
723 const uint16_t bootloader__do_spm
[16] BOOTLIBLINK
= {
726 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
727 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
730 00001826 <bootloader__do_spm>:
731 1826: bb be out 0x3b,r11 ; rampZ=r11; (rampZ is at IO 0x3b)
732 1828: ec 2d mov r30, r12
733 182a: fd 2d mov r31, r13
736 182c: b7 b6 in r11, 0x37 ; 55
737 182e: b0 fc sbrc r11, 0
738 1830: fd cf rjmp .-6 ; 0x182c <waitA>
739 1832: 27 bf out 0x37, r18 ; 55
743 1836: b7 b6 in r11, 0x37 ; 55
744 1838: b0 fc sbrc r11, 0
745 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
746 183c: 21 e1 ldi r18, 0x11 ; 17
747 183e: b7 b6 in r11, 0x37 ; 55
748 1840: b6 fc sbrc r11, 6
749 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
758 #error "bootloader__do_spm has to be adapted, since there is no architecture code, yet"