Initial import of NFC GNSS SDK project
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use Fcntl;
|
||||
use File::Basename;
|
||||
use File::Spec::Functions;
|
||||
|
||||
|
||||
$DEBUG=1;
|
||||
$INPUT_FILE=$ARGV[0];
|
||||
$CRC_TAIL_SIZE=4;
|
||||
|
||||
if ($^O eq 'MSWin32' || $^O eq 'msys' || $^O eq 'cygwin') {
|
||||
$EXE_SUFFIX = ".exe";
|
||||
} else {
|
||||
$EXE_SUFFIX = "_lnx";
|
||||
}
|
||||
|
||||
$TARGET_SIZE=((128+64+4)*1024-$CRC_TAIL_SIZE);
|
||||
|
||||
$CRC_TOOL_EXEC = catfile(dirname(__FILE__), "create_crc_res$EXE_SUFFIX");
|
||||
debug_msg("CRC_TOOL_EXEC=$CRC_TOOL_EXEC");
|
||||
|
||||
debug_msg("INPUT_FILE=$INPUT_FILE");
|
||||
sysopen(OUTBIN_REF,"$INPUT_FILE",O_BINARY|O_WRONLY|O_APPEND) or error_exit("Can't open [$INPUT_FILE] for further action; $!");
|
||||
|
||||
$INPUT_FILE_SIZE=-s "$INPUT_FILE";
|
||||
debug_msg("INPUT_FILE_SIZE=$INPUT_FILE_SIZE.byte");
|
||||
|
||||
if($INPUT_FILE_SIZE > $TARGET_SIZE){
|
||||
error_exit("INPUT_FILE_SIZE[$INPUT_FILE_SIZE] overflow TARGET_SIZE[$TARGET_SIZE]");
|
||||
}
|
||||
|
||||
#recorder and pring the append CRC code
|
||||
#
|
||||
$crc_exec_result=qx("$CRC_TOOL_EXEC" $INPUT_FILE);
|
||||
@split_result=split("\ +|\n|:",$crc_exec_result);
|
||||
debug_msg("APPEND_CRC_CODE=$split_result[19]");
|
||||
|
||||
#print out output file size
|
||||
#
|
||||
$OUTPUT_FILE_SIZE=-s "$INPUT_FILE";
|
||||
debug_msg("OUTPUT_FILE_SIZE=$OUTPUT_FILE_SIZE.byte");
|
||||
close OUTBIN_REF;
|
||||
|
||||
sub debug_msg{
|
||||
unless($DEBUG){return};
|
||||
local $DEBUG_MSG="DEBUG >>> :";
|
||||
print "$DEBUG_MSG @_";
|
||||
print "\n";
|
||||
}
|
||||
sub error_exit{
|
||||
local $ERROR_MSG="\nERROR:**";
|
||||
print "----------------------";
|
||||
print "$ERROR_MSG @_";
|
||||
print "\n";
|
||||
exit(1);
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
##[20210225][xiaokeweng@asrmicro.com]
|
||||
#
|
||||
# ----------------------------------
|
||||
# | Updater (with Ext info) |
|
||||
# |--------------------------------|
|
||||
# | dsp_adc.bin |
|
||||
# |--------------------------------|
|
||||
# | crc |
|
||||
# |--------------------------------|
|
||||
#
|
||||
# to append {dsp_adc.bin} to {updater.bin}
|
||||
# and ADC_SIZE into {Ext info}
|
||||
#
|
||||
# cmd should be :
|
||||
#
|
||||
# perl {this_script*.pl} APPEND UPD_SIZE updater.bin ADC_SIZE dsp_adc.bin
|
||||
#
|
||||
|
||||
|
||||
use Fcntl;
|
||||
#use Switch;
|
||||
|
||||
$DEBUG=1;
|
||||
$OPERATION_ARGV =glob $ARGV[0]; #{"APPEND"}
|
||||
$FRONT_IMG_FILENAME =glob $ARGV[1]; #front bin
|
||||
$FRONT_SIZE_STRING =glob $ARGV[2]; #front bin ext info string
|
||||
$APPEND_IMG_FILENAME =glob $ARGV[3]; #append bin
|
||||
$APPEND_SIZE_STRING =glob $ARGV[4]; #append bin ext info string
|
||||
|
||||
# NULL = 0x4c4c554e;
|
||||
$LT_INVALID_ADDRESS="NULL";
|
||||
$LOADTABLE_HEADER_LENGTH=0x1200;
|
||||
|
||||
$PART_1 = "pi_front";
|
||||
$PART_2 = "pi_tail";
|
||||
$PART_TMP = "pi_tmp";
|
||||
|
||||
debug_msg("ARGV[0]:$OPERATION_ARGV");
|
||||
debug_msg("ARGV[1]:$FRONT_IMG_FILENAME");
|
||||
debug_msg("ARGV[2]:$FRONT_SIZE_STRING");
|
||||
debug_msg("ARGV[3]:$APPEND_IMG_FILENAME");
|
||||
debug_msg("ARGV[4]:$APPEND_SIZE_STRING");
|
||||
print sprintf ("|%s\n","-------------------------------------------------------------------------------");
|
||||
|
||||
#
|
||||
#step-0 : input argv verification
|
||||
#
|
||||
debug_msg("STEP_0");
|
||||
sysopen(INPUT_STREAM,"$APPEND_IMG_FILENAME",O_BINARY|O_RDONLY)
|
||||
or error_exit("Can't open [$APPEND_IMG_FILENAME] for reading; $!");
|
||||
close INPUT_STREAM;
|
||||
sysopen(INPUT_STREAM,"$FRONT_IMG_FILENAME",O_BINARY|O_RDWR)
|
||||
or error_exit("Can't open [$FRONT_IMG_FILENAME] for reading; $!");
|
||||
|
||||
#
|
||||
#step-1 : count input {$FRONT_IMG_FILENAME} size to do further compare with val of item $("BIN_SIZE")
|
||||
#
|
||||
debug_msg("STEP_1");
|
||||
my $input_front_bin_size= -s $FRONT_IMG_FILENAME;
|
||||
if($DEBUG){print sprintf ("input_front_bin_size=[0x%.08x]\n", $input_front_bin_size)};
|
||||
|
||||
#
|
||||
#step-2 : detect item {"BIN_SIZE"} and verify if val available as [$lt_front_bin_size]
|
||||
#
|
||||
#load the first {$LOADTABLE_HEADER_LENGTH} binary to parse
|
||||
#
|
||||
#/csw/BSP/inc/loadTable.h
|
||||
# typedef struct{
|
||||
# char name[12];
|
||||
# UINT32 value;
|
||||
# }armlink_symbol_item;
|
||||
#
|
||||
debug_msg("STEP_2");
|
||||
sysread(INPUT_STREAM,$loadtable_header,$LOADTABLE_HEADER_LENGTH);
|
||||
|
||||
#index of "BIN_SIZE"
|
||||
$index=index($loadtable_header,$FRONT_SIZE_STRING);
|
||||
if ($index == -1){
|
||||
error_exit("NO [$FRONT_SIZE_STRING] detect, exit");
|
||||
}
|
||||
|
||||
#read val of "BIN_SIZE" and do compare check
|
||||
sysseek(INPUT_STREAM,$index+12,0);
|
||||
sysread(INPUT_STREAM,$lt_front_bin_size,4);
|
||||
$lt_front_bin_size=raw_to_hex($lt_front_bin_size);
|
||||
if($DEBUG){print sprintf ("lt_front_bin_size=[0x%.08x]\r\n",$lt_front_bin_size)};
|
||||
|
||||
if($OPERATION_ARGV =~ /APPEND/i){
|
||||
if ( $lt_front_bin_size != $input_front_bin_size){
|
||||
error_exit("item [$FRONT_SIZE_STRING] unmatch with [$FRONT_IMG_FILENAME] size, exit");
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
#step-3 : count input {$APPEND_IMG_FILENAME} size , going to fill in item {"APPEND_SIZE_STRING"}
|
||||
#
|
||||
debug_msg("STEP_3");
|
||||
$input_append_bin_size= -s $APPEND_IMG_FILENAME;
|
||||
if($DEBUG){print sprintf ("input_append_binary_size=[0x%.08x]\n", $input_append_bin_size)};
|
||||
|
||||
$index=index($loadtable_header,$APPEND_SIZE_STRING);
|
||||
if ($index == -1){
|
||||
error_exit("NO [$APPEND_SIZE_STRING] detect, exit");
|
||||
}
|
||||
|
||||
#
|
||||
#step-4 do raw RW action
|
||||
#
|
||||
debug_msg("STEP_4");
|
||||
if($OPERATION_ARGV =~ /APPEND/i){
|
||||
sysseek(INPUT_STREAM,$index+12,0);
|
||||
sysread(INPUT_STREAM,$tmp_size,4);
|
||||
if($tmp_size !~ /$LT_INVALID_ADDRESS/){
|
||||
error_exit("item [$APPEND_SIZE_STRING][$tmp_size] is not NULL");
|
||||
}
|
||||
sysseek(INPUT_STREAM,$index+12,0);
|
||||
$tmp_size = hex_32_reorder($input_append_bin_size);
|
||||
syswrite(INPUT_STREAM,pack("H*",sprintf("%08x",$tmp_size)),4);
|
||||
close INPUT_STREAM;
|
||||
|
||||
#step-4 : do binary file append action
|
||||
file_append($FRONT_IMG_FILENAME,$APPEND_IMG_FILENAME);
|
||||
|
||||
|
||||
print sprintf ("|%-53s| 0x%0.8x = %6.3f(KB)\n",$FRONT_IMG_FILENAME
|
||||
,$input_front_bin_size,$input_front_bin_size/1024);
|
||||
|
||||
print sprintf ("|%s\n"," + ");
|
||||
print sprintf ("|%-53s| 0x%0.8x = %6.3f(KB)\n",$APPEND_IMG_FILENAME
|
||||
,$input_append_bin_size,$input_append_bin_size/1024);
|
||||
|
||||
#print sprintf ("|%s|\n","-------------------------------------------------------------------------------");
|
||||
print sprintf ("|%s\n"," = ");
|
||||
print sprintf ("|%-53s| 0x%0.8x = %6.3f(KB)\n",$FRONT_IMG_FILENAME,
|
||||
($input_front_bin_size+$input_append_bin_size),($input_front_bin_size+$input_append_bin_size)/1024);
|
||||
}
|
||||
|
||||
#
|
||||
#step-5 printf handle success result info
|
||||
#
|
||||
print sprintf ("|%s\n","-------------------------------------------------------------------------------");
|
||||
|
||||
|
||||
#
|
||||
# common functions
|
||||
#
|
||||
sub debug_msg{
|
||||
unless($DEBUG){return};
|
||||
local $DEBUG_MSG="DEBUG >>> :";
|
||||
print "$DEBUG_MSG @_";
|
||||
print "\n";
|
||||
}
|
||||
|
||||
sub hex_32_reorder{
|
||||
local $m_hex = $_[0];
|
||||
$m_hex = ((($m_hex&0x000000ff)<<24)|
|
||||
(($m_hex&0x0000ff00)<<8)|
|
||||
(($m_hex&0x00ff0000)>>8)|
|
||||
(($m_hex&0xff000000)>>24));
|
||||
return $m_hex;
|
||||
}
|
||||
|
||||
sub raw_to_hex{
|
||||
local $m_hex = hex(unpack("H*",$_[0]));
|
||||
$m_hex = hex_32_reorder($m_hex);
|
||||
return $m_hex;
|
||||
}
|
||||
|
||||
sub error_exit{
|
||||
local $ERROR_MSG="\nERROR:**";
|
||||
print "----------------------";
|
||||
print "$ERROR_MSG @_";
|
||||
print "\n";
|
||||
print "****************************************************************\n";
|
||||
print("$OPERATION_ARGV ERROR!\n");
|
||||
print "****************************************************************\n";
|
||||
print sprintf ("|%s|\n","-------------------------------------------------------------------------------");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sub file_append{
|
||||
open(RH,$_[1]) or die "$!";
|
||||
binmode RH;
|
||||
my @src_1=<RH>;
|
||||
close RH;
|
||||
open(WH,">>$_[0]") or die "$!";
|
||||
binmode WH;
|
||||
my $i;
|
||||
for($i = 0; $i < @src_1; $i++){
|
||||
print WH $src_1[$i];
|
||||
}
|
||||
close WH;
|
||||
}
|
||||
|
||||
sub file_merge{
|
||||
open(RH,$_[0]) or die "$!";
|
||||
binmode RH;
|
||||
my @src_1=<RH>;
|
||||
close RH;
|
||||
|
||||
open(RH,$_[1]) or die "$!";
|
||||
binmode RH;
|
||||
my @src_2=<RH>;
|
||||
close RH;
|
||||
|
||||
#create&overwrite for input file arg0
|
||||
open(WH,">$_[2]") or die "$!";
|
||||
binmode WH;
|
||||
my $i;
|
||||
for($i = 0; $i < @src_1; $i++){
|
||||
print WH $src_1[$i];
|
||||
}
|
||||
close WH;
|
||||
|
||||
#append for input file arg1
|
||||
open(WH,">>$_[2]") or die "$!";
|
||||
binmode WH;
|
||||
my $i;
|
||||
for($i = 0; $i < @src_2; $i++){
|
||||
print WH $src_2[$i];
|
||||
}
|
||||
close WH;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
#[20210225][xiaokeweng@asrmicro.com]
|
||||
# COMM: update ext info BIN_SIZE update for Ext combined image
|
||||
#
|
||||
# ----------------------------------
|
||||
# | Updater (with Ext info) |
|
||||
# |--------------------------------|
|
||||
# | dsp_adc.bin |
|
||||
# |--------------------------------|
|
||||
# | crc |
|
||||
# |--------------------------------|
|
||||
#
|
||||
|
||||
use Fcntl;
|
||||
|
||||
$DEBUG=1;
|
||||
$LOADTABLE_HEADER_LENGTH=0x1200;
|
||||
$IMG_FILENAME = $ARGV[0];
|
||||
$BINARY_SIZE_STRING= $ARGV[1];
|
||||
|
||||
my $binary_size= -s $IMG_FILENAME;
|
||||
sysopen(INPUT_STREAM,"$IMG_FILENAME",O_BINARY|O_RDWR)
|
||||
or error_exit("Can't open [$IMG_FILENAME] for reading; $!");
|
||||
|
||||
#print sprintf ("binary_size=[0x%.08x]\n", $binary_size);
|
||||
sysread(INPUT_STREAM,$loadtable_header,$LOADTABLE_HEADER_LENGTH);
|
||||
$index=index($loadtable_header,$BINARY_SIZE_STRING);
|
||||
if ($index == -1){
|
||||
error_exit("NO BINARY_SIZE_STRING [$BINARY_SIZE_STRING] detect, exit");
|
||||
}
|
||||
|
||||
sysseek(INPUT_STREAM,$index,0);
|
||||
sysread(INPUT_STREAM,$ITEM_NAME,12);
|
||||
sysseek(INPUT_STREAM,$index+12,0);
|
||||
sysread(INPUT_STREAM,$original_val,4);
|
||||
|
||||
#print sprintf ("original_val =[0x%.08x ]\r\n",raw_to_hex($original_val));
|
||||
|
||||
# typedef struct{
|
||||
# char name[12];
|
||||
# UINT32 value;
|
||||
# }armlink_symbol_item;
|
||||
#
|
||||
#
|
||||
sysseek(INPUT_STREAM,$index+12,0);
|
||||
$tmp_raw = hex_32_reorder($binary_size);
|
||||
syswrite(INPUT_STREAM,pack("H*",sprintf("%08x",$tmp_raw)),4);
|
||||
|
||||
sysseek(INPUT_STREAM,$index+12,0);
|
||||
sysread(INPUT_STREAM,$filled_in_val,4);
|
||||
#print sprintf ("filledin_val =[0x%.08x ]\r\n",raw_to_hex($filled_in_val));
|
||||
|
||||
print sprintf ("[%12s]=[0x%.08x ] -> [0x%.08x ]\r\n",
|
||||
$ITEM_NAME,raw_to_hex($original_val),raw_to_hex($filled_in_val));
|
||||
|
||||
close INPUT_STREAM;
|
||||
|
||||
# functions
|
||||
#
|
||||
sub hex_32_reorder{
|
||||
local $m_hex = $_[0];
|
||||
$m_hex = ((($m_hex&0x000000ff)<<24)|
|
||||
(($m_hex&0x0000ff00)<<8)|
|
||||
(($m_hex&0x00ff0000)>>8)|
|
||||
(($m_hex&0xff000000)>>24));
|
||||
return $m_hex;
|
||||
}
|
||||
|
||||
sub raw_to_hex{
|
||||
local $m_hex = hex(unpack("H*",$_[0]));
|
||||
$m_hex = hex_32_reorder($m_hex);
|
||||
return $m_hex;
|
||||
}
|
||||
|
||||
sub error_exit{
|
||||
local $ERROR_MSG="\nERROR:**";
|
||||
print "----------------------";
|
||||
print "$ERROR_MSG @_";
|
||||
print "\n";
|
||||
exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user