ckScatter.pl
39.7 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
#!/usr/bin/perl
#
# 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) 2006
#
# 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:
#* ---------
#* ckScatter.pl
#*
#* Project:
#* --------
#*
#*
#* Description:
#* ------------
#* This script parse scatter file and embedded checking rules for it
#* 1. Load View --- NOR Flash
#* 2. Execution View --- RAM Device
#* 3. DSP execution region
#*
#* Author:
#* -------
#* JI Huang (mtk01077)
#*
#****************************************************************************/
#****************************************************************************
# Included Modules
#****************************************************************************
use strict;
BEGIN { push @INC, '.\\tools\\' } # add additional library path
use sysgenUtility; #pm file name without case sensitivity
use FileInfoParser;
use tools::pack_dep_gen;
PrintDependModule();
#****************************************************************************
# Constants
#****************************************************************************
my $CKSCATTER_VERNO = " V0.52";
# v0.52 , Support checking unexpected dummy scatter
# v0.51 , Phase-out system_drive_on_nand feature option
# v0.50 , Support EWS via tools::pack_dep_gen
# v0.49 , Error message refinement
# v0.48 , skip ckscatter2 check when ALICE_SUPPORT is turned on
# v0.47 , No need to check the DSP size sould be 2^N and the alignment restriction of DSP base and DSP length
# v0.45 , skip smartphone by using sysgenUtility.pm
# v0.44 , skip smartphone if secure turns on
# v0.43 , Fix parsing makefile
# v0.42 , Remove $$ to support Perl v5.12.*
# v0.41 , Support 6255
# v0.40 , skip smartphone DSP checking in ckscatter phase 1
# v0.39 , Change custom_flash.c to custom_flash.h and skip smartphone in ckscatter phase 2
# v0.38 , Refine EMI_EXTSRAM_SIZE pattern-matching to adapt to flexible () and spaces
# v0.37 , Skip ckscatter2 check when dcm_compression is turned on because ckscatter cannot see compressed image and will misjudge
# v0.36 , Get EXTSRAM_SIZE from custom_EMI_release.h
# v0.35 , Support eMMC Booting
# v0.34 , Skip SECURE_RO_ME and SECURE_RO_S from load region boundary check because they will be downloaded to CBR region
# v0.33 , Skip DSP alignment check for MT6276 shrinking
# v0.32 , Skip ckscatter2 check when DUMMY_SCATTER_ENABLE is turned on because invalid memory range will be used in Scatter Gen
# v0.31 , To support eMMC Booting
# v0.30 , Skip ckscatter2 check when ZIMAGE_SUPPORT is turned on because ckscatter cannot see compressed image and will misjudge
# v0.29 , Remove MT6253D
# v0.28 , Rename MT6253E/MT6253L as MT6252H/MT6252
# v0.27 , Check whether RAM consumption has exceeded DUMMY_END
# v0.26 , Move EMI_EXTSRAM_SIZE to custom_EMI_release.h
# v0.25 , Resume RAM boundary checking for MT6253E/L
# v0.24 , To support MT6253E/L, move EXTSRAM_SIZE to custom_EMI_release.h
# v0.23 , To support MT6253DV
# v0.22 , To support MT6253E/L, remove RAM boundary check because EXTSRAM_SIZE was moved from custom_EMI.h to custom_EMI_release.h
# v0.21 , To support MT6251
# v0.20 , Fix sort hex issue
# v0.19 , Adapt to NOR_FLASH_DENSITY unit change (Mbit to byte)
# v0.18 , Adopt different FAT configuration in custom_MemoryDevice.h
# v0.17 , Fix block alignment check errors
# v0.16 , Add MT6268 and remove BT/MT check
# v0.15 , Add file name and fline number information and unify all auto-gen error messages
# v0.14 , NAND_FLASH_BOOTING makefile option is changed
# v0.13 , Modify RAM boundary calculation and bypass 6516 boundary check
# v0.12 , Modify ~flash_cfg_tmp.c parsing rules for flash_opt.h template change for FOTA
# v0.11 , Parse ~flash_cfg_tmp.c only in Phase2 and fix load region calculation issue
# v0.10 , Split ckscatter into two phases and arrange checks into each phase
# v0.09 , add 2nd phase ckscatter at post-build stage
# v0.08 , temporarily remove FAT and load region check due to lack of FAT information and add CODE_PATCH_CODE/DSP_TX/DSP_RX start address alignment check
# v0.07 , add FAT and load region overlap check
# v0.06 , add SECONDARY_EXTSRAM_DSP_TX
# v0.05 , update scatter parser
# v0.04 , initial version
#****************************************************************************
# Input Parameters and Global Variables
#****************************************************************************
my $phase = $ARGV[0];
my $stop_build = $ARGV[1];
my $SCATTERFILE = $ARGV[2];
my $LIS_TEMP = $ARGV[3];
my $FLASH_CFG_TMP = $ARGV[4];
my $themf = $ARGV[5];
my $BB_FOLDER = $ARGV[6];
my $CUSTOM_EMI_H = $ARGV[6] . '\\' . "custom_EMI.h";
my $CUSTOM_EMI_RELEASE_H = $ARGV[6] . '\\' . "custom_EMI_release.h";
my $CUSTOM_FLASH_H = $ARGV[6] . '\\' . "custom_flash.h";
my $DUMMY_SCATTER_ALLOW = $ARGV[7];
my %Scat_Content;
my %MAKEFILE_OPTIONS;
my %EMI_H_Value;
my %FLASH_C_Value;
my @FLASH_H_Value_BLK_LIST;
my %FLASH_INFO;
my %NORFLASH_INFO_BLOCKS_TABLE;
# load/exec regions obtained from scatter file
my %LoadView;
my %ExecView;
# load/exec regions obtained from temp lis file
my %LoadRegion;
my %ExecRegion;
#****************************************************************************
# 0 >>> parse input parameters and decide ckscatter phase
#****************************************************************************
print "phase=$phase, stop_build=$stop_build\n";
# 0.1 >>> parse Project Make File
if ($themf =~ /make\\\w+(BT)_\w+.mak/i or $themf =~ /make\\\w+(MT)_\w+.mak/i) {
$MAKEFILE_OPTIONS{'type'} = uc($1);
}
&sysUtil::sysgen_die("[1.4]$themf: NOT exist!", __FILE__, __LINE__) if (!-e $themf);
if(1!=&FileInfo::Parse_MAKEFILE($themf, \%MAKEFILE_OPTIONS))
{
&sysUtil::sysgen_die("[1.1]Parse MakeFile failed");
}
# 0.2 >>> parse key definition in CUSTOM_FLASH_H
open (FLASHC_HANDLE, "<$CUSTOM_FLASH_H") or &error_handler($stop_build, "[3.2]$CUSTOM_FLASH_H: file error!", __FILE__, __LINE__);
while (<FLASHC_HANDLE>)
{
if (/NOR_FLASH_DENSITY:\s*(\w*)/)
{
$FLASH_INFO{'NOR_FLASH_DENSITY'} = $1;
}
elsif (/^FLASH_REGIONINFO_VAR_MODIFIER\s+FlashBlockTBL\s+\S+/)
{
$FLASH_C_Value{'BlockTBLFlag'} ++;
}
elsif (defined $FLASH_C_Value{'BlockTBLFlag'})
{
$FLASH_C_Value{'BlockTBLTxt'} .= $_;
# debug purpose
# print $_;
if (/\{\s*(\S+)\s*,\s*(\S+)\s*\}/)
{
push @FLASH_H_Value_BLK_LIST, $_;
}
delete $FLASH_C_Value{'BlockTBLFlag'} if (/^\s+EndBlockInfo\s+/);
}
}
close (FLASHC_HANDLE);
#&dump_custom_flash_h_values();
# 0.3 >>> parse key definition in CUSTOM_EMI_RELEASE_H
open (EMIRELEASEH_HANDLE, "<$CUSTOM_EMI_RELEASE_H") or &error_handler("[3.2/2.0]$CUSTOM_EMI_RELEASE_H: file error!", __FILE__, __LINE__);
while (<EMIRELEASEH_HANDLE>) {
if (/^#define EMI_EXTSRAM_SIZE\s+\(\s*\(*\s*\(*\s*(\S+)\)*\s*<<\s*20\s*\)*\s*>>\s*3\s*\)/)
{
$EMI_H_Value{'EXTSRAM_SIZE'} = $1;
}
}
close (EMIRELEASEH_HANDLE);
#&dump_custom_emi_h_values();
# 0.4 >>> do check in each phase
if ($phase == 1)
{
&ckscatter_phase1();
}
elsif ($phase == 2)
{
&ckscatter_phase2();
}
else
{
&error_handler($stop_build, "[3.2]make\\Gsm2.mak: Unsupported ckscatter command!", __FILE__, __LINE__);
}
exit;
#****************************************************************************
# 1 >>> Phase 1
#****************************************************************************
sub ckscatter_phase1
{
print "Phase1!\n";
# 1.1 >>> open and read scatter file, keep the important content in memory
open (SCAT_HANDLE, "<$SCATTERFILE") or &error_handler($stop_build, "[3.2/2.0]$SCATTERFILE: file error!", __FILE__, __LINE__);
while (<SCAT_HANDLE>) {
if (/\(.+\)/) {next;}
if (/;/) {s/;.*//;}
if (/{/ or /}/ or /\S+/) { $Scat_Content{$.} = $_; }
}
close (SCAT_HANDLE);
#&dump_scatter_file_structure();
# 1.2 >>> Build the LOAD View List and Execution View List
&parse_scatter_file_structure();
#&dump_load_view();
#&dump_exec_view();
# 1.3 >>> Check the DSP_TX and DSP_RX execution region
if (($MAKEFILE_OPTIONS{'platform'} ne 'MT6276') and ($MAKEFILE_OPTIONS{'platform'} ne 'MT6575') and ($MAKEFILE_OPTIONS{'platform'} ne 'MT6573')) # MT6276 is skipped because these regions no longer obey the alignment rule for shrinking purpose
{
my $rule = 0;
foreach my $e ( grep { /EXTSRAM_DSP_[TR]X/ } keys %ExecView )
{
printf "DSP Checking: $e \n";
# 1 : No Overlay
if ( defined $ExecView{$e}->{'attr'} and $ExecView{$e}->{'attr'} eq "OVERLAY")
{
printf "$e violate rule , No OVERLAY\n";
$rule++;
}
# 2 : Size >= 4KB
if ( exists $ExecView{$e}->{'length'} and hex( $ExecView{$e}->{'length'} ) < 4 * 1024 )
{
my $length = $ExecView{$e}->{'length'};
printf "$e violate rule , the Length($length) too small\n";
$rule++;
}
elsif ( not exists $ExecView{$e}->{'length'} )
{
printf "$e violate rule , please define Length\n";
$rule++;
next;
}
# Size must be 4K align
my $sz = hex( $ExecView{$e}->{'length'} );
if ($sz % (4 * 1024))
{
printf "$e violate rule , size must be 4K align \n";
$rule++;
next;
}
# 3 : address need to be assigned
if ( defined $ExecView{$e}->{'begin'} and $ExecView{$e} =~ /\+/ )
{
printf "$e address needs to be assigned\n";
$rule++;
}
elsif ( not defined $ExecView{$e}->{'begin'} )
{
printf "$e address not calculated, script error , please contact MTK\n";
$rule++;
}
}
if ($rule > 0)
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: Scatter File DSP check rule fail! Please contact with Scatter File owner!", __FILE__, __LINE__);
}
}
# 1.4 >>> CODE_PATCH_CODE, DSP_TX, and DSP_RX start addresses need to be 4KB-aligned
{
if (exists $MAKEFILE_OPTIONS{'platform'} and (&config_query_arm9($MAKEFILE_OPTIONS{'platform'}) == 1))
{
foreach my $e ( keys %ExecView )
{
if (($e =~ /EXTSRAM_DSP_[TR]X/) || ($e eq 'CODE_PATCH_CODE'))
{
#printf("$e start address = %08X\n", $ExecView{$e}->{'addr'});
if (!defined $ExecView{$e}->{'begin'})
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: $e lack of start address! Please contact with Scatter File owner!", __FILE__, __LINE__);
}
if (hex($ExecView{$e}->{'addr'}) % (4*1024) != 0)
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: $e start address needs to be 4KB-aligned! Please contact with Scatter File owner!", __FILE__, __LINE__);
}
}
}
}
}
# 1.5 >>> BOOTLOADER, __HIDDEN_SECURE_RO, __HIDDEN_FLASHTOOL_CFG, __HIDDEN_CUST_PARA start addresses need to be block-aligned
if (1 != &sysUtil::is_SmartPhone($MAKEFILE_OPTIONS{'platform'})) # smartphone has no need to be block-aligned
{
&get_block_table();
my @offset = sort {$b <=> $a} keys %NORFLASH_INFO_BLOCKS_TABLE;
foreach ( keys %LoadView )
{
if (/BOODLOADER|__HIDDEN_SECURE_RO|__HIDDEN_FLASHTOOL_CFG|__HIDDEN_CUST_PARA/)
{
foreach my $i (@offset)
{
if (hex($LoadView{$_}->{'begin'}) >= $i)
{
if (hex($LoadView{$_}->{'begin'}) == $i)
{
last;
}
my $tmp = hex($LoadView{$_}->{'begin'}) - $i;
while ($tmp > 0)
{
$tmp -= $NORFLASH_INFO_BLOCKS_TABLE{$i};
}
if ($tmp != 0)
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: $_ start address needs to be block-aligned! Please contact with Scatter File owner!", __FILE__, __LINE__);
}
else
{
last;
}
}
}
}
}
}
}
#****************************************************************************
# 2 >>> Phase 2
#****************************************************************************
sub ckscatter_phase2
{
print "Phase2!\n";
# 2.10 >>> When DUMMY_SCATTER_ENABLE is turned on (only available on NOR booting), ckscatter should bypass
# >>> When unexpected dummy scatter is used, ckscatter fail
if (&FileInfo::is("dummy_scatter_enable", "TRUE") and $DUMMY_SCATTER_ALLOW == 1)
{
#if ((exists $MAKEFILE_OPTIONS{'nand_flash_booting'} and $MAKEFILE_OPTIONS{'nand_flash_booting'} eq 'NONE') and (!exists $MAKEFILE_OPTIONS{'emmc_booting'} or $MAKEFILE_OPTIONS{'emmc_booting'} eq 'NONE'))
if (&FileInfo::is("nand_flash_booting", "NONE") and (!exists $MAKEFILE_OPTIONS{'emmc_booting'} or $MAKEFILE_OPTIONS{'emmc_booting'} eq 'NONE'))
{
print "bypass check when DUMMY_SCATTER_ENABLE = TRUE!\n";
return;
}
}
else # DUMMY_SCATTER_ENABLE != TRUE or !InsideMTK
{
# To check if the input scatter is dummy scatter
if(&is_DummyScatter() == 1)
{
&error_handler($stop_build, "[1.5]Unexpected dummy scatter is used, please do command m sysgen to generate the correct scatter file!", __FILE__, __LINE__);
}
}
# 2.11 >>> 6516 series do not have FAT information and thus is bypassed in ckscatter_phase2
if (exists $MAKEFILE_OPTIONS{'platform'} and ($MAKEFILE_OPTIONS{'platform'} =~ /6516/ or $MAKEFILE_OPTIONS{'platform'} =~ /6573/ or $MAKEFILE_OPTIONS{'platform'} =~ /6575/))
{
print "bypass check on Smart Phone!\n";
return;
}
# 2.12 >>> BT/MT projects do not contain EXTSRAM and thus is bypassed in ckscatter_phase2
if (exists $MAKEFILE_OPTIONS{'type'} and ($MAKEFILE_OPTIONS{'type'} =~ /BT/ or $MAKEFILE_OPTIONS{'type'} =~ /MT/))
{
print "bypass check on BT/MT!\n";
return;
}
# 2.13 >>> When ZIMAGE_SUPPORT or DCM Compression is turned on, ckscatter will misjudge because it cannot recognize compressed case. Besides, another tool will be used to check ZIMAGE_SUPPORT/DCM Compression memory expiration
if (exists $MAKEFILE_OPTIONS{'zimage_support'} and ($MAKEFILE_OPTIONS{'zimage_support'} eq 'TRUE'))
{
print "bypass check when ZIMAGE_SUPPORT = TRUE!\n";
return;
}
if (exists $MAKEFILE_OPTIONS{'dcm_compression_support'} and ($MAKEFILE_OPTIONS{'dcm_compression_support'} eq 'TRUE'))
{
print "bypass check when dcm_compression_support = TRUE!\n";
return;
}
if (exists $MAKEFILE_OPTIONS{'alice_support'} and ($MAKEFILE_OPTIONS{'alice_support'} eq 'TRUE'))
{
print "bypass check when alice_support = TRUE!\n";
return;
}
# 2.2 >>> open and read temp lis file, keep the important content in memory
open (LIS_HANDLE, "<$LIS_TEMP") or &error_handler($stop_build, "[3.2/2.0]$LIS_TEMP: file error!", __FILE__, __LINE__);
my $LoadRegion_seq = 0;
my $ExecRegion_seq = 0;
while (<LIS_HANDLE>) {
if (/Load\s+Region\s+(\S+)\s+\(Base:\s+(\w+),\s+Size:\s+(\w+),\s+Max:\s+(\w+)/)
{
# print $_ , "\n";
$LoadRegion{$1}->{'Base'} = $2;
$LoadRegion{$1}->{'Size'} = $3;
$LoadRegion{$1}->{'Max'} = $4;
$LoadRegion{$1}->{'Seq'} = $LoadRegion_seq;
$LoadRegion_seq++;
}
elsif (/Execution\s+Region\s+(\S+)\s+\(Base:\s+(\w+),\s+Size:\s+(\w+),\s+Max:\s+(\w+)/)
{
# print $_ , "\n";
$ExecRegion{$1}->{'Base'} = $2;
$ExecRegion{$1}->{'Size'} = $3;
$ExecRegion{$1}->{'Max'} = $4;
$ExecRegion{$1}->{'Seq'} = $ExecRegion_seq;
$ExecRegion_seq++;
}
}
close (LIS_HANDLE);
&dump_temp_lis_structure();
&error_handler($stop_build, "[1.5]$LIS_TEMP: LIS file empty! Please resolve link errors first!", __FILE__, __LINE__) if (($LoadRegion_seq == 0) && ($ExecRegion_seq == 0));
# 2.3 >>> parse key definition in ~flash_cfg_tmp.c
open (FLASH_TMP_HANDLE, "<$FLASH_CFG_TMP") or &error_handler($stop_build, "[3.2]$FLASH_CFG_TMP: file error!", __FILE__, __LINE__);
while (<FLASH_TMP_HANDLE>) {
if (/int\s+flash_base_address\s*=\s*(.+);/s)
{
my $flash_base_address = `perl -e "printf ($1)" 2>&1`;
$FLASH_INFO{'FLASH_BASE_ADDRESS'} = sprintf("%X", $flash_base_address);
}
elsif (/int\s+allocated_fat_space\s*=\s*(.+);/s)
{
my $allocated_fat_space = `perl -e "printf ($1)" 2>&1`;
$FLASH_INFO{'ALLOCATED_FAT_SPACE'} = sprintf("%X", $allocated_fat_space);
}
}
close (FLASH_TMP_HANDLE);
#&dump_flash_cfg_tmp_values();
# 2.4 >>> check size limit validation
my $flash_size = &comp_flash_size();
my $load_length = &comp_load_length();
my ($ram_size, $ram_boundary, $ram_size_dummy_end, $ram_boundary_before_dummy_end);
if ($MAKEFILE_OPTIONS{'platform'} ne 'MT6251')
{
$ram_size = &comp_ram_size();
$ram_boundary = &comp_ram_boundary();
$ram_size_dummy_end = &comp_ram_size_dummy_end();
$ram_boundary_before_dummy_end = &comp_ram_boundary_before_dummy_end($ram_size_dummy_end);
}
#printf "%x, %x, %x, %x\n", $flash_size, $ram_size, $load_length, $ram_boundary;
if ((exists $MAKEFILE_OPTIONS{'nand_flash_booting'} and $MAKEFILE_OPTIONS{'nand_flash_booting'} ne 'NONE') or (exists $MAKEFILE_OPTIONS{'emmc_booting'} and $MAKEFILE_OPTIONS{'emmc_booting'} ne 'NONE'))
{
printf "LOAD VIEW , bypass check on NAND FLASH BOOTING\n";
printf "EXEC VIEW , Physical Device Density 0x%x , Scatter File Configuration 0x%x , Scatter File DUMMY_END 0x%x , Scatter File Usage 0x%x\n",
$ram_size , $ram_boundary, $ram_size_dummy_end, $ram_boundary_before_dummy_end;
if ($ram_size < $ram_boundary)
{
&error_handler($stop_build, "[1.1]$SCATTERFILE: RAM consumption has exceeded its upper bound! Please turn off some features or change to a larger MCP!", __FILE__, __LINE__);
}
if ($ram_size_dummy_end < $ram_boundary_before_dummy_end)
{
&error_handler($stop_build, "[1.1]$SCATTERFILE: RAM consumption has exceeded its upper bound! Please turn off some features or change to a larger MCP!", __FILE__, __LINE__);
}
if ($ram_size > $ram_boundary and ($ram_size - $ram_boundary) >= 1024 * 1024)
{
print "Warnning : RAM / Exec View configure waste at least 1MB\n";
}
}
else
{
printf "LOAD VIEW , Physical Device Density 0x%x , Scatter File Configuration 0x%x\t%s\n",
$flash_size, $load_length, ($flash_size >= $load_length)? "PASS" : "ERROR";
if ($flash_size < $load_length)
{
&error_handler($stop_build, "[1.1]$SCATTERFILE: ROM consumption has exceeded its upper bound! Please turn off some features or change to a larger MCP!", __FILE__, __LINE__);
}
if (($MAKEFILE_OPTIONS{'platform'} ne 'MT6251'))
{
printf "EXEC VIEW , Physical Device Density 0x%x , Scatter File Configuration 0x%x , Scatter File DUMMY_END 0x%x , Scatter File Usage 0x%x\n",
$ram_size , $ram_boundary, $ram_size_dummy_end, $ram_boundary_before_dummy_end;
if ($ram_size < $ram_boundary)
{
&error_handler($stop_build, "[1.1]$SCATTERFILE: RAM consumption has exceeded its upper bound! Please turn off some features or change to a larger MCP!", __FILE__, __LINE__);
}
if ($ram_size_dummy_end < $ram_boundary_before_dummy_end)
{
&error_handler($stop_build, "[1.1]$SCATTERFILE: RAM consumption has exceeded its upper bound! Please turn off some features or change to a larger MCP!", __FILE__, __LINE__);
}
}
if ($flash_size > $load_length and ($flash_size - $load_length) >= 1024 * 1024)
{
print "Warnning : NOR flash / Load View configure waste at least 1MB\n";
}
if ($MAKEFILE_OPTIONS{'platform'} ne 'MT6251')
{
if ($ram_size > $ram_boundary and ($ram_size - $ram_boundary) >= 1024 * 1024)
{
print "Warnning : RAM / Exec View configure waste at least 1MB\n";
}
}
}
}
#****************************************************************************
# subroutine: SCHEME Configure Routines :: Query :: ARM9 Family
# input: BB chip
# Output: whether this chip belongs to ARM9 Family
#****************************************************************************
sub config_query_arm9
{
my ($bb) = @_;
my %BBtbl_ARM9_Family =
(
'MT6235' => 1,
'MT6235B' => 1,
'MT6238' => 1,
'MT6239' => 1,
'MT6268' => 1,
);
return $BBtbl_ARM9_Family{$bb};
}
#****************************************************************************
# subroutine: comp_flash_size
# return: EMI value
#****************************************************************************
sub comp_flash_size
{
my $flash_limit;
if ((exists $MAKEFILE_OPTIONS{'nand_flash_booting'} and $MAKEFILE_OPTIONS{'nand_flash_booting'} ne 'NONE') or (exists $MAKEFILE_OPTIONS{'emmc_booting'} and $MAKEFILE_OPTIONS{'emmc_booting'} ne 'NONE'))
{
$flash_limit = 0;
}
else
{
$flash_limit = hex($FLASH_INFO{'FLASH_BASE_ADDRESS'});
}
return $flash_limit;
}
#****************************************************************************
# subroutine: comp_ram_size
# return: EMI value
#****************************************************************************
sub comp_ram_size
{
$EMI_H_Value{'EXTSRAM_SIZE'} =~ s/\(//;
$EMI_H_Value{'EXTSRAM_SIZE'} =~ s/\)//;
return $EMI_H_Value{'EXTSRAM_SIZE'} * 1024 * 1024 / 8;
}
#****************************************************************************
# subroutine: comp_ram_size_dummy_end
# return: RAM size before DUMMY_END or DSP_TXRX
#****************************************************************************
sub comp_ram_size_dummy_end
{
my $extsram_ram_size_before_dummy_end;
if (exists $ExecRegion{'CODE_PATCH_CODE'})
{
$extsram_ram_size_before_dummy_end = hex($ExecRegion{'CODE_PATCH_CODE'}->{'Base'});
}
elsif (exists $ExecRegion{'CACHED_CODE_PATCH_CODE'})
{
$extsram_ram_size_before_dummy_end = hex($ExecRegion{'CACHED_CODE_PATCH_CODE'}->{'Base'});
}
elsif (exists $ExecRegion{'DUMMY_END'})
{
$extsram_ram_size_before_dummy_end = hex($ExecRegion{'DUMMY_END'}->{'Base'});
}
elsif (exists $ExecRegion{'CACHED_DUMMY_END'})
{
$extsram_ram_size_before_dummy_end = hex($ExecRegion{'CACHED_DUMMY_END'}->{'Base'});
}
elsif (exists $ExecRegion{'EXTSRAM_DSP_TX'})
{
$extsram_ram_size_before_dummy_end = hex($ExecRegion{'EXTSRAM_DSP_TX'}->{'Base'});
}
elsif (exists $ExecRegion{'SECONDARY_EXTSRAM_DSP_TX'})
{
$extsram_ram_size_before_dummy_end = hex($ExecRegion{'SECONDARY_EXTSRAM_DSP_TX'}->{'Base'});
}
else
{
die "[2.0]Unknown Scatter File Structure";
}
printf "RAM DUMMY END , %x\n" , $extsram_ram_size_before_dummy_end;
return $extsram_ram_size_before_dummy_end;
}
#****************************************************************************
# subroutine: comp_load_length
# return: LoadView
#****************************************************************************
sub comp_load_length
{
my @region_list = sort { hex($LoadRegion{$b}->{'Base'}) <=> hex($LoadRegion{$a}->{'Base'}) } keys %LoadRegion;
my $last_load_region;
for (0..$#region_list)
{
if (($region_list[$_] ne 'SECURE_RO_ME') and ($region_list[$_] ne 'SECURE_RO_S'))
{
$last_load_region = $region_list[$_];
last;
}
}
return ((hex($LoadRegion{$last_load_region}->{'Base'})+hex($LoadRegion{$last_load_region}->{'Size'})) & (~0xF8000000));
}
#****************************************************************************
# subroutine: get_regions_reside_EXTSRAM
#****************************************************************************
sub get_regions_reside_EXTSRAM
{
my @regions = (sort { hex($ExecRegion{$a}->{'Base'}) <=> hex($ExecRegion{$b}->{'Base'}) } keys %ExecRegion);
my $EXTSRAM_Addr;
for (my $i=0; $i <= $#regions; $i++)
{
if ($regions[$i] =~ /EXTSRAM/) # find the start of EXTSRAM
{
$EXTSRAM_Addr = $ExecRegion{$regions[$i]}->{'Base'};
}
}
@regions = grep { (hex($ExecRegion{$_}->{'Base'}) & 0xF8000000) == (hex($EXTSRAM_Addr) & 0xF8000000) } keys %ExecRegion;
return @regions;
}
#****************************************************************************
# subroutine: comp_ram_boundary
# return: LoadView
#****************************************************************************
sub comp_ram_boundary
{
my @regions1 = sort { hex($ExecRegion{$a}->{'Base'}) <=> hex($ExecRegion{$b}->{'Base'}) } &get_regions_reside_EXTSRAM();
my $extsram_baseaddr = hex($ExecRegion{ $regions1[0] }->{ 'Base' });
#
my $extsram_limitaddr;
if (exists $ExecRegion{'DUMMY_END'})
{
$extsram_limitaddr = hex($ExecRegion{'DUMMY_END'}->{'Base'});
}
elsif (exists $ExecRegion{'EXTSRAM_DSP_RX'})
{
$extsram_limitaddr = hex($ExecRegion{'EXTSRAM_DSP_RX'}->{'Base'}) + hex($ExecRegion{'EXTSRAM_DSP_RX'}->{'Size'});
}
elsif (exists $ExecRegion{'SECONDARY_EXTSRAM_DSP_RX'})
{
$extsram_limitaddr = hex($ExecRegion{'SECONDARY_EXTSRAM_DSP_RX'}->{'Base'}) + hex($ExecRegion{'SECONDARY_EXTSRAM_DSP_RX'}->{'Size'});
}
elsif (exists $ExecRegion{'CODE_PATCH_CODE'})
{
$extsram_limitaddr = hex($ExecRegion{'CODE_PATCH_CODE'}->{'Base'}) + hex($ExecRegion{'CODE_PATCH_CODE'}->{'Size'});
}
elsif (exists $ExecRegion{'CACHED_DUMMY_END'})
{
$extsram_limitaddr = hex($ExecRegion{'CACHED_DUMMY_END'}->{'Base'}) & (~0xf0000000);
}
elsif (exists $ExecRegion{'EXTSRAM'} and exists $ExecRegion{'EXTSRAM'}->{'Size'})
{
$extsram_limitaddr = hex($ExecRegion{'EXTSRAM'}->{'Base'}) + hex($ExecRegion{'EXTSRAM'}->{'Size'});
}
elsif (exists $ExecRegion{'SECONDARY_EXTSRAM'} and exists $ExecRegion{'SECONDARY_EXTSRAM'}->{'Size'})
{
$extsram_limitaddr = hex($ExecRegion{'SECONDARY_EXTSRAM'}->{'Base'}) + hex($ExecRegion{'SECONDARY_EXTSRAM'}->{'Size'});
}
else
{
die "[2.0]Unknown Scatter File Structure";
}
#printf "RAM %x , %x\n" , $extsram_baseaddr , $extsram_limitaddr;
return ($extsram_limitaddr & (~0xf8000000));
}
#****************************************************************************
# subroutine: comp_ram_boundary_before_dummy_end
# return: RAM boundary before DUMMY_END
#****************************************************************************
sub comp_ram_boundary_before_dummy_end
{
my ($ram_dummy_end) = @_;
my @regions1 = sort { hex($ExecRegion{$b}->{'Seq'}) <=> hex($ExecRegion{$a}->{'Seq'}) } &get_regions_reside_EXTSRAM();
#
my $extsram_limitaddr;
my $dummy_end_reached = 0;
foreach my $region (@regions1)
{
if ($dummy_end_reached == 1)
{
$extsram_limitaddr = hex($ExecRegion{$region}->{'Base'}) + hex($ExecRegion{$region}->{'Size'});
last;
}
if (hex($ExecRegion{$region}->{'Base'}) == $ram_dummy_end)
{
$dummy_end_reached = 1;
}
}
printf "RAM Limit before DUMMY_END , %x\n" , $extsram_limitaddr;
return $extsram_limitaddr;
}
#****************************************************************************
# subroutine: get_block_table
# return: block table hash
#****************************************************************************
sub get_block_table
{
if ($#FLASH_H_Value_BLK_LIST >= 0)
{
my %blk_href;
foreach(@FLASH_H_Value_BLK_LIST)
{
if (/\{(0x\w+),\s*(0x\w+)\}/)
{
$NORFLASH_INFO_BLOCKS_TABLE{hex($1)} = hex($2);
}
}
}
}
#****************************************************************************
# subroutine: dump_exec_view
# return: all %LoadView ; key = RegionName , value = hash ref , begin , attr , length
#****************************************************************************
sub dump_exec_view
{
print "=== EXEC VIEW ===\n";
foreach my $region_name (sort { $ExecView{$a}->{'seq'} <=> $ExecView{$b}->{'seq'} } keys %ExecView)
{
print $region_name, "\t", $ExecView{$region_name}->{'begin'}, "\n";
}
}
#****************************************************************************
# subroutine: dump_load_view
# return: all %LoadView ; key = RegionName , value = hash ref , begin , attr , length
#****************************************************************************
sub dump_load_view
{
print "=== LOAD VIEW ===\n";
foreach my $region_name (sort { $LoadView{$a}->{'seq'} <=> $LoadView{$b}->{'seq'} } keys %LoadView)
{
print $region_name, "\t", $LoadView{$region_name}->{'begin'}, "\n";
}
}
#****************************************************************************
# subroutine: parse_region_string
# input: reference to %LoadView or %ExecView ; Region Name start address string
# return: %LoadView ; key = RegionName , value = hash ref , begin , attr , length
#****************************************************************************
my $sequence = 0;
sub parse_region_string
{
my ($hash_ref, $string) = @_;
my %tmp;
if ($string =~ m/(\S+)\s+(\S+)\s+OVERLAY\s+(\S+)/)
{
#print 'PATTERN1', "\t", $1, "\t", $2, "\t", 'OVERLAY', "\t", $3 , "\n";
$tmp{'seq'} = ++$sequence;
$tmp{'attr'} = "OVERLAY";
$tmp{'begin'} = $2;
$tmp{'length'} = $3;
$hash_ref->{$1} = \%tmp;
}
elsif ($string =~ m/(\S+)\s+(\S+)\s+ABSOLUTE\s+(\S+)/)
{
#print 'PATTERN1', "\t", $1, "\t", $2, "\t", 'ABSOLUTE', "\t", $3 , "\n";
$tmp{'seq'} = ++$sequence;
$tmp{'attr'} = "ABSOLUTE";
$tmp{'begin'} = $2;
$tmp{'length'} = $3;
$hash_ref->{$1} = \%tmp;
}
elsif ($string =~ m/(\S+)\s+(\S+)\s+FIXED\s+(\S+)/)
{
#print 'PATTERN1', "\t", $1, "\t", $2, "\t", 'FIXED', "\t", $3, "\n";
$tmp{'seq'} = ++$sequence;
$tmp{'attr'} = "FIXED";
$tmp{'begin'} = $2;
$tmp{'length'} = $3;
$hash_ref->{$1} = \%tmp;
}
elsif ($string =~ m/(\S+)\s+(\S+)\s+(\S+)/)
{
#print 'PATTERN3', "\t", $1, "\t", $2, "\t", $3, "\n";
$tmp{'seq'} = ++$sequence;
$tmp{'begin'} = $2;
$tmp{'length'} = $3;
$hash_ref->{$1} = \%tmp;
}
elsif ($string =~ m/(\S+)\s+(\S+)/)
{
#print 'PATTERN4', "\t", $1, "\t", $2, "\n";
$tmp{'seq'} = ++$sequence;
$tmp{'begin'} = $2;
$hash_ref->{$1} = \%tmp;
}
else
{
warn "UNKNOWN PATTERN : $string";
}
}
#****************************************************************************
# subroutine: parse_scatter_file_structure
# return: %LoadView , %ExecView
#****************************************************************************
sub parse_scatter_file_structure
{
my $last_line_no;
my $text_line;
my $view=0; #counter , 1 = load view , 2 = exec view
foreach my $file_line_no (sort {$a <=> $b} keys %Scat_Content)
{
$text_line = $Scat_Content{$file_line_no};
if ($text_line =~ m/{/)
{
if ($view > 1)
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: Unrecognizable view at $file_line_no! Please contact with Scatter File owner!", __FILE__, __LINE__);
}
$view++;
if (not defined $last_line_no)
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: No region name detected before $file_line_no!Please contact with Scatter File owner!", __FILE__, __LINE__);
}
&parse_region_string( ($view == 1) ? \%LoadView : \%ExecView , $Scat_Content{$last_line_no} );
}
elsif ($text_line =~ m/}/)
{
$view--;
if ($view < 0)
{
&error_handler($stop_build, "[2.0]$SCATTERFILE: Unrecognizable view at $file_line_no!Please contact with Scatter File owner!", __FILE__, __LINE__);
}
}
$last_line_no = $file_line_no;
}
}
#****************************************************************************
# subroutine: error_handler
# return: none
#****************************************************************************
sub error_handler
{
my ($todie, $error_msg, $file, $line_no) = @_;
# print $todie, "\n";
my $final_error_msg = "CKSCATTER ERROR: $error_msg at $file line $line_no\n";
print $final_error_msg;
die $final_error_msg if ($todie eq 'TRUE');
}
#****************************************************************************
# subroutine: dump_scatter_file_structure
# return: none
#****************************************************************************
sub dump_scatter_file_structure
{
foreach my $file_line_no (sort {$a <=> $b} keys %Scat_Content)
{
print $file_line_no, "\t", $Scat_Content{$file_line_no};
}
}
#****************************************************************************
# subroutine: dump_temp_lis_structure
# return: none
#****************************************************************************
sub dump_temp_lis_structure
{
print "Dumping temp lis structure: \n";
foreach my $lv (sort {hex($LoadRegion{$a}->{'Base'}) <=> hex($LoadRegion{$a}->{'Base'})} keys %LoadRegion)
{
print $lv, "\t", $LoadRegion{$lv}->{'Base'}, "\t", $LoadRegion{$lv}->{'Size'}, "\t", $LoadRegion{$lv}->{'Max'}, "\t", $LoadRegion{$lv}->{'Seq'}, "\n";
}
foreach my $ev (sort {hex($ExecRegion{$a}->{'Base'}) <=> hex($ExecRegion{$a}->{'Base'})} keys %ExecRegion)
{
print $ev, "\t", $ExecRegion{$ev}->{'Base'}, "\t", $ExecRegion{$ev}->{'Size'}, "\t", $ExecRegion{$ev}->{'Max'}, "\t", $ExecRegion{$ev}->{'Seq'}, "\n";
}
}
#****************************************************************************
# subroutine: dump_custom_emi_h_values
# return: none
#****************************************************************************
sub dump_custom_emi_h_values
{
foreach my $key (sort keys %EMI_H_Value)
{
print $key, "\t", $EMI_H_Value{$key} , "\n";
}
}
#****************************************************************************
# subroutine: dump_custom_flash_h_values
# return: none
#****************************************************************************
sub dump_custom_flash_h_values
{
foreach (@FLASH_H_Value_BLK_LIST)
{
print "$_\n";
}
}
#****************************************************************************
# subroutine: is_DummyScatter
# return: 0: is not dummy scatter
# 1: is dummy scatter
#****************************************************************************
sub is_DummyScatter
{
my $isDummyScatter = 0;
open (SCAT_HANDLE, "<$SCATTERFILE") or &error_handler($stop_build, "[3.2/2.0]$SCATTERFILE: file error!", __FILE__, __LINE__);
while (<SCAT_HANDLE>) {
if (/\(Dummy scatter\)/)
{
$isDummyScatter = 1;
last;
}
}
close (SCAT_HANDLE);
return $isDummyScatter;
}
#****************************************************************************
# subroutine: dump_flash_cfg_tmp_values
# return: none
#****************************************************************************
sub dump_flash_cfg_tmp_values
{
foreach my $key (sort keys %FLASH_INFO)
{
print $key, "\t", $FLASH_INFO{$key} , "\n";
}
}