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 | #* Parsing_Padding_Info.pm |
| 40 | #* |
| 41 | #* Project: |
| 42 | #* -------- |
| 43 | #* |
| 44 | #* |
| 45 | #* Description: |
| 46 | #* ------------ |
| 47 | #* This script is used to get unused memory info. |
| 48 | #* |
| 49 | #* |
| 50 | #* Author: |
| 51 | #* ------- |
| 52 | #* Yao Liu (mtk15073) |
| 53 | #* |
| 54 | #*------------------------------------------------------------------------------ |
| 55 | #* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 56 | #*============================================================================ |
| 57 | #****************************************************************************/ |
| 58 | use strict; |
| 59 | |
| 60 | BEGIN { push @INC, './tools/MemoryUtility/' } # add additional library path |
| 61 | use BasicMemInfoQuery; |
| 62 | use LinkerOutputParser; |
| 63 | |
| 64 | package Parsing_Padding_Info; |
| 65 | use constant LOG => 0; |
| 66 | use constant WARNING => 1; |
| 67 | use constant FATAL => 2; |
| 68 | |
| 69 | sub get_padding_info |
| 70 | { |
| 71 | my ($platform, $c2k_mode_support, $themf, $scat, $map_file, $sym_file) = @_; |
| 72 | |
| 73 | my ($nRAMUsage, @raminfo); |
| 74 | if ($platform eq "MT6297" || $platform eq "MT6885" || $platform eq "MT6873" || $platform eq "MT6893" || $platform eq "MT6853") { |
| 75 | ($nRAMUsage, @raminfo) = &BasicMemInfo::DispatchCommand("CMD_GetRAMUsage", $themf, $scat, $map_file, $sym_file, undef); |
| 76 | return @raminfo; |
| 77 | } else { |
| 78 | &LinkerOutputParser::FileParse($sym_file); |
| 79 | my $ERinRAM_aref = &BasicMemInfo::GetERsInRAM($themf, $scat, $map_file, $sym_file, undef); |
| 80 | |
| 81 | my $nDummyEndBase = hex(&LinkerOutputParser::Get_DUMMY_END_Base()); |
| 82 | my $ROM_size = &BasicMemInfo::CMD_GetROMSize($themf, $scat, $map_file, $sym_file); |
| 83 | my @FreeRAMAreas; |
| 84 | my @UsedRAMAreas; |
| 85 | |
| 86 | foreach my $ER (@$ERinRAM_aref) #Go through all regions in ram |
| 87 | { |
| 88 | my $strERsize = LinkerOutputParser::GetExeRegionInfo($ER, Region::Size); |
| 89 | my $strERbase = &LinkerOutputParser::GetExeRegionInfo($ER, Region::VMA); |
| 90 | my $nERaddr = get_EMI_offset(hex($strERbase), $ER, $platform, $c2k_mode_support); |
| 91 | msg_handler(FATAL, "Section $ER base address($strERbase) or end address($strERbase + $strERsize) is bigger than total memory size!\nEMI offset is $nERaddr.\n") |
| 92 | if ($nERaddr > $nDummyEndBase || ($nERaddr + hex($strERsize)) > $nDummyEndBase); |
| 93 | |
| 94 | if (hex($strERsize)) { |
| 95 | my $ERsize = hex($strERsize); |
| 96 | my $append = 0; |
| 97 | my $note = undef; |
| 98 | |
| 99 | foreach my $used (@UsedRAMAreas) { |
| 100 | if(($used->[0]<=$nERaddr) and (($used->[0]+$used->[1])>=$nERaddr)) { |
| 101 | if (($used->[0]+$used->[1])<($nERaddr+$ERsize)){ |
| 102 | $used->[1]= ($nERaddr+$ERsize)-$used->[0]; |
| 103 | } |
| 104 | $append = 1; |
| 105 | } elsif (($used->[0]<=($nERaddr+$ERsize)) and (($used->[0]+$used->[1])>=($nERaddr+$ERsize))) { |
| 106 | if ($used->[0] > $nERaddr) { |
| 107 | $used->[1] += $used->[0] - $nERaddr; |
| 108 | $used->[0] = $nERaddr; |
| 109 | } |
| 110 | $append = 1; |
| 111 | } |
| 112 | if ($append == 1) { |
| 113 | $used->[2] = $note if($note ne undef); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if ($append == 1) { |
| 118 | $append = 0; |
| 119 | } else { |
| 120 | push @UsedRAMAreas, [$nERaddr, $ERsize, $note] |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | @UsedRAMAreas = sort {$a->[0]<=>$b->[0]} @UsedRAMAreas; |
| 126 | |
| 127 | if($ROM_size < $UsedRAMAreas[0][0]) { |
| 128 | push @FreeRAMAreas, [$ROM_size,$UsedRAMAreas[0][0] - $ROM_size]; |
| 129 | } |
| 130 | for( my $i = 0;$i < $#UsedRAMAreas;$i+=1) |
| 131 | { |
| 132 | my $freeStart =$UsedRAMAreas[$i][0]+$UsedRAMAreas[$i][1]; |
| 133 | my $freeSize =$UsedRAMAreas[$i+1][0]-$freeStart; |
| 134 | push @FreeRAMAreas, [$freeStart,$freeSize] if ($freeSize > 0); |
| 135 | } |
| 136 | |
| 137 | @FreeRAMAreas =sort {$b->[1] <=> $a->[1]} @FreeRAMAreas; |
| 138 | my @RAMMargins; |
| 139 | foreach my $refUsed (@FreeRAMAreas) { |
| 140 | my $MarginStart = ($refUsed->[0]+ 0xffff) & 0xffff0000; |
| 141 | my $MarginLength = (($refUsed->[0] + $refUsed->[1]) & 0xffff0000) - $MarginStart; |
| 142 | next if($MarginLength < 0x10000); |
| 143 | |
| 144 | push @RAMMargins, [$MarginStart,$MarginLength]; |
| 145 | } |
| 146 | |
| 147 | for (my $item_count = $#RAMMargins+1; $item_count < 8; $item_count+=1) { |
| 148 | push @RAMMargins, [0,0]; |
| 149 | } |
| 150 | @RAMMargins = sort {$b->[1] <=> $a->[1]} @RAMMargins; |
| 151 | splice @RAMMargins, 8; |
| 152 | |
| 153 | return @RAMMargins; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | sub get_EMI_offset() |
| 159 | { |
| 160 | my ($address, $section_name, $platform, $c2k_support) = @_; |
| 161 | my $addr_mask = 0x0fffffff; |
| 162 | my $bank = $address>>28; |
| 163 | if (($bank == 1) || ($bank == 7)) |
| 164 | { |
| 165 | $addr_mask = 0x1fffffff; |
| 166 | } |
| 167 | my $phsical_addr = $address & $addr_mask; |
| 168 | if ($section_name eq "EXTSRAM_L1DSP_ZI" and ($platform eq "MT6880" or $platform eq "MT6890" or $platform eq "MT2735")) { |
| 169 | if ($c2k_support eq "NONE"){ |
| 170 | $phsical_addr -= 0xE000000; |
| 171 | } elsif ($c2k_support ne "NONE") { |
| 172 | $phsical_addr -= 0xA000000; |
| 173 | } else { |
| 174 | msg_handler(FATAL, "Please check the C2K_SUPPORT status($c2k_support).\n"); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | return $phsical_addr; |
| 179 | } |
| 180 | |
| 181 | sub msg_handler |
| 182 | { |
| 183 | my ($type, $msg, $line_no, $file_name) = (@_); |
| 184 | my $prompt_prefix; |
| 185 | if($type == LOG) { |
| 186 | print $msg . "\n"; |
| 187 | } |
| 188 | elsif($type == WARNING) { |
| 189 | $prompt_prefix = ">> AAIS Warning : "; |
| 190 | my $location = (defined $file_name) ? "[$file_name] " : ""; |
| 191 | print $prompt_prefix . $location . $msg . "\n"; |
| 192 | } |
| 193 | elsif($type == FATAL) { |
| 194 | $prompt_prefix = ">> *** AAIS Fatal : "; |
| 195 | my $location = (defined $file_name) ? "[$file_name] " : ""; |
| 196 | $location .= "[at line $line_no] "; |
| 197 | die $prompt_prefix . $location . $msg . "\n"; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 202 | |
| 203 | 1; |
| 204 | |