1 /* Name: spminterface.h
2 * Project: USBaspLoader
3 * Author: Stephan Baerwolf
4 * Creation Date: 2012-08-01
5 * Copyright: (c) 2012 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 0x1e0e4
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 0x3e0e4
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 #define __do_spm_Ex_(flash_wordaddress, spmcrval, dataword, ___bootloader__do_spm__ptr) \
188 "mov r13, %B[flashaddress]\n\t" \
189 "mov r12, %A[flashaddress]\n\t" \
190 "mov r11, %C[flashaddress]\n\t" \
192 /* also load the spmcrval */ \
193 "mov r18, %[spmcrval]\n\t" \
196 "mov r1, %B[data]\n\t" \
197 "mov r0, %A[data]\n\t" \
199 /* finally call the bootloader-function */ \
203 * bootloader__do_spm should change spmcrval (r18) to \
204 * "((1<<RWWSRE) | (1<<SPMEN))" in case of success \
206 "cpi r18, %[spmret]\n\t" \
207 /* loop infitinte if not so, most likely we called an bootloader__do_spm \
208 * with wrong magic! To avoid calls to wrong initialized pages, better crash here... \
217 : [flashaddress] "r" (flash_wordaddress), \
218 [spmfunctionaddress] "z" ((uint16_t)(___bootloader__do_spm__ptr)), \
219 [spmcrval] "r" (spmcrval), \
220 [data] "r" (dataword), \
221 [spmret] "M" ((1<<RWWSRE) | (1<<SPMEN)) \
222 : "r0","r1","r11","r12","r13","r18" \
226 #define __do_spm_Ex_magic(flash_wordaddress, spmcrval, dataword, ___bootloader__do_spm__ptr) \
232 "ldi r23, %[magicD] \n\t" \
233 "ldi r22, %[magicC] \n\t" \
234 "ldi r21, %[magicB] \n\t" \
235 "ldi r20, %[magicA] \n\t" \
237 "mov r13, %B[flashaddress]\n\t" \
238 "mov r12, %A[flashaddress]\n\t" \
239 "mov r11, %C[flashaddress]\n\t" \
241 /* also load the spmcrval */ \
242 "mov r18, %[spmcrval]\n\t" \
245 "mov r1, %B[data]\n\t" \
246 "mov r0, %A[data]\n\t" \
248 /* finally call the bootloader-function */ \
252 * bootloader__do_spm should change spmcrval (r18) to \
253 * "((1<<RWWSRE) | (1<<SPMEN))" in case of success \
255 "cpi r18, %[spmret]\n\t" \
256 /* loop infitinte if not so, most likely we called an bootloader__do_spm \
257 * with wrong magic! To avoid calls to wrong initialized pages, better crash here... \
266 : [flashaddress] "r" (flash_wordaddress), \
267 [spmfunctionaddress] "z" ((uint16_t)(___bootloader__do_spm__ptr)), \
268 [spmcrval] "r" (spmcrval), \
269 [data] "r" (dataword), \
270 [spmret] "M" ((1<<RWWSRE) | (1<<SPMEN)), \
271 [magicD] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>>24)&0xff), \
272 [magicC] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>>16)&0xff), \
273 [magicB] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>> 8)&0xff), \
274 [magicA] "M" ((HAVE_SPMINTEREFACE_MAGICVALUE>> 0)&0xff) \
275 : "r0","r1","r11","r12","r13","r18","r20","r21","r22","r23" \
280 #if (!(defined(BOOTLOADER_ADDRESS))) || (defined(NEW_BOOTLOADER_ADDRESS))
281 void do_spm(const uint32_t flash_byteaddress
, const uint8_t spmcrval
, const uint16_t dataword
) {
282 __do_spm_Ex(flash_byteaddress
, spmcrval
, dataword
, funcaddr___bootloader__do_spm
>> 1);
286 #if HAVE_SPMINTEREFACE_NORETMAGIC
287 #define bootloader__do_spm_magic_exitstrategy(a) (0xf7f9)
289 #define bootloader__do_spm_magic_exitstrategy(a) (a)
292 #if (HAVE_SPMINTEREFACE) && (defined(BOOTLOADER_ADDRESS)) && (!(defined(NEW_BOOTLOADER_ADDRESS)))
295 * insert architecture dependend "bootloader_do_spm"-code
297 * try to make this array as big as possible
298 * (so bootloader always uses 2kbytes flash)
300 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) || defined (__AVR_ATmega8HVA__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
302 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) || defined (__AVR_ATmega8HVA__)
303 #if (BOOTLOADER_ADDRESS != 0x1800)
304 #error BOOTLOADER_ADDRESS!=0x1800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
306 #elif defined (__AVR_ATmega16__)
307 #if (BOOTLOADER_ADDRESS != 0x3800)
308 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
310 #elif defined (__AVR_ATmega32__)
311 #if (BOOTLOADER_ADDRESS != 0x7000)
312 #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
315 #error undefined device selection - this should not happen!
318 //assume SPMCR==0x37, SPMEN==0x0, RWWSRE=0x4, RWWSB=0x6
319 #if HAVE_SPMINTEREFACE_MAGICVALUE
320 const uint16_t bootloader__do_spm
[23] BOOTLIBLINK
= {
321 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
322 bootloader__do_spm_magic_exitstrategy(0xf4a1), // brne +20
323 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
324 bootloader__do_spm_magic_exitstrategy(0xf491), // brne +18
325 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
326 bootloader__do_spm_magic_exitstrategy(0xf481), // brne +16
327 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
328 bootloader__do_spm_magic_exitstrategy(0xf471), // brne +14
330 const uint16_t bootloader__do_spm
[15] BOOTLIBLINK
= {
332 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
333 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
337 00001826 <bootloader__do_spm>:
338 1828: ec 2d mov r30, r12
339 182a: fd 2d mov r31, r13
342 182c: b7 b6 in r11, 0x37 ; 55
343 182e: b0 fc sbrc r11, 0
344 1830: fd cf rjmp .-6 ; 0x182c <waitA>
345 1832: 27 bf out 0x37, r18 ; 55
349 1836: b7 b6 in r11, 0x37 ; 55
350 1838: b0 fc sbrc r11, 0
351 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
352 183c: 21 e1 ldi r18, 0x11 ; 17
353 183e: b7 b6 in r11, 0x37 ; 55
354 1840: b6 fc sbrc r11, 6
355 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
363 #elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega48P__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega88P__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__)
365 #if defined (__AVR_ATmega88__) || defined (__AVR_ATmega88P__)
366 #if (BOOTLOADER_ADDRESS != 0x1800)
367 #error BOOTLOADER_ADDRESS!=0x1800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
369 #elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__)
370 #if (BOOTLOADER_ADDRESS != 0x3800)
371 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
374 #error undefined device selection - this should not happen!
377 //assume SPMCR:=SPMCSR==0x37, SPMEN:=SELFPRGEN==0x0, RWWSRE=0x4, RWWSB=0x6
378 #if HAVE_SPMINTEREFACE_MAGICVALUE
379 const uint16_t bootloader__do_spm
[23] BOOTLIBLINK
= {
380 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
381 bootloader__do_spm_magic_exitstrategy(0xf4a1), // brne +20
382 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
383 bootloader__do_spm_magic_exitstrategy(0xf491), // brne +18
384 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
385 bootloader__do_spm_magic_exitstrategy(0xf481), // brne +16
386 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
387 bootloader__do_spm_magic_exitstrategy(0xf471), // brne +14
389 const uint16_t bootloader__do_spm
[15] BOOTLIBLINK
= {
391 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
392 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
395 00001826 <bootloader__do_spm>:
396 1828: ec 2d mov r30, r12
397 182a: fd 2d mov r31, r13
400 182c: b7 b6 in r11, 0x37 ; 55
401 182e: b0 fc sbrc r11, 0
402 1830: fd cf rjmp .-6 ; 0x182c <waitA>
403 1832: 27 bf out 0x37, r18 ; 55
407 1836: b7 b6 in r11, 0x37 ; 55
408 1838: b0 fc sbrc r11, 0
409 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
410 183c: 21 e1 ldi r18, 0x11 ; 17
411 183e: b7 b6 in r11, 0x37 ; 55
412 1840: b6 fc sbrc r11, 6
413 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
421 #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__)
423 #if defined (__AVR_ATmega88A__) || defined (__AVR_ATmega88PA__)
424 #if (BOOTLOADER_ADDRESS != 0x1800)
425 #error BOOTLOADER_ADDRESS!=0x1800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
427 #elif defined (__AVR_ATmega168A__) || defined (__AVR_ATmega168PA__)
428 #if (BOOTLOADER_ADDRESS != 0x3800)
429 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
431 #elif defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
432 #if (BOOTLOADER_ADDRESS != 0x7000)
433 #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
436 #error undefined device selection - this should not happen!
439 //assume SPMCR:=SPMCSR==0x37, SPMEN:=SELFPRGEN==0x0, RWWSRE=0x4, RWWSB=0x6
440 #if HAVE_SPMINTEREFACE_MAGICVALUE
441 const uint16_t bootloader__do_spm
[23] BOOTLIBLINK
= {
442 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
443 bootloader__do_spm_magic_exitstrategy(0xf4a1), // brne +20
444 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
445 bootloader__do_spm_magic_exitstrategy(0xf491), // brne +18
446 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
447 bootloader__do_spm_magic_exitstrategy(0xf481), // brne +16
448 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
449 bootloader__do_spm_magic_exitstrategy(0xf471), // brne +14
451 const uint16_t bootloader__do_spm
[15] BOOTLIBLINK
= {
453 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
454 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
457 00001826 <bootloader__do_spm>:
458 1828: ec 2d mov r30, r12
459 182a: fd 2d mov r31, r13
462 182c: b7 b6 in r11, 0x37 ; 55
463 182e: b0 fc sbrc r11, 0
464 1830: fd cf rjmp .-6 ; 0x182c <waitA>
465 1832: 27 bf out 0x37, r18 ; 55
469 1836: b7 b6 in r11, 0x37 ; 55
470 1838: b0 fc sbrc r11, 0
471 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
472 183c: 21 e1 ldi r18, 0x11 ; 17
473 183e: b7 b6 in r11, 0x37 ; 55
474 1840: b6 fc sbrc r11, 6
475 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
483 #elif defined (__AVR_ATmega128__)
485 #if defined (__AVR_ATmega128__)
486 #if (BOOTLOADER_ADDRESS != 0x1E000)
487 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
490 #error undefined device selection - this should not happen!
493 //assume SPMCR:=SPMCSR==0x68, SPMEN==0x0, RWWSRE=0x4, RWWSB=0x6 and rampZ=0x3b
494 #if HAVE_SPMINTEREFACE_MAGICVALUE
495 const uint16_t bootloader__do_spm
[28] BOOTLIBLINK
= {
496 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
497 bootloader__do_spm_magic_exitstrategy(0xf4c9), // brne +21+4
498 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
499 bootloader__do_spm_magic_exitstrategy(0xf4b9), // brne +19+4
500 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
501 bootloader__do_spm_magic_exitstrategy(0xf4a9), // brne +17+4
502 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
503 bootloader__do_spm_magic_exitstrategy(0xf499), // brne +15+4
505 const uint16_t bootloader__do_spm
[20] BOOTLIBLINK
= {
507 0xbebb, 0x2dec, 0x2dfd, 0x90b0, 0x0068, 0xfcb0, 0xcffc, 0x9320, 0x0068,
508 0x95e8, 0x90b0, 0x0068, 0xfcb0, 0xcffc, 0xe121, 0x90b0, 0x0068, 0xfcb6,
512 0001e08c <bootloader__do_spm>:
513 1e08c: bb be out 0x3b, r11 ; 59
514 1e08e: ec 2d mov r30, r12
515 1e090: fd 2d mov r31, r13
518 1e092: b0 90 68 00 lds r11, 0x0068
519 1e096: b0 fc sbrc r11, 0
520 1e098: fc cf rjmp .-8 ; 0x1e092 <waitA>
521 1e09a: 20 93 68 00 sts 0x0068, r18
525 1e0a0: b0 90 68 00 lds r11, 0x0068
526 1e0a4: b0 fc sbrc r11, 0
527 1e0a6: fc cf rjmp .-8 ; 0x1e0a0 <waitB>
528 1e0a8: 21 e1 ldi r18, 0x11 ; 17
529 1e0aa: b0 90 68 00 lds r11, 0x0068
530 1e0ae: b6 fc sbrc r11, 6
531 1e0b0: f0 cf rjmp .-32 ; 0x1e092 <waitA>
539 #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__)
541 #if defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__)
542 #if (BOOTLOADER_ADDRESS != 0x3800)
543 #error BOOTLOADER_ADDRESS!=0x3800, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
545 #elif defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324PA__)
546 #if (BOOTLOADER_ADDRESS != 0x7000)
547 #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
549 #elif defined (__AVR_ATmega640__)
550 #if (BOOTLOADER_ADDRESS != 0xE000)
551 #error BOOTLOADER_ADDRESS!=0xE000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
553 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
554 #if (BOOTLOADER_ADDRESS != 0xE000)
555 #error BOOTLOADER_ADDRESS!=0xE000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
557 #elif defined (__AVR_ATmega1280__)
558 #if (BOOTLOADER_ADDRESS != 0x1E000)
559 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
561 #elif defined (__AVR_ATmega1281__)
562 #if (BOOTLOADER_ADDRESS != 0x1E000)
563 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
565 #elif defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
566 #if (BOOTLOADER_ADDRESS != 0x1E000)
567 #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
569 #elif defined (__AVR_ATmega2560__)
570 #if (BOOTLOADER_ADDRESS != 0x3E000)
571 #error BOOTLOADER_ADDRESS!=0x3E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
573 #elif defined (__AVR_ATmega2561__)
574 #if (BOOTLOADER_ADDRESS != 0x3E000)
575 #error BOOTLOADER_ADDRESS!=0x3E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
578 #error undefined device selection - this should not happen!
581 //assume SPMCR:=SPCSR==0x37, SPMEN==0x0, RWWSRE=0x4, RWWSB=0x6 and rampZ=0x3b
582 #if HAVE_SPMINTEREFACE_MAGICVALUE
583 const uint16_t bootloader__do_spm
[24] BOOTLIBLINK
= {
584 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 28) & 0xf))<<8) | (0x70 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 24) & 0xf))), // r23
585 bootloader__do_spm_magic_exitstrategy(0xf4a9), // brne +21
586 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 20) & 0xf))<<8) | (0x60 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 16) & 0xf))), // r22
587 bootloader__do_spm_magic_exitstrategy(0xf499), // brne +19
588 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 12) & 0xf))<<8) | (0x50 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 8) & 0xf))), // r21
589 bootloader__do_spm_magic_exitstrategy(0xf489), // brne +17
590 (((0x30 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 4) & 0xf))<<8) | (0x40 | ((HAVE_SPMINTEREFACE_MAGICVALUE
>> 0) & 0xf))), // r20
591 bootloader__do_spm_magic_exitstrategy(0xf479), // brne +15
593 const uint16_t bootloader__do_spm
[16] BOOTLIBLINK
= {
596 0x2dec, 0x2dfd, 0xb6b7, 0xfcb0, 0xcffd, 0xbf27, 0x95e8, 0xb6b7,
597 0xfcb0, 0xcffd, 0xe121, 0xb6b7, 0xfcb6, 0xcff4, 0x9508
600 00001826 <bootloader__do_spm>:
601 1826: bb be out 0x3b,r11 ; rampZ=r11; (rampZ is at IO 0x3b)
602 1828: ec 2d mov r30, r12
603 182a: fd 2d mov r31, r13
606 182c: b7 b6 in r11, 0x37 ; 55
607 182e: b0 fc sbrc r11, 0
608 1830: fd cf rjmp .-6 ; 0x182c <waitA>
609 1832: 27 bf out 0x37, r18 ; 55
613 1836: b7 b6 in r11, 0x37 ; 55
614 1838: b0 fc sbrc r11, 0
615 183a: fd cf rjmp .-6 ; 0x1836 <waitB>
616 183c: 21 e1 ldi r18, 0x11 ; 17
617 183e: b7 b6 in r11, 0x37 ; 55
618 1840: b6 fc sbrc r11, 6
619 1842: f4 cf rjmp .-24 ; 0x182c <waitA>
628 #error "bootloader__do_spm has to be adapted, since there is no architecture code, yet"