blob: c17d4eaa4d6f10620a692e7b28da55f2af91e0d7 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#!/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#* EMI_MPIinfo.pm
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This script is used to get linker symbol for setting EMI RMPU
48#*
49#*
50#* Author:
51#* -------
52#* KC Tsai (mtk06471)
53#*
54#*------------------------------------------------------------------------------
55#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56#*============================================================================
57#****************************************************************************/
58
59BEGIN { push @INC, './common/tools/MemoryUtility/' } # add additional library path
60use LinkerOutputParser;
61use CommonUtility;
62use FileInfoParser;
63
64package EMI_MPUinfo;
65
66use constant ATTR__NO_PROTECTION => 0x0;
67use constant ATTR_________SEC_RW => 0x1;
68use constant ATTR__SEC_RW_NSEC_R => 0x2;
69use constant ATTR__SEC_RW_NSEC_W => 0x3;
70use constant ATTR___SEC_R_NSEC_R => 0x4;
71use constant ATTR______FORBIDDEN => 0x5;
72use constant ATTR__SEC_R_NSEC_RW => 0x6;
73use constant ATTR________UNUNSED => 0xF;
74
75
76
77############# user configuration##############
78
79my $nKBalign = 64; # 64KB alignment
80#
81# please align this setting with EMI_MPU_REGION in custom_scatstruct.c.template
82#
83my @aEMI_MPU_config = (
84 # Bas of MCURO HWRW
85 [LinkerSymPrefix::Image, "MCURO_HWRW",LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 0
86 # Bas of MCURW HWRO
87 [LinkerSymPrefix::Image,"EXTSRAM" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 1
88 # Bas of MCURW HWRW
89 [LinkerSymPrefix::Image,"EXTSRAM_MCURW_HWRW",LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 2
90 # Bas of MD end
91 [LinkerSymPrefix::Image,"DUMMY_END" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 3
92 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 4
93 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 5
94 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 6
95 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 7
96);
97
98#######################################
99
100my $version = "u0.08";
101 # u0.08, 2016/05/17, Carl, refine setting for ELBRUS
102 # u0.07, 2016/03/09, Carl, refine setting for ELBRUS
103 # u0.06, 2015/08/26, Carl, return directly for ELBRUS
104 # u0.05, 2015/07/06, Carl, return directly when processing TCM only load
105 # u0.04, 2015/04/15, Carl, refine setting for (MCU RO, MDHW RW) DNC+NC, (MCU RW, MDHW RW) DNC+NC
106 # u0.03, 2015/04/02, Carl, refine setting
107 # u0.02, 2015/03/30, Carl, refine setting
108 # u0.01, 2015/01/31, Carl, return EMI RMPU settion
109
110sub retrieveEMI_MPU_info()
111{
112 my ($strFilePath, $themf) = @_;
113 my $nAvailableChannel=-1;
114 my @aEMI_MPU;
115 my @aEMI_Domain;
116
117
118 &FileInfo::Parse_MAKEFILE($themf, \%g_MAKEFILE_OPTIONS);
119 if (FileInfo::is("MTK_MODEM_ARCH", "MT6297") or FileInfo::is("MTK_MODEM_ARCH", "MT6297P")) {
120 @aEMI_MPU_config = (
121 # Bas of MCURO HWRW
122 [LinkerSymPrefix::Image,"MCURO_HWRW" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 0
123 # Bas of MCURW HWRO
124 [LinkerSymPrefix::Image,"EXTSRAM" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 1
125 # Bas of MCURW HWRW
126 [LinkerSymPrefix::Image,"DYNAMIC_CACHEABLE_EXTSRAM_DEFAULT_NONCACHEABLE_MCURW_HWRW",LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 2
127 # Bas of MD end
128 [LinkerSymPrefix::Image,"DUMMY_END" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 3
129 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 4
130 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 5
131 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 6
132 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 7
133 );
134 } else {
135 @aEMI_MPU_config = (
136 # Bas of MCURO HWRW
137 [LinkerSymPrefix::Image, "MCURO_HWRW",LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 0
138 # Bas of MCURW HWRO
139 [LinkerSymPrefix::Image,"EXTSRAM" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 1
140 # Bas of MCURW HWRW
141 [LinkerSymPrefix::Image,"EXTSRAM_MCURW_HWRW",LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 2
142 # Bas of MD end
143 [LinkerSymPrefix::Image,"DUMMY_END" ,LinkerSymPostfix::Base, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 3
144 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 4
145 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 5
146 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 6
147 [0 ,"" ,0 , ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED, ATTR________UNUNSED], # 7
148 );
149 }
150 if( &FileInfo::find("TCM_ONLY_LOAD", "TRUE") )
151 {
152 return (0, undef, undef);
153 }
154
155
156 LinkerOutputParser::FileParse($strFilePath);
157
158
159# offset(base), size
160 my $base=0;
161 for( my $i=0; $i<scalar(@aEMI_MPU_config); ++$i)
162 {
163 my $channel_ref = @aEMI_MPU_config[$i];
164 if( @{$channel_ref}[1] ne "" )
165 {
166 my $end_addr = &get_Physical_Addr(@{$channel_ref}[0],@{$channel_ref}[1],@{$channel_ref}[2]);
167 push @aEMI_MPU, [$base, $end_addr-$base];
168 $base = $end_addr;
169 }
170 else
171 {
172 $nAvailableChannel = $i if ($nAvailableChannel==-1);
173 push @aEMI_MPU, [0,0];
174 $base = 0;
175 }
176 }
177
178# domain, 4 = nNumEmiMuDomain
179 for( my $i=0; $i<4; ++$i)
180 {
181 my $nChannelAttr = 0;
182 for( my $j=0; $j<scalar(@aEMI_MPU_config); ++$j)
183 {
184 my $channel_ref = @aEMI_MPU_config[$j];
185 $nChannelAttr |= @{$channel_ref}[3+$i] << ($j*4);
186 }
187 push @aEMI_Domain, $nChannelAttr;
188 }
189
190 return ($nAvailableChannel, \@aEMI_MPU, \@aEMI_Domain);
191}
192
193sub get_Physical_Addr()
194{
195 my ($nPrefix, $strName, $nPostfix) = @_;
196
197 my $strSymbol = "0x0FFFFFFF & ";
198
199 $strSymbol.= "Image\$\$" if( $nPrefix == LinkerSymPrefix::Image );
200 $strSymbol.= "Load\$\$" if( $nPrefix == LinkerSymPrefix::Load );
201 $strSymbol.= $strName;
202 $strSymbol.= "\$\$Base" if( $nPostfix == LinkerSymPostfix::Base );
203 $strSymbol.= "\$\$Limit" if( $nPostfix == LinkerSymPostfix::Limit );
204 $strSymbol.= "\$\$ZIBase" if( $nPostfix == LinkerSymPostfix::ZIBase );
205 $strSymbol.= "\$\$ZILimit" if( $nPostfix == LinkerSymPostfix::ZILimit );
206
207 my $strAddr = &LinkerOutputParser::GetLinkerSymbolAddress( $strName, $nPostfix, $nPrefix );
208 &EMP_MPUinfo_die("no linker symbol $strSymbol") if (defined $strAddr == undef);
209
210 my $nAddr = hex($strAddr);
211 #mask the Bank bits
212 if(($nAddr & 0xF0000000) == 0x70000000) {
213 $nAddr = $end_addr & 0x1FFFFFFF;
214 } elsif(($nAddr & 0xF0000000) > 0x10000000) {
215 $nAddr = $nAddr & 0x0FFFFFFF;
216 }
217 $strAddr = CommonUtil::Dec2Hex($nAddr);
218 &EMP_MPUinfo_die("symbol $strSymbol address $strAddr is not $nKBalign KB alignment") if ($nAddr != &CommonUtil::GetKBAligned($nAddr, $nKBalign));
219
220 $strSymbol.= " = $strAddr = $nAddr\n";
221 print $strSymbol;
222
223 return $nAddr;
224}
225
226sub EMP_MPUinfo_die
227{
228 my ($error_msg, $file, $line_no) = @_;
229 my $pack_name = undef;
230 if(!defined $file or !defined $line_no)
231 {
232 ($pack_name, $file, $line_no) = caller;
233 }
234 &CommonUtil::error_handler($error_msg, $file, $line_no, 'EMP_MPUinfo');
235}
236
237