imgtools/buildrom/tools/datadriveimage.pm
changeset 606 30b30f9da0b7
parent 0 044383f39525
child 607 378360dbbdba
equal deleted inserted replaced
605:122d2b873fd1 606:30b30f9da0b7
    42 
    42 
    43 use strict;
    43 use strict;
    44 use File::Path;		# Module to provide functions to remove or create directories in a convenient way.
    44 use File::Path;		# Module to provide functions to remove or create directories in a convenient way.
    45 use File::Copy;		# Module to provide functions to copy file(s) from source to destination.
    45 use File::Copy;		# Module to provide functions to copy file(s) from source to destination.
    46 
    46 
    47 use Pathutl;
       
    48 use Cwd;			# Module to provide functions for determining the pathname of the current working directory.
    47 use Cwd;			# Module to provide functions for determining the pathname of the current working directory.
       
    48 
       
    49 use romutl;
       
    50 use romosvariant;
    49 
    51 
    50 # This fuction is used primiarly to check for whitespace in the location for "zdrive" / "datadrive" folder creation,
    52 # This fuction is used primiarly to check for whitespace in the location for "zdrive" / "datadrive" folder creation,
    51 # specified by the user, if yes then it returns one, else zero
    53 # specified by the user, if yes then it returns one, else zero
    52 sub checkForWhiteSpace
    54 sub checkForWhiteSpace
    53 {
    55 {
   168 {
   170 {
   169 	my($dirName) = @_;
   171 	my($dirName) = @_;
   170 	# get the working directory.
   172 	# get the working directory.
   171 	my $curWorkingDir = getcwd;
   173 	my $curWorkingDir = getcwd;
   172 	# substitute slash with double backward slash.
   174 	# substitute slash with double backward slash.
   173 	$curWorkingDir =~ s/\//\\/g;
   175 	$curWorkingDir =~ s/\\/\//g;
   174  	#if $curWorkingDir already has trailing '\', don't include it again 
   176  	#if $curWorkingDir already has trailing '\', don't include it again 
   175  	if( $curWorkingDir =~ /\\$/)
   177  	if( $curWorkingDir =~ /\/$/)
   176  	{
   178  	{
   177  		return $curWorkingDir.$dirName;
   179  		return $curWorkingDir.$dirName;
   178  	}
   180  	}
   179  	else
   181  	else
   180  	{
   182  	{
   181  		return $curWorkingDir."\\".$dirName;
   183  		return $curWorkingDir."\/".$dirName;
   182  	}
   184  	}
   183 }
   185 }
   184 
   186 
   185 # create directory and copy respective file on to that directory.
   187 # create directory and copy respective file on to that directory.
   186 # is there is a problem while copying files from source to destination
   188 # is there is a problem while copying files from source to destination
   191 	$source =~ s/\"//g; # remove double quotes from the string. 
   193 	$source =~ s/\"//g; # remove double quotes from the string. 
   192 	my $destFileName = "";	# name of the destination file.
   194 	my $destFileName = "";	# name of the destination file.
   193 	$dest =~ s/\"//g;	# remove double quotes from the string. 
   195 	$dest =~ s/\"//g;	# remove double quotes from the string. 
   194 	my $destDirectory = $dest;
   196 	my $destDirectory = $dest;
   195 	# strip the last substring to get destination file 
   197 	# strip the last substring to get destination file 
   196 	if ($dest=~/.*\\(\S+)/) 
   198 	if ($dest=~/.*[\/\\](\S+)/) 
   197 	{
   199 	{
   198 		$destFileName = $1;
   200 		$destFileName = $1;
   199 	}
   201 	}
   200 	else
   202 	else
   201 	{
   203 	{
   212 	}
   214 	}
   213 	else
   215 	else
   214 	{	
   216 	{	
   215 		$destDirectory =~ s/$destFileName//;
   217 		$destDirectory =~ s/$destFileName//;
   216 	}
   218 	}
   217 	my $destfile = $dir."\\".$dest;
   219 	my $destfile = $dir."\/".$dest;
   218 	my $createdir = $dir."\\".$destDirectory ;
   220 	my $createdir = $dir."\/".$destDirectory ;
   219 
   221 
   220 	# create the specified directory.
   222 	# create the specified directory.
   221 	&createDirectory($createdir);
   223 	&createDirectory($createdir);
   222 	if (!copy($source,$destfile))
   224 	if (!copy($source,$destfile))
   223 	{
   225 	{
   225 		return 0;
   227 		return 0;
   226 	}
   228 	}
   227 	else
   229 	else
   228 	{
   230 	{
   229 		print "$source copied to $destfile\n" if($verboseOpt);
   231 		print "$source copied to $destfile\n" if($verboseOpt);
   230 		return $destfile;
   232 		return "\"".$destfile."\"";
   231 	}
   233 	}
   232 }
   234 }
   233 
   235 
   234 # Make a check for sisfile keyword by reading the specified iby/oby file,
   236 # Make a check for sisfile keyword by reading the specified iby/oby file,
   235 # if sisfile keyword is found then push the respective image on to the respective array 
   237 # if sisfile keyword is found then push the respective image on to the respective array 
   284 {
   286 {
   285 	my($dir,$obyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt) = @_;
   287 	my($dir,$obyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt) = @_;
   286 	open (OBEY ,$obyfile) or die($obyfile."\n");
   288 	open (OBEY ,$obyfile) or die($obyfile."\n");
   287 	while(my $line =<OBEY>) 
   289 	while(my $line =<OBEY>) 
   288 	{
   290 	{
   289 		if( $line =~ /^(file|data)\s*=\s*(\S+)\s+(\S+)/i )
   291 		if( $line =~ /^(file|data)\s*=\s*(\"[^"]+\")\s+(\"[^"]+\")/i || 
       
   292 				$line =~ /^(file|data)\s*=\s*(\"[^"]+\")\s+(\S+)/i || 
       
   293 				$line =~ /^(file|data)\s*=\s*(\S+)\s+(\"[^"]+\")/i || 
       
   294 				$line =~ /^(file|data)\s*=\s*(\S+)\s+(\S+)/i )
   290 		{
   295 		{
   291 			my $keyWord=$1;
   296 			my $keyWord=$1;
   292 			my $source=$2;
   297 			my $source=$2;
   293 			my $dest=$3;
   298 			my $dest=$3;
   294 
   299 
   295 			if( $source !~ /(\S+):(\S+)/ )
   300 			if( $source !~ /(\S+):([^"]+)/ )
   296 			{ 
   301 			{ 
   297 				$source = Path_Drive().$2;
   302 				$source = get_drive().$2;
   298 			}
   303 			}
   299 			my $var = &copyFilesToFolders( $source,$dest,$dir,$verboseOpt);
   304 			my $var = &copyFilesToFolders( $source,$dest,$dir,$verboseOpt);
   300 			if($var)
   305 			if($var)
   301 			{
   306 			{
   302 				$var = $keyWord."=".$var;
   307 				$line = $keyWord."=".$var."\t".$dest."\n";
   303 				$line =~ s/^(\S+)=(\S+)/$var/;
       
   304 				push(@$nonsisFileArray,$line);
   308 				push(@$nonsisFileArray,$line);
   305 			}
   309 			}
   306 			else
   310 			else
   307 			{
   311 			{
   308 				exit(1)if(!$keepgoingOpt);
   312 				exit(1)if(!$keepgoingOpt);
   364 	# default system drive letter is specified since interpretsis doesnt allow overloading of options unless default 
   368 	# default system drive letter is specified since interpretsis doesnt allow overloading of options unless default 
   365 	# options are specified.
   369 	# options are specified.
   366 	my $basicOption = "-d C: ";	# default system drive letter
   370 	my $basicOption = "-d C: ";	# default system drive letter
   367 	my $command = "interpretsis ";
   371 	my $command = "interpretsis ";
   368 	my $vOption = "-w info" if ($verboseOpt);
   372 	my $vOption = "-w info" if ($verboseOpt);
       
   373 	
       
   374 	is_existinpath("interpretsis", romutl::DIE_NOT_FOUND);
   369 
   375 
   370 	# do a check if the path has a white space.
   376 	# do a check if the path has a white space.
   371 	if( $dataDrivePath =~ m/ /)
   377 	if( $dataDrivePath =~ m/ /)
   372 	{
   378 	{
   373 		$dataDrivePath = '"'.$dataDrivePath.'"';
   379 		$dataDrivePath = '"'.$dataDrivePath.'"';
   428 		for( my $i = 0; $i < $arraysize; $i++ )
   434 		for( my $i = 0; $i < $arraysize; $i++ )
   429 		{
   435 		{
   430 			$command .= $$interpretsisOptList[$i]." ";
   436 			$command .= $$interpretsisOptList[$i]." ";
   431 		}
   437 		}
   432 	}
   438 	}
   433 
   439 	
   434 	print "* Executing $command\n" if ( $verboseOpt );
   440 	print "* Executing $command\n" if ( $verboseOpt );
   435 	system ( $command );
   441 	system ( $command );
   436 
   442 
   437 	if ($? != 0)
   443 	if ($? != 0)
   438 	{
   444 	{
   443 # invoke the READIMAGE tool with appropriate parameters.
   449 # invoke the READIMAGE tool with appropriate parameters.
   444 sub invokeReadImage
   450 sub invokeReadImage
   445 {
   451 {
   446 	my($imageName,$loc,$verboseOpt,$logFile,$keepgoingOpt) = @_;
   452 	my($imageName,$loc,$verboseOpt,$logFile,$keepgoingOpt) = @_;
   447 	my $command = "readimage ";
   453 	my $command = "readimage ";
       
   454 	
       
   455 	is_existinpath("readimage", romutl::DIE_NOT_FOUND);
       
   456 	
   448 	# check if log file has been supplied.
   457 	# check if log file has been supplied.
   449 	if(defined($logFile))
   458 	if(defined($logFile))
   450 	{
   459 	{
   451 		if( $logFile =~ m/ /)
   460 		if( $logFile =~ m/ /)
   452 		{
   461 		{
   490 	# destination file.
   499 	# destination file.
   491 	my $linedestFile;
   500 	my $linedestFile;
   492 	# get source file.
   501 	# get source file.
   493 
   502 
   494 	# strip first occurrence of back slash
   503 	# strip first occurrence of back slash
   495 	$linesource =~ s/\\//; 
   504 	$linesource =~ s/[\/\\]//; 
   496 
   505 
   497 	# get source file.
   506 	# get source file.
   498 	if ($linesource =~ /.*\\(\S+)/ ) 
   507 	if ($linesource =~ /.*[\/\\](\S+)/ ) 
   499 	{
   508 	{
   500 		$linesourceFile = $1;
   509 		$linesourceFile = $1;
   501 	}
   510 	}
   502 	# get destination file.
   511 	# get destination file.
   503 	if ($linedest =~ /.*\\(\S+)/ )
   512 	if ($linedest =~ /.*[\/\\](\S+)/ )
   504 	{
   513 	{
   505 		$linedestFile = $1;
   514 		$linedestFile = $1;
   506 	}
   515 	}
   507 	# iterate trough all
   516 	# iterate trough all
   508 	foreach my $firstarrayEntry (@$firstarray) 
   517 	foreach my $firstarrayEntry (@$firstarray) 
   523 					{
   532 					{
   524 						my $nonsisEntryDest = $3;
   533 						my $nonsisEntryDest = $3;
   525 						# remove double quotes.
   534 						# remove double quotes.
   526 						$nonsisEntryDest =~ s/\"//g;
   535 						$nonsisEntryDest =~ s/\"//g;
   527 						my $nonsisEntryDestFile;
   536 						my $nonsisEntryDestFile;
   528 						if ($nonsisEntryDest =~ /.*\\(\S+)/ ) 
   537 						if ($nonsisEntryDest =~ /.*[\/\\](\S+)/ ) 
   529 						{ 
   538 						{ 
   530 							$nonsisEntryDestFile = $1;
   539 							$nonsisEntryDestFile = $1;
   531 						}
   540 						}
   532 						if( $nonsisEntryDest eq $linesource )
   541 						if( $nonsisEntryDest eq $linesource )
   533 						{
   542 						{
   591 						{
   600 						{
   592 							my $newLineKeyword = $1;
   601 							my $newLineKeyword = $1;
   593 							my $newLinesource = $2;
   602 							my $newLinesource = $2;
   594 							my $newLinedest = $3;
   603 							my $newLinedest = $3;
   595 							$newLinedest =~ s/\"//g;
   604 							$newLinedest =~ s/\"//g;
   596 							$newLinedest = "\\".$newLinedest;
   605 							$newLinedest = "\/".$newLinedest;
   597 							if( $newLinedest eq $lineToSearch )
   606 							if( $newLinedest eq $lineToSearch )
   598 							{
   607 							{
   599 								# remove the specified element from the array.
   608 								# remove the specified element from the array.
   600 								splice(@$nonsisFileArray,$nonsisFileListCount,1);
   609 								splice(@$nonsisFileArray,$nonsisFileListCount,1);
   601 							}
   610 							}
   664 		#skip, parent directory and current directory.
   673 		#skip, parent directory and current directory.
   665 		next if ($entry eq "." || $entry eq "..");
   674 		next if ($entry eq "." || $entry eq "..");
   666 		#check if it is a file 
   675 		#check if it is a file 
   667 		if( -f $entry )
   676 		if( -f $entry )
   668 		{
   677 		{
   669 			my $sourcedir = $rootdir."\\".$folderList.$entry;
   678 			my $sourcedir = $rootdir."\/".$folderList.$entry;
   670 			my $destdir	= "$folderList".$entry;
   679 			my $destdir	= "$folderList".$entry;
   671 			my $sisSource;
   680 			my $sisSource;
   672 			my $sisdestination;
   681 			my $sisdestination;
   673 			if(&checkRegCtlFiles($entry))
   682 			if(&checkRegCtlFiles($entry))
   674 			{
   683 			{
   704 			}
   713 			}
   705 		}
   714 		}
   706 		#else it's a directory
   715 		#else it's a directory
   707 		else
   716 		else
   708 		{
   717 		{
   709 			&TraverseDir($entry,$folderList.$entry."\\",$sisFileContent,$rootdir);
   718 			&TraverseDir($entry,$folderList.$entry."\/",$sisFileContent,$rootdir);
   710 		}
   719 		}
   711 	}
   720 	}
   712 	closedir(DIR);
   721 	closedir(DIR);
   713 	chdir("..");
   722 	chdir("..");
   714 }
   723 }
   720 	#get the array size.
   729 	#get the array size.
   721 	my $arraySize = scalar(@$array);
   730 	my $arraySize = scalar(@$array);
   722 	for(my $i=0; $i<$arraySize ; $i++ )
   731 	for(my $i=0; $i<$arraySize ; $i++ )
   723 	{
   732 	{
   724 		#pop out the element to the respective obey file.
   733 		#pop out the element to the respective obey file.
   725 		 print NEWDATA pop(@$array)."\n";
   734 		my $line=pop(@$array);
   726 	}
   735 		if (&is_windows){
   727 }
   736 			$line =~ s-\/-\\-g;
       
   737 		}else{
       
   738 			$line =~ s-\\-\/-g;
       
   739 		}
       
   740 		print NEWDATA $line."\n";
       
   741 	}
       
   742 }