blob: 4401bd4a4130843404900435f32c1ab926c34086 [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) 2018
#
# 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:
#* ---------
#* ckL2CacheSection.pl
#*
#* Project:
#* --------
#*
#*
#* Description:
#* ------------
#* This scripts is used to check if all symbols allocated in L2$ Lock section register to config file.
#*
#* Author:
#* -------
#* Yao Liu (mtk15073)
#*
#****************************************************************************/
use strict;
use warnings;
BEGIN { push @INC , './tools/' } # add additional library path
use FileInfoParser;
use constant {
LOG => 0,
WARNING => 1,
FATAL => 2,
};
my ($MapFile, $Tempdir) = (@ARGV);
&msg_handler(LOG, "Input file: $MapFile, $Tempdir\n");
#record all official config info
my %official_config;
#record all symbols in L2Cache Lock Section
my %symbol_hash;
#record all symbols info from sym file
my %addr_to_symbol;
my $official_config = $Tempdir."~official_config.ldf";
&msg_handler(FATAL, "official config file do not exist!\n") if(!-e $official_config);
&Parse_Config_File();
&Parse_MAP_File($MapFile);
&Symbol_Check();
exit 0;
sub Parse_Config_File
{
open CFG, "$official_config" or &msg_handler(FATAL, "Can not open $official_config!", __LINE__);
local $/ = undef;
my $tempOutput = <CFG>;
close CFG;
my ($SubSection, $bFlag, $sFlag) = (undef, 0, 0);
my @TotalSecArray;
my $BreakRegExp = "[\\*]{20}\\s[<]\\sGROUP\\s*CFG\\s[>]\\s[\\*]{20}";
#split entire config file into several configuration groups.
foreach my $line (split /\n/, $tempOutput) {
if($bFlag == 0) {
$bFlag = 1 if(($line =~ m/^\[Symbol\]\s+\[Obj\]\s+\[Lib\]$/));
next;
}
next if($line =~ m/^\s*$/);
if($line =~ m/^\s*$BreakRegExp\s*$/) {
$sFlag = 1;
if(defined $SubSection) {
push @TotalSecArray, $SubSection;
undef $SubSection;
}
next;
}
$SubSection .= $line."\n" if($sFlag == 1);
}
push @TotalSecArray, $SubSection if(defined $SubSection);
foreach my $content (@TotalSecArray) {
my @tempArray = split /\n/, $content;
my ($Section_ID, $name_flag, $size_flag);
foreach my $line (@tempArray) {
if($line =~ /^Section ID\s*:\s*(.*)$/) {
$Section_ID = $1;
$name_flag = 1;
next;
} elsif($line =~ /^Reserved size\s*:\s*(.*)$/ && $name_flag == 1) {
$official_config{$Section_ID}{"size"} = $1;
$size_flag = 1;
next;
} elsif(!($name_flag == 1 && $size_flag == 1)) {
&msg_handler(FATAL, "Wrong config format in $Section_ID!", __LINE__, $official_config);
}
if($line =~ m/^(\S+)\s+(\S+)\s+(\S+)\s*$/) {
$official_config{$Section_ID}{$1.":".$2.":".$3}{"symbol_name"} = $1;
$official_config{$Section_ID}{$1.":".$2.":".$3}{"obj"} = $2;
$official_config{$Section_ID}{$1.":".$2.":".$3}{"lib"} = $3;
} elsif($Section_ID =~ /L2CACHE_LOCK_RO_SECTION_\w+/) {
my $msg = "Illegal Line Format: $line";
&msg_handler(FATAL, "Illegal Line Format: $line", __LINE__, $official_config);
next;
}
}
}
}
sub Parse_MAP_File
{
my ($map) = @_;
my $sym = $MapFile;
$sym =~ s/map/sym/;
open SYM, "<$sym" or &msg_handler(FATAL, "Can not open map $sym!", __LINE__);
map {$addr_to_symbol{uc($1)} = $5 if(/^(\w{8})\s+(\w)\s+(\w\s+)?CACHED_EXTSRAM_L2CACHE_LOCK_RO\s+(\w{8})\s+(\w+)$/)} (<SYM>);
close SYM;
my $flag = 0;
my ($input_section, $addr, $lib, $obj);
open MAP, "<$map" or &msg_handler(FATAL, "Can not open map $map!", __LINE__);
foreach my $line (<MAP>){
$flag = 1 if ($line =~ /^CACHED_EXTSRAM_L2CACHE_LOCK_RO$/);
next if (!($line =~ /^CACHED_EXTSRAM_L2CACHE_LOCK_RO$/ || $flag == 1));
last if ($line =~ /Image\$\$CACHED_EXTSRAM_L2CACHE_LOCK_RO\$\$ZI\$\$Limit = \.$/ && $flag == 1);
if ($line =~ /^\s(\w+)$/){
$input_section = $1;
($addr, $lib, $obj) = (undef, undef, undef);
} elsif ($line =~ /\s+(\S+)?\s+0x(\w+)\s+(0x\w+)\s+.*\/?\/(\w+\.a)\((\w+\.obj)\)/){
# 0x91e5e3c0 0x8a ./build/MT6885_SP/NLWCTG/bin/lib/libsys_drv.a(idle_task.obj)
($addr, $lib, $obj) = (uc($2), $4, $5);
my $symbol_name = $addr_to_symbol{$addr};
my $key = $symbol_name.":".$obj.":".$lib;
$symbol_hash{$input_section}{$key}{"symbol_name"} = $symbol_name;
$symbol_hash{$input_section}{$key}{"obj"} = $obj;
$symbol_hash{$input_section}{$key}{"lib"} = $lib;
} elsif ($line =~ /^\s+0x(\w+)\s+(\w+)$/) {
my $symbol_name = $2;
my $key = $symbol_name.":".$obj.":".$lib;
next if (exists $symbol_hash{$input_section}{$key});
$symbol_hash{$input_section}{$key}{"symbol_name"} = $symbol_name;
$symbol_hash{$input_section}{$key}{"obj"} = $obj;
$symbol_hash{$input_section}{$key}{"lib"} = $lib;
}
}
}
sub Symbol_Check
{
foreach my $section (keys %symbol_hash){
next if(!exists $official_config{$section});
foreach my $key (keys %{$symbol_hash{$section}}){
&msg_handler(FATAL, "Symbol $symbol_hash{$section}{$key}{\"symbol_name\"} doesn't register to official congfig file!", __LINE__) if(!exists $official_config{$section}{$key});
}
}
&msg_handler(LOG, "The following symbols don't exist in current load:\n");
my $index = 0;
foreach my $section (keys %official_config){
foreach my $key (keys %{$official_config{$section}}){
next if ($key eq "size");
&msg_handler(LOG, "[$index] $official_config{$section}{$key}{\"symbol_name\"} $official_config{$section}{$key}{\"obj\"} $official_config{$section}{$key}{\"lib\"}", __LINE__) if(!exists $symbol_hash{$section}{$key});
$index++;
}
}
&msg_handler(LOG, "[Done]: Section check!");
}
sub msg_handler
{
my ($type, $msg, $line_no) = (@_);
my $prompt_prefix;
if($type == LOG) {
print $msg . "\n";
}
elsif($type == WARNING) {
$prompt_prefix = ">> AAIS Warning : ";
print $prompt_prefix . $msg . "\n";
}
elsif($type == FATAL) {
$prompt_prefix = ">> *** AAIS Fatal : ";
my $location = "[at line $line_no] ";
die $prompt_prefix . $location . $msg . "\n";
}
}