summaryrefslogtreecommitdiffstats
path: root/src/build/simics/hb-pnor-vpd-preload.pl
blob: 77fca18687f2292c164c5ea6a0becb84aa97d826 (plain)
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/simics/hb-pnor-vpd-preload.pl $
#
# IBM CONFIDENTIAL
#
# COPYRIGHT International Business Machines Corp. 2012,2014
#
# p1
#
# Object Code Only (OCO) source materials
# Licensed Internal Code Source Materials
# IBM HostBoot Licensed Internal Code
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
#
# Origin: 30
#
# IBM_PROLOG_END_TAG
use strict;
use File::Temp qw/ tempfile tempdir /;

my $DEBUG = 0;

my $numProcs;
my $numCentPerProc;
my $dataPath = ".";
my $outputPath = ".";
my $machine = "MURANO";
my $procConfig = "uninit";
my $centConfig = "uninit";
my $maxProcs = 8;

# Create temp file for MVPD
my $emptyMVPDfh;
my $emptyMVPD;
($emptyMVPDfh, $emptyMVPD) = tempfile();

# Create temp file for SPD
my $emptySPDfh;
my $emptySPD;
($emptySPDfh, $emptySPD) = tempfile();

# Create temp file for CVPD
my $emptyCVPDfh;
my $emptyCVPD;
($emptyCVPDfh, $emptyCVPD) = tempfile();

my $mvpdFile = "procmvpd.dat";
my $cvpdFile = "cvpd.dat";
my $spdFile = "dimmspd.dat";
my $sysMVPD = "sysmvpd.dat";
my $sysCVPD = "syscvpd.dat";
my $sysSPD = "sysspd.dat";


my $MAX_CENT_PER_PROC = 8;
my $MAX_DIMMS_PER_CENT = 8;
my $MAX_MCS = 8;

my @mcsArray = ( 0,0,0,0,0,0,0,0 );


while( $ARGV = shift )
{
    if( $ARGV =~ m/--numProcs/ ||
        $ARGV =~ m/-np/ )
    {
        $numProcs = shift;
        debugMsg( "Num Procs: $numProcs" );
    }
    elsif( $ARGV =~ m/--maxProcs/ ||
           $ARGV =~ m/-mp/ )
    {
        $maxProcs = shift;
    }
    elsif( $ARGV =~ m/--numCentPerProc/ ||
           $ARGV =~ m/-ncpp/ )
    {
        $numCentPerProc = shift;
        debugMsg( "Num Centaurs Per Proc: $numCentPerProc" );
    }
    elsif( $ARGV =~ m/--dataPath/ ||
        $ARGV =~ m/-dp/ )
    {
        $dataPath = shift;
        debugMsg( "Data Path: $dataPath" );
    }
    elsif( $ARGV =~ m/--machine/ ||
        $ARGV =~ m/-m/ )
    {
        $machine = shift;
        debugMsg( "Machine: $machine" );
    }
    elsif( $ARGV =~ m/--outputPath/ ||
           $ARGV =~ m/-op/ )
    {
        $outputPath = shift;
    }
    elsif( $ARGV =~ m/--forceProc/ ||
           $ARGV =~ m/-fp/ )
    {
        $procConfig = shift;
    }
    elsif( $ARGV =~ m/--forceCent/ ||
           $ARGV =~ m/-fc/ )
    {
        $centConfig = shift;
        if(length($centConfig) != $MAX_MCS)
        {
            print "\nERROR: --forceCent/-fc arg must define presence for all $MAX_MCS Centaurs\n\n\n";
            usage();
        }
    }
    elsif( $ARGV =~ m/--examples/ ||
           $ARGV =~ m/-e/ )
    {
        examples();
    }
    else
    {
        usage();
    }
}

#figure out default procConfig if one was not specified.
#if procConfig was specified, validate it's length.
if( $procConfig =~ m/uninit/ )
{
    $procConfig = "";
    for( my $proc = 0; $proc < $maxProcs; $proc++ )
    {
        if( $proc < $numProcs )
        {
            $procConfig = $procConfig."1";
        }
        else
        {
            $procConfig = $procConfig."0";
        }
    }
}
elsif(length($procConfig) != $maxProcs)
{
    print "ERROR: forceProc arg must specify presence of same number of procs as indicated by maxProcs($maxProcs)\n";
    exit 1;
}

