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) 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 | #* Append2.pl
|
| 41 | #*
|
| 42 | #* Project:
|
| 43 | #* --------
|
| 44 | #* Maui_Software
|
| 45 | #*
|
| 46 | #* Description:
|
| 47 | #* ------------
|
| 48 | #* This script can append some information to a file
|
| 49 | #* 1. its file name
|
| 50 | #* 2. input strings
|
| 51 | #* 3. flash configuration information
|
| 52 | #* This script also can query flash configuration stored in FlashConf.c
|
| 53 | #*
|
| 54 | #*------------------------------------------------------------------------------
|
| 55 | #* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
|
| 56 | #*============================================================================
|
| 57 | #****************************************************************************/
|
| 58 | use File::stat;
|
| 59 | use Math::BigInt;
|
| 60 |
|
| 61 | my ($FLASH_CFG,$file,$bin_name,$verno,$themf,$build_time_str,$tmpfolder,$scat) = @ARGV;
|
| 62 | &error_handler("BIN_NAME: $bin_name should NOT exceed 127 bytes", __FILE__, __LINE__) if(length($bin_name) > 127);
|
| 63 | &error_handler("VERNO: $verno should NOT exceed 63 bytes", __FILE__, __LINE__) if(length($verno) > 63);
|
| 64 |
|
| 65 | if($file =~ /\.bin$/ && -d "$file")
|
| 66 | {
|
| 67 | $file = $file."/ROM";
|
| 68 | }
|
| 69 | &error_handler("$file does not exist!", __FILE__, __LINE__) if(!-e "$file");
|
| 70 | #****************************************************************************
|
| 71 | # parsing makefile
|
| 72 | #****************************************************************************
|
| 73 | open (FILE_HANDLE, "<$themf") or &error_handler("cannot open $themf!", __FILE__, __LINE__);
|
| 74 | while (<FILE_HANDLE>)
|
| 75 | {
|
| 76 | if ((/^([^\#]*)\#?.*/) && ($1 =~ /^(\w+)\s*=\s*(.*\S)\s*$/))
|
| 77 | {
|
| 78 | $keyname = lc($1);
|
| 79 | $${keyname} = uc($2);
|
| 80 | }
|
| 81 | }
|
| 82 |
|
| 83 | #****************************************************************************
|
| 84 | # parsing flash configuration from a file or a string
|
| 85 | #****************************************************************************
|
| 86 | my $full_hex_str = '';
|
| 87 | my $full_emi_str;
|
| 88 |
|
| 89 | open (FLASH_CFG, "<$FLASH_CFG") or &error_handler("cannot open $FLASH_CFG!", __FILE__, __LINE__);
|
| 90 | $backup = $/;
|
| 91 | undef $/;
|
| 92 | $reading = <FLASH_CFG>;
|
| 93 | $/ = $backup;
|
| 94 | close FLASH_CFG;
|
| 95 |
|
| 96 | my $flash_name = ''; # part number
|
| 97 | my @NORFlashID = (0, 0, 0, 0); # flash ID (manufacture ID, device ID, ext. device ID1, ext. device ID2)
|
| 98 | my @NANDFlashID = (0, 0, 0, 0); # flash ID (manufacture ID, device ID, ext. device ID1, ext. device ID2)
|
| 99 | my @EMMCFlashID = (0, 0, 0, 0); # flash ID (manufacture ID, device ID, ext. device ID1, ext. device ID2)
|
| 100 |
|
| 101 | my $fs_nor_addr = 0;
|
| 102 | my $fs_nor_len = 0;
|
| 103 | my $fs_nand_addr = 0;
|
| 104 | my $fs_nand_len = 0;
|
| 105 | my $fs_emmc_addr = 0;
|
| 106 | my $fs_emmc_len = 0;
|
| 107 | my $hex_str = '';
|
| 108 |
|
| 109 | # get flash name(part number)
|
| 110 | if ($reading =~ /const\s+kal_char\s+PART_NUMBER\w+\[\d*\]\s*=\s*\"(.*)\"\s*;/)
|
| 111 | {
|
| 112 | $flash_name = $1;
|
| 113 | if ($bin_name !~ /\_FLN/)
|
| 114 | { # there will be one more part number(NOR Flash with two and NAND with ONLY one)
|
| 115 | # specified in custom memory device configuration file
|
| 116 | $bin_name .= "_FLN" . $flash_name;
|
| 117 | &error_handler("PLATFORM ID: \"$bin_name\" should NOT exceed 127 bytes!", __FILE__, __LINE__) if(length($bin_name) > 127);
|
| 118 | }
|
| 119 | }
|
| 120 |
|
| 121 | # get flash ID
|
| 122 | my @flashID = (0, 0, 0, 0);
|
| 123 | 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*;/)
|
| 124 | { # Flash ID has four fields, manufacture ID, device ID, ext. device ID1 & ext. device ID2
|
| 125 | $flashID[0] = `perl -e "print ($1)" 2>&1` if ($1 ne "");
|
| 126 | $flashID[1] = `perl -e "print ($2)" 2>&1` if ($2 ne "");
|
| 127 | $flashID[2] = `perl -e "print ($4)" 2>&1` if ($4 ne "");
|
| 128 | $flashID[3] = `perl -e "print ($6)" 2>&1` if ($6 ne "");
|
| 129 | }
|
| 130 |
|
| 131 | if ($nand_flash_booting !~ /^NONE|FALSE$/)
|
| 132 | {
|
| 133 | @NANDFlashID = @flashID;
|
| 134 | }
|
| 135 | elsif ($emmc_booting !~ /^NONE|FALSE$/)
|
| 136 | {
|
| 137 | @EMMCFlashID = @flashID;
|
| 138 | }
|
| 139 | else
|
| 140 | {
|
| 141 | @NORFlashID = @flashID;
|
| 142 | }
|
| 143 |
|
| 144 | # get nor flash base address if device exists
|
| 145 | if ($reading =~ /int\s+fs_nor_base_address\s*=\s*(.*);/)
|
| 146 | {
|
| 147 | $fs_nor_addr = `perl -e "print ($1)" 2>&1`;
|
| 148 | }
|
| 149 |
|
| 150 | # get nor flash FAT space if device exists
|
| 151 | if ($reading =~ /int\s+fs_nor_length\s*=\s*(.*);/)
|
| 152 | {
|
| 153 | $fs_nor_len = `perl -e "print ($1)" 2>&1`;
|
| 154 | }
|
| 155 |
|
| 156 | # get nand flash base address if device exists
|
| 157 | if ($reading =~ /int\s+fs_nand_base_address\s*=\s*(.*);/)
|
| 158 | {
|
| 159 | $fs_nand_addr = `perl -e "print ($1)" 2>&1`;
|
| 160 | }
|
| 161 |
|
| 162 | # get nand flash FAT space if device exists
|
| 163 | if ($reading =~ /int\s+fs_nand_length\s*=\s*(.*);/)
|
| 164 | {
|
| 165 | $fs_nand_len = `perl -e "print ($1)" 2>&1`;
|
| 166 | }
|
| 167 |
|
| 168 | # get emmc flash base address if device exists
|
| 169 | if ($reading =~ /int\s+fs_emmc_base_address\s*=\s*(.*);/)
|
| 170 | {
|
| 171 | $fs_emmc_addr = `perl -e "print ($1)" 2>&1`;
|
| 172 | }
|
| 173 |
|
| 174 | # get emmc flash FAT space if device exists
|
| 175 | if ($reading =~ /int\s+fs_emmc_length\s*=\s*(.*);/)
|
| 176 | {
|
| 177 | $fs_emmc_len = `perl -e "print ($1)" 2>&1`;
|
| 178 | }
|
| 179 |
|
| 180 | $hex_str = sprintf("%02X", 3); # flash device num.
|
| 181 | $full_hex_str .= $hex_str;
|
| 182 |
|
| 183 | # 1st flash device info. --- NOR flash
|
| 184 | $hex_str = sprintf("%04X%04X%04X%04X%08X%08X", $NORFlashID[0], $NORFlashID[1], $NORFlashID[2], $NORFlashID[3], $fs_nor_addr, $fs_nor_len);
|
| 185 | $full_hex_str .= $hex_str;
|
| 186 |
|
| 187 | # 2nd flash device info. --- NAND flash
|
| 188 | $hex_str = sprintf("%04X%04X%04X%04X%08X%08X", $NANDFlashID[0], $NANDFlashID[1], $NANDFlashID[2], $NANDFlashID[3], $fs_nand_addr, $fs_nand_len);
|
| 189 | $full_hex_str .= $hex_str;
|
| 190 |
|
| 191 | # 3rd flash device info. --- eMMC flash
|
| 192 | $hex_str = sprintf("%04X%04X%04X%04X%08X%08X", $EMMCFlashID[0], $EMMCFlashID[1], $EMMCFlashID[2], $EMMCFlashID[3], $fs_emmc_addr, $fs_emmc_len);
|
| 193 | $full_hex_str .= $hex_str;
|
| 194 |
|
| 195 |
|
| 196 | $flash_len = length($full_hex_str);
|
| 197 | if ( ($flash_len == 2) || ((($flash_len-34)%32) !=0) || ($flash_len > 34+5*32) )
|
| 198 | {
|
| 199 | &error_handler("The length of $full_hex_str ($flash_len) should be 34+32n. (5>=n>=0)", __FILE__, __LINE__);
|
| 200 | }
|
| 201 | $flash_device_count = hex(substr($full_hex_str, 0, 2));
|
| 202 |
|
| 203 | if ((($flash_len-2)/32) != $flash_device_count)
|
| 204 | {
|
| 205 | &error_handler("$flash_len-2)/32 should be $flash_device_count", __FILE__, __LINE__);
|
| 206 | }
|
| 207 |
|
| 208 | open (CFG,">$tmpfolder/~gfh_cfg_flash.tmp") or &error_handler("cannot open $tmpfolder/~gfh_cfg_flash.tmp", __FILE__, __LINE__);
|
| 209 | print CFG "FLASH_DEV_CNT=$flash_device_count\n";
|
| 210 |
|
| 211 | for ($i=0; $i<$flash_device_count; $i++)
|
| 212 | {
|
| 213 | $menuID = hex(substr($full_hex_str, 2+32*$i, 4));
|
| 214 | $devID = hex(substr($full_hex_str, 6+32*$i, 4));
|
| 215 | $extID1 = hex(substr($full_hex_str, 10+32*$i, 4));
|
| 216 | $extID2 = hex(substr($full_hex_str, 14+32*$i, 4));
|
| 217 | $fatAddr = hex(substr($full_hex_str, 18+32*$i, 8));
|
| 218 | $fatLen = hex(substr($full_hex_str, 26+32*$i, 8));
|
| 219 |
|
| 220 | $regbase2 .= sprintf("0x%04X", $devID);
|
| 221 | $regbase2 .= sprintf("%04X" , $menuID).",";
|
| 222 | $regbase2 .= sprintf("0x%04X", $extID2);
|
| 223 | $regbase2 .= sprintf("%04X" , $extID1).",";
|
| 224 | $regbase2 .= sprintf("0x%08X", $fatAddr).",";
|
| 225 | $regbase2 .= sprintf("0x%08X", $fatLen).",";
|
| 226 | }
|
| 227 | print CFG "FLASH_CFG_STR =".$regbase2."\n";
|
| 228 | close CFG;
|
| 229 |
|
| 230 | print "Done\n";
|
| 231 | exit 0;
|
| 232 |
|
| 233 | #*************************************************************************************************
|
| 234 | # Error Handling Message
|
| 235 | #*************************************************************************************************
|
| 236 | sub error_handler
|
| 237 | {
|
| 238 | my ($error_msg, $file, $line_no) = @_;
|
| 239 | my $final_error_msg = "Error: $error_msg at $file line $line_no\n";
|
| 240 | print "$final_error_msg";
|
| 241 | die $final_error_msg;
|
| 242 | }
|