rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | #!/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 | #* sysInfoProcessLds.pm |
| 40 | #* |
| 41 | #* Project: |
| 42 | #* -------- |
| 43 | #* |
| 44 | #* |
| 45 | #* Description: |
| 46 | #* ------------ |
| 47 | #* This module collects the subroutines for system information. |
| 48 | #* |
| 49 | #* |
| 50 | #* Author: |
| 51 | #* ------- |
| 52 | #* Carl Kao (mtk08237) |
| 53 | #* |
| 54 | #****************************************************************************/ |
| 55 | |
| 56 | BEGIN { push @INC, '../', './tools/', './tools/MemoryUtility/' } |
| 57 | package sysInfoProcLds; |
| 58 | use CommonUtility; |
| 59 | use sysGenUtility; |
| 60 | use FileInfoParser; |
| 61 | use scatInfo; |
| 62 | use ldsInfo; |
| 63 | use List::Util qw(min max); |
| 64 | use strict; |
| 65 | |
| 66 | #**************************************************************************** |
| 67 | # Constants |
| 68 | #**************************************************************************** |
| 69 | my $SYSINFOPROCLDS_VERNO = " LR13_v0.02"; |
| 70 | # LR13_v0.02, 2018/04/13, Added L2CACHE_LOCK area detection in FilterOutRegionInRAM |
| 71 | # LR13_v0.01, 2017/03/29, Modify GetTCMmargin to use physical ISPRAM address |
| 72 | # LR12_v0.03, 2016/03/03, BIN sections filtered out in FilterOutRegionInRAM |
| 73 | # LR12_v0.02, 2016/01/26, Avoid dump sections with name "PHYSICAL_BOUNDARY" (for SPRAM physical name) |
| 74 | # LR12_v0.01 , 2016/01/25, Memory Utility Refinement for LR12 |
| 75 | # u0.01 , 2015/01/14, Memory Utility Refinement for LR11 |
| 76 | # m0.05 , 2013/05/17, Fix GetChipInsideRAMregion() to add _ZI if it's a data region |
| 77 | # m0.04 , 2013/02/14, Support BTCM1 in MOLY |
| 78 | # m0.03 , 2012/08/03, Modify GetTCMmargin() to store TCM physical size |
| 79 | # m0.02 , 2012/08/03, Modify module name and push additional library path |
| 80 | # m0.01 , 2012/07/05, Initial revision |
| 81 | |
| 82 | #**************************************************************************** |
| 83 | # Global variable |
| 84 | #**************************************************************************** |
| 85 | my $g_MAUIlds = undef; |
| 86 | my $g_SavedLDSPath = undef; |
| 87 | my $DebugPrint = 1; |
| 88 | |
| 89 | #**************************************************************************** |
| 90 | # oo >>> Finished |
| 91 | #**************************************************************************** |
| 92 | return 1; |
| 93 | |
| 94 | #**************************************************************************** |
| 95 | # Subroutine: GetChipInsideRAMregion - to query all Chip inside RAM regions |
| 96 | # Parameters: $LDSFILE = the path of lds file |
| 97 | # $INTSRAMregion_href = a Hash reference to store ChipInsideRAM infomation |
| 98 | # $INTSRAMregion_href->{regionName} = [] |
| 99 | # Returns: $nINTSRAMnum = the number of ChipInsideRAM regions |
| 100 | #**************************************************************************** |
| 101 | sub GetChipInsideRAMregion |
| 102 | { |
| 103 | my ($LDSFILE, $INTSRAMregion_href) = (@_); |
| 104 | my $nINTSRAMnum = 0; |
| 105 | my $strINTSRAMName = undef; |
| 106 | |
| 107 | &GetLdsInfo($LDSFILE); |
| 108 | my $ExeRegion_ref = $g_MAUIlds->GetAllExeRegion(); |
| 109 | foreach (@$ExeRegion_ref) |
| 110 | { |
| 111 | if($_ =~ /SPRAM|L2SRAM/) |
| 112 | { |
| 113 | $nINTSRAMnum++; |
| 114 | $INTSRAMregion_href -> {$_} = []; |
| 115 | if(($_ =~ /^DSPRAM/ || $_ =~ /DATA/) && !($_ =~ /DYNAMIC_SECTION/)) |
| 116 | { |
| 117 | $nINTSRAMnum++; |
| 118 | $INTSRAMregion_href -> {$_."_ZI"} = []; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | return ($nINTSRAMnum); |
| 123 | } |
| 124 | |
| 125 | #**************************************************************************** |
| 126 | # Subroutine: GetChipInsideRAMsize - to query ChipInsideRAM size |
| 127 | # Parameters: $LDSFILE = the path of lds file |
| 128 | # $INTSRAMinfo_href = a Hash reference to store ChipInsideRAM infomation |
| 129 | # ($INTSRAMinfo_href -> {ChipInsideRAM type} = MaxSize) |
| 130 | # Returns: $nINTSRAMnum = the number of ChipInsideRAM types |
| 131 | #**************************************************************************** |
| 132 | sub GetChipInsideRAMsize |
| 133 | { |
| 134 | my $strInsideRAMsizePattern = '[D|I].+\d$|L2SRAM|USPRAM'; |
| 135 | my $strSkipPattern = 'IOCU'; |
| 136 | my ($LDSFILE, $INTSRAMinfo_href) = (@_); |
| 137 | my $nINTSRAMnum = 0; |
| 138 | my $strINTSRAMName = undef; |
| 139 | |
| 140 | &GetLdsInfo($LDSFILE); |
| 141 | my $MemoryInfo_ref = $g_MAUIlds->{ldsInfo}->{MEMORYInfo}; |
| 142 | foreach (@$MemoryInfo_ref) |
| 143 | { |
| 144 | my $strMemory = $_->[0]; |
| 145 | my $nMaxSize = hex($_->[2]); |
| 146 | if($strMemory =~ /$strInsideRAMsizePattern/ && $strMemory !~ /$strSkipPattern/) |
| 147 | { |
| 148 | $INTSRAMinfo_href->{$strMemory} = $nMaxSize; |
| 149 | $nINTSRAMnum++ |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return ($nINTSRAMnum); |
| 154 | } |
| 155 | |
| 156 | #**************************************************************************** |
| 157 | # Subroutine: GetTCMmargin - to query TCM margin |
| 158 | # Parameters: $LDSFILE = the path of lds file |
| 159 | # $TCMregion_href = a Hash reference to store TCM infomation |
| 160 | # $TCMregion_href->{'regionName'} = size |
| 161 | # Returns: $hTCMmargin = a Hash reference to store TCM information |
| 162 | # $TCMmargin_href->{ITCM}->[0] = ITCM physical size, $TCMmargin_href->{ITCM}->[1] = ITCM margin |
| 163 | # $TCMmargin_href->{DTCM}->[0] = DTCM physical size, $TCMmargin_href->{DTCM}->[1] = DTCM margin |
| 164 | # $TCMmargin_href->{TCM}->[0] = TCM physical size , $TCMmargin_href->{TCM}->[1] = TCM margin |
| 165 | #**************************************************************************** |
| 166 | sub GetTCMmargin |
| 167 | { |
| 168 | my ($LDSFILE, $TCMregion_href) = (@_); |
| 169 | my %hTCMmargin; |
| 170 | my %INTSRAMinfo; |
| 171 | &GetChipInsideRAMsize($LDSFILE, \%INTSRAMinfo); |
| 172 | |
| 173 | if (1) |
| 174 | { |
| 175 | foreach my $strINTSRAMname (keys %INTSRAMinfo) |
| 176 | { |
| 177 | my $nSPRAMsize = $INTSRAMinfo{$strINTSRAMname}; |
| 178 | my $nSPRAMregionBasAddr=0xFFFFFFFF; |
| 179 | my $nSPRAMregionEndAddr=0; |
| 180 | |
| 181 | foreach my $strINTSRAM (keys %{$TCMregion_href}) |
| 182 | { |
| 183 | next if ($strINTSRAM !~ /$strINTSRAMname/ || $strINTSRAM =~ /PHYSICAL_BOUNDARY/); |
| 184 | |
| 185 | my $nINTSRAMSize = $TCMregion_href->{$strINTSRAM}->[0]; |
| 186 | my $nINTSRAMVMA = $TCMregion_href->{$strINTSRAM}->[1]; |
| 187 | #ISPRAM0 VMA adjustet to physical address to ISPRAM |
| 188 | $nINTSRAMVMA &= 0xfff3ffff if ($strINTSRAMname =~ /ISPRAM0/); |
| 189 | my $nEndAddr = $nINTSRAMSize + $nINTSRAMVMA; |
| 190 | |
| 191 | $nSPRAMregionBasAddr = $nINTSRAMVMA if ($nSPRAMregionBasAddr > $nINTSRAMVMA); |
| 192 | $nSPRAMregionEndAddr = $nEndAddr if ($nEndAddr > $nSPRAMregionEndAddr); |
| 193 | } |
| 194 | # no such outout section, reset base address to 0; |
| 195 | $nSPRAMregionBasAddr = 0 if ($nSPRAMregionBasAddr == 0xFFFFFFFF); |
| 196 | |
| 197 | my $nSPRAMmargin = $nSPRAMsize-($nSPRAMregionEndAddr-$nSPRAMregionBasAddr); |
| 198 | $hTCMmargin{$strINTSRAMname} = [$nSPRAMsize, $nSPRAMmargin]; |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | else #if(0) |
| 203 | { |
| 204 | # abandon to use this way since align will not be calculate in to size... |
| 205 | # e.g. |
| 206 | # 26 L2SRAM_L2C_CODE 00003e98 9fc00000 a0a472ec 00a472ec 2**2 |
| 207 | # 27 DYNAMIC_SECTION_L2SRAM_8_UBIN_W 00000000 9fc03ea0 9fc03ea0 00b1be00 2**0 |
| 208 | # end addr of L2SRAM_L2C_CODE is 0x9FC03E98 != base of DYNAMIC_SECTION_L2SRAM_8_UBIN_W = 0x9FC03EA0 since it needs 32 bytes alignment |
| 209 | |
| 210 | my %hCheckOverlapSection; |
| 211 | my @nISPRAMusedsize; |
| 212 | my @nDSPRAMusedsize; |
| 213 | my $L2SRAMusedsize = 0; |
| 214 | |
| 215 | foreach my $strINTSRAM (keys %{$TCMregion_href}) |
| 216 | { |
| 217 | my $nINTSRAMSize = $TCMregion_href->{$strINTSRAM}->[0]; |
| 218 | my $nINTSRAMVMA = $TCMregion_href->{$strINTSRAM}->[1]; |
| 219 | |
| 220 | # record Dynamic Section Management |
| 221 | if( $strINTSRAM =~ /^DYNAMIC_SECTION/) |
| 222 | { |
| 223 | # next if this section is marked or size is 0 |
| 224 | next if (defined $hCheckOverlapSection{$nINTSRAMVMA}); |
| 225 | next if ($nINTSRAMVMA == 0); |
| 226 | |
| 227 | # mark this overlap section is counting! |
| 228 | $hCheckOverlapSection{$nINTSRAMVMA} = 1; |
| 229 | |
| 230 | # start find max size of overlap sections |
| 231 | my $maxSize = $nINTSRAMSize; |
| 232 | foreach my $strSPRAM_tmp (keys %{$TCMregion_href}) |
| 233 | { |
| 234 | my $nINTSRAMSize_tmp = $TCMregion_href->{$strSPRAM_tmp}->[0]; |
| 235 | my $nINTSRAMVMA_tmp = $TCMregion_href->{$strSPRAM_tmp}->[1]; |
| 236 | |
| 237 | # no overlap section or no overlap |
| 238 | next if( $strSPRAM_tmp !~ /^DYNAMIC_SECTION/ || $nINTSRAMVMA_tmp != $nINTSRAMVMA); |
| 239 | |
| 240 | $maxSize = $nINTSRAMSize_tmp if ($nINTSRAMSize_tmp > $maxSize); |
| 241 | } |
| 242 | |
| 243 | # set section size as max size of overlap sections |
| 244 | $nINTSRAMSize = $maxSize; |
| 245 | } |
| 246 | |
| 247 | # now we process normal and overlap section by same rule |
| 248 | if( $strINTSRAM =~ /(\w)SPRAM(\d)/) |
| 249 | { |
| 250 | my $strIorD = $1; |
| 251 | my $nIdxOfSPRAM = $2; |
| 252 | |
| 253 | sysInfoProcLDS_die("no such case IorD: $strIorD index: $nIdxOfSPRAM", __FILE__, __LINE__) if( $strIorD ne "I" && $strIorD ne "D" ); |
| 254 | |
| 255 | $nISPRAMusedsize[$nIdxOfSPRAM] += $nINTSRAMSize if ($strIorD eq "I"); |
| 256 | $nDSPRAMusedsize[$nIdxOfSPRAM] += $nINTSRAMSize if ($strIorD eq "D"); |
| 257 | } |
| 258 | elsif($strINTSRAM =~ /^L2SRAM/) |
| 259 | { |
| 260 | $L2SRAMusedsize += $nINTSRAMSize; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | |
| 265 | foreach my $strINTSRAMname (keys %INTSRAMinfo) |
| 266 | { |
| 267 | if( $strINTSRAMname =~ /(\w)SPRAM(\d)/) |
| 268 | { |
| 269 | my $strIorD = $1; |
| 270 | my $nIdxOfSPRAM = $2; |
| 271 | |
| 272 | sysInfoProcLDS_die("no such case IorD: $strIorD index: $nIdxOfSPRAM", __FILE__, __LINE__) if( $strIorD ne "I" && $strIorD ne "D" ); |
| 273 | |
| 274 | my $nSPRAMsize = $INTSRAMinfo{$strINTSRAMname}; |
| 275 | my $nSPRAMmargin = $nSPRAMsize - (($strIorD eq "I") ? $nISPRAMusedsize[$nIdxOfSPRAM] : $nDSPRAMusedsize[$nIdxOfSPRAM]); |
| 276 | $hTCMmargin{$strINTSRAMname} = [$nSPRAMsize, $nSPRAMmargin]; |
| 277 | } |
| 278 | elsif($strINTSRAMname =~ /^L2SRAM/) |
| 279 | { |
| 280 | my $L2SRAMsize = $INTSRAMinfo{$strINTSRAMname}; |
| 281 | my $L2SRAMMmargin = $L2SRAMsize - $L2SRAMusedsize; |
| 282 | $hTCMmargin{'L2SRAM'} = [$L2SRAMsize, $L2SRAMMmargin]; |
| 283 | } |
| 284 | } |
| 285 | } # end of if(0) |
| 286 | return (\%hTCMmargin); |
| 287 | } |
| 288 | |
| 289 | #**************************************************************************** |
| 290 | # Subroutine: GetphysicalRAMsize - to query physical RAM size |
| 291 | # Parameters: $BB_PATH = the path of BB folder |
| 292 | # Returns: $nRAMsize = the physical RAM size |
| 293 | #**************************************************************************** |
| 294 | sub GetphysicalRAMsize |
| 295 | { |
| 296 | my ($BB_PATH) = (@_); |
| 297 | my $CUSTOM_EMI_RELEASE_H = $BB_PATH . '/' . "custom_EMI_release.h"; |
| 298 | my $nRAMsize = 0; |
| 299 | |
| 300 | open (EMIRELEASEH_HANDLE, "<$CUSTOM_EMI_RELEASE_H") or &sysInfoProcLDS_die("$CUSTOM_EMI_RELEASE_H: file error!", __FILE__, __LINE__); |
| 301 | while (<EMIRELEASEH_HANDLE>) { |
| 302 | if (/^#define EMI_EXTSRAM_SIZE\s+\(\s*\(*\s*\(*\s*(\S+)\)*\s*<<\s*20\s*\)*\s*>>\s*3\s*\)/) |
| 303 | { |
| 304 | $nRAMsize = $1 * 1024 * 1024 / 8; |
| 305 | } |
| 306 | } |
| 307 | close (EMIRELEASEH_HANDLE); |
| 308 | return $nRAMsize; |
| 309 | } |
| 310 | |
| 311 | #**************************************************************************** |
| 312 | # Subroutine: GetAvailableRAMsize - to query available RAM size |
| 313 | # Parameters: $BB_PATH = the path of BB folder |
| 314 | # Returns: $nRAMsize = the available RAM size |
| 315 | #**************************************************************************** |
| 316 | sub GetAvailableRAMsize |
| 317 | { |
| 318 | my ($BB_PATH) = (@_); |
| 319 | my $nRAMsize = undef; |
| 320 | my $CUSTOM_FEATURECONFIG_H = $BB_PATH . '/' . "custom_FeatureConfig.h"; |
| 321 | my $CUSTOM_EMI_RELEASE_H = $BB_PATH . '/' . "custom_EMI_release.h"; |
| 322 | my $bsetLimit = 0; |
| 323 | my $isNOR = (&FileInfo::is_NOR() and !FileInfo::is_SmartPhone()) ? 1 : 0; |
| 324 | |
| 325 | open (FEATURECONFIGH_HANDLE, "<$CUSTOM_FEATURECONFIG_H") or &sysInfoProcLDS_die("$CUSTOM_FEATURECONFIG_H: file error!", __FILE__, __LINE__); |
| 326 | while (<FEATURECONFIGH_HANDLE>) { |
| 327 | if (/^#define PROJECT_EXPECTED_RAM_LIMIT\s*(\w*)/ && $isNOR) |
| 328 | { |
| 329 | $nRAMsize = hex($1); |
| 330 | $bsetLimit = 1; |
| 331 | } |
| 332 | elsif (/^#define PROJECT_EXPECTED_RAM_LIMIT_NFB\s*(\w*)/) |
| 333 | { |
| 334 | $nRAMsize = hex($1); |
| 335 | $bsetLimit = 1; |
| 336 | } |
| 337 | } |
| 338 | close (FEATURECONFIGH_HANDLE); |
| 339 | |
| 340 | if($bsetLimit == 0) |
| 341 | { |
| 342 | open (EMIRELEASEH_HANDLE, "<$CUSTOM_EMI_RELEASE_H") or &sysInfoProcLDS_die("$CUSTOM_EMI_RELEASE_H: file error!", __FILE__, __LINE__); |
| 343 | while (<EMIRELEASEH_HANDLE>) { |
| 344 | if (/^#define EMI_EXTSRAM_SIZE\s+\(\s*\(*\s*\(*\s*(\S+)\)*\s*<<\s*20\s*\)*\s*>>\s*3\s*\)/) |
| 345 | { |
| 346 | $nRAMsize = $1 * 1024 * 1024 / 8; |
| 347 | } |
| 348 | } |
| 349 | close (EMIRELEASEH_HANDLE); |
| 350 | } |
| 351 | return $nRAMsize; |
| 352 | } |
| 353 | |
| 354 | #**************************************************************************** |
| 355 | # Subroutine: GetRAMregion - to query all regions placed in RAM |
| 356 | # Parameters: $BB_PATH |
| 357 | # $LDSFILE = the path of lds file |
| 358 | # $RAMregion_href = a Array reference to store RAM regions |
| 359 | # $RAMregion_href->{regionName} = [] |
| 360 | # $MAKEFILE_ref = a Hash to contain MAKEFILE information |
| 361 | # Returns: $nRAMnum = the number of RAM regions |
| 362 | #**************************************************************************** |
| 363 | sub GetRAMregion |
| 364 | { |
| 365 | my ($BB_path, $LDSFILE, $RAMregion_aref, $MAKEFILE_ref) = (@_); |
| 366 | &GetLdsInfo($LDSFILE); |
| 367 | my $allERs_aref = $g_MAUIlds->GetAllExeRegion(); |
| 368 | FilterOutRegionInRAM($allERs_aref, $RAMregion_aref); |
| 369 | my $nRAMnum = scalar(@$RAMregion_aref); |
| 370 | return $nRAMnum; |
| 371 | } |
| 372 | |
| 373 | |
| 374 | sub FilterOutRegionInRAM |
| 375 | { |
| 376 | my ($ERs_aref, $ERsInRAM_aref) = @_; |
| 377 | foreach my $ER (@$ERs_aref) |
| 378 | { |
| 379 | if($ER =~ /EXTSRAM|BOOT_CERT|.bss|PAGE_TABLE/i and $ER !~ /INTSRAM|BIN|L2CACHE_LOCK|CODE/i) |
| 380 | { |
| 381 | push(@$ERsInRAM_aref, $ER); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | sub FilterOutFixedRegion |
| 387 | { |
| 388 | sysInfoProcLDS_die("not support FilterOutFixedRegion", __FILE__, __LINE__); |
| 389 | |
| 390 | my ($ERs_aref, $ERsInRAM_aref) = @_; |
| 391 | foreach my $ER (@$ERs_aref) |
| 392 | { |
| 393 | ####################### |
| 394 | # FIX_ME: what is fixed region below 1 line |
| 395 | ####################### |
| 396 | if($ER =~ /TX|RX|FS|TMP_PAGE_TABLE|DSP|BOOT_CERT/i) |
| 397 | { |
| 398 | push(@$ERsInRAM_aref, $ER); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | sub GetRegionInfoFromLDS |
| 404 | { |
| 405 | my ($strRegionName, $nOption, $LDSFILE) = (@_); |
| 406 | &GetLdsInfo($LDSFILE); |
| 407 | return $g_MAUIlds->GetRegionInfo($strRegionName, $nOption); |
| 408 | } |
| 409 | |
| 410 | sub GetMemoryInfoFromLDS |
| 411 | { |
| 412 | #$nOption: 0=Name, 1=Base, 2=Length |
| 413 | my ($strRegionName, $nOption, $LDSFILE) = (@_); |
| 414 | my $strInfo = undef; |
| 415 | if($nOption < 3 or $nOption > 0) |
| 416 | { |
| 417 | &GetLdsInfo($LDSFILE); |
| 418 | my $MemoryInfo_aref = $g_MAUIlds->{ldsInfo}->{MEMORYInfo}; |
| 419 | |
| 420 | foreach my $aref (@$MemoryInfo_aref) |
| 421 | { |
| 422 | if($strRegionName eq $aref->[0]) |
| 423 | { |
| 424 | $strInfo = $aref->[$nOption]; |
| 425 | last; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | return $strInfo; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | #**************************************************************************** |
| 434 | # Subroutine: GetRAMBoundaryregion - to query the boundary regions in RAM |
| 435 | # this function can be used to calculate RAM margin |
| 436 | # Parameters: $LDSFILE = the path of lds file |
| 437 | # $MAKEFILE_ref = a Hash to contain MAKEFILE information |
| 438 | # Returns: $LAST_CACHED_REGION = the last cached region in RAM |
| 439 | # $DUMMY_END = the dummy_end region in RAM |
| 440 | #**************************************************************************** |
| 441 | sub GetRAMBoundaryregion |
| 442 | { |
| 443 | my ($LDSFILE, $MAKEFILE_ref) = (@_); |
| 444 | my $bb = $MAKEFILE_ref->{"platform"}; |
| 445 | my $DUMMY_END = undef; |
| 446 | my $LAST_CACHED_REGION = undef; |
| 447 | |
| 448 | &GetLdsInfo($LDSFILE); |
| 449 | |
| 450 | $DUMMY_END= &Gen_RegionName_EV_DUMMY_END_Base($bb); |
| 451 | $LAST_CACHED_REGION = &Gen_RegionName_EV_LAST_CACHED_REGION($bb); |
| 452 | |
| 453 | return ($LAST_CACHED_REGION, $DUMMY_END); |
| 454 | } |
| 455 | |
| 456 | #**************************************************************************** |
| 457 | # Subroutine: GetphysicalROMsize - to query physical ROM size |
| 458 | # Parameters: $BB_PATH = the path of BB folder |
| 459 | # $MAKEFILE_ref = a Hash to contain MAKEFILE information |
| 460 | # Returns: $nROMsize = the physical ROM size |
| 461 | #**************************************************************************** |
| 462 | sub GetphysicalROMsize |
| 463 | { |
| 464 | my ($BB_PATH) = (@_); |
| 465 | my $nROMsize = undef; |
| 466 | my $CUSTOM_FLASH_H = $BB_PATH . '/' . "custom_flash.h"; |
| 467 | my $FLASH_OPT_GEN_H = $BB_PATH . '/' . "flash_opt_gen.h"; |
| 468 | my $isNOR = (&FileInfo::is_NOR() and !FileInfo::is_SmartPhone()) ? 1 : 0; |
| 469 | |
| 470 | if($isNOR) |
| 471 | { |
| 472 | open (FLASHH_HANDLE, "<$CUSTOM_FLASH_H") or &sysInfoProcLDS_die("$CUSTOM_FLASH_H: file error!", __FILE__, __LINE__); |
| 473 | while (<FLASHH_HANDLE>) { |
| 474 | if (/^\s*\*\s+NOR_FLASH_SIZE\(Mb\):\s*(\w*)/) |
| 475 | { |
| 476 | $nROMsize = $1 * 1024 * 1024 / 8; |
| 477 | } |
| 478 | } |
| 479 | close (FLASHH_HANDLE); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | open (FLASHOPTGENH_HANDLE, "<$FLASH_OPT_GEN_H") or &sysInfoProcLDS_die("$FLASH_OPT_GEN_H: file error!", __FILE__, __LINE__); |
| 484 | while (<FLASHOPTGENH_HANDLE>) { |
| 485 | if (/^#define NAND_TOTAL_SIZE\s*(\w*)/) |
| 486 | { |
| 487 | $nROMsize = $1 * 1024 * 1024; |
| 488 | } |
| 489 | } |
| 490 | close (FLASHOPTGENH_HANDLE); |
| 491 | } |
| 492 | return $nROMsize; |
| 493 | } |
| 494 | |
| 495 | #**************************************************************************** |
| 496 | # Subroutine: GetAvailableROMsize - to query available ROM size |
| 497 | # Parameters: $BB_PATH = the path of BB folder |
| 498 | # $MAKEFILE_ref = a Hash to contain MAKEFILE information |
| 499 | # Returns: $nROMsize = the available ROM size |
| 500 | #**************************************************************************** |
| 501 | sub GetAvailableROMsize |
| 502 | { |
| 503 | my ($BB_PATH) = (@_); |
| 504 | my $nROMsize = 0; |
| 505 | my $CUSTOM_FEATURECONFIG_H = $BB_PATH . '/' . "custom_FeatureConfig.h"; |
| 506 | my $CUSTOM_MEMORYDEVICE_H = $BB_PATH . '/' . "custom_MemoryDevice.h"; |
| 507 | my $CUSTOM_FALSH_H = $BB_PATH . '/' . "custom_flash.h"; |
| 508 | my $isNOR = (&FileInfo::is_NOR() and !FileInfo::is_SmartPhone()) ? 1 : 0; |
| 509 | |
| 510 | #code/data can not be executed in NAND flash |
| 511 | return $nROMsize if(!$isNOR); |
| 512 | |
| 513 | my %FEATURE_CONFIG_Value; |
| 514 | my %MEM_DEV_H_Value; |
| 515 | &ParseDefinition($CUSTOM_FEATURECONFIG_H, \%FEATURE_CONFIG_Value); |
| 516 | &ParseDefinition($CUSTOM_MEMORYDEVICE_H, \%MEM_DEV_H_Value); |
| 517 | |
| 518 | if (exists $FEATURE_CONFIG_Value{'PROJECT_EXPECTED_CODE_LIMIT'}) |
| 519 | { |
| 520 | $nROMsize = hex($FEATURE_CONFIG_Value{'PROJECT_EXPECTED_CODE_LIMIT'});; |
| 521 | } |
| 522 | elsif (exists $MEM_DEV_H_Value{'NOR_BOOTING_NOR_FS_BASE_ADDRESS'}) |
| 523 | { |
| 524 | $nROMsize = hex($MEM_DEV_H_Value{'NOR_BOOTING_NOR_FS_BASE_ADDRESS'}); |
| 525 | } |
| 526 | else |
| 527 | { |
| 528 | my $flash_size = 0; |
| 529 | my $sum_of_regions = 0; |
| 530 | my $bisNORFDM5 = 0; |
| 531 | my %FLASH_H_Value; |
| 532 | my (@FLASH_H_Value_BLK_LIST, @FLASH_H_Value_REGION_LIST, @FLASH_H_Value_BANK_LIST); |
| 533 | &ParseFlashInfo($CUSTOM_FALSH_H, \%FLASH_H_Value, \@FLASH_H_Value_BLK_LIST, |
| 534 | \@FLASH_H_Value_REGION_LIST, |
| 535 | \@FLASH_H_Value_BANK_LIST); |
| 536 | $flash_size = hex($FLASH_H_Value{'NOR_FLASH_DENSITY'}); |
| 537 | $bisNORFDM5 = ((defined $MEM_DEV_H_Value{'__NOR_FDM5__'}) && ($MEM_DEV_H_Value{'__NOR_FDM5__'} eq 'TRUE')) ? 1 : 0; |
| 538 | $sum_of_regions = &Comp_lastBANKsize(\@FLASH_H_Value_REGION_LIST, \@FLASH_H_Value_BLK_LIST, $flash_size, $bisNORFDM5); |
| 539 | $nROMsize = $flash_size - $sum_of_regions; |
| 540 | } |
| 541 | return $nROMsize; |
| 542 | } |
| 543 | |
| 544 | #**************************************************************************** |
| 545 | # Subroutine: GetROMregion - to query all regions placed in ROM |
| 546 | # Parameters: $BB_PATH |
| 547 | # $LDSFILE = the path of lds file |
| 548 | # $ROMregion_aref = a Array reference to store ROM regions |
| 549 | # $MAKEFILE_ref = a Hash to contain MAKEFILE information |
| 550 | # Returns: N/A |
| 551 | #**************************************************************************** |
| 552 | sub GetROMregion |
| 553 | { |
| 554 | my ($BB_path, $LDSFILE, $ROMregion_aref, $MAKEFILE_ref) = @_; |
| 555 | |
| 556 | } |
| 557 | |
| 558 | #**************************************************************************** |
| 559 | # Subroutine: Gen_RegionName_EV_DUMMY_END_Base - to query DUMMY_END region |
| 560 | # Parameters: $bb = bb chip |
| 561 | # Returns: $strRegionName = region name |
| 562 | #**************************************************************************** |
| 563 | sub Gen_RegionName_EV_DUMMY_END_Base |
| 564 | { |
| 565 | my ($bb) = (@_); |
| 566 | my $strRegionName; |
| 567 | $strRegionName = "CACHED_DUMMY_END"; |
| 568 | $strRegionName = $g_MAUIlds->SearchExeRegionName("DUMMY_END") if(! $g_MAUIlds->IsRegionExistent($strRegionName)); |
| 569 | return $strRegionName; |
| 570 | } |
| 571 | |
| 572 | #**************************************************************************** |
| 573 | # Subroutine: Gen_RegionName_EV_LAST_CACHED_REGION - to query the last cached region |
| 574 | # before dummy end |
| 575 | # Parameters: $bb = bb chip |
| 576 | # Returns: $strPreviousRegionName = region name |
| 577 | #**************************************************************************** |
| 578 | sub Gen_RegionName_EV_LAST_CACHED_REGION |
| 579 | { |
| 580 | my ($bb) = (@_); |
| 581 | #wrong |
| 582 | my $strPreviousRegionName; |
| 583 | my $strRegionName = &Gen_RegionName_EV_DUMMY_END_Base($bb); |
| 584 | $strPreviousRegionName = $g_MAUIlds->GetPreviousExeRegionName($strRegionName) if(defined $strRegionName); |
| 585 | &sysInfoProcScat_die("Region Name can't be empty!", __FILE__, __LINE__) if(!defined $strPreviousRegionName); |
| 586 | return $strPreviousRegionName; |
| 587 | } |
| 588 | |
| 589 | #**************************************************************************** |
| 590 | # Subroutine: ParseFlashInfo - parse key definition in CUSTOM_FLASH_H |
| 591 | # Parameters: $strFilePath |
| 592 | # $Hash_refResult Container) = a Hash reference to store the parse result |
| 593 | # $BLK_LIST_aref = an Array reference to store Block info |
| 594 | # $REGION_LIST_aref = an Array reference to store Region info |
| 595 | # $BANK_LIST_aref = an Array reference to store Bank info |
| 596 | #**************************************************************************** |
| 597 | sub ParseFlashInfo |
| 598 | { |
| 599 | my ($strFilePath, $Hash_ref, $BLK_LIST_aref, $REGION_LIST_aref, $BANK_LIST_aref) = @_; |
| 600 | open (FLASHC_HANDLE, "<$strFilePath") or &sysInfoProcLDS_die("$strFilePath: file error!", __FILE__, __LINE__); |
| 601 | while (<FLASHC_HANDLE>) { |
| 602 | if (/^FLASH_REGIONINFO_VAR_MODIFIER\s+FlashBlockTBL\s+\S+/) |
| 603 | { |
| 604 | $Hash_ref->{'BlockTBLFlag'} ++; |
| 605 | } |
| 606 | elsif (defined $Hash_ref->{'BlockTBLFlag'}) |
| 607 | { |
| 608 | $Hash_ref->{'BlockTBLTxt'} .= $_; |
| 609 | # debug purpose |
| 610 | # print $_; |
| 611 | if (/\{\s*(\S+)\s*,\s*(\S+)\s*\}/) |
| 612 | { |
| 613 | push @$BLK_LIST_aref, $_; |
| 614 | } |
| 615 | delete $Hash_ref->{'BlockTBLFlag'} if (/^\s+EndBlockInfo\s+/); |
| 616 | } |
| 617 | elsif (/^FLASH_REGIONINFO_VAR_MODIFIER\s+FlashRegionInfo\s+oriRegionInfo\S+/) |
| 618 | { |
| 619 | $Hash_ref->{'RegionInfoFlag'} ++; |
| 620 | } |
| 621 | elsif (defined $Hash_ref->{'RegionInfoFlag'}) |
| 622 | { |
| 623 | $Hash_ref->{'RegionInfoTxt'} .= $_; |
| 624 | if (/\{\s*(\S+)\s*,\s*(\S+)\s*\}/) |
| 625 | { |
| 626 | push @$REGION_LIST_aref, $_; |
| 627 | } |
| 628 | delete $Hash_ref->{'RegionInfoFlag'} if (/^\s+EndoriRegionInfo\s+/); |
| 629 | } |
| 630 | elsif (/^static\s+NORBankInfo\s+oriBankInfo\S+/) |
| 631 | { |
| 632 | $Hash_ref->{'BankInfoFlag'} ++; |
| 633 | } |
| 634 | elsif (defined $Hash_ref->{'BankInfoFlag'}) |
| 635 | { |
| 636 | $Hash_ref->{'BankInfoTxt'} .= $_; |
| 637 | if (/\{\s*(\S+)\s*,\s*(\S+)\s*\}/) |
| 638 | { |
| 639 | push @$BANK_LIST_aref, $_; |
| 640 | } |
| 641 | delete $Hash_ref->{'BankInfoFlag'} if (/^\s+EndBankInfo\s+/); |
| 642 | } |
| 643 | elsif (/^\s*\*\s+NOR_FLASH_DENSITY:\s*(\w*)/) |
| 644 | { |
| 645 | $Hash_ref->{'NOR_FLASH_DENSITY'} = $1; |
| 646 | } |
| 647 | elsif (/^\s*\*\s+NOR_FLASH_SIZE\(Mb\):\s*(\w*)/) |
| 648 | { |
| 649 | $Hash_ref->{'NOR_FLASH_SIZE(Mb)'} = $1; |
| 650 | } |
| 651 | } |
| 652 | close (FLASHC_HANDLE); |
| 653 | } |
| 654 | |
| 655 | #**************************************************************************** |
| 656 | # Subroutine: ParseDefinition - parse key definition in the input file |
| 657 | # Parameters: $strFilePath |
| 658 | # $Hash_refResult Container) = a Hash reference to store the parse result |
| 659 | #**************************************************************************** |
| 660 | sub ParseDefinition |
| 661 | { |
| 662 | my ($strFilePath, $Hash_ref) = @_; |
| 663 | open (MEMDEVH_HANDLE, "<$strFilePath") or &sysInfoProcLDS_die("$strFilePath: file error!", __FILE__, __LINE__); |
| 664 | while (<MEMDEVH_HANDLE>) { |
| 665 | if (/^#define\s+(\w+)\s+\((\w*)\)/ || /^#define\s+(\w+)\s+(\w*)/) |
| 666 | { |
| 667 | my $option = $1; |
| 668 | my $value = $2; |
| 669 | |
| 670 | &sysInfoProcLDS_die("$strFilePath: $option redefined in custom_MemoryDevice.h!", __FILE__, __LINE__) if defined($Hash_ref->{$option}); |
| 671 | if (!defined $value) |
| 672 | { |
| 673 | $Hash_ref->{$option} = 'TRUE'; |
| 674 | } |
| 675 | else |
| 676 | { |
| 677 | $Hash_ref->{$option} = $value; |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | close (MEMDEVH_HANDLE); |
| 682 | } |
| 683 | |
| 684 | #**************************************************************************** |
| 685 | # Subroutine: ParseFlashInfo - parse key definition in CUSTOM_FLASH_H |
| 686 | # Parameters: $regions_aref = an Array reference to store Region info |
| 687 | # $blk_aref = an Array reference to store Block info |
| 688 | # $flash_size = Total flash size |
| 689 | # $bisFDM5 = check if __NOR_FDM5__ |
| 690 | # Returns : $fat_space = the size of FAT |
| 691 | #**************************************************************************** |
| 692 | sub Comp_lastBANKsize |
| 693 | { |
| 694 | my ($regions_aref, $blk_aref, $flash_size , $bisFDM5) = (@_); |
| 695 | my @regions = @$regions_aref; |
| 696 | my @blocks = @$blk_aref; |
| 697 | my $small_block_start = $flash_size; |
| 698 | my $sum_of_regions = 0; |
| 699 | my $fat_space = 0; |
| 700 | |
| 701 | for (0..$#regions) |
| 702 | { |
| 703 | if ($regions[$_] =~ /\{(0x\w+),\s*(\d+)\}/) # match {0x20000, 7} |
| 704 | { |
| 705 | $sum_of_regions += hex($1) * $2; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | if (($#regions>=0) && $bisFDM5) |
| 710 | { |
| 711 | if ($blocks[$#blocks] =~ /\{(0x\w+),\s*(0x\w+)\}/) # match {0xFF0000,0x2000} |
| 712 | { |
| 713 | $small_block_start = hex($1); |
| 714 | } |
| 715 | $fat_space = $sum_of_regions - ($flash_size-$small_block_start); |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | $fat_space = $sum_of_regions; |
| 720 | } |
| 721 | return $fat_space; |
| 722 | } |
| 723 | |
| 724 | #**************************************************************************** |
| 725 | # Subroutine: GetLdsInfo - to query Lds info by LdsInfo.pm |
| 726 | # Parameters: $LDSFILE = lds file |
| 727 | #**************************************************************************** |
| 728 | sub GetLdsInfo |
| 729 | { |
| 730 | my ($LDSFILE) = (@_); |
| 731 | if(!defined $g_MAUIlds or $g_SavedLDSPath ne $LDSFILE) |
| 732 | { |
| 733 | $g_MAUIlds = lds_new scatInfo($LDSFILE, "AUROM"); |
| 734 | $g_SavedLDSPath = $LDSFILE; |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | #**************************************************************************** |
| 739 | # subroutine: sysInfoProcLDS_die |
| 740 | # sample code: (message, __FILE__, __LINE__) |
| 741 | # parameters: $error_msg, $file, $line_no |
| 742 | #**************************************************************************** |
| 743 | sub sysInfoProcLDS_die |
| 744 | { |
| 745 | my ($error_msg, $file, $line_no) = (@_); |
| 746 | &CommonUtil::error_handler($error_msg, $file, $line_no, 'SYSINFOPROCESSLDS'); |
| 747 | } |