Update contrib.
2 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 # Initial Contributors:
10 # Nokia Corporation - initial contribution.
15 # This script is designed to provide a working ethernet setup
16 # for EKA1 or EKA2. It works by running Netcards.exe
17 # then taking the output from Netcards (ethernet.ini)
18 # and appending the ethernet settings to epoc.ini for EKA2
19 # or creating ethermac.dat and etherdriver.dat for EKA1
21 # - create a working ethernet setup with "ethernet" config option
22 # - restore previous setup with "restore" config option
23 # Please note: The script assumes that target wins is running on EKA1
24 # Copied from configchange.pl to make use of environment varible for mac address
25 # Copied from configchangebats.pl to adapt for multiple network cards in "Blade" type servers.
40 my $etherMac = $ENV{'WINSCW_MAC'};
43 # this variable is passed as an argument to netcards.exe
44 # specifies which interface to use in case of multiple interfaces
50 GetOptions('config=s' => \$config, 'kernel=s' => \$kernel, 'target=s' => \$target, 'variant=s' => \$variant, 'help' => \$showhelp, 'interface:i' => \$interface);
52 $config = lc( $config );
53 $kernel = lc( $kernel );
54 $target = lc( $target );
55 $variant = lc( $variant );
59 if( $showhelp || ( $kernel ne "eka1" && $kernel ne "eka2" ) ||
60 ( $target ne "wins" && $target ne "winscw" ) ||
61 ( $config ne "ethernetwithcommdb" && $config ne "restorecommdb" && $config ne "ethernetnocommdb" ) ||
62 ( $variant ne "udeb" && $variant ne "urel" ) )
64 print "Command usage: configchange --config [ethernetWithCommDB|restoreCommDB|ethernetNoCommDB] --kernel [EKA1|EKA2] --target [wins|winscw] --variant [UDEB|UREL]\n";
65 print "\t\t--config \tSelect required configuration\n";
66 print "\t\t--kernel \tKernel variant\n";
67 print "\t\t--target \tTarget emulator\n";
68 print "\t\t--variant \tBuild type\n";
69 print "\t\t--interface \tInterface Number\n";
70 print "\t\t--help \tThis text\n";
74 my $epocroot = &getEpocroot;
75 my $drive = &getDrive;
77 if($ENV{'SERVER_TYPE'} && $ENV{'SERVER_TYPE'} =~ /blade/i){
83 my $netConfigOutput = `net config rdr`;
86 #J:\epoc32\winscw\c>net config rdr
87 #Computer name \\SYWINPAP0005
88 #Full Computer name SYWINPAP0005.prod.ad.symbian.intra
89 #User name extkesavanathimoolam
91 #Workstation active on
92 # NetbiosSmb (000000000000)
93 # NetBT_Tcpip_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A} (00215E2CB2F6)
96 # capture the network-interface info to compare it later with netcards output
97 if($netConfigOutput =~ /NetBT_Tcpip_\{(.*)?\}/i){
102 # netcards output sample
103 #J:\epoc32\winscw\c>\epoc32\tools\netcards.exe 1
105 #N/A - \Device\NPF_GenericDialupAdapter
106 # Adapter for generic dialup and VPN capture
108 # 1 - \Device\NPF_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A}
109 # Broadcom Advanced Server Program Driver for Windows Server 2003 with SNP
112 # 2 - \Device\NPF_{11F02767-7BDE-49FF-87F2-FD7F46FA8C60}
113 # Broadcom L2 NDIS client driver
115 # 3 - \Device\NPF_{9672396E-2361-42BF-80CF-1E03AF7BD59F}
116 # Broadcom L2 NDIS client driver
119 #Physical address read: 00:21:5e:2c:b2:f6
120 #Writing settings to ethernet.ini.
123 $netCardsCommand = "$drive\\$epocroot\\epoc32\\tools\\netcards $interface";
124 foreach (split("\n",`$netCardsCommand`)){
125 if(/\s*(\d)\s+\-\s+.*?$netIF/){
134 if( $config ne "restorecommdb" )
136 # must be creating some ethernet setup
137 if( $config eq "ethernetwithcommdb" )
139 # write an appropriate commDB setup
140 print( "Setting up CommDB for ethernet\n" );
141 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ceddump" ) == 0
142 or die "Error running ceddump!\n";
143 system( "move $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) == 0
144 or die "Failed to rename cedout.cfg!\n";
145 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -dtextshell -- -i c:\\EthernetCed.xml") == 0
146 or die "Error running ced!\n";
148 print( "Running Netcards to obtain adapter info\n" );
149 system( "$drive\\$epocroot\\epoc32\\tools\\netcards $interface" ) == 0
150 or die "Error running netcards!\n";
152 open ( INFILE, "ethernet.ini" ) or die "Can't find netcards output file, ethernet.ini!\n"; # get from current directory where netcards wrote it to
154 if ($kernel eq "eka1")
156 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";
164 if( $sLine =~ /ETHER_NIF=(.*)/i )
166 #print "Matched ETHER_NIF\n";
167 if ($kernel eq "eka1")
176 elsif( $sLine =~ /ETHER_SPEED=(.*)/i )
178 #print "Matched ETHER_SPEED\n";
179 if ($kernel eq "eka2")
184 #print "line: $sLine\n";
186 if ($kernel eq "eka1")
192 # do the insertion to epoc.ini
199 if( -f "$drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" )
201 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -i c:\\nonethernetced.cfg" ) == 0
202 or die "Can't find backup ced file!\n";
203 system( "move $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg" ) == 0
204 or die "Can't rename backup ced file!\n";
208 print "No restore file found!\n";
216 # Determines, validates, and returns EPOCROOT.
220 my $epocroot = $ENV{EPOCROOT};
221 die "ERROR: Must set the EPOCROOT environment variable.\n"
222 if (!defined($epocroot));
223 $epocroot =~ s-/-\\-go; # for those working with UNIX shells
224 die "ERROR: EPOCROOT must be an absolute path, " .
225 "not containing a drive letter.\n" if ($epocroot !~ /^\\/);
226 die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/);
227 die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/);
228 die "ERROR: EPOCROOT must specify an existing directory.\n"
234 # Determines and returns the current drive, if any.
240 if($wd =~ /^([a-zA-Z]:)/) {
243 # Perhaps we're on a machine that has no drives.
256 my $needToAppend = TRUE;
257 my $epocIniAlreadyExists = FALSE;
258 my $finished = FALSE;
259 print "generating epoc ini\n";
260 if ( -e "$drive\\$epocroot\\epoc32\\data\\epoc.ini" )
262 $epocIniAlreadyExists = TRUE;
263 open( EPOCINI, "+<$drive\\$epocroot\\epoc32\\data\\epoc.ini" );
264 seek( EPOCINI, 0, 0 );
269 if( $sLine =~ /ETHER_NIF=(.*)/i )
271 #print "matched etherNIF\n";
272 $length = length( $etherNif );
274 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherNif;
275 $needToAppend = FALSE;
277 elsif( $sLine =~ /ETHER_MAC=(.*)/i )
279 print "Matched ETHER_MAC\n";
280 $length = length( $etherMac );
281 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherMac;
282 $needToAppend = FALSE;
284 elsif( $sLine =~ /ETHER_SPEED=(.*)/i )
286 #print "Matched etherSpeed\n";
287 $length = length( $etherSpeed );
288 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherSpeed;
289 $needToAppend = FALSE;
291 push( @outLines, $sLine );
292 push( @outLines, "\n" );
294 if ( $needToAppend eq FALSE )
296 print "Writing new settings into epoc.ini\n";
297 # we have read the entire file and replaced what we need to
298 # now lets write it back to the file
299 seek( EPOCINI, 0, 0 );
300 print EPOCINI @outLines;
306 if ( $finished eq FALSE )
308 if ( ($needToAppend eq TRUE) && ($epocIniAlreadyExists eq TRUE) )
310 print "Appending settings to current epoc.ini\n";
311 # we must append all the settings onto the end of the current epoc.ini
312 open( EPOCINI, ">>$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) or die "Can't open epoc.ini!\n";
314 elsif ( $epocIniAlreadyExists eq FALSE )
316 print "Creating new epoc.ini\n";
318 open( EPOCINI, ">$drive\\$epocroot\\epoc32\\data\\epoc.ini" );
321 print EPOCINI "\nETHER_NIF=";
322 print EPOCINI "$etherNif\n";
323 print EPOCINI "ETHER_MAC=";
324 print EPOCINI "$etherMac\n";
325 print EPOCINI "ETHER_SPEED=";
326 print EPOCINI "$etherSpeed\n";