blob: 5fc259707cfe7ce85a031dfe4845745845664591 [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) 2018
#
# 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:
#* ---------
#* update_drdi_table.pl
#*
#* Project:
#* --------
#*
#*
#* Description:
#* ------------
#* This scripts is used to gen md5 checksum of all RATs DRDI, which will be used to check if data corruption
#* occurs during run-time or exception stage
#*
#* Author:
#* -------
#* Frank Hu (mtk12175)
#*
#****************************************************************************/
use strict;
use warnings;
package Region;
use constant Size => 0;
use constant VMA => 1;
use constant LMA => 2;
use constant Fileoffset => 3;
package Symbol;
use constant VMA => 0;
use constant Region => 1;
use constant Size => 2;
package MSG;
use constant Log => 0;
use constant Warning => 1;
use constant Fatal => 2;
my ($output, $warning) = (undef, undef);
&msg_handler(MSG::Fatal, "Wrong Parameters, Usage: update_drdi_table.pl <ELF_FILE> <SYM_FILE>", __LINE__)
if($#ARGV != 1);
my ($elf_file, $sym_file) = @ARGV;
my $templog = "Input: ELF is $elf_file\n SYM is $sym_file\n\n";
$templog .= sprintf("%-10s%-50s%-15s%-15s%-15s%-s\n", "Idx", "SectionName", "LMA", "VMA", "Size", "RCU_CS");
&msg_handler(MSG::Log, $templog, __LINE__);
my @rat_array = qw/2G 3GFDD 3GTDD MMRF C2K LTE NR/;
my @symbol_array = qw/DRDI_RCUCS_Array DRDI_VMA_Array/;
my %sym_file_hash;
map{ $sym_file_hash{'symbol_info'}->{$_} = 0 } (@symbol_array);
&parse_sym_file();
my @rcu_cs_array;
my @drdi_vma_info_array;
&drdi_gen_rcu_cs();
&drdi_update_elf();
exit 0;
sub parse_sym_file
{
my ($bBegin, $sum_hit_sym) = (undef, 0);
open SYM, "< $sym_file" or &msg_handler(MSG::Fatal, "fail to open $sym_file", __LINE__);
while(my $line = <SYM>) {
$bBegin = 1 if($line =~ /^Sections:$/);
$bBegin = 2 if($line =~ /^SYMBOL TABLE:$/);
next unless(defined $bBegin);
#Idx Name Size VMA LMA File off Algn
# 0 ROM_GFH 0000084c 00000000 00000000 00000fd4 2**2
if($bBegin == 1 and $line =~ /\s*(\d+)\s+(\S+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\S+)/) {
my $section_name = $2;
$sym_file_hash{'section_info'}->{$section_name} = [$3, $4, $5, $6];
}
#91437ed0 g O ROM 00000180 DRDI_RCUCS_Array
elsif($bBegin == 2 and $line =~ /^([0-9a-fA-F]{8})\s+g\s+O\s+(\S+)\s+(\S+)\s+(?:\S+\s+)?(\S+)$/) {
my $symbol_name = $4;
next unless(exists $sym_file_hash{'symbol_info'}->{$symbol_name});
$sym_file_hash{'symbol_info'}->{$symbol_name} = [$1, $2, $3];
last if(($sum_hit_sym ++) == $#symbol_array);
}
}
close SYM;
}
sub drdi_gen_rcu_cs
{
open (ELF_FILE, "< $elf_file") or die "Open $elf_file file failed\n";
binmode ELF_FILE;
my $idx = 0;
foreach my $rat (@rat_array) {
foreach my $index (0 .. 63) {
my $section_name = 'CACHED_EXTSRAM_MCURO_HWRW_DRDI_' . $rat . '_' . sprintf("%02d", $index);
&msg_handler(MSG::Fatal, "can't find the section: $section_name", __LINE__)
unless(exists $sym_file_hash{'section_info'}->{$section_name});
my $offset = hex($sym_file_hash{'section_info'}->{$section_name}->[Region::Fileoffset]);
my $length = hex($sym_file_hash{'section_info'}->{$section_name}->[Region::Size]);
&msg_handler(MSG::Fatal, "$section_name is not 4 Byte alignment(Length is $length)", __LINE__)
if($length % 4);
seek ELF_FILE, $offset, 0;
my ($content, $temp_rcu_cs) = (undef, 0);
&msg_handler(MSG::Fatal, "fail to read the data fragment of $section_name", __LINE__)
if(read(ELF_FILE, $content, $length) != $length);
my @tmp = unpack("V*", $content);
map { $temp_rcu_cs = $temp_rcu_cs ^ $_ } (@tmp);
push @rcu_cs_array, $temp_rcu_cs;
push @drdi_vma_info_array, hex($sym_file_hash{'section_info'}->{$section_name}->[Region::VMA]), $length;
$templog = sprintf("%-10s%-50s%-15s%-15s%-15s%-08x", $idx, $section_name,
$sym_file_hash{'section_info'}->{$section_name}->[Region::LMA],
$sym_file_hash{'section_info'}->{$section_name}->[Region::VMA],
$sym_file_hash{'section_info'}->{$section_name}->[Region::Size], $temp_rcu_cs);
&msg_handler(MSG::Log, $templog, __LINE__);
$idx = $idx + 1;
}
}
close ELF_FILE;
}
sub drdi_update_elf
{
open (ELF_FILE, "+< $elf_file") or die "Open $elf_file file failed\n";
binmode ELF_FILE;
foreach my $symbol (@symbol_array) {
if($sym_file_hash{'symbol_info'}->{$symbol} == 0) {
&msg_handler(MSG::Fatal, "can't find symbol: $symbol", __LINE__);
next;
}
my $sym_region = $sym_file_hash{'symbol_info'}->{$symbol}->[Symbol::Region];
my $offset = (hex($sym_file_hash{'symbol_info'}->{$symbol}->[Symbol::VMA]) - hex($sym_file_hash{'section_info'}->{$sym_region}->[Region::VMA])) +
hex($sym_file_hash{'section_info'}->{$sym_region}->[Region::Fileoffset]);
seek ELF_FILE, $offset, 0;
my ($sym_size, $data_frag, $updated_content_size) = (hex($sym_file_hash{'symbol_info'}->{$symbol}->[Symbol::Size]), undef, undef);
if($symbol eq 'DRDI_RCUCS_Array') {
$updated_content_size = ($#rcu_cs_array + 1) * 4;
$data_frag = pack('V*',@rcu_cs_array);
}
elsif($symbol eq 'DRDI_VMA_Array') {
$updated_content_size = ($#drdi_vma_info_array + 1) * 4;
$data_frag = pack('V*',@drdi_vma_info_array);
}
&msg_handler(MSG::Fatal, $templog, __LINE__)
if($sym_size != $updated_content_size);
print ELF_FILE $data_frag;
}
close ELF_FILE;
&msg_handler(MSG::Log, "\n\nUpdate Elf succeed ^O^", __LINE__);
}
sub msg_handler
{
my ($type, $msg, $line_no) = (@_);
my $prompt_prefix;
if($type == MSG::Log) {
print $msg . "\n";
}
elsif($type == MSG::Warning) {
$prompt_prefix = ">> DRDI Warning : ";
print "\n" . $prompt_prefix . "[at line $line_no] " . $msg . "\n";
}
elsif($type == MSG::Fatal) {
$prompt_prefix = ">> *** DRDI Fatal : ";
die $prompt_prefix . "[at line $line_no] " . "$msg" . "\n";
}
}