blob: f581272e600fc0ee886ac871dbf48e36fedbfdb7 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#!/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#* LISInfo.pm
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This module collects the subroutines for common utility.
48#*
49#*
50#* Author:
51#* -------
52#* Qmei Yang (mtk03726)
53#*
54#****************************************************************************/
55
56
57use strict;
58#use warnings;
59BEGIN { push @INC, './tools/', './tools/MemoryUtility/' } # add additional library path
60use sysGenUtility; #pm file name without case sensitivity
61use LinkerOutputParser;
62use CommonUtility;
63use FileInfoParser;
64use scatInfo;
65#****************************************************************************
66# Constants
67#****************************************************************************
68my $LISINFO_VERNO = " m0.17";
69 # m0.17 , 2016/06/28, Support for AUROM memory dump in GetCMMDumpRegionInfo
70 # m0.16 , 2016/01/11, SPRAM region size calculation modified in GetCMMDumpRegionInfo
71 # m0.15 , 2016/01/07, Support for core spesific regions in GetCMMDumpRegionInfo
72 # m0.14 , 2015/01/19, Memory Utility Refinement
73 # m0.13 , 2014/01/15, Correct PA address in GetDumpRegionBase()
74 # m0.12 , 2013/12/01, Support cmm memory dump
75 # m0.11 , 2013/10/24, Dump regions in order
76 # m0.10 , 2013/09/05, Dump nc in CACHED_EXTSRAM on moly only
77 # m0.09 , 2013/05/29, Fix code region without dumping data regions
78 # m0.08 , 2013/05/27, Fix cacheable region's prefix
79 # m0.07 , 2012/11/17, Support GetDumpCodeRegions()
80 # m0.06 , 2012/10/05, Support SearchExeRegionName()
81 # m0.05 , 2012/08/17, Support GetChip() from FileInfoParser
82 # m0.04 , 2012/08/07, Move Dec2Hex from sysGenUtility to CommonUtility
83 # m0.03 , 2012/07/26, Change LinkerOutputParser.pm's location
84 # v0.12 , 2012/05/29, Refined GetScatterReservedSize()
85 # v0.10 , 2012/05/29, Provide GetScatterReservedSize() for vivaConfig.pl
86 # m0.02 , 2012/05/28, Support path and filename case sensitive on Linux
87 # m0.01 , 2012/05/28, Support parsing .sym by LinkerOutputParser.pm temporary
88 # v0.09 , 2012/05/16, Modify CheckROMSize() to fix the error of checking rule
89 # v0.08 , 2012/04/17, Support dump ALICE and compressed ALICE
90 # v0.07 , 2012/04/02, Modify the return type of CheckROMSize()
91 # v0.06 , 2012/04/02, Remove GetTotalSizesByObjList_and_ExeRegion()
92 # v0.05 , 2012/03/26, Provide GetTotalROMSize(), GetTotalROSize(), GetTotalRWZISize() instead of GetTotalSizeInfo()
93 # Extend parsing obj list for
94 # providing GetInputSectionnByExeRegion(), GetObjTotalSizesByExeRegion(),
95 # GetTotalSizesByObjList_and_ExeRegion() instead of GetObjInfo()
96 # v0.04 , 2012/03/12, Support GetObjInfo() and provide CheckRomSize() to ckImgSize.pl
97 # v0.03 , 2012/02/15, Support synced with scatInfo.pm
98 # v0.02 , 2011/12/16, Fix a bug
99 # v0.01 , 2011/09/18, Initial revision
100
101#****************************************************************************
102# Constants
103#****************************************************************************
104package InputSection;
105use constant ExeRegionName => 0;
106use constant Base => 1;
107use constant Size => 2;
108use constant Type => 3;
109use constant Attr => 4;
110use constant SectionAttr => 5;
111use constant ObjName => 6;
112use constant LibName => 7;
113
114package MemType;
115use constant CommonCached => 0;
116use constant CommonUnCached => 1;
117use constant CoreUnCached => 2;
118use constant Core0Cached => 3;
119use constant Core1Cached => 4;
120use constant Core2Cached => 5;
121use constant Core3Cached => 6;
122
123
124package LISInfo;
125#****************************************************************************
126# global variable
127#****************************************************************************
128my $g_LISPath;
129# Load Region
130my %g_LoadRegion;
131my $g_LoadRegionCount = 0;
132my %g_LoadRegionLookUpTable; # RegionName -> Index
133# Execution Region
134my %g_ExeRegion;
135my $g_ExeRegionCount = 0;
136my %g_ExeRegionLookUpTable; # RegionName -> Index
137
138# InputSection:
139my %g_InputSectionDetails; # {nIndex} => [0. strExecutionRegionName,
140 # 1. strBaseAddress,
141 # 2. strSize,
142 # 3. strType,
143 # 4. strAttr,
144 # 5. strSectionName,
145 # 6. strObjectName,
146 # 7. strLibName]
147 # nIndex starts from 0
148my %g_InputSections; # {strExecutionRegionName} => [nIndex, ...]
149my $g_InputSectionCount = 0;
150
151# Total Size
152my $g_nTotalROSize = 0;
153my $g_nTotalRWZISize = 0;
154my $g_nTotalROMSize = 0;
155
156my %g_RegionGroup; # {GroupName} => [RegionName, ... sorted by Index]
157my %g_RegionMap;
158my $g_scatInfo_ref = undef;
159#****************************************************************************
160# oo >>> Finished
161#****************************************************************************
162return 1;
163
164#****************************************************************************
165# subroutine: LIS_die
166# sample code: (message, __FILE__, __LINE__)
167# input: $error_msg, $file, $line_no
168#****************************************************************************
169sub LIS_die
170{
171 my ($error_msg, $file, $line_no) = (@_);
172 &sysUtil::error_handler($error_msg, $file, $line_no, 'LIS');
173}
174#****************************************************************************
175# subroutine: ParseLIS
176# input: LIS Path string
177# output: x
178#****************************************************************************
179sub ParseLIS
180{
181 ($g_LISPath) = (@_);
182 if(defined $g_LISPath and -e $g_LISPath)
183 {
184 open (FILE_HANDLE, "<$g_LISPath") or &LIS_die("$g_LISPath: file error!", __FILE__, __LINE__);
185 my $strPreExeRegionName = undef;
186 while (<FILE_HANDLE>)
187 {
188 my $strLine = $_;
189 if(/\s+Load Region\s(\w+)\s\(Base:\s(0x\w+)\,\sSize:\s(0x\w+),\sMax:\s(0x\w+),\s(\w+)\)/)
190 {
191 #$1=Region name, $2=nBaseAddress, $3=nActualSize, $4=nMaxSize, $5=strAttribute
192 $g_LoadRegion{++$g_LoadRegionCount}= [$1, hex($2), hex($3), hex($4), $5];
193 #print "Index=$g_LoadRegionCount, LoadRegionName=$1, BaseAddress=$2, MaxSize=$3, ActualSize=$4, Attribute=$5\n";
194 $g_LoadRegionLookUpTable{$1} = $g_LoadRegionCount;
195 $strPreExeRegionName = undef;
196 }
197 elsif (/\s+Execution Region\s(\w+)\s\(Base:\s(0x\w+)\,\sSize:\s(0x\w+),\sMax:\s(0x\w+),\s(\w+)(.*)\)/)
198 {
199 #$1=Region name, $2=nBaseAddress, $3=nActualSize, $4=nMaxSize, $5=strAttribute
200 $g_ExeRegion{++$g_ExeRegionCount}= [$1, hex($2), hex($3), hex($4), $5];
201 #print "Index=$g_ExeRegionCount, ExeRegionName=$1, BaseAddress=$2, Size=$3, ActualSize=$4, Attribute=$5\n";
202 $g_ExeRegionLookUpTable{$1} = $g_ExeRegionCount;
203 # For parsing Input sections
204 $strPreExeRegionName = $1;
205 $g_InputSections{$strPreExeRegionName} = [];
206 }
207 elsif (/=========/)
208 {
209 $strPreExeRegionName = undef;
210 }
211 elsif (/Total RO Size \(Code \+ RO Data\)\s+(\S+)/)
212 {
213 $g_nTotalROSize = $1;
214 }
215 elsif (/Total RW Size \(RW Data \+ ZI Data\)\s+(\S+)/)
216 {
217 $g_nTotalRWZISize = $1;
218 }
219 elsif (/Total ROM Size \(Code \+ RO Data \+ RW Data\)\s+(\S+)/)
220 {
221 $g_nTotalROMSize = $1;
222 }
223 &ParseInputSection($strPreExeRegionName, $strLine) if(defined $strPreExeRegionName);
224 }
225 close FILE_HANDLE;
226 }
227 else
228 {
229 &LIS_die("LIS Path($g_LISPath) doesn't exist", __FILE__, __LINE__);
230 }
231}
232
233sub Parse
234{
235 my ($InputPath) = @_;
236 if($InputPath =~ /lis/)
237 {
238 &ParseLIS($InputPath);
239 }
240 else
241 {
242 &LinkerOutputParser::FileParse($InputPath);
243 # Execution Region
244 my $ExeName_aref = &LinkerOutputParser::ListAllExeRegion();
245 foreach my $item (@$ExeName_aref)
246 {
247 next if($item =~/\./);
248 my $strBaseAddress = LinkerOutputParser::GetExeRegionInfo($item, Region::VMA);
249 my $strActualSize = LinkerOutputParser::GetExeRegionInfo($item, Region::Size);
250
251 #$1=Region name, $2=nBaseAddress, $3=nActualSize, $4=nMaxSize, $5=strAttribute
252 $g_ExeRegion{++$g_ExeRegionCount} = [$item, hex($strBaseAddress), hex($strActualSize), 0xffffffff, undef];
253 $g_ExeRegionLookUpTable{$item} = $g_ExeRegionCount;
254 #print "[$item][$g_ExeRegionCount]: $strBaseAddress, $strActualSize\n";
255 }
256 # Load Region
257 &Workaround_LoadRegion();
258 }
259}
260
261sub Workaround_LoadRegion
262{
263 $g_LoadRegion{1}= ["ROM", $g_ExeRegion{1}->[1], $g_ExeRegion{1}->[2], $g_ExeRegion{1}->[3], $g_ExeRegion{1}->[4]];
264 $g_LoadRegionCount = 1;
265 $g_LoadRegionLookUpTable{ROM} = 1;
266}
267
268#****************************************************************************
269# subroutine: ParseInputSection used by ParseLIS
270# to parse input sections
271# parsing format:
272# Base Addr Size Type Attr Idx E Section Name Object
273# 1. 0x70008230 0x00000020 Code RO 18 * VECTOR_TBL bl_BOOTARM.obj(bootloader.lib)
274# 2. 0x1007bb30 0x00000008 Ven RO 402248 Veneer$$Code anon$$obj.o
275# 3. 0x106f9c72 0x00000002 PAD
276# we don't need Idx(Index) and E(Entry)
277# input: 1. Execution Name, 2. $strLine
278# output: x
279#****************************************************************************
280sub ParseInputSection
281{
282 my ($strExeRegionName, $strLine) = @_;
283 return if(!defined $strExeRegionName);
284
285 my ($strBaseAddress, $strSize, $strType, $strAttr, $strInputSectionAttr, $strObjName, $strLibName)
286 = (undef, undef, undef, undef, undef, undef, undef);
287 my $bMatchInputSection = 0;
288 chomp($strLine);
289 if($strLine =~ /\s+(0x\w+)\s+(0x\w+)\s+(\w+)\s+(\w+)\s+\d+\s+\**\s+(\S+)\s+(\S+)\((\S+)\)/)
290 {
291 # Base Addr Size Type Attr Idx E Section Name Object
292 # 0x70008230 0x00000020 Code RO 18 * VECTOR_TBL bl_BOOTARM.obj(bootloader.lib)
293 $strBaseAddress = $1;
294 $strSize = $2;
295 $strType = $3;
296 $strAttr = $4;
297 $strInputSectionAttr = $5;
298 $strObjName = $6;
299 $strLibName = $7;
300 #print "[Pattern 1]$strLine:\n[Base]$strBaseAddress, [Size]$strSize, [Type]$strType, [Attr]$strAttr, [InputAttr]$strInputSectionAttr, [ObjName]$strObjName, [LibName]$strLibName\n";
301 $bMatchInputSection = 1;
302 }
303 elsif($strLine =~ /\s+(0x\w+)\s+(0x\w+)\s+(\w+)\s+(\w+)\s+\d+\s+\**\s+(\S+)\s+(\S+)/)
304 {
305 # Base Addr Size Type Attr Idx E Section Name Object
306 # 0x1007bb30 0x00000008 Ven RO 402248 Veneer$$Code anon$$obj.o
307 $strBaseAddress = $1;
308 $strSize = $2;
309 $strType = $3;
310 $strAttr = $4;
311 $strInputSectionAttr = $5;
312 $strObjName = $6;
313 #print "[Pattern 2]$strLine:\n[Base]$strBaseAddress, [Size]$strSize, [Type]$strType, [Attr]$strAttr, [InputAttr]$strInputSectionAttr, [ObjName]$strObjName, [LibName]x\n";
314 $bMatchInputSection = 1;
315 }
316 elsif($strLine =~ /\s+(0x\w+)\s+(0x\w+)\s+(\w+)/)
317 {
318 # Base Addr Size Type Attr Idx E Section Name Object
319 # 0x106f9c72 0x00000002 PAD
320 $strBaseAddress = $1;
321 $strSize = $2;
322 $strType = $3;
323 #print "[Pattern 3]$strLine:\n[Base]$strBaseAddress, [Size]$strSize, [Type]$strType\n";
324 $bMatchInputSection = 1;
325 }
326 if($bMatchInputSection == 1)
327 {
328 $g_InputSectionDetails{$g_InputSectionCount} = [$strExeRegionName, $strBaseAddress, $strSize,
329 $strType, $strAttr, $strInputSectionAttr,
330 $strObjName, $strLibName];
331 push (@{$g_InputSections{$strExeRegionName}}, $g_InputSectionCount);
332 $g_InputSectionCount++;
333 }
334}
335#****************************************************************************
336# subroutine: GetInputSectionsByExeRegion
337# input: $strExeRegionName: Execution Name (Case sensitive)
338# output: Array_ref : InputSections: [[ExeRegionName, Base...], [ExeRegionName, Base...], ...]
339# [ExeRegionName, Base...]: InputSectionDetails elements
340#****************************************************************************
341sub GetInputSectionsByExeRegion
342{
343 my ($strExeRegionName) = @_;
344 my @InputSections;
345 my $Indexes = $g_InputSections{$strExeRegionName};
346 foreach my $nIndex (@$Indexes)
347 {
348 push(@InputSections, $g_InputSectionDetails{$nIndex});
349 }
350 return \@InputSections;
351}
352#****************************************************************************
353# subroutine: GetObjTotalSizesByExeRegion
354# input: $strRegionName: Execution Name (Case sensitive)
355# output: ObjTotalSize Hash Reference: {ObjName::LibName} => nSize
356# sample code:
357# my $strExeRegionName = "xxx";
358# my $nObjTotalSize_ref = &LISInfo::GetObjTotalSizesByExeRegion($strExeRegionName);
359# foreach my $Obj_LibName (keys %$nObjTotalSize_ref) {...}
360# => $Obj_LibName: "ObjName::LibName"
361#****************************************************************************
362sub GetObjTotalSizesByExeRegion
363{
364 my ($strExeRegionName) = @_;
365 my $nIndex = 0;
366 my %nObjTotalSize; # {ObjName_LibName} = nSize;
367 my $InputSections_ref = &GetInputSectionsByExeRegion($strExeRegionName);
368 foreach my $Info ( @$InputSections_ref)
369 {
370 if(defined $Info->[InputSection::ObjName])
371 {
372 my $strKey = $Info->[InputSection::ObjName]."::".$Info->[InputSection::LibName];
373 if(exists $nObjTotalSize{$strKey})
374 {
375 $nObjTotalSize{$strKey} += hex($Info->[InputSection::Size]);
376 #print "$strKey = ". $ObjTotalSize{$strKey} ."\n";
377 }
378 else
379 {
380 $nObjTotalSize{$strKey} = hex($Info->[InputSection::Size]);
381 #print "$strKey = ". hex($Info->[InputSection::Size])."\n";
382 }
383 }
384 else #PAD
385 {
386 $nObjTotalSize{"PAD"} += hex($Info->[InputSection::Size]);
387 }
388 }
389 return \%nObjTotalSize;
390}
391
392#****************************************************************************
393# subroutine: GetExeRegionInfo - Get Execution Region information
394# input: $strRegionName: Execution Name (Case sensitive)
395# $bNeedString(optional): 0= return number(int), 1=return string if it's a size
396# output: 1.Region Base address, Used Size, Region MaxSize, Attribute
397#****************************************************************************
398sub GetExeRegionInfo
399{
400 my ($strRegionName, $bNeedString) = (@_);
401 $bNeedString = 0 if(!defined $bNeedString);
402 my ($nBase, $nSize, $nMaxSize, $strAttribute) = (0,0,0,'');
403 my $nIndex = $g_ExeRegionLookUpTable{$strRegionName};
404 if(defined $nIndex)
405 {
406 $nBase = $g_ExeRegion{$nIndex}->[1];
407 $nSize = $g_ExeRegion{$nIndex}->[2];
408 $nMaxSize = $g_ExeRegion{$nIndex}->[3];
409 $strAttribute = $g_ExeRegion{$nIndex}->[4];
410 }
411 return $bNeedString ? (&CommonUtil::Dec2Hex($nBase), &CommonUtil::Dec2Hex($nSize), &CommonUtil::Dec2Hex($nMaxSize), $strAttribute)
412 : ($nBase, $nSize, $nMaxSize, $strAttribute);
413}
414
415#****************************************************************************
416# subroutine: GetLoadRegionInfo - Get Load Region information
417# input: $strRegionName: Load Name (Case sensitive)
418# $bNeedString(optional): 0= return number(int), 1=return string if it's a size
419# output: 1.Region Base address, Used Size, Region MaxSize, Attribute
420#****************************************************************************
421sub GetLoadRegionInfo
422{
423 my ($strRegionName, $bNeedString) = (@_);
424 $bNeedString = 0 if(!defined $bNeedString);
425 my ($nBase, $nSize, $nMaxSize, $strAttribute) = (0,0,0,'');
426 my $nIndex = $g_LoadRegionLookUpTable{$strRegionName};
427 if(defined $nIndex)
428 {
429 $nBase = $g_LoadRegion{$nIndex}->[1];
430 $nSize = $g_LoadRegion{$nIndex}->[2];
431 $nMaxSize = $g_LoadRegion{$nIndex}->[3];
432 $strAttribute = $g_LoadRegion{$nIndex}->[4];
433 }
434 #print "$strRegionName's base=$nBase, ActualSize=$nSize, MaxSize=$nMaxSize, Attribute=$strAttribute\n";
435 return $bNeedString ? (&CommonUtil::Dec2Hex($nBase), &CommonUtil::Dec2Hex($nSize), &CommonUtil::Dec2Hex($nMaxSize), $strAttribute)
436 : ($nBase, $nSize, $nMaxSize, $strAttribute);
437}
438#****************************************************************************
439# should be used with scatInfo.pm
440# subroutine: ClassifyRegionType - For cmmautogen.pl to know Region Type
441# input: Makefile Hash Reference
442# output: x
443#****************************************************************************
444sub ClassifyRegionType
445{
446 my ($MAKEFILE_ref) = @_;
447 require "scatInfo.pm";
448 $g_scatInfo_ref = LIS_new scatInfo(\%g_LoadRegion, $g_LoadRegionCount, \%g_LoadRegionLookUpTable,
449 \%g_ExeRegion, $g_ExeRegionCount, \%g_ExeRegionLookUpTable,
450 \%g_RegionGroup,\%g_RegionMap);
451 $g_scatInfo_ref->ClassifyRegionType($MAKEFILE_ref);
452}
453
454#****************************************************************************
455# should be used with scatInfo.pm
456# subroutine: GetGroupedRegions - Use keyword to get grouped regions after classified by ClassifyRegionType()
457# input: strKeyword
458# output: return Grouped regions
459#****************************************************************************
460sub GetGroupedRegions
461{
462 my ($strKey) = @_;
463 my $array_ref = undef;
464 if($g_scatInfo_ref)
465 {
466 $array_ref = $g_scatInfo_ref->GetGroupedRegions($strKey);
467 }
468 return $array_ref;
469}
470
471#****************************************************************************
472# should be used with scatInfo.pm
473# subroutine: GetDumpExeRegions - Get dump regions for cmmautogen.pl
474# input: Makefile Hash Reference
475# output: Dump regions' reference
476#****************************************************************************
477sub GetDumpExeRegions
478{
479 my ($MAKEFILE_ref) = @_;
480 my $hash_ref = undef;
481 my $order_aref = undef;
482 if($g_scatInfo_ref)
483 {
484 my $bb = &FileInfo::GetChip($MAKEFILE_ref);
485 ($hash_ref, $order_aref) = $g_scatInfo_ref->GetDumpExeRegions($bb);
486 # if VECTOR TABLE and 1stROM Region both start from 0x0,
487 # then delete VECTOR TABLE group
488 my $ROMInfo = $g_scatInfo_ref->GetExeRegionInfo("ROM");
489 if(hex($ROMInfo->[0]) == 0)
490 {
491 delete $hash_ref->{"VECTOR_TABLE"};
492 }
493
494 # FLMM
495 my $KAL_STACK_LAYOUT = $MAKEFILE_ref->{KAL_STACK_LAYOUT};
496 push(@{$hash_ref->{OTHERS}}, ["FLMM_STACKSPACE"]) if(&IsRegionExistent("FLMM_STACKSPACE") and (defined $KAL_STACK_LAYOUT and $KAL_STACK_LAYOUT eq "ISOLATE") );
497 }
498 return $hash_ref;
499}
500
501#****************************************************************************
502# should be used with scatInfo.pm
503# subroutine: GetDumpCodeRegions - Get dump code region names for cmmautogen.pl
504# input: Makefile Hash Reference
505# output: an array reference of Dump code region names
506#****************************************************************************
507sub GetDumpCodeRegions
508{
509 my ($MAKEFILE_ref) = @_;
510 my @DumpCodeRegions;
511 my $DumpRegion_href = &GetDumpExeRegions($MAKEFILE_ref);
512 foreach my $strGroupName (keys %$DumpRegion_href)
513 {
514 next if($strGroupName !~/ROM|INTSRAM/);
515 my $array_ref = $DumpRegion_href->{$strGroupName};
516 foreach my $RegionItem (@$array_ref)
517 {
518 my $RegionName = $RegionItem->[0];
519 next if($strGroupName =~/INTSRAM/i and $RegionName =~ /data/i);
520 push(@DumpCodeRegions, $RegionName);
521 }
522 }
523 return \@DumpCodeRegions;
524}
525
526#****************************************************************************
527# should be used with scatInfo.pm
528# subroutine: IsFixedLengthDumpGroup - Query if the dump region is fixed
529# input: strDumpRegionName
530# output: undef = not fixed, 1= fixed
531#****************************************************************************
532sub IsFixedLengthDumpGroup
533{
534 my ($strKey) = @_;
535 my $bFixed = undef; # undef = not fixed, 1= fixed
536 if($g_scatInfo_ref)
537 {
538 $bFixed = $g_scatInfo_ref->IsFixedLengthDumpGroup($strKey);
539 }
540 return $bFixed;
541}
542#****************************************************************************
543# should be used with scatInfo.pm
544# subroutine: GetDumpRegionBase
545# input: 1. DumpRegionGroup, 2. strDumpRegionName
546# 3. BIN_PATH 4. $platform
547# output: str Base Address
548#****************************************************************************
549sub GetDumpRegionBase
550{
551 my ($strGroupName, $strRegionName, $BIN_PATH, $platform) = @_;
552 my $strBase = "0x0000000";
553 if($strRegionName eq "DUMP_VECTOR_TABLE")
554 {
555 if($g_scatInfo_ref)
556 {
557 my $Info = $g_scatInfo_ref->GetExeRegionInfo($strRegionName);
558 $strBase = $Info->[0];
559 }
560 }
561 else
562 {
563 my ($strSize, $strMaxSize, $strAttribute);
564 ($strBase, $strSize, $strMaxSize, $strAttribute) = &GetExeRegionInfo($strRegionName, 1);
565 if($strGroupName =~ /_PA/i)
566 {
567 if(0 == sysUtil::GetNonCacheablePrefix($platform))
568 {
569 $strBase = &CommonUtil::Dec2Hex(hex($strBase) & 0x0FFFFFFF);
570 }
571 else
572 {
573 $strBase = &CommonUtil::Dec2Hex(hex($strBase) | sysUtil::GetNonCacheablePrefix($platform));
574 }
575 }
576 elsif($strGroupName =~ /_VA/)
577 {
578 if(0 == sysUtil::GetCacheablePrefix($platform))
579 {
580 $strBase = &CommonUtil::Dec2Hex(hex($strBase) & 0x0FFFFFFF);
581 }
582 else
583 {
584 $strBase = &CommonUtil::Dec2Hex(hex($strBase) | sysUtil::GetCacheablePrefix($platform));
585 }
586 }
587 }
588 $strBase = sprintf("0x%08x", hex($strBase));
589 #print "[$strGroupName]$strRegionName: $strBase\n";
590 return $strBase;
591}
592#****************************************************************************
593# should be used with scatInfo.pm
594# subroutine: GetDumpRegionSize
595# input: MemType
596# output: an array contains [$strRegion, $strBase, $strSize] in hex ...
597#****************************************************************************
598sub GetCMMDumpRegionInfo
599{
600 my ($bb, $memtype) = @_;
601 my @CMMDumpRegions;
602 my $core;
603 $core = "CORE0" if($memtype ==MemType::Core0Cached);
604 $core = "CORE1" if($memtype ==MemType::Core1Cached);
605 $core = "CORE2" if($memtype ==MemType::Core2Cached);
606 $core = "CORE3" if($memtype ==MemType::Core3Cached);
607 $core = "CORE" if($memtype ==MemType::CoreUnCached);
608 my $region_aref = LinkerOutputParser::ListAllExeRegion(1);
609 foreach my $strRegionName (@$region_aref)
610 {
611
612 next if(($strRegionName =~/EMIINIT|DUMP_VECTOR_TABLE|SIGNATURE|CORE|[ID]SPRAM[23]|DYNAMIC_SECTION/i) && (($memtype ==MemType::CommonCached) ||($memtype ==MemType::CommonUnCached)));
613 next if(($strRegionName =~/[ID]SPRAM[0-1]/i) && ($strRegionName !~/^[ID]SPRAM[0-1]$/i) && (($memtype ==MemType::CommonCached) ||($memtype ==MemType::CommonUnCached)));
614 next if(($strRegionName =~/L2SRAM/i) && ($strRegionName !~/L2SRAM_L2C_CODE/i) && (($memtype ==MemType::CommonCached) ||($memtype ==MemType::CommonUnCached)));
615 next if(($strRegionName !~/$core/i) && ($memtype >=MemType::CoreUnCached)) ;
616 my $strBase = LinkerOutputParser::GetExeRegionInfo($strRegionName, Region::VMA);
617 my $strSize = 0;
618 if ($strRegionName =~/^[ID]SPRAM[0-1]$|L2SRAM_L2C_CODE/i) {
619 if ($strRegionName =~/^[ID]SPRAM[0-1]$/i) {
620 $strSize = "0x00080000"; #SPRAM size
621 } else {
622 $strSize = "0x00200000"; #L2SRAM size
623 }
624 } else {
625 $strSize = LinkerOutputParser::GetExeRegionInfo($strRegionName, Region::Size);
626 }
627
628 if (($memtype == MemType::CommonUnCached) || ($memtype == MemType::CoreUnCached))
629 {
630 if($strRegionName =~/^CACHED_|DEFAULT_CACHEABLE|bss|^ROM/i)
631 {
632 my $strPABase = sprintf("0x%08x", (hex($strBase) & 0x0FFFFFFF | sysUtil::GetNonCacheablePrefix($bb)));
633 push(@CMMDumpRegions, [$strRegionName."_PA", $strPABase, $strSize]);
634 next;
635 }
636 push(@CMMDumpRegions, [$strRegionName, $strBase, $strSize]);
637 } else {
638 if($strRegionName =~/^CACHED_|DEFAULT_CACHEABLE|bss|^ROM|^AUROM/i)
639 {
640 push(@CMMDumpRegions, [$strRegionName, $strBase, $strSize]);
641 }
642 }
643 }
644 return \@CMMDumpRegions;
645}
646
647#****************************************************************************
648# subroutine: IsRegionExistent
649# to see if this Region exists in Load Regions or Execution Regions
650# input: RegionName
651# output: $bExistent=undef: not existent, 1= existent
652#****************************************************************************
653sub IsRegionExistent
654{
655 my ($strRegionName) = @_;
656 my $bExistent = undef;
657 if(exists $g_LoadRegionLookUpTable{$strRegionName} or exists $g_ExeRegionLookUpTable{$strRegionName})
658 {
659 $bExistent = 1;
660 }
661 return $bExistent;
662}
663
664#****************************************************************************
665# subroutine: SearchExeRegionName
666# to get the first execution region name by keyword searching
667# input: Keyword
668# output: RegionName: undef means it's not existent
669#****************************************************************************
670sub SearchExeRegionName
671{
672 my ($strKey) = @_;
673 my $strRegion = undef;
674 foreach my $strTemp (keys %g_ExeRegionLookUpTable)
675 {
676 if($strTemp =~ /$strKey/)
677 {
678 $strRegion = $strTemp;
679 last;
680 }
681 }
682 return $strRegion;
683}
684
685#****************************************************************************
686# subroutine: CheckROMSize
687# to see if the free ROM is sufficient to put viva_bin
688# input: $Makefile_href : the hash reference of Makefile
689# $viva_bin_size : the size of viva binaray(include all compressed regions and viva region)
690# output: $compRegion_end : the end address of VIVA
691# $check_base : the base address of all bottom to top regions
692# (if there is no bottom to top regions, it will be the base address of files system)
693#****************************************************************************
694sub CheckROMSize
695{
696 my ($Makefile_href, $viva_bin_size) = @_;
697
698 my $bb = &FileInfo::GetChip($Makefile_href);;
699 my $compRegion_end = undef;
700 my $compRegion_start = undef;
701 my $check_base = undef;
702
703 my $nIndex_VIVA = $g_LoadRegionLookUpTable{'VIVA'};
704 $compRegion_start = &sysUtil::query_cs1_addr($bb, $g_LoadRegion{$nIndex_VIVA}->[1], 0);
705 $compRegion_end = $compRegion_start + $viva_bin_size;
706
707 if(defined $g_LoadRegionLookUpTable{'__HIDDEN_SECURE_MAC'})
708 {
709 my $nIndex_HIDDEN_SECURE_MAC = $g_LoadRegionLookUpTable{'__HIDDEN_SECURE_MAC'};
710 $check_base = &sysUtil::query_cs1_addr($bb, $g_LoadRegion{$nIndex_HIDDEN_SECURE_MAC}->[1], 0);
711 }
712 elsif(defined $g_LoadRegionLookUpTable{'BOOT_CERT'})
713 {
714 my $nIndex_BOOT_CERT = $g_LoadRegionLookUpTable{'BOOT_CERT'};
715 $check_base = &sysUtil::query_cs1_addr($bb, $g_LoadRegion{$nIndex_BOOT_CERT}->[1], 0);
716 }
717
718 return ($compRegion_end, $check_base);
719}
720
721#****************************************************************************
722# subroutine: GetScatterReservedSize
723# (this subroutine is used for NOR project & VIVA is enabled)
724# description: Get the estimated total ROM size with provided VIVA size
725# input: $Makefile_href : the hash reference of Makefile
726# $FS_base : the base address of file system
727# output: $nReservedSize : the reserved size of scatter file
728#****************************************************************************
729sub GetScatterReservedSize
730{
731 my ($Makefile_href, $FS_base) = @_;
732 my $viva_base;
733 my $bottom_to_top_base;
734 my $ROM_size = 0;
735 my $nReservedSize = undef;
736 my $nIndex_VIVA = undef;
737
738 my $bb = &FileInfo::GetChip($Makefile_href);;
739
740 my $nIndex_ROM = $g_LoadRegionLookUpTable{'ROM'};
741 $ROM_size = $g_LoadRegion{$nIndex_ROM}->[2];
742
743 $nIndex_VIVA = $g_LoadRegionLookUpTable{'VIVA'};
744 $viva_base = &sysUtil::query_cs1_addr($bb, $g_LoadRegion{$nIndex_VIVA}->[1], 0);
745
746 if((&sysUtil::is_NOR($Makefile_href) != 1) or !defined $nIndex_VIVA)
747 {
748 return ($nReservedSize);
749 }
750
751 if(defined $g_LoadRegionLookUpTable{'__HIDDEN_SECURE_MAC'})
752 {
753 my $nIndex_HIDDEN_SECURE_MAC = $g_LoadRegionLookUpTable{'__HIDDEN_SECURE_MAC'};
754 $bottom_to_top_base = &sysUtil::query_cs1_addr($bb, $g_LoadRegion{$nIndex_HIDDEN_SECURE_MAC}->[1], 0);
755 }
756 elsif(defined $g_LoadRegionLookUpTable{'BOOT_CERT'})
757 {
758 my $nIndex_BOOT_CERT = $g_LoadRegionLookUpTable{'BOOT_CERT'};
759 $bottom_to_top_base = &sysUtil::query_cs1_addr($bb, $g_LoadRegion{$nIndex_BOOT_CERT}->[1], 0);
760 }
761 else
762 {
763 $bottom_to_top_base = $FS_base;
764 }
765
766 $nReservedSize = ($viva_base - $ROM_size) + ($FS_base - $bottom_to_top_base);
767
768 return ($nReservedSize);
769}
770
771#****************************************************************************
772# subroutine: GetTotalROSize - Get total RO size
773# input: $bNeedString: 1=Return string, 0/default/no input=Return int
774# output: $bNeedString=0:nROSize/ $bNeedString=1:strROSize
775#****************************************************************************
776sub GetTotalROSize
777{
778 my ($bNeedString) = @_;
779 return $bNeedString ? &CommonUtil::Dec2Hex($g_nTotalROSize) : $g_nTotalROSize;
780}
781#****************************************************************************
782# subroutine: GetTotalRWZISize - Get total RWZI size
783# input: $bNeedString: 1=Return string, 0/default/no input=Return int
784# output: $bNeedString=0:nRWZISize/ $bNeedString=1:strRWZISize
785#****************************************************************************
786sub GetTotalRWZISize
787{
788 my ($bNeedString) = @_;
789 return $bNeedString ? &CommonUtil::Dec2Hex($g_nTotalRWZISize) : $g_nTotalRWZISize;
790}
791#****************************************************************************
792# subroutine: GetTotalROMSize - Get total ROM size
793# input: $bNeedString: 1=Return string, 0/default/no input=Return int
794# output: $bNeedString=0:nROMSize/ $bNeedString=1:strROMSize
795#****************************************************************************
796sub GetTotalROMSize
797{
798 my ($bNeedString) = @_;
799 return $bNeedString ? &CommonUtil::Dec2Hex($g_nTotalROMSize) : $g_nTotalROMSize;
800}