summaryrefslogtreecommitdiffstats
path: root/src/build/simics/hb-pnor-mvpd-preload.pl
blob: 39c7d099883e530568d71904af85749a70ccc57a (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
#!/usr/bin/perl
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/build/simics/hb-pnor-mvpd-preload.pl $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2012
#
#  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 other-
#  wise divested of its trade secrets, irrespective of what has
#  been deposited with the U.S. Copyright Office.
#
#  Origin: 30
#
#  IBM_PROLOG_END

use strict;
use File::Temp qw/ tempfile tempdir /;

my $DEBUG = 0;

my $numProcs;
my $numCentPerProc;
my $dataPath = ".";

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

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

my $mvpdFile = "procmvpd.dat";
my $spdFile = "dimmspd.dat";
my $sysMVPD = "sysmvpd.dat";
my $sysSPD = "sysspd.dat";

my $MAX_PROCS = 8;
my $MAX_CENT_PER_PROC = 8;
my $MAX_DIMMS_PER_CENT = 8;


while( $ARGV = shift )
{
    if( $ARGV =~ m/--numProcs/ ||
        $ARGV =~ m/-np/ )
    {
        $numProcs = shift;
    }
    elsif( $ARGV =~ m/--numCentPerProc/ ||
           $ARGV =~ m/-ncpp/ )
    {
        $numCentPerProc = shift;
    }
    elsif( $ARGV =~ m/--dataPath/ ||
           $ARGV =~ m/-dp/ )
    {
        $dataPath = shift;
    }
    else
    {
        usage();
    }
}

debugMsg( "numProcs: $numProcs" );
debugMsg( "numCentPerProc: $numCentPerProc" );

createMVPDData();
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> [-dataPath]\n";
    print "         [-h | --help]\n";
    print "\n";
    print "  -np    --numProcs        Number of Processors in the drawer.\n";
    print "  -ncpp  --numCentPerProc  Number of Centaurs per Processor.\n";
    print "  -dp    --dataPath        Path to where VPD data files are located.\n";
    print "                              Default: ./\n";
    print "  -h  --help               Help/Usage.\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 = "$dataPath/$sysMVPD";

    if( -e $sysMVPDFile )
    {
        # Cleanup any existing files
        system( "rm -rf $sysMVPDFile" );
    }
    
    # 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 < $MAX_PROCS; $proc++ )
    {
        if( $proc < $numProcs )
        {
            # 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" );
    }
    debugMsg( "MVPD Done." );
}

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

    my $cmd;
    my $result;
    my $sourceFile;
    my $sysSPDFile = "$dataPath/$sysSPD";

    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 < $MAX_PROCS; $proc++ )
    {
        for( my $cent = 0; $cent < $MAX_CENT_PER_PROC; $cent++ )
        {
            for( my $dimm = 0; $dimm < $MAX_DIMMS_PER_CENT; $dimm++ )
            {
                if( ($cent < $numCentPerProc) &&
                    ($proc < $numProcs) )
                {
                    # Use the real data to the full image
                    $sourceFile = "$dataPath/$spdFile";
                }
                else
                {
                    # 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" );
    }
    debugMsg( "SPD Done." );
}
OpenPOWER on IntegriCloud