diff -r 7c4a911dc066 -r 541af5ee3ed9 imgtools/buildrom/tools/spitool.pm --- a/imgtools/buildrom/tools/spitool.pm Fri Aug 13 14:59:05 2010 +0300 +++ b/imgtools/buildrom/tools/spitool.pm Wed Aug 18 17:23:33 2010 +0300 @@ -1,478 +1,478 @@ -# -# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# This component and the accompanying materials are made available -# under the terms of the License "Eclipse Public License v1.0" -# which accompanies this distribution, and is available -# at the URL "http://www.eclipse.org/legal/epl-v10.html". -# -# Initial Contributors: -# Nokia Corporation - initial contribution. -# -# Contributors: -# -# Description: -# - -package spitool; - -use strict; -use Exporter; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); - -$VERSION = 1.00; -@ISA = qw(Exporter); -@EXPORT = (); -@EXPORT_OK = qw(createSpi); - -sub binarize { #converts decimal number to 4 byte litte endian format - my $value = shift; - my $remainder; - my $returnValue; - for(my $i=0;$i<4;$i++) { - $remainder=$value % 256; - $returnValue.=chr($remainder); - $value = ($value-$remainder)/256; - } - return $returnValue; -} - -sub convertUidFromText { #converts UID from hexadeciaml text value to decimal value, passes decimal value unchanged, returns -1 if invalid UID - my $value = shift; - if($value =~ /^0x([\da-fA-F]{1,8})$/i) { - return hex $1; - } elsif ($value =~ /^\d*$/) { - return $value; - } else { - return -1; - } -} - -sub bin2hex { #converts 4 byte little endian value to 0x... hex text value - my $value=shift; - my $byte; - my $quotient; - my $remainder; - my $hexValue=""; - for(my $i=0;$i<4;$i++) { - $byte=ord(substr($value,$i,1)); - $remainder=$byte%16; - $quotient=($byte-$remainder)/16; - if($remainder>9) { - $remainder= chr($remainder+55); - } - if($quotient>9) { - $quotient= chr($quotient+55); - } - $hexValue=$quotient . $remainder . $hexValue; - } - return "0x" . $hexValue; -} - -sub uidcrc { #returns decimal UID checksum value for the three inputs - my $output = `uidcrc $_[0] $_[1] $_[2]`; - if($output =~ /([^ ]*)$/i) { - $output =$1; - chomp $output; - return hex($output); - } -} - -sub printZeroes { #prints as many hexadecimal zeroes to OUTPUTFILE as specified by input - my $numberOfZeroes=shift; - for(my $i=0;$i<$numberOfZeroes;$i++) { - print OUTPUTFILE chr(0); - } -} - -sub bytes2dec { #calculates decimal value from inputted 4 byte little endian value - my $bytes=shift; - my @byteArray; - for(my $i=0;$i= -- has value 1, 2 or 3, is an UID value in - decimal or 0x... hexadecimal --existinguid= -- has value 1, 2 or 3, is an UID value in - decimal or 0x... hexadecimal --existinguidcrc= -- is an UID value in decimal or 0x.. hexadecimal --hide -- is the list of the resource files - that are to be hidden in the SPI file separated by - space or comma. - -If an existing SPI file is specified with the -i option then this file is -used as a base and other data files are added to the end of this file, -otherwise a new SPI file is created. In either case the produced SPI file -is placed in the directory specified by the -d option and given the name -specified with the -t option. - -Files which are to be concatenated into the SPI file should be specified -on the command line by either specifying the file's name (and location), or -by including a directory name, in which case all files from that directory -will be included. - -The -uid options can be used to filter files for inclusion in the SPI file. -This option can be included multiple times, so a list of UID1 values can be -built up, and the same for UID2 and UID3 values. Each file on the command -line is compared with this list, and if any of its UID values match a -relevant value in the UID lists then that file will be included in the SPI -file. If the file does not match any values it will be excluded. - -The -existinguid options allow the UID values that an existing SPI file -should have to be specified. This will allow the possibility of checking -that the correct type of files are being concatenated together. - -The -hide option can be used to mark a resource file as hidden in the SPI file. -To mark a resource file as a hidden entry in the SPI file, the resource data -length will be written as 0. - -USAGE_EOF - } - -sub createSpi - { - my @resourceFiles=(); - my @hideresourceFiles=(); - my $spiFileName; - my $targetDirectory; - my $existingSpiFileName; - my @uid; - my @uidLengths = (0, 0, 0, 0); - my @uid1; - my @uid2; - my @uid3; - my @existingUid = (-1,-1,-1,-1); - my $uidNumber; - my $defaultSpiFileName = "ecom-0-0.spi"; - my $defaultTargetDirectory = "$ENV{EPOCROOT}epoc32\\tools\\"; - my @defaultUid = (-1,-1,-1,-1); - -########################################################################################## -# Reading arguments phase -########################################################################################## - - foreach my $arg (@_) { - if ($arg =~ /^-t(.*)/i) { # set target SPI file - $spiFileName = $1; - next; - } - if ($arg =~ /^-d(.*)/i) { # set target ouput directory - my $tempDirectory=$1; - if((-d $tempDirectory) ) { - $targetDirectory = $tempDirectory; - next; - } - else - { - print "Output directory \'",$tempDirectory,"\' does not exist.\n"; - exit(1); - } - } - if ($arg =~ /^-i(.*)/i) { # existing SPI file to use as a base - my $tempFileName = $1; - if((-e $tempFileName) && (!(-d $tempFileName))) { - $existingSpiFileName = $tempFileName; - next; - } - } - if ($arg =~ /^-uid([1-3])\=(.*)/i) { - $uid[$1-1][$uidLengths[$1-1]++] = $2; - next; - } - if($arg=~/^-existinguidcrc\=(.*)/i) { - $existingUid[3]=$1; - next; - } - if ($arg =~ /^-existinguid([1-3])\=(.*)/i) { - $existingUid[$1-1]=$2; - next; - } - if ($arg =~ /^-hide(.*)/i) { # Collect the files to be hidden - my $line = $1; - $line =~ s/,/ /g; - my @files = split(' ' , $line); - foreach my $file (@files) - { - push @hideresourceFiles, $file; - } - next; - } - if (-d $arg) { - if(($arg =~ m-^.:-) && ($arg =~ m-\\$-)) { - unless(opendir(DIRECTORY, $arg)) { print "Exiting: $arg"; exit; } - while (my $file=readdir(DIRECTORY)) { - my $newfile = $arg.$file; - if(!(-d $newfile)) { - push @resourceFiles, $newfile; - } - } - close(DIRECTORY); - next; - } - } - if ((-e $arg) && (!(-d $arg))) { - push @resourceFiles, $arg; - next; - } - if ($arg eq "-h") { - print_usage; - exit(1); - } - print "Unknown command: $arg\n"; - } - -##################################################################################### -# UID phase -##################################################################################### - - if(!(defined $spiFileName)) { #use default file name if none passed on command line - $spiFileName = $defaultSpiFileName; - } - if(!(defined $targetDirectory)) { #use default target dir if none passed on command line - $targetDirectory = $defaultTargetDirectory; - } - for(my $i=0;$i<3;$i++) { #if default UIDs specified then added to UID match lists - if($defaultUid[$i]>=0) { - $uid[$i][$uidLengths[$i]++] = $defaultUid[$i]; - } - } - for(my $i=0;$i<3;$i++) { #makes sure UIDs are valid UIDs - my @tempUidArray; - my $iterator=0; - while(defined $uid[$i][$iterator]) { - my $convertedUid=convertUidFromText($uid[$i][$iterator]); - if ($convertedUid != -1) { - push @tempUidArray, binarize($convertedUid); - } else { - print "Invalid UID: $uid[$i][$iterator]\n"; - } - $iterator++; - } - for(my $j=0;$i