blob: f938f2872571681633a8f33a13e2f0e508c808a7 [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#* emigenMD.pl
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* generate emi/flash configuration files
48#*
49#* Author:
50#* -------
51#* Guo-Huei Chang (mtk04123)
52#* Way Chen (mtk54483)
53#****************************************************************************
54
55#****************************************************************************
56# Included Modules
57#****************************************************************************
58use strict;
59use warnings;
60use Class::Struct ();
61use File::Basename ();
62use File::Copy ();
63use File::Spec ();
64use POSIX ();
65use Storable ();
66push @INC, ("tools/perl",".");
67require Spreadsheet::ParseExcel;
68
69local $| = 1; #auto flush 'print' function
70
71my $EMIGEN_VERNO = "v10.001";
72 #v10.001, by Holmes at 2019/08/01, modify for MT6297
73 # v9.008, by Guo-Huei at 2014/04/15, Update EMIGEN to generate SmartPhone's DRAM Size by MDL
74 # v9.007, by Guo-Huei at 2014/01/08, Update EMIGEN for SmartPhone project
75 # v9.006, by Guo-Huei at 2013/12/09, Update custom_EMI for MT6595
76 # v9.005, by Way at 2013/11/15, Optimal EMIGEN Flash Part Code for ROME.
77 # v9.004, by Guo-Huei at 2013/11/06, update emigen for MT6595 build pass
78 # v9.003, by Way at 2013/10/24, Support MP Level MDL
79 # v9.002, by Guo-Huei at 2013/08/07, 1. remove lagacy code. 2. auto-generate header file according MDL content 3. Add combo memory support 4. error check for combo memory configuration.
80 # v9.001, by Guo-Huei at 2013/08/05, 1. remove lagacy code. 2. re-arch emigen flow. 3. remove WIN32 OLE related code. 4. use warnings
81 # v8.276, by Way at 2013/06/24, 1. remove lagacy code; 2. Re-arch EMIGEN flow; 3. Implement combo flash part auto gen flow; 4. Add combo_nfi_config.h for enhance NAND flash flow of mT6290.
82 # v8.275, by Way at 2013/06/7, enable auto emigen flash part.
83 # v8.274, by Way at 2013/05/23, change checking smart phone method without flash.
84 # v8.273, by Guo-Huei at 2013/05/15, change checking smart phone method without emi.
85 # v8.272, by Guo-Huei at 2013/05/02, add emigen to support combo memory.
86 # v8.271, by Guo-Huei at 2013/04/12, update emigen to auto-gen custom_EMI_INFO.h
87 # v8.270, by Guo-Huei at 2013/03/27, update emigen to support parsing flash.
88 # v8.269, by Guo-Huei at 2013/03/22, update emigen to auto-generate emi related output files.
89 # v8.268, by Guo-Huei at 2013/03/19, update custom_EMI function and cfggen EMI part
90 # v8.267, by Guo-Huei at 2013/02/05, rename emigen from MT7208 to MT6290
91 # v8.266, by Marvin at 2012/11/01 , autogen support MT6290
92my $DebugPrint = 0; # 1 for debug; 0 for non-debug
93
94my $BOOL_EMI_CLEAN = $ARGV[0]; # FALSE
95my $CUSTOM_MEMORY_DEVICE_HDR = $ARGV[1]; # ./work/custom/TK6291E1_SUPER_HOSTED/system/custom_MemoryDevice.h
96my $THEMF = $ARGV[2]; # ./work/custom/TK6291E1_SUPER_HOSTED/build/customer_feature_option
97my $BOOL_MD_INFO = $ARGV[3]; # FALSE
98my $INSIDE_MTK = $ARGV[4]; # 1
99my $LOAD_TMP_PATH = $ARGV[5]; # ./out/tmp/TK6291E1_SUPER_HOSTED
100my $CUSTOM_SYSTEM_DIR = File::Basename::dirname($CUSTOM_MEMORY_DEVICE_HDR);
101my $CUSTOM_FEATURE_CONFIG_HDR = File::Spec->catfile($CUSTOM_SYSTEM_DIR, "custom_FeatureConfig.h");
102
103# to align error message file name format
104$CUSTOM_MEMORY_DEVICE_HDR =~ s/^.\\|^\\//;
105$THEMF =~ s/^.\\|^\\//;
106
107# global parameters
108my %PART_NUMBER;
109my $emi_clk_config;
110my $sfi_clk_config;
111my %BBtbl_SFI_FAST_CLK = ( 'MT6291' => 78 );
112my %BBtbl_SFI_SLOW_CLK = ( 'MT6291' => 13 );
113my $NOR_FLASH_BASE_ADDRESS_VAL;
114my $NOR_ALLOCATED_FAT_SPACE_VAL;
115my $LPSDRAM_CHIP_SELECT = 0xFF;
116my $emi_is_existed = 1;
117my @MCP_LIST; # list of PART_NUMBER hash references
118my @MDL_INFO_LIST; # list of MEM_DEV_LIST_INFO has references
119my %COMM_MDL_INFO; # common MDL info, obtained from MDL_INFO_LIST.
120my %MAKEFILE_OPTIONS; #list of makefile option
121my %CUSTOM_MEM_DEV_OPTIONS; #list of custom_memory_device option
122my %CUSTOM_FEATURE_CFG_OPTIONS;
123my $MEMORY_DEVICE_LIST_XLS; #CORRECT MDL FILE
124my $MEMORY_DEVICE_LIST_INT_XLS; #INTERNAL MDL FILE
125
126print "os environment: $^O\n";
127print "load temp path: $LOAD_TMP_PATH\n";
128print "custom memory device: $CUSTOM_MEMORY_DEVICE_HDR\n";
129print "makefile: $THEMF\n";
130print "inside_mtk: $INSIDE_MTK\n";
131
132require "tools/emigenemi.pl";
133require "tools/emigenflash.pl";
134
135#****************************************************************************
136# parse makefile
137#****************************************************************************
138&Parse_Makefile();
139if ($MAKEFILE_OPTIONS{'platform'} =~ '^MT629[1235]$') {
140 $MAKEFILE_OPTIONS{'platform'} = 'MT6291';
141} elsif ($MAKEFILE_OPTIONS{'platform'} =~ '^MT629[78]$') {
142 $MAKEFILE_OPTIONS{'platform'} = 'MT6297';
143} else {
144 &error_handler("not support platform, ".$MAKEFILE_OPTIONS{'platform'}, __FILE__, __LINE__);
145}
146
147#****************************************************************************
148# generated file list
149#****************************************************************************
150printf "\n%s#%d: %s\n", __FILE__, __LINE__, "generated file list";
151Class::Struct::struct(GEN_FLS_S => {name => '$', owner => '$', path => '$', exist => '$', description => '$'});
152my %GEN_FLS = (
153 custom_emi_h => GEN_FLS_S->new(name => (($MAKEFILE_OPTIONS{'platform'} eq 'MT6291')? "custom_EMI.h": "custom_emi.h"), owner => "holmes.lin (mtk09097)", description => "This Module defines the EMI (external memory interface) related setting."),
154 custom_emi_info_c => GEN_FLS_S->new(name => "custom_EMI_INFO.c", owner => "holmes.lin (mtk09097)", description => "This Module defines the EMI (external memory interface) related setting."),
155 custom_emi_release_h => GEN_FLS_S->new(name => "custom_EMI_release.h", owner => "holmes.lin (mtk09097)", description => "This Module defines the EMI (external memory interface) related setting."),
156 #custom_emi_c => GEN_FLS_S->new(name => "custom_EMI.c", owner => "holmes.lin (mtk09097)", description => ""),
157 #custom_sfi_h => GEN_FLS_S->new(name => "custom_SFI.h", owner => "way.chen (mtk54483)", description => ""),
158 custom_flash_h => GEN_FLS_S->new(name => "custom_flash.h", owner => "way.chen (mtk54483)", description => "This Module defines flash related settings."),
159 flash_opt_gen_h => GEN_FLS_S->new(name => "flash_opt_gen.h", owner => "way.chen (mtk54483)", description => "NOR flash related options."),
160 custom_flash_norfdm5_h => GEN_FLS_S->new(name => "custom_flash_norfdm5.h", owner => "way.chen (mtk54483)", description => "defines prototypes and data structure which will be used in NOR FDM 5.0"),
161 combo_flash_config_h => GEN_FLS_S->new(name => "combo_flash_config.h", owner => "way.chen (mtk54483)", description => "This Module defines the Flash configurations for Combo Memory."),
162 combo_flash_id_h => GEN_FLS_S->new(name => "combo_flash_id.h", owner => "way.chen (mtk54483)", description => "This Module defines the Flash ID table for Combo Memory."),
163 #combo_sfi_config_h => GEN_FLS_S->new(name => "combo_sfi_config.h", owner => "way.chen (mtk54483)", description => ""),
164 combo_sfi_defs_h => GEN_FLS_S->new(name => "combo_sfi_defs.h", owner => "way.chen (mtk54483)", description => "defines flash ID table"),
165 #custom_sfi_clock_h => GEN_FLS_S->new(name => "custom_sfi_clock.h", owner => "way.chen (mtk54483)", description => ""),
166 combo_nfi_config_h => GEN_FLS_S->new(name => "combo_nfi_config.h", owner => "way.chen (mtk54483)", description => "gen NAND Flash Related Configuration and Table"),
167);
168map {$GEN_FLS{$_}->path(File::Spec->catfile($CUSTOM_SYSTEM_DIR, $GEN_FLS{$_}->name))} keys(%GEN_FLS);
169print "output file: ", join(", ", map {$GEN_FLS{$_}->path} sort(keys(%GEN_FLS))), "\n";
170
171#****************************************************************************
172# emiclean
173#****************************************************************************
174printf "\n%s#%d: %s\n", __FILE__, __LINE__, "emiclean";
175my @gen_depends = ("tools/emigenMD.pl", "tools/emigenSP.pl", "tools/emigenemi.pl", "tools/emigenflash.pl", "tools/emigenSF.pl", $THEMF, $CUSTOM_MEMORY_DEVICE_HDR, $MEMORY_DEVICE_LIST_XLS, $MEMORY_DEVICE_LIST_INT_XLS, $CUSTOM_FEATURE_CONFIG_HDR);
176if ($BOOL_EMI_CLEAN eq 'TRUE') {
177 map {&Check_ManualCheckIn($GEN_FLS{$_}->path, "TRUE", @gen_depends)} keys(%GEN_FLS);
178 exit;
179} else {
180 map {&Check_ManualCheckIn($GEN_FLS{$_}->path, "FALSE", @gen_depends)} keys(%GEN_FLS);
181}
182map {$GEN_FLS{$_}->exist((-e $GEN_FLS{$_}->path)? 1: 0)} keys(%GEN_FLS);
183
184#****************************************************************************
185# find the correct EMI database
186#****************************************************************************
187&Find_MDL();
188
189#****************************************************************************
190# parse custom_MemoryDevice.h to extract MEMORY_DEVICE_TYPE & PART_NUMBER
191#****************************************************************************
192&Parse_Memory_Device();
193
194#****************************************************************************
195# parse custom_FeatureConfig.h to extract feature-related configurations
196#****************************************************************************
197&Parse_custom_FeatureConfig();
198
199#****************************************************************************
200# Check EMI exist
201#****************************************************************************
202if ($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE} eq 'NONE')
203{
204 require "tools/emiGenSP.pl";
205 $emi_is_existed = 0;
206}
207
208#****************************************************************************
209# parse EMI database to get EMI settings
210#****************************************************************************
211&Parse_MDL();
212
213#****************************************************************************
214# Check Combo Memory configuration validity
215#****************************************************************************
216my $nor_size_Mb;
217&CheckConfigValid();
218
219#****************************************************************************
220# check consistency among FEATURE, MEMORY_DEVICE_TYPE, PLATFORM, MCU_CLOCK and MemoryDeviceList data
221#****************************************************************************
222$sfi_clk_config = $BBtbl_SFI_FAST_CLK{$MAKEFILE_OPTIONS{'platform'}};
223&Decide_MemClockSpeed();
224
225#****************************************************************************
226# get common MDL information from a list of MDL information for Combo Memory
227#****************************************************************************
228printf "\n%s#%d: %s\n", __FILE__, __LINE__, "get_common_MDL_info";
229&get_common_MDL_info(\@MDL_INFO_LIST, \%CUSTOM_MEM_DEV_OPTIONS, \%COMM_MDL_INFO,\%MAKEFILE_OPTIONS, $LPSDRAM_CHIP_SELECT, $CUSTOM_MEMORY_DEVICE_HDR, $emi_is_existed);
230if ($DebugPrint == 1)
231{
232 print "COMM_MDL_INFO: Flash Size = $COMM_MDL_INFO{0}->{'Flash Size'}, NAND Block Size(KB) = $COMM_MDL_INFO{0}->{'NAND Block Size(KB)'}, Small Block Start = $COMM_MDL_INFO{0}->{'Small Block Start'}, Default FAT Base = $COMM_MDL_INFO{0}->{'Default FAT Base'}, Default FAT Size = $COMM_MDL_INFO{0}->{'Default FAT Size'}\n";
233 #print "RAM \"Size (Mb)\" = $COMM_MDL_INFO{1}->{'Size (Mb)'}, \"CS0 ADMUX\" = $COMM_MDL_INFO{0}->{'ADMUX'}, \"CS1 ADMUX\" = $COMM_MDL_INFO{1}->{'ADMUX'}, \"DRAM\" = $COMM_MDL_INFO{1}->{'DRAM'}, \"CS0 Comm. Series\" = $COMM_MDL_INFO{0}->{'Comm. Series'}, \"CS1 Comm. Series\" = $COMM_MDL_INFO{1}->{'Comm. Series'}, \"Bank\" = $COMM_MDL_INFO{0}->{'Bank'}, \"PBP->Y / N\" = $COMM_MDL_INFO{0}->{'PBP'}->{'Y / N'}, \"PBP->Size(W)\" = $COMM_MDL_INFO{0}->{'PBP'}->{'Size(W)'}\n";
234}
235
236#****************************************************************************
237# PROJECT EXPECTED CONFIGURE
238#****************************************************************************
239my $physical_ram_density;
240my $project_expected_ram_limit_common = (exists $MAKEFILE_OPTIONS{'nand_flash_booting'} and $MAKEFILE_OPTIONS{'nand_flash_booting'} ne 'NONE') ? $CUSTOM_FEATURE_CFG_OPTIONS{PROJECT_EXPECTED_RAM_LIMIT_NFB} : $CUSTOM_FEATURE_CFG_OPTIONS{PROJECT_EXPECTED_RAM_LIMIT};
241if (defined $project_expected_ram_limit_common)
242{
243 #ensure practical
244 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Cannot configure expected RAMSIZE larger than physical RAM size!", __FILE__, __LINE__)
245 if ( hex($project_expected_ram_limit_common) > ($COMM_MDL_INFO{1}->{'Size (Mb)'} * 1024 * 1024 / 8) );
246
247 #ensure 2^n
248 my $i;
249 for( $i = 1 ; $i < hex($project_expected_ram_limit_common) ; $i *= 2 ){1;}
250 if ( $i < ($COMM_MDL_INFO{1}->{'Size (Mb)'} * 1024 * 1024 / 8) )
251 {
252 $physical_ram_density = "// PHYSICAL RAM DENSITY $COMM_MDL_INFO{1}->{'Size (Mb)'} Mb\n";
253 $COMM_MDL_INFO{1}->{'Size (Mb)'} = $i * 8 / ( 1024 * 1024);
254 }
255}
256chomp $physical_ram_density if (defined $physical_ram_density);
257
258#****************************************************************************
259# get common entire geometry information for Combo Memory
260#****************************************************************************
261my (@entire_region_info_size_list, @entire_region_info_count_list, @entire_bank_info_size_list, @entire_bank_info_count_list);
262my (@entire_block_info_start_list, @entire_block_info_size_list);
263if ($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE')
264{
265 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "get_common_MDL_Geo_info, convert_regions_to_blocks";
266 &get_common_MDL_Geo_info(\@MDL_INFO_LIST, $CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT}, $CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE}, 0, $COMM_MDL_INFO{0}->{'Flash Size'}, \@entire_region_info_size_list, \@entire_region_info_count_list, \@entire_bank_info_size_list, \@entire_bank_info_count_list);
267 &convert_regions_to_blocks(0, \@entire_region_info_size_list, \@entire_region_info_count_list, \@entire_block_info_start_list, \@entire_block_info_size_list);
268
269}
270#NAND Flash Also need to check FAT for MT6290, we may use NAND FAT Infomation
271printf "\n%s#%d: %s\n", __FILE__, __LINE__, "Calculate_FAT_Info";
272&Calculate_FAT_Info(\%MAKEFILE_OPTIONS, \%CUSTOM_MEM_DEV_OPTIONS, \%COMM_MDL_INFO, \@MDL_INFO_LIST, \$NOR_FLASH_BASE_ADDRESS_VAL, \$NOR_ALLOCATED_FAT_SPACE_VAL, $nor_size_Mb, \%CUSTOM_FEATURE_CFG_OPTIONS, \@entire_block_info_start_list, \@entire_block_info_size_list);
273
274#****************************************************************************
275# get common FS geometry information for Combo Memory
276#****************************************************************************
277my (@fs_region_info_size_list, @fs_region_info_count_list, @fs_bank_info_size_list, @fs_bank_info_count_list);
278my (@fs_block_info_start_list, @fs_block_info_size_list);
279if ($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE')
280{
281 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "get_common_MDL_Geo_info; convert_regions_to_blocks";
282 &get_common_MDL_Geo_info(\@MDL_INFO_LIST, $CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT}, $CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE}, $NOR_FLASH_BASE_ADDRESS_VAL, $NOR_FLASH_BASE_ADDRESS_VAL+$NOR_ALLOCATED_FAT_SPACE_VAL, \@fs_region_info_size_list, \@fs_region_info_count_list, \@fs_bank_info_size_list, \@fs_bank_info_count_list);
283 &convert_regions_to_blocks($NOR_FLASH_BASE_ADDRESS_VAL, \@fs_region_info_size_list, \@fs_region_info_count_list, \@fs_block_info_start_list, \@fs_block_info_size_list);
284 if ($DebugPrint == 1)
285 {
286 print "Entire RegionInfo: ";
287 for (0..$#entire_region_info_size_list)
288 {
289 print "\{$entire_region_info_size_list[$_], $entire_region_info_count_list[$_]\}, ";
290 }
291 print "\nEntire BankInfo: ";
292 for (0..$#entire_bank_info_size_list)
293 {
294 print "\{$entire_bank_info_size_list[$_], $entire_bank_info_count_list[$_]\}, ";
295 }
296 print "\nEntire BlockInfo: ";
297 for (0..$#entire_block_info_start_list)
298 {
299 print "\{$entire_block_info_start_list[$_], $entire_block_info_size_list[$_]\}, ";
300 }
301 print "\nFS RegionInfo: ";
302 for (0..$#fs_region_info_size_list)
303 {
304 print "\{$fs_region_info_size_list[$_], $fs_region_info_count_list[$_]\}, ";
305 }
306 print "\nFS BankInfo: ";
307 for (0..$#fs_bank_info_size_list)
308 {
309 print "\{$fs_bank_info_size_list[$_], $fs_bank_info_count_list[$_]\}, ";
310 }
311 print "\nFS BlockInfo: ";
312 for (0..$#fs_block_info_start_list)
313 {
314 print "\{$fs_block_info_start_list[$_], $fs_block_info_size_list[$_]\}, ";
315 }
316 print "\n";
317 }
318}
319
320### Validate FAT and NOR Raw disk overlapping case
321printf "\n%s#%d: %s\n", __FILE__, __LINE__, "Validate_FAT_NORRAWDISK_OVERLAP; Calculate_NORRAWDISK_Region_Info";
322&Validate_FAT_NORRAWDISK_OVERLAP(\%CUSTOM_MEM_DEV_OPTIONS, \%COMM_MDL_INFO, \$NOR_FLASH_BASE_ADDRESS_VAL, \$NOR_ALLOCATED_FAT_SPACE_VAL, $CUSTOM_MEMORY_DEVICE_HDR);
323### Calculate NOR Raw disk Region Info
324&Calculate_NORRAWDISK_Region_Info(\%CUSTOM_MEM_DEV_OPTIONS);
325
326### Check CODE setting validity
327my $expected_code_limit;
328if (defined $CUSTOM_FEATURE_CFG_OPTIONS{PROJECT_EXPECTED_CODE_LIMIT})
329{
330 #ensure practical
331 &error_handler("$CUSTOM_FEATURE_CONFIG_HDR: Cannot configure expected CODESIZE larger than (physical NOR flash size - FAT space)!", __FILE__, __LINE__)
332 if ( hex($CUSTOM_FEATURE_CFG_OPTIONS{PROJECT_EXPECTED_CODE_LIMIT}) > $NOR_FLASH_BASE_ADDRESS_VAL );
333}
334
335#****************************************************************************
336# generate custom_EMI.h
337#****************************************************************************
338if (($GEN_FLS{custom_emi_h}->exist == 0) and
339 ($MAKEFILE_OPTIONS{'platform'} =~ 'MT629[17]'))
340{
341 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "custom_emi_h";
342 my $gf = $GEN_FLS{custom_emi_h};
343 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
344 print GFH &copyright_file_header();
345 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
346 if ($emi_is_existed == 0) {
347 print GFH &custom_EMI_h_file_body_for_sp($MAKEFILE_OPTIONS{'platform'});
348 } elsif ($MAKEFILE_OPTIONS{'platform'} eq 'MT6291') {
349 print GFH &custom_EMI_h_file_body_for_91(\%MAKEFILE_OPTIONS,\%CUSTOM_MEM_DEV_OPTIONS,\@MDL_INFO_LIST, \%COMM_MDL_INFO, \%PART_NUMBER, $CUSTOM_MEMORY_DEVICE_HDR, $LPSDRAM_CHIP_SELECT, $emi_clk_config);
350 } else {
351 print GFH &custom_emi_h_file_body_for_97(\%MAKEFILE_OPTIONS,\@MDL_INFO_LIST);
352 }
353 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
354 print $gf->path, " is generated\n";
355}
356
357#****************************************************************************
358# generate custom_EMI_INFO.c
359#****************************************************************************
360if (($GEN_FLS{custom_emi_info_c}->exist == 0) and
361 ($MAKEFILE_OPTIONS{'platform'} eq 'MT6291'))
362{
363 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "custom_emi_info_c";
364 my $gf = $GEN_FLS{custom_emi_info_c};
365 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
366 print GFH &copyright_file_header();
367 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
368 if ($emi_is_existed == 0) {
369 print GFH &custom_EMI_info_h_file_body_for_sp($MAKEFILE_OPTIONS{'platform'});
370 } else {
371 print GFH &custom_EMI_info_c_file_body_for_91(\%MAKEFILE_OPTIONS,\%CUSTOM_MEM_DEV_OPTIONS,\@MDL_INFO_LIST, \%COMM_MDL_INFO, \%PART_NUMBER, $CUSTOM_MEMORY_DEVICE_HDR, $LPSDRAM_CHIP_SELECT, $emi_clk_config);
372 }
373 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
374 print $gf->path, " is generated\n";
375}
376
377#****************************************************************************
378# generate custom_EMI_release.h
379#****************************************************************************
380if (($GEN_FLS{custom_emi_release_h}->exist == 0) and
381 ($MAKEFILE_OPTIONS{'platform'} eq 'MT6291'))
382{
383 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "custom_emi_release_h";
384 my $gf = $GEN_FLS{custom_emi_release_h};
385 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
386 print GFH &copyright_file_header();
387 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
388 if ($emi_is_existed == 0) {
389 print GFH &custom_EMI_release_h_file_body_for_sp(\%MAKEFILE_OPTIONS,\%CUSTOM_MEM_DEV_OPTIONS,\@MDL_INFO_LIST, \%COMM_MDL_INFO, $LPSDRAM_CHIP_SELECT, $emi_clk_config);
390 } else {
391 print GFH &custom_EMI_release_h_file_body_for_91(\%MAKEFILE_OPTIONS,\%CUSTOM_MEM_DEV_OPTIONS,\@MDL_INFO_LIST, \%COMM_MDL_INFO, $LPSDRAM_CHIP_SELECT, $emi_clk_config);
392 }
393 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
394 print $gf->path, " is generated\n";
395}
396
397#****************************************************************************
398# generate flash_opt_gen.h
399#****************************************************************************
400if ($GEN_FLS{flash_opt_gen_h}->exist == 0)
401{
402 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "flash_opt_gen_h";
403 my $gf = $GEN_FLS{flash_opt_gen_h};
404 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
405 print GFH &copyright_file_header();
406 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
407 print GFH &flash_opt_gen_h_file_body(\%MAKEFILE_OPTIONS,\%CUSTOM_MEM_DEV_OPTIONS,\@MDL_INFO_LIST, \%COMM_MDL_INFO, $CUSTOM_MEMORY_DEVICE_HDR, $THEMF, \@entire_bank_info_size_list, \@entire_bank_info_count_list, \@entire_block_info_start_list, \@entire_block_info_size_list, \@entire_region_info_size_list, \@entire_region_info_count_list);
408 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
409 print $gf->path, " is generated\n";
410}
411
412#****************************************************************************
413# generate custom_flash.h
414#****************************************************************************
415if ($GEN_FLS{custom_flash_h}->exist == 0)
416{
417 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "custom_flash_h";
418 my $gf = $GEN_FLS{custom_flash_h};
419 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
420 print GFH &copyright_file_header();
421 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
422 print GFH &custom_flash_h_file_body(\%MAKEFILE_OPTIONS,\%CUSTOM_MEM_DEV_OPTIONS, \@MDL_INFO_LIST, \%COMM_MDL_INFO, \@MCP_LIST, $NOR_FLASH_BASE_ADDRESS_VAL, $NOR_ALLOCATED_FAT_SPACE_VAL, $LPSDRAM_CHIP_SELECT, $CUSTOM_MEMORY_DEVICE_HDR, $nor_size_Mb, \@entire_bank_info_size_list, \@entire_bank_info_count_list, \@entire_block_info_start_list, \@entire_block_info_size_list,\@fs_region_info_size_list, \@fs_region_info_count_list, \@entire_region_info_size_list, \@entire_region_info_count_list);
423 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
424 print $gf->path, " is generated\n";
425}
426
427#****************************************************************************
428# generate custom_flash_norfdm5.h
429#****************************************************************************
430if (($GEN_FLS{custom_flash_norfdm5_h}->exist == 0) and
431 (defined $CUSTOM_MEM_DEV_OPTIONS{__NOR_FDM5__})) ##Only __NOR_FDM5__ defined will gen custom_flash_norfdm5.h
432{
433 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "custom_flash_norfdm5_h";
434 my $gf = $GEN_FLS{custom_flash_norfdm5_h};
435 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
436 print GFH &copyright_file_header();
437 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
438 print GFH &custom_flash_norfdm5_h_file_body(\%MAKEFILE_OPTIONS, \%CUSTOM_MEM_DEV_OPTIONS, \@MDL_INFO_LIST, \%COMM_MDL_INFO, $NOR_FLASH_BASE_ADDRESS_VAL, $NOR_ALLOCATED_FAT_SPACE_VAL,\@entire_bank_info_size_list, \@entire_bank_info_count_list);
439 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
440 print $gf->path, " is generated\n";
441}
442
443#****************************************************************************
444# generate combo_flash_config.h
445#****************************************************************************
446if ($GEN_FLS{combo_flash_config_h}->exist == 0)
447{
448 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "combo_flash_config_h";
449 my $gf = $GEN_FLS{combo_flash_config_h};
450 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
451 print GFH &copyright_file_header();
452 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
453 print GFH &combo_flash_config_h_file_body(\%MAKEFILE_OPTIONS, \%CUSTOM_MEM_DEV_OPTIONS, \@MDL_INFO_LIST, \%COMM_MDL_INFO);
454 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
455 print $gf->path, " is generated\n";
456}
457
458#****************************************************************************
459# generate combo_flash_id.h
460#****************************************************************************
461if ($GEN_FLS{combo_flash_id_h}->exist == 0)
462{
463 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "combo_flash_id_h";
464 my $gf = $GEN_FLS{combo_flash_id_h};
465 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
466 print GFH &copyright_file_header();
467 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
468 print GFH &combo_flash_id_h_file_body(\%MAKEFILE_OPTIONS, \%CUSTOM_MEM_DEV_OPTIONS, \@MDL_INFO_LIST, \%COMM_MDL_INFO);
469 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
470 print $gf->path, " is generated\n";
471}
472
473#****************************************************************************
474# generate combo_nfi_config.h
475#****************************************************************************
476if (($GEN_FLS{combo_nfi_config_h}->exist == 0) and
477 ($MAKEFILE_OPTIONS{'nand_support'} eq 'TRUE') and
478 ($MAKEFILE_OPTIONS{'platform'} =~ /MT629[17]/))
479{
480 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "combo_nfi_config_h";
481 my $gf = $GEN_FLS{combo_nfi_config_h};
482 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
483 print GFH &copyright_file_header();
484 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
485 print GFH &combo_nfi_config_h_file_body(\%MAKEFILE_OPTIONS, \%CUSTOM_MEM_DEV_OPTIONS, \@MDL_INFO_LIST, \%COMM_MDL_INFO);
486 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
487 print $gf->path, " is generated\n";
488}
489
490#****************************************************************************
491# generate combo_sfi_defs.h
492#****************************************************************************
493if (($GEN_FLS{combo_sfi_defs_h}->exist == 0) and
494 ($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE') and
495 ($MAKEFILE_OPTIONS{'platform'} =~ 'MT629[17]'))
496{
497 printf "\n%s#%d: %s\n", __FILE__, __LINE__, "combo_sfi_defs_h";
498 my $gf = $GEN_FLS{combo_sfi_defs_h};
499 open (GFH, ">", $gf->path) or &error_handler($gf->path.": $!", __FILE__, __LINE__);
500 print GFH &copyright_file_header();
501 print GFH &description_file_header($gf->name, $gf->description, $gf->owner);
502 print GFH &combo_sfi_defs_h_file_body(\%MAKEFILE_OPTIONS, \%CUSTOM_MEM_DEV_OPTIONS, \@MDL_INFO_LIST, \%COMM_MDL_INFO);
503 close GFH or &error_handler($gf->path.": $!", __FILE__, __LINE__);
504 print $gf->path, " is generated\n";
505}
506
507exit;
508
509#****************************************************************************
510# find the correct EMI database
511#****************************************************************************
512sub Find_MDL
513{
514 print("\n", (caller(0))[3], "\n");
515 my $MDL_DIR = "tools/MemoryDeviceList/";
516 my $platform = $MAKEFILE_OPTIONS{'platform'};
517 my $ver = 0000;
518
519 $MEMORY_DEVICE_LIST_XLS = "";
520 $MEMORY_DEVICE_LIST_INT_XLS = "";
521
522 opendir(DIR, $MDL_DIR) or &error_handler("$MDL_DIR: $!", __FILE__, __LINE__);;
523
524 if (defined($MAKEFILE_OPTIONS{'ram_support_type'}) && $MAKEFILE_OPTIONS{'ram_support_type'} eq 'NONE') {
525 $platform = $MAKEFILE_OPTIONS{'ram_support_type'};
526 }
527 while (my $mdl = readdir(DIR)) {
528 if ($mdl =~ /MemoryDeviceList_$platform\_SinceW(\w+)\.xls/) {
529 if ($1 > $ver) {
530 $ver = $1;
531 $MEMORY_DEVICE_LIST_XLS = $MDL_DIR . $mdl;
532 }
533 } elsif ($mdl =~ /MemoryDeviceList_$platform\_Internal\.xls/) {
534 $MEMORY_DEVICE_LIST_INT_XLS = $MDL_DIR . $mdl;
535 }
536 }
537
538 close(DIR);
539
540 if ((! -e $MEMORY_DEVICE_LIST_XLS) && (! -e $MEMORY_DEVICE_LIST_INT_XLS)) {
541 &error_handler("MDL Excel is not exist for platform '$platform':$MEMORY_DEVICE_LIST_XLS and $MEMORY_DEVICE_LIST_INT_XLS", __FILE__, __LINE__);
542 }
543
544 if ($DebugPrint == 1) {
545 print "custom memory device header file: $CUSTOM_MEMORY_DEVICE_HDR\n";
546 print "MDL Excel: $MEMORY_DEVICE_LIST_XLS, Internal MDL Excel: $MEMORY_DEVICE_LIST_INT_XLS\n";
547 print "Makefile: $THEMF\n";
548 }
549}
550
551#****************************************************************************
552# parse Project Makefile
553#****************************************************************************
554sub Parse_Makefile
555{
556 print("\n", (caller(0))[3], "\n");
557 my @filelist = ($THEMF, undef);
558 my $keyname;
559
560 foreach my $filename (@filelist) {
561 print "filename: $filename\n" if ($DebugPrint == 1);
562 open (FILE_HANDLE, "<$filename") or &error_handler("$filename: $!", __FILE__, __LINE__);
563 while (<FILE_HANDLE>) {
564 if (/^(\w+)\s*=\s*(\S+)/) {
565 $keyname = lc($1);
566 defined($MAKEFILE_OPTIONS{$keyname}) && warn "$1 redefined in $THEMF!\n";
567 $MAKEFILE_OPTIONS{$keyname} = $2;
568 if ($keyname eq 'internal_feature_option') {
569 ($filelist[1] = $2) =~ s/\$WORKDIR/$ENV{WORKDIR}/;
570 }
571 print "$1 = $2\n" if ($DebugPrint == 1);
572 }
573 }
574 close (FILE_HANDLE);
575 }
576
577 $MAKEFILE_OPTIONS{'platform'} = $MAKEFILE_OPTIONS{'platform_chip'} || 'MT6291';
578}
579
580#****************************************************************************
581# parse Memory Device
582#****************************************************************************
583sub Parse_Memory_Device
584{
585 print("\n", (caller(0))[3], "\n");
586
587 open CUSTOM_MEMORY_DEVICE_HDR, "<$CUSTOM_MEMORY_DEVICE_HDR" or &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: $!", __FILE__, __LINE__);
588 while (<CUSTOM_MEMORY_DEVICE_HDR>)
589 {
590 # error-checking
591 if ((/^#if|^#ifdef|^#ifndef|^#elif|^#else/) and !(/^#ifndef\s+__CUSTOM_MEMORYDEVICE__/))
592 {
593 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Not allowed to set conditional keywords $_ in custom_MemoryDevice.h!", __FILE__, __LINE__);
594 }
595
596 if (/^#define\s+(\w+)\s+\(?([\w|\-]*)\)?/)
597 {
598 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: $1 redefined in custom_MemoryDevice.h!", __FILE__, __LINE__) if defined($CUSTOM_MEM_DEV_OPTIONS{$1});
599 $CUSTOM_MEM_DEV_OPTIONS{$1} = ((!defined $2) or ($2 eq ''))? 'TRUE': $2;
600
601 my $option = $1;
602 my $content = $2;
603 if ($option =~ /COMBO_MEM(\d+)_CS(\d+)_PART_NUMBER/)
604 {
605 next if ((!defined $MAKEFILE_OPTIONS{'combo_memory_support'}) or ($MAKEFILE_OPTIONS{'combo_memory_support'} eq 'FALSE'));
606 print "$option = $content\n" if ($DebugPrint == 1);
607 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: COMBO_MEM_ENTRY_COUNT needs to be defined when COMBO_MEMORY_SUPPORT is turned on!", __FILE__, __LINE__) if (!defined $CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT});
608 my %TMP_PART_NUMBER;
609 my $mcp_idx = $1;
610 my $cs = $2;
611 $LPSDRAM_CHIP_SELECT = $cs;
612 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Only COMBO_MEM0n_CS0 or COMBO_MEM0n_CS1 is allowed!", __FILE__, __LINE__) if (($LPSDRAM_CHIP_SELECT != 0) && ($LPSDRAM_CHIP_SELECT != 1));
613 $TMP_PART_NUMBER{$cs} = $content;
614
615 if (defined $MCP_LIST[$mcp_idx])
616 {
617 if (defined $MCP_LIST[$mcp_idx]->{$cs})
618 {
619 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: COMBO_MEM$mcp_idx\_CS$cs\_PART_NUMBER multiply defined!", __FILE__, __LINE__);
620 }
621 else
622 {
623 $MCP_LIST[$mcp_idx]->{$cs} = $TMP_PART_NUMBER{$cs};
624 }
625 }
626 else
627 {
628 $MCP_LIST[$mcp_idx] = \%TMP_PART_NUMBER;
629 }
630 }
631 elsif ($option =~ /CS(\d+)_PART_NUMBER/)
632 {
633 next if ($MAKEFILE_OPTIONS{'combo_memory_support'} eq 'TRUE'); # when COMBO_MEMORY_SUPPORT is turned on, CSx_PART_NUMBER is ignored
634 print "$option = $content\n" if ($DebugPrint == 1);
635 my $cs = $1;
636 $LPSDRAM_CHIP_SELECT = $cs;
637 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Only COMBO_MEM0n_CS0 or COMBO_MEM0n_CS1 is allowed!", __FILE__, __LINE__) if (($LPSDRAM_CHIP_SELECT != 0) && ($LPSDRAM_CHIP_SELECT != 1));
638 $PART_NUMBER{$cs} = $content;
639 }
640 }
641 }
642 close CUSTOM_MEMORY_DEVICE_HDR;
643
644 $CUSTOM_MEM_DEV_OPTIONS{NOR_FDM4_ESB_PARAMETER_ERASE_QUEUE_SIZE} = (defined $CUSTOM_MEM_DEV_OPTIONS{NOR_FDM4_ESB_PARAMETER_ERASE_QUEUE_SIZE}) ? $CUSTOM_MEM_DEV_OPTIONS{NOR_FDM4_ESB_PARAMETER_ERASE_QUEUE_SIZE} : 5;
645 $CUSTOM_MEM_DEV_OPTIONS{NOR_PARAMETER_SYSTEM_DRIVE_RESERVED_BLOCK} = (defined $CUSTOM_MEM_DEV_OPTIONS{NOR_PARAMETER_SYSTEM_DRIVE_RESERVED_BLOCK}) ? $CUSTOM_MEM_DEV_OPTIONS{NOR_PARAMETER_SYSTEM_DRIVE_RESERVED_BLOCK} : 3;
646
647 # No Combo MCP case
648 if ($MAKEFILE_OPTIONS{'combo_memory_support'} ne 'TRUE')
649 {
650 $MCP_LIST[1] = \%PART_NUMBER;
651 $CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT} = 1;
652 }
653
654 # COMBO_MEM_ENTRY_COUNT and the number of COMBO_MEMxx_CSx_PART_NUMBER does not match
655 if ($CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT} != $#MCP_LIST)
656 {
657 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: COMBO_MEM_ENTRY_COUNT and the number of COMBO_MEMxx_CSx_PART_NUMBER does not match!", __FILE__, __LINE__);
658 }
659
660 ###Check MEMORY_DEVICE_TYPE correction
661 if (($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE} !~ /$MAKEFILE_OPTIONS{'ram_support_type'}/) ||
662 (($MAKEFILE_OPTIONS{'ram_support_type'} =~ /DDR$/) && ($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE} =~ /DDR\d+/))) {
663 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: ram type of MEMORY_DEVICE_TYPE ($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE}) and ram_support_type ($MAKEFILE_OPTIONS{'ram_support_type'}) should be the same", __FILE__, __LINE__);
664 }
665}
666
667#****************************************************************************
668# parse EMI database to get EMI settings
669#****************************************************************************
670sub Parse_MDL
671{
672 print("\n", (caller(0))[3], "\n");
673
674 my $result;
675 my %tmp_hash;
676
677 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Incorrect memory device type!", __FILE__, __LINE__) unless $CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE};
678
679 ##Parse DRAM Parameters
680 my $dram_sheet = $CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE};
681 if ($MAKEFILE_OPTIONS{'sip_ram_size'} ne 'NONE') {
682 $dram_sheet = 'SIP_' . $dram_sheet;
683 }
684 if ($emi_is_existed == 1) {
685 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
686 {
687 $result = &get_info($MEMORY_DEVICE_LIST_XLS, $dram_sheet, $MCP_LIST[$_], \%tmp_hash);
688 if ($result ne 'TRUE')
689 {
690 print "INTERNAL FIND part number: $MCP_LIST[$_]->{0}, $MCP_LIST[$_]->{1}\n";
691 $result = &get_info($MEMORY_DEVICE_LIST_INT_XLS, $dram_sheet, $MCP_LIST[$_], \%tmp_hash);
692 }
693 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Part Number $MCP_LIST[$_]->{0} not found!", __FILE__, __LINE__) if ($result ne 'TRUE');
694 $MDL_INFO_LIST[$_] = Storable::dclone(\%tmp_hash);
695 }
696 } else {
697 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
698 {
699 $result = &get_info($MEMORY_DEVICE_LIST_XLS, 'RAM', $MCP_LIST[$_], \%tmp_hash);
700 if ($result ne 'TRUE')
701 {
702 print "INTERNAL FIND part number: $MCP_LIST[$_]->{0}, $MCP_LIST[$_]->{1}\n";
703 $result = &get_info($MEMORY_DEVICE_LIST_INT_XLS, 'RAM', $MCP_LIST[$_], \%tmp_hash);
704 }
705 &error_handler("Cannot find $MAKEFILE_OPTIONS{'platform'} in MDL!", __FILE__, __LINE__) if ($result ne 'TRUE');
706 $MDL_INFO_LIST[$_] = Storable::dclone(\%tmp_hash);
707 }
708 }
709
710 undef %tmp_hash;
711 ##Parse Flash Parameters
712 ###disctete type should parse flash info sheet
713 if (($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE} !~ /\w+_\w+_MCP/) && (($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE') || ($MAKEFILE_OPTIONS{'nand_support'} eq 'TRUE')))
714 {
715 ###Parse Flash MDL info
716
717 my $flash_sheet = '';
718 if($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE')#sheet "SERIAL_FLASH" in MDL
719 {
720 $flash_sheet = 'SERIAL_FLASH';
721 }
722 elsif($MAKEFILE_OPTIONS{'nand_support'} eq 'TRUE')
723 {
724 $flash_sheet = 'NAND_FLASH';
725 }
726
727 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
728 {
729 print "part number: $MCP_LIST[$_]->{0}, $MCP_LIST[$_]->{1}\n";
730 $result = &get_info($MEMORY_DEVICE_LIST_XLS, $flash_sheet, $MCP_LIST[$_], \%tmp_hash);
731 if ($result ne 'TRUE')
732 {
733 print "INTERNAL FIND part number: $MCP_LIST[$_]->{0}, $MCP_LIST[$_]->{1}\n";
734 $result = &get_info($MEMORY_DEVICE_LIST_INT_XLS, $flash_sheet, $MCP_LIST[$_], \%tmp_hash);
735 }
736 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: $flash_sheet Part Number $MCP_LIST[$_]->{1} not found!", __FILE__, __LINE__) if ($result ne 'TRUE');
737 $MDL_INFO_LIST[$_]->{1} = Storable::dclone($tmp_hash{1});
738 }
739 }
740
741 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
742 {
743 &dump_mdl_info($MDL_INFO_LIST[$_], "\$MDL_INFO_LIST[$_]->");
744 }
745}
746
747#****************************************************************************
748# check emi clock driving config
749#****************************************************************************
750sub check_emi_clk_driving_cfg
751{
752 my ($emi_clk_driving, $bb_chip) = @_;
753 if ($bb_chip eq 'MT6290')
754 {
755 if (($emi_clk_driving->{'DRAMC_ACTIM0_VAL'} !~ /0x[0-9a-fA-F]{8,8}/) || ($emi_clk_driving->{'DRAMC_DRVCTL0_VAL'} !~ /0x[0-9a-fA-F]{8,8}/) || ($emi_clk_driving->{'DRAMC_DRVCTL1_VAL'} !~ /0x[0-9a-fA-F]{8,8}/))
756 {
757 return 0;
758 }
759 }
760 elsif ($bb_chip eq 'MT6291')
761 {
762 if (($emi_clk_driving->{'DRAMC_ACTIM0_VAL'} !~ /0x[0-9a-fA-F]{8,8}/) || ($emi_clk_driving->{'DRAMC_IODRV8_VAL'} !~ /0x[0-9a-fA-F]{8,8}/) || ($emi_clk_driving->{'DRAMC_DRVCTL1_VAL'} !~ /0x[0-9a-fA-F]{8,8}/))
763 {
764 return 0;
765 }
766 }
767 return 1;
768}
769
770#****************************************************************************
771# check consistency among FEATURE, MEMORY_DEVICE_TYPE, PLATFORM, MCU_CLOCK and MemoryDeviceList data
772#****************************************************************************
773sub Decide_MemClockSpeed
774{
775 print("\n", (caller(0))[3], "\n");
776
777 my $emi_force_clk = 0;
778 my $sfi_force_clk = 0;
779 if ((defined $CUSTOM_MEM_DEV_OPTIONS{EMI_CLK}) and $CUSTOM_MEM_DEV_OPTIONS{EMI_CLK} ne 'DEFAULT')
780 {
781 $emi_clk_config = $emi_force_clk = $CUSTOM_MEM_DEV_OPTIONS{EMI_CLK};
782 }
783 if ((defined $CUSTOM_MEM_DEV_OPTIONS{SFI_CLK}) and $CUSTOM_MEM_DEV_OPTIONS{SFI_CLK}ne 'DEFAULT')
784 {
785 if ($CUSTOM_MEM_DEV_OPTIONS{SFI_CLK} eq '104M')
786 {
787 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: $MAKEFILE_OPTIONS{'platform'} does not support SFI clock as 104MHz! Please configure SFI_CLK as DEFAULT!", __FILE__, __LINE__) if ($BBtbl_SFI_FAST_CLK{$MAKEFILE_OPTIONS{'platform'}} != 104);
788 $sfi_clk_config = $sfi_force_clk = 104;
789 }
790 elsif ($CUSTOM_MEM_DEV_OPTIONS{SFI_CLK} eq '78M')
791 {
792 $sfi_clk_config = $sfi_force_clk = 78;
793 }
794 else
795 {
796 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Please configure SFI_CLK as 104M, 78M, or DEFAULT!", __FILE__, __LINE__);
797 }
798 }
799
800 if($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE')
801 {
802 my $sfi_104_support = 1; # assume all devices can support 104; set as 0 if found not support
803 my $sfi_78_support = 1; # assume all devices can support 78; set as 0 if found not support
804
805 #print "test $CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE}\n";
806 ### Check if all devices can support the required clock
807 if ($sfi_force_clk != 0) # force specific clock
808 {
809 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
810 {
811 if ((!defined &Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, $sfi_clk_config, $MAKEFILE_OPTIONS{'platform'}, 'SF_CTL', \@MDL_INFO_LIST)) or (&Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, $sfi_clk_config, $MAKEFILE_OPTIONS{'platform'}, 'DRIVING', \@MDL_INFO_LIST) eq 'x') or (&Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, $sfi_clk_config, $MAKEFILE_OPTIONS{'platform'}, 'DRIVING', \@MDL_INFO_LIST) eq ' ')) # unable to find the specified clock setting
812 {
813 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Device $_ not support $sfi_clk_config MHz settings!", __FILE__, __LINE__);
814 }
815 }
816 }
817 else
818 {
819 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
820 {
821 #if ((!defined &Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 104, $MAKEFILE_OPTIONS{'platform'}, 'SF_CTL', \@MDL_INFO_LIST)) or (&Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 104, $MAKEFILE_OPTIONS{'platform'}, 'SFI_MAC_CTL', \@MDL_INFO_LIST) eq 'x') or (&Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 104, $MAKEFILE_OPTIONS{'platform'}, 'SFI_MAC_CTL', \@MDL_INFO_LIST) eq ' ')) # unable to find 104MHz clock setting
822 if (!defined &Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 104, $MAKEFILE_OPTIONS{'platform'}, 'SF_CTL', \@MDL_INFO_LIST))
823 {
824 $sfi_104_support = 0;
825 }
826 #if ((!defined &Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 78, $MAKEFILE_OPTIONS{'platform'}, 'SF_CTL', \@MDL_INFO_LIST)) or (&Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 78, $MAKEFILE_OPTIONS{'platform'}, 'SFI_MAC_CTL', \@MDL_INFO_LIST) eq 'x') or (&Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 78, $MAKEFILE_OPTIONS{'platform'}, 'SFI_MAC_CTL', \@MDL_INFO_LIST) eq ' ')) # unable to find 104MHz clock setting
827 if (!defined &Lookup_SFI_setting_by_IDX_CLK_BB_REG($_, 78, $MAKEFILE_OPTIONS{'platform'}, 'SF_CTL', \@MDL_INFO_LIST))
828 {
829 $sfi_78_support = 0;
830 }
831 if (($sfi_104_support == 0) and ($sfi_78_support == 0))
832 {
833 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Unable to find valid SFI settings!", __FILE__, __LINE__);
834 }
835 elsif ($sfi_104_support != 0)
836 {
837 $sfi_clk_config = 104;
838 }
839 else # sfi_104_support == 0 and sfi_78_support != 0
840 {
841 $sfi_clk_config = 78;
842 }
843 }
844 }
845 print "SFI_CLK configured as $sfi_clk_config\n" if ($DebugPrint == 1);
846 }
847
848 if (($emi_is_existed == 1) and ($MAKEFILE_OPTIONS{'platform'} eq 'MT6291')) {
849 ### Check if all devices can support the required clock
850 if ($emi_force_clk != 0) # force specific clock
851 {
852 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
853 {
854 my $mhz_emi_driving = $emi_clk_config . 'MHZ EMI Driving';
855 my $emi_clk_driving = $MDL_INFO_LIST[$_]->{0}->{$MAKEFILE_OPTIONS{'platform'}}->{$mhz_emi_driving};
856 if (&check_emi_clk_driving_cfg($emi_clk_driving, $MAKEFILE_OPTIONS{'platform'}) == 0)
857 {
858 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Device $_ not support $emi_clk_config MHz settings!", __FILE__, __LINE__);
859 }
860 }
861 }
862 else
863 {
864 my %emi_clk;
865 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
866 {
867 my $mdl_info_platform = $MDL_INFO_LIST[$_]->{0}->{$MAKEFILE_OPTIONS{'platform'}};
868 foreach my $mdl_info_content (sort keys %{$mdl_info_platform})
869 {
870 if ($mdl_info_content =~ /(\d+)MHZ EMI Driving/)
871 {
872 if (!defined $emi_clk{$1})
873 {
874 $emi_clk{$1} = 'TRUE';
875 }
876 my $emi_clk_driving = $mdl_info_platform->{$mdl_info_content};
877 if (&check_emi_clk_driving_cfg($emi_clk_driving, $MAKEFILE_OPTIONS{'platform'}) == 0)
878 {
879 $emi_clk{$1} = 'FALSE';
880 }
881 }
882 }
883 }
884 undef $emi_clk_config;
885 while( (my $clk_speed, my $value) = each %emi_clk)
886 {
887 if ($value eq 'TRUE')
888 {
889 next if ((defined $emi_clk_config) && ($emi_clk_config >= $clk_speed));
890
891 $emi_clk_config = $clk_speed;
892 }
893
894 }
895 if (!defined $emi_clk_config) {
896 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Device $_ not support $emi_clk_config MHz settings!", __FILE__, __LINE__);
897 }
898 }
899 print "EMI_CLK configured as $emi_clk_config\n" if ($DebugPrint == 1);
900 }
901}
902
903#****************************************************************************
904# subroutine: dump_mdl_info
905# return: none
906# input: $mdl_ref: MDL hash reference
907# $pre_string: to print prefix string
908#****************************************************************************
909sub dump_mdl_info
910{
911 my ($mdl_ref, $pre_string) = @_;
912 my $prefix_string;
913 foreach my $key (keys %{$mdl_ref})
914 {
915 $prefix_string = $pre_string if (defined $pre_string);
916 $prefix_string = $prefix_string . "{$key}";
917 if (ref $mdl_ref->{$key} eq 'HASH')
918 {
919 &dump_mdl_info($mdl_ref->{$key}, "$prefix_string->");
920 }
921 else
922 {
923 print "$prefix_string = " . $mdl_ref->{$key} . "\n";
924 }
925 }
926}
927
928#****************************************************************************
929# subroutine: fs_read_excel
930# return: hash of matching rows and indexing rows
931# input: $file: excel file to be read
932# $sheet: sheet to open
933# $target_href: the target patterns to be searched
934#****************************************************************************
935sub fs_read_excel
936{
937 my ($file, $sheet, $target_href, $BACKUP_MDL_PATH) = @_;
938 my %mdl_list;
939 my $copied_file;
940 my $curr_time_str = &get_CurrTime_str();
941 my $WorkSheet;
942 my $Excel;
943 my $Book;
944 my $parser;
945 my $workbook;
946 my ($row_min, $row_max);
947 my ($col_min, $col_max);
948
949 if (! -e $file) {
950 return %mdl_list;
951 }
952
953 ### copy and rename the current excel file to prevent concurrency build problem
954 # remove ^.\ or ^\
955 $BACKUP_MDL_PATH =~ s/^.\\|^\\//;
956
957 if($BACKUP_MDL_PATH =~ /out/)
958 {
959 print "BAKCUP_MDL_PATH match with /build/ PREMATCH:$`, MATCH:$&, POSTMATCH:$'\n";
960 $BACKUP_MDL_PATH = $& . $';
961 }
962 print "file is $file\n";
963 if($file =~ /^(\w+.*?)\.xls$/)
964 {
965 if($1 =~ /^(\w*.*?)tools(\w*.*?)MemoryDeviceList_(\w+)$/)
966 {
967 print "1:$1,2:$2,3:$3\n";
968 $copied_file = $1 . $BACKUP_MDL_PATH . "\/". "MemoryDeviceList_" . $3;
969 }
970 }
971 $copied_file = $copied_file . "_" . $sheet . "_" . $curr_time_str . $$ . ".xls";
972 File::Copy::copy($file, $copied_file);
973 $file = $copied_file;
974
975 $parser = Spreadsheet::ParseExcel->new();
976 $workbook = $parser->parse($file) or &error_handler("$file: $!", __FILE__, __LINE__);;
977 $WorkSheet = $workbook->worksheet($sheet);
978 ($row_min, $row_max) = $WorkSheet->row_range();
979 ($col_min, $col_max) = $WorkSheet->col_range();
980
981 # get the sheet name
982 my $name = $WorkSheet->get_name();
983 print "sheetname: $name, row: {$row_min, $row_max}, col: {$col_min, $col_max}\n";
984
985 my $xls_content_row_start;
986 my $xls_content_num;
987 for my $col ($col_min..$col_max)
988 {
989 my @mdl_each_col_content = undef;
990 my $array_content_row_start = undef;
991 foreach my $row ($row_min..$row_max)
992 {
993 if (($col == 0) && (!defined $WorkSheet->get_cell($row, $col)->is_merged()) && (!defined $xls_content_row_start))
994 {
995 $xls_content_row_start = $row;
996 $xls_content_num = $row_max - $xls_content_row_start + 1;
997 }
998 if (((defined $xls_content_row_start) && ($row >= $xls_content_row_start)) || (!defined $mdl_each_col_content[-1]) || ($mdl_each_col_content[-1] ne &xls_cell_value($WorkSheet, $row, $col)))
999 {
1000 push(@mdl_each_col_content, &xls_cell_value($WorkSheet, $row, $col));
1001 }
1002 if ((defined $xls_content_row_start) && ($row == $xls_content_row_start))
1003 {
1004 $array_content_row_start = $#mdl_each_col_content;
1005 }
1006 }
1007 my @hash_tail_array;
1008 my $hash_pointer;
1009 for (1..$xls_content_num)
1010 {
1011 push(@hash_tail_array, \%{$mdl_list{$_}});
1012 }
1013 print "col" if ($DebugPrint == 1);
1014 foreach my $idx (1..$array_content_row_start-1)
1015 {
1016 my $data = $mdl_each_col_content[$idx];
1017 print "{$data}" if ($DebugPrint == 1);
1018 for my $content_idx (1..$xls_content_num)
1019 {
1020 $hash_pointer = shift(@hash_tail_array);
1021 if ($idx != $array_content_row_start-1)
1022 {
1023 print "->" if ($content_idx == 1) && ($DebugPrint == 1);
1024 if (!defined $hash_pointer->{$data})
1025 {
1026 $hash_pointer->{$data} = {};
1027 }
1028 $hash_pointer = $hash_pointer->{$data};
1029 #print "[$idx][$content_idx]hash_pointer:$hash_pointer\n";
1030 }
1031 push(@hash_tail_array, $hash_pointer);
1032 }
1033 }
1034 print "=" if ($DebugPrint == 1);
1035 foreach my $idx ($array_content_row_start..$#mdl_each_col_content)
1036 {
1037 my $mdl_idx = $idx - $array_content_row_start + 1;
1038 my $data = $mdl_each_col_content[$idx];
1039 $hash_pointer = shift(@hash_tail_array);
1040 $hash_pointer->{$mdl_each_col_content[$array_content_row_start-1]} = $data;
1041 print "$mdl_idx:$data" if ($DebugPrint == 1);
1042 if ($idx != $#mdl_each_col_content)
1043 {
1044 print ", " if ($DebugPrint == 1);
1045 }
1046 }
1047 print "\n" if ($DebugPrint == 1);
1048 }
1049
1050 return %mdl_list;
1051}
1052
1053#****************************************************************************
1054# subroutine: get_info
1055# input: $file: file path
1056# $sheet: sheet to open
1057# $target_href: the target patterns to be searched
1058# $href: output matching hash reference
1059#****************************************************************************
1060sub get_info
1061{
1062 my ($file, $sheet, $target_href, $href) = @_;
1063 my %mdl_list;
1064
1065 %mdl_list = &fs_read_excel($file, $sheet, $target_href, $LOAD_TMP_PATH);
1066
1067 if (keys(%mdl_list) == 0)
1068 {
1069 print "get_info return FALSE!\n" if ($DebugPrint == 1);
1070 return "FALSE";
1071 }
1072
1073 foreach my $idx (keys %mdl_list)
1074 {
1075 if ($sheet =~ /\w+_\w+_MCP/)
1076 {
1077 if ($target_href->{0} eq $mdl_list{$idx}->{'Part Number'})
1078 {
1079 $href->{0} = $mdl_list{$idx}->{'DRAM Parameters'};
1080 $href->{1} = $mdl_list{$idx}->{'Flash Parameters'};
1081 for my $keys (keys %{$mdl_list{$idx}})
1082 {
1083 if (($keys ne 'DRAM Parameters') && ($keys ne 'Flash Parameters'))
1084 {
1085 for (0..1)
1086 {
1087 $href->{$_}->{$keys} = $mdl_list{$idx}->{$keys};
1088 }
1089 }
1090 }
1091 }
1092 }
1093 else
1094 {
1095 my $tgt = 0;
1096 $tgt = $tgt + 1 if ($sheet =~ /\w+_FLASH/);
1097 if ($target_href->{$tgt} eq $mdl_list{$idx}->{'Part Number'})
1098 {
1099 $href->{$tgt} = $mdl_list{$idx};
1100 }
1101 }
1102 }
1103 &dump_mdl_info($href, "\$href->") if ($DebugPrint == 1);
1104
1105 if (keys(%{$href}) == 0)
1106 {
1107 return "FALSE";
1108 }
1109
1110 return "TRUE";
1111}
1112
1113#****************************************************************************
1114# subroutine: xls_cell_value
1115# return: excel cell value no matter it's in merge area or not
1116# input: $sheet: specified Excel Sheet
1117# $row: specified row number
1118# $col: specified column number
1119#****************************************************************************
1120sub xls_cell_value
1121{
1122 my ($sheet, $row, $col) = @_;
1123
1124 my $cell = $sheet->get_cell($row, $col);
1125 if ($cell)
1126 {
1127 if ((defined $cell->is_merged()) && ($cell->is_merged() == 1))
1128 {
1129 my $mareas =$sheet->get_merged_areas();
1130 # get merged areas' value if cell is merged
1131 for (0..$#$mareas)
1132 {
1133 if(($row >= $mareas->[$_]->[0] && $row <= $mareas->[$_]->[2]) && ($col >= $mareas->[$_]->[1] && $col <= $mareas->[$_]->[3]))
1134 {
1135 return $sheet->get_cell($mareas->[$_]->[0], $mareas->[$_]->[1])->value();
1136 }
1137 }
1138 } else {
1139 # cell is not merged cell => get cell value
1140 return $cell->value();
1141 }
1142 } else {
1143 my $value;
1144 return $value;
1145 }
1146}
1147
1148#****************************************************************************
1149# subroutine: dependency check
1150# return: None
1151#****************************************************************************
1152sub Check_ManualCheckIn
1153{
1154 my ($target, $force_del_new_file, @depends) = @_;
1155
1156 return unless (-e $target);
1157
1158 ## Now check if the $target file check-in or auto-gen
1159 ## Read whole file ##
1160 open SRC_FILE_R, "<$target" or &error_handler("$target: file error!", __FILE__, __LINE__);
1161 local $/;
1162 my $reading = <SRC_FILE_R>;
1163 close SRC_FILE_R;
1164
1165 ## Look for check-in pattern ##
1166 if ($reading =~ /MANUAL-CHECKIN/i)
1167 {
1168 print "$target: Check-in message is found. No need to update.\n";
1169 return;
1170 }
1171
1172 unlink $target if (-e $target);
1173 return;
1174}
1175
1176#****************************************************************************
1177# subroutine: CheckConfigValid
1178# return: None
1179#****************************************************************************
1180sub CheckConfigValid
1181{
1182 print("\n", (caller(0))[3], "\n");
1183
1184 my $dram_size = eval($MDL_INFO_LIST[1]->{0}->{'Density (Mb)'});
1185
1186 ###Check DRAM Size
1187 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
1188 {
1189 if ($emi_is_existed == 1)
1190 {
1191 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Please select correct dram! dram_size is $dram_size.", __FILE__, __LINE__) if ((!defined $dram_size) || ($dram_size <= 0));
1192 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Please select dram with the same size ($dram_size vs. $MDL_INFO_LIST[$_]->{0}->{'Density (Mb)'}) when COMBO_MEMORY_SUPPORT is enabled!", __FILE__, __LINE__) if ($dram_size ne eval($MDL_INFO_LIST[$_]->{0}->{'Density (Mb)'}));
1193 }
1194 }
1195
1196 ###Check Combo Memory Supporting
1197 if($MAKEFILE_OPTIONS{'combo_memory_support'} eq 'TRUE')
1198 {
1199 my @combo_mem_part_number;
1200 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: MEMORY_DEVICE_TYPE supports only XXX_MCP when COMBO_MEMORY_SUPPORT is enabled!", __FILE__, __LINE__) if ((($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE} !~ /\w+_MCP/) && ($CUSTOM_MEM_DEV_OPTIONS{MEMORY_DEVICE_TYPE} ne 'NONE')) && ($MAKEFILE_OPTIONS{'sip_ram_size'} eq "NONE"));
1201 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
1202 {
1203 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: COMBO MEM Part Number ($MCP_LIST[$_]->{0}) of DRAM should be the same that ($MCP_LIST[$_]->{1}) of Flash!", __FILE__, __LINE__) if (($MCP_LIST[$_]->{0} ne $MCP_LIST[$_]->{1}) && ($MAKEFILE_OPTIONS{'sip_ram_size'} eq "NONE"));
1204 for my $combo_mem_idx (0..$#combo_mem_part_number)
1205 {
1206 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Each COMBO MEM Part Number should be difference ($combo_mem_part_number[$combo_mem_idx]:COMBO_MEM0$combo_mem_idx and COMBO_MEM0$_)!", __FILE__, __LINE__) if ($MCP_LIST[$_]->{1} eq $combo_mem_part_number[$combo_mem_idx]);
1207 }
1208 push(@combo_mem_part_number, $MCP_LIST[$_]->{1});
1209 }
1210 }
1211
1212 ###Combo Flash Size Should be same
1213 if($MAKEFILE_OPTIONS{'combo_memory_support'} eq 'TRUE')
1214 {
1215 if($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE')
1216 {
1217 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
1218 {
1219 my $cur_nor_size_Mb;
1220 $cur_nor_size_Mb = $MDL_INFO_LIST[$_]->{1}->{'Size (Mb)'};
1221 if (!defined $nor_size_Mb)
1222 {
1223 $nor_size_Mb = $cur_nor_size_Mb;
1224 }
1225 else
1226 {
1227 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Please select flash with the same size when COMBO_MEMORY_SUPPORT is enabled!", __FILE__, __LINE__) if ($nor_size_Mb != $cur_nor_size_Mb);
1228 }
1229 }
1230 }
1231 elsif($MAKEFILE_OPTIONS{'nand_support'} eq 'TRUE')
1232 {
1233 my $nand_size_Mb;
1234 my $nand_block_size;
1235 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
1236 {
1237 my $cur_nand_size_Mb;
1238 my $cur_nand_block_size;
1239 $cur_nand_size_Mb = $MDL_INFO_LIST[$_]->{1}->{'NAND Size(MB)'};
1240 $cur_nand_block_size = $MDL_INFO_LIST[$_]->{1}->{'NAND Block Size(KB)'};
1241 if (!defined $nand_size_Mb)
1242 {
1243 $nand_size_Mb = $cur_nand_size_Mb;
1244 $nand_block_size = $cur_nand_block_size;
1245 }
1246 else
1247 {
1248 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Please select flash with the same size when COMBO_MEMORY_SUPPORT is enabled!", __FILE__, __LINE__) if ($nand_size_Mb != $cur_nand_size_Mb);
1249 &error_handler("$CUSTOM_MEMORY_DEVICE_HDR: Please select flash with the same block size when COMBO_MEMORY_SUPPORT is enabled!", __FILE__, __LINE__) if ($nand_block_size != $cur_nand_block_size);
1250 }
1251 }
1252 }
1253 }
1254
1255 ###Serail Flash Support and NAND Support Should Not be TRUE at the same time
1256 if(($MAKEFILE_OPTIONS{'serial_flash_support'} eq 'TRUE') and ($MAKEFILE_OPTIONS{'nand_support'} eq 'TRUE'))
1257 {
1258 &error_handler("Serial Flash and NAND Flash Support at the same time, please check makefile setting!!", __FILE__, __LINE__);
1259 }
1260
1261 ###The Flash Name max length is 64
1262 if($MAKEFILE_OPTIONS{'nand_support'} eq 'TRUE')
1263 {
1264 for (1..$CUSTOM_MEM_DEV_OPTIONS{COMBO_MEM_ENTRY_COUNT})
1265 {
1266 my $vendor = uc($MDL_INFO_LIST[$_]->{1}->{'Vendor'});
1267 my $PartNumber = $MDL_INFO_LIST[$_]->{1}->{'Part Number'};
1268 my $flash_name .= "$vendor " if (defined $vendor);
1269 $flash_name .= "$PartNumber" if (defined $PartNumber);
1270 my $name_length = length($flash_name);
1271 if($name_length > 64)
1272 {
1273 &error_handler("Flash Name is too long, DA Support Max Length is 64 byte!!", __FILE__, __LINE__);
1274 }
1275 }
1276 }
1277
1278 return;
1279}
1280
1281#****************************************************************************
1282# subroutine: error_handler
1283# input: $error_msg: error message
1284#****************************************************************************
1285sub error_handler
1286{
1287 my ($error_msg, $file, $line_no) = @_;
1288 my $final_error_msg = "EMIGEN ERROR: $error_msg at $file line $line_no\n";
1289 print $final_error_msg;
1290 die $final_error_msg;
1291}
1292
1293#****************************************************************************
1294# subroutine: copyright_file_header
1295# return: file header -- copyright
1296#****************************************************************************
1297sub copyright_file_header
1298{
1299 my $template = <<"__TEMPLATE";
1300/*****************************************************************************
1301* Copyright Statement:
1302* --------------------
1303* This software is protected by Copyright and the information contained
1304* herein is confidential. The software may not be copied and the information
1305* contained herein may not be used or disclosed except with the written
1306* permission of MediaTek Inc. (C) 2019
1307*
1308* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
1309* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
1310* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
1311* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
1312* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
1313* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
1314* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
1315* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
1316* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
1317* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
1318* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
1319* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
1320*
1321* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
1322* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
1323* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
1324* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
1325* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
1326*
1327* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
1328* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
1329* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
1330* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
1331* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
1332*
1333*****************************************************************************/
1334
1335__TEMPLATE
1336
1337 return $template;
1338}
1339
1340#****************************************************************************
1341# subroutine: description_file_header
1342# return: file header -- description
1343# input: $filename: filename
1344# input: $description: one line description
1345# input: $author: optional
1346#****************************************************************************
1347sub description_file_header
1348{
1349 my ($filename, $description, $author) = @_;
1350 my $src_file = (-e $MEMORY_DEVICE_LIST_XLS)? $MEMORY_DEVICE_LIST_XLS:
1351 (-e $MEMORY_DEVICE_LIST_INT_XLS)? $MEMORY_DEVICE_LIST_INT_XLS:
1352 __FILE__;
1353 my $datetime = POSIX::strftime("%Y/%m/%d_%H:%M:%S", localtime((stat $src_file)[9]));
1354
1355 my $template = <<"__TEMPLATE";
1356/*****************************************************************************
1357 *
1358 * Filename:
1359 * ---------
1360 * $filename
1361 *
1362 * Project:
1363 * --------
1364 * MOLY
1365 *
1366 * Description:
1367 * ------------
1368 * $description
1369 *
1370 * Author:
1371 * -------
1372 * $author by emigen $EMIGEN_VERNO
1373 *
1374 * Memory Device database last modified on $datetime
1375 *
1376 *============================================================================
1377 * HISTORY
1378 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
1379 *------------------------------------------------------------------------------
1380 * \$Revision\$
1381 * \$Modtime\$
1382 * \$Log\$
1383 *
1384 *------------------------------------------------------------------------------
1385 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
1386 *============================================================================
1387 ****************************************************************************/
1388
1389__TEMPLATE
1390
1391 return $template;
1392}
1393
1394#******************************************************************************
1395# subroutine: get_CurrTime_str
1396# return: string of the current time
1397# input: None
1398#******************************************************************************
1399sub get_CurrTime_str
1400{
1401 my($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
1402 return (sprintf "%04d_%02d_%02d_%02d_%02d_%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
1403}
1404
1405#****************************************************************************
1406# subroutine: SCHEME Configure Routines :: Query :: MD Information
1407#****************************************************************************
1408sub query_MD_INFO
1409{
1410 my ($MAKEFILE_OPTIONS_LOCAL,$CUSTOM_MEM_DEV_OPTIONS_LOCAL,$COMM_MDL_INFO_LOCAL) = @_;
1411 open write_file, ">", "MD_INFO.txt" or &error_handler("MD_INFO.txt: $!", __FILE__, __LINE__);
1412 #if(($CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'} = 'LPDDR') || ($CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'} = 'LPDDR2') || ($CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'} = 'LPSDRAM'))
1413 #{
1414 #if(defined $MAKEFILE_OPTIONS{'sip_ram_size'})
1415 #{
1416 #print write_file "Memory device type:$CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'}";
1417 #print write_file "size:$COMM_MDL_INFO{1}->{'Size (Mb)'}"
1418 #}
1419 #else
1420 #{
1421 #print write_file "Memory device type:$CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'}";
1422 #print write_file "size:$COMM_MDL_INFO{1}->{'Size (Mb)'}"
1423 #}
1424
1425 #}
1426 #else
1427 #{
1428 #if(defined $MAKEFILE_OPTIONS{'sip_ram_size'})
1429 #{
1430 #print write_file "Memory device type:$CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'}";
1431 #print write_file "size:$COMM_MDL_INFO{1}->{'Size (Mb)'}"
1432 #}
1433 #else
1434 #{
1435 #print write_file "Memory device type:$CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'}";
1436 #print write_file "size:$COMM_MDL_INFO{1}->{'Size (Mb)'}"
1437 #}
1438 #}
1439
1440 print write_file "Memory device type:$CUSTOM_MEM_DEV_OPTIONS{'MEMORY_DEVICE_TYPE'}\n";
1441 print write_file "size:$COMM_MDL_INFO{1}->{'Size (Mb)'}\n";
1442 close(write_file);
1443}
1444
1445#****************************************************************************
1446# subroutine: Parse Custom Feature Configuration
1447#****************************************************************************
1448sub Parse_custom_FeatureConfig
1449{
1450 print("\n", (caller(0))[3], "\n");
1451
1452 open CUSTOM_FEATURE_CONFIG_HDR, "<$CUSTOM_FEATURE_CONFIG_HDR" or &error_handler("$CUSTOM_FEATURE_CONFIG_HDR: $!", __FILE__, __LINE__);
1453 while (<CUSTOM_FEATURE_CONFIG_HDR>)
1454 {
1455 # error-checking
1456 if ((/^#if|^#ifdef|^#ifndef|^#elif|^#else/) && !(/^#ifndef\s+__CUSTOM_FEATURECONFIG_H__/))
1457 {
1458 &error_handler("$CUSTOM_FEATURE_CONFIG_HDR: Not allowed to set conditional keywords $_ in custom_FeatureConfig.h!", __FILE__, __LINE__);
1459 }
1460
1461 if (/^#define\s+(\w+)\s+\(?([\w|\-]*)\)?/)
1462 {
1463 &error_handler("$CUSTOM_FEATURE_CONFIG_HDR: $1 redefined in custom_FeatureConfig.h!", __FILE__, __LINE__) if defined($CUSTOM_FEATURE_CFG_OPTIONS{$1});
1464 $CUSTOM_FEATURE_CFG_OPTIONS{$1} = ((!defined $2) or ($2 eq ''))? 'TRUE': $2;
1465 }
1466 }
1467 close CUSTOM_FEATURE_CONFIG_HDR;
1468}
1469
1470return 1;