-
Notifications
You must be signed in to change notification settings - Fork 12
/
dgmodul4.c
1418 lines (1312 loc) · 35.3 KB
/
dgmodul4.c
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
/*
* Copyright (c) 2015-2019, Renesas Electronics Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Renesas nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "common.h"
#include "dgtable.h"
#include "dgmodul4.h"
#include "rpcqspidrv.h"
#include "spiflash1drv.h"
#include "reg_rzg2.h"
#include "ramckmdl.h"
#include "dmaspi.h"
#include "devdrv.h"
#include "dgmodul1.h"
#include "boardid.h"
#if USB_ENABLE == 1
#include "usb_lib.h"
#endif /* USB_ENABLE == 1 */
uint32_t gSpiFlashSvArea;
uint32_t gUserPrgStartAdd;
uint32_t gUserPrgSize;
uint32_t gManufacturerId;
uint32_t gDeviceId;
uint32_t gQspi_sa_size;
uint32_t gQspi_end_addess;
extern uintptr_t gErrDdrAdd;
extern uint32_t gErrDdrData,gTrueDdrData;
extern uintptr_t gSubErrAdd;
extern uintptr_t gSubErrData;
extern uintptr_t gSubTrueData;
extern char gKeyBuf[64];
/****************************************************************
MODULE : dgG2LoadSpi *
FUNCTION : load Program to Spi memory *
COMMAND : XLS *
INPUT PARAMETER : XLS *
*****************************************************************/
void dgG2LoadSpiflash0(void)
{
char str[64];
uint32_t OnBoardSpiSysSize;
char buf[16],key[16],chCnt,chPtr;
uint32_t readManuId,readDevId;
uint32_t loop;
uint32_t wrData;
uintptr_t Load_workStartAdd,Load_workEndAdd;
uint32_t workAdd_Min,workAdd_Max;
uint32_t Read_workStartAdd;
uint32_t ClrSpiStartSecTopAdd,ClrSpiSecEndAdd;
uint32_t clearSize;
uint32_t MaskSectorSize;
uint32_t WriteDataStatAdd;
uint32_t PrgSpiStatAdd,PrgSpiEndAdd;
uint32_t saveSize;
uint32_t InfoPrgStatAdd;
uint32_t rdBufstatAdd;
uintptr_t prgStAdd,prgSize;
uint32_t WrittenSize;
uint32_t RemainingSize;
PutStr("===== Qspi writing of RZ/G2 Board Command ========",1);
PutStr("Load Program to Spiflash",1);
InitRPC_Mode();
if (CheckQspiFlashId())
{
return; //Error abortt
}
PutStr("------------------------------------------------------------",1);
PutStr("Please select,Qspi Save Area. ",1);
PutStr(" ",1);
PutStr("== Loader Program : Program to execute on SystemRAM ========",1);
PutStr(" 1 : A-Side SPI_Address = H' 004_0000-H' 007_FFFF ",1);
PutStr(" 2 : B-Side SPI_Address = H' 008_0000-H' 00B_FFFF ",1);
PutStr(" ",1);
PutStr("== User Program : Program to execute on DRAM or SystemRAM ==",1);
PutStr(" 3 : SPI_Address = H' 010_0000-H' 3FF_FFFF ",1);
PutStr("------------------------------------------------------------",1);
loop = 1;
while(loop)
{
PutStr(" Select area(1-3)>",0);
GetStr(str,&chCnt);
switch(str[0])
{
case '1': //LoaderProgram
gSpiFlashSvArea = 1;
Load_workStartAdd = LS_WORK_DRAM_SADD;
Load_workEndAdd = LS_WORK_DRAM_EADD_192K;
PrgSpiStatAdd = QSPI_SA01_STARTAD;
loop = 0;
break;
case '2': //LoaderProgram
gSpiFlashSvArea = 2;
Load_workStartAdd = LS_WORK_DRAM_SADD;
Load_workEndAdd = LS_WORK_DRAM_EADD_192K;
PrgSpiStatAdd = QSPI_SA02_STARTAD;
loop = 0;
break;
case '3': //UserProgram
gSpiFlashSvArea = 3;
Load_workStartAdd = LS_WORK_DRAM_SADD;
Load_workEndAdd = LS_WORK_DRAM_EADD_64M;
PrgSpiStatAdd = QSPI_SA04_STARTAD;
loop = 0;
break;
}
}
if (gSpiFlashSvArea == 1 || gSpiFlashSvArea ==2 )
{
gUserPrgStartAdd = SYSTEMRAM_IPL_SADD;
PutStr("-- Loader Program --------------------------",1);
}
else if (gSpiFlashSvArea == 3)
{
PutStr("-- User Program ----------------------------",1);
loop = 1;
while(loop)
{
PutStr("Please Input User Program Start Address : ",0);
GetStr(key,&chCnt);
chPtr = 0;
if (!GetStrBlk(key,buf,&chPtr,0))
{
if (chPtr == 1)
{
/* Case Return */
}
else if ((buf[0] == '.'))
{
/* Case End */
gUserPrgStartAdd = 0x40000000;
loop = 0;
}
else if (chPtr > (char)((SIZE_32BIT<<1)+1))
{
/* Case Data Size Over */
PutStr("Syntax Error",1);
}
else
{
if (HexAscii2Data((unsigned char*)buf,&wrData))
{
PutStr("Syntax Error",1);
}
else
{
if (wrData & 0x00000003)
{
PutStr("Memory Boundary Error",1);
}
else
{
gUserPrgStartAdd = wrData;
loop = 0;
}
}
}
}
else
{
PutStr("Syntax Error",1);
}
}
}
//=====================================================================================
// InfoPrgStatAdd = QSPI_SA03_STARTAD;
// InfoPrgSizeAdd = QSPI_SA03_STARTAD + 0x04;
//=====================================================================================
// WorkMemory CLEAR (Write H'FF)
if (gSpiFlashSvArea == 1 || gSpiFlashSvArea == 2)
{
//Loader Area
PutStr("Work RAM(H'50000000-H'5002FFFF) Clear....",1);
}
else if (gSpiFlashSvArea == 3)
{
PutStr("Work RAM(H'50000000-H'53FFFFFF) Clear....",1);
}
FillData32Bit((uint32_t *)Load_workStartAdd,(uint32_t *)Load_workEndAdd,0xFFFFFFFF);
if (dgLS_Load_Offset2(&workAdd_Max ,&workAdd_Min))
{
return;
}
PrgSpiStatAdd = PrgSpiStatAdd + (workAdd_Min - Load_workStartAdd);
PrgSpiEndAdd = PrgSpiStatAdd + (workAdd_Max - workAdd_Min);
saveSize = (PrgSpiEndAdd-PrgSpiStatAdd)+1;
MaskSectorSize = (~gQspi_sa_size) + 1;
WriteDataStatAdd = workAdd_Min;
ClrSpiStartSecTopAdd = PrgSpiStatAdd & MaskSectorSize;
ClrSpiSecEndAdd = PrgSpiEndAdd | ~(MaskSectorSize);
clearSize = (ClrSpiSecEndAdd-ClrSpiStartSecTopAdd)+1;
Read_workStartAdd = WORK_SPI_LOAD_AREA;
if (CkQspiFlash1ClearSectorSize(Read_workStartAdd,ClrSpiStartSecTopAdd,clearSize,1))
{
return;
}
// SAVE QSPI-FLASH
PutStr("SAVE SPI-FLASH.......",0);
SaveDataWithBuffeQspiFlash(WriteDataStatAdd, PrgSpiStatAdd, saveSize); //Manual Mode Single WriteBuffe
PutStr("-- Save (Program Start Address & Size ) -----",1);
if (gSpiFlashSvArea == 1)
{
//A-Side IPL
InfoPrgStatAdd = QSPI_SA00_STARTAD;
prgStAdd = Read_workStartAdd + SPIBOOT_A_IPL_ADD;
prgSize = Read_workStartAdd + SPIBOOT_A_IPL_SIZE;
}
else if (gSpiFlashSvArea == 2)
{
//B-Side IPL
InfoPrgStatAdd = QSPI_SA00_STARTAD;
prgStAdd = Read_workStartAdd + SPIBOOT_B_IPL_ADD;
prgSize = Read_workStartAdd + SPIBOOT_B_IPL_SIZE;
}
else if (gSpiFlashSvArea == 3)
{
//User Program Area
InfoPrgStatAdd = QSPI_SA03_STARTAD;
prgStAdd = Read_workStartAdd + SPIBOOT_UPRG_ST_AD;
prgSize = Read_workStartAdd + SPIBOOT_UPRG_SIZE;
}
rdBufstatAdd = Read_workStartAdd + InfoPrgStatAdd;
OnBoardSpiSysSize = 0x2000;
if ((gSpiFlashSvArea == 1) || (gSpiFlashSvArea == 2))
{
if (gQspi_end_addess <= TOTAL_SIZE_16MB)
{
FastRdQspiFlash(InfoPrgStatAdd, rdBufstatAdd, OnBoardSpiSysSize);
}
else
{
Fast4RdQspiFlash(InfoPrgStatAdd, rdBufstatAdd, OnBoardSpiSysSize);
}
PutStr("SPI Data Clear(H'FF):H'000000-03FFFF Erasing.", 0);
ParameterSectorEraseQspiFlash(InfoPrgStatAdd, ((OnBoardSpiSysSize) - 1));
}
else
{
SectorRdQspiFlash(InfoPrgStatAdd, rdBufstatAdd);
PutStr("SPI Data Clear(H'FF):H'0C0000-0FFFFF Erasing.", 0);
SectorEraseQspi_Flash(InfoPrgStatAdd, ((InfoPrgStatAdd + 0x8) -1));
}
*((uint32_t*)prgStAdd) = gUserPrgStartAdd;
saveSize = (saveSize|0x3)>>2;
*((uint32_t*)prgSize) = saveSize;
PutStr("SAVE SPI-FLASH.......",0);
if ((gSpiFlashSvArea == 1) || (gSpiFlashSvArea == 2))
{
SaveDataWithBuffeQspiFlash(rdBufstatAdd, InfoPrgStatAdd, OnBoardSpiSysSize); //Manual Mode Single WriteBuffe
}
else
{
SaveDataWithBuffeQspiFlash(rdBufstatAdd, InfoPrgStatAdd, gQspi_sa_size); //Manual Mode Single WriteBuffe
}
PutStr(" complete!",1);
PutStr("",1);
PutStr("========== Qspi Save Information =================",1);
PutStr(" Program Start Address : H'",0);
Data2HexAscii(gUserPrgStartAdd,str,4);
PutStr(str,1);
Data2HexAscii(saveSize,str,4);
PutStr(" Program Size (Byte/4) : H'",0);
PutStr(str,1);
PutStr("===============================================================",1);
PutStr("",1);
}
void InitRPC_Mode(void)
{
InitRPC_QspiFlash(RPC_CLK_40M);
// InitRPC_QspiFlash(RPC_CLK_80M);
}
uint32_t CheckQspiFlashId(void)
{
char str[64];
uint32_t readDevId, ret = 0;
uint8_t manuId;
uint16_t deviceId;
ReadQspiFlashID(&readDevId);
manuId = readDevId & 0x000000ff;
deviceId = (readDevId & 0x0000ff00) | ((readDevId >> 16) & 0xff);
gManufacturerId = manuId;
gDeviceId = deviceId;
switch(manuId)
{
case CYPRESS_MANUFACTURER_ID:
PutStr(" Cypress : ", 0);
switch(deviceId)
{
case DEVICE_ID_S25FS512S:
PutStr("S25FS512S", 1);
gQspi_sa_size = SA_256KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
case DEVICE_ID_S25FS128S:
PutStr("S25FS128S", 1);
gQspi_sa_size = SA_256KB;
gQspi_end_addess = TOTAL_SIZE_16MB - 0x8000 - 1;
break;
default:
ret = 1;
break;
}
break;
case WINBOND_MANUFACTURER_ID:
PutStr(" Winbond : ", 0);
switch(deviceId)
{
case DEVICE_ID_W25Q64JV:
PutStr("W25Q64JV", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_8MB - 0x8000 - 1;
break;
case DEVICE_ID_W25Q64JW:
PutStr("W25Q64JW", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_8MB - 0x8000 - 1;
break;
case DEVICE_ID_W25Q128JV:
PutStr("W25Q128JV", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_16MB - 0x8000 - 1;
break;
case DEVICE_ID_W25Q128JW:
PutStr("W25Q128JW", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_16MB - 0x8000 - 1;
break;
case DEVICE_ID_W25Q256:
PutStr("W25Q256", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_W25M512JV:
PutStr("W25M512JV", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_W25M512JW:
PutStr("W25M512JW", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_W25Q512JV:
PutStr("W25Q512JV", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
case DEVICE_ID_W25Q512JV_DTR:
PutStr("W25Q512JV-DTR", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
default:
ret = -1;
break;
}
break;
case MACRONIX_MANUFACTURER_ID:
PutStr(" Macronix : ", 0);
switch(deviceId)
{
case DEVICE_ID_MX25L12805:
PutStr("MX25L12805", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_16MB - 0x8000 - 1;
break;
case DEVICE_ID_MX25L25635F:
PutStr("MX25L25635F", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_MX25L51245G:
PutStr("MX25L51245G", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
case DEVICE_ID_MX66U25635F:
PutStr("MX66U25635F", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_MX66U51235F:
PutStr("MX66U51235F", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
default:
ret = -1;
break;
}
break;
case MICRON_MANUFACTURER_ID:
PutStr(" Micron : ", 0);
switch(deviceId)
{
case DEVICE_ID_MT25QL128:
PutStr("MT25QL128", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_16MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QU128:
PutStr("MT25QU128", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_16MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QL256:
PutStr("MT25QL256", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QU256:
PutStr("MT25QU256", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_32MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QL512:
PutStr("MT25QL512", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QU512:
PutStr("MT25QU512", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QL01G:
PutStr("MT25QL01G", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_128MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QU01G:
PutStr("MT25QU01G", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_128MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QL02G:
PutStr("MT25QL02G", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_256MB - 0x8000 - 1;
break;
case DEVICE_ID_MT25QU02G:
PutStr("MT25QU02G", 1);
gQspi_sa_size = SA_64KB;
gQspi_end_addess = TOTAL_SIZE_256MB - 0x8000 - 1;
break;
default:
ret = -1;
break;
}
break;
default:
ret = 1;
break;
}
if (ret)
{
Data2HexAscii(readDevId, str, 4);
PutStr(" FlashID = 0x", 0);
PutStr(str, 1);
}
return ret;
}
int32_t CkQspiFlash1ClearSectorSize(uint32_t rdBufAdd,uint32_t spiFlashStatAdd,uint32_t checkSize,uint32_t accessSize)
{
uint32_t flashStatus,flashEraseFlg;
char str1Buf[10],str2Buf[10];
char str[64];
PutStr("SPI Data Clear(H'FF) Check :",0);
if (gQspi_end_addess <= TOTAL_SIZE_16MB)
{
FastRdQspiFlash(spiFlashStatAdd, rdBufAdd,checkSize);
}
else
{
Fast4RdQspiFlash(spiFlashStatAdd, rdBufAdd,checkSize);
}
flashEraseFlg = 0;
if (CkSpiFlashAllF(rdBufAdd,checkSize))
{
PutStr("H'",0);
Data2HexAscii(spiFlashStatAdd,str1Buf,4);
PutStr(&str1Buf[0],0);
PutStr("-",0);
Data2HexAscii(((spiFlashStatAdd+checkSize)-1),str2Buf,4);
PutStr(&str2Buf[0],0);
PutStr(",Clear OK?(y/n)",0);
if (WaitKeyIn_YorN())
{
DelStr(34);
PutStr(" Exit ",1);
return(1);
}
DelStr(34);
flashEraseFlg = 1;
}
else
{
PutStr(" OK ",1);
}
if (flashEraseFlg)
{
// FLASH: erase
if (spiFlashStatAdd < 0x40000)
{
//Parameter Data Area Erase (H'0-H'7FFF)
PutStr("H'00000000-H'00007FFF",0);
PutStr(" Erasing.",1);
ParameterSectorEraseQspiFlash(0x0, 0x7FFF);
}
PutStr("H'",0);
PutStr(&str1Buf[0],0);
PutStr("-",0);
PutStr(&str2Buf[0],0);
PutStr(" Erasing.",0);
SectorEraseQspi_Flash(spiFlashStatAdd, ((spiFlashStatAdd + checkSize) - 1)); //SPI-FLASH-Address H'0000-H'FFFF
}
return(0);
}
void mem_copy(uint32_t prgStartAd, uint32_t sector_Ad, uint32_t accessSize)
{
uintptr_t readAdd, wrAdd;
uint32_t paddingOffset = 0;
uint32_t accessCount = 0;
paddingOffset = (accessSize + 0xFF ) & ~0xFF;
//accessCount = accessSize/64;
accessCount = paddingOffset >> 6;
//DMA Setting
InitDma01_Data(prgStartAd, sector_Ad, accessCount);
StartDma01();
WaitDma01();
DisableDma01();
ClearDmaCh01();
}
/****************************************************************
MODULE : dgG2LoadSpiflash0_3 *
FUNCTION : load Program to Spiflash memory *
COMMAND : XLS3 *
INPUT PARAMETER : XLS3 *
*****************************************************************/
void dgG2LoadSpiflash0_3(void)
{
XLoadSpiflash0_2(1U);
}
/************************************************************************
MODULE : dgG2LoadSpiflash0_2 *
FUNCTION : load Program to Spiflash memory *
COMMAND : XLS2 *
INPUT PARAMETER : XLS2 *
*************************************************************************/
void dgG2LoadSpiflash0_2(void)
{
XLoadSpiflash0_2(0U);
}
void XLoadSpiflash0_2(uint32_t mode)
{
char str[64];
uint32_t readManuId,readDevId;
uintptr_t Load_workStartAdd,Load_workEndAdd;
uint32_t workAdd_Min,workAdd_Max;
uint32_t Read_workStartAdd;
uint32_t ClrSpiStartSecTopAdd,ClrSpiSecEndAdd;
uint32_t clearSize;
uint32_t MaskSectorSize;
uint32_t WriteDataStatAdd;
uint32_t PrgSpiStatAdd,PrgSpiEndAdd;
uint32_t saveSize;
uint32_t WrittenSize;
uint32_t RemainingSize;
PutStr("===== Qspi writing of RZ/G2 Board Command =============",1);
PutStr("Load Program to Spiflash",1);
PutStr("Writes to any of SPI address.",1);
InitRPC_Mode();
if(CheckQspiFlashId())
{
return; //Error abortt
}
gUserPrgStartAdd = 0x0;
PutStr((mode == 0U ? "Program Top Address & Qspi Save Address " : "Program size & Qspi Save Address "),1);
gSpiFlashSvArea = 3;
Load_workStartAdd = LS_WORK_DRAM_SADD;
Load_workEndAdd = LS_WORK_DRAM_EADD_64M;
PrgSpiStatAdd = 0x0;
gUserPrgStartAdd = 0x0;
if (0U == mode)
{
PutStr("===== Please Input Program Top Address ============",1);
SetAddInputKey(&gUserPrgStartAdd);
}
else
{
PutStr("===== Please Input Program size ============",1);
SetSizeInputKey(&gUserPrgSize);
}
PutStr(" ",1);
PutStr("===== Please Input Qspi Save Address ===",1);
SetAddInputKey(&PrgSpiStatAdd);
if (gQspi_end_addess < PrgSpiStatAdd)
{
PutStr("Address Input Error", 1);
PutStr("Range of H'000_0000 ~ H'0FF_7FFF", 1);
return;
}
// WorkMemory CLEAR (Write H'FF)
PutStr("Work RAM(H'50000000-H'53FFFFFF) Clear....",1);
FillData32Bit((uint32_t *)Load_workStartAdd,(uint32_t *)Load_workEndAdd,0xFFFFFFFF);
if (0U == mode)
{
if (dgLS_Load_Offset2(&workAdd_Max, &workAdd_Min))
{
return;
}
}
else
{
char bin_data;
uint32_t image_offset = 0U;
PutStr("please send ! (binary)",1);
#if USB_ENABLE == 1
if (gTerminal == USB_TERMINAL)
{
image_offset = ((gUserPrgSize + (DMA_TRANSFER_SIZE-1)) & ~(DMA_TRANSFER_SIZE-1));
USB_ReadDataWithDMA((unsigned long)Load_workStartAdd, image_offset);
}
else
{
while (image_offset < gUserPrgSize)
{
GetChar(&bin_data);
*(uint8_t *)(Load_workStartAdd + image_offset) = bin_data;
image_offset++;
}
}
#else /* USB_ENABLE == 1 */
while (image_offset < gUserPrgSize)
{
GetChar(&bin_data);
*(uint8_t *)(Load_workStartAdd + image_offset) = bin_data;
image_offset++;
}
#endif /* USB_ENABLE == 1 */
workAdd_Min = Load_workStartAdd;
workAdd_Max = Load_workStartAdd + gUserPrgSize - 1;
}
PrgSpiStatAdd = PrgSpiStatAdd + (workAdd_Min - Load_workStartAdd);
PrgSpiEndAdd = PrgSpiStatAdd + (workAdd_Max - workAdd_Min);
saveSize = (PrgSpiEndAdd-PrgSpiStatAdd) + 1;
if (PrgSpiEndAdd > gQspi_end_addess)
{
PutStr("Program over size Error", 1);
PutStr(" SpiFlashMemory Stat Address : H'", 0);
Data2HexAscii(PrgSpiStatAdd, str, 4);
PutStr(str ,1);
PutStr(" SpiFlashMemory End Address : H'", 0);
Data2HexAscii(PrgSpiEndAdd,str, 4);
PutStr(str, 1);
return;
}
MaskSectorSize = (~gQspi_sa_size) + 1;
WriteDataStatAdd = workAdd_Min;
ClrSpiStartSecTopAdd = PrgSpiStatAdd & MaskSectorSize;
ClrSpiSecEndAdd = PrgSpiEndAdd | ~(MaskSectorSize);
clearSize = (ClrSpiSecEndAdd-ClrSpiStartSecTopAdd)+1;
Read_workStartAdd = WORK_SPI_LOAD_AREA;
if (CkQspiFlash1ClearSectorSize(Read_workStartAdd, ClrSpiStartSecTopAdd, clearSize,1))
{
return;
}
// SAVE QSPI-FLASH
PutStr("SAVE SPI-FLASH.......",0);
SaveDataWithBuffeQspiFlash(WriteDataStatAdd, PrgSpiStatAdd, saveSize); //Manual Mode Single WriteBuffe
PutStr("",1);
PutStr("======= Qspi Save Information =================",1);
PutStr(" SpiFlashMemory Stat Address : H'",0);
Data2HexAscii(PrgSpiStatAdd,str,4);
PutStr(str,1);
PutStr(" SpiFlashMemory End Address : H'",0);
Data2HexAscii(PrgSpiEndAdd,str,4);
PutStr(str,1);
PutStr("===========================================================",1);
PutStr("",1);
}
void SetData(uint32_t *setAdd)
{
char buf[16],key[16],chCnt,chPtr;
uint32_t loop;
uint32_t wrData;
loop = 1;
while(loop)
{
PutStr(" Set Data : ",0);
GetStr(key,&chCnt);
chPtr = 0;
if (!GetStrBlk(key,buf,&chPtr,0))
{
if (chPtr == 1)
{
/* Case Return */
}
else if (chPtr > (char)((SIZE_32BIT<<1)+1))
{
/* Case Data Size Over */
PutStr("Syntax Error",1);
}
else
{
if (HexAscii2Data((unsigned char*)buf,&wrData))
{
PutStr("Syntax Error",1);
}
else
{
*setAdd = wrData;
loop = 0;
}
}
}
else
{
PutStr("Syntax Error",1);
}
}
}
int32_t CkSpiFlashAllF(int32_t sAdd,int32_t cap)
{
uintptr_t ckAdd;
unsigned char rdData;
for (ckAdd = sAdd; ckAdd < (sAdd+cap); ckAdd++)
{
rdData = *((volatile unsigned char*)ckAdd);
if (rdData != 0xFF)
{
return(1);
}
}
return(0);
}
void SetAddInputKey(uint32_t *Address)
{
char str[64];
char buf[16],key[16],chCnt,chPtr;
uint32_t loop;
uint32_t wrData;
loop = 1;
while(loop)
{
PutStr(" Please Input : H'",0);
GetStr(key,&chCnt);
chPtr = 0;
if (!GetStrBlk(key,buf,&chPtr,0))
{
if (chPtr == 1)
{
/* Case Return */
}
else if((buf[0]=='.'))
{
/* Case End */
gUserPrgStartAdd = 0x40000000;
loop = 0;
}
else if (chPtr > (char)((SIZE_32BIT<<1)+1))
{
/* Case Data Size Over */
PutStr("Syntax Error",1);
}
else
{
if (HexAscii2Data((unsigned char*)buf,&wrData))
{
PutStr("Syntax Error",1);
}
else
{
if (wrData & 0x00000003)
{
PutStr("Memory Boundary Error",1);
}
else
{
*Address = wrData;
loop = 0;
}
}
}
}
else
{
PutStr("Syntax Error",1);
}
}
}
void SetSizeInputKey(uint32_t *size)
{
char str[64];
char buf[16],key[16],chCnt,chPtr;
uint32_t loop;
uint32_t wrData;
loop = 1;
while(loop)
{
PutStr(" Please Input : H'",0);
GetStr(key,&chCnt);
chPtr = 0;
if (!GetStrBlk(key,buf,&chPtr,0))
{
if (chPtr == 1)
{
/* Case Return */
} else if ((buf[0]=='.'))
{
/* Case End */
loop = 0;
}
else if (chPtr > (char)((SIZE_32BIT<<1)+1))
{
/* Case Data Size Over */
PutStr("Syntax Error",1);
}
else
{
if (HexAscii2Data((unsigned char*)buf,&wrData))
{
PutStr("Syntax Error",1);
}
else
{
*size = wrData;
loop = 0;
}
}
}
else
{
PutStr("Syntax Error",1);
}
}
}
/****************************************************************
MODULE : dgG2InfoSpiflash0_SA0 *
FUNCTION : read SA0 spi Spiflash memory *
COMMAND : XINFO_SA0 *
INPUT PARAMETER : XINFO_SA0 *
*****************************************************************/
void dgG2InfoSpiflash0_SA0(void)
{
char str[64];
uint32_t bootRomPara;
uint32_t prgStAdd,prgSize;
uint32_t prgStAdd_B,prgSize_B;
uint32_t readManuId,readDevId;
uint32_t spiFlashStatAdd,workTopAdd,rdBufstatAdd;
uintptr_t readAdd;
PutStr("=== SPI SA0 System Area Information ===",1);
InitRPC_Mode();
if (CheckQspiFlashId())
{
return; //Error abortt
}
//Setting SPI_Add, workRAM_Add
spiFlashStatAdd = QSPI_SA00_STARTAD;
workTopAdd = WORK_SPI_LOAD_AREA;
rdBufstatAdd = workTopAdd + spiFlashStatAdd;
SectorRdQspiFlash(spiFlashStatAdd, rdBufstatAdd);
readAdd = workTopAdd + SPIBOOT_BTROM_PARA; bootRomPara = *(uint32_t *)readAdd; //Read Boot ROM Parameters Address
readAdd = workTopAdd + SPIBOOT_A_IPL_ADD; prgStAdd = *(uint32_t *)readAdd; //Read Program Start Address
readAdd = workTopAdd + SPIBOOT_A_IPL_SIZE; prgSize = *(uint32_t *)readAdd; //Read Program Size
readAdd = workTopAdd + SPIBOOT_B_IPL_ADD; prgStAdd_B = *(uint32_t *)readAdd; //Read Program Start Address
readAdd = workTopAdd + SPIBOOT_B_IPL_SIZE; prgSize_B = *(uint32_t *)readAdd; //Read Program Size
Data2HexAscii(bootRomPara,str,4); PutStr(" Boot ROM Parameters : H'", 0); PutStr(str, 1);
Data2HexAscii(prgStAdd,str,4); PutStr(" A-side IPL Address (Loader Address) : H'", 0); PutStr(str, 1);
Data2HexAscii(prgSize,str,4); PutStr(" A-side IPL data size (Loader size) : H'", 0); PutStr(str, 1);
Data2HexAscii(prgStAdd_B,str,4); PutStr(" B-side IPL Address (Loader Address) : H'", 0); PutStr(str, 1);
Data2HexAscii(prgSize_B,str,4); PutStr(" B-side IPL data size (Loader size) : H'", 0); PutStr(str, 1);
PutStr("=========================================================", 1);
}
int32_t CheckDataChange(uintptr_t checkAdd)
{
uint32_t data;
uint32_t change;
char str[64];
char keyBuf[32],chCnt;
change = CHANGE_OFF;
data = *(uint32_t *)checkAdd;
Data2HexAscii(data,str,4); PutStr(str,1);
while(1)
{
PutStr(" Change ?(Y/N)",0);
GetStr(keyBuf,&chCnt);
if (chCnt ==1)
{
if ((keyBuf[0] == 'Y') || (keyBuf[0] == 'y'))
{
PutStr(" Please Input New Data ",1);
SetData(&data);
*((uint32_t*)checkAdd) = data;
change = CHANGE_ON;