| #!/usr/bin/perl |
| # |
| # Copyright Statement: |
| # -------------------- |
| # This software is protected by Copyright and the information contained |
| # herein is confidential. The software may not be copied and the information |
| # contained herein may not be used or disclosed except with the written |
| # permission of MediaTek Inc. (C) 2006 |
| # |
| # BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| # THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| # RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| # AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| # NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| # SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| # SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| # THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| # NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| # SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| # |
| # BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| # LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| # AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| # OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| # MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| # |
| # THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| # WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| # LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| # RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| # THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| # |
| #***************************************************************************** |
| #* |
| #* Filename: |
| #* --------- |
| #* cfgGen.pl |
| #* |
| #* Project: |
| #* -------- |
| #* |
| #* |
| #* Description: |
| #* ------------ |
| #* This script generates the CFG file for flash tool |
| #* |
| #* Author: |
| #* ------- |
| #* Cindy Tu |
| #* |
| #****************************************************************************/ |
| |
| #**************************************************************************** |
| # Included Modules |
| #**************************************************************************** |
| use strict; |
| use Cwd qw(realpath); |
| use File::Basename qw(dirname); |
| #**************************************************************************** |
| # Constants |
| #**************************************************************************** |
| my $CFGGEN_VERNO = " m0.03"; |
| # v0.03 , Update to support emigen |
| # v0.02 , Update for ASIC |
| # v0.01 , Update bootloader naming rule |
| # v0.00 , initial version |
| |
| #**************************************************************************** |
| # Input Parameters and Global Variables |
| #**************************************************************************** |
| my $BUILD_PATH = $ARGV[0]; |
| my $BL_BIN = $ARGV[1]; |
| my $MAKEFILE = $ARGV[2]; |
| my $BB_PATH = $ARGV[3]; |
| my $CC_CMD = $ARGV[4]; |
| my $VIA_CMD = $ARGV[5]; |
| my $OPTION_TMP = $ARGV[6]; |
| my $TMP_FOLDER = $ARGV[7]; |
| my $PRELOAD_BIN = $ARGV[8]; |
| #my $NET_PATH = $ARGV[8]; |
| #my $ACT_SIGN = $ARGV[9]; |
| |
| my $DebugPrint = 1; |
| |
| print "preCfggen: BUILD_PATH: $BUILD_PATH, BL_BIN: $BL_BIN, MAKEFILE: $MAKEFILE, BB_PATH: $BB_PATH, CC_CMD=$CC_CMD, VIA_CMD=$VIA_CMD, OPTION_TMP=$OPTION_TMP, Temp folder=$TMP_FOLDER\n" if ($DebugPrint == 1); |
| |
| #**************************************************************************** |
| # 1 >>> parse Project Make File |
| #**************************************************************************** |
| my %MAKEFILE_OPTIONS; |
| &Parse_Makefile(); |
| my $PLATFORM = $MAKEFILE_OPTIONS{'platform'}; |
| my $BOARD_VER = $ENV{"BOARD_VER"}; |
| my $BOARD_TYPE = $PLATFORM . "_" . $BOARD_VER; |
| |
| #**************************************************************************** |
| # 2 >>> generate the output cfg file for SV5 |
| #**************************************************************************** |
| my $CFG_FILE = $BUILD_PATH . "/" . $PLATFORM . "\.cfg"; |
| |
| my $FILEPATH = realpath dirname $0; |
| print "preCfggen: perl file path:$FILEPATH\n" if ($DebugPrint == 1); |
| require "$FILEPATH/cfgGen_EMI.pl"; |
| |
| ### Bootloader naming |
| |
| if ($BL_BIN eq "") |
| { |
| print "BL_BIN is NULL, set to default naming\n"; |
| # Set default bootloader name |
| $BL_BIN = "bootloader.bin"; |
| } |
| |
| open (CFG_FILE, ">$CFG_FILE") or &error_handler("$CFG_FILE: file error!", __FILE__, __LINE__); |
| |
| print CFG_FILE &gen_general_setting(); |
| print CFG_FILE &gen_boot_region_setting($BL_BIN, $PRELOAD_BIN); |
| print CFG_FILE &gen_control_block_region_setting(); |
| print CFG_FILE &gen_main_region_setting(); |
| print CFG_FILE &gen_fs_region_setting(); |
| print CFG_FILE &gen_external_memory_setting($BB_PATH, $BOARD_TYPE, $PLATFORM, $CC_CMD, $VIA_CMD, $OPTION_TMP, $TMP_FOLDER, \%MAKEFILE_OPTIONS); |
| print "preCfggen:$CFG_FILE is generated\n"; |
| |
| ### Sign |
| # if ($ACT_SIGN eq "-sign") |
| # { |
| # my $CFG_FILE_NET_PATH = $CFG_FILE; |
| # $CFG_FILE_NET_PATH =~ s/^\.\///; |
| # print "CFG_FILE_NET_PATH = $NET_PATH/$CFG_FILE_NET_PATH\n"; |
| # if($^O eq "MSWin32") |
| # { |
| # system("\\\\mbjsap101\\Guardian_Programs\\Guardian\\bin\\Debug\\Guardian.exe $NET_PATH\\$CFG_FILE_NET_PATH"); |
| # } |
| # else |
| # { |
| # system("/proj/wcp1sm/Guardian $NET_PATH/$CFG_FILE_NET_PATH"); |
| # } |
| # } |
| |
| |
| exit; |
| |
| #**************************************************************************** |
| # parse Project Makefile |
| #**************************************************************************** |
| sub Parse_Makefile |
| { |
| my @filelist = ($MAKEFILE, undef); |
| my $keyname; |
| |
| foreach my $filename (@filelist) { |
| print " filename: $filename\n" if ($DebugPrint == 1); |
| &error_handler("$filename: NOT exist!", __FILE__, __LINE__) if (!-e $filename); |
| |
| open (FILE_HANDLE, "<$filename") or &error_handler("$filename: file error!", __FILE__, __LINE__); |
| while (<FILE_HANDLE>) { |
| if (/^(\w+)\s*=\s*(\S+)/) { |
| $keyname = lc($1); |
| defined($MAKEFILE_OPTIONS{$keyname}) && warn "$1 redefined in $MAKEFILE!\n"; |
| $MAKEFILE_OPTIONS{$keyname} = $2; #uc($2); |
| if ($keyname eq 'internal_feature_option') { |
| $filelist[1] = $2; |
| $filelist[1] =~ s/\$WORKDIR/$ENV{WORKDIR}/; |
| } |
| if ($DebugPrint == 1) { |
| print "$1:$2\n"; |
| } |
| } |
| } |
| close (FILE_HANDLE); |
| } |
| |
| $MAKEFILE_OPTIONS{'platform'} = $MAKEFILE_OPTIONS{'platform_chip'} or "MT6291"; |
| } |
| |
| #**************************************************************************** |
| # subroutine: gen_general_setting |
| # return: General Setting |
| #**************************************************************************** |
| sub gen_general_setting |
| { |
| my $template = <<"__TEMPLATE"; |
| ############################################################################################################ |
| # |
| # General Setting |
| # |
| ############################################################################################################ |
| |
| general: |
| config_version : alpha # config file version ("alpha", "beta" is used before SQC done.) |
| # After SQC done, the version should be "1" for the first release version. |
| platform: $PLATFORM # It is used for tool to identify the right setting for specific target |
| |
| __TEMPLATE |
| } |
| |
| #**************************************************************************** |
| # subroutine: gen_boot_region_setting |
| # return: Boot Region Setting |
| #**************************************************************************** |
| sub gen_boot_region_setting |
| { |
| (my $bl_bin, my $preload_bin) = @_; |
| my $template = <<"__TEMPLATE"; |
| ############################################################################################################ |
| # |
| # Boot Region Setting |
| # |
| ############################################################################################################ |
| |
| boot_region: |
| alignment: block # block[default], page(NAND:2K/512B, NOR: 1KB, eMMC: 512B, SF: 256B) |
| rom: |
| - file: $bl_bin |
| - file: $preload_bin |
| |
| __TEMPLATE |
| } |
| |
| #**************************************************************************** |
| # subroutine: gen_control_block_region_setting |
| # return: Control Block Region Setting |
| #**************************************************************************** |
| sub gen_control_block_region_setting |
| { |
| my $template = <<"__TEMPLATE"; |
| ############################################################################################################ |
| # |
| # Control Block Region Setting |
| # |
| ############################################################################################################ |
| |
| control_block_region: |
| rom: |
| |
| __TEMPLATE |
| } |
| |
| #**************************************************************************** |
| # subroutine: gen_main_region_setting |
| # return: Main Region Setting |
| #**************************************************************************** |
| sub gen_main_region_setting |
| { |
| my $template = <<"__TEMPLATE"; |
| ############################################################################################################ |
| # |
| # Main Region Setting |
| # |
| ############################################################################################################ |
| |
| main_region: |
| alignment: block # block[default], page(NAND:2K/512B, NOR: 1KB, eMMC: 512B, SF: 256B) |
| rom: |
| |
| __TEMPLATE |
| } |
| |
| #**************************************************************************** |
| # subroutine: gen_fs_region_setting |
| # return: File System Region Setting |
| #**************************************************************************** |
| sub gen_fs_region_setting |
| { |
| my $template = <<"__TEMPLATE"; |
| ############################################################################################################ |
| # |
| # File System Region Setting |
| # |
| ############################################################################################################ |
| |
| file_system_region: |
| rom: |
| |
| __TEMPLATE |
| } |
| |
| #**************************************************************************** |
| # subroutine: error_handler |
| # input: $error_msg: error message |
| #**************************************************************************** |
| sub error_handler |
| { |
| my ($error_msg, $file, $line_no) = @_; |
| |
| my $final_error_msg = "CFGGEN ERROR: $error_msg at $file line $line_no\n"; |
| print $final_error_msg; |
| die $final_error_msg; |
| } |
| |