|
1 # |
|
2 # Copyright (c) 2004 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 "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: The script can |
|
15 # - create a working ethernet setup with "ethernet" config option |
|
16 # - restore previous setup with "restore" config option |
|
17 # |
|
18 |
|
19 use Getopt::Long; |
|
20 use Cwd; |
|
21 |
|
22 my $config="default"; |
|
23 my $target="default"; |
|
24 my $kernel="default"; |
|
25 my $showhelp='0'; |
|
26 |
|
27 my $etherNif; |
|
28 my $etherMac; |
|
29 my $etherSpeed; |
|
30 |
|
31 # this variable is passed as an argument to netcards.exe |
|
32 # specifies which interface to use in case of multiple interfaces |
|
33 |
|
34 my $interface=0; |
|
35 |
|
36 $/ = "\n"; |
|
37 |
|
38 GetOptions('config=s' => \$config, 'kernel=s' => \$kernel, 'target=s' => \$target, 'variant=s' => \$variant, 'help' => \$showhelp, 'interface:i' => \$interface); |
|
39 |
|
40 $config = lc( $config ); |
|
41 $kernel = lc( $kernel ); |
|
42 $target = lc( $target ); |
|
43 $variant = lc( $variant ); |
|
44 |
|
45 |
|
46 if( $showhelp || ( $kernel ne "eka1" && $kernel ne "eka2" ) || |
|
47 ( $target ne "wins" && $target ne "winscw" ) || |
|
48 ( $config ne "ethernetwithcommdb" && $config ne "restorecommdb" && $config ne "ethernetnocommdb" ) || |
|
49 ( $variant ne "udeb" && $variant ne "urel" ) ) |
|
50 { |
|
51 print "Command usage: configchange --config [ethernetWithCommDB|restoreCommDB|ethernetNoCommDB] --kernel [EKA1|EKA2] --target [wins|winscw] --variant [UDEB|UREL]\n"; |
|
52 print "\t\t--config \tSelect required configuration\n"; |
|
53 print "\t\t--kernel \tKernel variant\n"; |
|
54 print "\t\t--target \tTarget emulator\n"; |
|
55 print "\t\t--variant \tBuild type\n"; |
|
56 print "\t\t--interface \tInterface Number\n"; |
|
57 print "\t\t--help \tThis text\n"; |
|
58 exit 0; |
|
59 } |
|
60 |
|
61 my $epocroot = &getEpocroot; |
|
62 my $drive = &getDrive; |
|
63 |
|
64 if( $config ne "restorecommdb" ) |
|
65 { |
|
66 # must be creating some ethernet setup |
|
67 if( $config eq "ethernetwithcommdb" ) |
|
68 { |
|
69 # write an appropriate commDB setup |
|
70 print( "Setting up CommDB for ethernet\n" ); |
|
71 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ceddump -dtextshell --" ) == 0 |
|
72 or die "Error running ceddump!\n"; |
|
73 system( "move $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) == 0 |
|
74 or die "Failed to rename cedout.cfg!\n"; |
|
75 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -dtextshell -- -i c:\\EthernetCed.xml") == 0 |
|
76 or die "Error running ced!\n"; |
|
77 } |
|
78 print( "Running Netcards to obtain adapter info\n" ); |
|
79 system( "$drive\\$epocroot\\epoc32\\tools\\netcards $interface" ) == 0 |
|
80 or die "Error running netcards!\n"; |
|
81 |
|
82 open ( INFILE, "ethernet.ini" ) or die "Can't find netcards output file, ethernet.ini!\n"; # get from current directory where netcards wrote it to |
|
83 |
|
84 if ($kernel eq "eka1") |
|
85 { |
|
86 open ( ETHERMAC, ">$drive\\$epocroot\\epoc32\\$target\\c\\system\\data\\ethermac.dat" ) or die "Can't open $drive\\$epocroot\\epoc32\\$target\\c\\system\\data\\ethermac.dat!\n"; |
|
87 open ( ETHERDRV, ">$drive\\$epocroot\\epoc32\\$target\\c\\system\\data\\etherdriver.dat" ) or die "Can't open $drive\\$epocroot\\epoc32\\$target\\c\\system\\data\\etherdriver.dat!\n"; |
|
88 } |
|
89 |
|
90 while( <INFILE> ) |
|
91 { |
|
92 chomp; |
|
93 my $sLine = $_; |
|
94 |
|
95 if( $sLine =~ /ETHER_NIF=(.*)/i ) |
|
96 { |
|
97 #print "Matched ETHER_NIF\n"; |
|
98 if ($kernel eq "eka1") |
|
99 { |
|
100 print ETHERDRV "$1"; |
|
101 } |
|
102 else |
|
103 { |
|
104 $etherNif = $1; |
|
105 } |
|
106 } |
|
107 elsif( $sLine =~ /ETHER_MAC=(.*)/i ) |
|
108 { |
|
109 #print "Matched ETHER_MAC\n"; |
|
110 if ($kernel eq "eka1") |
|
111 { |
|
112 print ETHERMAC "$1"; |
|
113 } |
|
114 else |
|
115 { |
|
116 $etherMac = $1; |
|
117 } |
|
118 } |
|
119 elsif( $sLine =~ /ETHER_SPEED=(.*)/i ) |
|
120 { |
|
121 #print "Matched ETHER_SPEED\n"; |
|
122 if ($kernel eq "eka2") |
|
123 { |
|
124 $etherSpeed = $1; |
|
125 } |
|
126 } |
|
127 #print "line: $sLine\n"; |
|
128 } |
|
129 if ($kernel eq "eka1") |
|
130 { |
|
131 close( ETHERDRV ); |
|
132 close( ETHERMAC ); |
|
133 } |
|
134 else |
|
135 { |
|
136 # do the insertion to epoc.ini |
|
137 &generateEpocIni; |
|
138 } |
|
139 close( INFILE ); |
|
140 } |
|
141 else |
|
142 { |
|
143 if( -f "$drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) |
|
144 { |
|
145 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -i c:\\nonethernetced.cfg" ) == 0 |
|
146 or die "Can't find backup ced file!\n"; |
|
147 system( "move $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg") == 0 |
|
148 or die "Can't rename backup ced file!\n"; |
|
149 } |
|
150 else |
|
151 { |
|
152 print "No restore file found!\n"; |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 # |
|
160 # Determines, validates, and returns EPOCROOT. |
|
161 # |
|
162 sub getEpocroot |
|
163 { |
|
164 my $epocroot = $ENV{EPOCROOT}; |
|
165 die "ERROR: Must set the EPOCROOT environment variable.\n" |
|
166 if (!defined($epocroot)); |
|
167 $epocroot =~ s-/-\\-go; # for those working with UNIX shells |
|
168 die "ERROR: EPOCROOT must be an absolute path, " . |
|
169 "not containing a drive letter.\n" if ($epocroot !~ /^\\/); |
|
170 die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/); |
|
171 die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/); |
|
172 die "ERROR: EPOCROOT must specify an existing directory.\n" |
|
173 if (!-d $epocroot); |
|
174 return $epocroot; |
|
175 } |
|
176 |
|
177 # |
|
178 # Determines and returns the current drive, if any. |
|
179 # |
|
180 sub getDrive |
|
181 { |
|
182 my $wd = cwd; |
|
183 my $drive; |
|
184 if($wd =~ /^([a-zA-Z]:)/) { |
|
185 $drive = $1; |
|
186 } else { |
|
187 # Perhaps we're on a machine that has no drives. |
|
188 $drive = ""; |
|
189 } |
|
190 return $drive; |
|
191 } |
|
192 |
|
193 # |
|
194 # |
|
195 # |
|
196 sub generateEpocIni |
|
197 { |
|
198 my @outLines; |
|
199 my $length = 0; |
|
200 my $needToAppend = TRUE; |
|
201 my $epocIniAlreadyExists = FALSE; |
|
202 my $finished = FALSE; |
|
203 print "generating epoc ini\n"; |
|
204 if ( -e "$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) |
|
205 { |
|
206 $epocIniAlreadyExists = TRUE; |
|
207 open( EPOCINI, "+<$drive\\$epocroot\\epoc32\\data\\epoc.ini" ); |
|
208 seek( EPOCINI, 0, 0 ); |
|
209 while( <EPOCINI> ) |
|
210 { |
|
211 chomp; |
|
212 my $sLine = $_; |
|
213 if( $sLine =~ /ETHER_NIF=(.*)/i ) |
|
214 { |
|
215 #print "matched etherNIF\n"; |
|
216 $length = length( $etherNif ); |
|
217 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherNif; |
|
218 $needToAppend = FALSE; |
|
219 } |
|
220 elsif( $sLine =~ /ETHER_MAC=(.*)/i ) |
|
221 { |
|
222 #print "Matched ETHER_MAC\n"; |
|
223 $length = length( $etherMac ); |
|
224 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherMac; |
|
225 $needToAppend = FALSE; |
|
226 } |
|
227 elsif( $sLine =~ /ETHER_SPEED=(.*)/i ) |
|
228 { |
|
229 #print "Matched etherSpeed\n"; |
|
230 $length = length( $etherSpeed ); |
|
231 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherSpeed; |
|
232 $needToAppend = FALSE; |
|
233 } |
|
234 push( @outLines, $sLine ); |
|
235 push( @outLines, "\n" ); |
|
236 } |
|
237 if ( $needToAppend eq FALSE ) |
|
238 { |
|
239 print "Writing new settings into epoc.ini\n"; |
|
240 # we have read the entire file and replaced what we need to |
|
241 # now lets write it back to the file |
|
242 seek( EPOCINI, 0, 0 ); |
|
243 print EPOCINI @outLines; |
|
244 $finished = TRUE; |
|
245 } |
|
246 close ( EPOCINI ); |
|
247 } |
|
248 |
|
249 if ( $finished eq FALSE ) |
|
250 { |
|
251 if ( ($needToAppend eq TRUE) && ($epocIniAlreadyExists eq TRUE) ) |
|
252 { |
|
253 print "Appending settings to current epoc.ini\n"; |
|
254 # we must append all the settings onto the end of the current epoc.ini |
|
255 open( EPOCINI, ">>$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) or die "Can't open epoc.ini!\n"; |
|
256 } |
|
257 elsif ( $epocIniAlreadyExists eq FALSE ) |
|
258 { |
|
259 print "Creating new epoc.ini\n"; |
|
260 # create new file |
|
261 open( EPOCINI, ">$drive\\$epocroot\\epoc32\\data\\epoc.ini" ); |
|
262 } |
|
263 |
|
264 print EPOCINI "\nETHER_NIF="; |
|
265 print EPOCINI "$etherNif\n"; |
|
266 print EPOCINI "ETHER_MAC="; |
|
267 print EPOCINI "$etherMac\n"; |
|
268 print EPOCINI "ETHER_SPEED="; |
|
269 print EPOCINI "$etherSpeed\n"; |
|
270 close ( EPOCINI ); |
|
271 } |
|
272 } |