blob: 065d6f35e1822ba91a63f45cd64e7e85852ae8f4 [file] [log] [blame]
#!/usr/bin/perl
#
# Copyright Statement:
# --------------------
# This software is protected by Copyright and the information contained
# herein is confidential. The software may not be copied and the information
# contained herein may not be used or disclosed except with the written
# permission of MediaTek Inc. (C) 2006
#
# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
#
# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
#
# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
#
#*****************************************************************************
#*
#* Filename:
#* ---------
#* BasicInfoQuery.pm
#*
#* Project:
#* --------
#*
#*
#* Description:
#* ------------
#* This perl module is used to get system basic information
#*
#*
#* Author:
#* -------
#* Carl Kao (mtk08237)
#*
#****************************************************************************/
BEGIN { push @INC, '../', './tools/', './tools/MemoryUtility/' } # add additional library path
use strict;
use POSIX qw(floor ceil);
use systemInfo;
use LinkerOutputParser;
use FileInfoParser;
use CommonUtility;
package FILEOPTION;
use constant LIS => 1;
use constant MAP => 2;
use constant SYM => 3;
use constant MAKEFILE => 4;
use constant INFOMAKE => 5;
package BasicMemInfo;
#****************************************************************************
# Constants
#****************************************************************************
my $VERNO = " v0.01";
# v0.01 , 2018/10/17, Updated CMD_GetRAMUsage for 512MB memory
# e0.01 , 2018/08/06, Updated CMD_GetRAMUsage
# a0.06 , 2018/05/14, Limited memory padding count to 8 in CMD_GetRAMUsage
# a0.05 , 2017/11/28, Provide DRDI usage info in CMD_GetRAMUsage
# a0.04 , 2017/07/04, Fixed CMD_GetRAMUsage when calculating overlay section size
# a0.03 , 2017/07/04, Refactored CMD_GetRAMUsage due DRDI
# a0.02 , 2017/01/28, Fixed CMD_GetRAMUsage when using 64KB MPU granularity
# a0.01 , 2017/01/24, Fixed GetTotalRAMUsageFromLDS function
# u0.06 , 2016/11/02, Sort execution regions with start address in GetERsInRAM
# u0.05 , 2016/09/07, RAM margin info modified to CMD_GetRAMUsage
# u0.04 , 2016/09/06, Free RAM and RAM margin info modified to CMD_GetRAMUsage
# u0.03 , 2016/03/03, Memory Utility Refinement (Add shared region info to CMD_GetRAMUsage)
# u0.02 , 2015/01/20, Memory Utility Refinement (Add shared region info to CMD_GetRAMUsage)
# u0.01 , 2015/01/14, Memory Utility Refinement
# m0.06 , 2014/02/20, Correct GetTotalRAMUsageFromLDS's base address
# m0.05 , 2013/12/25, Fix LoadView which can't count in .bss
# m0.04 , 2013/10/20, Support Secure region
# m0.03 , 2013/06/25, Support CMD_GetROMSize() for filtering out COPRO section
# m0.02 , 2013/03/21, Support GetMBAlignment()
# m0.01 , 2013/01/08, Initial revision
#****************************************************************************
# Global variable
#****************************************************************************
my $g_bParseSYM = 0;
my $g_bParseMAP = 0;
my $g_bParseMAKEFILE = 0;
my %g_MAKEFILE_OPTIONS;
#****************************************************************************
# Subroutine: BasicInfoQuery_verno - to query this package's version number
# Parameters: x
# Returns: version number string
#****************************************************************************
sub BasicInfoQuery_verno
{
return $VERNO;
}
#****************************************************************************
# oo >>> Finished
#****************************************************************************
return 1;
sub DispatchCommand
{
my ($cmd, $MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
# force the Parse to be called in DispatchCommand in order to make sure the only entry function of this file is DispatchCommand
sub Parse
{
my ($nOption, $PATH) = @_;
if($nOption == FILEOPTION::MAP and !$g_bParseMAP)
{
basicinfo_die("$PATH doesn't exist!") if(!-e $PATH);
&LinkerOutputParser::FileParse($PATH);
$g_bParseMAP = 1;
}
elsif($nOption == FILEOPTION::SYM and !$g_bParseSYM)
{
basicinfo_die("$PATH doesn't exist!") if(!-e $PATH);
&LinkerOutputParser::FileParse($PATH);
$g_bParseSYM = 1;
}
elsif($nOption == FILEOPTION::MAKEFILE and !$g_bParseMAKEFILE)
{
basicinfo_die("$PATH doesn't exist!") if(!-e $PATH);
&FileInfo::Parse_MAKEFILE($PATH, \%g_MAKEFILE_OPTIONS);
$g_bParseMAKEFILE = 1;
}
}
Parse(FILEOPTION::SYM, $SYM_PATH);
Parse(FILEOPTION::MAKEFILE, $MAKEFILE_PATH, \%g_MAKEFILE_OPTIONS);
$cmd = "help" if($cmd eq "-h" or $cmd eq "--help");
my ($pack_name, $file, $line_no) = caller;
no strict 'refs';
&{$cmd}($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) if (exists &{$cmd})
or basicinfo_die("$cmd() doesn't exists!", $file, $line_no);
}
# It HAS L1core and Secure region !
sub CMD_GetLoadViewSize
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $ERs_aref = &LinkerOutputParser::ListAllExeRegion(1);
my $strLastRegion;
my $nLoadViewSize;
for (my $i = $#{$ERs_aref};$i >= 0; $i--)
{
$strLastRegion = $ERs_aref->[$i];
$nLoadViewSize = hex(&LinkerOutputParser::GetExeRegionInfo($strLastRegion, Region::LMA));
last if (LinkerOutputParser::GetExeRegionInfo($strLastRegion, Region::Attr) =~ /LOAD/);
}
my $strUROM_Base = sysInfo::GetMemoryInfo("UROM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
my $strROM_Length = sysInfo::GetMemoryInfo("ROM", 2, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
PrintLog($PrintFunc, "Load Information:\n");
PrintLog($PrintFunc, "ROM Base Address in LDS = $strUROM_Base\n");
PrintLog($PrintFunc, "ROM Length in LDS = $strROM_Length\n");
PrintLog($PrintFunc, "Last Region in load = $strLastRegion\n");
if($strLastRegion !~/zi|bss/i)
{
my $nLastRegionSize = hex(&LinkerOutputParser::GetExeRegionInfo($strLastRegion, Region::Size));
PrintLog($PrintFunc, "Last Region Size in Load = ". CommonUtil::Dec2Hex($nLastRegionSize) . " = $nLastRegionSize(Bytes) \n");
$nLoadViewSize += $nLastRegionSize;
}
else
{
PrintLog($PrintFunc, "Last Region Size in load = 0 (Bytes) \n");
}
PrintLog($PrintFunc, "End address of last Region LMA in load = ". CommonUtil::Dec2Hex($nLoadViewSize) . "\n");
PrintLog($PrintFunc, "-------------------------------------------------------------------\n");
$nLoadViewSize -= hex($strUROM_Base);
PrintLog($PrintFunc, "Total Load Size (ROM) = ". CommonUtil::Dec2Hex($nLoadViewSize) . " = $nLoadViewSize(Bytes) \n");
return $nLoadViewSize;
}
# NO L1core and Secure region !
sub CMD_GetROMSize
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $strUROM_Base = sysInfo::GetMemoryInfo("UROM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
my $strROM_Length = sysInfo::GetMemoryInfo("ROM", 2, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
PrintLog($PrintFunc, "ROM Information:\n");
PrintLog($PrintFunc, "ROM Base Address in LDS = $strUROM_Base\n");
PrintLog($PrintFunc, "ROM Length in LDS = $strROM_Length\n");
my $ERs_aref = &LinkerOutputParser::ListAllExeRegion(1);
$ERs_aref = sysInfo::FilterOutCoproReservedRegion($ERs_aref);
$ERs_aref = sysInfo::FilterOutSecureRegion($ERs_aref);# if(FileInfo::is_BuiltWithCopro());;
my $strLastRegion;
my $nLoadViewSize;
for (my $i = $#{$ERs_aref};$i >= 0; $i--)
{
$strLastRegion = $ERs_aref->[$i];
$nLoadViewSize = hex(&LinkerOutputParser::GetExeRegionInfo($strLastRegion, Region::LMA));
last if (LinkerOutputParser::GetExeRegionInfo($strLastRegion, Region::Attr) =~ /LOAD/);
}
my $nROMBase = hex($strUROM_Base);
my $nROMSize = ($nLoadViewSize&0x0fffffff) - ($nROMBase&0x0fffffff);
PrintLog($PrintFunc, "Last Load Region in ROM = $strLastRegion\n");
if($strLastRegion !~/zi|bss/i)
{
my $nLastRegionSize = hex(&LinkerOutputParser::GetExeRegionInfo($strLastRegion, Region::Size));
PrintLog($PrintFunc, "Last Load Region Size in ROM = ". CommonUtil::Dec2Hex($nLastRegionSize) ." = $nLastRegionSize(Bytes) \n");
$nROMSize += $nLastRegionSize;
}
else
{
PrintLog($PrintFunc, "Last Load Region Size in ROM = 0 (Bytes) \n");
}
my $strROMSize = CommonUtil::Dec2Hex($nROMSize); # $nROMSize = $nROMendAddress for pcore since $nROMBase=0
my $nROMendAddress = $nROMBase + $nROMSize;
PrintLog($PrintFunc, "End address of last Region LMA = ". CommonUtil::Dec2Hex($nROMendAddress) ."\n");
PrintLog($PrintFunc, "-------------------------------------------------------------------\n");
PrintLog($PrintFunc, "Total ROM Size (Code + RO Data + RW Data) = $strROMSize = $nROMSize(Bytes) \n");
return $nROMSize;
}
sub CMD_GetNonSharedRAMUsage
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $ERinRAM_aref = GetERsInRAM($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc);
my ($nNonSharedRAMUsage, $nRAMMargin) = (0, 0, 0);
if(scalar(@$ERinRAM_aref)>0)
{
my $EndRegion = @$ERinRAM_aref[scalar(@$ERinRAM_aref)-1];
# 1. calculate current RAM usage by "end of last section - base of first section "
#my $nFirstERInRAMVMA = hex(&LinkerOutputParser::GetExeRegionInfo($ERinRAM_aref->[0], Region::VMA));
my $nFirstNonSharedERInRAMVMAinBank0 = hex(&LinkerOutputParser::GetExeRegionInfo('CACHED_EXTSRAM', Region::VMA)) & 0x0FFFFFFF;
my $nEndRegionVMA = hex(&LinkerOutputParser::GetExeRegionInfo($EndRegion, Region::VMA));
my $nEndRegionSize = hex(&LinkerOutputParser::GetExeRegionInfo($EndRegion, Region::Size));
$nNonSharedRAMUsage = $nEndRegionVMA + $nEndRegionSize - $nFirstNonSharedERInRAMVMAinBank0;
# 2. get RAM Margin, 1:base, 2:length
my $nRAM_Base = hex(sysInfo::GetMemoryInfo("RAM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS));
my $nRAM_Length = hex(sysInfo::GetMemoryInfo("RAM", 2, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS));
my $nVRAM_Base = sysInfo::GetMemoryInfo("VRAM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
$nRAMMargin = ($nRAM_Base + $nRAM_Length) - ($nEndRegionVMA + $nEndRegionSize);
# 3. no need to get the space of dsp tx/rx since there is no region in the end of RAM
# $nReservedSize = GetReservedSize($IMAGELAYOUT_PATH, $SYM_PATH, $MAKEFILE_PATH);
}
return ($nNonSharedRAMUsage, $nRAMMargin);
}
sub CMD_GetRAMUsage
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc, $nRAM_Base) = @_;
$nRAM_Base = hex(sysInfo::GetMemoryInfo("RAM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS)) if(!defined $nRAM_Base);
my $ERinRAM_aref = GetERsInRAM($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc);
my $nRAMUsage = 0;
my @RAMMargins;
return $nRAMUsage if (!@$ERinRAM_aref);
my $strRAM_Base = sysInfo::GetMemoryInfo("RAM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
my $strVRAM_Base = sysInfo::GetMemoryInfo("VRAM", 1, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
my $strRAM_Length = sysInfo::GetMemoryInfo("RAM", 2, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
my $nDummyEndBase = hex(&LinkerOutputParser::Get_DUMMY_END_Base());
my $ER = $ERinRAM_aref->[-1];
my $nEndRegionVMA = hex(&LinkerOutputParser::GetExeRegionInfo($ER, Region::VMA));
my $nEndRegionSize = hex(&LinkerOutputParser::GetExeRegionInfo($ER, Region::Size));
my $strEndRegionEndVMA = CommonUtil::Dec2Hex($nEndRegionVMA+$nEndRegionSize);
my $nFirstERInRAMVMA = hex(&LinkerOutputParser::GetExeRegionInfo($ERinRAM_aref->[0], Region::VMA));
my $strFirstERInRAMVMA = CommonUtil::Dec2Hex($nFirstERInRAMVMA);
PrintLog($PrintFunc, "RAM Information:\n");
PrintLog($PrintFunc, "RAM Base Address in LDS = $strRAM_Base\n");
PrintLog($PrintFunc, "VRAM Base Address in LDS = $strVRAM_Base\n");
PrintLog($PrintFunc, "1st Region in RAM: ".$ERinRAM_aref->[0].", VMA=$strFirstERInRAMVMA\n");
PrintLog($PrintFunc, "RegionBeforeDummyEnd: $ER, VMA=".CommonUtil::Dec2Hex($nEndRegionVMA).
", Size=".CommonUtil::Dec2Hex($nEndRegionSize).", End address=$strEndRegionEndVMA\n");
PrintLog($PrintFunc, "DummyEndBase = ".CommonUtil::Dec2Hex($nDummyEndBase)." (the end address of total MD memory)\n");
PrintLog($PrintFunc, "-------------------------------------------------------------------\n");
my $nERend = CMD_GetROMSize(($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH));
my @FreeRAMAreas;
my @UsedRAMAreas;
my $drdi_start = 0;
my $drdi_load_start = 0;
my $drdi_end = 0;
my $drdi_load_end = 0;
my $drdi_found = 0;
foreach $ER (@$ERinRAM_aref) #Go through all regions in ram
{
my $strERsize = LinkerOutputParser::GetExeRegionInfo($ER, Region::Size);
my $nERaddr = get_physical_address(hex(&LinkerOutputParser::GetExeRegionInfo($ER, Region::VMA)));
if (hex($strERsize))
{
my $ERsize = hex($strERsize);
my $append = 0;
my $note = undef;
foreach my $used (@UsedRAMAreas)
{
if(($used->[0]<=$nERaddr) and (($used->[0]+$used->[1])>=$nERaddr))
{
if (($used->[0]+$used->[1])<=($nERaddr+$ERsize))
{
$used->[1]= ($nERaddr+$ERsize)-$used->[0];
}
$append = 1;
}
elsif(($used->[0]<=($nERaddr+$ERsize)) and (($used->[0]+$used->[1])>=($nERaddr+$ERsize)))
{
if ($used->[0] < $nERaddr)
{
$used->[1] += $nERaddr-$used->[0];
$used->[0] = $nERaddr;
$append = 1;
}
}
if($ER =~ /DRDI/)
{
if($drdi_found == 0)
{
$drdi_start = $nERaddr;
$drdi_load_start = hex(&LinkerOutputParser::GetExeRegionInfo($ER, Region::LMA));
$drdi_end = $nERaddr + $ERsize;
$drdi_load_end = $drdi_load_start + $ERsize;
$drdi_found = 1;
}
else
{
$drdi_end = $nERaddr+$ERsize if($drdi_end <= ($nERaddr+$ERsize));
$drdi_load_end = hex(&LinkerOutputParser::GetExeRegionInfo($ER, Region::LMA))+$ERsize;
}
}
if ($append == 1)
{
$used->[2] = $note if($note ne undef);
}
}
if ($append == 1)
{
$append = 0;
}
else
{
push @UsedRAMAreas, [$nERaddr, $ERsize, $note]
}
}
}
@UsedRAMAreas = sort {$a->[0]<=>$b->[0]} @UsedRAMAreas;
if($nERend < $UsedRAMAreas[0][0])
{
push @FreeRAMAreas, [$nERend,$UsedRAMAreas[0][0]-$nERend];
}
for( my $i = 0;$i < $#UsedRAMAreas;$i+=1)
{
my $freeStart =$UsedRAMAreas[$i][0]+$UsedRAMAreas[$i][1];
my $freeSize =$UsedRAMAreas[$i+1][0]-$freeStart;
push @FreeRAMAreas, [$freeStart,$freeSize] if ($freeSize > 0);
}
my $FRindex = 0;
my $totalRAM = 0;
foreach my $refUsed (@UsedRAMAreas)
{
$FRindex +=1;
$totalRAM += $refUsed->[1];
PrintLog($PrintFunc, "RAM Usage $FRindex ".CommonUtil::Dec2Hex($refUsed->[1])." = " .GetSizeFromBytes($refUsed->[1])."\tfrom ". CommonUtil::Dec2Hex($refUsed->[0])." to ".CommonUtil::Dec2Hex($refUsed->[0]+$refUsed->[1])." ".$refUsed->[2]."\n");
}
PrintLog($PrintFunc,"Total allocated (used) RAM: ".CommonUtil::Dec2Hex($totalRAM)." = ".GetSizeFromBytes($totalRAM)."\n\n");
$nRAMUsage = $totalRAM;
$FRindex = 0;
$totalRAM = 0;
foreach my $refUsed (@FreeRAMAreas)
{
$FRindex +=1;
$totalRAM += $refUsed->[1];
PrintLog($PrintFunc, "RAM unused $FRindex ".CommonUtil::Dec2Hex($refUsed->[1])." = " .GetSizeFromBytes($refUsed->[1])."\tfrom ". CommonUtil::Dec2Hex($refUsed->[0])." to ".CommonUtil::Dec2Hex($refUsed->[0]+$refUsed->[1])."\n");
}
PrintLog($PrintFunc,"Total unallocated (free) RAM: ".CommonUtil::Dec2Hex($totalRAM)." = ".GetSizeFromBytes($totalRAM)."\n\n");
PrintLog($PrintFunc, "RAM Usage consist of\n");
PrintLog($PrintFunc, " 1) RW + ZI : ".((hex($strEndRegionEndVMA)& 0x3fffffff)- get_physical_address($nFirstERInRAMVMA))."(Bytes) \tfrom $strFirstERInRAMVMA to $strEndRegionEndVMA\n");
PrintLog($PrintFunc, "Total used RAM Size (RW + ZI Data) = ". CommonUtil::Dec2Hex($nRAMUsage) . " = $nRAMUsage (Bytes) \n");
PrintLog($PrintFunc, "-------------------------------------------------------------------\n");
PrintLog($PrintFunc,"Top RAM Margins:\n");
@FreeRAMAreas =sort {$b->[1] <=> $a->[1]} @FreeRAMAreas;
$FRindex =1;
my $AP_RAM = 0;
foreach my $refUsed (@FreeRAMAreas)
{
my $MarginStart = ($refUsed->[0]+ 0xffff) & 0xffff0000;
my $MarginLength = (($refUsed->[0] + $refUsed->[1]) & 0xffff0000)- $MarginStart;
next if($MarginLength<0x10000);
$AP_RAM += $MarginLength;
if($g_MAKEFILE_OPTIONS{PLATFORM} =~ /MT6297/)
{
my $sib_area_start = hex(LinkerOutputParser::GetLinkerSymbolAddress("SIB_AREA", LinkerSymPostfix::Base,LinkerSymPrefix::Image));
my $sib_area_end = hex(LinkerOutputParser::GetLinkerSymbolAddress("SIB_AREA", LinkerSymPostfix::ZILimit,LinkerSymPrefix::Image));
if((($MarginStart <= $sib_area_start) && (($MarginStart+$MarginLength) >= $sib_area_start)) || (($MarginStart <= $sib_area_end) && (($MarginStart+$MarginLength) >= $sib_area_end)))
{
PrintLog($PrintFunc, "RAM Margin $FRindex ".CommonUtil::Dec2Hex($MarginLength)." = " .GetSizeFromBytes($MarginLength)."\tfrom ". CommonUtil::Dec2Hex($MarginStart)." to ".CommonUtil::Dec2Hex($MarginStart+$MarginLength)." Used for SIB area\n");
$FRindex +=1;
next;
}
}
PrintLog($PrintFunc, "RAM Margin $FRindex ".CommonUtil::Dec2Hex($MarginLength)." = " .GetSizeFromBytes($MarginLength)."\tfrom ". CommonUtil::Dec2Hex($MarginStart)." to ".CommonUtil::Dec2Hex($MarginStart+$MarginLength)."\n");
$FRindex +=1;
push @RAMMargins, [$MarginStart,$MarginLength];
}
PrintLog($PrintFunc,"Total recycle free RAM: ".CommonUtil::Dec2Hex($AP_RAM). " = ". GetSizeFromBytes($AP_RAM)."\n\n");
for (my $item_count = $#RAMMargins+1; $item_count < 8; $item_count+=1)
{
push @RAMMargins, [0,0];
}
@RAMMargins = sort {$b->[1] <=> $a->[1]} @RAMMargins;
splice @RAMMargins, 8;
if ($drdi_found == 1)
{
PrintLog($PrintFunc, "-------------------------------------------------------------------\n");
PrintLog($PrintFunc, "DRDI area\n");
PrintLog($PrintFunc, "Size : ".(($drdi_end& 0x0fffffff)- ($drdi_start& 0x0fffffff))." (Bytes) \tfrom ".CommonUtil::Dec2Hex($drdi_start& 0x0fffffff)." to ".CommonUtil::Dec2Hex($drdi_end& 0x0fffffff)."\n");
PrintLog($PrintFunc, "Load size: ".(($drdi_load_end& 0x0fffffff)- ($drdi_load_start& 0x0fffffff))." (Bytes) \tfrom ".CommonUtil::Dec2Hex($drdi_load_start& 0x0fffffff)." to ".CommonUtil::Dec2Hex($drdi_load_end& 0x0fffffff)."\n");
}
return ($nRAMUsage, (@RAMMargins)); # add $strRAMMarin1 as return value, the 3rd return value is different than l1core
}
sub GetSizeFromBytes
{
my ($given_size) = @_;
return sprintf("%5.1f",$given_size)."(B)" if ($given_size < 1024);
if (($given_size/1024) < 1024)
{
return sprintf("%5.1f",($given_size/1024))."(KB)" ;
}
return sprintf("%5.1f",($given_size/(1024*1024)))."(MB)";
}
sub GetERsInRAM
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $ERs_aref = &LinkerOutputParser::ListAllExeRegion(1);
my $ERinRAM_aref = &sysInfo::FilterOutRegionInRAM($ERs_aref, \%g_MAKEFILE_OPTIONS);
my @regions;
my @sorted_regions;
foreach my $ER (@$ERinRAM_aref)
{
my $ER_size = hex(&LinkerOutputParser::GetExeRegionInfo($ER, Region::VMA));
my $bank = $ER_size >> 28;
if($bank == 1 || $bank == 7)
{
$ER_size = $ER_size & 0x1FFFFFFF;
}
else
{
$ER_size = $ER_size & 0x0FFFFFFF;
}
push @regions, [$ER, $ER_size];
}
@regions = sort { $a->[1] <=> $b->[1] } @regions;
foreach my $ER (@regions)
{
push @sorted_regions, $ER->[0];
}
return \@sorted_regions;
}
sub GetNonSharedMemoryERsInRAM
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $ERinRAM_aref = GetERsInRAM($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc);
my $ERinRAMnoShared_aref = &sysInfo::FilterOutSharedRegion($ERinRAM_aref, \%g_MAKEFILE_OPTIONS);
return $ERinRAMnoShared_aref;
}
sub GetExpectedLoadViewSize
{
basicinfo_die("not support GetExpectedLoadViewSize");
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $nActualROMSize = CMD_GetLoadViewSize($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc);
PrintLog($PrintFunc, "ActualROMSize = ".CommonUtil::Dec2Hex($nActualROMSize)." = $nActualROMSize(Bytes)\n");
my $nExpectedROMSize = &CommonUtil::GetMBAligned($nActualROMSize, 1);
PrintLog($PrintFunc, "ExpectedROMSize = ".CommonUtil::Dec2Hex($nExpectedROMSize)." = $nExpectedROMSize(Bytes)\n");
return $nExpectedROMSize;
}
sub GetExpectedROMSize
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $nActualROMSize = CMD_GetROMSize($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc);
PrintLog($PrintFunc, "ActualROMSize = ".CommonUtil::Dec2Hex($nActualROMSize)." = $nActualROMSize(Bytes)\n");
my $nExpectedROMSize = $nActualROMSize;
#$nExpectedROMSize = 0x80000 if ($nActualROMSize < hex(0x80000)) ;
PrintLog($PrintFunc, "ExpectedROMSize = ".CommonUtil::Dec2Hex($nExpectedROMSize)." = $nExpectedROMSize(Bytes)\n");
#PrintLog($PrintFunc, "(The space from ".CommonUtil::Dec2Hex($nActualROMSize)." to 0x80000 is reserved for l1core TCM space)\n") if ($nActualROMSize < hex(0x80000));
PrintLog($PrintFunc, "-------------------------------------------------------------------\n");
return $nExpectedROMSize;
}
sub GetExpectedRAMSize
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my ($nRAMUsage, @RAMMargins) =
CMD_GetRAMUsage($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc);
my $nActualRAMSize = $nRAMUsage;
my $i = 0;
PrintLog($PrintFunc, "ActualRAMSize = ".CommonUtil::Dec2Hex($nActualRAMSize)." = $nActualRAMSize(Bytes)\n");
my $nExpectedRAMSize = $nRAMUsage ; #+ $nRAMMargin + $nRAMMargin1;
foreach my $nRAMMargin (@RAMMargins)
{
$i += 1;
PrintLog($PrintFunc, "RAM Margin $i ".CommonUtil::Dec2Hex($nRAMMargin)." = $nRAMMargin(Bytes)\n");
}
PrintLog($PrintFunc, "ExpectedRAMSize = ".CommonUtil::Dec2Hex($nExpectedRAMSize)." = $nExpectedRAMSize(Bytes)\n");
return $nExpectedRAMSize;
}
sub GetTotalRAMUsageFromLDS
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $strRAM_Length = LinkerOutputParser::Get_DUMMY_END_Base();
return hex($strRAM_Length);
}
sub CMD_GetPhysicalRAMUsage
{
my ($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, $PrintFunc) = @_;
my $nExepectedROMSize = GetExpectedROMSize($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, undef);
my $nExpectedRAMSize = GetExpectedRAMSize($MAKEFILE_PATH, $IMAGELAYOUT_PATH, $MAP_PATH, $SYM_PATH, undef);
my $nPRAMUsage = $nExepectedROMSize + $nExpectedRAMSize;
PrintLog($PrintFunc, "Total Physical RAMUsage(ROM + RAM) = ".CommonUtil::Dec2Hex($nExepectedROMSize)." + ".
CommonUtil::Dec2Hex($nExpectedRAMSize)." = ". CommonUtil::Dec2Hex($nPRAMUsage) ."\n");
return $nPRAMUsage ;
}
sub wait_for_reuse
#sub GetReservedSize
{
my ($IMAGELAYOUT_PATH, $SYM_PATH, $MAKEFILE_PATH) = @_;
my @ERinRAM;
my $BB_PATH = dirname($IMAGELAYOUT_PATH);
sysInfo::GetRAMregion($BB_PATH, $IMAGELAYOUT_PATH, \@ERinRAM, \%g_MAKEFILE_OPTIONS);
my $FixedER_aref = &sysInfo::FilterOutFixedRegion(\@ERinRAM, \%g_MAKEFILE_OPTIONS);
#######################
# FIX_ME, what is the reserve size?
#######################
# my $nReservedSize = 0;
# foreach my $ER (@$FixedER_aref)
# {
# my $strSize = sysInfo::GetRegionInfo($ER, Region::MaxSize, $IMAGELAYOUT_PATH, \%g_MAKEFILE_OPTIONS);
# $nReservedSize += hex($strSize);
# }
# return $nReservedSize;
}
sub PrintLog
{
my ($LogFunc, $strLog) = @_;
&{$LogFunc}($strLog) if(exists &{$LogFunc});
}
#****************************************************************************
# Subroutine: basicinfo_die
# Parameters: 1. string error message, 2. __FILE__ 3. __LINE__
# Returns: x
#****************************************************************************
sub basicinfo_die
{
my ($error_msg, $file, $line_no) = @_;
my $pack_name = undef;
if(!defined $file or !defined $line_no)
{
($pack_name, $file, $line_no) = caller;
}
&CommonUtil::error_handler($error_msg, $file, $line_no, 'BasicMemInfoPcore');
}
sub get_physical_address
{
my ($address) = @_;
my $addr_mask = 0x0fffffff;
my $bank = $address>>28;
if (($bank == 1) || ($bank == 7))
{
$addr_mask = 0x1fffffff;
}
return ($address & $addr_mask);
}