rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [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) 2005
|
| 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 | #*
|
| 38 | #* Filename:
|
| 39 | #* ---------
|
| 40 | #* zImageProcess.pl
|
| 41 | #*
|
| 42 | #* Project:
|
| 43 | #* --------
|
| 44 | #* Maui_Software
|
| 45 | #*
|
| 46 | #* Description:
|
| 47 | #* ------------
|
| 48 | #* This file implemented the ZIMAGE post build process.
|
| 49 | #*
|
| 50 | #*
|
| 51 | #* Author:
|
| 52 | #* -------
|
| 53 | #* Ke-Ting Chen (mtk03141)
|
| 54 | #*
|
| 55 | #*****************************************************************************
|
| 56 | package aliceProcess;
|
| 57 | #****************************************************************************
|
| 58 | # Included Modules
|
| 59 | #****************************************************************************
|
| 60 | use strict;
|
| 61 | use warnings;
|
| 62 | BEGIN { push @INC, '.\\pcore\\tools\\' } # add additional library path
|
| 63 | use vivaHelper;
|
| 64 | use File::Copy;
|
| 65 |
|
| 66 | #****************************************************************************
|
| 67 | # Constants
|
| 68 | #****************************************************************************
|
| 69 | my $DEBUG = 1;
|
| 70 | my $aliceBinaryName = "ALICE";
|
| 71 | my $aliceBinaryBackupName = "ALICE.bin";
|
| 72 | my $compressTool = "pcore\\tools\\ALICE.exe";
|
| 73 | my %info = ("name" => "ALICE",
|
| 74 | "binary_name" => $aliceBinaryName,
|
| 75 | "struct_name" => "alice",
|
| 76 | "entry_function" => \&Process);
|
| 77 |
|
| 78 | #****************************************************************************
|
| 79 | # subroutine: Process
|
| 80 | # description: Perform the ZIMAGE post build process.
|
| 81 | # input: Binary folder, available start address,
|
| 82 | # original start address ref, original size ref
|
| 83 | # output: Actual start address, new binary size
|
| 84 | #****************************************************************************
|
| 85 | sub Process
|
| 86 | {
|
| 87 | my $binaryFolder = shift;
|
| 88 | my $availableStartAddress = shift;
|
| 89 | my $startAddressRef = shift;
|
| 90 | my $sizeRef = shift;
|
| 91 |
|
| 92 | my $binary = "$binaryFolder\\$aliceBinaryName";
|
| 93 | my $binaryBackup = "$binaryFolder\\$aliceBinaryBackupName";
|
| 94 |
|
| 95 | my $compressedStartAddress = &vivaHelper::RoundUpToAlignment($availableStartAddress, 4);
|
| 96 | my $decompressedStartAddress = $$startAddressRef;
|
| 97 |
|
| 98 | my $aliceEnabled = &vivaHelper::GetMakefileOption("ALICE_SUPPORT");
|
| 99 | unless (defined $aliceEnabled and
|
| 100 | $aliceEnabled eq "TRUE" and
|
| 101 | -e $binary)
|
| 102 | {
|
| 103 | return 0;
|
| 104 | }
|
| 105 |
|
| 106 | # Backup the original binary
|
| 107 | printLog("Backup binary...");
|
| 108 | move($binary, $binaryBackup) or
|
| 109 | &vivaHelper::ErrorHandler("Cannot backup ALICE binary $binary: $!", __FILE__, __LINE__);
|
| 110 |
|
| 111 | # Update start address
|
| 112 | # Need 4 byte align
|
| 113 | $$startAddressRef = &vivaHelper::RoundUpToAlignment($availableStartAddress, 4);
|
| 114 |
|
| 115 | # Compress the binary directly
|
| 116 | {
|
| 117 | my $chip = &vivaHelper::GetMakefileOption("PLATFORM");
|
| 118 | printLog("Compressing binary...");
|
| 119 | if (0 != system("$compressTool -chip $chip -iBin $binaryBackup -oBin $binary -cBase $compressedStartAddress -dBase $decompressedStartAddress"))
|
| 120 | {
|
| 121 | &vivaHelper::ErrorHandler("Cannot compress ALICE binary $binary", __FILE__, __LINE__);
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | # Update binary size
|
| 126 | $$startAddressRef = $compressedStartAddress;
|
| 127 | $$sizeRef = -s $binary;
|
| 128 |
|
| 129 | #debugLog("Base Address: $$startAddressRef");
|
| 130 | #debugLog("Length: $$sizeRef");
|
| 131 |
|
| 132 | return 1;
|
| 133 | }
|
| 134 |
|
| 135 | #****************************************************************************
|
| 136 | # subroutine: GetInfo
|
| 137 | # description: Get the basic information of processing
|
| 138 | # input: None
|
| 139 | # output: Info ref
|
| 140 | #****************************************************************************
|
| 141 | sub GetInfo
|
| 142 | {
|
| 143 | return \%info;
|
| 144 | }
|
| 145 |
|
| 146 | #****************************************************************************
|
| 147 | # subroutine: GetRawDataStartAddress
|
| 148 | # description: Get the start address of ALICE raw data on the target
|
| 149 | # input: VIVA binary path, Is SV5
|
| 150 | # output: Base address
|
| 151 | #****************************************************************************
|
| 152 | sub GetRawDataStartAddress
|
| 153 | {
|
| 154 | my $binaryPath = shift;
|
| 155 | my $isSV5 = shift;
|
| 156 | my %vivaInfo;
|
| 157 | my $aliceBaseAddress;
|
| 158 | &vivaHelper::ReadVIVAInfoFromBinary_NI($binaryPath, \%vivaInfo, $isSV5);
|
| 159 |
|
| 160 | $aliceBaseAddress = $vivaInfo{"alice_base"};
|
| 161 |
|
| 162 | # TODO: read the alice header to check the remapping bank
|
| 163 | $aliceBaseAddress = ($aliceBaseAddress & 0x0FFFFFFF) | 0x90000000;
|
| 164 |
|
| 165 | return $aliceBaseAddress;
|
| 166 | }
|
| 167 |
|
| 168 | sub printLog
|
| 169 | {
|
| 170 | print "[ALICE] $_[0]\n";
|
| 171 | }
|
| 172 |
|
| 173 | sub debugLog
|
| 174 | {
|
| 175 | if ($DEBUG)
|
| 176 | {
|
| 177 | printLog("[ALICE] $_[0]");
|
| 178 | }
|
| 179 | }
|
| 180 |
|
| 181 | 1;
|
| 182 |
|
| 183 | # tools\ALICE.exe -chip MT6250 -iBin .\build\MT6250_EVB\MT6250_EVB_PCB01_gprs_MT6250_S00.MAUI_11BW1132SP_W12_08.bin\ALICE.bin -oBin .\build\MT6250_EVB\MT6250_EVB_PCB01_gprs_MT6250_S00.MAUI_11BW1132SP_W12_08.bin\ALICE -base 273860240 -statistics statistics.txt -debugLevel 3
|