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
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
185
186
187
188
189
190
191
192
193
194
198
199
200
206
207
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
1001
1002
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1423
1424
1425
1426
1427
1431
1432
1433
1434
1440
1441
1442
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1499
1500
1501
1507
1508
1515
1516
1517
1518
1519
1520
1524
1527
1528
1529
1535
1536
1537
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1660
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1684
1687
1690
1693
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1718
1719
1720
1721
1722
1723
1724
1725
1729
1730
1735
1736
1737
1738
1742
1743
1744
1745
1750
1751
1752
1753
1754
1760
1761
1762
1763
1764
1765
1766
1770
1771
1776
1777
1778
1782
1783
1784
1785
1786
1787
1792
1793
1794
1795
1796
1797
1801
1802
1807
1808
1809
1810
1811
1818
1819
1820
1821
1826
1827
1828
1829
1830
1831
1837
1838
1839
1840
1841
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2006
2007
2008
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2199
2203
2207
2216
2219
2220
2221
2222
2223
2224
2225
2226
2230
2234
2238
2242
2246
2250
2254
2258
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2334
2335
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2455
2456
2457
2461
2462
2463
2464
2465
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2488
2489
2490
2491
2492
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2533
2534
2535
2536
2537
2538
2539
2544
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2645
2646
2647
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2735
2736
2737
2741
2742
2743
2744
2745
2746
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2764
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2881
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2909
2910
2915
2916
2917
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3112
3113
3118
3123
3124
3142
3143
3165
3166
3170
3171
3172
3173
3174
3175
3176
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3195
3196
3197
3198
3199
3200
3205
3206
3207
3208
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "imp.h"
#include <helper/time_support.h>
#define REG_NAME_WIDTH (12)
#define FLASH_BANK_BASE_S 0x00400000
#define FLASH_BANK_BASE_C 0x01000000
#define FLASH_BANK0_BASE_SD FLASH_BANK_BASE_S
#define FLASH_BANK1_BASE_1024K_SD (FLASH_BANK0_BASE_SD+(1024*1024/2))
#define FLASH_BANK1_BASE_2048K_SD (FLASH_BANK0_BASE_SD+(2048*1024/2))
#define FLASH_BANK0_BASE_C32 FLASH_BANK_BASE_C
#define FLASH_BANK1_BASE_C32 (FLASH_BANK_BASE_C+(2048*1024/2))
#define AT91C_EFC_FCMD_GETD (0x0)
#define AT91C_EFC_FCMD_WP (0x1)
#define AT91C_EFC_FCMD_WPL (0x2)
#define AT91C_EFC_FCMD_EWP (0x3)
#define AT91C_EFC_FCMD_EWPL (0x4)
#define AT91C_EFC_FCMD_EA (0x5)
#define AT91C_EFC_FCMD_EPA (0x7)
#define AT91C_EFC_FCMD_SLB (0x8)
#define AT91C_EFC_FCMD_CLB (0x9)
#define AT91C_EFC_FCMD_GLB (0xA)
#define AT91C_EFC_FCMD_SFB (0xB)
#define AT91C_EFC_FCMD_CFB (0xC)
#define AT91C_EFC_FCMD_GFB (0xD)
#define AT91C_EFC_FCMD_STUI (0xE)
#define AT91C_EFC_FCMD_SPUI (0xF)
#define OFFSET_EFC_FMR 0
#define OFFSET_EFC_FCR 4
#define OFFSET_EFC_FSR 8
#define OFFSET_EFC_FRR 12
27 defines
static float _tomhz(uint32_t freq_hz)
{
float f;
f = ((float)(freq_hz)) / 1000000.0;
return f;
}{ ... }
struct sam4_cfg {
uint32_t unique_id[4];
uint32_t slow_freq;
uint32_t rc_freq;
uint32_t mainosc_freq;
uint32_t plla_freq;
uint32_t mclk_freq;
uint32_t cpu_freq;
uint32_t fclk_freq;
uint32_t pclk0_freq;
uint32_t pclk1_freq;
uint32_t pclk2_freq;
#define SAM4_CHIPID_CIDR (0x400E0740)
uint32_t CHIPID_CIDR;
#define SAM4_CHIPID_EXID (0x400E0744)
uint32_t CHIPID_EXID;
#define SAM4_PMC_BASE (0x400E0400)
#define SAM4_PMC_SCSR (SAM4_PMC_BASE + 0x0008)
uint32_t PMC_SCSR;
#define SAM4_PMC_PCSR (SAM4_PMC_BASE + 0x0018)
uint32_t PMC_PCSR;
#define SAM4_CKGR_UCKR (SAM4_PMC_BASE + 0x001c)
uint32_t CKGR_UCKR;
#define SAM4_CKGR_MOR (SAM4_PMC_BASE + 0x0020)
uint32_t CKGR_MOR;
#define SAM4_CKGR_MCFR (SAM4_PMC_BASE + 0x0024)
uint32_t CKGR_MCFR;
#define SAM4_CKGR_PLLAR (SAM4_PMC_BASE + 0x0028)
uint32_t CKGR_PLLAR;
#define SAM4_PMC_MCKR (SAM4_PMC_BASE + 0x0030)
uint32_t PMC_MCKR;
#define SAM4_PMC_PCK0 (SAM4_PMC_BASE + 0x0040)
uint32_t PMC_PCK0;
#define SAM4_PMC_PCK1 (SAM4_PMC_BASE + 0x0044)
uint32_t PMC_PCK1;
#define SAM4_PMC_PCK2 (SAM4_PMC_BASE + 0x0048)
uint32_t PMC_PCK2;
#define SAM4_PMC_SR (SAM4_PMC_BASE + 0x0068)
uint32_t PMC_SR;
#define SAM4_PMC_IMR (SAM4_PMC_BASE + 0x006c)
uint32_t PMC_IMR;
#define SAM4_PMC_FSMR (SAM4_PMC_BASE + 0x0070)
uint32_t PMC_FSMR;
#define SAM4_PMC_FSPR (SAM4_PMC_BASE + 0x0074)
uint32_t PMC_FSPR;
...};
struct sam4_bank_private {
bool probed;
struct sam4_chip *chip;
struct flash_bank *bank;
unsigned bank_number;
uint32_t controller_address;
uint32_t base_address;
uint32_t flash_wait_states;
bool present;
unsigned size_bytes;
unsigned nsectors;
unsigned sector_size;
unsigned page_size;
...};
struct sam4_chip_details {
uint32_t chipid_cidr;
const char *name;
unsigned n_gpnvms;
#define SAM4_N_NVM_BITS 3
unsigned gpnvm[SAM4_N_NVM_BITS];
unsigned total_flash_size;
unsigned total_sram_size;
unsigned n_banks;
#define SAM4_MAX_FLASH_BANKS 2
struct sam4_bank_private bank[SAM4_MAX_FLASH_BANKS];
...};
struct sam4_chip {
struct sam4_chip *next;
bool probed;
struct sam4_chip_details details;
struct target *target;
struct sam4_cfg cfg;
...};
struct sam4_reg_list {
uint32_t address; size_t struct_offset; const char *name;
void (*explain_func)(struct sam4_chip *chip);
...};
static struct sam4_chip *all_sam4_chips;
static struct sam4_chip *get_current_sam4(struct command_invocation *cmd)
{
struct target *t;
static struct sam4_chip *p;
t = get_current_target(cmd->ctx);
if (!t) {
command_print_sameline(cmd, "No current target?\n");
return NULL;
}if (!t) { ... }
p = all_sam4_chips;
if (!p) {
command_print_sameline(cmd, "No SAM4 chips exist?\n");
return NULL;
}if (!p) { ... }
while (p) {
if (p->target == t)
return p;
p = p->next;
}while (p) { ... }
command_print_sameline(cmd, "Cannot find SAM4 chip?\n");
return NULL;
}{ ... }
static const struct sam4_chip_details all_sam4_details[] = {
{
.chipid_cidr = 0xA66D0EE0,
.name = "at91sam4c32e",
.total_flash_size = 2024 * 1024,
.total_sram_size = 256 * 1024,
.n_gpnvms = 3,
.n_banks = 2,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK0_BASE_C32,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 1,
.base_address = FLASH_BANK1_BASE_C32,
.controller_address = 0x400e0c00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
...},
...},
{
.chipid_cidr = 0xA64D0EE0,
.name = "at91sam4c32c",
.total_flash_size = 2024 * 1024,
.total_sram_size = 256 * 1024,
.n_gpnvms = 3,
.n_banks = 2,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK0_BASE_C32,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 1,
.base_address = FLASH_BANK1_BASE_C32,
.controller_address = 0x400e0c00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
...},
...},
{
.chipid_cidr = 0xA64C0CE0,
.name = "at91sam4c16c",
.total_flash_size = 1024 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_C,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0xA64C0AE0,
.name = "at91sam4c8c",
.total_flash_size = 512 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_C,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0xA64C0CE5,
.name = "at91sam4c4c",
.total_flash_size = 256 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_C,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 256 * 1024,
.nsectors = 32,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0xA3CC0CE0,
.name = "at91sam4e16e",
.total_flash_size = 1024 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x293B0AE0,
.name = "at91sam4n8a",
.total_flash_size = 512 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x294B0AE0,
.name = "at91sam4n8b",
.total_flash_size = 512 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x295B0AE0,
.name = "at91sam4n8c",
.total_flash_size = 512 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x29460CE0,
.name = "at91sam4n16b",
.total_flash_size = 1024 * 1024,
.total_sram_size = 80 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x29560CE0,
.name = "at91sam4n16c",
.total_flash_size = 1024 * 1024,
.total_sram_size = 80 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x28AC0CE0,
.name = "at91sam4s16c",
.total_flash_size = 1024 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x28a70ce0,
.name = "at91sam4sa16c",
.total_flash_size = 1024 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x289C0CE0,
.name = "at91sam4s16b",
.total_flash_size = 1024 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x28970CE0,
.name = "at91sam4sa16b",
.total_flash_size = 1024 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x288C0CE0,
.name = "at91sam4s16a",
.total_flash_size = 1024 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x28AC0AE0,
.name = "at91sam4s8c",
.total_flash_size = 512 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x289C0AE0,
.name = "at91sam4s8b",
.total_flash_size = 512 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x288C0AE0,
.name = "at91sam4s8a",
.total_flash_size = 512 * 1024,
.total_sram_size = 128 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x28ab09e0,
.name = "at91sam4s4c",
.total_flash_size = 256 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 256 * 1024,
.nsectors = 32,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x289b09e0,
.name = "at91sam4s4b",
.total_flash_size = 256 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 256 * 1024,
.nsectors = 32,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x288b09e0,
.name = "at91sam4s4a",
.total_flash_size = 256 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 256 * 1024,
.nsectors = 32,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x28ab07e0,
.name = "at91sam4s2c",
.total_flash_size = 128 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 128 * 1024,
.nsectors = 16,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x289b07e0,
.name = "at91sam4s2b",
.total_flash_size = 128 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 128 * 1024,
.nsectors = 16,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x288b07e0,
.name = "at91sam4s2a",
.total_flash_size = 128 * 1024,
.total_sram_size = 64 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 128 * 1024,
.nsectors = 16,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...},
...},
{
.chipid_cidr = 0x29a70ee0,
.name = "at91sam4sd32c",
.total_flash_size = 2048 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 3,
.n_banks = 2,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK0_BASE_SD,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 1,
.base_address = FLASH_BANK1_BASE_2048K_SD,
.controller_address = 0x400e0c00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
...},
...},
{
.chipid_cidr = 0x29970ee0,
.name = "at91sam4sd32b",
.total_flash_size = 2048 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 3,
.n_banks = 2,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK0_BASE_SD,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 1,
.base_address = FLASH_BANK1_BASE_2048K_SD,
.controller_address = 0x400e0c00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 1024 * 1024,
.nsectors = 128,
.sector_size = 8192,
.page_size = 512,
...},
...},
...},
{
.chipid_cidr = 0x29a70ce0,
.name = "at91sam4sd16c",
.total_flash_size = 1024 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 3,
.n_banks = 2,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK0_BASE_SD,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 1,
.base_address = FLASH_BANK1_BASE_1024K_SD,
.controller_address = 0x400e0c00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
...},
...},
{
.chipid_cidr = 0x29970ce0,
.name = "at91sam4sd16b",
.total_flash_size = 1024 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 3,
.n_banks = 2,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK0_BASE_SD,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 1,
.base_address = FLASH_BANK1_BASE_1024K_SD,
.controller_address = 0x400e0c00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
...},
...},
{
.chipid_cidr = 0x247e0ae0,
.name = "atsamg53n19",
.total_flash_size = 512 * 1024,
.total_sram_size = 96 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...}
...},
{
.chipid_cidr = 0x24470ae0,
.name = "atsamg55g19",
.total_flash_size = 512 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...}
...},
{
.chipid_cidr = 0x24470ae1,
.name = "atsamg55g19b",
.total_flash_size = 512 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...}
...},
{
.chipid_cidr = 0x24570ae0,
.name = "atsamg55j19",
.total_flash_size = 512 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...}
...},
{
.chipid_cidr = 0x24570ae1,
.name = "atsamg55j19b",
.total_flash_size = 512 * 1024,
.total_sram_size = 160 * 1024,
.n_gpnvms = 2,
.n_banks = 1,
{
{
.probed = false,
.chip = NULL,
.bank = NULL,
.bank_number = 0,
.base_address = FLASH_BANK_BASE_S,
.controller_address = 0x400e0a00,
.flash_wait_states = 5,
.present = true,
.size_bytes = 512 * 1024,
.nsectors = 64,
.sector_size = 8192,
.page_size = 512,
...},
{
.present = false,
.probed = false,
.bank_number = 1,
...},
...}
...},
{
.chipid_cidr = 0,
.name = NULL,
...}
...};
/* ... */
/* ... */
static int efc_get_status(struct sam4_bank_private *private, uint32_t *v)
{
int r;
r = target_read_u32(private->chip->target,
private->controller_address + OFFSET_EFC_FSR,
v);
LOG_DEBUG("Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)",
(unsigned int)(*v),
((unsigned int)((*v >> 2) & 1)),
((unsigned int)((*v >> 1) & 1)),
((unsigned int)((*v >> 0) & 1)));
return r;
}{ ... }
/* ... */
static int efc_get_result(struct sam4_bank_private *private, uint32_t *v)
{
int r;
uint32_t rv;
r = target_read_u32(private->chip->target,
private->controller_address + OFFSET_EFC_FRR,
&rv);
if (v)
*v = rv;
LOG_DEBUG("Result: 0x%08x", ((unsigned int)(rv)));
return r;
}{ ... }
static int efc_start_command(struct sam4_bank_private *private,
unsigned command, unsigned argument)
{
uint32_t n, v;
int r;
int retry;
retry = 0;
do_retry:
switch (command) {
case AT91C_EFC_FCMD_WP:
case AT91C_EFC_FCMD_WPL:
case AT91C_EFC_FCMD_EWP:
case AT91C_EFC_FCMD_EWPL:
case AT91C_EFC_FCMD_EWPL:
case AT91C_EFC_FCMD_EPA:
case AT91C_EFC_FCMD_SLB:
case AT91C_EFC_FCMD_CLB:
n = (private->size_bytes / private->page_size);
if (argument >= n)
LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n));
break;
case AT91C_EFC_FCMD_CLB:
case AT91C_EFC_FCMD_SFB:
case AT91C_EFC_FCMD_CFB:
if (argument >= private->chip->details.n_gpnvms) {
LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs",
private->chip->details.n_gpnvms);
}if (argument >= private->chip->details.n_gpnvms) { ... }
break;
case AT91C_EFC_FCMD_CFB:
case AT91C_EFC_FCMD_GETD:
case AT91C_EFC_FCMD_EA:
case AT91C_EFC_FCMD_GLB:
case AT91C_EFC_FCMD_GFB:
case AT91C_EFC_FCMD_STUI:
case AT91C_EFC_FCMD_SPUI:
if (argument != 0)
LOG_ERROR("Argument is meaningless for cmd: %d", command);
break;case AT91C_EFC_FCMD_SPUI:
default:
LOG_ERROR("Unknown command %d", command);
break;default
}switch (command) { ... }
if (command == AT91C_EFC_FCMD_SPUI) {
}if (command == AT91C_EFC_FCMD_SPUI) { ... } else {
efc_get_status(private, &v);
if (v & 1) {
}if (v & 1) { ... } else {
if (retry) {
LOG_ERROR("flash controller(%d) is not ready! Error",
private->bank_number);
return ERROR_FAIL;
}if (retry) { ... } else {
retry++;
LOG_ERROR("Flash controller(%d) is not ready, attempting reset",
private->bank_number);
efc_start_command(private, AT91C_EFC_FCMD_SPUI, 0);
goto do_retry;
}else { ... }
}else { ... }
}else { ... }
v = (0x5A << 24) | (argument << 8) | command;
LOG_DEBUG("Command: 0x%08x", ((unsigned int)(v)));
r = target_write_u32(private->bank->target,
private->controller_address + OFFSET_EFC_FCR, v);
if (r != ERROR_OK)
LOG_DEBUG("Error Write failed");
return r;
}{ ... }
/* ... */
static int efc_perform_command(struct sam4_bank_private *private,
unsigned command,
unsigned argument,
uint32_t *status)
{
int r;
uint32_t v;
int64_t ms_now, ms_end;
if (status)
*status = 0;
r = efc_start_command(private, command, argument);
if (r != ERROR_OK)
return r;
ms_end = 10000 + timeval_ms();
do {
r = efc_get_status(private, &v);
if (r != ERROR_OK)
return r;
ms_now = timeval_ms();
if (ms_now > ms_end) {
LOG_ERROR("Command timeout");
return ERROR_FAIL;
}if (ms_now > ms_end) { ... }
...} while ((v & 1) == 0);
if (status)
*status = (v & 0x6);
return ERROR_OK;
}{ ... }
/* ... */
static int flashd_read_uid(struct sam4_bank_private *private)
{
int r;
uint32_t v;
int x;
private->chip->cfg.unique_id[0] = 0;
private->chip->cfg.unique_id[1] = 0;
private->chip->cfg.unique_id[2] = 0;
private->chip->cfg.unique_id[3] = 0;
LOG_DEBUG("Begin");
r = efc_start_command(private, AT91C_EFC_FCMD_STUI, 0);
if (r < 0)
return r;
for (x = 0; x < 4; x++) {
r = target_read_u32(private->chip->target,
private->bank->base + (x * 4),
&v);
if (r < 0)
return r;
private->chip->cfg.unique_id[x] = v;
}for (x = 0; x < 4; x++) { ... }
r = efc_perform_command(private, AT91C_EFC_FCMD_SPUI, 0, NULL);
LOG_DEBUG("End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x",
r,
(unsigned int)(private->chip->cfg.unique_id[0]),
(unsigned int)(private->chip->cfg.unique_id[1]),
(unsigned int)(private->chip->cfg.unique_id[2]),
(unsigned int)(private->chip->cfg.unique_id[3]));
return r;
}{ ... }
/* ... */
static int flashd_erase_entire_bank(struct sam4_bank_private *private)
{
LOG_DEBUG("Here");
return efc_perform_command(private, AT91C_EFC_FCMD_EA, 0, NULL);
}{ ... }
/* ... */
static int flashd_erase_pages(struct sam4_bank_private *private,
int first_page,
int num_pages,
uint32_t *status)
{
LOG_DEBUG("Here");
uint8_t erase_pages;
switch (num_pages) {
case 4:
erase_pages = 0x00;
break;case 4:
case 8:
erase_pages = 0x01;
break;case 8:
case 16:
erase_pages = 0x02;
break;case 16:
case 32:
erase_pages = 0x03;
break;case 32:
default:
erase_pages = 0x00;
break;default
}switch (num_pages) { ... }
/* ... */
return efc_perform_command(private,
AT91C_EFC_FCMD_EPA,
(first_page) | erase_pages,
status);
}{ ... }
/* ... */
static int flashd_get_gpnvm(struct sam4_bank_private *private, unsigned gpnvm, unsigned *puthere)
{
uint32_t v;
int r;
LOG_DEBUG("Here");
if (private->bank_number != 0) {
LOG_ERROR("GPNVM only works with Bank0");
return ERROR_FAIL;
}if (private->bank_number != 0) { ... }
if (gpnvm >= private->chip->details.n_gpnvms) {
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
gpnvm, private->chip->details.n_gpnvms);
return ERROR_FAIL;
}if (gpnvm >= private->chip->details.n_gpnvms) { ... }
r = efc_perform_command(private, AT91C_EFC_FCMD_GFB, 0, NULL);
if (r != ERROR_OK) {
LOG_ERROR("Failed");
return r;
}if (r != ERROR_OK) { ... }
r = efc_get_result(private, &v);
if (puthere) {
*puthere = (v >> gpnvm) & 1;
}if (puthere) { ... }
return r;
}{ ... }
/* ... */
static int flashd_clr_gpnvm(struct sam4_bank_private *private, unsigned gpnvm)
{
int r;
unsigned v;
LOG_DEBUG("Here");
if (private->bank_number != 0) {
LOG_ERROR("GPNVM only works with Bank0");
return ERROR_FAIL;
}if (private->bank_number != 0) { ... }
if (gpnvm >= private->chip->details.n_gpnvms) {
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
gpnvm, private->chip->details.n_gpnvms);
return ERROR_FAIL;
}if (gpnvm >= private->chip->details.n_gpnvms) { ... }
r = flashd_get_gpnvm(private, gpnvm, &v);
if (r != ERROR_OK) {
LOG_DEBUG("Failed: %d", r);
return r;
}if (r != ERROR_OK) { ... }
r = efc_perform_command(private, AT91C_EFC_FCMD_CFB, gpnvm, NULL);
LOG_DEBUG("End: %d", r);
return r;
}{ ... }
/* ... */
static int flashd_set_gpnvm(struct sam4_bank_private *private, unsigned gpnvm)
{
int r;
unsigned v;
if (private->bank_number != 0) {
LOG_ERROR("GPNVM only works with Bank0");
return ERROR_FAIL;
}if (private->bank_number != 0) { ... }
if (gpnvm >= private->chip->details.n_gpnvms) {
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
gpnvm, private->chip->details.n_gpnvms);
return ERROR_FAIL;
}if (gpnvm >= private->chip->details.n_gpnvms) { ... }
r = flashd_get_gpnvm(private, gpnvm, &v);
if (r != ERROR_OK)
return r;
if (v) {
r = ERROR_OK;
}if (v) { ... } else {
r = efc_perform_command(private, AT91C_EFC_FCMD_SFB, gpnvm, NULL);
}else { ... }
return r;
}{ ... }
/* ... */
static int flashd_get_lock_bits(struct sam4_bank_private *private, uint32_t *v)
{
int r;
LOG_DEBUG("Here");
r = efc_perform_command(private, AT91C_EFC_FCMD_GLB, 0, NULL);
if (r == ERROR_OK) {
efc_get_result(private, v);
efc_get_result(private, v);
efc_get_result(private, v);
r = efc_get_result(private, v);
}if (r == ERROR_OK) { ... }
LOG_DEBUG("End: %d", r);
return r;
}{ ... }
/* ... */
static int flashd_unlock(struct sam4_bank_private *private,
unsigned start_sector,
unsigned end_sector)
{
int r;
uint32_t status;
uint32_t pg;
uint32_t pages_per_sector;
pages_per_sector = private->sector_size / private->page_size;
while (start_sector <= end_sector) {
pg = start_sector * pages_per_sector;
r = efc_perform_command(private, AT91C_EFC_FCMD_CLB, pg, &status);
if (r != ERROR_OK)
return r;
start_sector++;
}while (start_sector <= end_sector) { ... }
return ERROR_OK;
}{ ... }
/* ... */
static int flashd_lock(struct sam4_bank_private *private,
unsigned start_sector,
unsigned end_sector)
{
uint32_t status;
uint32_t pg;
uint32_t pages_per_sector;
int r;
pages_per_sector = private->sector_size / private->page_size;
while (start_sector <= end_sector) {
pg = start_sector * pages_per_sector;
r = efc_perform_command(private, AT91C_EFC_FCMD_SLB, pg, &status);
if (r != ERROR_OK)
return r;
start_sector++;
}while (start_sector <= end_sector) { ... }
return ERROR_OK;
}{ ... }
static uint32_t sam4_reg_fieldname(struct sam4_chip *chip,
const char *regname,
uint32_t value,
unsigned shift,
unsigned width)
{
uint32_t v;
int hwidth, dwidth;
v = value >> shift;
v = v & ((1 << width)-1);
if (width <= 16) {
hwidth = 4;
dwidth = 5;
}if (width <= 16) { ... } else {
hwidth = 8;
dwidth = 12;
}else { ... }
LOG_USER_N("\t%*s: %*" PRIu32 " [0x%0*" PRIx32 "] ",
REG_NAME_WIDTH, regname,
dwidth, v,
hwidth, v);
return v;
}{ ... }
static const char _unknown[] = "unknown";
static const char *const eproc_names[] = {
"Cortex-M7",
"arm946es",
"arm7tdmi",
"Cortex-M3",
"arm920t",
"arm926ejs",
"Cortex-A5",
"Cortex-M4",
_unknown,
_unknown,
_unknown,
_unknown,
_unknown,
_unknown,
_unknown,
_unknown,
...};
#define nvpsize2 nvpsize
static const char *const nvpsize[] = {
"none",
"8K bytes",
"16K bytes",
"32K bytes",
_unknown,
"64K bytes",
_unknown,
"128K bytes",
"160K bytes",
"256K bytes",
"512K bytes",
_unknown,
"1024K bytes",
_unknown,
"2048K bytes",
_unknown,
...};
static const char *const sramsize[] = {
"48K Bytes",
"1K Bytes",
"2K Bytes",
"6K Bytes",
"112K Bytes",
"4K Bytes",
"80K Bytes",
"160K Bytes",
"8K Bytes",
"16K Bytes",
"32K Bytes",
"64K Bytes",
"128K Bytes",
"256K Bytes",
"96K Bytes",
"512K Bytes",
...};
static const struct archnames { unsigned value; const char *name; } archnames[] = {
{ 0x19, "AT91SAM9xx Series" },
{ 0x29, "AT91SAM9XExx Series" },
{ 0x34, "AT91x34 Series" },
{ 0x37, "CAP7 Series" },
{ 0x39, "CAP9 Series" },
{ 0x3B, "CAP11 Series" },
{ 0x3C, "ATSAM4E" },
{ 0x40, "AT91x40 Series" },
{ 0x42, "AT91x42 Series" },
{ 0x43, "SAMG51 Series"
...},
{ 0x44, "SAMG55 Series (49-pin WLCSP)" },
{ 0x45, "SAMG55 Series (64-pin)" },
{ 0x47, "SAMG53 Series"
...},
{ 0x55, "AT91x55 Series" },
{ 0x60, "AT91SAM7Axx Series" },
{ 0x61, "AT91SAM7AQxx Series" },
{ 0x63, "AT91x63 Series" },
{ 0x64, "SAM4CxxC (100-pin version)" },
{ 0x66, "SAM4CxxE (144-pin version)" },
{ 0x70, "AT91SAM7Sxx Series" },
{ 0x71, "AT91SAM7XCxx Series" },
{ 0x72, "AT91SAM7SExx Series" },
{ 0x73, "AT91SAM7Lxx Series" },
{ 0x75, "AT91SAM7Xxx Series" },
{ 0x76, "AT91SAM7SLxx Series" },
{ 0x80, "ATSAM3UxC Series (100-pin version)" },
{ 0x81, "ATSAM3UxE Series (144-pin version)" },
{ 0x83, "ATSAM3A/SAM4A xC Series (100-pin version)"},
{ 0x84, "ATSAM3X/SAM4X xC Series (100-pin version)"},
{ 0x85, "ATSAM3X/SAM4X xE Series (144-pin version)"},
{ 0x86, "ATSAM3X/SAM4X xG Series (208/217-pin version)" },
{ 0x88, "ATSAM3S/SAM4S xA Series (48-pin version)" },
{ 0x89, "ATSAM3S/SAM4S xB Series (64-pin version)" },
{ 0x8A, "ATSAM3S/SAM4S xC Series (100-pin version)"},
{ 0x92, "AT91x92 Series" },
{ 0x93, "ATSAM3NxA Series (48-pin version)" },
{ 0x94, "ATSAM3NxB Series (64-pin version)" },
{ 0x95, "ATSAM3NxC Series (100-pin version)" },
{ 0x98, "ATSAM3SDxA Series (48-pin version)" },
{ 0x99, "ATSAM3SDxB Series (64-pin version)" },
{ 0x9A, "ATSAM3SDxC Series (100-pin version)" },
{ 0xA5, "ATSAM5A" },
{ 0xF0, "AT75Cxx Series" },
{ -1, NULL },
...};
static const char *const nvptype[] = {
"rom",
"romless or onchip flash",
"embedded flash memory",
"rom(nvpsiz) + embedded flash (nvpsiz2)",
"sram emulating flash",
_unknown,
_unknown,
_unknown,
...};
static const char *_yes_or_no(uint32_t v)
{
if (v)
return "YES";
else
return "NO";
}{ ... }
static const char *const _rc_freq[] = {
"4 MHz", "8 MHz", "12 MHz", "reserved"
...};
static void sam4_explain_ckgr_mor(struct sam4_chip *chip)
{
uint32_t v;
uint32_t rcen;
v = sam4_reg_fieldname(chip, "MOSCXTEN", chip->cfg.CKGR_MOR, 0, 1);
LOG_USER("(main xtal enabled: %s)", _yes_or_no(v));
v = sam4_reg_fieldname(chip, "MOSCXTBY", chip->cfg.CKGR_MOR, 1, 1);
LOG_USER("(main osc bypass: %s)", _yes_or_no(v));
rcen = sam4_reg_fieldname(chip, "MOSCRCEN", chip->cfg.CKGR_MOR, 3, 1);
LOG_USER("(onchip RC-OSC enabled: %s)", _yes_or_no(rcen));
v = sam4_reg_fieldname(chip, "MOSCRCF", chip->cfg.CKGR_MOR, 4, 3);
LOG_USER("(onchip RC-OSC freq: %s)", _rc_freq[v]);
chip->cfg.rc_freq = 0;
if (rcen) {
switch (v) {
default:
chip->cfg.rc_freq = 0;
break;default
case 0:
chip->cfg.rc_freq = 4 * 1000 * 1000;
break;case 0:
case 1:
chip->cfg.rc_freq = 8 * 1000 * 1000;
break;case 1:
case 2:
chip->cfg.rc_freq = 12 * 1000 * 1000;
break;case 2:
}switch (v) { ... }
}if (rcen) { ... }
v = sam4_reg_fieldname(chip, "MOSCXTST", chip->cfg.CKGR_MOR, 8, 8);
LOG_USER("(startup clks, time= %f uSecs)",
((float)(v * 1000000)) / ((float)(chip->cfg.slow_freq)));
v = sam4_reg_fieldname(chip, "MOSCSEL", chip->cfg.CKGR_MOR, 24, 1);
LOG_USER("(mainosc source: %s)",
v ? "external xtal" : "internal RC");
v = sam4_reg_fieldname(chip, "CFDEN", chip->cfg.CKGR_MOR, 25, 1);
LOG_USER("(clock failure enabled: %s)",
_yes_or_no(v));
}{ ... }
static void sam4_explain_chipid_cidr(struct sam4_chip *chip)
{
int x;
uint32_t v;
const char *cp;
sam4_reg_fieldname(chip, "Version", chip->cfg.CHIPID_CIDR, 0, 5);
LOG_USER_N("\n");
v = sam4_reg_fieldname(chip, "EPROC", chip->cfg.CHIPID_CIDR, 5, 3);
LOG_USER("%s", eproc_names[v]);
v = sam4_reg_fieldname(chip, "NVPSIZE", chip->cfg.CHIPID_CIDR, 8, 4);
LOG_USER("%s", nvpsize[v]);
v = sam4_reg_fieldname(chip, "NVPSIZE2", chip->cfg.CHIPID_CIDR, 12, 4);
LOG_USER("%s", nvpsize2[v]);
v = sam4_reg_fieldname(chip, "SRAMSIZE", chip->cfg.CHIPID_CIDR, 16, 4);
LOG_USER("%s", sramsize[v]);
v = sam4_reg_fieldname(chip, "ARCH", chip->cfg.CHIPID_CIDR, 20, 8);
cp = _unknown;
for (x = 0; archnames[x].name; x++) {
if (v == archnames[x].value) {
cp = archnames[x].name;
break;
}if (v == archnames[x].value) { ... }
}for (x = 0; archnames[x].name; x++) { ... }
LOG_USER("%s", cp);
v = sam4_reg_fieldname(chip, "NVPTYP", chip->cfg.CHIPID_CIDR, 28, 3);
LOG_USER("%s", nvptype[v]);
v = sam4_reg_fieldname(chip, "EXTID", chip->cfg.CHIPID_CIDR, 31, 1);
LOG_USER("(exists: %s)", _yes_or_no(v));
}{ ... }
static void sam4_explain_ckgr_mcfr(struct sam4_chip *chip)
{
uint32_t v;
v = sam4_reg_fieldname(chip, "MAINFRDY", chip->cfg.CKGR_MCFR, 16, 1);
LOG_USER("(main ready: %s)", _yes_or_no(v));
v = sam4_reg_fieldname(chip, "MAINF", chip->cfg.CKGR_MCFR, 0, 16);
v = (v * chip->cfg.slow_freq) / 16;
chip->cfg.mainosc_freq = v;
LOG_USER("(%3.03f Mhz (%" PRIu32 ".%03" PRIu32 "khz slowclk)",
_tomhz(v),
(uint32_t)(chip->cfg.slow_freq / 1000),
(uint32_t)(chip->cfg.slow_freq % 1000));
}{ ... }
static void sam4_explain_ckgr_plla(struct sam4_chip *chip)
{
uint32_t mula, diva;
diva = sam4_reg_fieldname(chip, "DIVA", chip->cfg.CKGR_PLLAR, 0, 8);
LOG_USER_N("\n");
mula = sam4_reg_fieldname(chip, "MULA", chip->cfg.CKGR_PLLAR, 16, 11);
LOG_USER_N("\n");
chip->cfg.plla_freq = 0;
if (mula == 0)
LOG_USER("\tPLLA Freq: (Disabled,mula = 0)");
else if (diva == 0)
LOG_USER("\tPLLA Freq: (Disabled,diva = 0)");
else if (diva >= 1) {
chip->cfg.plla_freq = (chip->cfg.mainosc_freq * (mula + 1) / diva);
LOG_USER("\tPLLA Freq: %3.03f MHz",
_tomhz(chip->cfg.plla_freq));
}else if (diva >= 1) { ... }
}{ ... }
static void sam4_explain_mckr(struct sam4_chip *chip)
{
uint32_t css, pres, fin = 0;
int pdiv = 0;
const char *cp = NULL;
css = sam4_reg_fieldname(chip, "CSS", chip->cfg.PMC_MCKR, 0, 2);
switch (css & 3) {
case 0:
fin = chip->cfg.slow_freq;
cp = "slowclk";
break;case 0:
case 1:
fin = chip->cfg.mainosc_freq;
cp = "mainosc";
break;case 1:
case 2:
fin = chip->cfg.plla_freq;
cp = "plla";
break;case 2:
case 3:
if (chip->cfg.CKGR_UCKR & (1 << 16)) {
fin = 480 * 1000 * 1000;
cp = "upll";
}if (chip->cfg.CKGR_UCKR & (1 << 16)) { ... } else {
fin = 0;
cp = "upll (*ERROR* UPLL is disabled)";
}else { ... }
break;case 3:
default:
assert(0);
break;default
}switch (css & 3) { ... }
LOG_USER("%s (%3.03f Mhz)",
cp,
_tomhz(fin));
pres = sam4_reg_fieldname(chip, "PRES", chip->cfg.PMC_MCKR, 4, 3);
switch (pres & 0x07) {
case 0:
pdiv = 1;
cp = "selected clock";
break;case 0:
case 1:
pdiv = 2;
cp = "clock/2";
break;case 1:
case 2:
pdiv = 4;
cp = "clock/4";
break;case 2:
case 3:
pdiv = 8;
cp = "clock/8";
break;case 3:
case 4:
pdiv = 16;
cp = "clock/16";
break;case 4:
case 5:
pdiv = 32;
cp = "clock/32";
break;case 5:
case 6:
pdiv = 64;
cp = "clock/64";
break;case 6:
case 7:
pdiv = 6;
cp = "clock/6";
break;case 7:
default:
assert(0);
break;default
}switch (pres & 0x07) { ... }
LOG_USER("(%s)", cp);
fin = fin / pdiv;
chip->cfg.cpu_freq = fin;
chip->cfg.mclk_freq = fin;
chip->cfg.fclk_freq = fin;
LOG_USER("\t\tResult CPU Freq: %3.03f",
_tomhz(fin));
}{ ... }
#if 0
static struct sam4_chip *target2sam4(struct target *target)
{
struct sam4_chip *chip;
if (!target)
return NULL;
chip = all_sam4_chips;
while (chip) {
if (chip->target == target)
break;
else
chip = chip->next;
}while (chip) { ... }
return chip;
}target2sam4 (struct target *target) { ... }
/* ... */#endif
static uint32_t *sam4_get_reg_ptr(struct sam4_cfg *cfg, const struct sam4_reg_list *list)
{
return (uint32_t *)(void *)(((char *)(cfg)) + list->struct_offset);
}{ ... }
#define SAM4_ENTRY(NAME, FUNC) { .address = SAM4_ ## NAME, .struct_offset = offsetof( \
struct sam4_cfg, \
NAME), # NAME, FUNC ...}...
static const struct sam4_reg_list sam4_all_regs[] = {
SAM4_ENTRY(CKGR_MOR, sam4_explain_ckgr_mor),
SAM4_ENTRY(CKGR_MCFR, sam4_explain_ckgr_mcfr),
SAM4_ENTRY(CKGR_PLLAR, sam4_explain_ckgr_plla),
SAM4_ENTRY(CKGR_UCKR, NULL),
SAM4_ENTRY(PMC_FSMR, NULL),
SAM4_ENTRY(PMC_FSPR, NULL),
SAM4_ENTRY(PMC_IMR, NULL),
SAM4_ENTRY(PMC_MCKR, sam4_explain_mckr),
SAM4_ENTRY(PMC_PCK0, NULL),
SAM4_ENTRY(PMC_PCK1, NULL),
SAM4_ENTRY(PMC_PCK2, NULL),
SAM4_ENTRY(PMC_PCSR, NULL),
SAM4_ENTRY(PMC_SCSR, NULL),
SAM4_ENTRY(PMC_SR, NULL),
SAM4_ENTRY(CHIPID_CIDR, sam4_explain_chipid_cidr),
SAM4_ENTRY(CHIPID_EXID, NULL),
{ .name = NULL }
...};
#undef SAM4_ENTRY
static struct sam4_bank_private *get_sam4_bank_private(struct flash_bank *bank)
{
return bank->driver_priv;
}{ ... }
/* ... */
static const struct sam4_reg_list *sam4_get_reg(struct sam4_chip *chip, uint32_t *goes_here)
{
const struct sam4_reg_list *reg;
reg = &(sam4_all_regs[0]);
while (reg->name) {
uint32_t *possible;
possible = ((uint32_t *)(void *)(((char *)(&(chip->cfg))) + reg->struct_offset));
if (possible == goes_here) {
return reg;
}if (possible == goes_here) { ... }
reg++;
}while (reg->name) { ... }
LOG_ERROR("INVALID SAM4 REGISTER");
return NULL;
}{ ... }
static int sam4_read_this_reg(struct sam4_chip *chip, uint32_t *goes_here)
{
const struct sam4_reg_list *reg;
int r;
reg = sam4_get_reg(chip, goes_here);
if (!reg)
return ERROR_FAIL;
r = target_read_u32(chip->target, reg->address, goes_here);
if (r != ERROR_OK) {
LOG_ERROR("Cannot read SAM4 register: %s @ 0x%08x, Err: %d",
reg->name, (unsigned)(reg->address), r);
}if (r != ERROR_OK) { ... }
return r;
}{ ... }
static int sam4_read_all_regs(struct sam4_chip *chip)
{
int r;
const struct sam4_reg_list *reg;
reg = &(sam4_all_regs[0]);
while (reg->name) {
r = sam4_read_this_reg(chip,
sam4_get_reg_ptr(&(chip->cfg), reg));
if (r != ERROR_OK) {
LOG_ERROR("Cannot read SAM4 register: %s @ 0x%08x, Error: %d",
reg->name, ((unsigned)(reg->address)), r);
return r;
}if (r != ERROR_OK) { ... }
reg++;
}while (reg->name) { ... }
return ERROR_OK;
}{ ... }
static int sam4_get_info(struct sam4_chip *chip)
{
const struct sam4_reg_list *reg;
uint32_t regval;
int r;
r = sam4_read_all_regs(chip);
if (r != ERROR_OK)
return r;
reg = &(sam4_all_regs[0]);
while (reg->name) {
LOG_DEBUG("Start: %s", reg->name);
regval = *sam4_get_reg_ptr(&(chip->cfg), reg);
LOG_USER("%*s: [0x%08" PRIx32 "] -> 0x%08" PRIx32,
REG_NAME_WIDTH,
reg->name,
reg->address,
regval);
if (reg->explain_func)
(*(reg->explain_func))(chip);
LOG_DEBUG("End: %s", reg->name);
reg++;
}while (reg->name) { ... }
LOG_USER(" rc-osc: %3.03f MHz", _tomhz(chip->cfg.rc_freq));
LOG_USER(" mainosc: %3.03f MHz", _tomhz(chip->cfg.mainosc_freq));
LOG_USER(" plla: %3.03f MHz", _tomhz(chip->cfg.plla_freq));
LOG_USER(" cpu-freq: %3.03f MHz", _tomhz(chip->cfg.cpu_freq));
LOG_USER("mclk-freq: %3.03f MHz", _tomhz(chip->cfg.mclk_freq));
LOG_USER(" UniqueId: 0x%08" PRIx32 " 0x%08" PRIx32 " 0x%08" PRIx32 " 0x%08"PRIx32,
chip->cfg.unique_id[0],
chip->cfg.unique_id[1],
chip->cfg.unique_id[2],
chip->cfg.unique_id[3]);
return ERROR_OK;
}{ ... }
static int sam4_protect_check(struct flash_bank *bank)
{
int r;
uint32_t v[4] = {0};
unsigned x;
struct sam4_bank_private *private;
LOG_DEBUG("Begin");
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}if (bank->target->state != TARGET_HALTED) { ... }
private = get_sam4_bank_private(bank);
if (!private) {
LOG_ERROR("no private for this bank?");
return ERROR_FAIL;
}if (!private) { ... }
if (!(private->probed))
return ERROR_FLASH_BANK_NOT_PROBED;
r = flashd_get_lock_bits(private, v);
if (r != ERROR_OK) {
LOG_DEBUG("Failed: %d", r);
return r;
}if (r != ERROR_OK) { ... }
for (x = 0; x < private->nsectors; x++)
bank->sectors[x].is_protected = (!!(v[x >> 5] & (1 << (x % 32))));
LOG_DEBUG("Done");
return ERROR_OK;
}{ ... }
FLASH_BANK_COMMAND_HANDLER(sam4_flash_bank_command)
{
struct sam4_chip *chip;
chip = all_sam4_chips;
while (chip) {
if (chip->target == bank->target)
break;
chip = chip->next;
}while (chip) { ... }
if (!chip) {
chip = calloc(1, sizeof(struct sam4_chip));
if (!chip) {
LOG_ERROR("NO RAM!");
return ERROR_FAIL;
}if (!chip) { ... }
chip->target = bank->target;
chip->next = all_sam4_chips;
all_sam4_chips = chip;
chip->target = bank->target;
chip->cfg.slow_freq = 32768;
chip->probed = false;
}if (!chip) { ... }
switch (bank->base) {
default:
LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x"
"[at91sam4s series] )",
((unsigned int)(bank->base)),
((unsigned int)(FLASH_BANK_BASE_S)));
return ERROR_FAIL;
default
case FLASH_BANK_BASE_S:
case FLASH_BANK_BASE_C:
bank->driver_priv = &(chip->details.bank[0]);
bank->bank_number = 0;
chip->details.bank[0].chip = chip;
chip->details.bank[0].bank = bank;
break;
case FLASH_BANK_BASE_C:
case FLASH_BANK1_BASE_1024K_SD:
case FLASH_BANK1_BASE_2048K_SD:
case FLASH_BANK1_BASE_C32:
bank->driver_priv = &(chip->details.bank[1]);
bank->bank_number = 1;
chip->details.bank[1].chip = chip;
chip->details.bank[1].bank = bank;
break;case FLASH_BANK1_BASE_C32:
}switch (bank->base) { ... }
return ERROR_OK;
}{ ... }
/* ... */
static void sam4_free_driver_priv(struct flash_bank *bank)
{
struct sam4_chip *chip = all_sam4_chips;
while (chip) {
struct sam4_chip *next = chip->next;
free(chip);
chip = next;
}while (chip) { ... }
all_sam4_chips = NULL;
}{ ... }
static int sam4_get_details(struct sam4_bank_private *private)
{
const struct sam4_chip_details *details;
struct sam4_chip *chip;
struct flash_bank *saved_banks[SAM4_MAX_FLASH_BANKS];
unsigned x;
LOG_DEBUG("Begin");
details = all_sam4_details;
while (details->name) {
if (details->chipid_cidr == (private->chip->cfg.CHIPID_CIDR & 0xFFFFFFE0))
break;
else
details++;
}while (details->name) { ... }
if (!details->name) {
LOG_ERROR("SAM4 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
(unsigned int)(private->chip->cfg.CHIPID_CIDR));
LOG_INFO("SAM4 CHIPID_CIDR: 0x%08" PRIx32 " decodes as follows",
private->chip->cfg.CHIPID_CIDR);
sam4_explain_chipid_cidr(private->chip);
return ERROR_FAIL;
}if (!details->name) { ... } else {
LOG_DEBUG("SAM4 Found chip %s, CIDR 0x%08" PRIx32, details->name, details->chipid_cidr);
}else { ... }
chip = private->chip;
for (x = 0; x < SAM4_MAX_FLASH_BANKS; x++)
saved_banks[x] = chip->details.bank[x].bank;
memcpy(&(private->chip->details),
details,
sizeof(private->chip->details));
for (x = 0; x < SAM4_MAX_FLASH_BANKS; x++) {
chip->details.bank[x].chip = chip;
chip->details.bank[x].bank = saved_banks[x];
}for (x = 0; x < SAM4_MAX_FLASH_BANKS; x++) { ... }
LOG_DEBUG("End");
return ERROR_OK;
}{ ... }
static int sam4_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct sam4_bank_private *private;
int k = bank->size / 1024;
private = get_sam4_bank_private(bank);
if (!private)
return ERROR_FAIL;
command_print_sameline(cmd, "%s bank %d: %d kB at " TARGET_ADDR_FMT,
private->chip->details.name,
private->bank_number,
k,
bank->base);
return ERROR_OK;
}{ ... }
static int sam4_probe(struct flash_bank *bank)
{
int r;
struct sam4_bank_private *private;
LOG_DEBUG("Begin: Bank: %u", bank->bank_number);
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}if (bank->target->state != TARGET_HALTED) { ... }
private = get_sam4_bank_private(bank);
if (!private) {
LOG_ERROR("Invalid/unknown bank number");
return ERROR_FAIL;
}if (!private) { ... }
r = sam4_read_all_regs(private->chip);
if (r != ERROR_OK)
return r;
LOG_DEBUG("Here");
if (private->chip->probed)
r = sam4_get_info(private->chip);
else
r = sam4_get_details(private);
if (r != ERROR_OK)
return r;
for (unsigned int x = 0; x < SAM4_MAX_FLASH_BANKS; x++) {
if (bank->base == private->chip->details.bank[x].base_address) {
bank->size = private->chip->details.bank[x].size_bytes;
LOG_DEBUG("SAM4 Set flash bank to " TARGET_ADDR_FMT " - "
TARGET_ADDR_FMT ", idx %d", bank->base,
bank->base + bank->size, x);
break;
}if (bank->base == private->chip->details.bank[x].base_address) { ... }
}for (unsigned int x = 0; x < SAM4_MAX_FLASH_BANKS; x++) { ... }
if (!bank->sectors) {
bank->sectors = calloc(private->nsectors, (sizeof((bank->sectors)[0])));
if (!bank->sectors) {
LOG_ERROR("No memory!");
return ERROR_FAIL;
}if (!bank->sectors) { ... }
bank->num_sectors = private->nsectors;
for (unsigned int x = 0; x < bank->num_sectors; x++) {
bank->sectors[x].size = private->sector_size;
bank->sectors[x].offset = x * (private->sector_size);
bank->sectors[x].is_erased = -1;
bank->sectors[x].is_protected = -1;
}for (unsigned int x = 0; x < bank->num_sectors; x++) { ... }
}if (!bank->sectors) { ... }
private->probed = true;
r = sam4_protect_check(bank);
if (r != ERROR_OK)
return r;
LOG_DEBUG("Bank = %d, nbanks = %d",
private->bank_number, private->chip->details.n_banks);
if ((private->bank_number + 1) == private->chip->details.n_banks) {
flashd_read_uid(private);
}if ((private->bank_number + 1) == private->chip->details.n_banks) { ... }
return r;
}{ ... }
static int sam4_auto_probe(struct flash_bank *bank)
{
struct sam4_bank_private *private;
private = get_sam4_bank_private(bank);
if (private && private->probed)
return ERROR_OK;
return sam4_probe(bank);
}{ ... }
static int sam4_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{
struct sam4_bank_private *private;
int r;
int page_count;
page_count = 16;
uint32_t status;
LOG_DEBUG("Here");
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}if (bank->target->state != TARGET_HALTED) { ... }
r = sam4_auto_probe(bank);
if (r != ERROR_OK) {
LOG_DEBUG("Here,r=%d", r);
return r;
}if (r != ERROR_OK) { ... }
private = get_sam4_bank_private(bank);
if (!(private->probed))
return ERROR_FLASH_BANK_NOT_PROBED;
if ((first == 0) && ((last + 1) == private->nsectors)) {
LOG_DEBUG("Here");
return flashd_erase_entire_bank(private);
}if ((first == 0) && ((last + 1) == private->nsectors)) { ... }
LOG_INFO("sam4 does not auto-erase while programming (Erasing relevant sectors)");
LOG_INFO("sam4 First: 0x%08x Last: 0x%08x", first, last);
for (unsigned int i = first; i <= last; i++) {
r = flashd_erase_pages(private, (i * page_count), page_count, &status);
LOG_INFO("Erasing sector: 0x%08x", i);
if (r != ERROR_OK)
LOG_ERROR("SAM4: Error performing Erase page @ lock region number %u",
i);
if (status & (1 << 2)) {
LOG_ERROR("SAM4: Lock Region %u is locked", i);
return ERROR_FAIL;
}if (status & (1 << 2)) { ... }
if (status & (1 << 1)) {
LOG_ERROR("SAM4: Flash Command error @lock region %u", i);
return ERROR_FAIL;
}if (status & (1 << 1)) { ... }
}for (unsigned int i = first; i <= last; i++) { ... }
return ERROR_OK;
}{ ... }
static int sam4_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{
struct sam4_bank_private *private;
int r;
LOG_DEBUG("Here");
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}if (bank->target->state != TARGET_HALTED) { ... }
private = get_sam4_bank_private(bank);
if (!(private->probed))
return ERROR_FLASH_BANK_NOT_PROBED;
if (set)
r = flashd_lock(private, first, last);
else
r = flashd_unlock(private, first, last);
LOG_DEBUG("End: r=%d", r);
return r;
}{ ... }
static int sam4_page_read(struct sam4_bank_private *private, unsigned pagenum, uint8_t *buf)
{
uint32_t adr;
int r;
adr = pagenum * private->page_size;
adr = adr + private->base_address;
r = target_read_memory(private->chip->target,
adr,
4,
private->page_size / 4,
buf);
if (r != ERROR_OK)
LOG_ERROR("SAM4: Flash program failed to read page phys address: 0x%08x",
(unsigned int)(adr));
return r;
}{ ... }
static int sam4_set_wait(struct sam4_bank_private *private)
{
uint32_t fmr;
int r;
r = target_read_u32(private->chip->target, private->controller_address, &fmr);
if (r != ERROR_OK) {
LOG_ERROR("Error Read failed: read flash mode register");
return r;
}if (r != ERROR_OK) { ... }
fmr &= 0xfffff0ff;
fmr |= (private->flash_wait_states << 8);
LOG_DEBUG("Flash Mode: 0x%08x", ((unsigned int)(fmr)));
r = target_write_u32(private->bank->target, private->controller_address, fmr);
if (r != ERROR_OK)
LOG_ERROR("Error Write failed: set flash mode register");
return r;
}{ ... }
static int sam4_page_write(struct sam4_bank_private *private, unsigned pagenum, const uint8_t *buf)
{
uint32_t adr;
uint32_t status;
int r;
adr = pagenum * private->page_size;
adr = (adr + private->base_address);
LOG_DEBUG("Wr Page %u @ phys address: 0x%08x", pagenum, (unsigned int)(adr));
r = target_write_memory(private->chip->target,
adr,
4,
private->page_size / 4,
buf);
if (r != ERROR_OK) {
LOG_ERROR("SAM4: Failed to write (buffer) page at phys address 0x%08x",
(unsigned int)(adr));
return r;
}if (r != ERROR_OK) { ... }
r = efc_perform_command(private,
AT91C_EFC_FCMD_WP,
pagenum,
&status);
if (r != ERROR_OK)
LOG_ERROR("SAM4: Error performing Write page @ phys address 0x%08x",
(unsigned int)(adr));
if (status & (1 << 2)) {
LOG_ERROR("SAM4: Page @ Phys address 0x%08x is locked", (unsigned int)(adr));
return ERROR_FAIL;
}if (status & (1 << 2)) { ... }
if (status & (1 << 1)) {
LOG_ERROR("SAM4: Flash Command error @phys address 0x%08x", (unsigned int)(adr));
return ERROR_FAIL;
}if (status & (1 << 1)) { ... }
return ERROR_OK;
}{ ... }
static int sam4_write(struct flash_bank *bank,
const uint8_t *buffer,
uint32_t offset,
uint32_t count)
{
int n;
unsigned page_cur;
unsigned page_end;
int r;
unsigned page_offset;
struct sam4_bank_private *private;
uint8_t *pagebuffer;
pagebuffer = NULL;
if (count == 0) {
r = ERROR_OK;
goto done;
}if (count == 0) { ... }
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
r = ERROR_TARGET_NOT_HALTED;
goto done;
}if (bank->target->state != TARGET_HALTED) { ... }
private = get_sam4_bank_private(bank);
if (!(private->probed)) {
r = ERROR_FLASH_BANK_NOT_PROBED;
goto done;
}if (!(private->probed)) { ... }
if ((offset + count) > private->size_bytes) {
LOG_ERROR("Flash write error - past end of bank");
LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x",
(unsigned int)(offset),
(unsigned int)(count),
(unsigned int)(private->size_bytes));
r = ERROR_FAIL;
goto done;
}if ((offset + count) > private->size_bytes) { ... }
pagebuffer = malloc(private->page_size);
if (!pagebuffer) {
LOG_ERROR("No memory for %d Byte page buffer", (int)(private->page_size));
r = ERROR_FAIL;
goto done;
}if (!pagebuffer) { ... }
r = sam4_set_wait(private);
if (r != ERROR_OK)
goto done;
page_cur = offset / private->page_size;
page_end = (offset + count - 1) / private->page_size;
LOG_DEBUG("Offset: 0x%08x, Count: 0x%08x", (unsigned int)(offset), (unsigned int)(count));
LOG_DEBUG("Page start: %d, Page End: %d", (int)(page_cur), (int)(page_end));
if (page_cur == page_end) {
LOG_DEBUG("Special case, all in one page");
r = sam4_page_read(private, page_cur, pagebuffer);
if (r != ERROR_OK)
goto done;
page_offset = (offset & (private->page_size-1));
memcpy(pagebuffer + page_offset,
buffer,
count);
r = sam4_page_write(private, page_cur, pagebuffer);
if (r != ERROR_OK)
goto done;
r = ERROR_OK;
goto done;
}if (page_cur == page_end) { ... }
page_offset = offset & (private->page_size - 1);
if (page_offset) {
LOG_DEBUG("Not-Aligned start");
r = sam4_page_read(private, page_cur, pagebuffer);
if (r != ERROR_OK)
goto done;
n = (private->page_size - page_offset);
memcpy(pagebuffer + page_offset,
buffer,
n);
r = sam4_page_write(private, page_cur, pagebuffer);
if (r != ERROR_OK)
goto done;
count -= n;
offset += n;
buffer += n;
page_cur++;
}if (page_offset) { ... }
/* ... */
assert(offset % private->page_size == 0);
LOG_DEBUG("Full Page Loop: cur=%d, end=%d, count = 0x%08x",
(int)page_cur, (int)page_end, (unsigned int)(count));
while ((page_cur < page_end) &&
(count >= private->page_size)) {
r = sam4_page_write(private, page_cur, buffer);
if (r != ERROR_OK)
goto done;
count -= private->page_size;
buffer += private->page_size;
page_cur += 1;
}while ((page_cur < page_end) && (count >= private->page_size)) { ... }
if (count) {
LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count));
r = sam4_page_read(private, page_cur, pagebuffer);
if (r != ERROR_OK)
goto done;
memcpy(pagebuffer, buffer, count);
r = sam4_page_write(private, page_cur, pagebuffer);
if (r != ERROR_OK)
goto done;
}if (count) { ... }
LOG_DEBUG("Done!");
r = ERROR_OK;
done:
free(pagebuffer);
return r;
}{ ... }
COMMAND_HANDLER(sam4_handle_info_command)
{
struct sam4_chip *chip;
chip = get_current_sam4(CMD);
if (!chip)
return ERROR_OK;
unsigned x;
int r;
if (!chip->details.bank[0].bank) {
x = 0;
need_define:
command_print(CMD,
"Please define bank %d via command: flash bank %s ... ",
x,
at91sam4_flash.name);
return ERROR_FAIL;
}if (!chip->details.bank[0].bank) { ... }
if (!(chip->details.bank[0].probed)) {
r = sam4_auto_probe(chip->details.bank[0].bank);
if (r != ERROR_OK)
return ERROR_FAIL;
}if (!(chip->details.bank[0].probed)) { ... }
for (x = 1; x < SAM4_MAX_FLASH_BANKS; x++) {
if (!(chip->details.bank[x].present))
continue;
if (!chip->details.bank[x].bank)
goto need_define;
if (chip->details.bank[x].probed)
continue;
r = sam4_auto_probe(chip->details.bank[x].bank);
if (r != ERROR_OK)
return r;
}for (x = 1; x < SAM4_MAX_FLASH_BANKS; x++) { ... }
r = sam4_get_info(chip);
if (r != ERROR_OK) {
LOG_DEBUG("Sam4Info, Failed %d", r);
return r;
}if (r != ERROR_OK) { ... }
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(sam4_handle_gpnvm_command)
{
unsigned x, v;
int r, who;
struct sam4_chip *chip;
chip = get_current_sam4(CMD);
if (!chip)
return ERROR_OK;
if (chip->target->state != TARGET_HALTED) {
LOG_ERROR("sam4 - target not halted");
return ERROR_TARGET_NOT_HALTED;
}if (chip->target->state != TARGET_HALTED) { ... }
if (!chip->details.bank[0].bank) {
command_print(CMD, "Bank0 must be defined first via: flash bank %s ...",
at91sam4_flash.name);
return ERROR_FAIL;
}if (!chip->details.bank[0].bank) { ... }
if (!chip->details.bank[0].probed) {
r = sam4_auto_probe(chip->details.bank[0].bank);
if (r != ERROR_OK)
return r;
}if (!chip->details.bank[0].probed) { ... }
switch (CMD_ARGC) {
default:
return ERROR_COMMAND_SYNTAX_ERROR;default
case 0:
goto showall;case 0:
case 1:
who = -1;
break;case 1:
case 2:
if ((strcmp(CMD_ARGV[0], "show") == 0) && (strcmp(CMD_ARGV[1], "all") == 0))
who = -1;
else {
uint32_t v32;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], v32);
who = v32;
}else { ... }
break;case 2:
}switch (CMD_ARGC) { ... }
if (strcmp("show", CMD_ARGV[0]) == 0) {
if (who == -1) {
showall:
r = ERROR_OK;
for (x = 0; x < chip->details.n_gpnvms; x++) {
r = flashd_get_gpnvm(&(chip->details.bank[0]), x, &v);
if (r != ERROR_OK)
break;
command_print(CMD, "sam4-gpnvm%u: %u", x, v);
}for (x = 0; x < chip->details.n_gpnvms; x++) { ... }
return r;
}if (who == -1) { ... }
if ((who >= 0) && (((unsigned)(who)) < chip->details.n_gpnvms)) {
r = flashd_get_gpnvm(&(chip->details.bank[0]), who, &v);
if (r == ERROR_OK)
command_print(CMD, "sam4-gpnvm%u: %u", who, v);
return r;
}if ((who >= 0) && (((unsigned)(who)) < chip->details.n_gpnvms)) { ... } else {
command_print(CMD, "sam4-gpnvm invalid GPNVM: %u", who);
return ERROR_COMMAND_SYNTAX_ERROR;
}else { ... }
}if (strcmp("show", CMD_ARGV[0]) == 0) { ... }
if (who == -1) {
command_print(CMD, "Missing GPNVM number");
return ERROR_COMMAND_SYNTAX_ERROR;
}if (who == -1) { ... }
if (strcmp("set", CMD_ARGV[0]) == 0)
r = flashd_set_gpnvm(&(chip->details.bank[0]), who);
else if ((strcmp("clr", CMD_ARGV[0]) == 0) ||
(strcmp("clear", CMD_ARGV[0]) == 0))
r = flashd_clr_gpnvm(&(chip->details.bank[0]), who);
else {
command_print(CMD, "Unknown command: %s", CMD_ARGV[0]);
r = ERROR_COMMAND_SYNTAX_ERROR;
}else { ... }
return r;
}{ ... }
COMMAND_HANDLER(sam4_handle_slowclk_command)
{
struct sam4_chip *chip;
chip = get_current_sam4(CMD);
if (!chip)
return ERROR_OK;
switch (CMD_ARGC) {
case 0:
break;case 0:
case 1:
{
uint32_t v;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], v);
if (v > 200000) {
command_print(CMD, "Absurd/illegal slow clock freq: %d\n", (int)(v));
return ERROR_COMMAND_SYNTAX_ERROR;
}if (v > 200000) { ... }
chip->cfg.slow_freq = v;
break;
...}case 1:
default:
command_print(CMD, "Too many parameters");
return ERROR_COMMAND_SYNTAX_ERROR;default
}switch (CMD_ARGC) { ... }
command_print(CMD, "Slowclk freq: %d.%03dkhz",
(int)(chip->cfg.slow_freq / 1000),
(int)(chip->cfg.slow_freq % 1000));
return ERROR_OK;
}{ ... }
static const struct command_registration at91sam4_exec_command_handlers[] = {
{
.name = "gpnvm",
.handler = sam4_handle_gpnvm_command,
.mode = COMMAND_EXEC,
.usage = "[('clr'|'set'|'show') bitnum]",
.help = "Without arguments, shows all bits in the gpnvm "
"register. Otherwise, clears, sets, or shows one "
"General Purpose Non-Volatile Memory (gpnvm) bit.",
...},
{
.name = "info",
.handler = sam4_handle_info_command,
.mode = COMMAND_EXEC,
.help = "Print information about the current at91sam4 chip "
"and its flash configuration.",
.usage = "",
...},
{
.name = "slowclk",
.handler = sam4_handle_slowclk_command,
.mode = COMMAND_EXEC,
.usage = "[clock_hz]",
.help = "Display or set the slowclock frequency "
"(default 32768 Hz).",
...},
COMMAND_REGISTRATION_DONE
...};
static const struct command_registration at91sam4_command_handlers[] = {
{
.name = "at91sam4",
.mode = COMMAND_ANY,
.help = "at91sam4 flash command group",
.usage = "",
.chain = at91sam4_exec_command_handlers,
...},
COMMAND_REGISTRATION_DONE
...};
const struct flash_driver at91sam4_flash = {
.name = "at91sam4",
.commands = at91sam4_command_handlers,
.flash_bank_command = sam4_flash_bank_command,
.erase = sam4_erase,
.protect = sam4_protect,
.write = sam4_write,
.read = default_flash_read,
.probe = sam4_probe,
.auto_probe = sam4_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = sam4_protect_check,
.info = sam4_info,
.free_driver_priv = sam4_free_driver_priv,
...};