bl_Main.c
67.5 KB
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
1001
1002
1003
1004
1005
1006
1007
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
1037
1038
1039
1040
1041
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
1071
1072
1073
1074
1075
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
1282
1283
1284
1285
1286
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
1317
1318
1319
1320
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
1351
1352
1353
1354
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
1385
1386
1387
1388
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
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
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
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
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
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
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
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
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
1873
1874
1875
1876
1877
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
1919
1920
1921
1922
1923
1924
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
2005
2006
2007
2008
2009
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
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
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
2134
2135
2136
2137
2138
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
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
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
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
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
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
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
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
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
2642
2643
2644
2645
2646
2647
2648
2649
2650
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
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
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
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
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
2826
2827
2828
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
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* bl_main.c
*
* Project:
* --------
* Bootloader
*
* Description:
* ------------
* This file defines the major procedure of bootloader
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
* removed!
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include "kal_general_types.h"
#include "kal_public_api.h"
#include "sw_types.h"
#include "reg_base.h"
#include "emi_hw.h"
#include "bl_MTK_BB_REG.H"
#include "bl_BootInfo.h"
#include "bl_Init.h"
#include "bl_FOTA.h"
#include "bl_loader.h"
#include <rt_misc.h> /* for __rt_lib_init() */
#include "bl_uart_hw.h"
#include "kbd_table.h"
#include "bl_common.h"
#include "bl_features.h"
#include "bl_custom.h"
#include "bl_setting.h"
#include "feature_def.h"
#include <string.h>
#include "br_time_stamp.h"
#ifdef __TIME_STAMP__
#include "br_time_stamp_cb.h"
#include "bl_time_stamp_id.h"
#endif
#ifdef __SV5_ENABLED__
#include "br_GFH_file_info.h"
#include "br_GFH_epp_param.h"
#include "br_header_block.h"
#include "br_bl_param.h"
#include "bl_GFH_body.h"
#endif /* __SV5_ENABLED__ */
#if defined __NAND_FDM_50__
#include "nand_dal_version.h"
#endif /* __NAND_FDM_50__ */
#if defined(__CARD_DOWNLOAD__)
#include "bl_update.h"
#endif /* __CARD_DOWNLOAD__ */
#if defined(__FUNET_ENABLE__)
#include "bl_funet.h"
#endif /* __FUNET_ENABLE__ */
#if defined(__FUNET_ENABLE__) && defined(__EXT_BOOTLOADER__)
#include "funet.h"
#endif /* __FUNET_ENABLE__ && __EXT_BOOTLOADER__ */
#if defined(__DSP_FCORE4__)
#include "dmdsp_init.h"
#endif /* __DSP_FCORE4__ */
#ifdef __EXT_BL_UPDATE__
#include "SSF_ROMInfo_Type.h"
#include "custom_img_config.h"
#endif /* __EXT_BL_UPDATE__ */
#if defined(__FAST_LOGO__) && defined(__EXT_BOOTLOADER__)
#include "bootup_logo.h"
#include "CustFastLogoImgData.h"
#endif /* __FAST_LOGO__ && __EXT_BOOTLOADER__*/
#include "drv_features.h"
//#include "gpio_sw.h"
#include "dcl.h"
#include "dcl_gpio.h"
#if defined(__BMT_2_0_ARCHITECTURE__)
#include "bmt_chr_setting.h"
#endif
#include "init.h"
#include "config_hw.h"
/*************************************************************************
* Macro and const definition
*************************************************************************/
//Note that these value cannot be adjusted without discussing with Tool team
#ifndef __N_PLUS_0_PROJECT__
#define BL_DA_SHARED_DATA_MAX_SIZE (32*1024)
#else
#define BL_DA_SHARED_DATA_MAX_SIZE (4*1024)
#endif
#define BL_DA_SHARED_DATA_ID "_BL_DA_SHARED_DATA_"
#define MINI_EXT_SHARED_DATA_ID "_MINI_EXT_SHR_DATA_"
//ID for share data items
#define MINI_EXT_SHARD_FEATURE_COMBINATION 0x1000
#define MINI_EXT_SHARD_FEATURE_COMBINATION_EXT 0x1001
#define MINI_EXT_SHARD_RANDOM_SEED 0x1002
#define MINI_EXT_SHARD_BL_PARAM 0x1003
#define MINI_EXT_SHARE_BL_HEADER 0x1004
#define MINI_EXT_SHARE_BL_TOKEN 0x1005
#define MINI_EXT_SHARE_BL_TIME_STAMP_RECORD 0x1006
#define MINI_EXT_SHARE_EMI_PARAM 0x1007
#define MINI_EXT_SHARE_EXT_BL_UPDATE_INFO 0x1008
#define MINI_EXT_SHARE_USBDL_RETN 0x1009
#define TLV_SIZE_RECORD 0
#define REMAPPING_MASK (custom_RAM_baseaddr()-1)
#define BROM_USBDL_V2_TIMEOUT (30)
/*************************************************************************
* Structure definition
*************************************************************************/
typedef struct
{
kal_char m_blDaSharedDataId[32];
kal_uint32 m_payloadLength;
kal_uint32 m_payload[3];
} BL_DA_SHARED_DATA_HEADER;
typedef struct
{
kal_uint32 m_type;
kal_uint32 m_length;
} BL_DA_SHARED_DATA_STRUCT;
typedef enum
{
USBDL_NOT_TRIGGERED = 0x00,
USBDL_RESCUE_KEY,
USBDL_KEY,
USBDL_GPIO,
USBDL_FLAG,
USBDL_AUTO = 0x81,
} USBDL_TRIGGER_REASON;
/*************************************************************************
* External reference definition
*************************************************************************/
extern void Connect_FactoryTool(void);
extern kal_uint32 custom_ROM_baseaddr(void);
extern kal_bool USBDL_UART_Init(void);
extern void USBDL_Release(void);
extern kal_bool USBDL_Update_USB_Download_Mode(void);
extern kal_bool USBDL_Is_USB_Download_Mode(void);
extern void INT_RestorePLL(void);
extern void WatchDogResetAll(void);
extern kal_uint32 SST_Get_Secinfo(kal_uint32 rom_base, kal_bool check_mac);
extern kal_int32 SST_VerifyImageContent(kal_uint32 secinfo_addr, kal_uint32 mac_addr, kal_bool bFactoryBin);
extern kal_int32 SST_VerifyExtBootloader(kal_uint32 ebl_addr, kal_uint32 ebl_len, kal_uint32 ebl_header_addr, kal_uint32 ebl_header_len);
extern void set_debug_level(LOG_LEVEL level);
extern void NorFlashBooting(void);
extern void InitRegionsExt(void);
extern void CacheDeinit(void);
extern void CacheInit(void);
extern void InitExt(void);
extern void GetFeatureCombination(void);
extern kal_bool CheckPairedVersion(void);
extern kal_bool USBDLKey_Pressed(void);
extern kal_uint32* SST_GetToken(void);
extern void CacheDeInitMini(void);
extern void SetWDTNormalResetFlag(void);
extern void InitFPU(void);
extern kal_bool BL_kbd_IsKeyPressed(kal_uint8 key);
extern void ShutDownModule(void);
extern kal_uint32 custom_get_bootloader_version(kal_uint8 *version, kal_uint32 len);
extern void SST_SetToken(kal_uint32 *pToken, kal_uint32 tokenLen);
extern kal_uint32 GetMainRegionStartBlock(void);
extern kal_bool CheckFeatureCombination(void);
#ifdef __SV5_ENABLED__
extern kal_uint32 LoadMauiBody(void);
extern BL_STATUS LoadMAUIFirstPart(void);
#endif
#if defined(__FOTA_DM__)
extern kal_uint32 bl_loadFOTAImage(void);
#endif
#if defined(__SERIAL_FLASH_STT_EN__)
extern void stt_main(void);
#endif
extern void BL_ScanSerialFlashBlocks(void);
#if defined(__SNAND_STT_EN__)
extern void stt_snand_main();
#endif
extern kal_uint32 g_Bl_Secure_Test;
extern const LOG_LEVEL bootloader_debug_level;
/*************************************************************************
* Forward declearaion
*************************************************************************/
kal_bool bl_Init_BL_DA_SharedData(void);
void SetBootupFlag(kal_uint32 flag);
kal_uint32* bl_Allocate_BL_DA_SharedData(kal_uint32 type, kal_uint32 size);
void SetRetnFlag(kal_uint32 flag);
void ClrRetnFlag(kal_uint32 flag);
void SetRetnTimeout(kal_uint32 time);
USBDL_TRIGGER_REASON USBDL_Detect(void);
kal_bool IsBromUSBDLDetectionFailed(void);
/*************************************************************************
* Global variables definition
*************************************************************************/
kal_uint32 g_mauiFeatureCombination = 0;
kal_uint32 g_randomSeed = 0;
kal_bool g_bromCmdModeDisabled = KAL_FALSE;
kal_uint8 g_emi_param[2] = {0};
//Flag to control the flow
kal_uint32 g_bootupStatus = BL_BOOTUP_FAIL_REASON_NONE;
kal_bool g_bootupDisabled = KAL_FALSE;
kal_bool g_usbdlDisabled = KAL_FALSE;
kal_bool g_carddlDisabled = KAL_FALSE;
kal_bool g_enterCarddl = KAL_FALSE;
kal_bool g_enterFUNET = KAL_FALSE;
#ifdef __EXT_BL_UPDATE__
BL_EXT_BL_UPDATE_INFO g_extBlUpdateInfo;
#endif /* __EXT_BL_UPDATE__ */
#ifdef __SV5_ENABLED__
#if defined(__COPY_BROM_BL_PARAM_TO_EXTERNAL_RAM__) && defined(__EXT_BOOTLOADER__)
BL_Param_v4 g_BROM_BL_Param;
BL_Param_v4 *g_pBROM_BL_Param = &g_BROM_BL_Param;
#else
BL_Param_v4 *g_pBROM_BL_Param = NULL;
#endif /* __COPY_BROM_BL_PARAM_TO_EXTERNAL_RAM__ && __EXT_BOOTLOADER__ */
#else
#pragma arm section rodata = "HEAD_BL"
const MTK_EXT_BL_INFO_v01 g_ExtBootloaderInfo =
{
#if defined(_NAND_FLASH_BOOTING_) || defined(__EMMC_BOOTING__)
#if defined(__EBL_UPDATE_TOOL_SUPPORT_NAND__)
"MTK_EBL_INFO_v02",
#else
"MTK_EBL_INFO_v01",
#endif
#else
"MTK_EBL_INFO_v02",
#endif
BL_MAUI_PAIRED_VER,
(FEATURE_COMBINATION | FEATURE_BL_ALWAYS_SUPPORT),
#if defined __NAND_FDM_50__
FDM_VERSION, 0, 0, DAL_VERISON // FDM and DAL version
#else
0, 0, 0, 0 // FDM and DAL version
#endif
};
#pragma arm section rodata
#endif /* __SV5_ENABLED__ */
#if defined (__BROM_USBDL_V2__) || defined(__FUNET_ENABLE__)
kal_uint32 g_usbdlRetnValue = 0xffffffff; //Must use RW
#endif /* __BROM_USBDL_V2__ */
#pragma arm section rwdata = "MINI_EXT_DA_SHARE", zidata = "MINI_EXT_DA_SHARE"
kal_uint32 g_mini_ext_da_share_buf[BL_DA_SHARED_DATA_MAX_SIZE/4];
#pragma arm section rwdata, zidata
/*************************************************************************
* Main code
*************************************************************************/
#ifdef __BL_SLIM_DIV__
kal_uint32 bl_slim_div(const kal_uint32 n, const kal_uint32 d, kal_uint32 *pR)
{
kal_uint32 q=0, r=0;
kal_int32 m;
for(m=0x8000000; m; m>>=1)
{
r = r << 1;
r |= (n&m) ? 1 : 0;
if(r >= d)
{
r -= d;
q |= m;
}
}
if(pR)
{
*pR = r;
}
return q;
}
kal_uint32 bl_slim_mod(const kal_uint32 n, const kal_uint32 d)
{
kal_uint32 r;
bl_slim_div(n, d, &r);
return r;
}
#endif
/**********************************************************
Description : Facility for BL-DA shared data, initialize structure
Input :
Output :
***********************************************************/
kal_bool bl_Init_TLV_Service(kal_uint32 buffAddr, kal_uint32 buffSize, const kal_char *pId)
{
BL_DA_SHARED_DATA_HEADER *pSharedData = (BL_DA_SHARED_DATA_HEADER*)buffAddr;
ASSERT(buffSize > sizeof(BL_DA_SHARED_DATA_HEADER));
memset(pSharedData->m_blDaSharedDataId, 0, sizeof(pSharedData->m_blDaSharedDataId));
strcpy(pSharedData->m_blDaSharedDataId, pId);
pSharedData->m_payload[0] = TLV_SIZE_RECORD;
pSharedData->m_payload[1] = 4;
pSharedData->m_payload[2] = buffSize;
pSharedData->m_payloadLength = sizeof(pSharedData->m_payload);
return KAL_TRUE;
}
kal_uint32* bl_Traverse_TLV_Record(kal_uint32 buffAddr, kal_uint32 *it, kal_uint32 *pType, kal_uint32 *pSize)
{
BL_DA_SHARED_DATA_HEADER *pSharedDataHeader = (BL_DA_SHARED_DATA_HEADER*)buffAddr;
BL_DA_SHARED_DATA_STRUCT *pSharedData;
if(*it == NULL)
{
*it = (kal_uint32)pSharedDataHeader->m_payload;
}
pSharedData = (BL_DA_SHARED_DATA_STRUCT*)((kal_uint32)*it + sizeof(BL_DA_SHARED_DATA_STRUCT) + ((BL_DA_SHARED_DATA_STRUCT*)*it)->m_length);
if((kal_uint32)pSharedData - (kal_uint32)pSharedDataHeader->m_payload < pSharedDataHeader->m_payloadLength)
{
if(pType)
{
*pType = pSharedData->m_type;
}
if(pSize)
{
*pSize = pSharedData->m_length;
}
*it = (kal_uint32)pSharedData;
return (kal_uint32*)(pSharedData+1);
}
return NULL;
}
kal_uint32* bl_Get_TLV_Record(kal_uint32 buffAddr, kal_uint32 type, kal_uint32 *pSize)
{
BL_DA_SHARED_DATA_HEADER *pSharedDataHeader = (BL_DA_SHARED_DATA_HEADER*)buffAddr;
BL_DA_SHARED_DATA_STRUCT *pSharedData;
kal_uint32 n;
ASSERT(pSharedDataHeader->m_payload[0] == TLV_SIZE_RECORD && pSharedDataHeader->m_payload[1] == 4);
n = 3;
while(n<pSharedDataHeader->m_payloadLength)
{
pSharedData = (BL_DA_SHARED_DATA_STRUCT*)((kal_uint32)(&pSharedDataHeader->m_payload) + n);
if(pSharedData->m_type == type)
{
if(pSize)
{
*pSize = pSharedData->m_length;
}
return (kal_uint32*)(pSharedData+1);
}
n += pSharedData->m_length + sizeof(BL_DA_SHARED_DATA_STRUCT);
}
return NULL;
}
/**********************************************************
Description : Facility for BL-DA shared data, allocate a new space
Input : id of the requested record, and size of it
Output : the pointer to the buffer for record
***********************************************************/
kal_uint32* bl_Allocate_TLV_Record(kal_uint32 buffAddr, kal_uint32 type, kal_uint32 size)
{
BL_DA_SHARED_DATA_HEADER *pSharedDataHeader = (BL_DA_SHARED_DATA_HEADER*)buffAddr;
BL_DA_SHARED_DATA_STRUCT *pSharedData;
kal_uint32 tlvLen = pSharedDataHeader->m_payload[2];
ASSERT(type != TLV_SIZE_RECORD);
//Align to 4B
size = ((size+3)>>2)<<2;
if(pSharedDataHeader->m_payloadLength + (size + sizeof(BL_DA_SHARED_DATA_STRUCT)) > tlvLen)
{
return NULL;
}
pSharedData = (BL_DA_SHARED_DATA_STRUCT*)(&pSharedDataHeader->m_payload[pSharedDataHeader->m_payloadLength/4]);
pSharedData->m_type = type;
pSharedData->m_length = size;
pSharedDataHeader->m_payloadLength += (size + sizeof(BL_DA_SHARED_DATA_STRUCT));
return (kal_uint32*)(pSharedData+1);
}
/**********************************************************
Description : Facility for BL-DA shared data, initialize structure
Input :
Output :
***********************************************************/
kal_bool bl_Init_MINI_EXT_SharedData(void)
{
return bl_Init_TLV_Service((kal_uint32)g_mini_ext_da_share_buf, sizeof(g_mini_ext_da_share_buf), MINI_EXT_SHARED_DATA_ID);
}
/**********************************************************
Description : Facility for BL-DA shared data, allocate a new space
Input : id of the requested record, and size of it
Output : the pointer to the buffer for record
***********************************************************/
kal_uint32* bl_Allocate_MINI_EXT_SharedData(kal_uint32 type, kal_uint32 size)
{
return bl_Allocate_TLV_Record((kal_uint32)g_mini_ext_da_share_buf, type, size);
}
#ifdef __MINI_BOOTLOADER__
kal_bool VerifyExtBootloader(kal_uint32 extBlAddr)
{
#ifdef __MTK_SECURE_PLATFORM__
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(__SV5_ENABLED__)
/* under construction !*/
#if !defined(__BRINGUP_SUPPORT__)
/* under construction !*/
#if !defined(__16_3_SEG__) && !defined(__32_32_SEG__) || defined(__MTK_SECURE_PLATFORM__)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
#endif /* !__BRINGUP_SUPPORT__ */
/* under construction !*/
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(_NAND_FLASH_BOOTING_) || defined(__EMMC_BOOTING__)
/* under construction !*/
#if defined(__EBL_UPDATE_TOOL_SUPPORT_NAND__)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
#endif /* __SV5_ENABLED__ */
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MTK_SECURE_PLATFORM__ */
return KAL_TRUE;
}
void JumpToExtBootloader(kal_uint32 extBlAddr)
{
bl_Init_MINI_EXT_SharedData();
//Prepare argument needs to be passed
#define PASS_BUFFER_TO_EXT_BL(_ID, _P, _LEN) \
memcpy(bl_Allocate_MINI_EXT_SharedData((_ID), (_LEN)), (void*)(_P), (_LEN))
//This is the simplied version for convenience. User must make sure this variable is 4B aligned
#define PASS_VARIABLE_TO_EXT_BL(_ID, _VAR) \
if(sizeof(_VAR) <= 4) *(kal_uint32*)bl_Allocate_MINI_EXT_SharedData((_ID), sizeof(_VAR)) = *(kal_uint32*)(&(_VAR)); \
else memcpy(bl_Allocate_MINI_EXT_SharedData((_ID), sizeof(_VAR)), &(_VAR), sizeof(_VAR))
#ifdef __SV5_ENABLED__
#ifdef __COPY_BROM_BL_PARAM_TO_EXTERNAL_RAM__
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARD_BL_PARAM, *g_pBROM_BL_Param);
#else
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARD_BL_PARAM, g_pBROM_BL_Param);
#endif
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARD_FEATURE_COMBINATION, g_bootloader_gfh.gfh_arm_bl_info.m_feature_combination);
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARD_FEATURE_COMBINATION_EXT, g_bootloader_gfh.gfh_arm_bl_info.m_feature_combination_ex);
#else
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARD_FEATURE_COMBINATION, g_ExtBootloaderInfo.m_feature_combination);
#endif
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARD_RANDOM_SEED, g_randomSeed);
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARE_BL_HEADER, BLHeader);
PASS_BUFFER_TO_EXT_BL(MINI_EXT_SHARE_BL_TOKEN, (kal_uint32*)SST_GetToken(), sizeof(((BL_MAUI_ShareData*)(0))->m_bl_token));
PASS_BUFFER_TO_EXT_BL(MINI_EXT_SHARE_EMI_PARAM, g_emi_param, sizeof(g_emi_param));
#ifdef __EXT_BL_UPDATE__
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARE_EXT_BL_UPDATE_INFO, g_extBlUpdateInfo);
#endif /* __EXT_BL_UPDATE__ */
#if defined(__BROM_USBDL_V2__) || defined(__FUNET_ENABLE__)
PASS_VARIABLE_TO_EXT_BL(MINI_EXT_SHARE_USBDL_RETN, g_usbdlRetnValue);
#endif /* __BROM_USBDL_V2__ */
#ifdef __SV5_ENABLED__
if(extBlAddr != INVALID_START_ADDR)
{
extBlAddr += ((GFH_FILE_INFO_v1*)(extBlAddr))->m_jump_offset;
}
#endif /* __SV5_ENABLED__ */
CacheDeInitMini();
BL_PRINT(LOG_INFO, "Jump to ExtBL, %x\n\r",extBlAddr);
TS_END(TSID_BL_BOOTLOADER);
#ifdef __TIME_STAMP__
{
kal_uint32 tsAddr, tsSize;
TS_GetContext(&tsAddr, &tsSize);
PASS_BUFFER_TO_EXT_BL(MINI_EXT_SHARE_BL_TIME_STAMP_RECORD, tsAddr, tsSize);
}
#endif
JumpCmd(extBlAddr);
}
void USBDLPreSet(void)
{
#if defined(__USB_DOWNLOAD__) && defined(__BROM_USBDL_V2__)
g_usbdlRetnValue = *RETN_FLAG;
//Set it to BROM USBDL, 10s
SetRetnTimeout(10);
SetRetnFlag(RETN_USBDL_BY_FLAG_EN);
ClrRetnFlag(RETN_USBDL_TYPE_MASK);
#ifdef MT6250
SetRetnFlag(RETN_USBDL_TRIGGERED_BY_BL);
#endif
#elif defined(__FUNET_ENABLE__)
g_usbdlRetnValue = *RETN_FLAG;
#endif /* __USB_DOWNLOAD__ && __BROM_USBDL_V2__ */
}
void MiniBLErrorHandler(void)
{
BL_PRINT(LOG_ERROR, "MiniBL is dead!!\r\n");
#if defined(__USB_DOWNLOAD__) && defined(__BROM_USBDL_V2__)
//Trigger BROM USBDL and try to recover this situation
WatchDogResetAll();
#endif
}
#endif /*__MINI_BOOTLOADER__ */
/*************************************************************************
* Main code of both of Bootloaders
*************************************************************************/
void TriggerMetaMode(void)
{
(*(volatile kal_uint16 *)BOOT_CONFIG_ADDR) |= 0x01;
}
kal_bool IsUsbATModeEnabled(void)
{
return ((*(volatile kal_uint16 *)BOOT_CONFIG_ADDR) & 0x04) ? KAL_TRUE : KAL_FALSE;
}
kal_bool IsMetaModeEnabled(void)
{
return ((*(volatile kal_uint16 *)BOOT_CONFIG_ADDR) & 0x01) ? KAL_TRUE : KAL_FALSE;
}
kal_bool IsFactoryModeToMAUI(void)
{
return (IsMetaModeEnabled() || IsUsbATModeEnabled()) ? KAL_TRUE : KAL_FALSE;
}
#ifdef __USBDL_IN_BOOTROM__
kal_bool IsUSBEstablishedInBootROM(void)
{
#ifdef __SV5_ENABLED__
return (g_pBROM_BL_Param->m_brom_flags & BL_PARAM_USB_COM_ENABLED) ? KAL_TRUE : KAL_FALSE;
#else
return ((*(volatile kal_uint16 *)BOOT_CONFIG_ADDR) & 0x02) ? KAL_TRUE : KAL_FALSE;
#endif
}
#endif /* __USBDL_IN_BOOTROM__ */
kal_bool IsInWithOutBatteryMode(void)
{
return ((*(volatile kal_uint16 *)BOOT_CONFIG_ADDR) & 0x08) ? KAL_TRUE : KAL_FALSE;
}
#ifdef __BROM_USBDL_V2__
void SetRetnFlag(kal_uint32 flag)
{
*RETN_FLAG_SET = (0x4e000000 | flag);
}
void ClrRetnFlag(kal_uint32 flag)
{
*RETN_FLAG_CLR = (0x4e000000 | flag);
}
void SetRetnTimeout(kal_uint32 time)
{
*RETN_DAT0 = time;
}
void ClearUSBDLFlag(void)
{
#ifdef MT6250
ClrRetnFlag(RETN_USBDL_TRIGGERED_BY_BL);
#endif
ClrRetnFlag(RETN_USBDL_BY_FLAG_EN|RETN_USBDL_TYPE_MASK);
}
void RestoreUSBDLFlag(void)
{
ClearUSBDLFlag();
SetRetnFlag(g_usbdlRetnValue & (RETN_USBDL_BY_FLAG_EN|RETN_USBDL_TYPE_MASK));
}
#endif /* __BROM_USBDL_V2__ */
/*************************************************************************
* Main code of ExtBootloader
*************************************************************************/
#ifdef __EXT_BOOTLOADER__
#if defined(__USB_DOWNLOAD__) || defined(__UART_DOWNLOAD__)
static kal_uint32 usbdl_timer_start = 0xffffffff;
static enum {USBDL_TIMER_STOP, USBDL_TIMER_RUNNING} usbdl_timer_state = USBDL_TIMER_STOP;
kal_bool USBDLGPIO_Enabled(void)
{
/* When the GPIO is connected to ground, enable USBDL */
#ifdef __CUST_NEW__
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
#else
DCL_HANDLE handle;
GPIO_CTRL_READ_T data;
handle = DclGPIO_Open(DCL_GPIO, gpio_usbdl_pin);
DclGPIO_Control(handle, GPIO_CMD_READ, (DCL_CTRL_DATA_T*)&data);
DclGPIO_Close(handle);
if(data.u1IOData == 0)
{
return KAL_TRUE;
}
#endif
#endif /* __CUST_NEW__ */
return KAL_FALSE;
}
void USBDL_Start_Timer(void)
{
if ( usbdl_timer_state == USBDL_TIMER_STOP )
{
usbdl_timer_state = USBDL_TIMER_RUNNING;
usbdl_timer_start = INT_GetCurrentTime();
}
}
void USBDL_Stop_Timer(void)
{
usbdl_timer_state = USBDL_TIMER_STOP;
}
kal_bool USBDL_Is_Timeout_Ex(kal_uint32 timeoutMs)
{
kal_uint32 elapsed;
switch (usbdl_timer_state)
{
case USBDL_TIMER_STOP:
return KAL_FALSE;
case USBDL_TIMER_RUNNING:
elapsed = INT_GetCurrentTime() - usbdl_timer_start;
//32K, elapsed * (1/32K) is second based
if ((elapsed>>10)*1000 < timeoutMs*32 )
return KAL_FALSE;
return KAL_TRUE;
}
return KAL_FALSE;
}
kal_bool USBDL_Is_Timeout(void)
{
if (usbdlauto_timeout != NO_USBDL_AUTO_TIMEOUT)
{
return USBDL_Is_Timeout_Ex(usbdlauto_timeout);
}
return KAL_FALSE;
}
kal_bool USBDL_Cable_Detected(void)
{
#ifdef __DRV_EXT_CHARGER_DETECTION__
extern kal_bool MU_BootUP_USB_Detect(void);
return MU_BootUP_USB_Detect();
#else
extern kal_bool USBDL_Cable_IN(void);
return USBDL_Cable_IN();
#endif /* __DRV_EXT_CHARGER_DETECTION__ */
}
kal_bool USBDL_76DLFlag_Detect(void)
{
#if defined(MT6276) || defined(MT6270)
kal_bool firstBootup = KAL_FALSE;
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
if( ((*(volatile unsigned short *)(RTC_base + 0x50)) != 0xa357) || ((*(volatile unsigned short *)(RTC_base + 0x54)) != 0x67d2) )
{
firstBootup = KAL_TRUE;
}
if(firstBootup == KAL_FALSE)
{
if ((*(volatile unsigned short *)(RTC_base + 0x60)) & 0x1) //For data card to active USB COM PORT
{
return KAL_TRUE;
}
}
else
{
*(volatile unsigned short *)(RTC_base + 0x68) = 0x586a;
*(volatile unsigned short *)(RTC_base + 0x74) = 0x0001;
while((*(volatile unsigned short *)(RTC_base + 0x00)) & 0x40) {}; // Timeout period: 120usec
*(volatile unsigned short *)(RTC_base + 0x68) = 0x9136;
*(volatile unsigned short *)(RTC_base + 0x74) = 0x0001;
while((*(volatile unsigned short *)(RTC_base + 0x00)) & 0x40) {}; // Timeout period: 120usec
//Clear SPARE 2
*(volatile unsigned short *)(RTC_base + 0x60) = 0x0000;
*(volatile unsigned short *)(RTC_base + 0x74) = 0x0001;
}
#endif
return KAL_FALSE;
}
/* Exported API for continously checking if the triggering condition remains,
* including the 30s/auto-detection timeout handling
*/
kal_bool USBDL_Ready_To_Enter_DLMode(void)
{
static USBDL_TRIGGER_REASON triggeredReason = USBDL_NOT_TRIGGERED;
static kal_bool explicitUSBDLDetected = KAL_FALSE;
#if defined(__USBDL_IN_BOOTROM__) && !defined(__BROM_USBDL_V2__)
if (IsUSBEstablishedInBootROM())
{
//Since BootROM has established the connection, no more tests
return IsFactoryModeToMAUI() ? KAL_FALSE : KAL_TRUE;
}
#endif /* __USBDL_IN_BOOTROM__ && !__BROM_USBDL_V2__ */
if(usbdl_holding_mode)
{
if(explicitUSBDLDetected)
{
return KAL_TRUE;
}
}
//For auto-detection and BROM USBDL v2's timeout
USBDL_Start_Timer();
//Aligned with BootROM's behavior -- "detect once, trigger always until timedout"
#if defined(__BROM_USBDL_V2__)
if(triggeredReason == USBDL_NOT_TRIGGERED)
#endif
{
triggeredReason = USBDL_Detect();
//Explict USBDL conditions
if(triggeredReason != USBDL_NOT_TRIGGERED && triggeredReason != USBDL_AUTO)
{
explicitUSBDLDetected = KAL_TRUE;
return KAL_TRUE;
}
}
//No explicit condition now, check timeout
if(explicitUSBDLDetected)
{
//Explicit condition was found, keep it waiting for BROM v2
#if defined(__BROM_USBDL_V2__)
if(USBDL_Is_Timeout_Ex(BROM_USBDL_V2_TIMEOUT*1000) == KAL_FALSE)
{
return KAL_TRUE;
}
#endif
}
else
{
//Try auto-timeout if no explicit condition has been ever found
if(triggeredReason == USBDL_AUTO && USBDL_Cable_Detected() && USBDL_Is_Timeout() == KAL_FALSE)
{
return KAL_TRUE;
}
}
return KAL_FALSE;
}
#define Delay_Count 324675
static const volatile kal_uint8 startcmd_len = 4;
static const kal_uint8 startcmd[4] = {
0xa0,
0x0a,
0x50,
0x05
};
kal_uint8 USBDL_CheckStartCmd(void)
{
kal_uint8 startcmd_index = 0;
kal_uint32 count = Delay_Count;
kal_uint8 data;
kal_uint8 GetStartCmd = KAL_FALSE;
while(count || usbdl_holding_mode)
{
#ifdef __USB_DOWNLOAD__
data = USBDL_GetUARTByte_Ext(KAL_FALSE) ;
USBDL_PutUARTByte_Ext(~data,KAL_FALSE);
USBDL_PutUARTByte_Complete_Ext(KAL_FALSE);
if(USBDL_Ready_To_Enter_DLMode() == KAL_FALSE)
{
break;
}
#elif __UART_DOWNLOAD__
data = GetUARTByte() ;
PutUARTByte(~data);
PutUARTByte_Complete();
#else
#error "Impossible"
#endif
if (data == startcmd[startcmd_index])
{
count = Delay_Count;
startcmd_index++;
if (startcmd_index == startcmd_len)
{
GetStartCmd = KAL_TRUE;
break;
}
}
else
{
startcmd_index = 0;
}
count--;
}
return GetStartCmd;
}
/**********************************************************
Description : Major Procedure for USB Download
Input : None
Output : None
***********************************************************/
void USBDL_Main(void)
{
kal_bool skipDownload = KAL_FALSE;
/* MAIN 1 : Check USB DL KEY Pressed */
if (USBDL_Ready_To_Enter_DLMode() == KAL_FALSE)
{
/* go to boot maui */
return;
}
dbg_print("Open COM port...\n\r");
/* MAIN 2 : Setup USB Virtual COM */
#ifdef __DRV_EXT_CHARGER_DETECTION__
{
extern kal_bool MU_BootUP_USB_Detect(void);
MU_BootUP_USB_Detect();
}
#endif /* __DRV_EXT_CHARGER_DETECTION__ */
#ifdef __USB_DOWNLOAD__
#if defined(__USBDL_IN_BOOTROM__) && !defined(__BROM_USBDL_V2__)
if (IsUSBEstablishedInBootROM())
{
USBDL_USB_Config_Init();
}
else
#endif
{
USBDL_UART_Init();
}
/* MAIN 3 : Confirm COM port is ready */
if (USBDL_Is_USB_Download_Mode() == KAL_FALSE )
{
/* User Abort the USB Download */
skipDownload = KAL_TRUE;
}
#endif
/* MAIN 4 : Check Start Cmd */
#if defined(__USBDL_IN_BOOTROM__) && !defined(__BROM_USBDL_V2__) && defined(__USB_DOWNLOAD__)
if(!IsUSBEstablishedInBootROM())
#endif
{
if (skipDownload == KAL_FALSE && USBDL_CheckStartCmd() == KAL_FALSE)
{
/* User Run Unknown Program on PC side */
skipDownload = KAL_TRUE;
}
}
/* MAIN 5 : BOOTROM-like procedure start */
if (skipDownload == KAL_FALSE)
{
#ifdef __USBDL_IN_BOOTROM__
/* Reset the boot config register since it may be set due to GPIO init */
*(volatile kal_uint16 *)BOOT_CONFIG_ADDR = 0;
#endif
#if defined(__MTK_SECURE_PLATFORM__) && defined(_NAND_FLASH_BOOTING_) && !defined(__SV5_ENABLED__)
/* under construction !*/
#endif /* __MTK_SECURE_PLATFORM__ && _NAND_FLASH_BOOTING_ */
#if defined(__MTK_SECURE_PLATFORM__) && defined(__SV5_ENABLED__)
/* under construction !*/
#endif
USBDL_Stop_Timer();
if(usbdl_holding_mode)
{
extern void USBDL_SetWDTMode(kal_bool wdtkick);
USBDL_SetWDTMode(KAL_FALSE);
WacthDogDisable();
}
bl_Init_BL_DA_SharedData();
#if defined(__TC01__)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
#if defined(__EXT_BL_UPDATE__)
{
BL_EXT_BL_UPDATE_INFO *pExtBlUpdateInfo = (BL_EXT_BL_UPDATE_INFO*) bl_Allocate_BL_DA_SharedData(BL_DA_SHARED_DATA_ID_EXT_BL_UPDATE_INFO, sizeof(BL_EXT_BL_UPDATE_INFO));
memcpy(pExtBlUpdateInfo, &g_extBlUpdateInfo, sizeof(BL_EXT_BL_UPDATE_INFO));
}
#endif /* __EXT_BL_UPDATE__ */
#if defined(__BROM_USBDL_V2__)
RestoreUSBDLFlag();
#endif
Connect_FactoryTool();
/* if it reach here, boot maui directly (Meta mode) */
SetBootupFlag(BL_INFO_USBDL_IN_BL_CONNECTED);
#if defined(__SECURE_USB_DOWNLOAD__) || defined(__SECURE_UART_DOWNLOAD__)
{
extern kal_bool g_BlFirstDownload;
if(g_BlFirstDownload != KAL_TRUE)
{
SetBootupFlag(BL_INFO_SUSBDL_IN_BL_ENABLED);
}
}
#endif
}
else
{
if (USBDL_Is_Timeout() == KAL_FALSE)
{
/* Not because of timeout. Reset the phone */
dbg_print("Key or GPIO release before USBDL initialization completed, reset\n\r");
SetWDTNormalResetFlag();
WatchDogResetAll();
}
// Go on with the bootup procedure since it's caused by a time-out of implicit USBDL
#ifdef __USB_DOWNLOAD__
USBDL_Release();
#endif
}
//Return and continue the boot-up
}
kal_bool KeyCombinationPressed(kal_uint8 key1, kal_uint8 key2)
{
if(key1 != DEVICE_KEY_NONE)
{
if(!BL_kbd_IsKeyPressed(key1))
{
return KAL_FALSE;
}
if(key2 != DEVICE_KEY_NONE && !BL_kbd_IsKeyPressed(key2) )
{
return KAL_FALSE;
}
}
else
{
return KAL_FALSE;
}
return KAL_TRUE;
}
USBDL_TRIGGER_REASON USBDL_Detect(void)
{
USBDL_TRIGGER_REASON detected = USBDL_NOT_TRIGGERED;
#if defined(__BROM_USBDL_V2__)
if(IsBromUSBDLDetectionFailed())
{
BL_PRINT(LOG_INFO, "BROM tried but not detected cable or tool, skip it this time\r\n");
return USBDL_NOT_TRIGGERED;
}
#endif
#if defined(__BMT_2_0_ARCHITECTURE__)
if(USBDL_Cable_Detected())
{
DCL_BOOL vbat_cc_det_status = DCL_FALSE;
bl_chr_control_handler(BMT_BL_CHARGING_CMD_GET_CC_STATUS, &vbat_cc_det_status);
if(vbat_cc_det_status == DCL_FALSE)
{
BL_PRINT(LOG_INFO, "Still in preCC stage, skip it this time\r\n");
return USBDL_NOT_TRIGGERED;
}
}
#endif
//Check all possible conditions to enter USBDL
//Rescue key has the highest priority
#if defined(__BROM_USBDL_V2__)
if(KeyCombinationPressed(usbdlkey_rescue_position, usbdlkey_rescue_position2))
{
detected = USBDL_RESCUE_KEY;
}
else
#endif /* __BROM_USBDL_V2__ */
//Detect flags from MAUI
#if defined(__BROM_USBDL_V2__)
if((g_usbdlRetnValue & RETN_USBDL_BY_FLAG_EN) &&
(g_usbdlRetnValue & RETN_USBDL_TYPE_MASK))
{
detected = USBDL_FLAG;
}
else
#else
if(USBDL_76DLFlag_Detect())
{
detected = USBDL_FLAG;
}
else
#endif /* __BROM_USBDL_V2__ */
//GPIO
#ifdef __CUST_NEW__
if (gpio_usbdl_pin != NO_USBDL_GPIO && USBDLGPIO_Enabled() == KAL_TRUE)
{
detected = USBDL_GPIO;
}
else
#endif /* __CUST_NEW__ */
//Keypad, normal download
if(KeyCombinationPressed(usbdlkey_position, usbdlkey_position2))
{
detected = USBDL_KEY;
}
else
//Auto-timeout, lowest priority
if(usbdlauto_timeout != NO_USBDL_AUTO_TIMEOUT && USBDL_Cable_Detected())
{
detected = USBDL_AUTO;
}
return detected;
}
#ifdef __MTK_INTERNAL__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(__BROM_USBDL_V2__)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(__SECURE_USB_DOWNLOAD__)
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if defined(__BROM_USBDL_V2__)
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef __CUST_NEW__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MTK_INTERNAL__ */
#ifdef __BROM_USBDL_V2__
void InitiateBromUSBDL(USBDL_TRIGGER_REASON triggerReason)
{
kal_uint32 timeout = 0;
switch(triggerReason)
{
case USBDL_RESCUE_KEY:
case USBDL_KEY:
case USBDL_GPIO:
case USBDL_FLAG:
if(usbdl_holding_mode)
{
timeout = 0xff;
}
else
{
timeout = BROM_USBDL_V2_TIMEOUT;
}
break;
case USBDL_AUTO:
timeout = usbdlauto_timeout/1000;
break;
default:
ASSERT(0);
}
SetRetnTimeout(timeout);
SetRetnFlag(RETN_USBDL_BY_FLAG_EN);
ClrRetnFlag(RETN_USBDL_TYPE_MASK);
#ifdef MT6250
SetRetnFlag(RETN_USBDL_TRIGGERED_BY_BL);
#endif
BL_PRINT(LOG_INFO, "Launch BROM USBDL (%ds)\r\n\r\n\r\n\r\n\r\n", timeout);
SetWDTNormalResetFlag();
WatchDogResetAll();
while(1);
}
kal_bool IsBromUSBDLDetectionFailed(void)
{
#ifndef MT6250
return (g_pBROM_BL_Param->m_brom_flags & BL_PARAM_BROM_USBDL_FAILED) ? KAL_TRUE : KAL_FALSE;
#else
//MT6250 BootROM doesn't has this flag, use another retention bit instead
return (g_usbdlRetnValue & RETN_USBDL_TRIGGERED_BY_BL) ? KAL_TRUE : KAL_FALSE ;
#endif
}
#endif /* __BROM_USBDL_V2__ */
#endif /* __USB_DOWNLOAD__ || __UART_DOWNLOAD__ */
void CheckForOpenedUSBDLConn(void)
{
#if defined(__USBDL_IN_BOOTROM__)
#if !defined(__USB_DOWNLOAD__) || defined(__BROM_USBDL_V2__)
//It is not normal since Tool needs Bootloader to do Secure USBDL, which is, however, not enabled or correct
if (IsUSBEstablishedInBootROM() && !IsFactoryModeToMAUI())
{
BL_PRINT(LOG_ERROR, "BROM requested doing DL, beyond capbility\n\r");
#if defined(__BROM_USBDL_V2__)
ClearUSBDLFlag();
#endif
SetWDTNormalResetFlag();
WatchDogResetAll();
}
#endif
#endif
}
/**********************************************************
Description : Major Procedure for Factory Purpose
Input : None
Output : None
***********************************************************/
void FactoryProcedure(void)
{
TS_BEGIN(TSID_BL_FACTORY_PROCEDURE);
InitFPU();
if(metakey_position != NO_META_KEY && BL_kbd_IsKeyPressed(metakey_position))
{
BL_PRINT(LOG_INFO, "Fast META triggered\n\r");
SetBootupFlag(BL_FAST_META_TRIGGERED);
TriggerMetaMode();
return;
}
CheckForOpenedUSBDLConn();
#if defined(__USB_DOWNLOAD__) || defined(__UART_DOWNLOAD__)
if (!g_usbdlDisabled)
{
#if __MTK_INTERNAL__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MTK_INTERNAL__ */
#if defined(__BROM_USBDL_V2__)
if(!IsFactoryModeToMAUI())
{
USBDL_TRIGGER_REASON usbdlTriggered = USBDL_Detect();
#if __MTK_INTERNAL__
/* under construction !*/
#endif
if(usbdlTriggered != USBDL_NOT_TRIGGERED)
{
//If Bootloader supports S-USBDL, then only go to BROM when Rescue mode is detected
//Or always go to BROM dirtectly since BROM can provide all we need;
#if !defined(__SECURE_USB_DOWNLOAD__)
InitiateBromUSBDL(usbdlTriggered);
#else
if(usbdlTriggered == USBDL_RESCUE_KEY)
{
InitiateBromUSBDL(usbdlTriggered);
}
USBDL_Main();
#endif
}
else
{
ClearUSBDLFlag();
}
}
else
{
BL_PRINT(LOG_INFO, "META mode detected, go to MAUI directly\r\n");
}
//Wait for tools' ready
ClearUSBDLFlag();
#else
//BROM USBDL v1 or legacy BL USBDL part
USBDL_Main();
#endif
}
#endif // __USB_DOWNLOAD__|| __UART_DOWNLOAD__
TS_END(TSID_BL_FACTORY_PROCEDURE);
}
/**********************************************************
Description : Major Procedure for Card download
Input : None
Output : None
***********************************************************/
void CardDLProcedure(void)
{
#if defined(__CARD_DOWNLOAD__)
if( g_carddlDisabled )
{
return;
}
TS_BEGIN(TSID_BL_CARD_DOWNLOAD_PROCEDURE);
if( bl_IsCardDownloadGoing() )
{
g_enterCarddl = KAL_TRUE;
g_bootupDisabled = KAL_TRUE;
g_bootupStatus = BL_BOOTUP_FAIL_REASON_UPDATE_IN_PROGRESS;
}
if (g_enterCarddl || bl_CardDownloadTriggered() )
{
BL_CD_ERROR_CODE status;
WacthDogRestart();
status = bl_UpdateMain(g_bootupDisabled);
if(status == BL_CD_ERROR_NONE)
{
//Impossible to get here.
}
else if(status == BL_CD_ERROR_NO_CARD_FOUND || status == BL_CD_ERROR_NO_DL_PACKAGE_FOUND)
{
//Continue bootup
}
else
{
dbg_print("CDL error:%d\n\r", status);
while(1);
}
}
TS_END(TSID_BL_CARD_DOWNLOAD_PROCEDURE);
#endif // __CARD_DOWNLOAD__
}
kal_bool bl_FUNET_Triggered()
{
// full download
if(g_usbdlRetnValue & RETN_FUNET_FULL_DL_EN)
{
return KAL_TRUE;
}
// partial download (diff package)
else if(g_usbdlRetnValue & RETN_FUNET_PARTIAL_DL_EN)
{
return KAL_TRUE;
}
else
{
return KAL_FALSE;
}
}
kal_bool bl_FUNET_IsGoing()
{
#if defined(__FUNET_ENABLE__)
return bl_IsFUNETGoing();
#else
return KAL_FALSE;
#endif
}
void FUNETProcedure(void)
{
#if defined(__FUNET_ENABLE__) && defined(__SV5_ENABLED__)
if( bl_FUNET_IsGoing() ) {
g_enterFUNET = KAL_TRUE;
g_bootupDisabled = KAL_TRUE;
g_bootupStatus = BL_BOOTUP_FAIL_REASON_FUNET_IN_PROGRESS;
}
if(g_enterFUNET || bl_FUNET_Triggered())
{
BL_FUNET_ERROR_CODE status;
WacthDogRestart();
status = bl_UpdateMain(g_bootupDisabled);
if(status == BL_FUNET_ERROR_NONE)
{
//Impossible to get here.
}
else if(status == BL_FUNET_ERROR_NO_CARD_FOUND || status == BL_FUNET_ERROR_NO_DL_PACKAGE_FOUND)
{
//Continue bootup
}
else
{
dbg_print("FUNET error%d\n\r", status);
while(1);
}
}
#endif /* __FUNET_ENABLE__ && __SV5_ENABLED__ */
}
#pragma arm section code = "INTERNCODE"
/**********************************************************
Description : Post process before jumping
Input : None
Output : None
***********************************************************/
void PostProcess(void)
{
#if defined(MT6268T) || defined(MT6268H)
{
kal_uint32 delay;
*(volatile kal_uint32 *)0x80010060 = 3;
/* delay for a while to wait for EMI remapping takes effect */
for (delay = 0; delay < 5000; delay++) {
}
}
#else /* MT6268T || MT6268H */
#if defined(__USB_DOWNLOAD__) && defined(__BROM_USBDL_V2__)
BL_PRINT(LOG_INFO, "Out Retn = (%d,%d), %d\r\n", (*RETN_FLAG&RETN_USBDL_BY_FLAG_EN)?1:0, (*RETN_FLAG&RETN_USBDL_TYPE_MASK)?1:0, (*RETN_FLAG&RETN_USBDL_TRIGGERED_BY_BL)?1:0);
#endif
CheckUARTSendEnd();
#endif /* MT6268T || MT6268H */
}
/**********************************************************
Description : Procedures for boot and handover to next ROM
Input : None
Output : None
***********************************************************/
#ifdef __SV5_ENABLED__
kal_uint32 LoadAndVerifyNextBinary(kal_bool *pDoRemap)
{
kal_uint32 targetAddr = INVALID_START_ADDR;
#if defined(__FOTA_DM__)
#if defined(_NAND_FLASH_BOOTING_) || defined(__EMMC_BOOTING__)
/* NAND FOTA support */
targetAddr = LoadFotaOnNand();
#else
/* NOR FOTA support */
targetAddr = bl_loadFOTAImage();
*pDoRemap = KAL_TRUE; /* must be executed in internal RAM since remapping register is changed */
#endif /* _NAND_FLASH_BOOTING_ || __EMMC_BOOTING__ */
#else
/* Non-FOTA part */
targetAddr = LoadMauiBody();
#endif /* __FOTA_DM__ */
if(targetAddr != INVALID_START_ADDR)
{
targetAddr += ((GFH_FILE_INFO_v1*)(targetAddr))->m_jump_offset;
}
return targetAddr;
}
#else
kal_uint32 LoadAndVerifyNextBinary(kal_bool *pDoRemap)
{
kal_uint32 targetAddr = INVALID_START_ADDR;
#if defined(__FOTA_DM__)
#if defined(_NAND_FLASH_BOOTING_)
/* NAND FOTA support */
targetAddr = LoadFotaOnNand();
#else
/* NOR FOTA support */
targetAddr = bl_loadFOTAImage();
*pDoRemap = KAL_TRUE; /* must be executed in internal RAM since remapping register is changed */
#endif /* _NAND_FLASH_BOOTING_ */
#else
#ifdef _NAND_FLASH_BOOTING_
targetAddr = LoadPrimariMAUI();
#else
if(FACTORY_BIN_START_ADDR_NOR != 0xffffffff && IsMetaModeEnabled() )
{
targetAddr = FACTORY_BIN_START_ADDR_NOR & REMAPPING_MASK ;
BL_PRINT(LOG_INFO, "Launching FactoryBin in Combine mode...\r\n");
}
else
{
targetAddr = MAUI_START_ADDR_NOR & REMAPPING_MASK;
}
#ifdef __MTK_SECURE_PLATFORM__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MTK_SECURE_PLATFORM__ */
#endif /* _NAND_FLASH_BOOTING_ */
#endif /* __FOTA_DM__ */
return targetAddr;
}
#endif
void RemapCmd(void)
{
#ifdef EMI_REMAP_OFFSET_MIXED
*EMI_REMAP |= 3;
#else
*EMI_REMAP = 3;
#endif
}
#if defined(__DSP_BOOT_SEC__) || defined(__DSP_BOOT_ORG__)
void DmdspBootInit(void)
{
#ifdef MT6276
*(volatile unsigned long *)0x81160090 = 0;
*(volatile unsigned long *)0x811600A0 = 5;
#endif
#if defined(__DSP_BOOT_SEC__)
//Used to ungate DSP
dmdsp_ungate_dsp();
#elif defined(__DSP_BOOT_ORG__)
*(volatile unsigned long *)0xFF080000 |= 0xC;
#endif
}
#endif /* __DSP_BOOT_SEC__ || __DSP_BOOT_ORG__ */
void BootAndHandOver(void)
{
kal_uint32 targetAddr = INVALID_START_ADDR;
kal_bool doRemap = KAL_FALSE;
TS_BEGIN(TSID_BL_BOOT_AND_HANDOVER);
#if defined(_NAND_FLASH_BOOTING_) || defined(__EMMC_BOOTING__)
dbg_print("Start loading image...\n\r");
#endif
WacthDogRestart();
targetAddr = LoadAndVerifyNextBinary(&doRemap);
WacthDogRestart();
#if defined(__DSP_BOOT_SEC__) || defined(__DSP_BOOT_ORG__)
DmdspBootInit();
#endif /* __DSP_BOOT_SEC__ || __DSP_BOOT_ORG__ */
#if !defined(__BL_SLIM_SEG__) && !defined(__BRINGUP_SUPPORT__)
CacheDeinit();
#endif /* !__BL_SLIM_SEG__ && !__BRINGUP_SUPPORT__ */
ShutDownModule();
if(targetAddr != INVALID_START_ADDR)
{
TS_END(TSID_BL_BOOT_AND_HANDOVER);
TS_END(TSID_BL_EXT_BOOTLOADER);
TS_END(TSID_BL_TOTAL);
#ifdef __TIME_STAMP__
TS_SetTimeUnit(TS_TIME_MS);
TS_ConvertTimeUnit();
TS_DumpTimeStamps();
BL_PRINT(LOG_DEBUG, "Dump timestamp done\r\n");
#endif
dbg_print("\nBye bye bootloader, jump to=%x\n\r", targetAddr);
PostProcess();
if (doRemap == KAL_TRUE)
{
RemapCmd();
}
JumpCmd(targetAddr);
}
g_Bl_Secure_Test = 1;
}
#pragma arm section code
/**********************************************************
Description : Set up flags for init module
Input : None
Output : None
***********************************************************/
void SetBootupFlag(kal_uint32 flag)
{
extern BL_Info_Wrapper_st BL_Shared_info;
ASSERT(BL_Shared_info.m_bl_maui_share_data.m_bl_magic_head == BL_INFO_V1);
BL_Shared_info.m_bl_maui_share_data.m_bl_bootup_flag |= flag;
}
kal_uint32 InitBlSysInfo(void)
{
extern BL_Info_Wrapper_st BL_Shared_info;
extern kal_uint32* SST_GetToken(void);
memset(&BL_Shared_info.m_bl_maui_share_data, 0x00, sizeof(BL_Shared_info.m_bl_maui_share_data));
BL_Shared_info.m_bl_maui_share_data.m_bl_magic_head = BL_INFO_V1;
BL_Shared_info.m_bl_maui_share_data.m_bl_random_seed = g_randomSeed;
custom_get_bootloader_version(BL_Shared_info.m_bl_maui_share_data.m_bl_version_str, sizeof(BL_Shared_info.m_bl_maui_share_data.m_bl_version_str));
#ifndef __16_3_SEG__
memcpy(BL_Shared_info.m_bl_maui_share_data.m_bl_token, SST_GetToken(), sizeof(BL_Shared_info.m_bl_maui_share_data.m_bl_token));
#endif /* __16_3_SEG__ */
memcpy(&BL_Shared_info.m_bl_maui_share_data.m_emi_param, g_emi_param, sizeof(g_emi_param));
memcpy(&BL_Shared_info.m_bl_maui_share_data.m_me_identity, &g_pBROM_BL_Param->m_me_identity, sizeof(BL_Shared_info.m_bl_maui_share_data.m_me_identity));
SetBootupFlag(BL_BROM_RID_GOT);
#if 0
/* under construction !*/
#ifdef __SV5_ENABLED__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifndef MT6251
/* under construction !*/
#else
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
#endif /* __SV5_ENABLED__ */
#endif
return 0;
}
#ifdef __SV5_ENABLED__
void ChekcInfoFromBootROM(void)
{
if((g_pBROM_BL_Param->m_brom_flags & BL_PARAM_BL_ALL_PASS) == 0)
{
kal_uint32 i;
BL_LoadInfo *pLoadInfo = g_pBROM_BL_Param->m_bl_loadinfo;
for(i=0; i<MAX_BL_NUM; i++)
{
if(pLoadInfo[i].m_state == BL_NOT_EXIST)
{
continue;
}
BL_PRINT(LOG_INFO, "Bootloader[%d], state=%d, c1=%x, c2=%x\n\r", i, pLoadInfo[i].m_state, pLoadInfo[i].m_code_1, pLoadInfo[i].m_code_2);
}
BL_PRINT(LOG_ERROR, "Some bootloader is not loaded!\n\rDeadEnd!!");
while(1);
}
}
#endif /* __SV5_ENABLED__ */
void GetArgFromMini(void)
{
kal_uint32 it = 0;
kal_uint32 *p, type, size;
p = bl_Traverse_TLV_Record((kal_uint32)g_mini_ext_da_share_buf, &it, &type, &size);
while(p)
{
switch(type)
{
case MINI_EXT_SHARD_RANDOM_SEED:
g_randomSeed = *p;
break;
#ifdef __SV5_ENABLED__
case MINI_EXT_SHARD_BL_PARAM:
#if defined(__COPY_BROM_BL_PARAM_TO_EXTERNAL_RAM__)
memcpy(&g_BROM_BL_Param, p, sizeof(g_BROM_BL_Param));
#else
g_pBROM_BL_Param = (BL_Param_v4*)*p;
#endif /* __COPY_BROM_BL_PARAM_TO_EXTERNAL_RAM__ */
break;
#endif
case MINI_EXT_SHARE_BL_HEADER:
memcpy(&BLHeader, p, sizeof(BLHeader));
break;
case MINI_EXT_SHARE_BL_TOKEN:
SST_SetToken(p, size);
break;
#ifdef __SV5_ENABLED__
case MINI_EXT_SHARD_FEATURE_COMBINATION:
//BL_TODO
break;
#else
case MINI_EXT_SHARD_FEATURE_COMBINATION:
//BL_TODO
break;
#endif
#ifdef __TIME_STAMP__
case MINI_EXT_SHARE_BL_TIME_STAMP_RECORD:
{
kal_uint32 tsAddr, tsSize;
TS_GetContext(&tsAddr, &tsSize);
memcpy((void*)tsAddr, p, tsSize);
break;
}
#endif /* __TIME_STAMP__ */
case MINI_EXT_SHARE_EMI_PARAM:
memcpy(g_emi_param, p, sizeof(g_emi_param));
break;
#ifdef __EXT_BL_UPDATE__
case MINI_EXT_SHARE_EXT_BL_UPDATE_INFO:
memcpy(&g_extBlUpdateInfo, p, sizeof(g_extBlUpdateInfo));
break;
#endif /* __EXT_BL_UPDATE__ */
#ifdef __BROM_USBDL_V2__
case MINI_EXT_SHARE_USBDL_RETN:
g_usbdlRetnValue = *p;
break;
#endif /* __BROM_USBDL_V2__ */
}
p = bl_Traverse_TLV_Record((kal_uint32)g_mini_ext_da_share_buf, &it, &type, &size);
}
}
#ifdef __FAST_LOGO__
const kal_uint8 *GetBootLogoPicture(void)
{
return g_fast_logo_img;
}
#endif /* __FAST_LOGO__ */
void ShowLogo(void)
{
#ifdef __FAST_LOGO__
//Show the first screen
const kal_uint8 *pLogoPic = GetBootLogoPicture();
TS_BEGIN(TSID_BL_DISPLAY_LOGO);
BL_PRINT(LOG_INFO, "Displaying logo...\r\n");
BL_LCDHWInit();
#if defined(GUI_BOOTUP_LOGO_X) && defined(GUI_BOOTUP_LOGO_Y)
BL_ShowUpdateFirmwareInitBackgroundByImage((U8*)pLogoPic, GUI_BOOTUP_LOGO_X, GUI_BOOTUP_LOGO_Y, KAL_FALSE);
#else
BL_ShowUpdateFirmwareInitBackgroundByImage((U8*)pLogoPic, 0, 0, KAL_TRUE);
#endif
BL_LCDSetBackLight();
SetBootupFlag(BL_FAST_LOGO_DISPLAYED);
TS_END(TSID_BL_DISPLAY_LOGO);
#endif /* __FAST_LOGO__ */
}
kal_bool LatchPowerInBL(void)
{
kal_bool toLatchPower = KAL_FALSE;
extern kal_bool custom_NeedToLatchPower(void);
TS_BEGIN(TSID_BL_PREPARE_LATCH_POWER);
#ifdef __TC01__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
#ifdef __FAST_LOGO__
DclPW_Initialize();
BL_Shared_info.m_bl_maui_share_data.m_poweron_param = PW_PowerDetect();
if(BL_Shared_info.m_bl_maui_share_data.m_poweron_param != 0)
{
toLatchPower = KAL_TRUE;
}
#endif
TS_END(TSID_BL_PREPARE_LATCH_POWER);
if(toLatchPower)
{
kal_bool firstBootup;
DCL_HANDLE rtc_handler;
RTC_CTRL_BOOTLOADER_POWERON_T rtc_cmd_data12;
TS_BEGIN(TSID_BL_LATCH_POWER);
rtc_handler = DclRTC_Open(DCL_RTC,FLAGS_NONE);
DclRTC_Control(rtc_handler, RTC_CMD_BOOTLOADER_POWERON, (DCL_CTRL_DATA_T *)&rtc_cmd_data12);
firstBootup = (kal_bool)rtc_cmd_data12.fgBootloaderPowerOn;
DclRTC_Close(rtc_handler);
SetBootupFlag(BL_INFO_POWER_LATCHED);
if(firstBootup)
{
SetBootupFlag(BL_INFO_FIRST_POWER_ON);
}
TS_END(TSID_BL_LATCH_POWER);
}
return toLatchPower;
}
/**********************************************************
Description : Main body of Ext Bootloader
Input : None
Output : None
***********************************************************/
void ExtBootloader(void)
{
#ifdef __DRV_EXT_CHARGER_DETECTION__
extern void MU_BootUp_Init(void);
#endif /* __DRV_EXT_CHARGER_DETECTION__ */
GetArgFromMini();
TS_Init(KAL_FALSE);
set_debug_level(bootloader_debug_level);
TS_BEGIN(TSID_BL_EXT_BOOTLOADER);
TS_BEGIN(TSID_BL_PRINT_WELCOME);
dbg_print("\n\n\n\r~~~ Welcome to MTK Bootloader %s (since 2005) ~~~\n\r", BootLDVerno);
dbg_print("**===================================================**\n\n\r");
#ifdef __MTK_INTERNAL__
/* under construction !*/
#if defined(_NAND_FLASH_BOOTING_)
/* under construction !*/
#elif defined(__EMMC_BOOTING__)
/* under construction !*/
#endif
/* under construction !*/
#endif
#if defined(__EXT_BL_UPDATE__)
BL_PRINT(LOG_DEBUG, "Active BL = %d\r\n", g_extBlUpdateInfo.m_current_bl);
#endif
TS_END(TSID_BL_PRINT_WELCOME);
#ifdef __DRV_EXT_CHARGER_DETECTION__
MU_BootUp_Init();
#endif /* __DRV_EXT_CHARGER_DETECTION__ */
InitExt();
#if defined(__SERIAL_FLASH_STT_EN__)
stt_main();
#endif
#if defined(__SNAND_STT_EN__)
stt_snand_main();
#endif
InitBlSysInfo();
#ifdef __SV5_ENABLED__
/* There is only one bootloader on 50/60, no need to check them */
#if!defined(MT6250) && !defined(MT6260) && !defined(MT6261)
ChekcInfoFromBootROM();
#endif
if(g_bromCmdModeDisabled)
{
SetBootupFlag(BL_BROM_CMD_MODE_DISABLED);
}
#if defined(_NAND_FLASH_BOOTING_) || defined(__EMMC_BOOTING__)
//Temp solution for non-final tool. This part should be replaced by CBR
BL_DEBUG_PRINT("Find and load image list block...\n\r");
if ( LoadImageListblock(GetMainRegionStartBlock()) == KAL_FALSE )
{
BL_PRINT(LOG_ERROR, "Invalid ILB config\n\r");
return;
}
#endif /* _NAND_FLASH_BOOTING_ */
//Find (and load) MAUI's GFH
if(!g_bootupDisabled)
{
LoadMAUIFirstPart();
}
#else
#ifdef _NAND_FLASH_BOOTING_
BL_DEBUG_PRINT("Find and load image list block...\n\r");
if ( LoadImageListblock(GetMainRegionStartBlock()) == KAL_FALSE )
{
dbg_print("Invalid ILB config\n\r");
return;
}
#endif /* _NAND_FLASH_BOOTING_ */
#endif /* __SV5_ENABLED__ */
WacthDogRestart();
GetFeatureCombination();
if ( CheckPairedVersion() == KAL_FALSE )
{
g_bootupDisabled = KAL_TRUE;
g_bootupStatus = BL_BOOTUP_FAIL_PAIRED_VER_MISMATCHED;
}
if ( CheckFeatureCombination() == KAL_FALSE )
{
g_bootupDisabled = KAL_TRUE;
g_bootupStatus = BL_BOOTUP_FAIL_UNSUPPORTED_MAUI_FEAUTRE;
}
#if !defined(__BL_SLIM_SEG__) && !defined(__BRINGUP_SUPPORT__)
FactoryProcedure();
if(!IsInWithOutBatteryMode())
BL_Disable_Usbdl_Wo_Battery();
CardDLProcedure();
#if defined(__EXT_BL_UPDATE__)
if(g_bootupDisabled == KAL_FALSE && g_extBlUpdateInfo.m_current_bl != E_EXTBL_PRIMARY_REGION)
{
g_bootupDisabled = KAL_TRUE;
g_bootupStatus = BL_BOOTUP_FAIL_BACKUP_BL_EXECUTING;
}
#endif /* __EXT_BL_UPDATE__ */
#endif /* !__BL_SLIM_SEG__ && !__BRINGUP_SUPPORT__ */
FUNETProcedure();
if(!IsInWithOutBatteryMode())
BL_Disable_Usbdl_Wo_Battery();
if( !g_bootupDisabled )
{
kal_bool powerLatched = KAL_FALSE;
TS_BEGIN(TSID_BL_PREPARE_BOOTUP);
TS_END(TSID_BL_PREPARE_BOOTUP);
#if !defined(__BL_SLIM_SEG__) && !defined(__BRINGUP_SUPPORT__)
powerLatched = LatchPowerInBL();
CacheInit();
if(powerLatched)
{
ShowLogo();
}
#endif /* !__BL_SLIM_SEG__ && !__BRINGUP_SUPPORT__ */
#if defined(__UBL__) && defined(__NOR_FULL_DRIVER__)
BL_ScanSerialFlashBlocks();
#endif
BootAndHandOver();
}
dbg_print("Bootloader dead end(%d,%d)\n\r", g_bootupDisabled, g_bootupStatus);
}
/**********************************************************
Description : Get the memory regions that are used by bootloader
Input : A buffer and lenght of it
Output : The information about bootloader region
***********************************************************/
kal_uint32 GetBootloaderRegion(BL_MEM_REGION_INFO **pResultArr)
{
#define GET_REGION_INFO(R, T) { \
extern kal_uint32 Image$$##R##$$Base; \
extern kal_uint32 Image$$##R##$$Length; \
extern kal_uint32 Image$$##R##$$ZI$$Length; \
if ( (kal_uint32)(&Image$$##R##$$Length) != 0 || (kal_uint32)(&Image$$##R##$$ZI$$Length) != 0 ) \
{ \
pInfo[count].addr = (kal_uint32)(&Image$$##R##$$Base); \
pInfo[count].len = (kal_uint32)(&Image$$##R##$$Length) + (kal_uint32)(&Image$$##R##$$ZI$$Length); \
pInfo[count].type = T; \
count++; \
} \
}
static kal_uint32 count = 0;
static BL_MEM_REGION_INFO regionInfo[9];
BL_MEM_REGION_INFO *pInfo = ®ionInfo[0];
if(count == 0)
{
//These code should be modified corresponding to scatter file
#ifdef __N_PLUS_0_PROJECT__
GET_REGION_INFO(DA_SHARE, BL_EXCLUSIVE_TO_DA)
#else
GET_REGION_INFO(EXT_READ_ONLY, BL_EXCLUSIVE_TO_DA)
GET_REGION_INFO(EXT_READ_ONLY_HEAD, BL_EXCLUSIVE_TO_DA)
GET_REGION_INFO(EXT_READ_ONLY_TAIL, BL_EXCLUSIVE_TO_DA)
GET_REGION_INFO(EXT_READ_WRITE, BL_EXCLUSIVE_TO_DA)
#endif
GET_REGION_INFO(EXT_READ_ONLY_INT, BL_FREE_DURING_EXECUTION)
GET_REGION_INFO(EXT_READ_WRITE_INT, BL_FREE_DURING_EXECUTION)
GET_REGION_INFO(STACK_AREA, BL_FREE_DURING_EXECUTION)
GET_REGION_INFO(EXT_UN_INIT, BL_FREE_DURING_EXECUTION)
//SHARE_BUF is not protected due to DA's behavior
//GET_REGION_INFO(SHARE_BUF, BL_FREE_DURING_EXECUTION)
ASSERT(count < sizeof(regionInfo)/sizeof(regionInfo[0]));
}
if(pResultArr)
{
*pResultArr = pInfo;
}
return count;
}
/**********************************************************
Description : Facility for wrapping USB and UART driver
Input :
Output :
***********************************************************/
#if defined(__USB_DOWNLOAD__) || defined(__UART_DOWNLOAD__)
kal_uint8 BL_GetUARTByte(void)
{
#ifdef __UART_DOWNLOAD__
return GetUARTByte();
#else
return USBDL_GetUARTByte();
#endif
}
void BL_PutUARTByte(kal_uint8 data)
{
#ifdef __UART_DOWNLOAD__
PutUARTByte(data);
#else
USBDL_PutUARTByte(data);
#endif
}
void BL_PutUARTByte_Complete(void)
{
#ifdef __UART_DOWNLOAD__
PutUARTByte_Complete();
#else
USBDL_PutUARTByte_Complete();
#endif
}
void BL_CheckUARTSendEnd(void)
{
#ifdef __UART_DOWNLOAD__
CheckUARTSendEnd();
#else
USBDL_CheckUARTSendEnd();
#endif
}
#endif /* defined(__USB_DOWNLOAD__) || defined(__UART_DOWNLOAD__) */
/**********************************************************
Description : Facility for BL-DA shared data, initialize structure
Input :
Output :
***********************************************************/
kal_bool bl_Init_BL_DA_SharedData(void)
{
return bl_Init_TLV_Service((kal_uint32)g_mini_ext_da_share_buf, sizeof(g_mini_ext_da_share_buf), BL_DA_SHARED_DATA_ID);
}
/**********************************************************
Description : Facility for BL-DA shared data, allocate a new space
Input : id of the requested record, and size of it
Output : the pointer to the buffer for record
***********************************************************/
kal_uint32* bl_Allocate_BL_DA_SharedData(kal_uint32 type, kal_uint32 size)
{
return bl_Allocate_TLV_Record((kal_uint32)g_mini_ext_da_share_buf, type, size);
}
#endif /* __EXT_BOOTLOADER__ */