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) 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 | #* MemoryUtility/memquery.pl |
| 40 | #* |
| 41 | #* Description: |
| 42 | #* ------------ |
| 43 | #* This script should be used in build flow |
| 44 | #* This provides corresponding memory utility command and system call |
| 45 | #* |
| 46 | #* Author: |
| 47 | #* ------- |
| 48 | #* Carl Kao (mtk08237) |
| 49 | #* |
| 50 | #****************************************************************************/ |
| 51 | use strict; |
| 52 | BEGIN { push @INC, "./" , './tools/', './tools/MemoryUtility/', '../' } |
| 53 | use CommonUtility; |
| 54 | use File::Basename; |
| 55 | use BasicMemInfoQuery; |
| 56 | |
| 57 | my $nVerion = "LR13_v0.02"; |
| 58 | # LR13_v0.02 , 20180423 , updated l2cachelockinfo |
| 59 | # LR13_v0.01 , 20160906 , Removed SPRAM2 support |
| 60 | # LR12_v0.06 , 20160303 , Memory Utility implementation for LR12 |
| 61 | # LR12_v0.05 , 20160125 , Memory Utility Refinement for LR12 |
| 62 | # LR12_v0.04 , 20160113 , memquery remove l1 core related feature |
| 63 | # LR12_v0.03 , 20151215 , fix memory utility .map file parsing feature for LR12 (64bit address) |
| 64 | # LR12_v0.02 , 20151102 , detectZI parsing rule change |
| 65 | # LR12_v0.01 , 20151026 , add GrepSymbolByInputSection feature to memory utility |
| 66 | # u0.07 , 20151030 , Carl , Parsing ELF file instead of parsing BIN file since there is CCCI header in front of bin file |
| 67 | # u0.06 , 20150127 , Carl , Take bin file path from build flow (final solution) |
| 68 | # u0.05 , 20150127 , Carl , Fix GetBinFile for UMOLY TRUNK since the nameing rule is different (temp solution) |
| 69 | # u0.04 , 20150121 , Carl , Fix GetBinFile for 91 |
| 70 | # u0.03 , 20150119 , Carl , Memory Utility Refinement |
| 71 | # u0.02 , 20150107 , Carl , refine for 91 image layout |
| 72 | # u0.01 , |
| 73 | |
| 74 | |
| 75 | #**************************************************************************** |
| 76 | # Inputs |
| 77 | #**************************************************************************** |
| 78 | my $ARGV_FILE_PATH = $ARGV[0]; #./build/MT6297_EVB/NLWCTG_SAP/tmp/~memquery.tmp |
| 79 | my $IMAGELAYOUT_PATH = $ARGV[1]; # scatter file or linker script |
| 80 | my $MAKE_FILE = $ARGV[2]; |
| 81 | my $LINKER_OUTPUT_PATH = $ARGV[3]; # map |
| 82 | my $LOG_FOLDER = $ARGV[4]; |
| 83 | my $LOG_PATH = $ARGV[4]."/memquery.log"; |
| 84 | my $INFOMAKE_PATH = $ARGV[5]; |
| 85 | my $BIN_FILE = $ARGV[6]; |
| 86 | my $SYM_FILE = $LINKER_OUTPUT_PATH; |
| 87 | $SYM_FILE =~ s/\.map$/\.sym/; |
| 88 | if(!-f $SYM_FILE) |
| 89 | { |
| 90 | print "\n[memquery][Note]$SYM_FILE doesn't exist!\n"; |
| 91 | my $file = basename($SYM_FILE); |
| 92 | my $dirname = dirname($SYM_FILE); |
| 93 | $SYM_FILE = $dirname."\/dummy_$file"; |
| 94 | print "Use $SYM_FILE instead of it.\n"; |
| 95 | } |
| 96 | |
| 97 | #**************************************************************************** |
| 98 | # Global variable |
| 99 | #**************************************************************************** |
| 100 | my @Supported_Cmd = qw(-h help --help |
| 101 | # basic comand |
| 102 | symin objin libinfo objinfo discard |
| 103 | compareobj comparelib comparediscard |
| 104 | diff2symin diffsymin |
| 105 | basicinfo chkmemusage detectZI |
| 106 | symbolinfo sdatainfo l2cachelockinfo |
| 107 | topsizeobj |
| 108 | syminobj syminlib symthreshold fillinfo |
| 109 | # special command |
| 110 | tcmmargin rammargin l2srammargin sprammargin |
| 111 | objinspram0 objinspram1 objinspramall objinl2sram objintcm |
| 112 | syminspram0 syminspram1 syminspramall syminl2sram symintcm |
| 113 | comparespram0 comparespram1 comparespramall comparetcm); # no comparel2sram |
| 114 | my $g_bToLog = 0; |
| 115 | #**************************************************************************** |
| 116 | # MainFlow |
| 117 | #**************************************************************************** |
| 118 | unlink $LOG_PATH if(-e $LOG_PATH); |
| 119 | PrintLog("Command: $0 $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] \n\n"); |
| 120 | my $arg_aref = ParseARGV($ARGV_FILE_PATH); |
| 121 | DispatchCommand($arg_aref, \@Supported_Cmd, $IMAGELAYOUT_PATH, $MAKE_FILE, |
| 122 | $LINKER_OUTPUT_PATH, $SYM_FILE, $LOG_FOLDER, $BIN_FILE); |
| 123 | |
| 124 | #**************************************************************************** |
| 125 | # 0 >>> exit - no error: 0, error code: > 0 |
| 126 | #**************************************************************************** |
| 127 | exit 0; |
| 128 | |
| 129 | #**************************************************************************** |
| 130 | # subroutines |
| 131 | #**************************************************************************** |
| 132 | sub DispatchCommand |
| 133 | { |
| 134 | my ($arg_aref, $Supported_Cmd_aref, |
| 135 | $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 136 | my $str1stCmd = $arg_aref->[0]; |
| 137 | $g_bToLog = 1 if (grep {$_ =~/log/i} @$arg_aref); |
| 138 | my $bRunCommand = 0; |
| 139 | foreach my $cmd (@$Supported_Cmd_aref) |
| 140 | { |
| 141 | if($str1stCmd =~ /^$cmd$/i) |
| 142 | { |
| 143 | $cmd = "help" if($cmd eq "-h" or $cmd eq "--help"); |
| 144 | shift(@$arg_aref); |
| 145 | no strict 'refs'; |
| 146 | my $Func = "CMD_$cmd"; |
| 147 | PrintToScreen("\n-----------------------------[Memory Query]---------------------------\n"); |
| 148 | &{$Func}($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) if (exists &{$Func}) |
| 149 | or mem_die("$Func() doesn't exists!", __FILE__, __LINE__); |
| 150 | $bRunCommand = 1; |
| 151 | last; |
| 152 | } |
| 153 | } |
| 154 | if(!$bRunCommand) |
| 155 | { |
| 156 | print "$str1stCmd is not supported. Please refer to the following command option:\n"; |
| 157 | Usage(); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | sub ParseARGV |
| 162 | { |
| 163 | my ($strTmpFilePath) = @_; |
| 164 | Usage() if(!-e $strTmpFilePath); |
| 165 | my $strContent = CommonUtil::GetFileContent($strTmpFilePath); |
| 166 | my @arguments = split(/\s/, $strContent); |
| 167 | return \@arguments; |
| 168 | } |
| 169 | |
| 170 | sub GetLogName |
| 171 | { |
| 172 | my ($makefile, $log_folder, $strPostfix) = @_; |
| 173 | my $project = basename($makefile); |
| 174 | $project =~ s/\.mak|~//ig; |
| 175 | return "$log_folder/$project\_$strPostfix\.txt"; |
| 176 | } |
| 177 | sub DecideOuput |
| 178 | { |
| 179 | my ($makefile, $log_folder, $strPostfix) = @_; |
| 180 | my $Func = \&PrintToScreen; |
| 181 | if($g_bToLog) |
| 182 | { |
| 183 | $Func = \&PrintLog; |
| 184 | $LOG_PATH = GetLogName($makefile, $log_folder, $strPostfix); |
| 185 | unlink $LOG_PATH if(-e $LOG_PATH); |
| 186 | } |
| 187 | return $Func; |
| 188 | } |
| 189 | #**************************************************************************** |
| 190 | # command |
| 191 | #**************************************************************************** |
| 192 | sub CMD_basicinfo |
| 193 | { |
| 194 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 195 | my $Func = DecideOuput($makefile, $log_folder, "BasicInfo"); |
| 196 | no strict 'refs'; |
| 197 | &BasicMemInfo::DispatchCommand("CMD_GetROMSize", $makefile, $lds_path, $map_path, $sym_path, $Func); |
| 198 | &{$Func}("-------------------------------------------------------------------\n"); |
| 199 | &BasicMemInfo::DispatchCommand("CMD_GetRAMUsage", $makefile, $lds_path, $map_path, $sym_path, $Func); |
| 200 | &{$Func}("-------------------------------------------------------------------\n"); |
| 201 | &BasicMemInfo::DispatchCommand("CMD_GetPhysicalRAMUsage", $makefile, $lds_path, $map_path, $sym_path, $Func); |
| 202 | &{$Func}("-------------------------------------------------------------------\n"); |
| 203 | print "The output is generated under: $LOG_PATH\n" if($g_bToLog); |
| 204 | } |
| 205 | sub system_cmd |
| 206 | { |
| 207 | my ($cmd, $strPostfix, $makefile, $log_folder) =@_; |
| 208 | my $path = GetLogName($makefile, $log_folder, $strPostfix); |
| 209 | my $output = "> \"$path\"" if($g_bToLog); |
| 210 | print "cmd=$cmd $output\n\n"; |
| 211 | system("$cmd $output"); |
| 212 | print "The output is generated under: $path\n" if($g_bToLog); |
| 213 | } |
| 214 | |
| 215 | sub system_cmd_csv |
| 216 | { |
| 217 | my ($cmd, $strPostfix, $makefile, $log_folder) =@_; |
| 218 | my $project = basename($makefile); |
| 219 | $project =~ s/\.mak|~//ig; |
| 220 | my $path = "$log_folder/$project\_$strPostfix\.csv"; |
| 221 | my $output = "> \"$path\"" if($g_bToLog); |
| 222 | print "cmd=$cmd $output\n\n"; |
| 223 | system("$cmd $output"); |
| 224 | print "The output is generated under: $path\n" if($g_bToLog); |
| 225 | } |
| 226 | |
| 227 | sub CMD_tcmmargin |
| 228 | { |
| 229 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 230 | print"Redirect to memquery sprammargin!\n"; |
| 231 | CMD_sprammargin($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder); |
| 232 | } |
| 233 | |
| 234 | sub CMD_sprammargin |
| 235 | { |
| 236 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 237 | system_cmd("perl ./tools/MemoryUtility/TCMMargin.pl \"$makefile\" \"$lds_path\" \"$sym_path\"", |
| 238 | "SPRAMMargin", $makefile, $log_folder); |
| 239 | } |
| 240 | |
| 241 | sub CMD_l2srammargin |
| 242 | { |
| 243 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 244 | CMD_sprammargin($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder); |
| 245 | } |
| 246 | |
| 247 | sub CMD_rammargin |
| 248 | { |
| 249 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 250 | system_cmd("perl ./tools/MemoryUtility/RAMMargin.pl \"$makefile\" \"$lds_path\" \"$sym_path\"", |
| 251 | "RAMMargin", $makefile, $log_folder); |
| 252 | } |
| 253 | |
| 254 | sub _CMD_comparespram |
| 255 | { |
| 256 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, $query_range) = @_; |
| 257 | if(scalar(@$arg_aref) < 1) |
| 258 | { |
| 259 | print "Please add the map path after comparespram.\nFor more information, you can refer to memquery -h\n\n"; |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | my $compare_path = $arg_aref->[0]; |
| 264 | my $output_log = GetLogName($makefile, $log_folder, "Compare".$query_range.($query_range eq "SPRAM"?"All":"")); |
| 265 | system("perl ./tools/MemoryUtility/TCMQuery.pl -c $query_range \"$map_path\" \"$compare_path\" > \"$output_log\""); |
| 266 | print "The output is generated under: $output_log\n"; |
| 267 | } |
| 268 | } |
| 269 | sub CMD_comparespram0 |
| 270 | { |
| 271 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 272 | &_CMD_comparespram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, "SPRAM0"); |
| 273 | } |
| 274 | sub CMD_comparespram1 |
| 275 | { |
| 276 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 277 | &_CMD_comparespram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, "SPRAM1"); |
| 278 | } |
| 279 | sub CMD_comparespramall |
| 280 | { |
| 281 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 282 | &_CMD_comparespram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, "SPRAM"); |
| 283 | } |
| 284 | |
| 285 | sub CMD_comparetcm |
| 286 | { |
| 287 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 288 | print"Redirect to memquery comparespram!\n"; |
| 289 | CMD_comparespram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path); |
| 290 | } |
| 291 | |
| 292 | sub CMD_objintcm |
| 293 | { |
| 294 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 295 | print"Redirect to memquery objinspramall!\n"; |
| 296 | CMD_objinspramall($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path); |
| 297 | } |
| 298 | |
| 299 | |
| 300 | sub _CMD_objinspram |
| 301 | { |
| 302 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, $query_range) = @_; |
| 303 | $g_bToLog = 1; |
| 304 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -q $query_range \"$map_path\"", "size".($query_range eq "SPRAM"?"All":""), $makefile, $log_folder); |
| 305 | } |
| 306 | sub CMD_objinspram0 |
| 307 | { |
| 308 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 309 | _CMD_objinspram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, "SPRAM0"); |
| 310 | } |
| 311 | sub CMD_objinspram1 |
| 312 | { |
| 313 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 314 | _CMD_objinspram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, "SPRAM1"); |
| 315 | } |
| 316 | sub CMD_objinspramall |
| 317 | { |
| 318 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 319 | print "This command is euqal to objinspram0 + objinspram1\n"; |
| 320 | _CMD_objinspram($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path, "SPRAM"); |
| 321 | } |
| 322 | |
| 323 | sub CMD_objinl2sram |
| 324 | { |
| 325 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 326 | $g_bToLog = 1; |
| 327 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -q L2SRAM \"$map_path\"", "L2SRAMSize", $makefile, $log_folder); |
| 328 | } |
| 329 | |
| 330 | sub CMD_objin |
| 331 | { |
| 332 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 333 | $g_bToLog = 1; |
| 334 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -q $arg_aref->[0] \"$map_path\"", "ObjSize", $makefile, $log_folder); |
| 335 | } |
| 336 | |
| 337 | sub CMD_symbolinfo |
| 338 | { |
| 339 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 340 | $g_bToLog = 1; |
| 341 | system_cmd_csv("perl ./tools/MemoryUtility/TCMQuery.pl -is $arg_aref->[0] \"$map_path\" \"$sym_path\"", "SymbolInfo", $makefile, $log_folder); |
| 342 | } |
| 343 | |
| 344 | sub CMD_sdatainfo |
| 345 | { |
| 346 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 347 | my $output_log = GetLogName($makefile, $log_folder, "sdata"); |
| 348 | system("perl ./tools/MemoryUtility/TCMQuery.pl -is \"\\.s(data|bss)_0\\.{0,1}\" \"$map_path\" \"$sym_path\" > \"$output_log\""); |
| 349 | system("perl ./tools/MemoryUtility/TCMQuery.pl -is \"\\.s(data|bss)_1\\.{0,1}\" \"$map_path\" \"$sym_path\" >> \"$output_log\""); |
| 350 | print "The output is generated under: $output_log\n"; |
| 351 | } |
| 352 | |
| 353 | sub CMD_l2cachelockinfo |
| 354 | { |
| 355 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 356 | $g_bToLog = 1; |
| 357 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -is \"L2CACHE_LOCK\" \"$map_path\" \"$sym_path\"", "l2cachelock", $makefile, $log_folder); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | sub CMD_discard |
| 362 | { |
| 363 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 364 | $g_bToLog = 1; |
| 365 | system_cmd("perl ./tools/MemoryUtility/QueryDiscardedSym.pl -q \"$map_path\"", "Discard", $makefile, $log_folder); |
| 366 | } |
| 367 | |
| 368 | sub CMD_comparediscard |
| 369 | { |
| 370 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 371 | $g_bToLog = 1; |
| 372 | system_cmd("perl ./tools/MemoryUtility/QueryDiscardedSym.pl -c \"$map_path\" \"$arg_aref->[0]\"", "CompareDiscard", $makefile, $log_folder); |
| 373 | } |
| 374 | |
| 375 | sub CMD_symintcm |
| 376 | { |
| 377 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 378 | print "Redirect to objinspramall!\n"; |
| 379 | CMD_objinspramall(); |
| 380 | } |
| 381 | |
| 382 | sub CMD_syminl2sram |
| 383 | { |
| 384 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 385 | $g_bToLog = 1; |
| 386 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -s L2SRAM \"$sym_path\"", "L2SRAMsymbol", $makefile, $log_folder); |
| 387 | } |
| 388 | |
| 389 | sub CMD_syminspramall |
| 390 | { |
| 391 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 392 | $g_bToLog = 1; |
| 393 | print "This command is euqal to syminspram0 + syminspram1\n"; |
| 394 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -s SPRAM \"$sym_path\"", "SPRAMsymbolAll", $makefile, $log_folder); |
| 395 | } |
| 396 | |
| 397 | sub CMD_syminspram0 |
| 398 | { |
| 399 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 400 | $g_bToLog = 1; |
| 401 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -s SPRAM0 \"$sym_path\"", "SPRAM0symbol", $makefile, $log_folder); |
| 402 | } |
| 403 | |
| 404 | sub CMD_syminspram1 |
| 405 | { |
| 406 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 407 | $g_bToLog = 1; |
| 408 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -s SPRAM1 \"$sym_path\"", "SPRAM1symbol", $makefile, $log_folder); |
| 409 | } |
| 410 | sub CMD_symin |
| 411 | { |
| 412 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 413 | $g_bToLog = 1; |
| 414 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -s $arg_aref->[0] \"$sym_path\"", "SymbolsBySection", $makefile, $log_folder); |
| 415 | } |
| 416 | |
| 417 | sub CMD_syminobj |
| 418 | { |
| 419 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 420 | $g_bToLog = 1; |
| 421 | system_cmd_csv("perl ./tools/MemoryUtility/TCMQuery.pl -so $arg_aref->[0] \"$map_path\" \"$sym_path\"", "SymbolsByObj", $makefile, $log_folder); |
| 422 | } |
| 423 | |
| 424 | sub CMD_syminlib |
| 425 | { |
| 426 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 427 | $g_bToLog = 1; |
| 428 | system_cmd_csv("perl ./tools/MemoryUtility/TCMQuery.pl -sl $arg_aref->[0] \"$map_path\" \"$sym_path\"", "SymbolsByLib", $makefile, $log_folder); |
| 429 | } |
| 430 | |
| 431 | sub CMD_symthreshold |
| 432 | { |
| 433 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 434 | $g_bToLog = 1; |
| 435 | system_cmd_csv("perl ./tools/MemoryUtility/TCMQuery.pl -st $arg_aref->[0] \"$map_path\" \"$sym_path\"", "SymbolsThreshold", $makefile, $log_folder); |
| 436 | } |
| 437 | |
| 438 | sub CMD_diffsymin |
| 439 | { |
| 440 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 441 | $g_bToLog = 1; |
| 442 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -sc $arg_aref->[0] \"$sym_path\" \"$arg_aref->[1]\"", "DiffSymbol", $makefile, $log_folder); |
| 443 | } |
| 444 | |
| 445 | #Only List the difference without existence |
| 446 | sub CMD_diff2symin |
| 447 | { |
| 448 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 449 | $g_bToLog = 1; |
| 450 | system_cmd("perl ./tools/MemoryUtility/TCMQuery.pl -sce $arg_aref->[0] \"$sym_path\" \"$arg_aref->[1]\"", "Diff2Symbol", $makefile, $log_folder); |
| 451 | } |
| 452 | |
| 453 | sub CMD_objinfo |
| 454 | { |
| 455 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 456 | if(scalar(@$arg_aref) == 0) |
| 457 | { |
| 458 | my $output_log = GetLogName($makefile, $log_folder, "ObjectSize"); |
| 459 | system("perl ./tools/MemoryUtility/CompareObjSize.pl \"$map_path\" \"$map_path\" > \"$output_log\" "); |
| 460 | print "The output of all library information is generated under: $output_log\n"; |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | foreach my $obj (@$arg_aref) |
| 465 | { |
| 466 | $obj .= ".obj" if($obj !~ /\.o/); |
| 467 | print "$obj\n===================================================\n"; |
| 468 | system("perl ./tools/MemoryUtility/QuerySize.pl \"$map_path\" $obj"); |
| 469 | print "\n"; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | sub CMD_fillinfo |
| 475 | { |
| 476 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 477 | $g_bToLog = 1; |
| 478 | |
| 479 | system_cmd_csv("perl ./tools/MemoryUtility/TCMQuery.pl -sf $arg_aref->[0] \"$map_path\" \"$sym_path\"", "FillInfo", $makefile, $log_folder); |
| 480 | } |
| 481 | |
| 482 | sub CMD_comparelib |
| 483 | { |
| 484 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 485 | if(scalar(@$arg_aref) < 1) |
| 486 | { |
| 487 | print "Please add the map path after comparelibinfo.\nFor more information, you can refer to memquery -h\n\n"; |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | my $compare_path = $arg_aref->[0]; |
| 492 | my $output_log = GetLogName($makefile, $log_folder, "LibrarySize"); |
| 493 | system("perl ./tools/MemoryUtility/CompareLibrarySize.pl \"$map_path\" \"$compare_path\" > \"$output_log\" "); |
| 494 | print "The output is generated under: $output_log\n"; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | sub CMD_compareobj |
| 499 | { |
| 500 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 501 | if(scalar(@$arg_aref) < 1) |
| 502 | { |
| 503 | print "Please add the map path after compareobjinfo.\nFor more information, you can refer to memquery -h\n\n"; |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | my $compare_path = $arg_aref->[0]; |
| 508 | my $output_log = GetLogName($makefile, $log_folder, "ObjectSize"); |
| 509 | system("perl ./tools/MemoryUtility/CompareObjSize.pl \"$map_path\" \"$compare_path\" > \"$output_log\" "); |
| 510 | print "The output is generated under: $output_log\n"; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | sub CMD_libinfo |
| 515 | { |
| 516 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 517 | if(scalar(@$arg_aref) == 0) |
| 518 | { |
| 519 | my $output_log = GetLogName($makefile, $log_folder, "LibrarySize"); |
| 520 | system("perl ./tools/MemoryUtility/CompareLibrarySize.pl \"$map_path\" \"$map_path\" > \"$output_log\" "); |
| 521 | print "The output of all library information is generated under: $output_log\n"; |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | foreach my $lib (@$arg_aref) |
| 526 | { |
| 527 | if($lib !~ /\.l|\.a/) |
| 528 | { |
| 529 | print "Please add filename extension after $lib. Otherwise it can't be searched properly."; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | print "$lib\n===================================================\n"; |
| 534 | system("perl ./tools/MemoryUtility/QuerySize.pl \"$map_path\" $lib"); |
| 535 | print "\n"; |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | sub CMD_chkmemusage |
| 542 | { |
| 543 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 544 | system_cmd("perl ./tools/MemoryUtility/ChkMemUsage.pl \"$makefile\" \"$lds_path\" \"$map_path\" \"$sym_path\" ", |
| 545 | "chkmemusage", $makefile, $log_folder); |
| 546 | } |
| 547 | |
| 548 | sub CMD_detectZI |
| 549 | { |
| 550 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 551 | |
| 552 | #my $bin_path = GetBinFile($map_path); |
| 553 | my $bin_path = $bin_path; |
| 554 | my $elf_path = $map_path; |
| 555 | $elf_path =~ s/map/elf/g; |
| 556 | my ($nZIpercent, $gnZIthreshold) = ($arg_aref->[0], $arg_aref->[1]); |
| 557 | |
| 558 | $g_bToLog = 1; |
| 559 | |
| 560 | system_cmd("perl ./tools/MemoryUtility/DetectZI.pl \"$sym_path\" \"$map_path\" \"$elf_path\" \"$nZIpercent\" \"$gnZIthreshold\"", |
| 561 | "detectZI_".$nZIpercent."_".$gnZIthreshold, $makefile, $log_folder); |
| 562 | } |
| 563 | |
| 564 | sub CMD_topsizeobj |
| 565 | { |
| 566 | my ($arg_aref, $lds_path, $makefile, $map_path, $sym_path, $log_folder, $bin_path) = @_; |
| 567 | my $output_log = GetLogName($makefile, $log_folder, "TopSizeObj"); |
| 568 | system("perl ./tools/MemoryUtility/ListTopSizeObj.pl \"$map_path\" > \"$output_log\" "); |
| 569 | print "The output is generated under: $output_log\n"; |
| 570 | } |
| 571 | |
| 572 | # We don't use this function since the naming rule of bin file and map file are different in UMOLY |
| 573 | sub GetBinFile() |
| 574 | { |
| 575 | my ($map_path) = @_; |
| 576 | my $binDir = &dirname($map_path)."\/"; |
| 577 | |
| 578 | opendir (DIR, $binDir) or mem_die("can not open bin folder $binDir", __FILE__, __LINE__); |
| 579 | my $binfilePrefix = &basename($map_path, ".map"); |
| 580 | $binfilePrefix =~ s/\_P\_|\_L\_/\_/g; |
| 581 | my @TMP_BIN_FILE = grep { /$binfilePrefix\..+\.bin/ } readdir DIR; |
| 582 | closedir DIR; |
| 583 | if( scalar(@TMP_BIN_FILE) == 0 ) { |
| 584 | opendir (DIR, $binDir) or mem_die("can not open bin folder $binDir", __FILE__, __LINE__); |
| 585 | @TMP_BIN_FILE = grep { /.+\_MDBIN\_.+\..+\.bin/ } readdir DIR; |
| 586 | closedir DIR; |
| 587 | } |
| 588 | mem_die("no bin file is found") if( scalar(@TMP_BIN_FILE) == 0 ); |
| 589 | return $binDir.$TMP_BIN_FILE[0]; |
| 590 | } |
| 591 | |
| 592 | sub CMD_help |
| 593 | { |
| 594 | Usage(); |
| 595 | } |
| 596 | |
| 597 | #**************************************************************************** |
| 598 | # Subroutine: PrintLog |
| 599 | # Parameters: string log |
| 600 | # Returns: x |
| 601 | #**************************************************************************** |
| 602 | sub PrintLog |
| 603 | { |
| 604 | my ($strInput) = @_; |
| 605 | my ($pack_name, $file, $line_no) = caller; |
| 606 | open (FILE_HANDLE, ">>$LOG_PATH") or &mem_die("Cannot open log: $LOG_PATH\n", $file, $line_no); |
| 607 | print FILE_HANDLE $strInput if(defined $strInput); |
| 608 | close FILE_HANDLE; |
| 609 | } |
| 610 | |
| 611 | sub PrintToScreen |
| 612 | { |
| 613 | my ($strInput) = @_; |
| 614 | print $strInput if (defined $strInput); |
| 615 | } |
| 616 | |
| 617 | #**************************************************************************** |
| 618 | # Subroutine: mem_die |
| 619 | # Parameters: 1. string error message, 2. __FILE__ 3. __LINE__ |
| 620 | # Returns: x |
| 621 | #**************************************************************************** |
| 622 | sub mem_die |
| 623 | { |
| 624 | my ($error_msg, $file, $line_no) = @_; |
| 625 | my $pack_name = undef; |
| 626 | if(!defined $file or !defined $line_no) |
| 627 | { |
| 628 | ($pack_name, $file, $line_no) = caller; |
| 629 | } |
| 630 | &CommonUtil::error_handler($error_msg, $file, $line_no, 'Memory Query'); |
| 631 | } |
| 632 | |
| 633 | #**************************************************************************** |
| 634 | # Subroutine: Usage |
| 635 | # Parameters: x |
| 636 | # Returns: x |
| 637 | #**************************************************************************** |
| 638 | sub Usage |
| 639 | { |
| 640 | #system("clear"); # windows: cls, linux: clear |
| 641 | my $make = "m"; |
| 642 | $make = "./m" if ($^O eq "linux") ; |
| 643 | print <<"__EOFUSAGE"; |
| 644 | |
| 645 | ---------------------------------------------------------------------------- |
| 646 | [USAGE] |
| 647 | $make [MAKEFILE] memquery [OPTIONS] |
| 648 | Note: The project must be built before using memquery. |
| 649 | |
| 650 | e.g. |
| 651 | ./m "MT6589_MD1_GPRS(SKYPA).mak" memquery sprammargin |
| 652 | ./m "MT6589_MD1_GPRS(SKYPA).mak" memquery objinfo abc.obj cde.obj |
| 653 | ./m "MT6589_MD1_GPRS(SKYPA).mak" memquery libinfo libabc.a libcde.a |
| 654 | ./m "MT6589_MD1_GPRS(SKYPA).mak" memquery libinfo |
| 655 | ./m "MT6589_MD1_GPRS(SKYPA).mak" memquery symin ROM |
| 656 | [OPTIONS] |
| 657 | help|-h|--help |
| 658 | Show how to use memquer |
| 659 | basicinfo |
| 660 | Show ROM/RAM/PhysicalRAMUsage information |
| 661 | chkmemusage |
| 662 | Check if the memory usage is more than the predefined percentage of hardware provided memory size |
| 663 | detectZI [ZIpercent, ZIthreshold] |
| 664 | List the RW with ZIpercent % of its contents are ZI and the size is larger than ZIthreshold byte. |
| 665 | If no ZIpercentand ZIthreshold and specified, default ZIpercent=100 and ZIthreshold=0 |
| 666 | sprammargin |
| 667 | l2srammargin |
| 668 | Show spram and l2sram left sizes |
| 669 | rammargin |
| 670 | Show ram left sizes |
| 671 | syminspram[all,0,1] |
| 672 | Output the information of all symbol in all spram or SPRAM[0,1] to a log |
| 673 | e.g. syminspramall |
| 674 | syminspram0 |
| 675 | objinspram[all,0,1] |
| 676 | Output the information of all objects in all spram or SPRAM[0,1] to a log |
| 677 | e.g. objinspramall |
| 678 | objinspram0 |
| 679 | comparespram[all,0,1] |
| 680 | Compare object list in all spram or SPRAM[0,1,2] between current project with input map |
| 681 | e.g. comparespramall |
| 682 | comparespram0 |
| 683 | objinl2sram |
| 684 | Output the information of all objects in l2sram to a log |
| 685 | objin 'section,section,...' |
| 686 | Output the information of all objects in specfic section to a log |
| 687 | e.g. objin 'ROM,INTSRAM_CODE' |
| 688 | objin ROM |
| 689 | symin 'section,section,...' |
| 690 | Output the symbol information in specfic section to a log |
| 691 | e.g. symin 'ROM,INTSRAM_CODE' |
| 692 | symin L2SRAM |
| 693 | objinfo [objname] |
| 694 | Show ro/rwzi sizes of these objects |
| 695 | libinfo [libname.l|libname.a] |
| 696 | Show ro/rwzi sizes of these libraries |
| 697 | objinfo |
| 698 | Output all object information to a log |
| 699 | libinfo |
| 700 | Output all library information to a log |
| 701 | symbolinfo |
| 702 | Output symbol information in specfic input section to a log |
| 703 | sdatainfo |
| 704 | Output symbol information in small data sections of core 0~1 to a log |
| 705 | l2cachelockinfo |
| 706 | Output symbol information in static l2cache_lock sections to a log |
| 707 | comparelib [map path] |
| 708 | Compare library list in current project with input map |
| 709 | [NOTE]sym filename should be the same as maps and |
| 710 | be put under the same folder. |
| 711 | compareobj [map path] |
| 712 | Compare object list in current project with input map |
| 713 | [NOTE]sym filename should be the same as maps and |
| 714 | be put under the same folder. |
| 715 | diffsymin 'section,section,...' [sym path] |
| 716 | Compare 2 sym files by section |
| 717 | (List all difference) |
| 718 | diff2symin 'section,section,...' [sym path] |
| 719 | Compare 2 sym files by section |
| 720 | (List only difference if any one symbol doesnt exist) |
| 721 | |
| 722 | |
| 723 | --Redirect command in LR13-- |
| 724 | symintcm |
| 725 | This command will be redirected to syminspramall |
| 726 | objintcm |
| 727 | This command will be redirected to objinspramall |
| 728 | comparetcm [map path] |
| 729 | This command will be redirected to comparespramall |
| 730 | tcmmargin |
| 731 | This command will be redirected to l2srammargin |
| 732 | |
| 733 | |
| 734 | --Not support command in LR13-- |
| 735 | |
| 736 | ---------------------------------------------------------------------------- |
| 737 | __EOFUSAGE |
| 738 | exit 0; |
| 739 | } |