|
1 #!perl |
|
2 # |
|
3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 # All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of the License "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Nokia Corporation - initial contribution. |
|
12 # |
|
13 # Contributors: |
|
14 # |
|
15 # Description: |
|
16 # |
|
17 |
|
18 # rom.pl - Build a rom |
|
19 # |
|
20 # Pre-processes the .oby/iby files then invokes rombuild.exe |
|
21 # (or other specified builder) |
|
22 |
|
23 # First, read our config file |
|
24 |
|
25 use strict; |
|
26 use Getopt::Long; |
|
27 use Cwd; |
|
28 |
|
29 #Getopt::Long::Configure("ignore_case"); |
|
30 my %opts=(); |
|
31 my $param_count = scalar(@ARGV); |
|
32 my $result = GetOptions (\%opts, "assp=s", |
|
33 "inst=s", |
|
34 "type=s", |
|
35 "variant=s", |
|
36 "build=s", |
|
37 "conf=s", |
|
38 "name=s", |
|
39 "modules=s", |
|
40 "xabi=s", |
|
41 "clean", |
|
42 "quiet", |
|
43 "help", |
|
44 "_debug", |
|
45 "zip", |
|
46 "symbol", |
|
47 "noheader", |
|
48 "kerneltrace=s", |
|
49 "rombuilder=s", |
|
50 "define=s@", |
|
51 "rofsbuilder=s", |
|
52 "compress", |
|
53 ); |
|
54 |
|
55 my (@assps, @builds, %variants, @templates, %flags, %insts, %zip, %builder); |
|
56 my $main; |
|
57 my $kmain; |
|
58 my $toroot; |
|
59 my $e32path; |
|
60 my $rombuildpath; |
|
61 my $euserdir; |
|
62 my $elocldir; |
|
63 my $kbdir; |
|
64 my $romname; |
|
65 my $single; |
|
66 my $smain; |
|
67 my $pagedCode; |
|
68 my $debug = $opts{_debug}; |
|
69 my $quiet; |
|
70 $quiet = $opts{quiet} unless $debug; |
|
71 |
|
72 my $drive; |
|
73 |
|
74 # discover where this script is running from to set the $toroot and $e32path variables |
|
75 |
|
76 my $toolpath; |
|
77 my $Epoc32Path; |
|
78 my $EpocRoot; |
|
79 my $drive; |
|
80 my $BasePath; |
|
81 |
|
82 BEGIN { |
|
83 |
|
84 $EpocRoot = $ENV{EPOCROOT}; |
|
85 die "ERROR: Must set the EPOCROOT environment variable.\n" if (!defined($EpocRoot)); |
|
86 print "Environmental epocroot - >$EpocRoot<\n"; |
|
87 $EpocRoot =~ s-/-\\-go; # for those working with UNIX shells |
|
88 if ($EpocRoot =~ /^([a-z]:)(.*)$/i) |
|
89 { |
|
90 # Raptor style: Drive letter and trailing \\ removed |
|
91 $drive = $1; |
|
92 $EpocRoot = "$2\\"; |
|
93 $ENV{EPOCROOT} = $EpocRoot; |
|
94 } |
|
95 die "ERROR: EPOCROOT must be an absolute path, " . |
|
96 "not containing a drive letter.\n" if ($EpocRoot !~ /^\\/); |
|
97 die "ERROR: EPOCROOT must not be a UNC path.\n" if ($EpocRoot =~ /^\\\\/); |
|
98 die "ERROR: EPOCROOT must end with a backslash.\n" if ($EpocRoot !~ /\\$/); |
|
99 die "ERROR: EPOCROOT must specify an existing directory.\n" if (!-d $EpocRoot); |
|
100 |
|
101 # The cpp needed a drive apparently |
|
102 my $cwd = Cwd::cwd(); |
|
103 $cwd =~ /^(.)/; |
|
104 $drive = "$1:" unless $drive; |
|
105 print "epocroot = >$EpocRoot<\n"; |
|
106 print "drive = >$drive<\n"; |
|
107 |
|
108 my $fp0 = $0; |
|
109 $cwd =~ s/\//\\/g; |
|
110 $fp0 =~ s/\//\\/g; |
|
111 unless ($fp0 =~ /^([A-Za-z]:)?\\/) { |
|
112 if ($cwd =~ /\\$/) { |
|
113 $fp0 = "$cwd$fp0"; |
|
114 } else { |
|
115 $fp0 = "$cwd\\$fp0"; |
|
116 } |
|
117 } |
|
118 |
|
119 my @path = split(/\\/, $cwd); |
|
120 shift(@path); |
|
121 $toroot = ('..\\') x @path; |
|
122 $toroot =~ s/\\$//; |
|
123 #e32path supposed to be = to "\sf\os" |
|
124 $e32path = $fp0; |
|
125 $e32path =~ s/\\kernelhwsrv\\kernel\\eka\\rombuild\\rom_sbs\.pl$//i; |
|
126 $e32path =~ s/^[A-Za-z]://; |
|
127 $rombuildpath = $toroot."\\sf\\os\\kernelhwsrv\\kernel\\eka\\rombuild"; |
|
128 $Epoc32Path = $toroot; |
|
129 $Epoc32Path =~ s/\\$//; |
|
130 $Epoc32Path .= $EpocRoot . "epoc32"; |
|
131 $toolpath = "$Epoc32Path\\tools\\"; |
|
132 push @INC, $toolpath; |
|
133 $BasePath = $toroot . $e32path."\\"; |
|
134 } |
|
135 |
|
136 use E32Plat; |
|
137 { |
|
138 Plat_Init($toolpath); |
|
139 } |
|
140 |
|
141 if ($debug) { |
|
142 print "EpocRoot = $EpocRoot\n"; |
|
143 print "Epoc32Path = $Epoc32Path\n"; |
|
144 print "drive = $drive\n"; |
|
145 print "toolpath = $toolpath\n"; |
|
146 print "toroot = $toroot\n"; |
|
147 print "e32path = $e32path\n"; |
|
148 print "rombuildpath = $rombuildpath\n"; |
|
149 print "BasePath = $BasePath\n"; |
|
150 } |
|
151 |
|
152 my $cppflags="-P -undef -traditional -lang-c++ -nostdinc -iwithprefixbefore $rombuildpath -I $rombuildpath -I $drive$Epoc32Path "; |
|
153 |
|
154 # Include variant hrh file defines when processing oby and ibys with cpp |
|
155 # (Code copied from \\EPOC\master\cedar\generic\tools\romkit\tools\buildrom.pm - |
|
156 # it used relative path to the working dir but we are using absolute path seems neater) |
|
157 use E32Variant; |
|
158 use Pathutl; |
|
159 my $variantMacroHRHFile = Variant_GetMacroHRHFile(); |
|
160 if($variantMacroHRHFile){ |
|
161 # Using absolute paths so must include drive letter otherwise cpp will fail |
|
162 # Also adding the directory containing the HRH file to main includes paths in |
|
163 # case it includes files |
|
164 my $variantFilePath = Path_Split('Path',$variantMacroHRHFile); |
|
165 $cppflags .= " -I $drive$variantFilePath -include $drive$variantMacroHRHFile"; |
|
166 } |
|
167 |
|
168 if($param_count == 0 || $opts{'help'} || !$result) { |
|
169 usage(); |
|
170 exit 0; |
|
171 } |
|
172 |
|
173 # Now check that the options we have make sense |
|
174 |
|
175 checkopts(); |
|
176 |
|
177 if (!$quiet) { |
|
178 print "Starting directory: ", Cwd::cwd(), "\n"; |
|
179 print <<EOF; |
|
180 OPTIONS: |
|
181 \tTYPE: $opts{'type'} |
|
182 \tVARIANT: $opts{'variant'} |
|
183 \tINSTRUCTION SET: $opts{'inst'} |
|
184 \tBUILD: $opts{'build'} |
|
185 \tMODULES: $opts{'modules'} |
|
186 EOF |
|
187 } |
|
188 |
|
189 #Pick out the type file |
|
190 my $skel; |
|
191 |
|
192 if (-e "$opts{'type'}.oby") { |
|
193 $skel="$opts{'type'}.oby"; |
|
194 } elsif (-e "$rombuildpath\\$opts{'type'}.oby") { |
|
195 $skel="$rombuildpath\\$opts{'type'}.oby"; |
|
196 } else { |
|
197 die "Can't find type file for type $opts{'type'}, $!"; |
|
198 } |
|
199 |
|
200 print "Using type file $skel\n" if !$quiet; |
|
201 |
|
202 # If clean is specified, zap all the image and .oby files |
|
203 |
|
204 if($opts{'clean'}) { |
|
205 unlink glob("*.img"); |
|
206 unlink "rom.oby"; |
|
207 unlink "rombuild.log"; |
|
208 unlink glob("*.rofs"); |
|
209 unlink "rofsbuild.log"; |
|
210 } |
|
211 |
|
212 # Now pre-pre-process this file to point to the right places for .ibys |
|
213 # Unfortunately cpp won't do macro replacement in #include strings, so |
|
214 # we have to do it by hand |
|
215 |
|
216 my $k = $opts{kerneltrace}; |
|
217 |
|
218 if ($opts{assp}=~/^m(\S+)/i) { |
|
219 $kbdir="kb$1"; |
|
220 $kbdir="kbarm" if (lc $1 eq 'eig'); |
|
221 } else { |
|
222 $kbdir="kb$opts{assp}"; |
|
223 } |
|
224 $single=1 if ($opts{assp}=~/^s(\S+)/i); |
|
225 |
|
226 if ($single) { |
|
227 # Hackery to cope with old compiler |
|
228 if ($main eq 'MARM') { |
|
229 $smain='SARM'; |
|
230 } else { |
|
231 $smain="S$main"; |
|
232 } |
|
233 } else { |
|
234 $smain=$main; |
|
235 } |
|
236 |
|
237 open(X, "$skel") || die "Can't open type file $skel, $!"; |
|
238 open(OUT, "> rom1.tmp") || die "Can't open output file, $!"; |
|
239 |
|
240 # First output the ROM name |
|
241 print OUT "\nromname=$romname\n"; |
|
242 # Go through the iby file passed as parameter of this script and replace flags by proper values before copying the line in rom1.tmp. |
|
243 while(<X>) { |
|
244 s/\#\#ASSP\#\#/$opts{'assp'}/; |
|
245 s/\#\#VARIANT\#\#/$opts{'variant'}/; |
|
246 s/\#\#BUILD\#\#/$opts{'build'}/; |
|
247 s/\#\#MAIN\#\#/$main/; |
|
248 s/\#\#KMAIN\#\#/$kmain/; |
|
249 s/\#\#E32PATH\#\#/$e32path/; |
|
250 s/\#\#BASEPATH\#\#/$BasePath/; |
|
251 s/\#\#EUSERDIR\#\#/$euserdir/; |
|
252 s/\#\#ELOCLDIR\#\#/$elocldir/; |
|
253 s/\#\#KBDIR\#\#/$kbdir/; |
|
254 print OUT; |
|
255 } |
|
256 |
|
257 close X; |
|
258 close OUT; |
|
259 |
|
260 # Use cpp to pull in include chains and replace defines |
|
261 |
|
262 my $defines = ""; |
|
263 $defines .= "-D MAIN=$main "; |
|
264 $defines .= "-D KMAIN=$kmain "; |
|
265 $defines .= "-D EUSERDIR=$euserdir "; |
|
266 $defines .= "-D ELOCLDIR=$elocldir "; |
|
267 $defines .= "-D E32PATH=$e32path "; |
|
268 $defines .= "-D BASEPATH=$BasePath "; |
|
269 $defines .= "-D EPOCROOT=$EpocRoot "; |
|
270 $defines .= "-D SMAIN=$smain " if $smain; |
|
271 |
|
272 foreach (@{$opts{'define'}}) { |
|
273 my @array=split(/,/,$_); |
|
274 foreach (@array) { |
|
275 $defines.="-D ".uc $_." "; |
|
276 $pagedCode = 1 if $_ eq 'PAGED_CODE'; |
|
277 } |
|
278 } |
|
279 |
|
280 if ($opts{'modules'}) { |
|
281 my @array=split(/,/,$opts{'modules'}); |
|
282 foreach (@array) { |
|
283 $defines.="-D ".uc $_." "; |
|
284 } |
|
285 } |
|
286 |
|
287 foreach (keys %opts) { |
|
288 next if ($_ eq 'name'); |
|
289 next if ($_ eq 'modules'); |
|
290 next if ($_ eq 'zip'); |
|
291 next if ($_ eq 'symbol'); |
|
292 next if ($_ eq 'kerneltrace'); |
|
293 next if ($_ eq 'define'); |
|
294 $defines.="-D ".uc $_."=".$opts{$_}." "; |
|
295 $defines.="-D ".uc $_."_".$opts{$_}." "; |
|
296 } |
|
297 |
|
298 $defines.="-D SINGLE " if ($single); |
|
299 |
|
300 sub IsRVCTBuild($) { |
|
301 my ($build)=@_; |
|
302 return 1 if ($build =~ /^ARMV/i); |
|
303 my @customizations = Plat_Customizations('ARMV5'); |
|
304 return 1 if (grep /$build/, @customizations); |
|
305 return 0; |
|
306 } |
|
307 |
|
308 $defines.="-D RVCT " if (IsRVCTBuild($main)); |
|
309 |
|
310 print "Using defines $defines\n" if !$quiet; |
|
311 |
|
312 my $ret=1; |
|
313 my $cppcmd; |
|
314 if($opts{'build'}=~/^u/i) { |
|
315 # Unicode build |
|
316 $cppcmd = "$Epoc32Path/gcc/bin/cpp $cppflags -D UNICODE $defines rom1.tmp rom2.tmp"; |
|
317 } else { |
|
318 $cppcmd = "$Epoc32Path/gcc/bin/cpp $cppflags $defines rom1.tmp rom2.tmp"; |
|
319 } |
|
320 print "Executing CPP:\n\t$cppcmd\n" if $debug; |
|
321 $ret = system($cppcmd); |
|
322 die "ERROR EXECUTING CPP\n" if $ret; |
|
323 |
|
324 # Zap any ## marks REMS or blank lines |
|
325 |
|
326 cleanup("rom2.tmp", "rom3.tmp", $k); |
|
327 |
|
328 # scan tmp file and generate auxiliary files, if required |
|
329 open TMP, "rom3.tmp" or die("Can't open rom3.tmp\n"); |
|
330 my $line; |
|
331 while ($line=<TMP>) |
|
332 { |
|
333 if ($line=~/\s*gentestpaged/i) { |
|
334 genfile("paged"); } |
|
335 if ($line=~/\s*gentestnonpaged/i) { |
|
336 genfile("nonpaged"); } |
|
337 } |
|
338 |
|
339 parsePatchData("rom3.tmp", "rom4.tmp"); |
|
340 |
|
341 # break down the oby file into rom, rofs and extensions oby files |
|
342 |
|
343 my $oby_index =0; |
|
344 my $dumpfile="rom.oby"; |
|
345 my $rofs=0; |
|
346 my $extension=0; |
|
347 my $corerofsname=""; |
|
348 open DUMPFILE, ">$dumpfile" or die("Can't create $dumpfile\n"); |
|
349 my $line; |
|
350 open TMP, "rom4.tmp" or die("Can't open rom4.tmp\n"); |
|
351 while ($line=<TMP>) |
|
352 { |
|
353 if ($line=~/^\s*rofsname/i) |
|
354 { |
|
355 close DUMPFILE; # close rom.oby or previous rofs#/extension#.oby |
|
356 $oby_index=1; |
|
357 $corerofsname=$line; |
|
358 $corerofsname =~ s/rofsname\s*=\s*//i; # save core rofs name |
|
359 $corerofsname =~ s/\s*$//g; # remove trailing \n |
|
360 unlink $corerofsname || print "unable to delete $corerofsname"; |
|
361 my $dumpfile="rofs".$rofs.".oby"; |
|
362 $rofs++; |
|
363 open DUMPFILE, ">$dumpfile" or (close TMP and die("Can't create $dumpfile\n")); |
|
364 } |
|
365 |
|
366 if ($line=~/^\s*coreimage/i) |
|
367 { |
|
368 close DUMPFILE; # close rofs.oby |
|
369 if ($oby_index ne 1) { |
|
370 close TMP; |
|
371 die "Must specify ROFS image before ROFS extension\n"; |
|
372 } |
|
373 my $name=$line; |
|
374 $name =~ s/coreimage\s*=\s*//i; # read core rofs name |
|
375 $name =~ s/\s*$//g; # remove trailing \n |
|
376 if ($name ne $corerofsname) { |
|
377 close TMP; |
|
378 die "This extension does not relate to previous ROFS\n"; |
|
379 } |
|
380 $oby_index=33; # open window |
|
381 my $dumpfile="extension".$extension.".oby"; |
|
382 $extension++; |
|
383 open DUMPFILE, ">$dumpfile" or (close TMP and die("Can't create $dumpfile\n")); |
|
384 } |
|
385 |
|
386 if ($line=~/^\s*extensionrofs/i) |
|
387 { |
|
388 $oby_index=3 if ($oby_index eq 2); |
|
389 } |
|
390 |
|
391 if (($oby_index eq 2) && !($line=~/^\s*$/)) { |
|
392 close TMP; |
|
393 die "Bad ROFS extension specification\n"; |
|
394 } |
|
395 print DUMPFILE $line; |
|
396 $oby_index=2 if ($oby_index eq 33); # close window |
|
397 } |
|
398 close DUMPFILE; |
|
399 close TMP; |
|
400 |
|
401 # For paged roms that use rofs, move all data= lines in rom which are not 'paging_unmovable' to rofs, so that paged ram-loaded code |
|
402 # is automatically put into rofs |
|
403 rename('rom.oby', 'rom4.tmp') || die; |
|
404 |
|
405 open(IN, 'rom4.tmp') || die "Can't read rom4.tmp"; |
|
406 open(ROM, '>rom.oby') || die "Can't write to rom.oby"; |
|
407 |
|
408 if ($oby_index >= 1 && $pagedCode) { |
|
409 open(ROFS, '>>rofs0.oby') || die "Can't append to rofs0.oby"; |
|
410 } |
|
411 |
|
412 while ($line=<IN>) |
|
413 { |
|
414 if(($oby_index >= 1) && ($pagedCode) && ($line=~/^\s*data\s*=/) && !($line=~/\.*paging_unmovable\s*/)) { |
|
415 print ROFS $line; |
|
416 } |
|
417 else { |
|
418 $line=~s/paging_unmovable//; |
|
419 print ROM $line; |
|
420 } |
|
421 } |
|
422 |
|
423 close IN; |
|
424 close ROM; |
|
425 |
|
426 if ($oby_index >= 1 && $pagedCode) { |
|
427 close ROFS; |
|
428 } |
|
429 unlink 'rom4.tmp'; |
|
430 |
|
431 my $flags; |
|
432 |
|
433 foreach (@{$flags{$opts{'assp'}}}) { |
|
434 $flags.=" -$_"; |
|
435 } |
|
436 |
|
437 if($opts{'noheader'}) { |
|
438 $flags.=" -no-header"; |
|
439 } |
|
440 |
|
441 if($opts{'compress'}) { |
|
442 $flags.=" -compress"; |
|
443 } |
|
444 |
|
445 my $builder = $opts{'rombuilder'}; |
|
446 $builder = "rombuild" unless ($builder); |
|
447 |
|
448 |
|
449 |
|
450 print "$builder $flags -type-safe-link -S rom.oby 2>&1\n\n"; |
|
451 |
|
452 open(Y, "$builder $flags -type-safe-link -S rom.oby 2>&1 |") || |
|
453 die "Can't start $builder command, $!"; |
|
454 |
|
455 my $nerrors=0; |
|
456 my $nwarnings=0; |
|
457 |
|
458 while(<Y>) { |
|
459 my $error=(/^error:/i); |
|
460 my $warning=(/^warning:/i); |
|
461 print if ($error or $warning or !$quiet); |
|
462 $nerrors++ if ($error); |
|
463 $nwarnings++ if ($warning); |
|
464 } |
|
465 |
|
466 print "\nGenerated .oby file is rom.oby\n" if !$quiet; |
|
467 print "\nGenerated image file is $romname\n" if (!$nerrors); |
|
468 |
|
469 my$rerrors; |
|
470 my $rofsbuilder; |
|
471 if ($rofs) { |
|
472 $rofsbuilder = $opts{'rofsbuilder'}; |
|
473 $rofsbuilder = "rofsbuild" unless ($rofsbuilder); |
|
474 for(my $i=0;$i<$rofs;++$i) { |
|
475 print "Executing $rofsbuilder on main rofs\n" if !$quiet; |
|
476 my $image="rofs".$i.".oby"; |
|
477 system("$rofsbuilder $image"); |
|
478 if ($? != 0) |
|
479 { |
|
480 print "$rofsbuilder $image returned $?\n"; |
|
481 $rerrors++; |
|
482 } |
|
483 rename "rofsbuild.log", "rofs$i.log" |
|
484 } |
|
485 } |
|
486 |
|
487 if ($rofs and $extension) { |
|
488 for(my $i=0;$i<$extension;++$i) { |
|
489 print "Executing $rofsbuilder on extension rofs\n" if !$quiet; |
|
490 my $image="extension".$i.".oby"; |
|
491 system("$rofsbuilder $image"); |
|
492 if ($? != 0) |
|
493 { |
|
494 print "$rofsbuilder $image returned $?\n"; |
|
495 $rerrors++; |
|
496 } |
|
497 rename "rofsbuild.log", "extension$i.log" |
|
498 } |
|
499 } |
|
500 |
|
501 if ($nerrors) { |
|
502 print "\n\n Errors found during $builder!!\n\nLeaving tmp files\n"; |
|
503 } elsif ($nwarnings) { |
|
504 print "\n\n Warnings during $builder!!\n\nLeaving tmp files\n"; |
|
505 } elsif ($rerrors) { |
|
506 print "\n\n Errors during $rofsbuilder!!\n\nLeaving tmp files\n"; |
|
507 } else { |
|
508 unlink glob("*.tmp") if !$debug; |
|
509 } |
|
510 if ($opts{zip} or $zip{$opts{assp}}) { |
|
511 my $zipname=$romname; |
|
512 $zipname =~ s/\.(\w+)$/\.zip/i; |
|
513 unlink $zipname; |
|
514 system("zip $zipname $romname"); |
|
515 } |
|
516 if ($opts{symbol}) { |
|
517 my $logname=$romname; |
|
518 $logname =~ s/\.(\w+)$/\.log/i; |
|
519 my $obyname=$romname; |
|
520 $obyname =~ s/\.(\w+)$/\.oby/i; |
|
521 unlink $logname; |
|
522 unlink $obyname; |
|
523 system("rename rombuild.log $logname"); |
|
524 system("rename rom.oby $obyname"); |
|
525 system("maksym $logname"); |
|
526 } |
|
527 |
|
528 if ($nerrors || $nwarnings || $rerrors) { |
|
529 exit 4; |
|
530 } |
|
531 |
|
532 exit 0; |
|
533 |
|
534 |
|
535 ################################ Subroutines ################################## |
|
536 |
|
537 sub usage { |
|
538 print <<EOT; |
|
539 |
|
540 rom <options> |
|
541 |
|
542 Generate a rom image for the specified target, along with a rom.oby file |
|
543 that can be fed to (a) rombuild to regenerate the image. |
|
544 |
|
545 The following options are required: |
|
546 --variant=<variant> e.g. --variant=assabet |
|
547 --inst=<instruction set> e.g. --inst=arm4 |
|
548 --build=<build> e.g. --build=udeb |
|
549 --type=<type of rom> |
|
550 tshell for a text shell rom |
|
551 e32tests for a rom with e32tests |
|
552 f32tests for rom with f32tests |
|
553 alltests for all the tests |
|
554 |
|
555 The following are optional: |
|
556 --name=<image name> Give image file specified name |
|
557 --noheader Pass -no-header option on to rombuild |
|
558 --help This help message. |
|
559 --clean Remove existing generated files first |
|
560 --quiet Be less verbose |
|
561 --modules=<comma separated list> List of additional modules for this ROM |
|
562 --define=<comma separated list> List of CPP macros to define |
|
563 |
|
564 Options may be specified as a short abbreviation |
|
565 e.g. -b udeb instead of --build udeb |
|
566 |
|
567 EOT |
|
568 } |
|
569 |
|
570 sub cleanup($$$) { |
|
571 print "What's going on!\n"; |
|
572 my ($in, $out, $k) = @_; |
|
573 my ($line, $lastblank); |
|
574 |
|
575 open(OUTPUT_FILE, "> $out") or die "Cannot open $out for output"; |
|
576 open(INPUT_FILE, "< $in") or die "Cannot open for $in input"; |
|
577 |
|
578 while ($line=<INPUT_FILE>) { |
|
579 $line=~s/##//g; |
|
580 |
|
581 # file=\epoc32\... ==> file=%EPOCROOT%\epoc32\... |
|
582 $line =~ s/(=\s*)\\epoc32/\1${EpocRoot}Epoc32/i; |
|
583 |
|
584 # Now compress blank lines down to one |
|
585 |
|
586 if($line=~/^\s*$/) { |
|
587 if($lastblank) { |
|
588 # Do nothing |
|
589 } else { |
|
590 # This is the first blank line |
|
591 $lastblank=1; |
|
592 print OUTPUT_FILE $line; |
|
593 } |
|
594 } else { |
|
595 # Not blank |
|
596 $lastblank=0; |
|
597 if ($k and $line=~/^\s*kerneltrace/i) { |
|
598 $line = "kerneltrace $k\n"; |
|
599 } |
|
600 |
|
601 # This next line is about converting all the / to \ to make sure that we are using the right format for the build generation |
|
602 $line =~ s/\//\\/g; |
|
603 |
|
604 print OUTPUT_FILE $line if !($line=~/^\s*REM\s+/i); |
|
605 } |
|
606 } |
|
607 close(INPUT_FILE); |
|
608 close(OUTPUT_FILE); |
|
609 } |
|
610 |
|
611 sub IsSmp($) { |
|
612 my %SmpKernelDirs=( |
|
613 'x86smp' => 1, |
|
614 'x86gmp' => 1, |
|
615 'arm4smp' => 1, |
|
616 'armv4smp' => 1, |
|
617 'armv5smp' => 1 |
|
618 ); |
|
619 |
|
620 my ($kdir) = @_; |
|
621 return $SmpKernelDirs{lc $kdir}; |
|
622 } |
|
623 |
|
624 sub checkopts { |
|
625 unless($opts{variant}) { die "No Variant specified"; } |
|
626 $opts{'build'}="UDEB" unless($opts{'build'}); |
|
627 $opts{'type'}="TSHELL" unless($opts{'type'}); |
|
628 $opts{'inst'}="ARM4" unless($opts{'inst'}); |
|
629 |
|
630 my $additional; |
|
631 if ($opts{'modules'}) { |
|
632 $additional="_".$opts{modules}; |
|
633 $additional=~ s/,/_/ig; |
|
634 } |
|
635 my $build=lc $opts{build}; |
|
636 my $inst=uc $opts{'inst'}; |
|
637 if ($inst eq "MARM") { |
|
638 # Hackery to cope with old compiler |
|
639 $main="MARM"; |
|
640 $euserdir="MARM"; |
|
641 $elocldir="MARM"; |
|
642 } |
|
643 else { |
|
644 $main=$inst; |
|
645 if ($main eq "THUMB") { |
|
646 $euserdir="ARMI"; |
|
647 } else { |
|
648 $euserdir=$main; |
|
649 } |
|
650 if ($main eq "ARMI" or $main eq "THUMB") { |
|
651 $elocldir="ARM4"; |
|
652 } else { |
|
653 $elocldir=$main; |
|
654 } |
|
655 } |
|
656 $kmain = $opts{'xabi'}; |
|
657 $kmain = $main unless ($kmain); |
|
658 if (IsSmp($kmain)) { |
|
659 $euserdir = $kmain; |
|
660 } |
|
661 if ($opts{name}) { |
|
662 $romname=$opts{name}; |
|
663 } else { |
|
664 $romname=uc($opts{variant}.$additional.$main); |
|
665 if ($build=~/^\w*DEB$/i) { |
|
666 $romname.='D'; |
|
667 } |
|
668 $romname.='.IMG'; |
|
669 } |
|
670 } |
|
671 |
|
672 sub lookupFileInfo($$) |
|
673 { |
|
674 my ($infile, $fullname) = @_; |
|
675 |
|
676 my ($name, $ext) = $fullname =~ /^(.+)\.(\w+)$/ ? ($1, $2) : ($fullname, undef); |
|
677 |
|
678 open TMP, $infile or die("Can't open $infile\n"); |
|
679 while(<TMP>) |
|
680 { |
|
681 $_ = lc; |
|
682 if(/^\s*(\S+)\s*=\s*(\S+)\s+(\S+)/i) |
|
683 { |
|
684 my ($src, $dest) = ($2, $3); |
|
685 |
|
686 my $destFullname = $dest =~ /^.*\\(.+)$/ ? $1 : $dest; |
|
687 my ($destName, $destExt) = $destFullname =~ /^(.+?)\.(\w+)$/ ? ($1, $2) : ($destFullname, undef); |
|
688 |
|
689 if ($destName eq $name && (!$ext || $ext eq $destExt)) |
|
690 { |
|
691 close TMP; |
|
692 return ($src, $dest); |
|
693 } |
|
694 } |
|
695 } |
|
696 |
|
697 die "patchdata: Can't find file $fullname\n"; |
|
698 } |
|
699 |
|
700 sub lookupSymbolInfo($$) |
|
701 { |
|
702 my ($file, $name) = @_; |
|
703 |
|
704 open TMP, $file or die "Can't read $file\n"; |
|
705 |
|
706 # ignore local symbols. |
|
707 while (<TMP> !~ /Global Symbols/) { } |
|
708 |
|
709 while (<TMP>) |
|
710 { |
|
711 if (/^\s*(\S+)\s+(\S+)\s+data\s+(\S+)/i) |
|
712 { |
|
713 my ($symbol, $addr, $size) = ($1, $2, $3); |
|
714 if ($symbol eq $name) |
|
715 { |
|
716 close TMP; |
|
717 return ($addr, $size); |
|
718 } |
|
719 } |
|
720 |
|
721 # This is a quick fix for RVCT 3.1, which uses the text "(EXPORTED)" |
|
722 # in the map file. Here is an example: |
|
723 # |
|
724 # KHeapMinCellSize (EXPORTED) 0x0003d81c Data 4 mem.o(.constdata) |
|
725 # |
|
726 elsif (/^\s*(\S+)\s+\(exported\)\s+(\S+)\s+data\s+(\S+)/i) |
|
727 { |
|
728 my ($symbol, $addr, $size) = ($1, $2, $3); |
|
729 if ($symbol eq $name) |
|
730 { |
|
731 close TMP; |
|
732 return ($addr, $size); |
|
733 } |
|
734 } |
|
735 } |
|
736 |
|
737 die "patchdata: Can't find symbol $name\n"; |
|
738 } |
|
739 |
|
740 sub parsePatchData($$) |
|
741 { |
|
742 my ($infile, $outfile) = @_; |
|
743 |
|
744 open IN, $infile or die("Can't read $infile\n"); |
|
745 open OUT, ">$outfile" or die("Can't write $outfile\n"); |
|
746 |
|
747 my $line; |
|
748 while($line = <IN>) |
|
749 { |
|
750 if ($line =~ /^\s*patchdata\s+(.+?)\s*$/i) |
|
751 { |
|
752 if ($1 !~ /(\S+)\s*@\s*(\S+)\s+(\S+)\s*$/) |
|
753 { |
|
754 die "Bad patchdata command: $line\n"; |
|
755 } |
|
756 |
|
757 my ($file, $symbol, $value) = (lc $1, $2, $3); |
|
758 my ($srcFile, $destFile) = lookupFileInfo($infile, $file); |
|
759 my ($index, $elementSize) = (undef, undef); |
|
760 if ($symbol =~ s/:(\d+)\[(\d+)\]$//) |
|
761 { |
|
762 ($index, $elementSize) = ($2, $1); |
|
763 $index = hex($index) if $index =~ /^0x/i; |
|
764 } |
|
765 |
|
766 if ($srcFile =~ /\\armv5(smp)?\\/i) |
|
767 { |
|
768 my ($symbolAddr, $symbolSize) = lookupSymbolInfo("$srcFile.map", $symbol); |
|
769 |
|
770 my $max; |
|
771 if (defined($index)) |
|
772 { |
|
773 my $bytes; |
|
774 $bytes = 1, $max = 0xff if $elementSize == 8; |
|
775 $bytes = 2, $max = 0xffff if $elementSize == 16; |
|
776 $bytes = 4, $max = 0xffffffff if $elementSize == 32; |
|
777 die("patchdata: invalid element size $elementSize: $line\n") unless defined($bytes); |
|
778 |
|
779 if ($bytes > 1 && (($symbolSize & ($bytes-1)) != 0)) |
|
780 { |
|
781 die("patchdata: unexpected symbol size $symbolSize for array $symbol ($elementSize-bit elements)\n"); |
|
782 } |
|
783 |
|
784 if ($index >= int($symbolSize / $bytes)) |
|
785 { |
|
786 die("patchdata: index $index out of bounds for $symbol of $symbolSize bytes ($elementSize-bit elements)\n"); |
|
787 } |
|
788 |
|
789 $symbolAddr = hex($symbolAddr) if $symbolAddr =~ /^0x/i; |
|
790 $symbolAddr += $index * $bytes; |
|
791 $symbolAddr = sprintf("0x%x", $symbolAddr); |
|
792 |
|
793 $symbolSize = $bytes; |
|
794 } |
|
795 elsif ($symbolSize == 1) { $max = 0xff; } |
|
796 elsif ($symbolSize == 2) { $max = 0xffff; } |
|
797 elsif ($symbolSize == 4) { $max = 0xffffffff; } |
|
798 else { die "patchdata: Unexpected symbol size $symbolSize for $symbol\n"; } |
|
799 |
|
800 $value = hex($value) if $value =~ /^0x/i; |
|
801 if ($value > $max) |
|
802 { |
|
803 print("Warning: Value overflow of $symbol\n"); |
|
804 $value &= $max; |
|
805 } |
|
806 $value = sprintf("0x%08x", $value); |
|
807 |
|
808 $line = "patchdata $destFile addr $symbolAddr $symbolSize $value\n"; |
|
809 } |
|
810 else |
|
811 { |
|
812 $line = ""; |
|
813 } |
|
814 |
|
815 } |
|
816 |
|
817 print OUT $line; |
|
818 } |
|
819 |
|
820 close IN; |
|
821 close OUT; |
|
822 } |
|
823 |
|
824 sub genfile { |
|
825 my $count=0; |
|
826 if($_[0] eq 'paged') { |
|
827 my $file='gentestpaged.txt'; |
|
828 unlink $file; |
|
829 open(OUTFILE, ">$file") or die "Can't open output file, $!"; |
|
830 for(my $i=0;$i<50000;++$i) { |
|
831 if(($i >5) && ($i % 40 ==0)) { |
|
832 print OUTFILE "\n"; |
|
833 $count++; |
|
834 } |
|
835 if(($i+$count) % 5 ==0) { |
|
836 print OUTFILE "SATOR "; |
|
837 } |
|
838 if(($i+$count) % 5 ==1) { |
|
839 print OUTFILE "AREPO "; |
|
840 } |
|
841 if(($i+$count) % 5 ==2) { |
|
842 print OUTFILE "TENET "; |
|
843 } |
|
844 if(($i+$count) % 5 ==3) { |
|
845 print OUTFILE "OPERA "; |
|
846 } |
|
847 if(($i+$count) % 5 ==4) { |
|
848 print OUTFILE "ROTAS "; |
|
849 } |
|
850 } |
|
851 } else { |
|
852 my $file='gentestnonpaged.txt'; |
|
853 unlink $file; |
|
854 open(OUTFILE, ">$file") or die "Can't open output file, $!"; |
|
855 for(my $i=0;$i<20000;++$i) { |
|
856 if(($i >5) && ($i % 40 ==0)) { |
|
857 print OUTFILE "\n"; |
|
858 $count++; |
|
859 } |
|
860 if(($i+$count) % 4 ==0) { |
|
861 print OUTFILE "STEP "; |
|
862 } |
|
863 if(($i+$count) % 4 ==1) { |
|
864 print OUTFILE "TIME "; |
|
865 } |
|
866 if(($i+$count) % 4 ==2) { |
|
867 print OUTFILE "EMIT "; |
|
868 } |
|
869 if(($i+$count) % 4 ==3) { |
|
870 print OUTFILE "PETS "; |
|
871 } |
|
872 } |
|
873 } |
|
874 } |
|
875 |
|
876 __END__ |
|
877 |
|
878 # Tell emacs that this is a perl script even 'though it has a .bat extension |
|
879 # Local Variables: |
|
880 # mode:perl |
|
881 # tab-width:4 |
|
882 # End: |
|
883 |