blob: 6e36ab7232e4c9325221a6c4e6e70d99bf0472cf [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/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#* PcoreUpdateDSPAddress.pl
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This script is used to modify elf file for share buffer mechanism
48#*
49#*
50#* Author:
51#* -------
52#* Carl Kao (mtk08237)
53#*
54#*------------------------------------------------------------------------------
55#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56#*============================================================================
57#****************************************************************************/
58#****************************************************************************
59# Included Modules
60#****************************************************************************
61use strict;
62BEGIN { push @INC, './pcore/tools/', './common/tools/MemoryUtility/' } # add additional library path
63use SymFileParser; #tools of pcore
64
65
66#****************************************************************************
67# Constants
68#****************************************************************************
69my $PCORE_UPDATE_DSP_ADDRESS_VERNO = " v0.03";
70 # v0.03 , 2015/06/18, Refine error message for avoid false alarm in EWS build
71 # v0.02 , 2015/01/19, Memory Utility Refinement
72 # v0.01 , 2014/07/18, Initial revision
73
74#****************************************************************************
75# Input
76#****************************************************************************
77my $PCORE_SYM_FILE = $ARGV[0];
78my $PCORE_ELF_FILE = $ARGV[1];
79my $L1CORE_SYM_FILE = $ARGV[2];
80my $BM_NEW = $ARGV[3];
81
82print "Input:\n";
83print map{ "\t".$_."\n" } @ARGV ;
84
85
86#****************************************************************************
87# Variable for configuation
88#****************************************************************************
89my $strPcoreSymbolName = "g_dsp_bin_ptr";
90my $strL1coreSymbolName = "dsp_bin";
91
92
93#****************************************************************************
94# >>> Main Flow
95#****************************************************************************
96# fix build error for MIPS
97exit 0;
98
99# add below checking for avoid false alarm in EWS build
100&CheckParamForEWS();
101
102# 1. parsing L1CORE SYM "first"
103SymFileParser::ParseSYM($L1CORE_SYM_FILE);
104my $l1coreSymbolRef = SymFileParser::GetSymbol();
105my $nl1coreDSPSectionAddr = hex(@{$l1coreSymbolRef->{$strL1coreSymbolName}}[Symbol::Addr]);
106
107pcoreUpdateDSPSection_die("[1.0] LCORE variable not exist", __FILE__, __LINE__) if( $nl1coreDSPSectionAddr == undef );
108
109
110
111# 2. then parsing PCORE SYM FIRST
112SymFileParser::ParseSYM($PCORE_SYM_FILE);
113my $pcoreSymbolRef = SymFileParser::GetSymbol();
114my $nPcorePtrAddr = hex(@{$pcoreSymbolRef->{$strPcoreSymbolName}}[Symbol::Addr]);
115
116pcoreUpdateDSPSection_die("[2.0] PCORE variable not exist", __FILE__, __LINE__) if( $nPcorePtrAddr == undef );
117
118
119
120# 3. get section info
121my $strPcoreSymSection = "ROM";
122my $nPcoreSymSectionVMA = hex(SymFileParser::GetExeRegionInfo($strPcoreSymSection, Region::VMA));
123my $nPcoreSymSectionOffset = hex(SymFileParser::GetExeRegionInfo($strPcoreSymSection, Region::Offsets));
124
125
126
127# 4. update l1core symbol address to pcore elf
128my $nAddrInElf = $nPcorePtrAddr + ($nPcoreSymSectionOffset - $nPcoreSymSectionVMA);
129ModifyElf($nAddrInElf, $nl1coreDSPSectionAddr);
130printf("strPcoreSymbolName:\t%s,\tnl1coreDSPSectionAddr:\t0x%.8x\n", $strPcoreSymbolName, $nl1coreDSPSectionAddr);
131printf("strL1coreSymbolName:\t%s,\tnPcorePtrAddr:\t0x%.8x\n", $strL1coreSymbolName, $nPcorePtrAddr);
132printf("nPcoreSymSectionVMA:\t0x%.8x,\tnAddrInElf:\t0x%.8x\n", $nPcoreSymSectionVMA, $nAddrInElf);
133
134exit 0;
135
136#****************************************************************************
137# Subroutines
138#****************************************************************************
139sub ModifyElf
140{
141 my ($ModifyAddr, $nModifyValue) = (@_);
142 my $buffer;
143
144 open (FILE_HANDLE, "+<$PCORE_ELF_FILE") or &ReadElf_die("[2.0]$PCORE_ELF_FILE: file error!", __FILE__, __LINE__);
145 binmode FILE_HANDLE;
146 seek FILE_HANDLE,$ModifyAddr,0;
147 $buffer = pack("L", $nModifyValue);
148 print FILE_HANDLE $buffer;
149}
150
151
152#---------------------------------------------------------------------
153
154
155sub pcoreUpdateDSPSection_die
156{
157 my ($error_msg, $file, $line_no) = @_;
158 my $pack_name = undef;
159 if(!defined $file or !defined $line_no)
160 {
161 ($pack_name, $file, $line_no) = caller;
162 }
163 &CommonUtil::error_handler($error_msg, $file, $line_no, 'PCORE_DSP_SECTION_UPDATE');
164}
165
166
167#---------------------------------------------------------------------
168
169
170sub CheckParam
171{
172 my ($stage, $file, $checkCore) = @_;
173
174 if(!(defined $file and -e $file))
175 {
176 if($BM_NEW ne "bm_new")
177 {
178 &pcoreUpdateDSPSection_die("[Parameter $stage] $file doesn't exist. \"Please fix $checkCore build error (check error message in log folder) to avoid this error!\"", __FILE__, __LINE__)
179 }
180 else
181 {
182 print("[Parameter $stage] $file doesn't exist. \"Please fix $checkCore build error (check error message in log folder) to avoid this build check!\"", __FILE__, __LINE__);
183 exit 0;
184 }
185 }
186}
187
188
189#---------------------------------------------------------------------
190
191
192sub CheckParamForEWS
193{
194 my $count = 1;
195
196 &CheckParam($count++, $PCORE_SYM_FILE, "Pcore");
197 &CheckParam($count++, $PCORE_ELF_FILE, "Pcore");
198 &CheckParam($count++, $L1CORE_SYM_FILE,"L1core");
199}
200