blob: 05a59e5c542ee9a05586cd10b4b514e981783e90 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +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#* cfgGen_flash.pl
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This script generates flash part in the CFG file for flash tool for SV5
48#*
49#* Author:
50#* -------
51#* Marvin Lin (mtk03483)
52#*
53#*============================================================================
54#* HISTORY
55#* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56#*------------------------------------------------------------------------------
57#* $Revision$
58#* $Modtime$
59#* $Log$
60#*
61#*
62#*------------------------------------------------------------------------------
63#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
64#*============================================================================
65#****************************************************************************/
66
67#****************************************************************************
68# Included Modules
69#****************************************************************************
70use strict;
71
721;
73
74#****************************************************************************
75# Constants
76#****************************************************************************
77my $CFGGEN_FLASH_VERNO = " V0.00";
78 # v0.00 , initial version
79
80#****************************************************************************
81# Input Parameters and Global Variables
82#****************************************************************************
83
84#****************************************************************************
85# subroutine: get_mem_dev_h_value
86# input: $str_BB_path: BB folder path
87# input: $href_mem_dev: reference of hash of custom_MemoryDevice.h configurations
88#****************************************************************************
89sub get_mem_dev_h_value
90{
91 my ($str_BB_path, $href_mem_dev) = @_;
92
93 my $CUSTOM_MEM_DEV_H = $str_BB_path . "\\custom_MemoryDevice.h";
94
95 open (MEMDEVH_HANDLE, "<$CUSTOM_MEM_DEV_H") or &error_handler("$CUSTOM_MEM_DEV_H: file error!", __FILE__, __LINE__);
96 while (<MEMDEVH_HANDLE>) {
97 if (/^#define\s+(\w+)\s+\((\w*)\)/ || /^#define\s+(\w+)\s+(\w*)/)
98 {
99 my $option = $1;
100 my $value = $2;
101
102 &error_handler("$CUSTOM_MEM_DEV_H: $option redefined in custom_MemoryDevice.h!", __FILE__, __LINE__) if defined($href_mem_dev->{$option});
103 if ((!defined $value) or ($value eq ''))
104 {
105 $href_mem_dev->{$option} = 'TRUE';
106 }
107 else
108 {
109 if ($option =~ /CS(\d+)_PART_NUMBER/)
110 {
111 if (($href_mem_dev->{MEMORY_DEVICE_TYPE} eq 'LPSDRAM') or ($href_mem_dev->{MEMORY_DEVICE_TYPE} eq 'LPDDR') or ($href_mem_dev->{MEMORY_DEVICE_TYPE} eq 'LPDDR2'))
112 {
113 if ($value =~ /(\w+)_([A-Za-z0-9]+EVB)/ or $value =~ /(\w+)_(Sapphire28)/i)
114 {
115 $href_mem_dev->{$option} = $1;
116 }
117 else
118 {
119 $href_mem_dev->{$option} = $value;
120 }
121 }
122 elsif ($href_mem_dev->{MEMORY_DEVICE_TYPE} eq 'NOR_LPSDRAM_MCP')
123 {
124 if ($value =~ /(\w+)_([A-Za-z0-9]+EVB)/ or $value =~ /(\w+)_(Sapphire28)/i)
125 {
126 $href_mem_dev->{$option} = $1;
127 }
128 else
129 {
130 $href_mem_dev->{$option} = $value;
131 }
132 }
133 else
134 {
135 $href_mem_dev->{$option} = $value;
136 }
137 }
138 else
139 {
140 $href_mem_dev->{$option} = $value;
141 }
142 }
143 }
144 }
145 close (MEMDEVH_HANDLE);
146}
147
148#****************************************************************************
149# subroutine: error_handler
150# input: $error_msg: error message
151#****************************************************************************
152sub error_handler
153{
154 my ($error_msg, $file, $line_no) = @_;
155
156 my $final_error_msg = "CFGGEN ERROR: $error_msg at $file line $line_no\n";
157 print $final_error_msg;
158 die $final_error_msg;
159}
160
161#****************************************************************************
162# subroutine: gen_flash_info
163# return: Flash information
164#****************************************************************************
165sub gen_flash_info
166{
167 my ($str_BB_path, $str_board_ver, $bb) = @_;
168
169 my %MEM_DEV_H_Value;
170 &get_mem_dev_h_value($str_BB_path, \%MEM_DEV_H_Value);
171
172 ### DRAM
173 my $is_dram = (($MEM_DEV_H_Value{MEMORY_DEVICE_TYPE} eq 'LPSDRAM') or ($MEM_DEV_H_Value{MEMORY_DEVICE_TYPE} eq 'LPDDR') or ($MEM_DEV_H_Value{MEMORY_DEVICE_TYPE} eq 'LPDDR2')) ? 'TRUE' : 'FALSE';
174
175 ### Flash type
176 my $flash_type;
177 if ($is_dram eq 'TRUE')
178 {
179 $flash_type = "[NAND Flash]";
180 }
181 elsif ($MEM_DEV_H_Value{MEMORY_DEVICE_TYPE} eq 'SERIAL_FLASH')
182 {
183 $flash_type = "[Serial Flash]";
184 }
185 else
186 {
187 $flash_type = "[NOR Flash]";
188 }
189
190 ### Read custom_flash.h for flash ID and NOR flash size
191 my ($flash_id_str, @flash_id, $flash_id_template);
192 my ($nor_flash_size_mb, $nor_flash_size_template);
193 my $CUSTOM_FLASH_H = $str_BB_path . "\\custom_flash.h";
194 open (CUSTOM_FLASH_H, "<$CUSTOM_FLASH_H") or &error_handler("$CUSTOM_FLASH_H: file error!", __FILE__, __LINE__);
195 while (<CUSTOM_FLASH_H>)
196 {
197 if (/const\s+kal_char\s+FLASH_ID\[\]\s+=\s+\"(.+)\";/)
198 {
199 $flash_id_str = $1;
200 }
201 elsif (/NOR_FLASH_SIZE\(Mb\):\s+(\d+)/)
202 {
203 $nor_flash_size_mb = $1;
204 }
205 }
206 close CUSTOM_FLASH_H;
207 if ($MEM_DEV_H_Value{CS0_PART_NUMBER} eq 'EHD013111MA_60_MTKINTERN') # work-around for QC
208 {
209 $flash_id_str = "0x0020,0x00BA,0x0010,0x0055";
210 }
211 print "FLASH_ID = $flash_id_str\n";
212 $flash_id_str =~ s/\{//;
213 $flash_id_str =~ s/\}//;
214 $flash_id_str =~ s/\s+//g;
215 @flash_id = split /\,/, $flash_id_str;
216 for (0..7) # there are totally 8 flash ID
217 {
218 my $idx = $_ + 1;
219 my $cur_flash_id = (($is_dram eq 'TRUE') or ($MEM_DEV_H_Value{MEMORY_DEVICE_TYPE} eq 'SERIAL_FLASH')) ? "0xFF" : "0xFFFF";
220 if (defined $flash_id[$_])
221 {
222 if (($is_dram eq 'TRUE') or ($MEM_DEV_H_Value{MEMORY_DEVICE_TYPE} eq 'SERIAL_FLASH'))
223 {
224 $cur_flash_id = sprintf("0x%02X", hex($flash_id[$_]));
225 }
226 else
227 {
228 $cur_flash_id = sprintf("0x%04X", hex($flash_id[$_]));
229 }
230 }
231 $flash_id_template .= "ID$idx=$cur_flash_id\n";
232 }
233 chomp $flash_id_template;
234
235 if ($is_dram eq 'FALSE')
236 {
237 $nor_flash_size_template = sprintf("Flash_Size=0x%x", $nor_flash_size_mb/8*1024*1024);
238 }
239
240 my $template = <<"__TEMPLATE";
241$flash_type
242$flash_id_template
243$nor_flash_size_template
244
245__TEMPLATE
246}