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 | #* ldsInfoWrap.pm |
| 40 | #* |
| 41 | #* Project: |
| 42 | #* -------- |
| 43 | #* |
| 44 | #* |
| 45 | #* Description: |
| 46 | #* ------------ |
| 47 | #* This script is to provide functions for parsing linker script and getting information |
| 48 | #* It helps to cover linker script's insufficient syntax part. |
| 49 | #* e.g. no Load View, no max size...etc |
| 50 | #* |
| 51 | #* Author: |
| 52 | #* ------- |
| 53 | #* Qmei Yang (mtk03726) |
| 54 | #* |
| 55 | #****************************************************************************/ |
| 56 | #**************************************************************************** |
| 57 | # Included Modules |
| 58 | #**************************************************************************** |
| 59 | use strict; |
| 60 | BEGIN { push @INC, './pcore/tools/' } # add additional library path |
| 61 | use CommonUtility; |
| 62 | use ldsInfo; |
| 63 | package ldsInfoWrap; |
| 64 | #**************************************************************************** |
| 65 | # oo >>> Finished |
| 66 | #**************************************************************************** |
| 67 | return 1; |
| 68 | |
| 69 | #**************************************************************************** |
| 70 | # ldsInfoWrap Version |
| 71 | #**************************************************************************** |
| 72 | sub ldsInfoWrap_verno |
| 73 | { |
| 74 | return " u0.06"; |
| 75 | # u0.06 , 20160801 by tero, Removed TCM support |
| 76 | # u0.05 , 20141125 by carl, Added support for SPRAM in SetTCMSize |
| 77 | # u0.04 , 20141125 by carl, Merge ATCM and BTCM as a single TCM |
| 78 | # u0.03 , 20140801 by carl, Refine GetL1COREDumpExeRegions() for dump L1CORE TCM |
| 79 | # u0.02 , 20140503 by carl, Remove unused library path |
| 80 | # u0.01 , 20140220 by BM, Initial revision |
| 81 | # ... |
| 82 | # m0.07 , 20131023 by mei, Fix SECURE_RO's bug |
| 83 | # m0.06 , 20130503 by mei, Export GetMEMROYInfo and GetMEMROYInfoByName from ldsInfo.pm |
| 84 | # m0.05_From WR8 , 20121219 by mei, Support SECURE_RO |
| 85 | # m0.05 , 20121002 by mei, Support MT7208 BTCM1 |
| 86 | # m0.04 , 20120911 by mei, Support setting Load Region |
| 87 | # m0.03 , 20120724 by mei, Use MaxSize directly except getting TCMSize from MEMORY |
| 88 | # m0.02 , 20120528 by mei, Support path and filename case sensitive on Linux |
| 89 | # m0.01 , 20120528 by mei, initial version |
| 90 | } |
| 91 | |
| 92 | |
| 93 | sub new |
| 94 | { |
| 95 | my $class = shift; |
| 96 | my $self = {}; |
| 97 | my ($strFakeLoadRegionName) = @_; |
| 98 | #default value |
| 99 | $self->{ldsInfo} = new ldsInfo; |
| 100 | #default value |
| 101 | $self->{ldsPath} = undef; |
| 102 | $self->{MEMORY} = undef; #=string |
| 103 | $self->{SECTIONS} = undef; #=string |
| 104 | |
| 105 | $self->{FAKE_LRName} = $strFakeLoadRegionName; |
| 106 | |
| 107 | $self->{ExeRegion} = {}; #%g_ExeRegion; (start from 1) |
| 108 | # nIndex => [$1=Region name, $2=strBaseAddress, $3=strOffset, $4=nMaxSize, $5=\@Attribute] |
| 109 | $self->{ExeRegionCount} = 0; #$g_ExeRegionCount = 0; |
| 110 | $self->{ExeRegionLookUpTable} = {}; #%g_ExeRegionLookUpTable; # RegionName -> Index |
| 111 | |
| 112 | $self->{MemoryView} = {}; # %g_MemoryView; (start from 1) |
| 113 | # $RegionName => [$ExecutionView, $LoadView]; |
| 114 | $self->{InputSection} = {}; # $self->{InputSection}{$strRegionName} = @InputSections; |
| 115 | #$self->{EXCLUDE_FILE} = {}; # $self->{EXCLUDE_FILE}{$strInputSection} = @files; |
| 116 | $self->{RegionMap} = undef; |
| 117 | bless $self, $class; |
| 118 | return $self; |
| 119 | } |
| 120 | sub ParseLinkerScript |
| 121 | { |
| 122 | my $self = shift; |
| 123 | my ($strLDSPath) = @_; |
| 124 | $self->{ldsInfo}->ParseLinkerScript($strLDSPath); |
| 125 | #default value |
| 126 | $self->{ldsPath} = $self->{ldsInfo}->{ldsPath}; |
| 127 | $self->{MEMORY} = $self->{ldsInfo}->{MEMORY}; #=string |
| 128 | $self->{SECTIONS} = $self->{ldsInfo}->{SECTIONS}; #=string |
| 129 | $self->{MEMORYInfo} = $self->{ldsInfo}->{MEMORYInfo}; #aref: [$strName, $strBase, $strLength] |
| 130 | $self->{ExeRegion} = $self->{ldsInfo}->{ExeRegion}; #%g_ExeRegion; (start from 1) |
| 131 | # nIndex => [$1=Region name, $2=strBaseAddress, $3=strOffset, $4=nMaxSize, $5=\@Attribute] |
| 132 | $self->{ExeRegionCount} = $self->{ldsInfo}->{ExeRegionCount}; #$g_ExeRegionCount = 0; |
| 133 | $self->{ExeRegionLookUpTable} = $self->{ldsInfo}->{ExeRegionLookUpTable}; #%g_ExeRegionLookUpTable; # RegionName -> Index |
| 134 | |
| 135 | $self->{MemoryView} = $self->{ldsInfo}->{MemoryView}; # %g_MemoryView; (start from 1) |
| 136 | # $RegionName => [$ExecutionView, $LoadView]; |
| 137 | $self->{InputSection} = $self->{ldsInfo}->{InputSection}; # $self->{InputSection}{$strRegionName} = @InputSections; |
| 138 | |
| 139 | $self->SetLoadRegion(); |
| 140 | $self->SetTCMSize(); #Set TCMSize due to linker script using MEMORY to limit TCM not ASSERT |
| 141 | } |
| 142 | |
| 143 | sub GetMEMROYInfo |
| 144 | { |
| 145 | my $self = shift; |
| 146 | return $self->{ldsInfo}->GetMEMROYInfo(); |
| 147 | } |
| 148 | |
| 149 | sub GetMEMORYInfoByName |
| 150 | { |
| 151 | my $self = shift; |
| 152 | my ($strRegionName) = @_; |
| 153 | return $self->{ldsInfo}->GetMEMORYInfoByName($strRegionName); |
| 154 | } |
| 155 | |
| 156 | sub SetTCMSize |
| 157 | { |
| 158 | my $self = shift; |
| 159 | foreach (@{$self->{MEMORYInfo}}) |
| 160 | { |
| 161 | if($_->[0] =~ /^[ID]SPRAM[0-2]/) |
| 162 | { |
| 163 | my $SPRAMIndex = $self->{ExeRegionLookUpTable}{$_->[0]}; |
| 164 | $self->{ExeRegion}{$SPRAMIndex}->[InfoIndex::MaxSize] = hex($_->[2]); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | #**************************************************************************** |
| 169 | # subroutine: SetLoadRegion |
| 170 | # helps to setting HardCode Load Region in linker script |
| 171 | # for prompting cfggen and binfile generation |
| 172 | # input: N/A |
| 173 | # output: N/A |
| 174 | #**************************************************************************** |
| 175 | sub SetLoadRegion |
| 176 | { |
| 177 | my $self = shift; |
| 178 | my $strFakeLRName = $self->{FAKE_LRName}; |
| 179 | foreach (1..$self->{ExeRegionCount}) |
| 180 | { |
| 181 | my $ER = $self->{ExeRegion}{$_}; |
| 182 | # nIndex => [$1=Region name, $2=strBaseAddress, $3=strOffset, $4=nMaxSize, $5=\@Attribute] |
| 183 | my $strERName = $ER->[0]; |
| 184 | if($strERName =~ /BOOT_CERT/) |
| 185 | { |
| 186 | ++$self->{LoadRegionCount}; |
| 187 | $self->{LoadRegionLookUpTable}{$strERName} = $self->{LoadRegionCount}; |
| 188 | #%g_LoadRegionLookUpTable; # RegionName -> Index |
| 189 | $self->{LoadRegion}{$self->{LoadRegionCount}} = [$strERName, $ER->[1], $ER->[2], $ER->[3], $ER->[4], ()]; |
| 190 | # => [$1=Region name, $2=ImageLimit(Previous region) or strBaseAddress, $3=strOffset, $4=nMaxSize, $5=\@Attribute] |
| 191 | push( @{$self->{RegionMap}{$strERName}}, $strERName); |
| 192 | } |
| 193 | elsif($strERName =~ /SECURE_RO/) |
| 194 | { |
| 195 | if(!exists $self->{RegionMap}{SECURE_RO}) |
| 196 | { |
| 197 | ++$self->{LoadRegionCount}; |
| 198 | $self->{LoadRegionLookUpTable}{SECURE_RO} = $self->{LoadRegionCount}; |
| 199 | #%g_LoadRegionLookUpTable; # RegionName -> Index |
| 200 | $self->{LoadRegion}{$self->{LoadRegionCount}} = ["SECURE_RO", $ER->[1], $ER->[2], $ER->[3], $ER->[4], ()]; |
| 201 | # => [$1=Region name, $2=ImageLimit(Previous region) or strBaseAddress, $3=strOffset, $4=nMaxSize, $5=\@Attribute] |
| 202 | } |
| 203 | push( @{$self->{RegionMap}{SECURE_RO}}, $strERName); |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | if(!exists $self->{LoadRegionLookUpTable}{$strFakeLRName}) |
| 208 | { |
| 209 | ++$self->{LoadRegionCount}; |
| 210 | $self->{LoadRegionLookUpTable}{$strFakeLRName} = $self->{LoadRegionCount}; |
| 211 | $self->{LoadRegion}{$self->{LoadRegionCount}} = [$strFakeLRName, $ER->[1], $ER->[2], $ER->[3], $ER->[4], ()]; |
| 212 | } |
| 213 | push( @{$self->{RegionMap}{$strFakeLRName}}, $strERName); |
| 214 | } |
| 215 | } |
| 216 | #map{print "$_\n"}keys %{$self->{RegionMap}}; |
| 217 | } |
| 218 | |
| 219 | #**************************************************************************** |
| 220 | # subroutine: SearchExeRegionName |
| 221 | # to get the first execution region name by keyword searching |
| 222 | # input: Keyword |
| 223 | # output: RegionName: undef means it's not existent |
| 224 | #**************************************************************************** |
| 225 | sub SearchExeRegionName |
| 226 | { |
| 227 | my $self = shift; |
| 228 | my ($strKey) = @_; |
| 229 | my $strRegion = undef; |
| 230 | foreach my $strTemp (keys %{$self->{ExeRegionLookUpTable}}) |
| 231 | { |
| 232 | if($strTemp =~ /$strKey/) |
| 233 | { |
| 234 | $strRegion = $strTemp; |
| 235 | last; |
| 236 | } |
| 237 | } |
| 238 | return $strRegion; |
| 239 | } |
| 240 | |
| 241 | #**************************************************************************** |
| 242 | # subroutine: ldsWrap_die |
| 243 | # sample code: (message, __FILE__, __LINE__) |
| 244 | # input: $error_msg, $file, $line_no |
| 245 | #**************************************************************************** |
| 246 | sub ldsWrap_die |
| 247 | { |
| 248 | my ($error_msg, $file, $line_no) = (@_); |
| 249 | &CommonUtil::error_handler($error_msg, $file, $line_no, 'ldsInfoWrap'); |
| 250 | } |