blob: a362912e5514024e6ae1083b78c34b28f575445f [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/usr/bin/perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2006
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35#*****************************************************************************
36#*
37#* Filename:
38#* ---------
39#* sysGen2.pl
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This script parse scatter file and
48#* 1. force generate custom_scatstruct.h if update required
49#* 2. force generate custom_scatstruct.c if update required
50#* 3. force generate custom_blconfig.c if update required
51#*
52#* Author:
53#* -------
54#* Qmei Yang (mtk03726)
55#*
56#****************************************************************************/
57
58#****************************************************************************
59# Included Modules
60#****************************************************************************
61use strict;
62BEGIN { push @INC , './tools/' } # add additional library path
63use sysGenUtility; #pm file name without case sensitivity
64use scatInfo;
65use CommonUtility;
66use FileInfoParser;
67use config_MemSegment;
68use tools::pack_dep_gen;
69PrintDependModule();
70
71#****************************************************************************
72# Constants
73#****************************************************************************
74my $SYSGEN2_VERNO = " v0.02_VMOLY";
75 # v0.02_VMOLY, 2019/04/16, Yao, Modem mini dump implementation
76 # v0.01_VMOLY, 2018/08/22, Tero, Fixed region symbol generation
77 # u0.44_UMOLY, 2018/02/27, Tero, Added debug info to dump memory
78 # u0.43_UMOLY, 2017/07/25, Carl, Support overlapped ROM region
79 # u0.42_UMOLY, 2017/07/05, Tero, Code region dump support
80 # u0.41_UMOLY, 2017/06/08, Tero, IOCU dump support
81 # u0.40_UMOLY, 2017/03/22, Tero, Dynamic code load area dump support
82 # u0.39_UMOLY, 2016/09/25, Tero, Removed MMU info
83 # u0.38_UMOLY, 2016/09/06, Tero, Removed Core2 and volte sections from MMU info
84 # u0.37_UMOLY, 2016/08/01, Tero, Removed LR11 support
85 # u0.26_UMOLY, 2016/03/03, Tero, Fixed get_region_info_template length calculation
86 # u0.25_UMOLY, 2016/02/24, Tero, Refactored L2SRAM_L2NC and L2SRAM_L2C functions
87 # u0.24_UMOLY, 2016/02/23, Tero, Added MMU table info generation
88 # u0.23_UMOLY, 2016/02/17, Tero, Added support MMU table generation
89 # u0.22_UMOLY, 2016/02/16, Tero, Added support for dynamic code region info query
90 # u0.21_UMOLY, 2016/02/03, Tero, Added L2SRAM_L2NC base and length template functions
91 # u0.20_UMOLY, 2016/01/31, Tero, refined custom_scatgen.c template functions
92 # u0.19_UMOLY, 2016/01/13, Tero, Added core spesific cacheable data dump info support
93 # u0.18_UMOLY, 2016/01/11, Tero, Refine Dump Assing
94 # u0.17_UMOLY, 2016/01/08, Tero, Refine Dump Assing
95 # u0.16_UMOLY, 2015/07/15, Carl, Support runtime (not exception time) dump memory
96 # u0.15_UMOLY, 2015/06/26, Carl, Adjust custom_get_INTSRAMDATA_End for DSM
97 # u0.14_UMOLY 2015/05/11, Carl, Support Ramdisk for TK6291
98 # u0.13_UMOLY 2015/04/15, Carl, Refine setting for (MCU RO, MDHW RW) DNC+NC, (MCU RW, MDHW RW) DNC+NC
99 # u0.12_UMOLY, 2015/04/07, Carl, Use GetExeRegionsInROMByLoadRegion in custom_get_1st_ROM_ROMBase()
100 # u0.11_UMOLY, 2015/01/20, Carl, Remove bootloader and legacy security code from UMOLY
101 # u0.10_UMOLY, 2014/11/02, Carl, support custom_scatStruct.c to get L1CORE_LV info
102 # u0.09_UMOLY, 2014/10/20, Carl, call L1coreCommonUtil function
103 # u0.08_UMOLY, 2014/08/26, Carl, Refine L1core memory dump
104 # u0.07_UMOLY, 2014/07/31, Carl, Remove unused library path
105 # u0.06_UMOLY, 2014/06/27, Carl, Refine the base and end address of SWLA
106 # u0.05_UMOLY, 2014/04/07, Carl, Rename "l1dsp" to "l1core", "L1DSP" to "L1CORE"
107 # u0.04_UMOLY, 2014/04/02, Carl, pcore sysGen2
108 # u0.03_UMOLY, 2014/04/02, Carl, 1) pcore sysGen2. 2) Remove useless secure region query API
109 # u0.02_UMOLY, 2014/03/03, Carl, initial version, fix build fail
110 # u0.01_UMOLY, 2014/02/20, BM, porting to MT291_DEV
111
112#****************************************************************************
113# Global Variable
114#****************************************************************************
115my $g_bb;
116my $g_MAUILinkInfo = undef;
117my $g_BLLinkerInfo = undef;
118my %g_GroupedRegions; # Key => [content count, contents] #for saving time
119my $g_DumpRegions_href = undef; # Key => [[], [], []]
120my $g_DumpRegionOrder_aref = undef; # [GroupName, GroupName,...]
121my $DebugPrint = 0; # 1 for debug; 0 for non-debug
122my $official_config = "./interface/layout/L2CacheLockSection/official_config.ldf";
123my $local_config = "./interface/layout/L2CacheLockSection/local_config.ldf";
124my @section_array;
125my $local_test = 0;
126my $bin_path;
127my $gcc_command;
128my $infomake;
129my %CmplOption;
130my %RelOption;
131my $OptFile;
132
133# File Name
134my $CUSTOM_SCATSTRUCT_C;
135my $CUSTOM_SCATSTRUCT_H;
136my $CUSTOM_DEMP_H;
137my $CUSTOM_FEATURE_CFG_H;
138my $CUSTOM_MEM_DEV_H ;
139my $CUSTOM_IMG_CONFIG_H ;
140my $CUSTOM_FLASH_H;
141my $CUSTOM_EMI_OFFSET_H;
142my $SCATTERFILE;
143my $BL_SCATTERFILE;
144my $EXT_BL_SCATTERFILE;
145my $CUSTOM_DL2CMGR_C;
146my $CUSTOM_DL2CMGR_H;
147
1481;
149#****************************************************************************
150# Subroutine: GetOBJCOPYInput - API for objcopy input on Build Flow of GCC
151# Purpose: To provide command for objcopy
152# Input : $LDS_FILEPATH
153# Output : undef or a hash reference contains LoadRegionName => Corresponding command line
154# e.g. "ROM" => "-R BOOT_CERT -R SECURE_RO -R SECURE_RO_GFH "
155# "BOOT_CERT" => "-j BOOT_CERT "
156# "SECURE_RO" => "-j SECURE_RO -j SECURE_RO_GFH "
157# [!!!Caution!!!] if there is only one LoadRegion in RegionMap, it should return undef.
158#****************************************************************************
159sub GetOBJCOPYInput
160{
161 my ($LDS_FILEPATH) = @_;
162 my %OBJCopyInput;
163 my $LinkInfo = lds_new scatInfo($LDS_FILEPATH, "ROM");
164 my $RegionMap_href = $LinkInfo->GetRegionMap();
165 my $LRSize = scalar keys %$RegionMap_href;
166 if($LRSize > 1)
167 {
168 my $strROMER;
169 foreach my $strLRName (keys %$RegionMap_href)
170 {
171 my $LR = $RegionMap_href->{$strLRName};
172 if($strLRName !~ /rom/i)
173 {
174 map{ $strROMER .= "-R $_ ";}@$LR;
175 my $strER;
176 map {$strER .= "-j $_ ";}@$LR;
177 $OBJCopyInput{$strLRName} = $strER;
178 }
179 }
180 $OBJCopyInput{ROM} = $strROMER;
181#print "[OBJCopyInput]\n";
182#foreach my $item (keys %OBJCopyInput)
183#{
184# print "$item: ". $OBJCopyInput{$item}. "\n";
185#}
186 return \%OBJCopyInput;
187 }
188 else
189 {
190 return undef;
191 }
192}
193#****************************************************************************
194# subroutine: sysgen2_main
195# to be called by scatGen.pl
196# Input: 4 paths: $BB_PATH, $IMAGELAYOUT, $BL_IMAGELAYOUT, $EXT_BL_IMAGELAYOUT
197# Output: x
198#****************************************************************************
199sub sysgen2_main
200{
201 my ($BB_PATH, $IMAGELAYOUT, $BL_IMAGELAYOUT, $EXT_BL_IMAGELAYOUT, $GCC, $INFOMAKE) = @_;
202 #****************************************************************************
203 # >>> Setting
204 #****************************************************************************
205 $CUSTOM_SCATSTRUCT_C = $BB_PATH . '/' . "custom_scatstruct.c";
206 $CUSTOM_SCATSTRUCT_H = $BB_PATH . '/' . "custom_scatstruct.h";
207 $CUSTOM_DEMP_H = $BB_PATH . '/' . "custom_demp.h";
208 $CUSTOM_FEATURE_CFG_H = $BB_PATH . '/' . "custom_FeatureConfig.h";
209 $CUSTOM_MEM_DEV_H = $BB_PATH . '/' . "custom_MemoryDevice.h";
210 $CUSTOM_IMG_CONFIG_H = $BB_PATH . '/' . "custom_img_config.h";
211 $CUSTOM_FLASH_H = $BB_PATH . '/' . "custom_flash.h";
212 $CUSTOM_EMI_OFFSET_H = $BB_PATH . '/' . "custom_emi_offset.h";
213 $CUSTOM_DL2CMGR_C = $BB_PATH . '/' . "custom_dl2cmgr.c";
214 $CUSTOM_DL2CMGR_H = $BB_PATH . '/' . "custom_dl2cmgr.h";
215 $SCATTERFILE = $IMAGELAYOUT;
216 $BL_SCATTERFILE = $BL_IMAGELAYOUT;
217 $EXT_BL_SCATTERFILE = $EXT_BL_IMAGELAYOUT;
218 $bin_path = $BB_PATH;
219 $gcc_command = $GCC;
220 $infomake = $INFOMAKE;
221 $g_bb = &sysUtil::SwitchToClonedChip(&FileInfo::GetChip());
222 #****************************************************************************
223 # >>> Generate files
224 #****************************************************************************
225 &GCC_Process() if(&FileInfo::GetCompiler() eq "GCC");
226}
227
228#****************************************************************************
229# subroutine: GCC_Process
230# Input: x
231# Output: x
232#****************************************************************************
233sub GCC_Process
234{
235 # >>> Parse Scatter File
236 $g_MAUILinkInfo = lds_new scatInfo($SCATTERFILE, "ROM");
237 $g_MAUILinkInfo->ClassifyRegionType( &FileInfo::GetMakeFileRef() );
238 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
239
240 if(-e $EXT_BL_SCATTERFILE)
241 {
242 $g_BLLinkerInfo = lds_new scatInfo($EXT_BL_SCATTERFILE, "EXT_BOOTLOADER");
243 }
244 &Generate_Process();
245}
246
247sub Generate_Process
248{
249 # >>> Generate files
250 &GenerateFile($CUSTOM_SCATSTRUCT_C, \&SCAT_C_Preprocess);
251 &GenerateFile($CUSTOM_SCATSTRUCT_H, undef);
252 &GenerateFile($CUSTOM_IMG_CONFIG_H, undef);
253 &GenerateFile($CUSTOM_EMI_OFFSET_H, undef);
254 &GenerateFile($CUSTOM_DL2CMGR_H, \&Get_Config_Info);
255 &GenerateFile($CUSTOM_DL2CMGR_C, undef);
256}
257#****************************************************************************
258# subroutine: GenerateFile
259# Input: $strFilePath = the file to be generated if it exists without check-in history.
260# $PreprocessFunc_ref = to preprocess if there is any condition
261# which needs to be tested before generating
262# Output: x
263#****************************************************************************
264sub GenerateFile
265{
266 my ($strFilePath, $PreprocessFunc_ref) = @_;
267 if(&isToGen($strFilePath))
268 {
269 &$PreprocessFunc_ref() if(defined $PreprocessFunc_ref);
270 my $content = &ProcessTemplate($strFilePath);
271 &WriteFile($strFilePath, $content);
272 }
273}
274#****************************************************************************
275# subroutine: isToGen
276# Input: $strFilePath = the file to be generated if it exists without check-in history.
277# Output: $bToGen: undef = not to generate file, 1=need to generate file
278#****************************************************************************
279sub isToGen
280{
281 my ($strFilePath) = @_;
282 my $bToGen = undef;
283 if(-e $strFilePath)
284 {
285 $bToGen = 1 if(1 != &sysUtil::HasCheckinHistory($strFilePath));
286 }
287 else
288 {
289 &sysUtil::sysgen_die("$strFilePath: the template must exist!", __FILE__, __LINE__);
290 }
291 return $bToGen;
292}
293#****************************************************************************
294# subroutine: ProcessTemplate
295# Input: $strFilePath: the file to be processed
296# Output: $content: the content after processing
297# Description: if there is the pattern as [AUTOGEN_funcname],
298# the whole pattern will be replaced by calling funcname().
299# if funcname() doesn't exist, it'll fail and report error.
300#****************************************************************************
301sub ProcessTemplate
302{
303 my ($strFilePath) = @_;
304 my $content;
305 open (FILE_HANDLE, $strFilePath) or &sysUtil::sysgen_die("Cannot open $strFilePath\n", __FILE__, __LINE__);
306 while(<FILE_HANDLE>)
307 {
308 my $strLine = $_;
309 while ($strLine =~ /\[AUTOGEN_(\w+)\]/)
310 {
311 my $func = $1;
312 my $template;
313 {
314 no strict 'refs';
315 $template = &{$func}() if(exists &{$func})
316 or &sysUtil::sysgen_die("$func() doesn't exist!\n", __FILE__, __LINE__);
317 }
318 $strLine =~ s/\[AUTOGEN_$func\]/$template/g;
319 }
320 $content .= $strLine;
321 }
322 close FILE_HANDLE;
323 return $content;
324}
325#****************************************************************************
326# subroutine: WriteFile
327# Input: $strFilePath: the file to be generated
328# $content: the content to be written into $strFilePath
329# Output: x
330#****************************************************************************
331sub WriteFile
332{
333 my ($strFilePath, $content) = @_;
334 open (FILE, ">$strFilePath") or &sysUtil::sysgen_die("Cannot open $strFilePath\n", __FILE__, __LINE__);
335 print FILE $content;
336 close FILE;
337}
338#-----------------------------------------------------------------------------
339# Preprocess fucntions:
340#-----------------------------------------------------------------------------
341sub SCAT_C_Preprocess
342{
343 # Report error if there is another region ahead of SINGLE_BANK_CODE (between SINGLE_BANK_CODE and vector table)
344 # Because MPU channel will be wrapped from vector table (0x0) to the end of SINGLE_BANK_CODE to reduce the number of channels
345 my $strRegionName = $g_MAUILinkInfo->SearchExeRegionName("SINGLE_BANK_CODE");
346 if(defined $strRegionName)
347 {
348 my $array_ref = $g_MAUILinkInfo->GetExeRegionsByLoadRegion("ROM");
349 my $SINGLE_BANK_CODE_Base = $g_MAUILinkInfo->GetRegionInfo($strRegionName, Region::Base);
350 foreach (@$array_ref)
351 {
352 next if(/SINGLE_BANK_CODE/);
353 my $Info = $g_MAUILinkInfo->GetExeRegionInfo($_);
354 if(defined $Info->[Region::Base])
355 {
356 if ((hex($Info->[Region::Base])) <= (hex($SINGLE_BANK_CODE_Base))
357 and ((hex($Info->[Region::Base]) >= (0xFF000000 & hex($SINGLE_BANK_CODE_Base))) ))
358 {
359 &sysUtil::sysgen_die("$SCATTERFILE: No region($_) can exist between vector table and SINGLE_BANK_CODE for MPU configuration!", __FILE__, __LINE__);
360 }
361 }
362 }
363 }
364}
365#-----------------------------------------------------------------------------
366# Gen fucntions:
367#-----------------------------------------------------------------------------
368sub DieIfEmpty
369{
370 my ($Input, $strInputDescription) = @_;
371 my ($pack_name, $file, $line_no) = caller;
372 &sysUtil::sysgen_die("Please check $strInputDescription($Input) which can't be empty ", $file, $line_no)
373 if(!defined $Input or $Input eq "");
374}
375sub GenVersion
376{
377 return "system auto generator". $SYSGEN2_VERNO. " + sysGenUtility" . &sysUtil::sysgenUtility_verno();
378}
379
380sub DEMP_H_Gen_MBA_LIST
381{
382 my $template;
383 my $MBA_href = &GetGroupedRegions("MBA");
384 foreach(@$MBA_href)
385 {
386 my $temp = uc($_->[0]);
387 $temp =~ s/_ROM//;
388 $template .= " DEMP_$temp,\n";
389 }
390 return $template;
391}
392sub DEMP_H_Gen_DEMP_MAIN_BINSIZE
393{
394 my $nMaxSize = 0;
395 if($g_MAUILinkInfo->IsRegionExistent("DEMAND_PAGING_ROM0"))
396 {
397 my $Info = $g_MAUILinkInfo->GetLoadRegionInfo("DEMAND_PAGING_ROM0");
398 $nMaxSize = hex($Info->[Region::MaxSize])/ (1024*1024);
399 }
400 return $nMaxSize;
401}
402sub DEMP_H_Gen_MBA_BINSIZE_LIST
403{
404 my $template;
405 my $MBA_href = &GetGroupedRegions("MBA");
406 foreach(@$MBA_href)
407 {
408 my $temp = uc($_->[0]);
409 $temp =~ s/_ROM//;
410 my $Info = $g_MAUILinkInfo->GetLoadRegionInfo($_->[0]);
411 my $nMaxSize = hex($Info->[Region::MaxSize])/ (1024*1024);
412 $template .= "#define DEMP_$temp\_SIZE $nMaxSize\n";
413 }
414 return $template;
415}
416sub DEMP_H_Gen_DEMP_MBA_BINSIZE
417{
418 my $template;
419 my $MBA_href = &GetGroupedRegions("MBA");
420 foreach(@$MBA_href)
421 {
422 my $temp = uc($_->[0]);
423 $temp =~ s/_ROM//;
424 $template .= " + DEMP_$temp\_SIZE";
425 }
426 return $template;
427}
428
429
430sub SCAT_H_Gen_DUMP_REGION_COUNT
431{
432 my $nCount = 0;
433 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
434 {
435 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
436 }
437 foreach my $strGroupName (keys %$g_DumpRegions_href)
438 {
439 my $array_ref = $g_DumpRegions_href->{$strGroupName};
440 $nCount += ($#$array_ref +1);
441 }
442 return $nCount;
443}
444sub SCAT_C_Gen_TEMPLATE_FirstRODumpRegionBase
445{
446 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
447 {
448 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
449 }
450 my $DumpRegions_ref = &Get_Dump_Regions($g_DumpRegions_href, $g_DumpRegionOrder_aref);
451 my $template = &Get_FirstROM_Dump_Region_Base_String($DumpRegions_ref);
452 return $template;
453}
454sub SCAT_C_Gen_TEMPLATE_DUMP_REGION_ASSIGN
455{
456 my $template;
457 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
458 {
459 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
460 }
461 my $DumpRegions_ref = &Get_Dump_Regions($g_DumpRegions_href, $g_DumpRegionOrder_aref);
462 $template = DumpAssign($DumpRegions_ref);
463 return $template;
464}
465
466sub SCAT_C_Gen_TEMPLATE_DUMP_REGION_NO_UC_ROM_ASSIGN
467{
468 my $template;
469 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
470 {
471 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
472 }
473 my @skip_regions = ("ROM","_VA","_PA","L2LOCK");
474 my $DumpRegions_ref = &Get_Dump_Regions($g_DumpRegions_href, $g_DumpRegionOrder_aref,\@skip_regions );
475 $template = DumpAssign($DumpRegions_ref);
476 return $template;
477}
478
479sub SCAT_C_Gen_TEMPLATE_DUMP_REGION_ROM_ASSIGN
480{
481 my $template;
482 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
483 {
484 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
485 }
486 my @skip_regions;
487 my @reserved_regions = ("ROM");
488 my $DumpRegions_ref = &Get_Dump_Regions($g_DumpRegions_href, $g_DumpRegionOrder_aref, \@skip_regions, \@reserved_regions);
489 $template = DumpAssign($DumpRegions_ref);
490 return $template;
491}
492
493sub SCAT_C_Gen_TEMPLATE_DUMP_REGION_PA_ASSIGN
494{
495 my $template;
496 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
497 {
498 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
499 }
500 my @skip_regions;
501 my @reserved_regions = ("_PA");
502 my $DumpRegions_ref = &Get_Dump_Regions($g_DumpRegions_href, $g_DumpRegionOrder_aref, \@skip_regions, \@reserved_regions);
503 $template = DumpAssign($DumpRegions_ref);
504 return $template;
505}
506
507sub SCAT_C_Gen_TEMPLATE_DUMP_REGION_VA_ASSIGN
508{
509 my $template;
510 if(!defined $g_DumpRegions_href or !defined $g_DumpRegionOrder_aref)
511 {
512 ($g_DumpRegions_href, $g_DumpRegionOrder_aref) = $g_MAUILinkInfo->GetDumpExeRegions($g_bb);
513 }
514 my @skip_regions;
515 my @reserved_regions = ("_VA");
516 my $DumpRegions_ref = &Get_Dump_Regions($g_DumpRegions_href, $g_DumpRegionOrder_aref, \@skip_regions, \@reserved_regions);
517 $template = DumpAssign($DumpRegions_ref);
518 return $template;
519}
520
521sub SCAT_C_Gen_TEMPLATE_CACHEABLE_PREFIX
522{
523 return &CommonUtil::Dec2Hex(sysUtil::GetCacheablePrefix($g_bb));
524}
525
526sub DumpAssign
527{
528 my ($DumpRegions_ref) = @_;
529 my $template = " extern kal_bool INT_IsAnyCore_Enter_Exception(void);\n\n";
530 my $i = 0;
531 my $prevGrpName;
532 for($i = 0; $i < $#$DumpRegions_ref+1; $i++)
533 {
534 my $GroupName = $DumpRegions_ref->[$i]->[0];
535 if (!($GroupName eq $prevGrpName))
536 {
537 $prevGrpName = $GroupName;
538 $template .= " /*".$GroupName."*/\n";
539 }
540 $template .= " region[$i].addr = ".$DumpRegions_ref->[$i]->[1].";\n";
541 $template .= " region[$i].len = ".$DumpRegions_ref->[$i]->[2].";\n";
542
543 if($GroupName =~ /VECTOR_TABLE/i)
544 {
545 $template .= " if( FirstRODumpRegionBase == 0x0)\n region[$i].addr += 4;\n";
546 }
547
548 $template .= " region[$i].addr = MAP2CREGPA(region[$i].addr);\n" if($GroupName =~ /DYNAMIC_DC_PA|CACHED_.*_PA|ROM_PA|IOCU.*_PA|DRDI_.*_PA/i);
549 $template .= " region[$i].addr = MAP2CREGVA(region[$i].addr);\n" if($GroupName =~ /DYNAMIC_DNC_.*VA/i);
550 }
551 $template .="\n return ". $i. "*2;";
552 return $template;
553}
554sub Get_FirstROM_Dump_Region_Base_String
555{
556 my ($DumpRegions_aref)= @_; #[[GroupName, Base, Length]...]
557 my $strBase = "0xFFFFFFFF";
558 for(my $i = 0; $i < $#$DumpRegions_aref+1; $i++)
559 {
560 my $GroupName = $DumpRegions_aref->[$i]->[0];
561 if($GroupName ne "ROM")
562 {
563 next;
564 }
565 else
566 {
567 $strBase = $DumpRegions_aref->[$i]->[1];
568 last;
569 }
570 }
571 return $strBase;
572}
573
574sub Get_Dump_Regions
575{
576 my ($DumpRegion_href, $DumpRegionOrder_aref, $skip_region_ref, $reserved_region_ref) = @_;
577 my @DumpRegions;
578 my $nIndex = 0;
579 foreach my $strGroupName (@$DumpRegionOrder_aref)
580 {
581 my $skip = 0;
582 foreach my $skip_region (@$skip_region_ref)
583 {
584 if($strGroupName =~ /$skip_region/)
585 {
586 $skip = 1;
587 last;
588 }
589 }
590 foreach my $reserved_region (@$reserved_region_ref)
591 {
592 unless($strGroupName =~ /$reserved_region$/)
593 {
594 $skip = 1;
595 last;
596 }
597 }
598 next if($skip==1);
599 my $array_ref = $DumpRegion_href->{$strGroupName};
600 foreach my $RegionItem (@$array_ref)
601 {
602 my $RegionName = $RegionItem->[0];
603 my $Info = $g_MAUILinkInfo->GetExeRegionInfo($RegionName);
604 if($RegionName eq "DUMP_VECTOR_TABLE")
605 {
606 #print "[$strGroupName]$RegionName: ".$Info->[Region::Base].", ".$Info->[Region::MaxSize]."\n";
607 push(@DumpRegions, [$strGroupName, $Info->[Region::Base], $Info->[Region::MaxSize]]);
608 $nIndex++; next;
609 }
610 if($g_MAUILinkInfo->IsFixedLengthDumpGroup($strGroupName))
611 {
612 #print "[$strGroupName]$RegionName: (kal_uint32)&Image\$\$$RegionName\$\$Base, ".$Info->[Region::MaxSize]."\n";
613 push(@DumpRegions, [$strGroupName, "(kal_uint32)&Image\$\$$RegionName\$\$Base", $Info->[Region::MaxSize]]);
614 $nIndex++; next;
615 }
616 elsif($strGroupName =~ /LOAD_AREA/ && !($RegionItem =~/DRDI/))
617 {
618 my $LastRegionName = $RegionItem->[ scalar(@$RegionItem)-1 ];
619 my $strLength = "(kal_uint32)&Image\$\$$RegionName\$\$Length";
620
621 my ($bIsOverlapped, $strOverlappedLength) = $g_MAUILinkInfo->IsOverlappedRegion($LastRegionName);
622 if( $bIsOverlapped && (scalar(@$RegionItem) > 1) )
623 { # load view is not overlapped
624 $strLength = "(kal_uint32)&Load\$\$$RegionItem->[scalar(@$RegionItem)-1]\$\$Base";
625 $strLength .= "\n + (kal_uint32)&Image\$\$$RegionItem->[scalar(@$RegionItem)-1]\$\$Length";
626 $strLength .= "\n - region\[$nIndex].addr";
627 }
628
629 print "[$strGroupName]$RegionName: (kal_uint32)&Load\$\$$RegionName\$\$Base, $strLength\n" if($DebugPrint);
630 push(@DumpRegions, [$strGroupName, "(kal_uint32)&Load\$\$$RegionName\$\$Base", $strLength]);
631 $nIndex++; next;
632 }
633 else
634 {
635 my $LastRegionName = $RegionItem->[ scalar(@$RegionItem)-1 ];
636 my $strLength = undef;
637 if(scalar(@$RegionItem) == 1)
638 {
639 my ($bIsFixed, $strFixedLength) = $g_MAUILinkInfo->IsFixedLengthRegion($RegionName);
640 $strLength = $strFixedLength if ($bIsFixed == 1);
641 }
642 if(!defined $strLength)
643 {
644 $strLength = "(kal_uint32)&Image\$\$$LastRegionName\$\$ZI\$\$Limit - region\[$nIndex].addr";
645 }
646
647 my ($bIsOverlapped, $strOverlappedLength) = $g_MAUILinkInfo->IsOverlappedRegion($LastRegionName);
648 if( $bIsOverlapped && (scalar(@$RegionItem) > 1) )
649 {
650 my $template = "(kal_uint32)&Image\$\$$RegionItem->[0]\$\$ZI\$\$Limit";
651 for(my $i=1; $i<scalar(@$RegionItem);++$i)
652 {
653 $template = "\n\tscat_max(".$template.",\n". "\t (kal_uint32)&Image\$\$$RegionItem->[$i]\$\$ZI\$\$Limit)";
654 }
655 $strLength = $template;
656 $strLength .= "\n - region\[$nIndex].addr";
657 }
658
659 print "[$strGroupName]$RegionName: (kal_uint32)&Image\$\$$RegionName\$\$Base, $strLength\n" if($DebugPrint);
660 push(@DumpRegions, [$strGroupName, "(kal_uint32)&Image\$\$$RegionName\$\$Base", $strLength]);
661 $nIndex++; next;
662 }
663 }
664 }
665 return \@DumpRegions; #[[GroupName, Base, Length]...]
666}
667
668sub SCAT_C_Gen_REGION_SYMBOL
669{
670 my $template;
671 my $ExeRegion_ref = $g_MAUILinkInfo->GetAllExeRegion();
672 foreach (@$ExeRegion_ref)
673 {
674 $template .= "extern kal_uint32 Image\$\$$_\$\$Base;\n";
675 $template .= "extern kal_uint32 Load\$\$$_\$\$Base;\n" if((/ISPRAM[0-1]|ROM|DRDI|CODE/)&&(!/PHYSICAL_BOUNDARY/));
676 $template .= "extern kal_uint32 Image\$\$$_\$\$Length;\n";
677 $template .= "extern kal_uint32 Image\$\$$_\$\$ZI\$\$Limit;\n";
678 }
679 my $ROM_End = &Gen_RegionName_EV_ROM_END("ROM");
680 $template .= "extern kal_uint32 Load\$\$$ROM_End\$\$Base;\n";
681
682 return $template;
683}
684sub SCAT_C_Gen_ARRAY_DEMP_RESOURCE_TABLE
685{
686 my $template;
687 my $MBA_href = &GetGroupedRegions("MBA");
688 foreach(@$MBA_href)
689 {
690 my $temp = $_->[0];
691 $temp =~ s/_ROM//;
692 $template .= "static kal_uint16 demp_".lc($temp)."_image_table[DEMP_".uc($temp)."_SIZE * DEMP_BLOCK_PER_MB];\n";
693 }
694 return $template;
695}
696sub SCAT_C_Gen_TEMPLATE_DEMP_RESOURCE_TABLE_ASSIGN
697{
698 my $template;
699 my $MBA_href = &GetGroupedRegions("MBA");
700 foreach(@$MBA_href)
701 {
702 my $temp = $_->[0];
703 $temp =~ s/_ROM//;
704 $template .= " demp_image_table[DEMP_".uc($temp)."] = demp_".lc($temp)."_image_table;\n";
705 }
706 return $template;
707}
708sub GetGroupedRegionCount
709{
710 my ($strKey) = @_;
711 my $nCount = 0;
712 if($strKey eq "CPT")
713 {
714 my $fpt_count = 1; # ROM
715# $fpt_count++ if($g_MAUILinkInfo->IsRegionExistent("SECONDARY_ROM"));
716 $nCount = 1 + (4*&GetGroupedRegionCount("DYNAMIC_DNC")) +
717 (4*&GetGroupedRegionCount("DYNAMIC_DC")) +
718 (4*&GetGroupedRegionCount("CACHED_RW")) +
719 (4*&GetGroupedRegionCount("CACHED_RO")) +
720 (2*&GetGroupedRegionCount("NONCACHED_RW")) +
721 (2*&GetGroupedRegionCount("NONCACHED_RO")) +
722 1 + #cpt_for_last: DSPTX, DSPRX
723 (&GetGroupedRegionCount("EXTCODE")-1) + 2 +
724 $fpt_count;
725 }
726 else
727 {
728 if(exists $g_GroupedRegions{$strKey})
729 {
730 $nCount = $g_GroupedRegions{$strKey}->[0];
731 }
732 else
733 {
734 my $Array_ref = $g_MAUILinkInfo->GetGroupedRegions($strKey);
735 $nCount = (scalar(@$Array_ref));
736 $g_GroupedRegions{$strKey} = [$nCount, $Array_ref];
737 }
738 }
739 return $nCount;
740}
741sub SCAT_C_Gen_ARM9_PT_POOLSIZE
742{
743 my $template;
744 my $cpt_count = &GetGroupedRegionCount("CPT");
745 $template = "#define MAX_FPT_POOL_SIZE ( 0 )\n";
746 $template .="#define MAX_CPT_POOL_SIZE ($cpt_count * 1 * 1024)";
747
748 return $template;
749}
750sub SCAT_C_Gen_ARM11_PT_POOLSIZE
751{
752 my $template;
753 my $cpt_count = &GetGroupedRegionCount("CPT");
754 $template = "#define MAX_CPT_POOL_SIZE ( $cpt_count * 1 * 1024)";
755
756 return $template;
757}
758sub SCAT_C_Gen_ARRAY_EXTSRAM_REGION
759{
760 my $DYNAMIC_DNC_Count = 1+&GetGroupedRegionCount("DYNAMIC_DNC");
761 my $DYNAMIC_DC_Count = 1+&GetGroupedRegionCount("DYNAMIC_DC");
762 my $CACHED_RW_Count = 1+&GetGroupedRegionCount("CACHED_RW_INCLUDE_DRDI");
763 my $CACHED_RO_Count = 1+&GetGroupedRegionCount("CACHED_RO");
764 my $NONCACHED_RW_Count = 1+&GetGroupedRegionCount("NONCACHED_RW");
765 my $NONCACHED_RO_Count = 1+&GetGroupedRegionCount("NONCACHED_RO");
766 my $EXTCODE_Count = 1+&GetGroupedRegionCount("EXTCODE");
767 my $template = <<"__TEMPLATE";
768__TCMZI static EXTSRAM_REGION_INFO_T DYNAMIC_CACHED_EXTSRAM_DNC_REGION[$DYNAMIC_DNC_Count];
769__TCMZI static EXTSRAM_REGION_INFO_T DYNAMIC_CACHED_EXTSRAM_DC_REGION[$DYNAMIC_DC_Count];
770__TCMZI static EXTSRAM_REGION_INFO_T CACHED_EXTSRAM_REGION[$CACHED_RW_Count];
771__TCMZI static EXTSRAM_REGION_INFO_T CACHED_EXTSRAM_CODE_REGION[$CACHED_RO_Count];
772__TCMZI static EXTSRAM_REGION_INFO_T NONCACHED_EXTSRAM_REGION[$NONCACHED_RW_Count];
773__TCMZI static EXTSRAM_REGION_INFO_T NONCACHED_EXTSRAM_RO_REGION[$NONCACHED_RO_Count];
774__TEMPLATE
775}
776
777sub SCAT_C_Gen_ARRAY_DYNAMIC_CODE_REGION
778{
779 my $array = $g_MAUILinkInfo->GetAllExeRegion();
780 my $ISPRAM0_Count = 1;
781 my $ISPRAM0_sections ="";
782 my $ISPRAM1_Count = 1;
783 my $ISPRAM1_sections ="";
784 my $template;
785 foreach my $region (@{$array})
786 {
787 next if (!($region =~ /DYNAMIC_SECTION/));
788 if ($region =~ /ISPRAM0/) {
789 $ISPRAM0_Count += 1;
790 $ISPRAM0_sections .="{(kal_uint32)&Image\$\$$region\$\$Base,(kal_uint32)&Load\$\$$region\$\$Base,(kal_uint32)&Image\$\$$region\$\$Length},\n\t\t";
791 } elsif ($region =~ /ISPRAM1/) {
792 $ISPRAM1_Count += 1;
793 $ISPRAM1_sections .="{(kal_uint32)&Image\$\$$region\$\$Base,(kal_uint32)&Load\$\$$region\$\$Base,(kal_uint32)&Image\$\$$region\$\$Length},\n\t\t";
794 }
795 }
796 $ISPRAM0_sections .="{0,0,0}";
797 $ISPRAM1_sections .="{0,0,0}";
798 $template = "\nstatic kal_uint32 ISPRAM0_CODE_SECTIONS[$ISPRAM0_Count][3]={$ISPRAM0_sections};\nstatic kal_uint32 ISPRAM1_CODE_SECTIONS[$ISPRAM1_Count][3]={$ISPRAM1_sections};\n";
799 return $template;
800}
801
802sub SCAT_C_Gen_ARRAY_CODE_REGIONS
803{
804 my $array = $g_MAUILinkInfo->GetAllExeRegion();
805 my $Code_region_Count = 1;
806 my $code_sections ="";
807 my $template;
808 foreach my $region (@{$array})
809 {
810 next if (!($region =~ /DYNAMIC_SECTION|L2CACHE_LOCK|^ROM|^UROM|^ISPRAM[01]$/));
811 next if ($region =~ /^AUROM|^ROM_GFH|ROM_SIGNATURE_SECTION/);
812 $Code_region_Count += 1;
813 $code_sections .="{(kal_uint32)&Image\$\$$region\$\$Base,(kal_uint32)&Image\$\$$region\$\$Length},\n\t\t";
814 }
815 $code_sections .="{0,0}";
816 $template = "\nstatic kal_uint32 CODE_SECTIONS[$Code_region_Count][2]={$code_sections};\n";
817 return $template;
818}
819
820sub SCAT_C_Gen_ARRAY_MCURO_HWRW_REGIONS
821{
822 my $array = $g_MAUILinkInfo->GetAllExeRegion();
823 my $MCURO_HWRW_Region_Count = 1;
824 my $MCURO_HWRW_Sections ="";
825 my $template;
826 foreach my $region (@{$array}){
827 if ($region =~ /MCURO_HWRW/){
828 $MCURO_HWRW_Region_Count += 1;
829 $MCURO_HWRW_Sections .="{(kal_uint32)&Image\$\$$region\$\$Base,(kal_uint32)&Image\$\$$region\$\$ZI\$\$Limit},\n\t\t";
830 }
831 }
832 $MCURO_HWRW_Sections .="{0,0}";
833 $template = "\nstatic kal_uint32 MCURO_HWRW_SECTIONS[$MCURO_HWRW_Region_Count][2]={$MCURO_HWRW_Sections};\n";
834
835 return $template;
836}
837
838sub SCAT_C_Gen_TEMPLATE_1stRAM_BEGIN
839{
840 my $template = "0";
841 my $array_ref = $g_MAUILinkInfo->GetExeRegionsInRAMByLoadRegion("ROM");
842 &sysUtil::sysgen_die("There should be execution regions in ROM!", __FILE__, __LINE__) if(!defined $array_ref);
843 my $strRegionName = $array_ref->[0];
844 my $Offset = lc($g_MAUILinkInfo->GetRegionInfo($strRegionName, Region::Offset));
845 if($Offset =~ /\+0xf/)
846 {
847 $template = "(kal_uint32)((kal_uint32)&Image\$\$$strRegionName\$\$Base & (~0xf0000000))";
848 }
849 else
850 {
851 $template = "((kal_uint32)&Image\$\$$strRegionName\$\$Base & (~0xF0000000)) | ". &sysUtil::GetNonCacheablePrefix($g_bb);
852 }
853 return $template;
854}
855sub SCAT_C_Gen_RegionName_EV_1stRAM_END
856{
857 my $array_ref = $g_MAUILinkInfo->GetExeRegionsInRAMByLoadRegion("ROM");
858 &sysUtil::sysgen_die("There should be execution regions in ROM!", __FILE__, __LINE__) if(!defined $array_ref);
859 return $array_ref->[$#{$array_ref}];
860}
861sub SCAT_C_Gen_RegionName_EV_1stROM_BEGIN
862{
863 my $array_ref = $g_MAUILinkInfo->GetExeRegionsInROMByLoadRegion("ROM");
864 &sysUtil::sysgen_die("There should be execution regions in ROM!", __FILE__, __LINE__) if(!defined $array_ref);
865 return $array_ref->[0];
866}
867sub SCAT_C_Gen_TEMPLATE_1stROM_LENGTH
868{
869 my $array_ref = $g_MAUILinkInfo->GetExeRegionsInROMByLoadRegion("ROM");
870 &sysUtil::sysgen_die("There should be execution regions in ROM!", __FILE__, __LINE__) if(!defined $array_ref);
871 my $template = "";
872 foreach (@$array_ref)
873 {
874 $template .= " (kal_uint32)&Load\$\$$_\$\$Base,(kal_uint32)&Image\$\$$_\$\$Length";
875 if (!($_ eq $$array_ref[-1]))
876 {
877 $template .= ",";
878 }
879 $template .= "\n";
880 }
881 return $template;
882}
883
884sub SCAT_C_Gen_RegionName_EV_1stROM_END
885{
886 return &Gen_RegionName_EV_ROM_END("ROM");
887}
888sub Gen_RegionName_EV_ROM_END
889{
890 my ($ROM) = @_;
891 my $array_ref = $g_MAUILinkInfo->GetExeRegionsByLoadRegion($ROM);
892 &sysUtil::sysgen_die("There should be execution regions in ROM!", __FILE__, __LINE__) if(!defined $array_ref and $ROM eq "ROM");
893 my $LastRegion = undef;
894 if(defined $array_ref)
895 {
896 my $nIndex = $#{$array_ref};
897 foreach my $i (0 .. $nIndex)
898 {
899 if($array_ref->[$#{$array_ref} - $i] !~ /INTSRAM_BLINUSED|FLEXL2_DATA|FLMM/)
900 {
901 $LastRegion = $array_ref->[$#{$array_ref} - $i];
902 last;
903 }
904 }
905 }
906 return $LastRegion;
907}
908sub SCAT_C_Gen_TEMPLATE_SYSRAM_BEGIN
909{
910 my $strBase = "0xE0000000";
911 $strBase = '(kal_uint32)&Image$$INTSRAM_MULTIMEDIA$$Base' if($g_MAUILinkInfo->IsRegionExistent("INTSRAM_MULTIMEDIA"));
912 return $strBase;
913}
914sub SCAT_C_Gen_TEMPLATE_SYSRAM_END
915{
916 my $strBase = "0xE0000000";
917 $strBase = '(kal_uint32)&Image$$INTSRAM_MULTIMEDIA$$ZI$$Limit' if($g_MAUILinkInfo->IsRegionExistent("INTSRAM_MULTIMEDIA"));
918 return $strBase;
919}
920sub SCAT_C_Gen_MaxSize_SYSRAM
921{
922 my $strMaxSize = "0";
923 $strMaxSize = $g_MAUILinkInfo->GetRegionInfo("INTSRAM_MULTIMEDIA", Region::MaxSize) if($g_MAUILinkInfo->IsRegionExistent("INTSRAM_MULTIMEDIA"));
924 return $strMaxSize;
925}
926sub GetGroupBase
927{
928 my ($strGroupName) = @_;
929 my $template = "0";
930 my $aref = GetGroupedRegions($strGroupName);
931 if(scalar(@$aref)>0)
932 {
933 my $strRegionName = $aref->[0]->[0];
934 $template = "(kal_uint32)&Image\$\$$strRegionName\$\$Base";
935 }
936 return $template;
937}
938sub GetGroupEnd
939{
940 my ($strGroupName) = @_;
941 my $template = "0";
942 my $aref = GetGroupedRegions($strGroupName);
943 if(scalar(@$aref)>0)
944 {
945 my $end_index = scalar(@{$aref->[0]}) -1;
946 my $strRegionName = $aref->[0]->[$end_index];
947 $template = "(kal_uint32)&Image\$\$$strRegionName\$\$ZI\$\$Limit";
948 }
949 return $template;
950}
951
952sub GetGroupBaseRegionName
953{
954 my ($strGroupName) = @_;
955 my $strRegionName = undef;
956 my $aref = GetGroupedRegions($strGroupName);
957 if(scalar(@$aref)>0)
958 {
959 my $end_index = scalar(@{$aref->[0]}) -1;
960 $strRegionName = $aref->[0]->[$end_index];
961 }
962 return $strRegionName;
963}
964
965sub SCAT_C_Gen_INTSRAMDATA_END
966{
967 my $template = "kal_uint32 ret=0;\n";
968 my $INTSRAM_ref = &GetGroupedRegions("INTSRAM");
969 foreach (@$INTSRAM_ref)
970 {
971 my $array_ref = $_;
972 my $nCount = (scalar(@$array_ref));
973 for(my $i=0; $i<$nCount;++$i)
974 {
975 next if ( $array_ref->[ $i ] =~ /INTSRAM_PHYSICAL_BOUNDARY/ );
976 my $strEnd = "(kal_uint32)&Image\$\$".$array_ref->[ $i ]."\$\$ZI\$\$Limit";
977 $template .= "\tret = ($strEnd > ret ? $strEnd : ret);\n";
978 }
979 }
980 $template .= "\treturn ret;\n";
981 return $template;
982}
983
984sub SCAT_C_Gen_RegionName_EV_INTSRAM_HW_BOUNDARY
985{
986 my $strRegion = "INTSRAM_DATA";
987 $strRegion = "INTSRAM_PHYSICAL_BOUNDARY" if($g_MAUILinkInfo->IsRegionExistent("INTSRAM_PHYSICAL_BOUNDARY"));
988 return $strRegion;
989}
990sub SCAT_C_Gen_MaxSize_INTSRAM_HW_BOUNDARY
991{
992 my $strMaxSize = "0";
993 $strMaxSize = $g_MAUILinkInfo->GetRegionInfo("INTSRAM_PHYSICAL_BOUNDARY", Region::MaxSize) if($g_MAUILinkInfo->IsRegionExistent("INTSRAM_PHYSICAL_BOUNDARY"));
994 return $strMaxSize;
995}
996sub SCAT_C_Gen_TEMPLATE_PROTECTED_RES_BEGIN
997{
998 return &Gen_Region_EV_TEMPLATE("PROTECTED_RES", "Base");
999}
1000sub SCAT_C_Gen_TEMPLATE_PROTECTED_RES_LEGNTH
1001{
1002 return &Gen_Region_EV_TEMPLATE("PROTECTED_RES", "Length");
1003}
1004sub SCAT_C_Gen_TEMPLATE_BOOTCERT_BEGIN
1005{
1006 my $template = "0";
1007 $template = '(kal_uint32)&Load$$BOOT_CERT$$Base' if($g_MAUILinkInfo->IsRegionExistent("BOOT_CERT"));
1008 return $template;
1009}
1010sub SCAT_C_Gen_TEMPLATE_SECUREMAC_BEGIN
1011{
1012 my $template = "0";
1013 $template = '(kal_uint32)&Load$$__HIDDEN_SECURE_MAC$$Base' if($g_MAUILinkInfo->IsRegionExistent("__HIDDEN_SECURE_MAC"));
1014 return $template;
1015}
1016sub SCAT_C_Gen_TEMPLATE_SECUREMAC_LEGNTH
1017{
1018 my $template = "0";
1019 $template = '(kal_uint32)&Image$$__HIDDEN_SECURE_MAC$$Length' if($g_MAUILinkInfo->IsRegionExistent("__HIDDEN_SECURE_MAC"));
1020 return $template;
1021}
1022sub SCAT_C_Gen_TEMPLATE_SECURERO_BEGIN
1023{
1024 my $template = "0";
1025 $template = '(kal_uint32)&Load$$SECURE_RO$$Base' if($g_MAUILinkInfo->IsRegionExistent("SECURE_RO"));
1026 return $template;
1027}
1028sub SCAT_C_Gen_TEMPLATE_SECURERO_LEGNTH
1029{
1030 my $template = "0";
1031 $template = '(kal_uint32)&Image$$SECURE_RO$$Length' if($g_MAUILinkInfo->IsRegionExistent("SECURE_RO"));
1032 return $template;
1033}
1034
1035sub SCAT_C_Gen_TEMPLATE_DSPTXRX_BEGIN
1036{
1037 my $template = "0";
1038 my $strRegionName = $g_MAUILinkInfo->SearchExeRegionName("_DSP_TX");
1039 $strRegionName = $g_MAUILinkInfo->SearchExeRegionName("_DSP_RX") if(!defined $strRegionName);
1040 $template = "(kal_uint32)&Image\$\$$strRegionName\$\$Base" if(defined $strRegionName);
1041 return $template;
1042}
1043sub SCAT_C_Gen_TEMPLATE_DSPTXRX_MAXSIZE
1044{
1045 my ($nTXLength,$nRXLength) = &sysUtil::DSPTXRX_query_length($g_bb, &FileInfo::get("MODE"));
1046 return &CommonUtil::Dec2Hex($nTXLength) ." + ". &CommonUtil::Dec2Hex($nRXLength);
1047}
1048
1049
1050sub Gen_RegionName_UNUSED_END_Base
1051{
1052 my $strRegionName;
1053 if(1 == &sysUtil::is_mmu($g_bb))
1054 {
1055 $strRegionName = "CACHED_DUMMY_END";
1056 $strRegionName = $g_MAUILinkInfo->SearchExeRegionName("DUMMY_END") if(! $g_MAUILinkInfo->IsRegionExistent($strRegionName));
1057 }
1058 $strRegionName = $g_MAUILinkInfo->SearchExeRegionName("EXTSRAM_FS_ZI") if( $g_MAUILinkInfo->IsRegionExistent("EXTSRAM_FS_ZI") );
1059 return $strRegionName;
1060}
1061sub Gen_RegionName_EV_LAST_CACHED_REGION
1062{
1063 my $strPreviousRegionName;
1064 if(1 == &sysUtil::is_mmu($g_bb))
1065 {
1066 my $strRegionName = &Gen_RegionName_UNUSED_END_Base();
1067 $strPreviousRegionName = $g_MAUILinkInfo->GetPreviousExeRegionName($strRegionName) if(defined $strRegionName);
1068 $strPreviousRegionName = $g_MAUILinkInfo->GetPreviousExeRegionName($strPreviousRegionName) if( $strPreviousRegionName eq "EXECUTION_VIEW_END" );
1069 &sysUtil::sysgen_die("Region Name can't be empty!", __FILE__, __LINE__) if(!defined $strPreviousRegionName);
1070 }
1071 return $strPreviousRegionName;
1072}
1073
1074sub SCAT_C_Gen_TEMPLATE_NVRAM_BASE
1075{
1076 return &Gen_Region_EV_TEMPLATE("NVRAM", "Base");
1077}
1078sub SCAT_C_Gen_TEMPLATE_NVRAM_LENGTH
1079{
1080 return &Gen_Region_EV_TEMPLATE("NVRAM", "Length");
1081}
1082
1083sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_CODE_BASE
1084{
1085 return GetGroupBase("L2SRAM_L2NC");
1086}
1087sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_CODE_LOAD_BASE
1088{
1089 return "MAP2CREGPA(&Load\$\$L2SRAM_L2NC_CODE\$\$Base)";
1090}
1091sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_CODE_LENGTH
1092{
1093 return "(kal_uint32)&Image\$\$L2SRAM_L2NC_CODE\$\$Length"
1094}
1095sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_DATA_BASE
1096{
1097 return "(kal_uint32)&Image\$\$L2SRAM_L2NC_DATA\$\$Base";
1098}
1099sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_DATA_LOAD_BASE
1100{
1101 return "MAP2CREGPA(&Load\$\$L2SRAM_L2NC_DATA\$\$Base)";
1102}
1103sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_DATA_LENGTH
1104{
1105 return "(kal_uint32)&Image\$\$L2SRAM_L2NC_DATA\$\$Length";
1106}
1107sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_DATA_ZI_BASE
1108{
1109 return "(kal_uint32)&Image\$\$L2SRAM_L2NC_DATA\$\$ZI\$\$Base";
1110}
1111sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2NC_DATA_ZI_LENGTH
1112{
1113 return "(kal_uint32)&Image\$\$L2SRAM_L2NC_DATA\$\$ZI\$\$Length";
1114}
1115sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_CODE_BASE
1116{
1117 return "(kal_uint32)&Image\$\$L2SRAM_L2C_CODE\$\$Base";
1118}
1119sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_CODE_LOAD_BASE
1120{
1121 return "MAP2CREGPA(&Load\$\$L2SRAM_L2C_CODE\$\$Base)";
1122}
1123sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_CODE_LENGTH
1124{
1125 return "(kal_uint32)&Image\$\$L2SRAM_L2C_CODE\$\$Length"
1126}
1127sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_DATA_BASE
1128{
1129 return "(kal_uint32)&Image\$\$L2SRAM_L2C_DATA\$\$Base";
1130}
1131sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_DATA_LOAD_BASE
1132{
1133 return "MAP2CREGPA(&Load\$\$L2SRAM_L2C_DATA\$\$Base)";
1134}
1135sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_DATA_LENGTH
1136{
1137 return "(kal_uint32)&Image\$\$L2SRAM_L2C_DATA\$\$Length";
1138}
1139sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_DATA_ZI_BASE
1140{
1141 return "(kal_uint32)&Image\$\$L2SRAM_L2C_DATA\$\$ZI\$\$Base";
1142}
1143sub SCAT_C_Gen_TEMPLATE_L2SRAM_L2C_DATA_ZI_LENGTH
1144{
1145 return "(kal_uint32)&Image\$\$L2SRAM_L2C_DATA\$\$ZI\$\$Length";
1146}
1147sub Gen_Region_EV_TEMPLATE
1148{
1149 my ($strKey, $strPostfix) = @_;
1150 my $template = "0";
1151 my $RegionName = $g_MAUILinkInfo->SearchExeRegionName($strKey);
1152 if(defined $RegionName)
1153 {
1154 $template = "(kal_uint32)&Image\$\$$RegionName\$\$$strPostfix";
1155 }
1156 return $template;
1157}
1158sub SCAT_C_Gen_TEMPLATE_EXTSRAM_REGION_DYNAMIC_DC_ASSIGN
1159{
1160 return &get_region_info_template("DYNAMIC_DC","DYNAMIC_CACHED_EXTSRAM_DC_REGION");
1161}
1162sub SCAT_C_Gen_TEMPLATE_EXTSRAM_REGION_DYNAMIC_DNC_ASSIGN
1163{
1164 return &get_region_info_template("DYNAMIC_DNC","DYNAMIC_CACHED_EXTSRAM_DNC_REGION");
1165}
1166sub SCAT_C_Gen_TEMPLATE_EXTSRAM_REGION_CACHED_RW_ASSIGN
1167{
1168# return &get_region_info_template("CACHED_RW","CACHED_EXTSRAM_REGION");
1169 return &get_region_info_template("CACHED_RW_INCLUDE_DRDI","CACHED_EXTSRAM_REGION");
1170}
1171sub SCAT_C_Gen_TEMPLATE_EXTSRAM_REGION_CACHED_RO_ASSIGN
1172{
1173 return &get_region_info_template("CACHED_RO","CACHED_EXTSRAM_CODE_REGION");
1174}
1175sub SCAT_C_Gen_TEMPLATE_EXTSRAM_REGION_NONCACHED_RW_ASSIGN
1176{
1177 return &get_region_info_template("NONCACHED_RW","NONCACHED_EXTSRAM_REGION");
1178}
1179sub SCAT_C_Gen_TEMPLATE_EXTSRAM_REGION_NONCACHED_RO_ASSIGN
1180{
1181 return &get_region_info_template("NONCACHED_RO","NONCACHED_EXTSRAM_RO_REGION");
1182}
1183
1184sub SCAT_C_Gen_TEMPLATE_CORE0_CACHEABLE_ASSING
1185{
1186 return &GetCoreCachedRegions_template(0);
1187}
1188
1189sub SCAT_C_Gen_TEMPLATE_CORE1_CACHEABLE_ASSING
1190{
1191 return &GetCoreCachedRegions_template(1);
1192}
1193
1194sub SCAT_C_Gen_TEMPLATE_CORE2_CACHEABLE_ASSING
1195{
1196 return &GetCoreCachedRegions_template(2);
1197}
1198
1199sub SCAT_C_Gen_TEMPLATE_1st_MCURW_SECTION
1200{
1201 my $array_ref = $g_MAUILinkInfo->GetExeRegionsByLoadRegion("ROM");
1202 &sysUtil::sysgen_die("There should be execution regions in ROM!", __FILE__, __LINE__) if(!defined $array_ref);
1203 my $Region = undef;
1204 if(defined $array_ref)
1205 {
1206 my $nIndex = $#{$array_ref};
1207 foreach my $i (0 .. $nIndex)
1208 {
1209 next if ($array_ref->[$i] !~ /EXTSRAM/);
1210 next if ($array_ref->[$i] =~ /L1DSP|MCURO/); # L1DSP is MCURO
1211
1212 $Region = $array_ref->[$i];
1213
1214 last;
1215 }
1216 }
1217 return $Region;
1218}
1219
1220sub GetCoreCachedRegions_template
1221{
1222 my ($core) = @_;
1223 my $template;
1224 my $regionsgrp = $g_MAUILinkInfo->GetGroupedRegions("CORE$core\_C");
1225 my $index = 0;
1226 foreach my $regions (@$regionsgrp)
1227 {
1228 $template .= ",\n" if($index != 0);
1229 my $strStartName = $regions->[0];
1230 my $strEndName = $regions->[-1];
1231 $template = "\{(kal_uint32)&Image\$\$$strStartName\$\$Base,(kal_uint32)&Image\$\$$strEndName\$\$ZI\$\$Limit,DUMP_OP_CORE". $core ."_CACHE\}";
1232 $index = $index + 1;
1233 }
1234 return $template;
1235}
1236
1237sub GetGroupedRegions
1238{
1239 my ($strKey) = @_;
1240 my $Array_ref = undef;
1241 my $nCount = 0;
1242 if(exists $g_GroupedRegions{$strKey})
1243 {
1244 $Array_ref = $g_GroupedRegions{$strKey}->[1];
1245 }
1246 else
1247 {
1248 $Array_ref = $g_MAUILinkInfo->GetGroupedRegions($strKey);
1249 $nCount = (scalar(@$Array_ref));
1250 $g_GroupedRegions{$strKey} = [$nCount, $Array_ref];
1251 }
1252 return $Array_ref;
1253}
1254sub get_region_info_template
1255{
1256 my ($strKey, $strArrayName) = @_;
1257 my $template;
1258 my $GroupedRegion_ref = &GetGroupedRegions($strKey);
1259 my $nIndex =0;
1260 my $RegionPrefix = ($strKey ne "MULTIROM") ? "Image" : "Load";
1261 foreach (@$GroupedRegion_ref) #[[], [], []]
1262 {
1263 my $array_ref = $_;
1264 my $Region = $array_ref->[0];
1265 my $strLength = undef;
1266 if($Region =~ /DYNAMIC_CODE/ and $strKey eq "MULTIROM")
1267 {# DCM Regions in MULTIROM should be handled especially
1268 ($Region, $strLength) = &Get_DCM_Region_Info($array_ref);
1269 }
1270 $template .= " $strArrayName\[$nIndex].addr = (kal_uint32)&$RegionPrefix\$\$$Region\$\$Base;\n";
1271
1272 if(scalar(@$array_ref) > 1)
1273 {
1274 $Region = $array_ref->[ scalar(@$array_ref)-1 ]; #LastRegion
1275
1276 }
1277 else
1278 {
1279 my ($bIsFixed, $strFixedLength) = $g_MAUILinkInfo->IsFixedLengthRegion($Region);
1280 $strLength = $strFixedLength if ($bIsFixed == 1
1281 or ($g_bb eq "MT6256" and $Region eq "DSP_ROM")
1282 or ($strKey =~ /MCU_([NC|C]+)_DSP_([NC|C]+)/ and $Region =~/SHAREMEM/));
1283 }
1284 if(!defined $strLength)
1285 {
1286 if($Region =~/SECURE|FLASHTOOL_CFG|CUST_PARA|BOOT_CERT/)
1287 {
1288 $strLength = "(kal_uint32)&Image\$\$$Region\$\$Length";
1289 }
1290 else
1291 {
1292 $strLength = "(kal_uint32)&Image\$\$$Region\$\$ZI\$\$Limit - $strArrayName\[$nIndex].addr";
1293 }
1294 }
1295
1296 my ($bIsOverlapped, $strOverlappedLength) = $g_MAUILinkInfo->IsOverlappedRegion($Region);
1297 if( $bIsOverlapped && (scalar(@$array_ref) > 1) )
1298 {
1299 $template .= " {\n kal_uint32 max_overlap_limit=0;\n";
1300 foreach my $region (@$array_ref)
1301 {
1302 $template .= " max_overlap_limit = scat_max(max_overlap_limit, (kal_uint32)&Image\$\$$region\$\$ZI\$\$Limit);\n";
1303 }
1304 $template .= " $strArrayName\[$nIndex].len = max_overlap_limit - $strArrayName\[$nIndex].addr;\n }\n";
1305 }
1306 else
1307 {
1308 $template .= " $strArrayName\[$nIndex].len = $strLength;\n";
1309 }
1310
1311 $nIndex++;
1312 }
1313 $template .= " $strArrayName\[$nIndex].addr = $strArrayName\[$nIndex].len = 0;\n";
1314 return $template;
1315}
1316sub IMG_CFG_H_Gen_CBR_NORMAL_BLOCK_NUM
1317{
1318 my $template = "0";
1319 if(!&FileInfo::is_NOR() or $g_bb eq "MT6290") # smart phone can be default 0
1320 {
1321 $template = "2";
1322 }
1323 elsif(&FileInfo::is("secure_ro_enable","TRUE") or &FileInfo::is("secure_support","TRUE"))
1324 {
1325 $template = "1";
1326 }
1327 return $template;
1328}
1329sub IMG_CFG_H_Gen_CBR_SPARE_BLOCK_NUM
1330{
1331 my $template = "0";
1332 if(!&FileInfo::is_NOR()) # smart phone can be default 0
1333 {
1334 $template = "2";
1335 }
1336 return $template;
1337}
1338
1339sub EMI_OFFSET_H_Gen_MD_SIZE
1340{
1341 my($strBase, $strLen) = $g_MAUILinkInfo->{ldsInfo}->GetMEMORYInfoByName("RAM");
1342 my $nBase = hex($strBase);
1343 my $nLen = hex($strLen);
1344 #xor bank address
1345 my $nPrefix = sysUtil::GetNonCacheablePrefix($g_bb);
1346 my $nMDSize = ($nBase ^ $nPrefix) + $nLen;
1347 return CommonUtil::Dec2Hex($nMDSize);
1348}
1349sub Preprocess_Prepare
1350{
1351 die "Parse infomake $infomake failed!\n" if(!BuildInfo::Parse_InfoMakeLog($infomake, \%CmplOption, \%RelOption));
1352
1353 my ($tempdir) = ($bin_path =~ /^(.*)custom/);
1354 $tempdir .= "tmp/";
1355 $OptFile = $tempdir."PreProcessOpt.txt";
1356 my $cmpOpt = undef;
1357 #Gather compiler options
1358 foreach my $key ( keys %CmplOption ) {
1359 next if($key eq lc $key);
1360 if (defined $CmplOption{$key}) {
1361 $cmpOpt .= " -D$key=$CmplOption{$key}";
1362 } else {
1363 $cmpOpt .= " -D$key";
1364 }
1365 }
1366
1367 open (FILE, "> $OptFile") or die "$OptFile: open file error!";
1368 print FILE $cmpOpt;
1369 close FILE;
1370}
1371
1372sub Parse_Config_File
1373{
1374 my ($ConfigFile) = (@_);
1375 my $FileName = File::Basename::basename($ConfigFile);
1376
1377 #Preprocess CustomInputSection.txt
1378 my $cmd = "$gcc_command -x c -E -undef \@$OptFile $ConfigFile";
1379 my $output = qx($cmd);
1380 $? == 0 or die "$ConfigFile preprosseing failed $?\n$output";
1381
1382 #Tidy preprocessor output
1383 my $tempOutput = undef;
1384 map{ $tempOutput .= $_."\n" if (!($_ =~ /(^\s*$)|(^#)/)); } (split /\n/, $output);
1385
1386 #split entire config file into several configuration groups.
1387 foreach my $line (split /\n/, $tempOutput) {
1388 push @section_array, $1 if($line =~ /^Section ID\s*:\s*(.*)\s*$/);
1389 }
1390 my ($tempdir) = ($bin_path =~ /^(.*)custom/);
1391 open CONFIG, '>', $tempdir."tmp/~$FileName";
1392 print CONFIG $tempOutput;
1393 close CONFIG;
1394}
1395
1396sub Get_Config_Info
1397{
1398 Preprocess_Prepare();
1399 Parse_Config_File($official_config);
1400 Parse_Config_File($local_config) if($local_test);
1401}
1402sub DL2CMGR_H_Gen_SECTION_ID_ENUM
1403{
1404 my $template;
1405 map{ $template .= " $_,\n" } @section_array;
1406 $template .= " L2CACHE_LOCK_SECTION_NUM,";
1407 return $template;
1408}
1409
1410sub DL2CMGR_H_Gen_SECTION_LINKER_SYMBOL
1411{
1412 my $template;
1413 map {$template .= "extern kal_uint32 $_\$\$Base;\nextern kal_uint32 $_\$\$Length;\n"} @section_array;
1414 return $template;
1415}
1416
1417sub DL2CMGR_H_Gen_LINKER_SYMBOL_ARRAY
1418{
1419 my $template;
1420 foreach my $id (@section_array) {
1421 $template .= " {\n (kal_uint32) &$id\$\$Base,\n (kal_uint32) &$id\$\$Length,\n";
1422 if ($id =~ /^L2CACHE_LOCK_RO_SECTION_/) {
1423 $template .= " (kal_uint32) 0,\n },\n";
1424 } elsif ($id =~ /^L2CACHE_LOCK_RW_SECTION_/) {
1425 $template .= " (kal_uint32) 1,\n },\n";
1426 } else {
1427 die "Wrong section name format, please check the section name:$id!\n";
1428 }
1429 }
1430 return $template;
1431}