|
1 # |
|
2 # Copyright (c) 2004-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 # Concatenate an extension ROM onto the core ROM. |
|
16 # Works for ROMBUILD XIP ROMs and ROFSBUILD non-XIP ROMs |
|
17 # |
|
18 |
|
19 use strict; |
|
20 |
|
21 if (@ARGV<2 || @ARGV>3) |
|
22 { |
|
23 #........1.........2.........3.........4.........5.........6.........7..... |
|
24 print <<USAGE_EOF; |
|
25 |
|
26 Usage: |
|
27 addextension <kernelRom> <extensionRom> [<outputfile>] |
|
28 |
|
29 If <extensionRom> doesn\'t exist, addextension will try concatenating |
|
30 the <kernelrom> and <extensionrom> names. |
|
31 If no <outputfile> is specified, the default is sys\$rom.bin |
|
32 |
|
33 USAGE_EOF |
|
34 exit(1); |
|
35 } |
|
36 |
|
37 my $kernelROM = @ARGV[0]; |
|
38 my $extensionROM = @ARGV[1]; |
|
39 my $outputfile = "sys\$rom.bin"; |
|
40 $outputfile = @ARGV[2] if (@ARGV==3); |
|
41 |
|
42 open KERNEL, "<$kernelROM" or die "Cannot open $kernelROM"; |
|
43 binmode KERNEL; |
|
44 |
|
45 if (!open EXTENSION, "<$extensionROM") |
|
46 { |
|
47 open EXTENSION , "<$kernelROM$extensionROM" or |
|
48 die "Cannot open $extensionROM or $kernelROM$extensionROM"; |
|
49 $extensionROM = $kernelROM.$extensionROM; |
|
50 } |
|
51 binmode EXTENSION; |
|
52 |
|
53 open RESULT, ">$outputfile" or die "Cannot open $outputfile for output"; |
|
54 binmode RESULT; |
|
55 |
|
56 print "Writing $kernelROM + $extensionROM to $outputfile\n"; |
|
57 |
|
58 my $reproheader = ""; |
|
59 read KERNEL, $reproheader, 256; |
|
60 if ($reproheader !~ /^EPOC....ROM/) |
|
61 { |
|
62 seek KERNEL, 0, 0; # No REPRO header, rewind back to the start |
|
63 $reproheader = ""; |
|
64 } |
|
65 |
|
66 my $kerneldata; |
|
67 read KERNEL, $kerneldata, 4096; |
|
68 |
|
69 my $kernelsize; |
|
70 my $imagesize; |
|
71 if ($kerneldata =~ /^ROFS/) |
|
72 { |
|
73 $imagesize = unpack "V", substr($kerneldata, 0x24, 4); |
|
74 $kernelsize = unpack "V", substr($kerneldata, 0x2c, 4); |
|
75 printf "ROFS size: 0x%08x ", ($imagesize); |
|
76 } |
|
77 else |
|
78 { |
|
79 $kernelsize = unpack "V", substr($kerneldata, 0x90, 4); |
|
80 } |
|
81 printf "\nCore ROM maximium size: 0x%08x", $kernelsize; |
|
82 |
|
83 |
|
84 if ($reproheader ne "") |
|
85 { |
|
86 # Add REPRO header to output, but update image size |
|
87 my $tmp; |
|
88 read(EXTENSION, $tmp, 128); |
|
89 seek EXTENSION, 0, 0; |
|
90 |
|
91 my $extensionsize = unpack "V", substr($tmp, 0x10, 4); |
|
92 substr($reproheader, 0x18, 4) = pack "V", $extensionsize+$kernelsize; |
|
93 |
|
94 syswrite RESULT, $reproheader; |
|
95 } |
|
96 |
|
97 $kernelsize -= syswrite RESULT, $kerneldata; |
|
98 while (read(KERNEL, $kerneldata, 4096)) |
|
99 { |
|
100 $kernelsize -= syswrite RESULT, $kerneldata, $kernelsize; |
|
101 } |
|
102 close KERNEL; |
|
103 |
|
104 # Pad the data to the full size of the kernel ROM image |
|
105 |
|
106 $kerneldata = "\377\377\377\377"; # 4 |
|
107 $kerneldata = $kerneldata.$kerneldata.$kerneldata.$kerneldata; # 16 |
|
108 $kerneldata = $kerneldata.$kerneldata.$kerneldata.$kerneldata; # 64 |
|
109 $kerneldata = $kerneldata.$kerneldata.$kerneldata.$kerneldata; # 256 |
|
110 $kerneldata = $kerneldata.$kerneldata.$kerneldata.$kerneldata; # 1024 |
|
111 $kerneldata = $kerneldata.$kerneldata.$kerneldata.$kerneldata; # 4096 |
|
112 |
|
113 while ($kernelsize > 0) |
|
114 { |
|
115 $kernelsize -= syswrite RESULT, $kerneldata, $kernelsize; |
|
116 } |
|
117 |
|
118 # Stick the extension ROM on the end |
|
119 |
|
120 my $extensiondata; |
|
121 while (read(EXTENSION, $extensiondata, 4096)) |
|
122 { |
|
123 syswrite RESULT, $extensiondata; |
|
124 } |
|
125 close RESULT; |