yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | #!/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 | #* gen_bin_from_elf.pl
|
| 40 | #*
|
| 41 | #* Project:
|
| 42 | #* --------
|
| 43 | #*
|
| 44 | #*
|
| 45 | #* Description:
|
| 46 | #* ------------
|
| 47 | #* The script will generate single bin file or multiple bin files from elf file.
|
| 48 | #*
|
| 49 | #*
|
| 50 | #* Author:
|
| 51 | #* -------
|
| 52 | #* Amber Su (mtk03389)
|
| 53 | #*
|
| 54 | #*============================================================================
|
| 55 | #* HISTORY
|
| 56 | #* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
|
| 57 | #*------------------------------------------------------------------------------
|
| 58 | #* $Revision$
|
| 59 | #* $Modtime$
|
| 60 | #* $Log$
|
| 61 | #*
|
| 62 | #* 09 04 2018 chi-chun.lu
|
| 63 | #* [MOLY00350152] [VMOLY build] dummy checkin for correcting ownership |
| 64 | #* |
| 65 | #* .
|
| 66 | #*
|
| 67 | #* 09 21 2012 amber.su
|
| 68 | #* [MOLY00003688] [SystemService][Auto-Gen][Internal Refinement] Support BOOT_CERT & multibin on MOLY
|
| 69 | #* .
|
| 70 | #*
|
| 71 | #* 09 12 2012 amber.su
|
| 72 | #* NULL
|
| 73 | #* .
|
| 74 | #*
|
| 75 | #*
|
| 76 | #*
|
| 77 | #*------------------------------------------------------------------------------
|
| 78 | #* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
|
| 79 | #*============================================================================
|
| 80 | #****************************************************************************/
|
| 81 | #****************************************************************************
|
| 82 | # Included Modules
|
| 83 | #****************************************************************************
|
| 84 | use File::Path;
|
| 85 | BEGIN { push @INC , './tools/' }
|
| 86 | require 'sysGen2.pl';
|
| 87 |
|
| 88 | #****************************************************************************
|
| 89 | # Input and Parameters initialization
|
| 90 | #****************************************************************************
|
| 91 | my ($bin_create,$linker_script,$elf_file,$bin_file)=@ARGV;
|
| 92 | my $err_flag = 0;
|
| 93 | print "Input: $bin_create $linker_script $elf_file $bin_file\n";
|
| 94 | &error_handler("$linker_script does not exist!", __FILE__, __LINE__) if(!-e $linker_script);
|
| 95 | #****************************************************************************
|
| 96 | # Main Flow
|
| 97 | #****************************************************************************
|
| 98 | my $objcopy_input_href = &GetOBJCOPYInput($linker_script);
|
| 99 | if(defined $objcopy_input_href)
|
| 100 | {
|
| 101 | rmtree($bin_file) or &error_handler("delete $bin_file folder failed!", __FILE__, __LINE__) if(-d $bin_file);
|
| 102 | mkpath($bin_file) or &error_handler("create $bin_file folder failed!", __FILE__, __LINE__) if(!-d $bin_file);
|
| 103 | foreach my $strBinFileName (keys %$objcopy_input_href)
|
| 104 | {
|
| 105 | $strCommandLine = $objcopy_input_href->{$strBinFileName};
|
| 106 | $cmd = "$bin_create -O binary $strCommandLine $elf_file $bin_file/$strBinFileName";
|
| 107 | print "$cmd\n";
|
| 108 | $result = system("$cmd");
|
| 109 | if($result != 0)
|
| 110 | {
|
| 111 | $err_flag = 1;
|
| 112 | print "Failed!\n";
|
| 113 | }
|
| 114 | else
|
| 115 | {
|
| 116 | print "Done!\n";
|
| 117 | }
|
| 118 | }
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | $cmd = "$bin_create -O binary $elf_file $bin_file";
|
| 123 | print "$cmd\n";
|
| 124 | $result = system("$cmd");
|
| 125 | if($result != 0)
|
| 126 | {
|
| 127 | $err_flag = 1;
|
| 128 | print "Failed!\n";
|
| 129 | }
|
| 130 | else
|
| 131 | {
|
| 132 | print "Done!\n";
|
| 133 | }
|
| 134 | }
|
| 135 | if($err_flag)
|
| 136 | {
|
| 137 | &error_handler("The process of generating bin file failed!", __FILE__, __LINE__);
|
| 138 | }
|
| 139 | else
|
| 140 | {
|
| 141 | print "The process of generating bin file is finished!\n";
|
| 142 | exit 0;
|
| 143 | }
|
| 144 | #*************************************************************************************************
|
| 145 | # Error Handling Message
|
| 146 | #*************************************************************************************************
|
| 147 | sub error_handler
|
| 148 | {
|
| 149 | my ($error_msg, $file, $line_no) = @_;
|
| 150 | my $final_error_msg = "Error: $error_msg at $file line $line_no\n";
|
| 151 | print "$final_error_msg";
|
| 152 | exit 3;
|
| 153 | }
|