[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/tools/aliceProcess.pm b/mcu/tools/aliceProcess.pm
new file mode 100644
index 0000000..9c076e8
--- /dev/null
+++ b/mcu/tools/aliceProcess.pm
@@ -0,0 +1,183 @@
+#!/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) 2005

+#

+#  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:

+#* ---------

+#*   zImageProcess.pl

+#*

+#* Project:

+#* --------

+#*   Maui_Software

+#*

+#* Description:

+#* ------------

+#*   This file implemented the ZIMAGE post build process.

+#*

+#*

+#* Author:

+#* -------

+#*   Ke-Ting Chen (mtk03141)

+#*

+#*****************************************************************************

+package aliceProcess;

+#****************************************************************************

+# Included Modules

+#****************************************************************************

+use strict;

+use warnings;

+BEGIN { push @INC, '.\\pcore\\tools\\' }  # add additional library path

+use vivaHelper;

+use File::Copy;

+

+#****************************************************************************

+# Constants

+#****************************************************************************

+my $DEBUG = 1;

+my $aliceBinaryName = "ALICE";

+my $aliceBinaryBackupName = "ALICE.bin";

+my $compressTool = "pcore\\tools\\ALICE.exe";

+my %info = ("name" => "ALICE",

+            "binary_name" => $aliceBinaryName,

+            "struct_name" => "alice",

+            "entry_function" => \&Process);

+

+#****************************************************************************

+# subroutine:  Process

+# description: Perform the ZIMAGE post build process.

+# input:       Binary folder, available start address,

+#              original start address ref, original size ref

+# output:      Actual start address, new binary size

+#****************************************************************************

+sub Process

+{

+   my $binaryFolder = shift;

+   my $availableStartAddress = shift;

+   my $startAddressRef = shift;

+   my $sizeRef = shift;

+

+   my $binary = "$binaryFolder\\$aliceBinaryName";

+   my $binaryBackup = "$binaryFolder\\$aliceBinaryBackupName";

+

+   my $compressedStartAddress = &vivaHelper::RoundUpToAlignment($availableStartAddress, 4);

+   my $decompressedStartAddress = $$startAddressRef;

+

+   my $aliceEnabled = &vivaHelper::GetMakefileOption("ALICE_SUPPORT");

+   unless (defined $aliceEnabled and

+           $aliceEnabled eq "TRUE" and

+           -e $binary)

+   {

+      return 0;

+   }

+

+   # Backup the original binary

+   printLog("Backup binary...");

+   move($binary, $binaryBackup) or

+      &vivaHelper::ErrorHandler("Cannot backup ALICE binary $binary: $!", __FILE__, __LINE__);

+

+   # Update start address

+   # Need 4 byte align

+   $$startAddressRef = &vivaHelper::RoundUpToAlignment($availableStartAddress, 4);

+

+   # Compress the binary directly

+   {

+      my $chip = &vivaHelper::GetMakefileOption("PLATFORM");

+      printLog("Compressing binary...");

+      if (0 != system("$compressTool -chip $chip -iBin $binaryBackup -oBin $binary -cBase $compressedStartAddress -dBase $decompressedStartAddress"))

+      {

+         &vivaHelper::ErrorHandler("Cannot compress ALICE binary $binary", __FILE__, __LINE__);

+      }

+   }

+

+   # Update binary size

+   $$startAddressRef = $compressedStartAddress;

+   $$sizeRef = -s $binary;

+

+   #debugLog("Base Address: $$startAddressRef");

+   #debugLog("Length: $$sizeRef");

+

+   return 1;

+}

+

+#****************************************************************************

+# subroutine:  GetInfo

+# description: Get the basic information of processing

+# input:       None

+# output:      Info ref

+#****************************************************************************

+sub GetInfo

+{

+   return \%info;

+}

+

+#****************************************************************************

+# subroutine:  GetRawDataStartAddress

+# description: Get the start address of ALICE raw data on the target

+# input:       VIVA binary path, Is SV5

+# output:      Base address

+#****************************************************************************

+sub GetRawDataStartAddress

+{

+   my $binaryPath = shift;

+   my $isSV5 = shift;

+   my %vivaInfo;

+   my $aliceBaseAddress;

+   &vivaHelper::ReadVIVAInfoFromBinary_NI($binaryPath, \%vivaInfo, $isSV5);

+

+   $aliceBaseAddress = $vivaInfo{"alice_base"};

+

+   # TODO: read the alice header to check the remapping bank

+   $aliceBaseAddress = ($aliceBaseAddress & 0x0FFFFFFF) | 0x90000000;

+

+   return $aliceBaseAddress;

+}

+

+sub printLog

+{

+   print "[ALICE] $_[0]\n";

+}

+

+sub debugLog

+{

+   if ($DEBUG)

+   {

+      printLog("[ALICE] $_[0]");

+   }

+}

+

+1;

+

+# 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