yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [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) 2018 |
| 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 | #* ckL2CacheSection.pl |
| 40 | #* |
| 41 | #* Project: |
| 42 | #* -------- |
| 43 | #* |
| 44 | #* |
| 45 | #* Description: |
| 46 | #* ------------ |
| 47 | #* This scripts is used to check if all symbols allocated in L2$ Lock section register to config file. |
| 48 | #* |
| 49 | #* Author: |
| 50 | #* ------- |
| 51 | #* Yao Liu (mtk15073) |
| 52 | #* |
| 53 | #****************************************************************************/ |
| 54 | |
| 55 | use strict; |
| 56 | use warnings; |
| 57 | |
| 58 | BEGIN { push @INC , './tools/' } # add additional library path |
| 59 | use FileInfoParser; |
| 60 | use constant { |
| 61 | LOG => 0, |
| 62 | WARNING => 1, |
| 63 | FATAL => 2, |
| 64 | }; |
| 65 | |
| 66 | my ($MapFile, $Tempdir) = (@ARGV); |
| 67 | &msg_handler(LOG, "Input file: $MapFile, $Tempdir\n"); |
| 68 | |
| 69 | #record all official config info |
| 70 | my %official_config; |
| 71 | #record all symbols in L2Cache Lock Section |
| 72 | my %symbol_hash; |
| 73 | #record all symbols info from sym file |
| 74 | my %addr_to_symbol; |
| 75 | |
| 76 | my $official_config = $Tempdir."~official_config.ldf"; |
| 77 | &msg_handler(FATAL, "official config file do not exist!\n") if(!-e $official_config); |
| 78 | |
| 79 | &Parse_Config_File(); |
| 80 | &Parse_MAP_File($MapFile); |
| 81 | |
| 82 | &Symbol_Check(); |
| 83 | |
| 84 | exit 0; |
| 85 | |
| 86 | sub Parse_Config_File |
| 87 | { |
| 88 | open CFG, "$official_config" or &msg_handler(FATAL, "Can not open $official_config!", __LINE__); |
| 89 | local $/ = undef; |
| 90 | my $tempOutput = <CFG>; |
| 91 | close CFG; |
| 92 | |
| 93 | my ($SubSection, $bFlag, $sFlag) = (undef, 0, 0); |
| 94 | my @TotalSecArray; |
| 95 | my $BreakRegExp = "[\\*]{20}\\s[<]\\sGROUP\\s*CFG\\s[>]\\s[\\*]{20}"; |
| 96 | |
| 97 | #split entire config file into several configuration groups. |
| 98 | foreach my $line (split /\n/, $tempOutput) { |
| 99 | if($bFlag == 0) { |
| 100 | $bFlag = 1 if(($line =~ m/^\[Symbol\]\s+\[Obj\]\s+\[Lib\]$/)); |
| 101 | next; |
| 102 | } |
| 103 | next if($line =~ m/^\s*$/); |
| 104 | |
| 105 | if($line =~ m/^\s*$BreakRegExp\s*$/) { |
| 106 | $sFlag = 1; |
| 107 | if(defined $SubSection) { |
| 108 | push @TotalSecArray, $SubSection; |
| 109 | undef $SubSection; |
| 110 | } |
| 111 | next; |
| 112 | } |
| 113 | $SubSection .= $line."\n" if($sFlag == 1); |
| 114 | } |
| 115 | push @TotalSecArray, $SubSection if(defined $SubSection); |
| 116 | |
| 117 | foreach my $content (@TotalSecArray) { |
| 118 | my @tempArray = split /\n/, $content; |
| 119 | my ($Section_ID, $name_flag, $size_flag); |
| 120 | foreach my $line (@tempArray) { |
| 121 | if($line =~ /^Section ID\s*:\s*(.*)$/) { |
| 122 | $Section_ID = $1; |
| 123 | $name_flag = 1; |
| 124 | next; |
| 125 | } elsif($line =~ /^Reserved size\s*:\s*(.*)$/ && $name_flag == 1) { |
| 126 | $official_config{$Section_ID}{"size"} = $1; |
| 127 | $size_flag = 1; |
| 128 | next; |
| 129 | } elsif(!($name_flag == 1 && $size_flag == 1)) { |
| 130 | &msg_handler(FATAL, "Wrong config format in $Section_ID!", __LINE__, $official_config); |
| 131 | } |
| 132 | |
| 133 | if($line =~ m/^(\S+)\s+(\S+)\s+(\S+)\s*$/) { |
| 134 | $official_config{$Section_ID}{$1.":".$2.":".$3}{"symbol_name"} = $1; |
| 135 | $official_config{$Section_ID}{$1.":".$2.":".$3}{"obj"} = $2; |
| 136 | $official_config{$Section_ID}{$1.":".$2.":".$3}{"lib"} = $3; |
| 137 | } elsif($Section_ID =~ /L2CACHE_LOCK_RO_SECTION_\w+/) { |
| 138 | my $msg = "Illegal Line Format: $line"; |
| 139 | &msg_handler(FATAL, "Illegal Line Format: $line", __LINE__, $official_config); |
| 140 | next; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | sub Parse_MAP_File |
| 147 | { |
| 148 | my ($map) = @_; |
| 149 | my $sym = $MapFile; |
| 150 | $sym =~ s/map/sym/; |
| 151 | |
| 152 | open SYM, "<$sym" or &msg_handler(FATAL, "Can not open map $sym!", __LINE__); |
| 153 | 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>); |
| 154 | close SYM; |
| 155 | |
| 156 | my $flag = 0; |
| 157 | my ($input_section, $addr, $lib, $obj); |
| 158 | open MAP, "<$map" or &msg_handler(FATAL, "Can not open map $map!", __LINE__); |
| 159 | foreach my $line (<MAP>){ |
| 160 | $flag = 1 if ($line =~ /^CACHED_EXTSRAM_L2CACHE_LOCK_RO$/); |
| 161 | next if (!($line =~ /^CACHED_EXTSRAM_L2CACHE_LOCK_RO$/ || $flag == 1)); |
| 162 | last if ($line =~ /Image\$\$CACHED_EXTSRAM_L2CACHE_LOCK_RO\$\$ZI\$\$Limit = \.$/ && $flag == 1); |
| 163 | |
| 164 | if ($line =~ /^\s(\w+)$/){ |
| 165 | $input_section = $1; |
| 166 | ($addr, $lib, $obj) = (undef, undef, undef); |
| 167 | } elsif ($line =~ /\s+(\S+)?\s+0x(\w+)\s+(0x\w+)\s+.*\/?\/(\w+\.a)\((\w+\.obj)\)/){ |
| 168 | # 0x91e5e3c0 0x8a ./build/MT6885_SP/NLWCTG/bin/lib/libsys_drv.a(idle_task.obj) |
| 169 | ($addr, $lib, $obj) = (uc($2), $4, $5); |
| 170 | my $symbol_name = $addr_to_symbol{$addr}; |
| 171 | my $key = $symbol_name.":".$obj.":".$lib; |
| 172 | $symbol_hash{$input_section}{$key}{"symbol_name"} = $symbol_name; |
| 173 | $symbol_hash{$input_section}{$key}{"obj"} = $obj; |
| 174 | $symbol_hash{$input_section}{$key}{"lib"} = $lib; |
| 175 | } elsif ($line =~ /^\s+0x(\w+)\s+(\w+)$/) { |
| 176 | my $symbol_name = $2; |
| 177 | my $key = $symbol_name.":".$obj.":".$lib; |
| 178 | next if (exists $symbol_hash{$input_section}{$key}); |
| 179 | $symbol_hash{$input_section}{$key}{"symbol_name"} = $symbol_name; |
| 180 | $symbol_hash{$input_section}{$key}{"obj"} = $obj; |
| 181 | $symbol_hash{$input_section}{$key}{"lib"} = $lib; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | sub Symbol_Check |
| 187 | { |
| 188 | foreach my $section (keys %symbol_hash){ |
| 189 | next if(!exists $official_config{$section}); |
| 190 | foreach my $key (keys %{$symbol_hash{$section}}){ |
| 191 | &msg_handler(FATAL, "Symbol $symbol_hash{$section}{$key}{\"symbol_name\"} doesn't register to official congfig file!", __LINE__) if(!exists $official_config{$section}{$key}); |
| 192 | } |
| 193 | } |
| 194 | &msg_handler(LOG, "The following symbols don't exist in current load:\n"); |
| 195 | my $index = 0; |
| 196 | foreach my $section (keys %official_config){ |
| 197 | foreach my $key (keys %{$official_config{$section}}){ |
| 198 | next if ($key eq "size"); |
| 199 | &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}); |
| 200 | $index++; |
| 201 | } |
| 202 | } |
| 203 | &msg_handler(LOG, "[Done]: Section check!"); |
| 204 | } |
| 205 | |
| 206 | sub msg_handler |
| 207 | { |
| 208 | my ($type, $msg, $line_no) = (@_); |
| 209 | my $prompt_prefix; |
| 210 | if($type == LOG) { |
| 211 | print $msg . "\n"; |
| 212 | } |
| 213 | elsif($type == WARNING) { |
| 214 | $prompt_prefix = ">> AAIS Warning : "; |
| 215 | print $prompt_prefix . $msg . "\n"; |
| 216 | } |
| 217 | elsif($type == FATAL) { |
| 218 | $prompt_prefix = ">> *** AAIS Fatal : "; |
| 219 | my $location = "[at line $line_no] "; |
| 220 | die $prompt_prefix . $location . $msg . "\n"; |
| 221 | } |
| 222 | } |