blob: 15ea4a4397175f994771c339bf16f39dd88cb14a [file] [log] [blame]
#!/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:
#* ---------
#* Append2.pl
#*
#* Project:
#* --------
#* Maui_Software
#*
#* Description:
#* ------------
#* This script can append some information to a file
#* 1. its file name
#* 2. input strings
#* 3. flash configuration information
#* This script also can query flash configuration stored in FlashConf.c
#*
#*------------------------------------------------------------------------------
#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
#*============================================================================
#****************************************************************************/
BEGIN { push @INC, './tools/MemoryUtility/' } # add additional library path
BEGIN { push @INC, './tools/DSP/' }
BEGIN { push @INC, './tools/', './tools/AutoGen/postBuild/' } # add additional library path
use File::stat;
use Math::BigInt;
use BasicMemInfoQuery;
use Parsing_DSP_array;
use EMI_MPUinfo;
use Parsing_ARM7_info;
use Parsing_VoLTE_Core_Info;
use Parsing_Ramdisk_Info;
use FreeRam_info;
use drdi_info;
use AMMS_POSinfo;
use CONSYS_info;
use NV_cache_shm_info;
use Parsing_Padding_Info;
use BAT_buffer_info;
#************************************************************
#endian example:
#************************************************************
#int x = 0x76543210;
#char *c = (char*) &x;
#
#big-endian format:
#------------------
#Byte address | 0x01 | 0x02 | 0x03 | 0x04 |
#Byte content | 0x76 | 0x54 | 0x32 | 0x10 |
#
#little-endian format:
#---------------------
#Byte address | 0x01 | 0x02 | 0x03 | 0x04 |
#Byte content | 0x10 | 0x32 | 0x54 | 0x76 |
#************************************************************
#write hex with big-endian
#input argument: file handler, hex_value, total_hex_num
#************************************************************
sub write_hex_with_big_endian
{
my($file_handler, $hex_value, $total_hex_num) = @_;
print $file_handler pack("H".$total_hex_num, $hex_value); # write hex digit, with big-endian order
}
#************************************************************
#convert string to hex, and write hex with big-endian
#input argument: file handler, string_value, total_char_num
#************************************************************
sub write_string_with_big_endian
{
my($file_handler, $string_value, $total_char_num) = @_;
print $file_handler "$string_value";
my $remain_hex_digit = 2*($total_char_num - length($string_value));# a char takes 2 hex digit to represent
&write_hex_with_big_endian($file_handler, "0", $remain_hex_digit);
}
#************************************************************
#convert number to hex, and write hex with little-endian
#input argument: file handler, number_value, total_int_num
#************************************************************
sub write_number_with_little_endian
{
my($file_handler, $number_value, $total_int_num) = @_;
print $file_handler pack("V".$total_int_num, $number_value);# write hex digit, with little-endian order
}
#************************************************************
#main program
#************************************************************
my ($FLASH_CFG, $file, $bin_name, $verno, $themf, $build_time_str, $tmpfolder, $scat, $sym_filename, $copro_sym_file, $infomake_log, $drdi_file) = @ARGV;
print "All input: @ARGV\n";
&error_handler("BIN_NAME: $bin_name should NOT exceed 127 bytes", __FILE__, __LINE__) if(length($bin_name) > 127);
&error_handler("VERNO: $verno should NOT exceed 63 bytes", __FILE__, __LINE__) if(length($verno) > 63);
$targetDir = $file;
if($file =~ /\.bin$/ && -d "$file")
{
$file = $file."/ROM";
}
&error_handler("$file does not exist!", __FILE__, __LINE__) if(!-e "$file");
$targetDir =~ s/\\/\//g;
if($targetDir =~ /(.+)\/(.+)/)
{
$targetDir = $1;
}
$sym_file = $targetDir."/".$sym_filename;
$map_file = $sym_file;
#****************************************************************************
# parsing makefile
#****************************************************************************
my %prj_fo_hash;
open (FILE_HANDLE, "<$themf") or &error_handler("cannot open $themf!", __FILE__, __LINE__);
while (<FILE_HANDLE>) {
if ((/^([^\#]*)\#?.*/) && ($1 =~ /^(\w+)\s*=\s*(.*\S)\s*$/)) {
$keyname = lc($1);
$${keyname} = uc($2);
$prj_fo_hash{$keyname} = $${keyname};
}
}
$map_file =~ s/\.sym/\.map/;
&error_handler("$map_file does not exist!", __FILE__, __LINE__) if(!-e "$map_file");
&error_handler("$sym_file does not exist!", __FILE__, __LINE__) if(!-e "$sym_file");
#****************************************************************************
# parsing flash configuration from a file or a string
#****************************************************************************
my $full_hex_str = '';
my $full_emi_str;
open (FLASH_CFG, "<$FLASH_CFG") or &error_handler("cannot open $FLASH_CFG!", __FILE__, __LINE__);
$backup = $/;
undef $/;
$reading = <FLASH_CFG>;
$/ = $backup;
close FLASH_CFG;
my $flash_name = ''; # part number
my @NORFlashID = (0, 0, 0, 0); # flash ID (manufacture ID, device ID, ext. device ID1, ext. device ID2)
my @NANDFlashID = (0, 0, 0, 0); # flash ID (manufacture ID, device ID, ext. device ID1, ext. device ID2)
my @EMMCFlashID = (0, 0, 0, 0); # flash ID (manufacture ID, device ID, ext. device ID1, ext. device ID2)
my $fs_nor_addr = 0;
my $fs_nor_len = 0;
my $fs_nand_addr = 0;
my $fs_nand_len = 0;
my $fs_emmc_addr = 0;
my $fs_emmc_len = 0;
my $hex_str = '';
# get flash name(part number)
if ($reading =~ /const\s+kal_char\s+PART_NUMBER\w+\[\d*\]\s*=\s*\"(.*)\"\s*;/)
{
$flash_name = $1;
if ($bin_name !~ /\_FLN/)
{ # there will be one more part number(NOR Flash with two and NAND with ONLY one)
# specified in custom memory device configuration file
$bin_name .= "_FLN" . $flash_name;
&error_handler("PLATFORM ID: \"$bin_name\" should NOT exceed 127 bytes!", __FILE__, __LINE__) if(length($bin_name) > 127);
}
}
# get flash ID
my @flashID = (0, 0, 0, 0);
if ($reading =~ /const\s+kal_char\s+FLASH_ID\[\d*\]\s*=\s*\"\s*(?:\{\s*)?(\w+)\s*\,\s*(\w+)\s*(\,\s*(\w+))?\s*(\,\s*(\w+))?\s*(\,\s*(\w+))*\s*(?:\}\s*)?\"\s*;/)
{ # Flash ID has four fields, manufacture ID, device ID, ext. device ID1 & ext. device ID2
$flashID[0] = `perl -e "print ($1)" 2>&1` if ($1 ne "");
$flashID[1] = `perl -e "print ($2)" 2>&1` if ($2 ne "");
$flashID[2] = `perl -e "print ($4)" 2>&1` if ($4 ne "");
$flashID[3] = `perl -e "print ($6)" 2>&1` if ($6 ne "");
}
if ($nand_flash_booting !~ /^NONE|FALSE$/)
{
@NANDFlashID = @flashID;
}
elsif ($emmc_booting !~ /^NONE|FALSE$/)
{
@EMMCFlashID = @flashID;
}
else
{
@NORFlashID = @flashID;
}
# get nor flash base address if device exists
if ($reading =~ /int\s+fs_nor_base_address\s*=\s*(.*);/)
{
$fs_nor_addr = `perl -e "print ($1)" 2>&1`;
}
# get nor flash FAT space if device exists
if ($reading =~ /int\s+fs_nor_length\s*=\s*(.*);/)
{
$fs_nor_len = `perl -e "print ($1)" 2>&1`;
}
# get nand flash base address if device exists
if ($reading =~ /int\s+fs_nand_base_address\s*=\s*(.*);/)
{
$fs_nand_addr = `perl -e "print ($1)" 2>&1`;
}
# get nand flash FAT space if device exists
if ($reading =~ /int\s+fs_nand_length\s*=\s*(.*);/)
{
$fs_nand_len = `perl -e "print ($1)" 2>&1`;
}
# get emmc flash base address if device exists
if ($reading =~ /int\s+fs_emmc_base_address\s*=\s*(.*);/)
{
$fs_emmc_addr = `perl -e "print ($1)" 2>&1`;
}
# get emmc flash FAT space if device exists
if ($reading =~ /int\s+fs_emmc_length\s*=\s*(.*);/)
{
$fs_emmc_len = `perl -e "print ($1)" 2>&1`;
}
$hex_str = sprintf("%02X", 3); # flash device num.
$full_hex_str .= $hex_str;
# 1st flash device info. --- NOR flash
$hex_str = sprintf("%04X%04X%04X%04X%08X%08X", $NORFlashID[0], $NORFlashID[1], $NORFlashID[2], $NORFlashID[3], $fs_nor_addr, $fs_nor_len);
$full_hex_str .= $hex_str;
# 2nd flash device info. --- NAND flash
$hex_str = sprintf("%04X%04X%04X%04X%08X%08X", $NANDFlashID[0], $NANDFlashID[1], $NANDFlashID[2], $NANDFlashID[3], $fs_nand_addr, $fs_nand_len);
$full_hex_str .= $hex_str;
# 3rd flash device info. --- eMMC flash
$hex_str = sprintf("%04X%04X%04X%04X%08X%08X", $EMMCFlashID[0], $EMMCFlashID[1], $EMMCFlashID[2], $EMMCFlashID[3], $fs_emmc_addr, $fs_emmc_len);
$full_hex_str .= $hex_str;
$flash_len = length($full_hex_str);
if ( ($flash_len == 2) || ((($flash_len-34)%32) !=0) || ($flash_len > 34+5*32) )
{
&error_handler("The length of $full_hex_str ($flash_len) should be 34+32n. (5>=n>=0)", __FILE__, __LINE__);
}
$flash_device_count = hex(substr($full_hex_str, 0, 2));
if ((($flash_len-2)/32) != $flash_device_count)
{
&error_handler("$flash_len-2)/32 should be $flash_device_count", __FILE__, __LINE__);
}
open (CFG,">$tmpfolder/~gfh_cfg_flash.tmp") or &error_handler("cannot open $tmpfolder/~gfh_cfg_flash.tmp", __FILE__, __LINE__);
print CFG "FLASH_DEV_CNT=$flash_device_count\n";
for ($i=0; $i<$flash_device_count; $i++)
{
$menuID = hex(substr($full_hex_str, 2+32*$i, 4));
$devID = hex(substr($full_hex_str, 6+32*$i, 4));
$extID1 = hex(substr($full_hex_str, 10+32*$i, 4));
$extID2 = hex(substr($full_hex_str, 14+32*$i, 4));
$fatAddr = hex(substr($full_hex_str, 18+32*$i, 8));
$fatLen = hex(substr($full_hex_str, 26+32*$i, 8));
$regbase2 .= sprintf("0x%04X", $devID);
$regbase2 .= sprintf("%04X" , $menuID).",";
$regbase2 .= sprintf("0x%04X", $extID2);
$regbase2 .= sprintf("%04X" , $extID1).",";
$regbase2 .= sprintf("0x%08X", $fatAddr).",";
$regbase2 .= sprintf("0x%08X", $fatLen).",";
}
print CFG "FLASH_CFG_STR =".$regbase2."\n";
close CFG;
#************************************************************
#Get original binary size(before appending info in tail)
#************************************************************
my $img_rom_size = stat("$file")->size;
if(defined($amms_drdi_support) && $amms_drdi_support eq "TRUE")
{
$img_rom_size += stat("$drdi_file")->size;
}
#************************************************************
#Fill in PROJECT_NAME and PROJECT_FLAVOR to bin file
#************************************************************
open (FILE, "+<$file") or &error_handler("cannot open $file!", __FILE__, __LINE__);
#binmode(FILE); #seems no use?
# seek(FILE, x, y);
# move file cursor, y=>0: to new position x, y=>1: to current position + x, y=>2: to file tail + x
seek(FILE, 0, 2);
print "original_project_name = $original_project_name\n";
&write_string_with_big_endian(FILE, $original_project_name, 128);
print "original_flavor = $original_flavor\n";
&write_string_with_big_endian(FILE, $original_flavor, 36);
if(defined $original_verno)
{
print "original_verno = $original_verno\n";
&write_string_with_big_endian(FILE, $original_verno, 64);
}
else
{
print "verno = $verno\n";
&write_string_with_big_endian(FILE, $verno, 64);
}
close FILE;
#************************************************************
#Start to write infomation to BIN file for MODEM
#************************************************************
my $check_header = "CHECK_HEADER";
my $header_verno = "06";
#Debug/Release mode check
#0x01: debug mode
#0x02: release mode
my $product_ver = "";
if($production_release eq "FALSE")
{
$product_ver = "01";
}
elsif($production_release eq "TRUE")
{
$product_ver = "02";
}
else
{
$product_ver = "00";
}
my $image_type = "";
#modem CHECK
#0x01: 2G
#0x02: 3G
#0x03: WG
#0x04: TG
#0x05: LWG same as ulwg
#0x06: LTG same as ultg
#0x07: sglte only in MOLY
#0x08: ultg
#0x09: ulwg
#0x0A: ulwtg
#0x0B: ulwcg
#0x0C: ulwctg
#0x0D: unlwtg
#0x0E: unlwctg
if($fiveg_mode_support eq "FIVEG_MODE" && $eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_FDD_TDD_SUPPORT" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (defined $c2k_mode_support && $c2k_mode_support ne "NONE"))
{
$image_type = "0E";
}
elsif($fiveg_mode_support eq "FIVEG_MODE" && $eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_FDD_TDD_SUPPORT" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (!defined $c2k_mode_support || $c2k_mode_support eq "NONE"))
{
$image_type = "0D";
}
elsif($eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_FDD_TDD_SUPPORT" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (defined $c2k_mode_support && $c2k_mode_support ne "NONE"))
{
$image_type = "0C";
}
elsif($eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_FDD_MODE" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (defined $c2k_mode_support && $c2k_mode_support ne "NONE"))
{
$image_type = "0B";
}
elsif($eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_FDD_TDD_SUPPORT" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (!defined $c2k_mode_support || $c2k_mode_support eq "NONE"))
{
$image_type = "0A";
}
elsif($eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_FDD_MODE" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (!defined $c2k_mode_support || $c2k_mode_support eq "NONE"))
{
$image_type = "09";
}
elsif($eutran_mode_support eq "EUTRAN_MODE" && $utran_mode_support eq "UTRAN_TDD128_MODE" && $geran_mode_support eq "GERAN_EGPRS_MODE" && (!defined $c2k_mode_support || $c2k_mode_support eq "NONE"))
{
$image_type = "08";
}
elsif($utran_mode_support eq "UTRAN_TDD128_MODE" && $eutran_mode_support eq "NONE")
{
$image_type = "04";
}
elsif($utran_mode_support eq "UTRAN_FDD_MODE" && $eutran_mode_support eq "NONE")
{
$image_type = "03";
}
elsif($geran_mode_support eq "GERAN_GSM_MODE" || ($geran_mode_support eq "GERAN_EGPRS_MODE" && $utran_mode_support eq "NONE"))
{
$image_type = "01";
}
else
{
$image_type = "00";
}
my $mcu_platform = $platform."_".$chip_ver;
#append project_name and flavor to build time, and limit it's length to at most 64 bytes
my $build_time = $build_time_str."*".$original_project_name."*".$original_flavor;
if (length($build_time) > 64)
{
$build_time = substr($build_time, 0, 64);
}
my $build_ver = $verno;
my $bind_sys_id = "";
# 01: default value
# 02: MD2
# 03: reserved
# 04: reserved
# 05: MD5
if(defined $mdsys && $mdsys eq "MD5")
{
$bind_sys_id = "05";
}
elsif(defined $mdsys && $mdsys eq "MD2")
{
$bind_sys_id = "02";
}
else
{
$bind_sys_id = "01";
}
my $ext_attr = "00"; # 00:no shrink, 01:shrink
my $reserved = "\0"; # string \0 => 00 in hex digit
print "Get Total RAM Usage from LDS: $themf $scat $map_file $sym_file\n";
my $mem_size = &BasicMemInfo::DispatchCommand("GetTotalRAMUsageFromLDS", $themf, $scat, $map_file, $sym_file, undef);
my $md_img_size = $img_rom_size;
my $rpc_sec_mem_addr = "00";
my $dspFlagSymbol = "dsp_bin_ro";
my $dspSymbol = "dsp_bin_ro";
print "Get DSP load address: $sym_file $platform $c2k_mode_support $infomake_log\n";
my ($dsp_img_offset, $dsp_img_size) = Parsing_DSP_array::getDSPsymbol($sym_file, $platform, $c2k_mode_support, $infomake_log, $fs_ramdisk);
print "Get EMI MPU info:$sym_file\n";
my ($region_num, $aMPU_ref, $aDomain_ref) = &EMI_MPUinfo::retrieveEMI_MPU_info($sym_file, $themf);
my @region_offset;
my @region_size;
foreach my $regionAry_ref (@{$aMPU_ref})
{
push @region_offset, $regionAry_ref->[0];
push @region_size, $regionAry_ref->[1];
}
my @domain_attr;
foreach my $attr (@{$aDomain_ref})
{
push @domain_attr, $attr;
}
print "Get volte address: $sym_file $infomake_log\n";
my ($arm7_img_offset, $arm7_img_size) = Parsing_VoLTE_Core_Info::getVoLTECoresymbol($sym_file, $infomake_log);
print "Get FreeRam info: $sym_file\n";
my @raminfo = &Parsing_Padding_Info::get_padding_info($platform, $c2k_mode_support, $themf, $scat, $map_file, $sym_file);
my @free_padding_block_start_offset;
my @free_padding_block_length;
foreach $free_padding_block_ref (@raminfo)
{
push @free_padding_block_start_offset, $free_padding_block_ref->[0];
push @free_padding_block_length, $free_padding_block_ref->[1];
}
my $ap_md_smem_size = 0;
my $md_to_md_smem_size = 0;
print "Get Ramdisk info: $sym_file $infomake_log\n";
my ($ramdisk_offset, $ramdisk_size) = Parsing_Ramdisk_Info::getRamdisksymbol($sym_file, $infomake_log);
print "Get DRDI info: $sym_file\n";
my ($drdi_offset, $drdi_size, $drdi_rt_offset ,$drdi_rt_size) = drdi_info::GetDRDIInfo($sym_file);
my $reserved_1 = "\0";
my $size = 512;
$amms_pos_support = "FALSE" if($amms_pos_support ne "TRUE");
print "Get AMMS POS info: $amms_pos_support\n";
print "Get MTK_MODEM_ARCH: $mtk_modem_arch\n";
my $pos_size = AMMS_POSinfo::retrieveAMMS_POS_Support($amms_pos_support,$mtk_modem_arch);
$mcif_support = "FALSE" if($mcif_support ne "TRUE");
$mcif_wifi_support = "FALSE" if($mcif_wifi_support ne "TRUE");
print "Get MTK_MODEM_ARCH: $mtk_modem_arch\n";
my $consys_size = CONSYS_info::retrieveCONSYS_Support(\%prj_fo_hash, "$mtk_modem_arch");
my $nv_cache_shm_size = NV_cache_shm_info::retrieveNV_CACHE_Support(\%prj_fo_hash);
$r15_deflate_udc_support = "FALSE" if($r15_deflate_udc_support ne "TRUE");
print "Get R15_DEFLATE_UDC_SUPPORT info: $r15_deflate_udc_support\n";
my $udc_support = 0;
$udc_support = 1 if($r15_deflate_udc_support eq "TRUE");
my $bat_buffer_info_ver = BAT_buffer_info::retrieveBAT_Buffer_Info(\%prj_fo_hash);
print "\n\ncheck_header: $check_header\n";
print "header_verno: $header_verno\n";
print "product_ver: $product_ver\n";
print "image_type: $image_type\n";
print "mcu_platform: $mcu_platform\n";
print "build_time: $build_time\n";
print "build_ver: $build_ver\n";
print "bind_sys_id: $bind_sys_id\n";
print "ext_attr: $ext_attr\n";
print "reserved: $reserved\n";
print "mem_size: $mem_size\n";
print "md_img_size: $md_img_size (amms_drdi_support = $amms_drdi_support)\n";
print "rpc_sec_mem_addr: $rpc_sec_mem_addr\n";
print "dsp_img_offset: $dsp_img_offset\n";
print "dsp_img_size: $dsp_img_size\n";
print "region_num: $region_num\n";
for my $i (0 .. $#region_offset)
{
print "region_offset_$i: $region_offset[$i]\n";
print "region_size_$i: $region_size[$i]\n";
}
for my $i (0 .. $#domain_attr)
{
print "domain_attr_$i: $domain_attr[$i]\n";
}
print "arm7_img_offset (volte address): $arm7_img_offset\n";
print "arm7_img_size (volte size): $arm7_img_size\n";
for my $i (0 .. $#free_padding_block_start_offset)
{
print "free_padding_block_start_offset_$i: $free_padding_block_start_offset[$i]\n";
print "free_padding_block_length_$i: $free_padding_block_length[$i]\n";
}
print "ap_md_smem_size: $ap_md_smem_size\n";
print "md_to_md_smem_size: $md_to_md_smem_size\n";
print "ramdisk_offset: $ramdisk_offset\n";
print "ramdisk_size: $ramdisk_size\n";
print "drdi_offset: $drdi_offset\n";
print "drdi_size: $drdi_size\n";
print "drdi_rt_offset: $drdi_rt_offset\n";
print "drdi_rt_size: $drdi_rt_size\n";
print "pos_size: $pos_size\n";
print "consys_size: $consys_size\n";
print "udc_support: $udc_support (r15_deflate_udc_support = $r15_deflate_udc_support)\n";
print "nv_cache_shm_size: $nv_cache_shm_size\n";
print "bat_buffer_info_ver: $bat_buffer_info_ver\n";
print "reserved_1: $reserved_1\n";
print "size: $size\n\n";
# open in read/write mode with the file cursor at the beginning of the file, it won't create file if file not exist
open (FILE, "+<$file") or &error_handler("cannot open $file!", __FILE__, __LINE__);
#binmode(FILE); #seems no use?
# seek(FILE, x, y);
# move file cursor, y=>0: to new position x, y=>1: to current position + x, y=>2: to file tail + x
seek(FILE, 0, 2);
&write_string_with_big_endian(FILE, $check_header, 12);
&write_hex_with_big_endian(FILE, $header_verno, 8);
&write_hex_with_big_endian(FILE, $product_ver, 8);
&write_hex_with_big_endian(FILE, $image_type, 8);
&write_string_with_big_endian(FILE, $mcu_platform, 16);
&write_string_with_big_endian(FILE, $build_time, 64);
&write_string_with_big_endian(FILE, $build_ver, 64);
&write_hex_with_big_endian(FILE, $bind_sys_id, 2);
&write_hex_with_big_endian(FILE, $ext_attr, 2);
&write_string_with_big_endian(FILE, $reserved, 2);
&write_number_with_little_endian(FILE, $mem_size, 1);
&write_number_with_little_endian(FILE, $md_img_size, 1);
&write_hex_with_big_endian(FILE, $rpc_sec_mem_addr, 8);
&write_number_with_little_endian(FILE, $dsp_img_offset, 1);
&write_number_with_little_endian(FILE, $dsp_img_size, 1);
&write_number_with_little_endian(FILE, $region_num, 1);
for my $i (0 .. $#region_offset)
{
&write_number_with_little_endian(FILE, $region_offset[$i], 1);
&write_number_with_little_endian(FILE, $region_size[$i], 1);
}
for my $i (0 .. $#domain_attr)
{
&write_number_with_little_endian(FILE, $domain_attr[$i], 1);
}
&write_number_with_little_endian(FILE, $arm7_img_offset, 1);
&write_number_with_little_endian(FILE, $arm7_img_size, 1);
for my $i (0 .. $#free_padding_block_start_offset)
{
&write_number_with_little_endian(FILE, $free_padding_block_start_offset[$i], 1);
&write_number_with_little_endian(FILE, $free_padding_block_length[$i], 1);
}
&write_number_with_little_endian(FILE, $ap_md_smem_size, 1);
&write_number_with_little_endian(FILE, $md_to_md_smem_size, 1);
&write_number_with_little_endian(FILE, $ramdisk_offset, 1);
&write_number_with_little_endian(FILE, $ramdisk_size, 1);
&write_number_with_little_endian(FILE, $drdi_offset, 1);
&write_number_with_little_endian(FILE, $drdi_size, 1);
&write_number_with_little_endian(FILE, $drdi_rt_offset, 1);
&write_number_with_little_endian(FILE, $drdi_rt_size, 1);
&write_number_with_little_endian(FILE, $pos_size, 1);
&write_number_with_little_endian(FILE, $consys_size, 1);
&write_number_with_little_endian(FILE, $udc_support, 1);
&write_string_with_big_endian(FILE, $reserved_1, 4);
&write_number_with_little_endian(FILE, $nv_cache_shm_size, 1);
&write_string_with_big_endian(FILE, $reserved_1, 4);
&write_number_with_little_endian(FILE, $bat_buffer_info_ver, 1);
&write_string_with_big_endian(FILE, $reserved_1, 100);
&write_number_with_little_endian(FILE, $size, 1);
close (FILE);
print "Done\n";
exit 0;
#*************************************************************************************************
# Error Handling Message
#*************************************************************************************************
sub error_handler {
my ($error_msg, $file, $line_no) = @_;
my $final_error_msg = "Error: $error_msg at $file line $line_no\n";
print "$final_error_msg";
die $final_error_msg;
}