-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstk500boot.lst
6897 lines (6896 loc) · 286 KB
/
stk500boot.lst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1 .file "stk500boot.c"
2 __SP_H__ = 0x3e
3 __SP_L__ = 0x3d
4 __SREG__ = 0x3f
5 __RAMPZ__ = 0x3b
6 __tmp_reg__ = 0
7 __zero_reg__ = 1
8 .text
9 .Ltext0:
10 .cfi_sections .debug_frame
12 XorWithIv:
13 .LFB14:
14 .file 1 "stk500boot.c"
1:stk500boot.c **** /****************************************************************************
2:stk500boot.c **** Title: STK500v2 compatible bootloader
3:stk500boot.c **** Modified for Wiring board ATMega128-16MHz
4:stk500boot.c **** Author: Peter Fleury <[email protected]> http://jump.to/fleury
5:stk500boot.c **** Compiler: avr-gcc 3.4.5 or 4.1 / avr-libc 1.4.3
6:stk500boot.c **** Hardware: All AVRs with bootloader support, tested with ATmega8
7:stk500boot.c **** License: GNU General Public License
8:stk500boot.c ****
9:stk500boot.c **** Modified: Worapoht Kornkaewwattanakul <[email protected]> http://www.avride.com
10:stk500boot.c **** Date: 17 October 2007
11:stk500boot.c **** Update: 1st, 29 Dec 2007 : Enable CMD_SPI_MULTI but ignore unused command by return 0x00 byte re
12:stk500boot.c **** Compiler: WINAVR20060421
13:stk500boot.c **** Description: add timeout feature like previous Wiring bootloader
14:stk500boot.c ****
15:stk500boot.c **** DESCRIPTION:
16:stk500boot.c **** This program allows an AVR with bootloader capabilities to
17:stk500boot.c **** read/write its own Flash/EEprom. To enter Programming mode
18:stk500boot.c **** an input pin is checked. If this pin is pulled low, programming mode
19:stk500boot.c **** is entered. If not, normal execution is done from $0000
20:stk500boot.c **** "reset" vector in Application area.
21:stk500boot.c **** Size fits into a 1024 word bootloader section
22:stk500boot.c **** when compiled with avr-gcc 4.1
23:stk500boot.c **** (direct replace on Wiring Board without fuse setting changed)
24:stk500boot.c ****
25:stk500boot.c **** USAGE:
26:stk500boot.c **** - Set AVR MCU type and clock-frequency (F_CPU) in the Makefile.
27:stk500boot.c **** - Set baud rate below (AVRISP only works with 115200 bps)
28:stk500boot.c **** - compile/link the bootloader with the supplied Makefile
29:stk500boot.c **** - program the "Boot Flash section size" (BOOTSZ fuses),
30:stk500boot.c **** for boot-size 1024 words: program BOOTSZ01
31:stk500boot.c **** - enable the BOOT Reset Vector (program BOOTRST)
32:stk500boot.c **** - Upload the hex file to the AVR using any ISP programmer
33:stk500boot.c **** - Program Boot Lock Mode 3 (program BootLock 11 and BootLock 12 lock bits) // (leave them)
34:stk500boot.c **** - Reset your AVR while keeping PROG_PIN pulled low // (for enter bootloader by switch)
35:stk500boot.c **** - Start AVRISP Programmer (AVRStudio/Tools/Program AVR)
36:stk500boot.c **** - AVRISP will detect the bootloader
37:stk500boot.c **** - Program your application FLASH file and optional EEPROM file using AVRISP
38:stk500boot.c ****
39:stk500boot.c **** Note:
40:stk500boot.c **** Erasing the device without flashing, through AVRISP GUI button "Erase Device"
41:stk500boot.c **** is not implemented, due to AVRStudio limitations.
42:stk500boot.c **** Flash is always erased before programming.
43:stk500boot.c ****
44:stk500boot.c **** AVRdude:
45:stk500boot.c **** Please uncomment #define REMOVE_CMD_SPI_MULTI when using AVRdude.
46:stk500boot.c **** Comment #define REMOVE_PROGRAM_LOCK_BIT_SUPPORT to reduce code size
47:stk500boot.c **** Read Fuse Bits and Read/Write Lock Bits is not supported
48:stk500boot.c ****
49:stk500boot.c **** NOTES:
50:stk500boot.c **** Based on Atmel Application Note AVR109 - Self-programming
51:stk500boot.c **** Based on Atmel Application Note AVR068 - STK500v2 Protocol
52:stk500boot.c ****
53:stk500boot.c **** LICENSE:
54:stk500boot.c **** Copyright (C) 2006 Peter Fleury
55:stk500boot.c ****
56:stk500boot.c **** This program is free software; you can redistribute it and/or modify
57:stk500boot.c **** it under the terms of the GNU General Public License as published by
58:stk500boot.c **** the Free Software Foundation; either version 2 of the License, or
59:stk500boot.c **** any later version.
60:stk500boot.c ****
61:stk500boot.c **** This program is distributed in the hope that it will be useful,
62:stk500boot.c **** but WITHOUT ANY WARRANTY; without even the implied warranty of
63:stk500boot.c **** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64:stk500boot.c **** GNU General Public License for more details.
65:stk500boot.c ****
66:stk500boot.c **** *****************************************************************************/
67:stk500boot.c ****
68:stk500boot.c **** //************************************************************************
69:stk500boot.c **** //* Edit History
70:stk500boot.c **** //************************************************************************
71:stk500boot.c **** //* Jul 7, 2010 <MLS> = Mark Sproul [email protected]
72:stk500boot.c **** //* Jul 7, 2010 <MLS> Working on mega2560. No Auto-restart
73:stk500boot.c **** //* Jul 7, 2010 <MLS> Switched to 8K bytes (4K words) so that we have room for the monitor
74:stk500boot.c **** //* Jul 8, 2010 <MLS> Found older version of source that had auto restart, put that code back in
75:stk500boot.c **** //* Jul 8, 2010 <MLS> Adding monitor code
76:stk500boot.c **** //* Jul 11, 2010 <MLS> Added blinking LED while waiting for download to start
77:stk500boot.c **** //* Jul 11, 2010 <MLS> Added EEPROM test
78:stk500boot.c **** //* Jul 29, 2010 <MLS> Added recchar_timeout for timing out on bootloading
79:stk500boot.c **** //* Aug 23, 2010 <MLS> Added support for atmega2561
80:stk500boot.c **** //* Aug 26, 2010 <MLS> Removed support for BOOT_BY_SWITCH
81:stk500boot.c **** //* Sep 8, 2010 <MLS> Added support for atmega16
82:stk500boot.c **** //* Nov 9, 2010 <MLS> Issue 392:Fixed bug that 3 !!! in code would cause it to jump to monitor
83:stk500boot.c **** //* Jun 24, 2011 <MLS> Removed analogRead (was not used)
84:stk500boot.c **** //* Dec 29, 2011 <MLS> Issue 181: added watch dog timmer support
85:stk500boot.c **** //* Dec 29, 2011 <MLS> Issue 505: bootloader is comparing the seqNum to 1 or the current sequence
86:stk500boot.c **** //* Jan 1, 2012 <MLS> Issue 543: CMD_CHIP_ERASE_ISP now returns STATUS_CMD_FAILED instead of STATU
87:stk500boot.c **** //* Jan 1, 2012 <MLS> Issue 543: Write EEPROM now does something (NOT TESTED)
88:stk500boot.c **** //* Jan 1, 2012 <MLS> Issue 544: stk500v2 bootloader doesn't support reading fuses
89:stk500boot.c **** //************************************************************************
90:stk500boot.c ****
91:stk500boot.c **** //************************************************************************
92:stk500boot.c **** //* these are used to test issues
93:stk500boot.c **** //* http://code.google.com/p/arduino/issues/detail?id=505
94:stk500boot.c **** //* Reported by mark.stubbs, Mar 14, 2011
95:stk500boot.c **** //* The STK500V2 bootloader is comparing the seqNum to 1 or the current sequence
96:stk500boot.c **** //* (IE: Requiring the sequence to be 1 or match seqNum before continuing).
97:stk500boot.c **** //* The correct behavior is for the STK500V2 to accept the PC's sequence number, and echo it back f
98:stk500boot.c **** #define _FIX_ISSUE_505_
99:stk500boot.c **** //************************************************************************
100:stk500boot.c **** //* Issue 181: added watch dog timmer support
101:stk500boot.c **** #define _FIX_ISSUE_181_
102:stk500boot.c ****
103:stk500boot.c ****
104:stk500boot.c **** #include <inttypes.h>
105:stk500boot.c **** #include <avr/io.h>
106:stk500boot.c **** #include <avr/interrupt.h>
107:stk500boot.c **** #include <avr/boot.h>
108:stk500boot.c **** #include <avr/pgmspace.h>
109:stk500boot.c **** #include <util/delay.h>
110:stk500boot.c **** #include <avr/eeprom.h>
111:stk500boot.c **** #include <avr/common.h>
112:stk500boot.c **** #include <stdlib.h>
113:stk500boot.c **** #include "command.h"
114:stk500boot.c **** #include <string.h>
115:stk500boot.c **** // #include "aes.h"
116:stk500boot.c ****
117:stk500boot.c **** const unsigned char iv [] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0
118:stk500boot.c **** const unsigned char key[] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88
119:stk500boot.c ****
120:stk500boot.c **** #undef ENABLE_MONITOR
121:stk500boot.c ****
122:stk500boot.c ****
123:stk500boot.c ****
124:stk500boot.c **** // #if defined(_MEGA_BOARD_) || defined(_BOARD_AMBER128_) || defined(__AVR_ATmega1280__) || defined
125:stk500boot.c **** // || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1284P__) || defined(ENABLE_MONITOR)
126:stk500boot.c **** // #undef ENABLE_MONITOR
127:stk500boot.c **** // #define ENABLE_MONITOR
128:stk500boot.c **** // static void RunMonitor(void);
129:stk500boot.c **** // #endif
130:stk500boot.c ****
131:stk500boot.c **** #ifndef EEWE
132:stk500boot.c **** #define EEWE 1
133:stk500boot.c **** #endif
134:stk500boot.c **** #ifndef EEMWE
135:stk500boot.c **** #define EEMWE 2
136:stk500boot.c **** #endif
137:stk500boot.c ****
138:stk500boot.c **** //#define _DEBUG_SERIAL_
139:stk500boot.c **** //#define _DEBUG_WITH_LEDS_
140:stk500boot.c ****
141:stk500boot.c ****
142:stk500boot.c **** /*
143:stk500boot.c **** * Uncomment the following lines to save code space
144:stk500boot.c **** */
145:stk500boot.c **** #define REMOVE_PROGRAM_LOCK_BIT_SUPPORT // disable program lock bits
146:stk500boot.c **** #define REMOVE_BOOTLOADER_LED // no LED to show active bootloader
147:stk500boot.c **** #define REMOVE_CMD_SPI_MULTI // disable processing of SPI_MULTI commands, Remark this line for A
148:stk500boot.c **** //
149:stk500boot.c ****
150:stk500boot.c ****
151:stk500boot.c ****
152:stk500boot.c **** //************************************************************************
153:stk500boot.c **** //* LED on pin "PROGLED_PIN" on port "PROGLED_PORT"
154:stk500boot.c **** //* indicates that bootloader is active
155:stk500boot.c **** //* PG2 -> LED on Wiring board
156:stk500boot.c **** //************************************************************************
157:stk500boot.c **** //#define BLINK_LED_WHILE_WAITING
158:stk500boot.c ****
159:stk500boot.c **** #ifdef _MEGA_BOARD_
160:stk500boot.c **** #define PROGLED_PORT PORTB
161:stk500boot.c **** #define PROGLED_DDR DDRB
162:stk500boot.c **** #define PROGLED_PIN PINB7
163:stk500boot.c **** #elif defined( _BOARD_AMBER128_ )
164:stk500boot.c **** //* this is for the amber 128 http://www.soc-robotics.com/
165:stk500boot.c **** //* onbarod led is PORTE4
166:stk500boot.c **** #define PROGLED_PORT PORTD
167:stk500boot.c **** #define PROGLED_DDR DDRD
168:stk500boot.c **** #define PROGLED_PIN PINE7
169:stk500boot.c **** #elif defined( _CEREBOTPLUS_BOARD_ ) || defined(_CEREBOT_II_BOARD_)
170:stk500boot.c **** //* this is for the Cerebot 2560 board and the Cerebot-ii
171:stk500boot.c **** //* onbarod leds are on PORTE4-7
172:stk500boot.c **** #define PROGLED_PORT PORTE
173:stk500boot.c **** #define PROGLED_DDR DDRE
174:stk500boot.c **** #define PROGLED_PIN PINE7
175:stk500boot.c **** #elif defined( _PENGUINO_ )
176:stk500boot.c **** //* this is for the Penguino
177:stk500boot.c **** //* onbarod led is PORTE4
178:stk500boot.c **** #define PROGLED_PORT PORTC
179:stk500boot.c **** #define PROGLED_DDR DDRC
180:stk500boot.c **** #define PROGLED_PIN PINC6
181:stk500boot.c **** #elif defined( _ANDROID_2561_ ) || defined( __AVR_ATmega2561__ )
182:stk500boot.c **** //* this is for the Boston Android 2561
183:stk500boot.c **** //* onbarod led is PORTE4
184:stk500boot.c **** #define PROGLED_PORT PORTA
185:stk500boot.c **** #define PROGLED_DDR DDRA
186:stk500boot.c **** #define PROGLED_PIN PINA3
187:stk500boot.c **** #elif defined( _BOARD_MEGA16 )
188:stk500boot.c **** //* onbarod led is PORTA7
189:stk500boot.c **** #define PROGLED_PORT PORTA
190:stk500boot.c **** #define PROGLED_DDR DDRA
191:stk500boot.c **** #define PROGLED_PIN PINA7
192:stk500boot.c **** #define UART_BAUDRATE_DOUBLE_SPEED 0
193:stk500boot.c ****
194:stk500boot.c **** #elif defined( _BOARD_BAHBOT_ )
195:stk500boot.c **** //* dosent have an onboard LED but this is what will probably be added to this port
196:stk500boot.c **** #define PROGLED_PORT PORTB
197:stk500boot.c **** #define PROGLED_DDR DDRB
198:stk500boot.c **** #define PROGLED_PIN PINB0
199:stk500boot.c ****
200:stk500boot.c **** #elif defined( _BOARD_ROBOTX_ )
201:stk500boot.c **** #define PROGLED_PORT PORTB
202:stk500boot.c **** #define PROGLED_DDR DDRB
203:stk500boot.c **** #define PROGLED_PIN PINB6
204:stk500boot.c **** #elif defined( _BOARD_CUSTOM1284_BLINK_B0_ )
205:stk500boot.c **** #define PROGLED_PORT PORTB
206:stk500boot.c **** #define PROGLED_DDR DDRB
207:stk500boot.c **** #define PROGLED_PIN PINB0
208:stk500boot.c **** #elif defined( _BOARD_CUSTOM1284_ )
209:stk500boot.c **** #define PROGLED_PORT PORTD
210:stk500boot.c **** #define PROGLED_DDR DDRD
211:stk500boot.c **** #define PROGLED_PIN PIND5
212:stk500boot.c **** #elif defined( _AVRLIP_ )
213:stk500boot.c **** #define PROGLED_PORT PORTB
214:stk500boot.c **** #define PROGLED_DDR DDRB
215:stk500boot.c **** #define PROGLED_PIN PINB5
216:stk500boot.c **** #elif defined( _BOARD_STK500_ )
217:stk500boot.c **** #define PROGLED_PORT PORTA
218:stk500boot.c **** #define PROGLED_DDR DDRA
219:stk500boot.c **** #define PROGLED_PIN PINA7
220:stk500boot.c **** #elif defined( _BOARD_STK502_ )
221:stk500boot.c **** #define PROGLED_PORT PORTB
222:stk500boot.c **** #define PROGLED_DDR DDRB
223:stk500boot.c **** #define PROGLED_PIN PINB5
224:stk500boot.c **** #elif defined( _BOARD_STK525_ )
225:stk500boot.c **** #define PROGLED_PORT PORTB
226:stk500boot.c **** #define PROGLED_DDR DDRB
227:stk500boot.c **** #define PROGLED_PIN PINB7
228:stk500boot.c **** #else
229:stk500boot.c **** #define PROGLED_PORT PORTG
230:stk500boot.c **** #define PROGLED_DDR DDRG
231:stk500boot.c **** #define PROGLED_PIN PING2
232:stk500boot.c **** #endif
233:stk500boot.c ****
234:stk500boot.c ****
235:stk500boot.c ****
236:stk500boot.c **** /*
237:stk500boot.c **** * define CPU frequency in Mhz here if not defined in Makefile
238:stk500boot.c **** */
239:stk500boot.c **** #ifndef F_CPU
240:stk500boot.c **** #define F_CPU 16000000UL
241:stk500boot.c **** #endif
242:stk500boot.c ****
243:stk500boot.c **** #define _BLINK_LOOP_COUNT_ (F_CPU / 2250)
244:stk500boot.c **** /*
245:stk500boot.c **** * UART Baudrate, AVRStudio AVRISP only accepts 115200 bps
246:stk500boot.c **** */
247:stk500boot.c ****
248:stk500boot.c **** #ifndef BAUDRATE
249:stk500boot.c **** #define BAUDRATE 115200
250:stk500boot.c **** #endif
251:stk500boot.c ****
252:stk500boot.c **** /*
253:stk500boot.c **** * Enable (1) or disable (0) USART double speed operation
254:stk500boot.c **** */
255:stk500boot.c **** #ifndef UART_BAUDRATE_DOUBLE_SPEED
256:stk500boot.c **** #if defined (__AVR_ATmega32__)
257:stk500boot.c **** #define UART_BAUDRATE_DOUBLE_SPEED 0
258:stk500boot.c **** #else
259:stk500boot.c **** #define UART_BAUDRATE_DOUBLE_SPEED 1
260:stk500boot.c **** #endif
261:stk500boot.c **** #endif
262:stk500boot.c ****
263:stk500boot.c **** /*
264:stk500boot.c **** * HW and SW version, reported to AVRISP, must match version of AVRStudio
265:stk500boot.c **** */
266:stk500boot.c **** #define CONFIG_PARAM_BUILD_NUMBER_LOW 0
267:stk500boot.c **** #define CONFIG_PARAM_BUILD_NUMBER_HIGH 0
268:stk500boot.c **** #define CONFIG_PARAM_HW_VER 0x0F
269:stk500boot.c **** #define CONFIG_PARAM_SW_MAJOR 2
270:stk500boot.c **** #define CONFIG_PARAM_SW_MINOR 0x0A
271:stk500boot.c ****
272:stk500boot.c **** /*
273:stk500boot.c **** * Calculate the address where the bootloader starts from FLASHEND and BOOTSIZE
274:stk500boot.c **** * (adjust BOOTSIZE below and BOOTLOADER_ADDRESS in Makefile if you want to change the size of the
275:stk500boot.c **** */
276:stk500boot.c **** //#define BOOTSIZE 1024
277:stk500boot.c **** #if FLASHEND > 0x0F000
278:stk500boot.c **** #define BOOTSIZE 8192
279:stk500boot.c **** #else
280:stk500boot.c **** #define BOOTSIZE 2048
281:stk500boot.c **** #endif
282:stk500boot.c ****
283:stk500boot.c **** #define APP_END (FLASHEND -(2*BOOTSIZE) + 1)
284:stk500boot.c ****
285:stk500boot.c **** /*
286:stk500boot.c **** * Signature bytes are not available in avr-gcc io_xxx.h
287:stk500boot.c **** */
288:stk500boot.c **** #if defined (__AVR_ATmega8__)
289:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9307
290:stk500boot.c **** #elif defined (__AVR_ATmega16__)
291:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9403
292:stk500boot.c **** #elif defined (__AVR_ATmega32__)
293:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9502
294:stk500boot.c **** #elif defined (__AVR_ATmega8515__)
295:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9306
296:stk500boot.c **** #elif defined (__AVR_ATmega8535__)
297:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9308
298:stk500boot.c **** #elif defined (__AVR_ATmega162__)
299:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9404
300:stk500boot.c **** #elif defined (__AVR_ATmega128__)
301:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9702
302:stk500boot.c **** #elif defined (__AVR_ATmega1280__)
303:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9703
304:stk500boot.c **** #elif defined (__AVR_ATmega2560__)
305:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9801
306:stk500boot.c **** #elif defined (__AVR_ATmega2561__)
307:stk500boot.c **** #define SIGNATURE_BYTES 0x1e9802
308:stk500boot.c **** #elif defined (__AVR_ATmega1284P__)
309:stk500boot.c **** #define SIGNATURE_BYTES 0x1e9705
310:stk500boot.c **** #elif defined (__AVR_ATmega640__)
311:stk500boot.c **** #define SIGNATURE_BYTES 0x1e9608
312:stk500boot.c **** #elif defined (__AVR_ATmega64__)
313:stk500boot.c **** #define SIGNATURE_BYTES 0x1E9602
314:stk500boot.c **** #elif defined (__AVR_ATmega169__)
315:stk500boot.c **** #define SIGNATURE_BYTES 0x1e9405
316:stk500boot.c **** #elif defined (__AVR_AT90USB1287__)
317:stk500boot.c **** #define SIGNATURE_BYTES 0x1e9782
318:stk500boot.c **** #else
319:stk500boot.c **** #error "no signature definition for MCU available"
320:stk500boot.c **** #endif
321:stk500boot.c ****
322:stk500boot.c ****
323:stk500boot.c **** #if defined(_BOARD_ROBOTX_) || defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__)
324:stk500boot.c **** #define UART_BAUD_RATE_LOW UBRR1L
325:stk500boot.c **** #define UART_STATUS_REG UCSR1A
326:stk500boot.c **** #define UART_CONTROL_REG UCSR1B
327:stk500boot.c **** #define UART_ENABLE_TRANSMITTER TXEN1
328:stk500boot.c **** #define UART_ENABLE_RECEIVER RXEN1
329:stk500boot.c **** #define UART_TRANSMIT_COMPLETE TXC1
330:stk500boot.c **** #define UART_RECEIVE_COMPLETE RXC1
331:stk500boot.c **** #define UART_DATA_REG UDR1
332:stk500boot.c **** #define UART_DOUBLE_SPEED U2X1
333:stk500boot.c ****
334:stk500boot.c **** #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \
335:stk500boot.c **** || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__)
336:stk500boot.c **** /* ATMega8 with one USART */
337:stk500boot.c **** #define UART_BAUD_RATE_LOW UBRRL
338:stk500boot.c **** #define UART_STATUS_REG UCSRA
339:stk500boot.c **** #define UART_CONTROL_REG UCSRB
340:stk500boot.c **** #define UART_ENABLE_TRANSMITTER TXEN
341:stk500boot.c **** #define UART_ENABLE_RECEIVER RXEN
342:stk500boot.c **** #define UART_TRANSMIT_COMPLETE TXC
343:stk500boot.c **** #define UART_RECEIVE_COMPLETE RXC
344:stk500boot.c **** #define UART_DATA_REG UDR
345:stk500boot.c **** #define UART_DOUBLE_SPEED U2X
346:stk500boot.c ****
347:stk500boot.c **** #elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega162__) \
348:stk500boot.c **** || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
349:stk500boot.c **** /* ATMega with two USART, use UART0 */
350:stk500boot.c **** #define UART_BAUD_RATE_LOW UBRR0L
351:stk500boot.c **** #define UART_STATUS_REG UCSR0A
352:stk500boot.c **** #define UART_CONTROL_REG UCSR0B
353:stk500boot.c **** #define UART_ENABLE_TRANSMITTER TXEN0
354:stk500boot.c **** #define UART_ENABLE_RECEIVER RXEN0
355:stk500boot.c **** #define UART_TRANSMIT_COMPLETE TXC0
356:stk500boot.c **** #define UART_RECEIVE_COMPLETE RXC0
357:stk500boot.c **** #define UART_DATA_REG UDR0
358:stk500boot.c **** #define UART_DOUBLE_SPEED U2X0
359:stk500boot.c **** #elif defined(UBRR0L) && defined(UCSR0A) && defined(TXEN0)
360:stk500boot.c **** /* ATMega with two USART, use UART0 */
361:stk500boot.c **** #define UART_BAUD_RATE_LOW UBRR0L
362:stk500boot.c **** #define UART_STATUS_REG UCSR0A
363:stk500boot.c **** #define UART_CONTROL_REG UCSR0B
364:stk500boot.c **** #define UART_ENABLE_TRANSMITTER TXEN0
365:stk500boot.c **** #define UART_ENABLE_RECEIVER RXEN0
366:stk500boot.c **** #define UART_TRANSMIT_COMPLETE TXC0
367:stk500boot.c **** #define UART_RECEIVE_COMPLETE RXC0
368:stk500boot.c **** #define UART_DATA_REG UDR0
369:stk500boot.c **** #define UART_DOUBLE_SPEED U2X0
370:stk500boot.c **** #elif defined(UBRRL) && defined(UCSRA) && defined(UCSRB) && defined(TXEN) && defined(RXEN)
371:stk500boot.c **** //* catch all
372:stk500boot.c **** #define UART_BAUD_RATE_LOW UBRRL
373:stk500boot.c **** #define UART_STATUS_REG UCSRA
374:stk500boot.c **** #define UART_CONTROL_REG UCSRB
375:stk500boot.c **** #define UART_ENABLE_TRANSMITTER TXEN
376:stk500boot.c **** #define UART_ENABLE_RECEIVER RXEN
377:stk500boot.c **** #define UART_TRANSMIT_COMPLETE TXC
378:stk500boot.c **** #define UART_RECEIVE_COMPLETE RXC
379:stk500boot.c **** #define UART_DATA_REG UDR
380:stk500boot.c **** #define UART_DOUBLE_SPEED U2X
381:stk500boot.c **** #else
382:stk500boot.c **** #error "no UART definition for MCU available"
383:stk500boot.c **** #endif
384:stk500boot.c ****
385:stk500boot.c ****
386:stk500boot.c ****
387:stk500boot.c **** /*
388:stk500boot.c **** * Macro to calculate UBBR from XTAL and baudrate
389:stk500boot.c **** */
390:stk500boot.c **** #if defined(__AVR_ATmega32__) && UART_BAUDRATE_DOUBLE_SPEED
391:stk500boot.c **** #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu / 4 / baudRate - 1) / 2)
392:stk500boot.c **** #elif defined(__AVR_ATmega32__)
393:stk500boot.c **** #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu / 8 / baudRate - 1) / 2)
394:stk500boot.c **** #elif UART_BAUDRATE_DOUBLE_SPEED
395:stk500boot.c **** #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*8.0)-1.0+0.5)
396:stk500boot.c **** #else
397:stk500boot.c **** #define UART_BAUD_SELECT(baudRate,xtalCpu) (((float)(xtalCpu))/(((float)(baudRate))*16.0)-1.0+0.5)
398:stk500boot.c **** #endif
399:stk500boot.c ****
400:stk500boot.c ****
401:stk500boot.c ****
402:stk500boot.c ****
403:stk500boot.c **** /*
404:stk500boot.c **** * States used in the receive state machine
405:stk500boot.c **** */
406:stk500boot.c **** #define ST_START 0
407:stk500boot.c **** #define ST_GET_SEQ_NUM 1
408:stk500boot.c **** #define ST_MSG_SIZE_1 2
409:stk500boot.c **** #define ST_MSG_SIZE_2 3
410:stk500boot.c **** #define ST_GET_TOKEN 4
411:stk500boot.c **** #define ST_GET_DATA 5
412:stk500boot.c **** #define ST_GET_CHECK 6
413:stk500boot.c **** #define ST_PROCESS 7
414:stk500boot.c ****
415:stk500boot.c **** /*
416:stk500boot.c **** * States used in the encrypted command packet stage.
417:stk500boot.c **** */
418:stk500boot.c **** #define SOTA_MESSAGE_START 0x58
419:stk500boot.c **** #define SOTA_PACKET_RETRIEVE_START 0
420:stk500boot.c **** #define SOTA_PACKET_RETRIEVE_SIZE 1
421:stk500boot.c **** #define SOTA_PACKET_RETRIEVE_PROCESSING 2
422:stk500boot.c **** #define SOTA_PACKET_RETRIEVE_FINISHED 3
423:stk500boot.c ****
424:stk500boot.c **** /*
425:stk500boot.c **** * use 16bit address variable for ATmegas with <= 64K flash
426:stk500boot.c **** */
427:stk500boot.c **** #if defined(RAMPZ)
428:stk500boot.c **** typedef uint32_t address_t;
429:stk500boot.c **** #else
430:stk500boot.c **** typedef uint16_t address_t;
431:stk500boot.c **** #endif
432:stk500boot.c ****
433:stk500boot.c **** /*
434:stk500boot.c **** * function prototypes
435:stk500boot.c **** */
436:stk500boot.c **** static void sendchar(char c);
437:stk500boot.c **** void PrintDecInt(int theNumber, int digitCnt)
438:stk500boot.c **** {
439:stk500boot.c **** int theChar;
440:stk500boot.c **** int myNumber;
441:stk500boot.c ****
442:stk500boot.c **** myNumber = theNumber;
443:stk500boot.c ****
444:stk500boot.c **** if ((myNumber > 100) || (digitCnt >= 3))
445:stk500boot.c **** {
446:stk500boot.c **** theChar = 0x30 + myNumber / 100;
447:stk500boot.c **** sendchar(theChar );
448:stk500boot.c **** }
449:stk500boot.c ****
450:stk500boot.c **** if ((myNumber > 10) || (digitCnt >= 2))
451:stk500boot.c **** {
452:stk500boot.c **** theChar = 0x30 + ((myNumber % 100) / 10 );
453:stk500boot.c **** sendchar(theChar );
454:stk500boot.c **** }
455:stk500boot.c **** theChar = 0x30 + (myNumber % 10);
456:stk500boot.c **** sendchar(theChar );
457:stk500boot.c **** }
458:stk500boot.c **** static unsigned char recchar(void);
459:stk500boot.c **** //Burak
460:stk500boot.c **** #define Nb 4
461:stk500boot.c **** // The number of 32 bit words in a key.
462:stk500boot.c **** #define Nk 4
463:stk500boot.c ****
464:stk500boot.c **** // The number of rounds in AES Cipher.
465:stk500boot.c **** #define Nr 10
466:stk500boot.c ****
467:stk500boot.c **** #define BLOCKLEN 16
468:stk500boot.c ****
469:stk500boot.c **** // jcallan@github points out that declaring Multiply as a function
470:stk500boot.c **** // reduces code size considerably with the Keil ARM compiler.
471:stk500boot.c **** // See this link for more information: https://github.com/kokke/tiny-AES128-C/pull/3
472:stk500boot.c **** #ifndef MULTIPLY_AS_A_FUNCTION
473:stk500boot.c **** #define MULTIPLY_AS_A_FUNCTION 0
474:stk500boot.c **** #endif
475:stk500boot.c ****
476:stk500boot.c ****
477:stk500boot.c **** /*****************************************************************************/
478:stk500boot.c **** /* Private variables: */
479:stk500boot.c **** /*****************************************************************************/
480:stk500boot.c **** // state - array holding the intermediate results during decryption.
481:stk500boot.c **** typedef unsigned char state_t[4][4];
482:stk500boot.c **** static state_t* state;
483:stk500boot.c ****
484:stk500boot.c **** // The array that stores the round keys.
485:stk500boot.c **** static unsigned char RoundKey[176];
486:stk500boot.c ****
487:stk500boot.c **** // The Key input to the AES Program
488:stk500boot.c **** static const unsigned char* Key;
489:stk500boot.c ****
490:stk500boot.c **** // #if defined(CBC) && CBC
491:stk500boot.c **** // Initial Vector used only for CBC mode
492:stk500boot.c **** static unsigned char* Iv;
493:stk500boot.c **** // #endif
494:stk500boot.c ****
495:stk500boot.c **** // The lookup-tables are marked const so they can be placed in read-only storage instead of RAM
496:stk500boot.c **** // The numbers below can be computed dynamically trading ROM for RAM -
497:stk500boot.c **** // This can be useful in (embedded) bootloader applications, where ROM is often limited.
498:stk500boot.c **** static const unsigned char sbox[256] = {
499:stk500boot.c **** //0 1 2 3 4 5 6 7 8 9 A B C D E F
500:stk500boot.c **** 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
501:stk500boot.c **** 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
502:stk500boot.c **** 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
503:stk500boot.c **** 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
504:stk500boot.c **** 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
505:stk500boot.c **** 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
506:stk500boot.c **** 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
507:stk500boot.c **** 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
508:stk500boot.c **** 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
509:stk500boot.c **** 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
510:stk500boot.c **** 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
511:stk500boot.c **** 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
512:stk500boot.c **** 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
513:stk500boot.c **** 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
514:stk500boot.c **** 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
515:stk500boot.c **** 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
516:stk500boot.c ****
517:stk500boot.c **** static const unsigned char rsbox[256] =
518:stk500boot.c **** { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
519:stk500boot.c **** 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
520:stk500boot.c **** 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
521:stk500boot.c **** 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
522:stk500boot.c **** 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
523:stk500boot.c **** 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
524:stk500boot.c **** 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
525:stk500boot.c **** 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
526:stk500boot.c **** 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
527:stk500boot.c **** 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
528:stk500boot.c **** 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
529:stk500boot.c **** 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
530:stk500boot.c **** 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
531:stk500boot.c **** 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
532:stk500boot.c **** 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
533:stk500boot.c **** 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
534:stk500boot.c ****
535:stk500boot.c ****
536:stk500boot.c **** // The round constant word array, Rcon[i], contains the values given by
537:stk500boot.c **** // x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
538:stk500boot.c **** // Note that i starts at 1, not 0).
539:stk500boot.c **** static const unsigned char Rcon[255] = {
540:stk500boot.c **** 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
541:stk500boot.c **** 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39,
542:stk500boot.c **** 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
543:stk500boot.c **** 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
544:stk500boot.c **** 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef,
545:stk500boot.c **** 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
546:stk500boot.c **** 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b,
547:stk500boot.c **** 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3,
548:stk500boot.c **** 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
549:stk500boot.c **** 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
550:stk500boot.c **** 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35,
551:stk500boot.c **** 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
552:stk500boot.c **** 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
553:stk500boot.c **** 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63,
554:stk500boot.c **** 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
555:stk500boot.c **** 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb };
556:stk500boot.c ****
557:stk500boot.c ****
558:stk500boot.c **** /*****************************************************************************/
559:stk500boot.c **** /* Private functions: */
560:stk500boot.c **** /*****************************************************************************/
561:stk500boot.c **** static unsigned char getSBoxValue(unsigned char num)
562:stk500boot.c **** {
563:stk500boot.c **** return sbox[num];
564:stk500boot.c **** }
565:stk500boot.c ****
566:stk500boot.c **** static unsigned char getSBoxInvert(unsigned char num)
567:stk500boot.c **** {
568:stk500boot.c **** return rsbox[num];
569:stk500boot.c **** }
570:stk500boot.c **** static void XorWithIv(unsigned char* buf)
571:stk500boot.c **** {
15 .loc 1 571 0
16 .cfi_startproc
17 .LVL0:
18 /* prologue: function */
19 /* frame size = 0 */
20 /* stack size = 0 */
21 .L__stack_usage = 0
22 0000 E091 0000 lds r30,Iv
23 0004 F091 0000 lds r31,Iv+1
24 0008 AC01 movw r20,r24
25 000a 405F subi r20,-16
26 000c 5F4F sbci r21,-1
27 .LVL1:
28 .L2:
572:stk500boot.c **** unsigned char i;
573:stk500boot.c **** for(i = 0; i < 16; ++i)
574:stk500boot.c **** {
575:stk500boot.c **** buf[i] ^= Iv[i];
29 .loc 1 575 0 discriminator 3
30 000e DC01 movw r26,r24
31 0010 2D91 ld r18,X+
32 0012 CD01 movw r24,r26
33 .LVL2:
34 0014 3191 ld r19,Z+
35 0016 1197 sbiw r26,1
36 0018 2327 eor r18,r19
37 001a 2C93 st X,r18
38 .LVL3:
573:stk500boot.c **** {
39 .loc 1 573 0 discriminator 3
40 001c 8417 cp r24,r20
41 001e 9507 cpc r25,r21
42 0020 01F4 brne .L2
43 /* epilogue start */
576:stk500boot.c **** }
577:stk500boot.c **** }
44 .loc 1 577 0
45 0022 0895 ret
46 .cfi_endproc
47 .LFE14:
50 KeyExpansion:
51 .LFB15:
578:stk500boot.c **** // This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the
579:stk500boot.c **** static void KeyExpansion(void)
580:stk500boot.c **** {
52 .loc 1 580 0
53 .cfi_startproc
54 0024 8F92 push r8
55 .LCFI0:
56 .cfi_def_cfa_offset 4
57 .cfi_offset 8, -3
58 0026 9F92 push r9
59 .LCFI1:
60 .cfi_def_cfa_offset 5
61 .cfi_offset 9, -4
62 0028 AF92 push r10
63 .LCFI2:
64 .cfi_def_cfa_offset 6
65 .cfi_offset 10, -5
66 002a BF92 push r11
67 .LCFI3:
68 .cfi_def_cfa_offset 7
69 .cfi_offset 11, -6
70 002c FF92 push r15
71 .LCFI4:
72 .cfi_def_cfa_offset 8
73 .cfi_offset 15, -7
74 002e 0F93 push r16
75 .LCFI5:
76 .cfi_def_cfa_offset 9
77 .cfi_offset 16, -8
78 0030 1F93 push r17
79 .LCFI6:
80 .cfi_def_cfa_offset 10
81 .cfi_offset 17, -9
82 0032 CF93 push r28
83 .LCFI7:
84 .cfi_def_cfa_offset 11
85 .cfi_offset 28, -10
86 0034 DF93 push r29
87 .LCFI8:
88 .cfi_def_cfa_offset 12
89 .cfi_offset 29, -11
90 0036 00D0 rcall .
91 0038 1F92 push __zero_reg__
92 .LCFI9:
93 .cfi_def_cfa_offset 16
94 003a CDB7 in r28,__SP_L__
95 003c DEB7 in r29,__SP_H__
96 .LCFI10:
97 .cfi_def_cfa_register 28
98 /* prologue: function */
99 /* frame size = 4 */
100 /* stack size = 13 */
101 .L__stack_usage = 13
102 .LVL4:
103 003e 6091 0000 lds r22,Key
104 0042 7091 0000 lds r23,Key+1
105 0046 E0E0 ldi r30,lo8(RoundKey)
106 0048 F0E0 ldi r31,hi8(RoundKey)
107 004a 9B01 movw r18,r22
108 004c 205F subi r18,-16
109 004e 3F4F sbci r19,-1
581:stk500boot.c **** uint32_t i, j, k;
582:stk500boot.c **** unsigned char tempa[4]; // Used for the column/row operations
583:stk500boot.c ****
584:stk500boot.c **** // The first round key is the key itself.
585:stk500boot.c **** for(i = 0; i < Nk; ++i)
586:stk500boot.c **** {
587:stk500boot.c **** RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
110 .loc 1 587 0
111 0050 CF01 movw r24,r30
112 .LVL5:
113 .L5:
114 .loc 1 587 0 is_stmt 0 discriminator 3
115 0052 DB01 movw r26,r22
116 0054 4C91 ld r20,X
117 0056 DC01 movw r26,r24
118 0058 4C93 st X,r20
588:stk500boot.c **** RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
119 .loc 1 588 0 is_stmt 1 discriminator 3
120 005a DB01 movw r26,r22
121 005c 1196 adiw r26,1
122 005e 4C91 ld r20,X
123 0060 DC01 movw r26,r24
124 0062 1196 adiw r26,1
125 0064 4C93 st X,r20
589:stk500boot.c **** RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
126 .loc 1 589 0 discriminator 3
127 0066 DB01 movw r26,r22
128 0068 1296 adiw r26,2
129 006a 4C91 ld r20,X
130 006c DC01 movw r26,r24
131 006e 1296 adiw r26,2
132 0070 4C93 st X,r20
590:stk500boot.c **** RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
133 .loc 1 590 0 discriminator 3
134 0072 DB01 movw r26,r22
135 0074 1396 adiw r26,3
136 0076 4C91 ld r20,X
137 0078 DC01 movw r26,r24
138 007a 1396 adiw r26,3
139 007c 4C93 st X,r20
140 007e 6C5F subi r22,-4
141 0080 7F4F sbci r23,-1
142 0082 0496 adiw r24,4
585:stk500boot.c **** {
143 .loc 1 585 0 discriminator 3
144 0084 6217 cp r22,r18
145 0086 7307 cpc r23,r19
146 0088 01F4 brne .L5
147 008a 94E0 ldi r25,lo8(4)
148 008c 892E mov r8,r25
149 008e 912C mov r9,__zero_reg__
150 0090 A12C mov r10,__zero_reg__
151 0092 B12C mov r11,__zero_reg__
152 0094 BE01 movw r22,r28
153 0096 6B5F subi r22,-5
154 0098 7F4F sbci r23,-1
155 .L6:
156 .LVL6:
157 009a AF01 movw r20,r30
158 009c 445F subi r20,-12
159 009e 5F4F sbci r21,-1
160 00a0 9E01 movw r18,r28
161 00a2 2F5F subi r18,-1
162 00a4 3F4F sbci r19,-1
163 .LVL7:
164 .L7:
591:stk500boot.c **** }
592:stk500boot.c ****
593:stk500boot.c **** // All other round keys are found from the previous round keys.
594:stk500boot.c **** for(; (i < (Nb * (Nr + 1))); ++i)
595:stk500boot.c **** {
596:stk500boot.c **** for(j = 0; j < 4; ++j)
597:stk500boot.c **** {
598:stk500boot.c **** tempa[j]=RoundKey[(i-1) * 4 + j];
165 .loc 1 598 0 discriminator 3
166 00a6 DA01 movw r26,r20
167 00a8 1D91 ld r17,X+
168 00aa AD01 movw r20,r26
169 00ac D901 movw r26,r18
170 00ae 1D93 st X+,r17
171 00b0 9D01 movw r18,r26
596:stk500boot.c **** {
172 .loc 1 596 0 discriminator 3
173 00b2 6A17 cp r22,r26
174 00b4 7B07 cpc r23,r27
175 00b6 01F4 brne .L7
599:stk500boot.c **** }
600:stk500boot.c **** if (i % Nk == 0)
176 .loc 1 600 0
177 00b8 9501 movw r18,r10
178 00ba 8401 movw r16,r8
179 00bc 0370 andi r16,3
180 00be 1127 clr r17
181 00c0 2227 clr r18
182 00c2 3327 clr r19
183 00c4 012B or r16,r17
184 00c6 022B or r16,r18
185 00c8 032B or r16,r19
186 00ca 01F4 brne .L8
187 00cc 2981 ldd r18,Y+1
188 00ce 4C81 ldd r20,Y+4
189 .LVL8:
190 .LBB54:
191 .LBB55:
563:stk500boot.c **** }
192 .loc 1 563 0
193 00d0 0A81 ldd r16,Y+2
194 00d2 10E0 ldi r17,0
195 00d4 0050 subi r16,lo8(-(sbox))
196 00d6 1040 sbci r17,hi8(-(sbox))
197 00d8 D801 movw r26,r16
198 00da FC90 ld r15,X
199 .LVL9:
200 .LBE55:
201 .LBE54:
202 .LBB56:
203 .LBB57:
204 00dc 0B81 ldd r16,Y+3
205 00de 10E0 ldi r17,0
206 00e0 0050 subi r16,lo8(-(sbox))
207 00e2 1040 sbci r17,hi8(-(sbox))
208 .LBE57:
209 .LBE56:
601:stk500boot.c **** {
602:stk500boot.c **** // This function rotates the 4 bytes in a word to the left once.
603:stk500boot.c **** // [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
604:stk500boot.c ****
605:stk500boot.c **** // Function RotWord()
606:stk500boot.c **** {
607:stk500boot.c **** k = tempa[0];
608:stk500boot.c **** tempa[0] = tempa[1];
609:stk500boot.c **** tempa[1] = tempa[2];
610:stk500boot.c **** tempa[2] = tempa[3];
611:stk500boot.c **** tempa[3] = k;
612:stk500boot.c **** }
613:stk500boot.c ****
614:stk500boot.c **** // SubWord() is a function that takes a four-byte input word and
615:stk500boot.c **** // applies the S-box to each of the four bytes to produce an output word.
616:stk500boot.c ****
617:stk500boot.c **** // Function Subword()
618:stk500boot.c **** {
619:stk500boot.c **** tempa[0] = getSBoxValue(tempa[0]);
620:stk500boot.c **** tempa[1] = getSBoxValue(tempa[1]);
210 .loc 1 620 0
211 00e4 D801 movw r26,r16
212 00e6 3C91 ld r19,X
213 00e8 3A83 std Y+2,r19
214 .LBB58:
215 .LBB59:
563:stk500boot.c **** }
216 .loc 1 563 0
217 00ea 50E0 ldi r21,0
218 00ec 4050 subi r20,lo8(-(sbox))
219 00ee 5040 sbci r21,hi8(-(sbox))
220 .LBE59:
221 .LBE58:
621:stk500boot.c **** tempa[2] = getSBoxValue(tempa[2]);
222 .loc 1 621 0
223 00f0 DA01 movw r26,r20
224 00f2 3C91 ld r19,X
225 00f4 3B83 std Y+3,r19
226 .LBB60:
227 .LBB61:
563:stk500boot.c **** }
228 .loc 1 563 0
229 00f6 30E0 ldi r19,0
230 00f8 2050 subi r18,lo8(-(sbox))
231 00fa 3040 sbci r19,hi8(-(sbox))
232 .LVL10:
233 .LBE61:
234 .LBE60:
622:stk500boot.c **** tempa[3] = getSBoxValue(tempa[3]);
235 .loc 1 622 0
236 00fc D901 movw r26,r18
237 00fe 2C91 ld r18,X
238 0100 2C83 std Y+4,r18
623:stk500boot.c **** }
624:stk500boot.c ****
625:stk500boot.c **** tempa[0] = tempa[0] ^ Rcon[i/Nk];
239 .loc 1 625 0
240 0102 9501 movw r18,r10
241 0104 8401 movw r16,r8
242 0106 82E0 ldi r24,2
243 1:
244 0108 3695 lsr r19
245 010a 2795 ror r18
246 010c 1795 ror r17
247 010e 0795 ror r16
248 0110 8A95 dec r24
249 0112 01F4 brne 1b
250 0114 0050 subi r16,lo8(-(Rcon))
251 0116 1040 sbci r17,hi8(-(Rcon))
252 0118 D801 movw r26,r16
253 011a 2C91 ld r18,X
254 011c 2F25 eor r18,r15
255 011e 2983 std Y+1,r18
256 .LVL11:
257 .L8:
626:stk500boot.c **** }
627:stk500boot.c **** else if (Nk > 6 && i % Nk == 4)
628:stk500boot.c **** {
629:stk500boot.c **** // Function Subword()
630:stk500boot.c **** {
631:stk500boot.c **** tempa[0] = getSBoxValue(tempa[0]);
632:stk500boot.c **** tempa[1] = getSBoxValue(tempa[1]);
633:stk500boot.c **** tempa[2] = getSBoxValue(tempa[2]);
634:stk500boot.c **** tempa[3] = getSBoxValue(tempa[3]);
635:stk500boot.c **** }
636:stk500boot.c **** }
637:stk500boot.c **** // uint32_t brk = 0xFF ^ tempa[0];
638:stk500boot.c **** // static unsigned char burakim[1024];
639:stk500boot.c **** // for(uint8_t i =0; i<1024;i++)
640:stk500boot.c **** // burakim[i] = 0xFF;
641:stk500boot.c **** // RoundKey[i * 4 + 0] = RoundKey[(i - Nk) * 4 + 0];
642:stk500boot.c **** // sendchar(0x91);
643:stk500boot.c **** RoundKey[i * 4 + 0] = RoundKey[(i - Nk) * 4 + 0] ^ tempa[0];
258 .loc 1 643 0
259 0120 2081 ld r18,Z
260 0122 3981 ldd r19,Y+1
261 0124 2327 eor r18,r19
262 0126 208B std Z+16,r18
644:stk500boot.c **** // sendchar(0x92);
645:stk500boot.c **** RoundKey[i * 4 + 1] = RoundKey[(i - Nk) * 4 + 1] ^ tempa[1];
263 .loc 1 645 0
264 0128 2181 ldd r18,Z+1
265 012a 3A81 ldd r19,Y+2
266 012c 2327 eor r18,r19
267 012e 218B std Z+17,r18
646:stk500boot.c **** // sendchar(0x93);
647:stk500boot.c **** RoundKey[i * 4 + 2] = RoundKey[(i - Nk) * 4 + 2] ^ tempa[2];
268 .loc 1 647 0
269 0130 2281 ldd r18,Z+2
270 0132 3B81 ldd r19,Y+3
271 0134 2327 eor r18,r19
272 0136 228B std Z+18,r18
648:stk500boot.c **** // sendchar(0x94);
649:stk500boot.c **** RoundKey[i * 4 + 3] = RoundKey[(i - Nk) * 4 + 3] ^ tempa[3];
273 .loc 1 649 0
274 0138 2381 ldd r18,Z+3
275 013a 3C81 ldd r19,Y+4
276 013c 2327 eor r18,r19
277 013e 238B std Z+19,r18
594:stk500boot.c **** {
278 .loc 1 594 0
279 0140 BFEF ldi r27,-1
280 0142 8B1A sub r8,r27
281 0144 9B0A sbc r9,r27
282 0146 AB0A sbc r10,r27
283 0148 BB0A sbc r11,r27
284 .LVL12:
285 014a 3496 adiw r30,4
286 014c 8CE2 ldi r24,44
287 014e 8816 cp r8,r24
288 0150 9104 cpc r9,__zero_reg__
289 0152 A104 cpc r10,__zero_reg__
290 0154 B104 cpc r11,__zero_reg__
291 0156 01F0 breq .+2
292 0158 00C0 rjmp .L6
293 /* epilogue start */
650:stk500boot.c **** // sendchar(0x95);
651:stk500boot.c **** }
652:stk500boot.c **** }
294 .loc 1 652 0
295 015a 0F90 pop __tmp_reg__
296 015c 0F90 pop __tmp_reg__
297 015e 0F90 pop __tmp_reg__
298 0160 0F90 pop __tmp_reg__
299 0162 DF91 pop r29
300 0164 CF91 pop r28
301 0166 1F91 pop r17
302 0168 0F91 pop r16
303 016a FF90 pop r15
304 016c BF90 pop r11
305 016e AF90 pop r10
306 0170 9F90 pop r9
307 0172 8F90 pop r8
308 .LVL13:
309 0174 0895 ret
310 .cfi_endproc
311 .LFE15:
314 AddRoundKey:
315 .LFB16:
653:stk500boot.c ****
654:stk500boot.c **** // This function adds the round key to state.
655:stk500boot.c **** // The round key is added to the state by an XOR function.
656:stk500boot.c **** static void AddRoundKey(unsigned char round)
657:stk500boot.c **** {
316 .loc 1 657 0
317 .cfi_startproc
318 .LVL14:
319 0176 1F93 push r17
320 .LCFI11:
321 .cfi_def_cfa_offset 4
322 .cfi_offset 17, -3
323 0178 CF93 push r28
324 .LCFI12:
325 .cfi_def_cfa_offset 5
326 .cfi_offset 28, -4
327 017a DF93 push r29
328 .LCFI13:
329 .cfi_def_cfa_offset 6
330 .cfi_offset 29, -5
331 /* prologue: function */
332 /* frame size = 0 */
333 /* stack size = 3 */
334 .L__stack_usage = 3
335 .LVL15:
658:stk500boot.c **** unsigned char i,j;
659:stk500boot.c **** for(i=0;i<4;++i)
660:stk500boot.c **** {
661:stk500boot.c **** for(j = 0; j < 4; ++j)
662:stk500boot.c **** {
663:stk500boot.c **** (*state)[i][j] ^= RoundKey[round * Nb * 4 + i * Nb + j];