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