getCentaurConfig();
createMVPDData();
createCVPDData();
createSPDData();
cleanup();

print "PNOR VPD Data Build Complete.\n";
exit 0;

############################################
# End of Main program
############################################

#====================================================================
# Usage Message
#====================================================================
sub usage
{
    print "Usage: $0 --numProcs <value> [--numCentPerProc <value>]\n";
    print "         [--dataPath <path> ] [-m | --machine <value>]\n";
    print "         [-mp | --maxProcs <value>]\n";
    print "         [-fp | --forceProc <value ] [-fc | -forceCent <value>]\n";
    print "         [-h | --help]\n";
    print "\n";
    print "  -np    --numProcs        Number of Processors in the drawer.\n";
    print "  -mp    --maxProcs        Max number of Proc records created.\n";
    print "  -fp    --forceProc       Force specific procs to be present.\n";
    print "  -ncpp  --numCentPerProc  Number of Centaurs per Processor.\n";
    print "                             not required with --forceCent.\n";
    print "  -fc    --forceCent       Force specifc Centaurs to be present\n";
    print "                           behind each processor. Must always\n";
    print "                           contain info for 8 Centaurs\n";
    print "                           --numCentPerProc\n";
    print "  -m     --machine         Text machine to build data for.\n";
    print "                              Default: MURANO\n";
    print "  -dp    --dataPath        Path to VPD data files.\n";
    print "  -op    --outputPath      Path where VPD files should end up.\n";
    print "                              Default: ./\n";
    print "  -h  --help               Help/Usage.\n";
    print "  -e  --examples           List some example use cases.\n";
    print "\n\n";
    exit 1;
}

#====================================================================
# Examples Message
#====================================================================
sub examples
{
    print "Following are some Examples of common use-cases for this tool\n";
    print "\n";
    print "Create System Specfic image with standard plugging:\n";
    print "$0 --numProcs 2 --numCentPerProc 2 --machine MURANO";
    print "   --dataPath <path to input dat files>\n";
    print "\n";
    print "Create a VPO image with explicit Proc and Centaur plugging\n";
    print "   This will result in VPD for the first to proc and Centuars\n";
    print "   behind MCS0 and MCS1 on each processor\n";
    print "   NOTE: for VPO, maxProcs must be set to 4\n";
    print "$0 --maxProcs 4 --forceProc 1100 --forceCent 11000000";
    print "   --dataPath <path to input dat files>\n";
    print "\n\n";
    exit 1;
}

#====================================================================
# Print Debug Messages
#====================================================================
sub debugMsg
{
    my ($msg) = @_;
    if( $DEBUG )
    {
        print "DEBUG: $msg\n";
    }
}

#====================================================================
# Cleanup
#====================================================================
sub cleanup
{
    print "Cleaning up...\n";
    my $cmd = "rm -rf $emptyMVPD $emptySPD";
    system( $cmd ) == 0 or die "Failure to cleanup!";
}

