author | Zheng Shen <zheng.shen@nokia.com> |
Tue, 17 Aug 2010 15:31:16 +0800 | |
changeset 626 | ac03b93ca9c4 |
parent 607 | 378360dbbdba |
child 647 | 53d1ab72f5bc |
permissions | -rw-r--r-- |
606 | 1 |
# |
2 |
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
# All rights reserved. |
|
4 |
# This component and the accompanying materials are made available |
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
|
6 |
# which accompanies this distribution, and is available |
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
# |
|
9 |
# Initial Contributors: |
|
10 |
# Nokia Corporation - initial contribution. |
|
11 |
# |
|
12 |
# Contributors: |
|
13 |
# |
|
14 |
# Description: |
|
15 |
# This package contains fuctions specific to data drive image generation |
|
16 |
# |
|
17 |
||
18 |
||
19 |
package datadriveimage; |
|
20 |
||
21 |
require Exporter; |
|
22 |
@ISA=qw(Exporter); |
|
23 |
@EXPORT=qw( |
|
24 |
createDirectory |
|
25 |
deleteDirectory |
|
26 |
checkInArray |
|
27 |
setPath |
|
28 |
locateStubsisfiles |
|
29 |
copyFilesToFolders |
|
30 |
checkForSisFile |
|
31 |
copyNonSisFiles |
|
32 |
invokeInterpretsis |
|
33 |
invokeReadImage |
|
34 |
compareArrays |
|
35 |
dumpDatadriveObydata |
|
36 |
TraverseDir |
|
37 |
writeDataToFile |
|
38 |
generate_datadriveheader |
|
39 |
checkForWhiteSpace |
|
40 |
reportError |
|
41 |
); |
|
42 |
||
43 |
use strict; |
|
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. |
|
46 |
||
47 |
use Cwd; # Module to provide functions for determining the pathname of the current working directory. |
|
48 |
||
49 |
use romutl; |
|
50 |
use romosvariant; |
|
51 |
||
52 |
# This fuction is used primiarly to check for whitespace in the location for "zdrive" / "datadrive" folder creation, |
|
53 |
# specified by the user, if yes then it returns one, else zero |
|
54 |
sub checkForWhiteSpace |
|
55 |
{ |
|
56 |
my ($dirLoc,$dirName) = @_; |
|
57 |
if( $dirLoc =~ m/ / ) |
|
58 |
{ |
|
59 |
print "* Warning: $dirLoc contains whitespace, hence $dirName will be created in default location \n"; |
|
60 |
return 1; |
|
61 |
} |
|
62 |
else |
|
63 |
{ |
|
64 |
return 0; |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
||
69 |
# This function reports the appropriate meassage supplied to it |
|
70 |
# and does a exit if and only if keepgoing option is disabled. |
|
71 |
sub reportError |
|
72 |
{ |
|
73 |
my( $message,$keepgoingOpt ) = @_; |
|
74 |
# print the specified meassage. |
|
75 |
print STDERR "$message \n"; |
|
76 |
# bail out, if keepgoing option is not set. |
|
77 |
exit(1) if (!$keepgoingOpt); |
|
78 |
} |
|
79 |
||
80 |
# generate header for final datadrive oby file. |
|
81 |
sub generate_datadriveheader |
|
82 |
{ |
|
83 |
my ($idx,$datadriveimage) = @_; |
|
84 |
my $header; |
|
85 |
$header = "dataimagename=$$datadriveimage[$idx]{name}.img\n"; |
|
86 |
$header .= "dataimagefilesystem=$$datadriveimage[$idx]{fstype}\n"; |
|
87 |
||
88 |
# check whether the size of the image has been mentioned |
|
89 |
if(defined($$datadriveimage[$idx]{size})) |
|
90 |
{ |
|
91 |
$header .= "dataimagesize=$$datadriveimage[$idx]{size}\n\n"; |
|
92 |
} |
|
93 |
return $header; |
|
94 |
} |
|
95 |
||
96 |
# Create the specified directory by making use of mkpath function |
|
97 |
# from File::Path module. |
|
98 |
sub createDirectory |
|
99 |
{ |
|
100 |
my($dir) = @_; |
|
101 |
if( !-d $dir ) |
|
102 |
{ |
|
103 |
mkpath($dir); |
|
104 |
if (! -e $dir) |
|
105 |
{ |
|
106 |
print ("ERROR: Couldn't create $dir\n"); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
# check if the given file is a reg file or ctl file or a txt file |
|
112 |
# if it is any of these files then return true else false. |
|
113 |
# This check is need since these three files or not valid not valid e32 file |
|
114 |
# and hence needs to be placed as an data file inside the image. |
|
115 |
sub checkRegCtlFiles |
|
116 |
{ |
|
117 |
my ($fileName) = @_; |
|
118 |
||
119 |
# check whether the file has "reg","ctl" or "txt" extension. |
|
120 |
if( $fileName =~/\.(reg|ctl|txt)$/i ) |
|
121 |
{ |
|
122 |
return 1; |
|
123 |
} |
|
124 |
else |
|
125 |
{ |
|
126 |
return 0; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
# delete the given directory by making use of rmtree function |
|
131 |
# from File::Path module. |
|
132 |
sub deleteDirectory |
|
133 |
{ |
|
134 |
my($dir,$verboseOpt) = @_; |
|
135 |
# check whether the directory exists. |
|
136 |
if( -d $dir ) |
|
137 |
{ |
|
138 |
print("found $dir directory \n") if($verboseOpt); |
|
139 |
if(rmtree($dir)) |
|
140 |
{ |
|
141 |
print("$dir directory deleted \n") if($verboseOpt); |
|
142 |
return 0; |
|
143 |
} |
|
144 |
else |
|
145 |
{ |
|
146 |
print("$dir directory could'nt be deleted \n") if($verboseOpt); |
|
147 |
return 1; |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
# check for processed data drive image index. |
|
153 |
# if there is a match return one else return zero. |
|
154 |
# this check is done in order to ensure data drive image index is not repeated. |
|
155 |
sub checkInArray |
|
156 |
{ |
|
157 |
my($array, $value) = @_; |
|
158 |
foreach my $aLine(@$array) |
|
159 |
{ |
|
160 |
if( $aLine eq $value ) |
|
161 |
{ |
|
162 |
return 0; |
|
163 |
} |
|
164 |
} |
|
165 |
return 1; |
|
166 |
} |
|
167 |
||
168 |
# set the path for the given directory. |
|
169 |
sub setPath |
|
170 |
{ |
|
171 |
my($dirName) = @_; |
|
172 |
# get the working directory. |
|
173 |
my $curWorkingDir = getcwd; |
|
174 |
# substitute slash with double backward slash. |
|
175 |
$curWorkingDir =~ s/\\/\//g; |
|
176 |
#if $curWorkingDir already has trailing '\', don't include it again |
|
177 |
if( $curWorkingDir =~ /\/$/) |
|
178 |
{ |
|
179 |
return $curWorkingDir.$dirName; |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
return $curWorkingDir."\/".$dirName; |
|
184 |
} |
|
185 |
} |
|
186 |
||
187 |
# create directory and copy respective file on to that directory. |
|
188 |
# is there is a problem while copying files from source to destination |
|
189 |
# then bail out if and only if keep going option is disabled. |
|
190 |
sub copyFilesToFolders |
|
191 |
{ |
|
192 |
my ($source,$dest,$dir,$verboseOpt) = @_; |
|
193 |
$source =~ s/\"//g; # remove double quotes from the string. |
|
194 |
my $destFileName = ""; # name of the destination file. |
|
195 |
$dest =~ s/\"//g; # remove double quotes from the string. |
|
196 |
my $destDirectory = $dest; |
|
197 |
# strip the last substring to get destination file |
|
198 |
if ($dest=~/.*[\/\\](\S+)/) |
|
199 |
{ |
|
200 |
$destFileName = $1; |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
$destFileName = $dest; |
|
205 |
} |
|
206 |
#get the destination directory along with full path |
|
207 |
#when "[" and "]" appear in the file name we need add "\" before "[" or "]" |
|
208 |
#like this: [filename].exe translate to \[filename\].exe |
|
209 |
if($destFileName =~ /\[|\]/) |
|
210 |
{ |
|
211 |
my $tempFileName = $destFileName; |
|
212 |
$tempFileName =~ s/(\[|\])/\\$1/g; |
|
213 |
$destDirectory =~ s/$tempFileName//; |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
$destDirectory =~ s/$destFileName//; |
|
218 |
} |
|
219 |
my $destfile = $dir."\/".$dest; |
|
220 |
my $createdir = $dir."\/".$destDirectory ; |
|
221 |
||
222 |
# create the specified directory. |
|
223 |
&createDirectory($createdir); |
|
224 |
if (!copy($source,$destfile)) |
|
225 |
{ |
|
226 |
warn "warning : $source file could not found \n"; |
|
227 |
return 0; |
|
228 |
} |
|
229 |
else |
|
230 |
{ |
|
231 |
print "$source copied to $destfile\n" if($verboseOpt); |
|
232 |
return "\"".$destfile."\""; |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
# Make a check for sisfile keyword by reading the specified iby/oby file, |
|
237 |
# if sisfile keyword is found then push the respective image on to the respective array |
|
238 |
# and return true. |
|
239 |
sub checkForSisFile |
|
240 |
{ |
|
241 |
my($obyfile,$sisFileArray,$sisFilePrestent) = @_; |
|
242 |
# open the oby file in read only mode. |
|
243 |
open (DATA, "< $obyfile") or die("* Can't open $obyfile\n"); |
|
244 |
while (my $line =<DATA>) |
|
245 |
{ |
|
246 |
if($line =~ /^\s*sisfile\s*=\s*(\S+)/i ) |
|
247 |
{ |
|
248 |
# found a sis file. |
|
249 |
$$sisFilePrestent = 1; |
|
250 |
# push sis file on to stack. |
|
251 |
push(@$sisFileArray,$1); |
|
252 |
next; |
|
253 |
} |
|
254 |
} |
|
255 |
close(DATA); |
|
256 |
return $$sisFilePrestent; |
|
257 |
} |
|
258 |
||
259 |
# Make a check for zdriveimagename keyword by reading the specified iby/oby file, |
|
260 |
# if zdriveimagename keyword is found then push the respective image on to the respective array |
|
261 |
# and return true. |
|
262 |
sub checkForZDriveImageKeyword |
|
263 |
{ |
|
264 |
#$ZDriveImageFilePresent |
|
265 |
my($obyfile,$ZDriveImageKeywordArray,$ImageFilePresent) = @_; |
|
266 |
# open the oby file in read only mode. |
|
267 |
open (DATA, "< $obyfile") or die("* Can't open $obyfile\n"); |
|
268 |
while (my $line =<DATA>) |
|
269 |
{ |
|
270 |
if($line =~ /^\s*zdriveimagename\s*=\s*(\S+)/i ) |
|
271 |
{ |
|
272 |
# found a Z Drive Image file. |
|
273 |
$$ImageFilePresent = 1; |
|
274 |
# push sis file on to stack. |
|
275 |
push(@$ZDriveImageKeywordArray,$1); |
|
276 |
next; |
|
277 |
} |
|
278 |
} |
|
279 |
close(DATA); |
|
280 |
return $$ImageFilePresent; |
|
281 |
} |
|
282 |
||
283 |
# copy all non-sis file(s) on to prototype data drive folder |
|
284 |
# which are mentioned under input data drive iby/oby file. |
|
285 |
sub copyNonSisFiles |
|
286 |
{ |
|
287 |
my($dir,$obyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt) = @_; |
|
288 |
open (OBEY ,$obyfile) or die($obyfile."\n"); |
|
289 |
while(my $line =<OBEY>) |
|
290 |
{ |
|
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 ) |
|
295 |
{ |
|
296 |
my $keyWord=$1; |
|
297 |
my $source=$2; |
|
298 |
my $dest=$3; |
|
299 |
||
300 |
if( $source !~ /(\S+):([^"]+)/ ) |
|
301 |
{ |
|
302 |
$source = get_drive().$2; |
|
303 |
} |
|
304 |
my $var = ©FilesToFolders( $source,$dest,$dir,$verboseOpt); |
|
305 |
if($var) |
|
306 |
{ |
|
307 |
$line = $keyWord."=".$var."\t".$dest."\n"; |
|
308 |
push(@$nonsisFileArray,$line); |
|
309 |
} |
|
310 |
else |
|
311 |
{ |
|
312 |
exit(1)if(!$keepgoingOpt); |
|
313 |
} |
|
314 |
} |
|
315 |
elsif($line =~ /^rename\s+(\S+)\s+(\S+)/i) |
|
316 |
{ |
|
317 |
my $oldFile = $dir.$1; # existing-file |
|
318 |
my $newFile = $dir.$2; # destination-file |
|
319 |
print"found rename keyword\nrenaming $oldFile to $newFile\n" if ($verboseOpt); |
|
320 |
if ( rename($oldFile, $newFile) ) |
|
321 |
{ |
|
322 |
# push the line on to the stack. |
|
323 |
push(@$renameArray,$1."\t".$2."\n"); |
|
324 |
} |
|
325 |
else |
|
326 |
{ |
|
327 |
&datadriveimage::reportError("* Warning : can't rename $oldFile to $newFile: $!",$keepgoingOpt); |
|
328 |
} |
|
329 |
} |
|
330 |
elsif($line =~ /^alias\s+(\S+)\s+(\S+)/i) |
|
331 |
{ |
|
332 |
my $exFile = $dir.$1; # existing-file |
|
333 |
my $destFile = $dir.$2; # destination-file |
|
334 |
print"found alias keyword\n" if ($verboseOpt); |
|
335 |
if(!copy($exFile,$destFile)) |
|
336 |
{ |
|
337 |
&datadriveimage::reportError("* warning : couldnt create alias of $1 to $2 ",$keepgoingOpt); |
|
338 |
} |
|
339 |
else |
|
340 |
{ |
|
341 |
# push the line on to the stack. |
|
342 |
push(@$aliasArray,$1."\t".$2."\n"); |
|
343 |
} |
|
344 |
} |
|
345 |
elsif($line =~ /^hide\s+(\S+)/i) |
|
346 |
{ |
|
347 |
print"found hide keyword\n" if ($verboseOpt); |
|
348 |
print "$1 is marked as hidden, hence will not be part of the image\n" if($verboseOpt); |
|
349 |
if( unlink($dir.$1) ) |
|
350 |
{ |
|
351 |
# push the line on to the stack. |
|
352 |
push(@$hideArray,$1); |
|
353 |
} |
|
354 |
else |
|
355 |
{ |
|
356 |
&datadriveimage::reportError("* Warning : Can't delete $1: $! ",$keepgoingOpt); |
|
357 |
} |
|
358 |
} |
|
359 |
} |
|
360 |
close(OBEY); |
|
361 |
} |
|
362 |
||
363 |
# invoke the INTERPRETSIS tool with appropriate parameters. |
|
364 |
sub invokeInterpretsis |
|
365 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
366 |
my($sisFileArray,$dataDrivePath,$verboseOpt,$zDrivePath,$parafile,$keepgoingOpt,$interpretsisOptList,$outputdir) = @_; |
606 | 367 |
my $sisfile = ""; |
368 |
# default system drive letter is specified since interpretsis doesnt allow overloading of options unless default |
|
369 |
# options are specified. |
|
370 |
my $basicOption = "-d C: "; # default system drive letter |
|
371 |
my $command = "interpretsis "; |
|
372 |
my $vOption = "-w info" if ($verboseOpt); |
|
373 |
||
374 |
is_existinpath("interpretsis", romutl::DIE_NOT_FOUND); |
|
375 |
||
376 |
# do a check if the path has a white space. |
|
377 |
if( $dataDrivePath =~ m/ /) |
|
378 |
{ |
|
379 |
$dataDrivePath = '"'.$dataDrivePath.'"'; |
|
380 |
} |
|
381 |
||
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
382 |
my $currentdir=cwd; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
383 |
$currentdir=~s-\\-\/-go; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
384 |
$currentdir.= "\/" unless $currentdir =~ /\/$/; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
385 |
$currentdir =~ s-\/-\\-g if (&is_windows); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
386 |
my $drive = ""; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
387 |
$drive = $1 if ($currentdir =~ /^(.:)/); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
388 |
|
606 | 389 |
# find out size of the array |
390 |
my $sisarraysize = scalar(@$sisFileArray); |
|
391 |
for( my $i=0; $i<$sisarraysize; $i++ ) |
|
392 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
393 |
my $tempsisfile = pop(@$sisFileArray); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
394 |
if ($tempsisfile =~ /^[\\\/]/) |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
395 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
396 |
$tempsisfile = $drive.$tempsisfile; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
397 |
}elsif ($tempsisfile !~ /^.:/) |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
398 |
{ |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
399 |
$tempsisfile = $currentdir.$tempsisfile; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
400 |
} |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
401 |
|
606 | 402 |
if($sisfile ne "") |
403 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
404 |
$sisfile = $tempsisfile.",".$sisfile; |
606 | 405 |
} |
406 |
else |
|
407 |
{ |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
408 |
$sisfile = $tempsisfile; |
606 | 409 |
} |
410 |
} |
|
411 |
||
412 |
# check whether the directory exists or not |
|
413 |
if( -d $zDrivePath ) |
|
414 |
{ |
|
415 |
# do a check if the path has a white space. |
|
416 |
if( $zDrivePath =~ m/ /) |
|
417 |
{ |
|
418 |
$zDrivePath = '"'.$zDrivePath.'"'; |
|
419 |
} |
|
420 |
$basicOption .= "-z $zDrivePath "; |
|
421 |
} |
|
422 |
||
423 |
$basicOption .= "-c $dataDrivePath -s $sisfile $vOption"; |
|
424 |
||
425 |
# if parameter file is specified then invoke the INTERPRETSIS |
|
426 |
# with the specified parameter file with "-p" option. |
|
427 |
if( defined($parafile) ) |
|
428 |
{ |
|
429 |
# do a check if the path has a white space. |
|
430 |
if( $parafile =~ m/ /) |
|
431 |
{ |
|
432 |
$parafile = '"'.$parafile.'"'; |
|
433 |
} |
|
434 |
$command .= "-p $parafile "; |
|
435 |
} |
|
436 |
# else invoke the INTERPRETSIS with default parameter file with "-p" option. |
|
437 |
else |
|
438 |
{ |
|
439 |
# Truncate and open the parameter file for writing.. |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
440 |
$parafile = $outputdir."parameterfile.txt"; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
441 |
open( OPTDATA, "> $parafile" ) or die "can't open $parafile"; |
606 | 442 |
print OPTDATA $basicOption."\n"; |
443 |
close( OPTDATA ); |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
444 |
$command .= "-p $parafile "; |
606 | 445 |
} |
446 |
||
447 |
if( $interpretsisOptList ) |
|
448 |
{ |
|
449 |
# find out size of the array |
|
450 |
my $arraysize = scalar( @$interpretsisOptList ); |
|
451 |
for( my $i = 0; $i < $arraysize; $i++ ) |
|
452 |
{ |
|
453 |
$command .= $$interpretsisOptList[$i]." "; |
|
454 |
} |
|
455 |
} |
|
456 |
||
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
457 |
print "* Changing to $outputdir\n" if ( $verboseOpt ); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
458 |
chdir "$outputdir"; |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
459 |
|
606 | 460 |
print "* Executing $command\n" if ( $verboseOpt ); |
461 |
system ( $command ); |
|
462 |
||
463 |
if ($? != 0) |
|
464 |
{ |
|
465 |
&datadriveimage::reportError("* ERROR: INTERPRETSIS failed",$keepgoingOpt); |
|
466 |
} |
|
626
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
467 |
|
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
468 |
print "* Changing back to $currentdir\n" if ( $verboseOpt ); |
ac03b93ca9c4
ROM Tools 12.3.4 + RCOMP 8.4.2
Zheng Shen <zheng.shen@nokia.com>
parents:
607
diff
changeset
|
469 |
chdir "$currentdir"; |
606 | 470 |
} |
471 |
||
472 |
# invoke the READIMAGE tool with appropriate parameters. |
|
473 |
sub invokeReadImage |
|
474 |
{ |
|
475 |
my($imageName,$loc,$verboseOpt,$logFile,$keepgoingOpt) = @_; |
|
476 |
my $command = "readimage "; |
|
477 |
||
478 |
is_existinpath("readimage", romutl::DIE_NOT_FOUND); |
|
479 |
||
480 |
# check if log file has been supplied. |
|
481 |
if(defined($logFile)) |
|
482 |
{ |
|
483 |
if( $logFile =~ m/ /) |
|
484 |
{ |
|
485 |
$logFile = '"'.$logFile.'"'; |
|
486 |
} |
|
487 |
$command .= "-l $logFile "; |
|
488 |
} |
|
489 |
||
490 |
# do a check if the path has a white space. |
|
491 |
if( $loc =~ m/ /) |
|
492 |
{ |
|
493 |
$loc = '"'.$loc.'"'; |
|
494 |
} |
|
495 |
$command .= "-z ".$loc." ".$imageName; |
|
496 |
print "* Executing $command\n" if ($verboseOpt); |
|
497 |
system ($command); |
|
498 |
if ($? != 0) |
|
499 |
{ |
|
500 |
&datadriveimage::reportError("* ERROR: READIMAGE failed to read the image",$keepgoingOpt); |
|
501 |
return 0; |
|
502 |
} |
|
503 |
return 1; |
|
504 |
} |
|
505 |
||
506 |
# Each line from the OBY file is read and if any of the line contains "rename"/ "alias" keyword |
|
507 |
# then that corresponding line source and line destination is obtained and is passed to this function as one of the parameters. |
|
508 |
# This fuction compares given array with non-sis file(s) array, when an given line destination matches with the destination of an |
|
509 |
# element in the rename array/alias array(array holding list of file(s) that are renamed / made alias) then, |
|
510 |
# that respective element is removed from the rename array and a further check is made to see whether the given |
|
511 |
# line source matches with the destination of an element in the rename array/alias array.If a match is found then |
|
512 |
# a keyword check is done,if the keyword is "rename" then corresponding element's source and destination file is replaced |
|
513 |
# with given line destination file and if the keyword is "alias" then a new element will be added to non sis file array |
|
514 |
# with line destination file as the source and destination file. |
|
515 |
sub compareArrays |
|
516 |
{ |
|
517 |
my ( $firstarray,$nonsisArray,$linesource,$linedest,$linekeyword ) = @_; |
|
518 |
# count of array element(s). |
|
519 |
my $firstArrayCount = 0; |
|
520 |
# source file. |
|
521 |
my $linesourceFile; |
|
522 |
# destination file. |
|
523 |
my $linedestFile; |
|
524 |
# get source file. |
|
525 |
||
526 |
# strip first occurrence of back slash |
|
527 |
$linesource =~ s/[\/\\]//; |
|
528 |
||
529 |
# get source file. |
|
530 |
if ($linesource =~ /.*[\/\\](\S+)/ ) |
|
531 |
{ |
|
532 |
$linesourceFile = $1; |
|
533 |
} |
|
534 |
# get destination file. |
|
535 |
if ($linedest =~ /.*[\/\\](\S+)/ ) |
|
536 |
{ |
|
537 |
$linedestFile = $1; |
|
538 |
} |
|
539 |
# iterate trough all |
|
540 |
foreach my $firstarrayEntry (@$firstarray) |
|
541 |
{ |
|
542 |
if( $firstarrayEntry =~ /(\S+)\s+(\S+)/ ) |
|
543 |
{ |
|
544 |
my $firstarrayEntrydest = $2; |
|
545 |
||
546 |
if( $linedest eq $firstarrayEntrydest ) |
|
547 |
{ |
|
548 |
# remove the specified element from the array. |
|
549 |
splice(@$firstarray,$firstArrayCount,1); |
|
550 |
# initialize the nonsisFileListCount to zero. |
|
551 |
my $nonsisFileListCount = 0; |
|
552 |
foreach my $nonsisEntry ( @$nonsisArray ) |
|
553 |
{ |
|
554 |
if( $nonsisEntry =~ /^(\S+)=(\S+)\s+(\S+)/ ) |
|
555 |
{ |
|
556 |
my $nonsisEntryDest = $3; |
|
557 |
# remove double quotes. |
|
558 |
$nonsisEntryDest =~ s/\"//g; |
|
559 |
my $nonsisEntryDestFile; |
|
560 |
if ($nonsisEntryDest =~ /.*[\/\\](\S+)/ ) |
|
561 |
{ |
|
562 |
$nonsisEntryDestFile = $1; |
|
563 |
} |
|
564 |
if( $nonsisEntryDest eq $linesource ) |
|
565 |
{ |
|
566 |
if($linekeyword eq "rename") |
|
567 |
{ |
|
568 |
# remove the specified element from the array. |
|
569 |
splice(@$nonsisArray,$nonsisFileListCount,1); |
|
570 |
$nonsisEntry =~ s/$nonsisEntryDestFile/$linedestFile/g; |
|
571 |
push(@$nonsisArray,$nonsisEntry); |
|
572 |
} |
|
573 |
elsif($linekeyword eq "alias") |
|
574 |
{ |
|
575 |
my $newLine = $nonsisEntry; |
|
576 |
$newLine =~ s/$nonsisEntryDestFile/$linedestFile/g; |
|
577 |
push(@$nonsisArray,$newLine); |
|
578 |
} |
|
579 |
} |
|
580 |
} |
|
581 |
$nonsisFileListCount++; |
|
582 |
}#end of loop foreach my $newLine ( @nonsisArray ) |
|
583 |
} |
|
584 |
$firstArrayCount++; |
|
585 |
}#end of loop foreach my $newLine ( @firstarray) |
|
586 |
} |
|
587 |
} |
|
588 |
||
589 |
# Traverse the entire directory and log the folder contents on to a file. |
|
590 |
sub dumpDatadriveObydata |
|
591 |
{ |
|
592 |
#assign a temporary name and extension to the new oby file. |
|
593 |
my $newobyfile = "temp.$$"; |
|
594 |
my ($datadir,$oldobyfile,$size,$nonsisFileArray,$renameArray,$aliasArray, |
|
595 |
$hideArray,$sisobyArray,$datadriveArray,$keepgoingOpt,$verboseOpt) = @_; |
|
596 |
# get the working directory. |
|
597 |
my $curWorkingDir = getcwd; |
|
598 |
# traverse the updated data drive directory structure. |
|
599 |
&TraverseDir($datadir,"",$sisobyArray,$datadir); |
|
600 |
# change the directrory to the Working directory. |
|
601 |
chdir($curWorkingDir); |
|
602 |
# copy non-sis file(s) on to prototype data drive folder. |
|
603 |
copyNonSisFiles($datadir,$oldobyfile,$nonsisFileArray,$renameArray,$aliasArray,$hideArray,$verboseOpt,$keepgoingOpt); |
|
604 |
#open the oby file in read-only mode. |
|
605 |
open (OLDDATA, "< $oldobyfile") or die("* Can't open $oldobyfile\n"); |
|
606 |
# Truncate and open the new oby file for writing.. |
|
607 |
open(NEWDATA, "> $newobyfile") or die "can't open $newobyfile"; |
|
608 |
while (my $line =<OLDDATA>) |
|
609 |
{ |
|
610 |
if( $line =~ /^hide\s+(\S+)/i) |
|
611 |
{ |
|
612 |
my $lineToSearch = $1; |
|
613 |
my $hideListCount = 0; |
|
614 |
foreach my $newLine ( @$hideArray ) |
|
615 |
{ |
|
616 |
if( $newLine eq $lineToSearch ) |
|
617 |
{ |
|
618 |
splice(@$hideArray,$hideListCount,1); |
|
619 |
my $nonsisFileListCount = 0; |
|
620 |
foreach my $newLine ( @$nonsisFileArray ) |
|
621 |
{ |
|
622 |
if( $newLine =~ /^(\S+)=(\S+)\s+(\S+)/ ) |
|
623 |
{ |
|
624 |
my $newLineKeyword = $1; |
|
625 |
my $newLinesource = $2; |
|
626 |
my $newLinedest = $3; |
|
627 |
$newLinedest =~ s/\"//g; |
|
628 |
$newLinedest = "\/".$newLinedest; |
|
629 |
if( $newLinedest eq $lineToSearch ) |
|
630 |
{ |
|
631 |
# remove the specified element from the array. |
|
632 |
splice(@$nonsisFileArray,$nonsisFileListCount,1); |
|
633 |
} |
|
634 |
} |
|
635 |
# increment the non sis file list count. |
|
636 |
$nonsisFileListCount++; |
|
637 |
} |
|
638 |
} |
|
639 |
# increment the hide file list count. |
|
640 |
$hideListCount++; |
|
641 |
} |
|
642 |
} |
|
643 |
elsif( $line =~ /^rename\s+(\S+)\s+(\S+)/i) |
|
644 |
{ |
|
645 |
my $linesource = $1 ; |
|
646 |
my $linedest = $2; |
|
647 |
my $linekeyword = "rename"; |
|
648 |
&compareArrays($renameArray,$nonsisFileArray,$linesource,$linedest,$linekeyword); |
|
649 |
} |
|
650 |
elsif( $line =~ /^alias\s+(\S+)\s+(\S+)/i ) |
|
651 |
{ |
|
652 |
my $linesource = $1 ; |
|
653 |
my $linedest = $2; |
|
654 |
my $linekeyword = "alias"; |
|
655 |
&compareArrays($aliasArray,$nonsisFileArray,$linesource,$linedest,$linekeyword); |
|
656 |
} |
|
657 |
elsif( $line =~ /^(file|data)\s*=\s*/i || $line =~ /^\s*(zdriveimagename|sisfile)\s*=\s*/i ) |
|
658 |
{ |
|
659 |
# skip to next line. |
|
660 |
next; |
|
661 |
} |
|
662 |
else |
|
663 |
{ |
|
664 |
# push it on to the array. |
|
665 |
unshift(@$datadriveArray,$line); |
|
666 |
} |
|
667 |
next; |
|
668 |
} |
|
669 |
# close the old oby files. |
|
670 |
close(OLDDATA)or die "can't close $oldobyfile"; |
|
671 |
#write the array contents on to the file |
|
672 |
print"* Updating $oldobyfile - final OBY file\n"; |
|
673 |
&writeDataToFile( $datadriveArray ); |
|
674 |
&writeDataToFile( $sisobyArray ); |
|
675 |
&writeDataToFile( $nonsisFileArray ); |
|
676 |
# close the new oby file. |
|
677 |
close(NEWDATA)or die "can't close $newobyfile"; |
|
678 |
#rename the file. |
|
679 |
rename( $newobyfile, $oldobyfile )or die "can't rename $newobyfile to $oldobyfile: $!"; |
|
680 |
} |
|
681 |
||
682 |
||
683 |
# Traverse the entire given directory |
|
684 |
# push all the folder contents on to an array. |
|
685 |
sub TraverseDir |
|
686 |
{ |
|
687 |
my($dir,$folderList,$sisFileContent,$rootdir) = @_; |
|
688 |
#check the specified directory |
|
689 |
chdir($dir) || die "Cannot chdir to $dir\n"; |
|
690 |
local(*DIR); |
|
691 |
opendir(DIR, ".");#open current directory. |
|
692 |
my $sourcedir; |
|
693 |
my $destdir; |
|
694 |
while (my $entry=readdir(DIR)) |
|
695 |
{ |
|
696 |
#skip, parent directory and current directory. |
|
697 |
next if ($entry eq "." || $entry eq ".."); |
|
698 |
#check if it is a file |
|
699 |
if( -f $entry ) |
|
700 |
{ |
|
701 |
my $sourcedir = $rootdir."\/".$folderList.$entry; |
|
702 |
my $destdir = "$folderList".$entry; |
|
703 |
my $sisSource; |
|
704 |
my $sisdestination; |
|
705 |
if(&checkRegCtlFiles($entry)) |
|
706 |
{ |
|
707 |
# check for any whitespace |
|
708 |
if($sourcedir =~ m/ /) |
|
709 |
{ |
|
710 |
# if yes, then append double quotes |
|
711 |
$sisSource = "data="."\"".$sourcedir."\""; |
|
712 |
} |
|
713 |
else |
|
714 |
{ |
|
715 |
# else dont append any double quotes for destination |
|
716 |
$sisSource = "data=".$sourcedir; |
|
717 |
} |
|
718 |
# push the line on to the array. |
|
719 |
push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"'); |
|
720 |
} |
|
721 |
else |
|
722 |
{ |
|
723 |
# check for any white space |
|
724 |
if($sourcedir =~ m/ /) |
|
725 |
{ |
|
726 |
# if yes, then append double quotes |
|
727 |
$sisSource = "file="."\"".$sourcedir."\""; |
|
728 |
} |
|
729 |
else |
|
730 |
{ |
|
731 |
# else dont append any double quotes for destination |
|
732 |
$sisSource = "file=".$sourcedir; |
|
733 |
} |
|
734 |
# push the line on to the array. |
|
735 |
push(@$sisFileContent,$sisSource."\t".'"'.$destdir.'"'); |
|
736 |
} |
|
737 |
} |
|
738 |
#else it's a directory |
|
739 |
else |
|
740 |
{ |
|
741 |
&TraverseDir($entry,$folderList.$entry."\/",$sisFileContent,$rootdir); |
|
742 |
} |
|
743 |
} |
|
744 |
closedir(DIR); |
|
745 |
chdir(".."); |
|
746 |
} |
|
747 |
||
748 |
# write the data in to oby file by accessing appropriate array. |
|
749 |
sub writeDataToFile |
|
750 |
{ |
|
751 |
my ($array) = @_; |
|
752 |
#get the array size. |
|
753 |
my $arraySize = scalar(@$array); |
|
754 |
for(my $i=0; $i<$arraySize ; $i++ ) |
|
755 |
{ |
|
756 |
#pop out the element to the respective obey file. |
|
757 |
my $line=pop(@$array); |
|
758 |
if (&is_windows){ |
|
759 |
$line =~ s-\/-\\-g; |
|
760 |
}else{ |
|
761 |
$line =~ s-\\-\/-g; |
|
762 |
} |
|
763 |
print NEWDATA $line."\n"; |
|
764 |
} |
|
765 |
} |