1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/targeting/common/genNodeMrwXml.pl $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2013,2014
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
#
# Usage:
#
# genNodeMrwXml.pl --system=systemname --systemnodes=2 --mrwdir=pathname
# --build=hb/fsp --nodeCount=nodeCount
# [--help]
#
# --system=systemname
# Specify which system MRW XML to be generated.
# The file name will be set as uppercase
# --systemnodes=systemnodesinbrazos
# Specify number of nodes for brazos system, by default it is 4
# --mrwdir=pathname
# Specify the complete dir pathname of the MRW. Colon-delimited
# list accepted to specify multiple directories to search.
# --outfileDir=pathname
# Specify the complete dir pathname to where output files should
# be created
# --build=hb/fsp
# Specify if HostBoot build (hb) or FSP build (fsp)
# --nodeCount
# Specify the max number of nodes for the system
# --help
# displays usage
#
# Purpose:
#
# This perl script processes the various xml files of the Tuleta MRW to
# extract the needed information for generating the final xml file.
#
use strict;
use XML::Simple;
use Data::Dumper;
################################################################################
# Set PREFERRED_PARSER to XML::Parser. Otherwise it uses XML::SAX which contains
# bugs that result in XML parse errors that can be fixed by adjusting white-
# space (i.e. parse errors that do not make sense).
################################################################################
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
################################################################################
#main
################################################################################
my $mrwdir = "";
my $sysname = "";
my $sysnodes = "";
my $usage = 0;
my $nodeCount = 0;
my $outFileDir = "";
my $build = "fsp";
use Getopt::Long;
GetOptions( "mrwdir:s" => \$mrwdir,
"system:s" => \$sysname,
"systemnodes:s" => \$sysnodes,
"nodeCount:i" => \$nodeCount,
"outfileDir:s" => \$outFileDir,
"build:s" => \$build,
"help" => \$usage, );
if ($usage || ($mrwdir eq "") || ($sysname eq "") || ($outFileDir eq ""))
{
display_help();
exit 0;
}
if ($nodeCount ==0)
{
#no nodes so don't need to create node xml files
exit 0;
}
my $SYSNAME = uc($sysname);
my $outFile = "";
my @nodeOutFiles;
my $sysInfo;
my $fileSuffix;
if ($build eq "fsp")
{
$fileSuffix="fsp";
}
elsif ($build eq "hb")
{
$fileSuffix="hb";
}
else
{
die "ERROR: $build is not valid. Valid values are fsp or hb\n";
}
my $nodeSuffix = "";
if( ($sysnodes) && ($sysnodes =~ /2/) )
{
$nodeSuffix = "2N_"
}
#create files
my $mrw_file =
open_mrw_file($mrwdir, "${SYSNAME}_${nodeSuffix}${fileSuffix}.mrw.xml");
$sysInfo = XMLin($mrw_file,
ForceArray=>1);
#print Dumper($sysInfo);
for my $j(0..($nodeCount))
{
$outFile =
"$outFileDir/${SYSNAME}_${nodeSuffix}node_$j"."_${fileSuffix}.mrw.xml";
push @nodeOutFiles, [$outFile];
}
#create file discriptor array
my @nodeFD;
for my $k(0..$#nodeOutFiles)
{
my $filename= sprintf("%s",@{$nodeOutFiles[$k]});
open $nodeFD[$k], '>', $filename ||
die "ERROR: unable to create $filename\n";
}
#read in the targeting data from system xml files
foreach my $targetInstance (@{$sysInfo->{targetInstance}})
{
my $Id = $targetInstance->{'id'};
my $targetId = sprintf("%s",@{$Id});
#print("targetId =", $targetId, "\n");
my $xmlData= XMLout($targetInstance,RootName => "targetInstance");
#print Dumper($xmlData);
if ($targetId eq "sys0")
{
for my $node(0..$nodeCount)
{
print {$nodeFD[$node]} $xmlData;
}
}
else
{
my $nodeValue = $targetId;
$nodeValue =~ s/.*node(\d?).*/$1/;
if ($nodeValue < $#nodeFD )
{
print {$nodeFD[$nodeValue]} $xmlData;
}
elsif ($nodeValue == $#nodeFD)
{
print {$nodeFD[0]} $xmlData;
}
else
{
die "ERROR: node value($nodeValue) is not in the range of possible nodes\n";
}
}
}
#close file descriptors
for my $k(0..$#nodeOutFiles)
{
my $filename= sprintf("%s",@{$nodeOutFiles[$k]});
close $nodeFD[$k] ||
die "ERROR: unable to close $filename\n";
}
exit 0;
################################################################################
#subroutines below
################################################################################
#subroutines below
sub open_mrw_file
{
my ($paths, $filename) = @_;
#Need to get list of paths to search
my @paths_to_search = split /:/, $paths;
my $file_found = "";
#Check for file at each directory in list
foreach my $path (@paths_to_search)
{
if ( open (FH, "<$path/$filename") )
{
$file_found = "$path/$filename";
close(FH);
last; #break out of loop
}
}
if ($file_found eq "")
{
#If the file was not found, build up error message and exit
my $err_msg = "Could not find $filename in following paths:\n";
foreach my $path (@paths_to_search)
{
$err_msg = $err_msg." $path\n";
}
die $err_msg;
}
else
{
#Return the full path to the file found
return $file_found;
}
}
sub display_help
{
use File::Basename;
my $scriptname = basename($0);
print STDERR "
Usage:
$scriptname --help
--help
displays usage
$scriptname --system=sysname --systemnodes=2 --mrwdir=pathname
--build=hb --nodeCount=nodeCount
--system=systemname
Specify which system MRW XML to be generated
The system name will be set as uppercase
--systemnodes=systemnodesinbrazos
Specify number of nodes for brazos system, by default it is 4
--mrwdir=pathname
Specify the complete dir pathname of the MRW. Colon-delimited
list accepted to specify multiple directories to search.
--outfileDir=pathname
Specify the complete dir pathname to where output files should
be created
--build=hb/fsp
Specify if HostBoot build (hb) or FSP build (fsp)
--nodeCount
Specify the max number of nodes for the system
\n";
}
|