#====================================================================
# Create the MVPD data for PNOR
#====================================================================
sub createMVPDData
{
    print "Creating MVPD Data...\n";

    my $cmd;
    my $result;
    my $sourceFile;
    my $sysMVPDFile = "$outputPath/$sysMVPD";
    my $sysMVPDFileECC = $sysMVPDFile . ".ecc";

    if( -e $sysMVPDFile )
    {
        # Cleanup any existing files
        system( "rm -rf $sysMVPDFile" );
    }

    # Currently it looks like all processors are populated in the order that
    # they are numbered.  The following logic should work for every platform.
    # If this ever changes, building the MVPD data and SPD data will need to
    # be combined to not duplicate the logic for determining which processors
    # have which DIMMs.

    # Create empty processor MVPD chunk.
    $cmd = "echo \"00FFFF: 00\" \| xxd -r \> $emptyMVPD";
    system( $cmd ) == 0 or die "Creating $emptyMVPD failed!";

    for( my $proc = 0; $proc < $maxProcs; $proc++ )
    {
        if( substr($procConfig,$proc,1) =~ /1/ )
        {
            # Use real data to the full image.
            $sourceFile = "$dataPath/$mvpdFile";
        }
        else
        {
            # No processor, use empty data chunk.
            $sourceFile = $emptyMVPD;
        }

        $result = `dd if=$sourceFile of=$sysMVPDFile conv=notrunc oflag=append 2>&1 1>/dev/null`;
        if( $? )
        {
            debugMsg( "Failed to create: $sysMVPDFile, using source: $sourceFile" );
            die "Error building MVPD file! $proc\n";
        }
    }

    if( -e $sysMVPDFile )
    {
        system( "chmod 775 $sysMVPDFile" );
        system( "ecc --inject $sysMVPDFile --output $sysMVPDFileECC --p8" );
        system( "chmod 775 $sysMVPDFileECC" );
    }
    debugMsg( "MVPD Done." );
}

#====================================================================
# Create the CVPD data for PNOR
#====================================================================
sub createCVPDData
{
    print "Creating CVPD Data...\n";

    my $cmd;
    my $result;
    my $sourceFile;
    my $sysCVPDFile = "$outputPath/$sysCVPD";
    my $sysCVPDFileECC = $sysCVPDFile . ".ecc";

    if( -e $sysCVPDFile )
    {
        # Cleanup any existing files
        system( "rm -rf $sysCVPDFile" );
    }

    #Centaurs are populated based on populated Processors and special
    #MCS plugging rules.  We can look at $procConfig and $maxProcs
    #to determine processor config.  Centaur plugging is contained
    #in $mcsArray, populated by getCentaurConfig()

    # Create empty CVPD data chunk
    $cmd = " echo \"000FFF: 00\" \| xxd -r \> $emptyCVPD";
    system( $cmd ) == 0 or die "Creating $emptyCVPD failed!";

    for( my $proc = 0; $proc < $maxProcs; $proc++ )
    {
        for( my $cent = 0; $cent < $MAX_CENT_PER_PROC; $cent++ )
        {
            if( ($mcsArray[$cent] == 1) &&
                substr($procConfig,$proc,1) =~ /1/ )
            {
                debugMsg( "$machine( $proc, $cent): Real File" );
                # Use the real data to the full image
                $sourceFile = "$dataPath/$cvpdFile";
            }
            else
            {
                debugMsg( "$machine( $proc, $cent): Empty file" );
                # No Centaur, use empty data chunk
                $sourceFile = $emptyCVPD;
            }

            $result = `dd if=$sourceFile of=$sysCVPDFile conv=notrunc oflag=append 2>&1 1>/dev/null`;
            if( $? )
            {
                die "Error building CVPD file! proc=$proc cent=$cent\n";
            }

        }
    }

    if( -e $sysCVPDFile )
    {
        system( "chmod 775 $sysCVPDFile" );
        system( "ecc --inject $sysCVPDFile --output $sysCVPDFileECC --p8" );
        system( "chmod 775 $sysCVPDFileECC" );
    }
    debugMsg( "CVPD Done." );
}


