blob: ac80d4d7fac7e41b3b4073c0c1a636279caf77a1 [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) 2011
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#*============================================================================
38#* HISTORY
39#* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
40#*------------------------------------------------------------------------------
41#* $Revision$
42#* $Modtime$
43#* $Log$
44#*
45#* 02 22 2018 raymondwt.chen
46#* [MOLY00307580] [MT6295] Fix bootrom jump address
47#* .
48#*
49#* 12 20 2016 raymondwt.chen
50#* [MOLY00219375] [UMOLYA][Call for checkin] GFH header for MT6293
51#* .
52#*
53#* 08 07 2015 hc.yang
54#* [MOLY00136062] [System Service] Merge Nucleus/KAL changes from 91 Plus DEV to UMOLY Trunk
55#* check in make/l1core folder modification
56#*
57#* 01 20 2015 raymondwt.chen
58#* [MOLY00092726] [TK6291] [SystemService][Auto-Gen] Memory Utility Refinement
59#* .
60#*
61#* 09 21 2014 raymondwt.chen
62#* .Fix after layout change
63#*
64#*
65#*------------------------------------------------------------------------------
66#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
67#*============================================================================
68#****************************************************************************/
69#****************************************************************************
70# Included Modules
71#****************************************************************************
72use strict;
73BEGIN { push @INC, './tools/', './tools/MemoryUtility/' } # add additional library path
74use LinkerOutputParser;
75
76
77#****************************************************************************
78# Variables
79#****************************************************************************
80my $maxIVRegionSize = 0x400;
81
82#****************************************************************************
83# Input
84#****************************************************************************
85my ($elf_file,$sym_file)=@ARGV;
86print "Input: $elf_file $sym_file\n";
87
88
89#****************************************************************************
90# >>> Main Flow
91#****************************************************************************
92
93# 1. parsing PCORE SYM
94&LinkerOutputParser::FileParse($sym_file);
95
96# 2. get section info
97my $nInitialVectorCodeBase = hex(&LinkerOutputParser::GetLinkerSymbolAddress("INT_VECTOR_CODE", LinkerSymPostfix::Base, LinkerSymPrefix::None));
98my $nInitialVectorCodeLimit = hex(&LinkerOutputParser::GetLinkerSymbolAddress("INT_VECTOR_CODE", LinkerSymPostfix::Limit, LinkerSymPrefix::None));
99my $nSizeInitialVector = $nInitialVectorCodeLimit - $nInitialVectorCodeBase;
100my $nAUROMCodeBase = hex(&LinkerOutputParser::GetLinkerSymbolAddress("AUROM", LinkerSymPostfix::Base, LinkerSymPrefix::Image));
101printf "INT_VECTOR_CODE base : 0x%x\n", $nInitialVectorCodeBase;
102printf "INT_VECTOR_CODE limit : 0x%x\n", $nInitialVectorCodeLimit;
103printf "INT_VECTOR_CODE size : 0x%x\n", $nSizeInitialVector;
104printf "AUROM base : 0x%x\n", $nAUROMCodeBase;
105
106my $nROMIVRegionOffset_InELF = hex(&LinkerOutputParser::GetExeRegionInfo("ROM_GFH", Region::Offsets));
107printf "IV Region file offset in ELF : 0x%x\n", $nROMIVRegionOffset_InELF;
108
109my $nAUROMOffset_InELF = hex(&LinkerOutputParser::GetExeRegionInfo("AUROM", Region::Offsets));
110my $nINTVectorOffset_InELF = $nAUROMOffset_InELF + ($nInitialVectorCodeBase - $nAUROMCodeBase);
111printf "INT Vector offset in ELF : 0x%x\n", $nINTVectorOffset_InELF;
112
113# size check
114if ($nSizeInitialVector > $maxIVRegionSize )
115{
116 die "Section : 'INT_VECTOR_CODE' size too big\n";
117}
118
119# 3. copy input vector to the head of ROM image (IV Region)
120CopyInitialVectorInElf($nROMIVRegionOffset_InELF, $nINTVectorOffset_InELF, $nSizeInitialVector);
121
122
123
124#****************************************************************************
125# Subroutines
126#****************************************************************************
127sub CopyInitialVectorInElf
128{
129 my ($DstAddr, $SrcAddr, $nSize) = (@_);
130 my ($buffer, $data, $n);
131
132 open (FILE_HANDLE, "+<$elf_file") or &ReadElf_die("[2.0]$elf_file: file error!", __FILE__, __LINE__);
133 binmode FILE_HANDLE;
134
135 # Read initial vector
136 seek FILE_HANDLE,$SrcAddr,0;
137 if (($n = read FILE_HANDLE, $data, $nSize) != 0)
138 {
139 $buffer .= $data;
140 }
141 else
142 {
143 die "Error : Read IV failed\n";
144 }
145
146 #write initial vector
147 seek FILE_HANDLE,$DstAddr,0;
148 print FILE_HANDLE $buffer;
149
150
151 close(FILE_HANDLE);
152}