Perl script to check the length of a file
In a embedded project, because of the cost, the size of ROM or SRAM is usually restricted,the same rule certainly applies to the code running in ROM or SRAM.when the ELF files is complete, one may want to check the total length of .text, .data, and some other sections together.
So, for that, here is a length-checking script which is written in perl.
1. how to call it to check
./check_length.pl ${MAX_BIN_FILE_SIZE}
the command above is in a Makefile in the root path of that project.
MAX_BIN_FILE_SIZE is the max size, whichcould be specified according to the requirement of your project.
Actually, there should be another argument of "check_length.pl".
But at present, a fixed file name is gived to it , so that file name to be checked is not specified.
2. let's have a look at the perl script itself
#!/usr/bin/perl
#####this command is used to indicate that Linux bash command stat will be used in this perl script.
use Shell qw(stat);
#####here, temp.bin is the file that will be checked.
#####for the flexibility, the file name should be provided through command line while check_length.pl is called.
##### the actual size of that file
$fileone=stat("-c %s temp.bin");
##### that max size from the command line
$KBytes = @ARGV/1024;
#@filetwo=stat("1.text");
##### Give infos, that the checking is underway
print "\nCheck the length - the length of temp.bin in Bytes is $fileone";
print " - the max length of binary file in Bytes is @ARGV< $KBytes*102\
4 >\n";
##the max length of bootrom code is 3KBytes, 3 * 1024 = 3072
#if(@ARGV > 3072)
#print "Result:\n";
if ($fileone > @ARGV)
{
die "ERROR:\n The length of temp.bin Exceeds @ARGV< $KBytes*1024 >!\n";
}
else
{
print "INFO:\n The length of temp.bin is OK.\n";
}
print "\n";
#if ($filetwo lt "2048"){
# die "Errorrrrrrrrrrrrrrrrr 222222222222222\n"
#}
#else
#{
# print "Gooddddddddddddddd 22222222222222222\n"
#}
exit;
This is a very simple perl script.
But the essential aspects are contained in the perl file.
If there are some complex requirements, this perl script could be improved.
页:
[1]