[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/tools/AutoGen/postBuild/Parsing_Padding_Info.pm b/mcu/tools/AutoGen/postBuild/Parsing_Padding_Info.pm
new file mode 100644
index 0000000..df58ff1
--- /dev/null
+++ b/mcu/tools/AutoGen/postBuild/Parsing_Padding_Info.pm
@@ -0,0 +1,204 @@
+#!/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:
+#* ---------
+#*   Parsing_Padding_Info.pm
+#*
+#* Project:
+#* --------
+#*
+#*
+#* Description:
+#* ------------
+#*   This script is used to get unused memory info.
+#* 
+#*
+#* Author:
+#* -------
+#*   Yao Liu (mtk15073)
+#*
+#*------------------------------------------------------------------------------
+#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+#*============================================================================
+#****************************************************************************/
+use strict;
+
+BEGIN { push @INC, './tools/MemoryUtility/' }  # add additional library path
+use BasicMemInfoQuery;
+use LinkerOutputParser;
+
+package Parsing_Padding_Info;
+use constant LOG        => 0;
+use constant WARNING    => 1;
+use constant FATAL      => 2;
+
+sub get_padding_info
+{
+    my ($platform, $c2k_mode_support, $themf, $scat, $map_file, $sym_file) = @_;
+    
+    my ($nRAMUsage, @raminfo);
+    if ($platform eq "MT6297" || $platform eq "MT6885" || $platform eq "MT6873" || $platform eq "MT6893" || $platform eq "MT6853") {
+        ($nRAMUsage, @raminfo) = &BasicMemInfo::DispatchCommand("CMD_GetRAMUsage", $themf, $scat, $map_file, $sym_file, undef);
+        return @raminfo;
+    } else {
+        &LinkerOutputParser::FileParse($sym_file);
+        my $ERinRAM_aref = &BasicMemInfo::GetERsInRAM($themf, $scat, $map_file, $sym_file, undef);
+
+        my $nDummyEndBase = hex(&LinkerOutputParser::Get_DUMMY_END_Base());
+        my $ROM_size = &BasicMemInfo::CMD_GetROMSize($themf, $scat, $map_file, $sym_file);
+        my @FreeRAMAreas;
+        my @UsedRAMAreas;
+        
+        foreach my $ER (@$ERinRAM_aref) #Go through all regions in ram
+        {
+            my $strERsize = LinkerOutputParser::GetExeRegionInfo($ER, Region::Size);
+            my $strERbase = &LinkerOutputParser::GetExeRegionInfo($ER, Region::VMA);
+            my $nERaddr = get_EMI_offset(hex($strERbase), $ER, $platform, $c2k_mode_support);
+            msg_handler(FATAL, "Section $ER base address($strERbase) or end address($strERbase + $strERsize) is bigger than total memory size!\nEMI offset is $nERaddr.\n")
+            if ($nERaddr > $nDummyEndBase || ($nERaddr + hex($strERsize)) > $nDummyEndBase);
+
+            if (hex($strERsize)) {
+                my $ERsize = hex($strERsize);
+                my $append = 0;
+                my $note = undef;
+ 
+                foreach my $used (@UsedRAMAreas) {
+                    if(($used->[0]<=$nERaddr) and (($used->[0]+$used->[1])>=$nERaddr)) {
+                        if (($used->[0]+$used->[1])<($nERaddr+$ERsize)){
+                        $used->[1]= ($nERaddr+$ERsize)-$used->[0];
+                        }
+                        $append = 1;
+                    } elsif (($used->[0]<=($nERaddr+$ERsize)) and (($used->[0]+$used->[1])>=($nERaddr+$ERsize))) {
+                        if ($used->[0] > $nERaddr) {
+                            $used->[1] += $used->[0] - $nERaddr;
+                            $used->[0] = $nERaddr;
+                        }
+                        $append = 1;
+                    }
+                    if ($append == 1) {
+                        $used->[2] = $note if($note ne undef);
+                       }
+                }
+
+                if ($append == 1) {
+                    $append = 0;
+                } else {
+                    push @UsedRAMAreas, [$nERaddr, $ERsize, $note]
+                }
+            }
+        }
+
+        @UsedRAMAreas = sort {$a->[0]<=>$b->[0]} @UsedRAMAreas;
+
+        if($ROM_size < $UsedRAMAreas[0][0]) {
+            push @FreeRAMAreas, [$ROM_size,$UsedRAMAreas[0][0] - $ROM_size];
+        }
+        for( my $i = 0;$i < $#UsedRAMAreas;$i+=1)
+        {
+            my $freeStart =$UsedRAMAreas[$i][0]+$UsedRAMAreas[$i][1];
+            my $freeSize  =$UsedRAMAreas[$i+1][0]-$freeStart;
+            push @FreeRAMAreas, [$freeStart,$freeSize]	 if ($freeSize > 0);
+        }
+
+        @FreeRAMAreas =sort {$b->[1] <=> $a->[1]} @FreeRAMAreas;
+        my @RAMMargins;
+        foreach my $refUsed (@FreeRAMAreas) {
+            my $MarginStart = ($refUsed->[0]+ 0xffff) & 0xffff0000;
+            my $MarginLength = (($refUsed->[0] + $refUsed->[1]) & 0xffff0000) - $MarginStart;
+            next if($MarginLength < 0x10000);
+
+            push @RAMMargins, [$MarginStart,$MarginLength];
+        }
+
+        for (my $item_count = $#RAMMargins+1; $item_count < 8; $item_count+=1) {
+            push @RAMMargins, [0,0];
+        }
+        @RAMMargins = sort {$b->[1] <=> $a->[1]} @RAMMargins;
+        splice @RAMMargins, 8;
+    
+        return @RAMMargins;
+    }  
+}
+
+
+sub get_EMI_offset()
+{
+    my ($address, $section_name, $platform, $c2k_support) = @_;
+    my $addr_mask = 0x0fffffff;
+    my $bank = $address>>28;
+    if (($bank == 1) || ($bank == 7)) 
+    {
+        $addr_mask = 0x1fffffff;
+    }
+    my $phsical_addr = $address & $addr_mask;
+    if ($section_name eq "EXTSRAM_L1DSP_ZI" and ($platform eq "MT6880" or $platform eq "MT6890" or $platform eq "MT2735")) {
+        if ($c2k_support eq "NONE"){
+            $phsical_addr -= 0xE000000;
+        } elsif ($c2k_support ne "NONE") {
+            $phsical_addr -= 0xA000000;
+        } else {
+            msg_handler(FATAL, "Please check the C2K_SUPPORT status($c2k_support).\n");
+        }
+    }
+
+    return $phsical_addr;
+}
+
+sub msg_handler
+{
+    my ($type, $msg, $line_no, $file_name) = (@_);
+    my $prompt_prefix;
+    if($type == LOG) {
+        print $msg . "\n";
+    }
+    elsif($type == WARNING) {
+        $prompt_prefix = ">> AAIS Warning : ";
+        my $location = (defined $file_name) ? "[$file_name] " : "";
+        print $prompt_prefix . $location . $msg . "\n";
+    }
+    elsif($type == FATAL) {
+        $prompt_prefix = ">> *** AAIS Fatal : ";
+        my $location = (defined $file_name) ? "[$file_name] " : "";
+        $location .= "[at line $line_no] ";
+        die $prompt_prefix . $location . $msg . "\n";
+    }
+}
+
+
+
+1;
+