blob: 6fca8b198ac2243626fcdefd76d8faa166524037 [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) 2012
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#* cp_dsp_files.pl
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This script is to copy dsp files and append the DSP label info.
48##*
49#* Author:
50#* -------
51#* Ray Lin-Wang (mtk04222)
52#*
53#****************************************************************************/
54#****************************************************************************
55# Included Modules
56#****************************************************************************
57use strict;
58use File::Copy;
59use File::Path;
60use File::Basename;
61use Cwd;
62
63#****************************************************************************
64# Input Parameters & Global Variables
65#****************************************************************************
66(($#ARGV <0) || ($#ARGV > 6)) && &Usage;
67my $dsp_dir = $ARGV[0]; # The DSP folder ex:modem/dsp_bin
68my $build_dsp_dir = $ARGV[1]; # The DSP files will copy to this folder ex: build/$project/$flavor/bin/dsp
69my $target_dir = $ARGV[2]; # The DSP bin will copy to this folder ex: build/$project/$flavor/bin/
70my $project_mk = $ARGV[3]; # The project makefile path. ex: make/pcore/XXXX.mak
71my $dsp_version = $ARGV[4]; # The DSP label info.
72my $need_cp_sig = $ARGV[5]; # Copy signature file accodring to PARTIAL_SOURCE
73my $info_out_file = $ARGV[6]; # output the DSP info to this file for cmmgen
74$target_dir = dirname($target_dir) if(!-d $target_dir);
75
76my $OStype = 'WIN';
77if($^O ne "MSWin32"){
78 $OStype = 'LINUX';
79}
80my $dsp_project ="";
81my $dsp_flavor = "";
82my $dsp_file = "";
83my $nand_flash_support = "";
84my $category ="";
85#****************************************************************************
86# Read from project makefile
87#****************************************************************************
88my %feature;
89open(FILE_HANDLE, "<$project_mk") or &error_handler("Fail to read $project_mk!", __FILE__, __LINE__);
90while (<FILE_HANDLE>)
91{
92 if (/^(\w+)\s*=\s*(\S+)/)
93 {
94 my $keyname = $1;
95 defined($feature{$keyname}) && warn "$1 redefined in $project_mk!\n";
96 $feature{$keyname} = $2;
97 }
98}
99close FILE_HANDLE;
100
101#****************************************************************************
102# Setting DSP files
103#****************************************************************************
104# read dsp_project
105if (defined($feature{'DSP_PROJECT'}) && $feature{'DSP_PROJECT'} ne "") {
106 $dsp_project = $feature{'DSP_PROJECT'};
107}
108else {
109 &error_handler("Fail to get the DSP_PROJECT value from $project_mk!", __FILE__, __LINE__);
110}
111
112#read dsp_flavor
113if (defined($feature{'DSP_FLAVOR'}) && $feature{'DSP_FLAVOR'} ne "") {
114 $dsp_flavor = $feature{'DSP_FLAVOR'};
115}
116else {
117 &error_handler("Fail to get the DSP_FLAVOR value from $project_mk!", __FILE__, __LINE__);
118}
119
120#read nand_support
121if (defined($feature{'NAND_SUPPORT'}) && $feature{'NAND_SUPPORT'} ne "") {
122 $nand_flash_support = $feature{'NAND_SUPPORT'};
123}
124else {
125 &error_handler("Fail to get the NAND_SUPPORT value from $project_mk!", __FILE__, __LINE__);
126}
127if ($nand_flash_support eq "TRUE") {
128 $category = "NAND";
129} else {
130 $category = "SPI";
131}
132
133#****************************************************************************
134# Execute
135#****************************************************************************
136my $pattern = "DSP";
137my @delfiles = glob "$target_dir/${pattern}*.bin";
138unlink(@delfiles) if (@delfiles);
139
140#my $dsp_bin_file = "${dsp_dir}/${dsp_project}/${dsp_flavor}/${category}/${dsp_project}_${dsp_flavor}_${category}.bin";
141my $dsp_bin_file = "${dsp_dir}/$dsp_project/$dsp_flavor/final_bin/dsp.bin";
142my ($name, $path, $suffix) = fileparse($dsp_bin_file,qr/\.+?.*/);
143my $dsp_dst_file = "$target_dir/DSP_${dsp_version}${suffix}";
144my @dsp_dbg_file = glob "${dsp_dir}/$dsp_project/$dsp_flavor/final_bin/DbgInfo_DSP_*";
145&error_handler("There're more than one DbgInfo_DSP_* files under folder: ${dsp_dir}/$dsp_project/$dsp_flavor/final_bin, please remove the old DbgInfo_DSP_* file\n") if $#dsp_dbg_file ne 0;
146#if ($dsp_version !~ /DSP/) {
147# &error_handler("Cannot find the \"DSP\" pattern in the DSP version \"$dsp_version\", it may cause download fail.", __FILE__, __LINE__);
148#}
149copy($dsp_bin_file,"$dsp_dst_file") or &error_handler("copy $dsp_bin_file to $dsp_dst_file $!", __FILE__, __LINE__);
150
151my @del_dsp_dbg_files = glob "$target_dir/DbgInfo_DSP_*";
152unlink(@del_dsp_dbg_files) if (@del_dsp_dbg_files);
153if (-e $dsp_dbg_file[0]){
154 copy("$dsp_dbg_file[0]","$target_dir") or &error_handler("copy $dsp_dbg_file[0] to $target_dir $!", __FILE__, __LINE__);
155}
156
157if ($need_cp_sig eq "TRUE" && -e "$dsp_bin_file.sig") {
158 copy("$dsp_bin_file.sig","$dsp_dst_file.sig") or &error_handler("copy $dsp_bin_file.sig to $dsp_dst_file.sig $!", __FILE__, __LINE__);
159}
160
161# write the DSP file to cp_dsp_info.tmp for cmmgen
162open(FH,">$info_out_file") or &error_handler("Cannot open $info_out_file!", __FILE__, __LINE__);
163print FH "DSPMOLY_BIN = $dsp_dst_file\n";
164close(FH);
165
166#****************************************************************************
167# subroutine: Usage
168#****************************************************************************
169sub Usage
170{
171 warn <<"_END_OF_USAGE";
172Usage:
173 perl cp_dsp_files.pl dsp_folder build_dsp_folder bin_folder platform label
174Example:
175 perl pcore/tools/cp_dsp_files.pl ./pcore/modem/dsp_bin ./build/project/flavor/bin/dsp ./build/project/flavor/bin MTXXXX XX_XX_W1X_1X
176
177_END_OF_USAGE
178 exit 1;
179}
180
181#****************************************************************************
182# subroutine: error_handler
183# input: $error_msg: error message
184#****************************************************************************
185sub error_handler
186{
187 my ($error_msg, $file, $line_no) = @_;
188
189 my $final_error_msg = "COPY_DSP_FILES ERROR: $error_msg at $file line $line_no\n";
190 print $final_error_msg;
191 die $final_error_msg;
192}