#====================================================================
# Create the SPD data for PNOR
#====================================================================
sub createSPDData
{
    print "Creating SPD Data...\n";

    my $cmd;
    my $result;
    my $sourceFile;
    my $sysSPDFile = "$outputPath/$sysSPD";
    my $sysSPDFileECC = $sysSPDFile . ".ecc";

    if( -e $sysSPDFile )
    {
        # Cleanup any existing files
        system( "rm -rf $sysSPDFile" );
    }

    # Create empty SPD data chunk
    $cmd = " echo \"0001FF: 00\" \| xxd -r \> $emptySPD";
    system( $cmd ) == 0 or die "Creating $emptySPD failed!";

    for( my $proc = 0; $proc < $maxProcs; $proc++ )
    {
        for( my $cent = 0; $cent < $MAX_CENT_PER_PROC; $cent++ )
        {
            for( my $dimm = 0; $dimm < $MAX_DIMMS_PER_CENT; $dimm++ )
            {
                if( ($mcsArray[$cent] == 1) &&
                    substr($procConfig,$proc,1) =~ /1/ )
                {
                    debugMsg( "$machine( $proc, $cent, $dimm ): Real File" );
                    # Use the real data to the full image
                    $sourceFile = "$dataPath/$spdFile";
                }
                else
                {
                    debugMsg( "$machine( $proc, $cent, $dimm ): Empty file" );
                    # No dimm, use empty data chunk
                    $sourceFile = $emptySPD;
                }

                $result = `dd if=$sourceFile of=$sysSPDFile conv=notrunc oflag=append 2>&1 1>/dev/null`;
                if( $? )
                {
                    die "Error building SPD file! $proc  $cent  $dimm\n";
                }
            }
        }
    }


    if( -e $sysSPDFile )
    {
        system( "chmod 775 $sysSPDFile" );
        system( "ecc --inject $sysSPDFile --output $sysSPDFileECC --p8" );
        system( "chmod 775 $sysSPDFileECC" );
    }
    debugMsg( "SPD Done." );
}


sub getCentaurConfig
{
    debugMsg( "getCentaurConfig $machine" );

    #First check if explicit Centaur Plugging rules were provided
    if( $centConfig !~ m/uninit/ )
    {
        for( my $mcs = 0; $mcs < $MAX_MCS; $mcs++ )
        {
            if( substr($centConfig,$mcs,1) =~ /1/ )
            {
                $mcsArray[$mcs] = 1;
            }
            else
            {
                $mcsArray[$mcs] = 0;
            }
        }
    }
    else
    {
        #use pre-defined Centaur Plugging order
        for( my $mcs = 0; $mcs < $MAX_MCS; $mcs++ )
        {
            debugMsg( "Mcs: $mcs" );
            if( $machine eq "MURANO" )
            {
                # Plugging order is:
                #   Processor 0 - 3
                #   MCS 4 - 7 (1 Centaur/MCS)
                if( $mcs >= 4 &&
                    $mcs <= (4 + ($numCentPerProc - 1)) )
                {
                    $mcsArray[$mcs] = 1;
                }
            }
            elsif( $machine eq "VENICE" )
            {
                # Plugging order is:
                #   Processor 0 - 7
                #   MCS 4 - 7, then 0 - 3
                if( ($numCentPerProc <= 4) &&
                    ($mcs >= 4) &&
                    ($mcs <= (4 + ($numCentPerProc - 1))) )
                {
                    $mcsArray[$mcs] = 1;
                }
                elsif( $numCentPerProc > 4 )
                {
                    if( $mcs >= 4 &&
                        $mcs <= 7 )
                    {
                        $mcsArray[$mcs] = 1;
                    }
                    elsif( $mcs >= 0 &&
                           $mcs < ($numCentPerProc - 4) )
                    {
                        $mcsArray[$mcs] = 1;
                    }
                }
            }
            elsif( $machine eq "TULETA" )
            {
                # Plugging order is:
                #   Processor 0 - 3
                #   MCS 4 - 7, then 0 - 3 (1 Centaur/MCS)
                if( ($numCentPerProc <= 4) &&
                    ($mcs >= 4) &&
                    ($mcs <= (4 + ($numCentPerProc - 1))) )
                {
                    $mcsArray[$mcs] = 1;
                }
                elsif( $numCentPerProc > 4 )
                {
                    if( $mcs >= 4 &&
                        $mcs <= 7 )
                    {
                        $mcsArray[$mcs] = 1;
                    }
                    elsif( $mcs >= 0 &&
                           $mcs < ($numCentPerProc - 4) )
                    {
                        $mcsArray[$mcs] = 1;
                    }
                }
            }
            else
            {
                die "Invalid machine ($machine)!!!  Cannot preload DIMM VPD data...exiting.";
            }
        }
    }

    debugMsg( "@mcsArray" );


}
OpenPOWER on IntegriCloud