summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiPlatCreateHwpErrParser.pl
blob: 762e7280b63e152ff5b73bfff543920d0f3f24b2 (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
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/hwpf/plat/fapiPlatCreateHwpErrParser.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 otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
#
# Origin: 30
#
# IBM_PROLOG_END_TAG

#
# Purpose:  This perl script will parse HWP Error XML files and create a
#           file containing functions that parses the return code and FFDC
#           data in HWP error logs
#
# Author: Mike Jones
#

use strict;

#------------------------------------------------------------------------------
# Print Command Line Help
#------------------------------------------------------------------------------
my $numArgs = $#ARGV + 1;
if ($numArgs < 2)
{
    print ("Usage: fapiPlatCreateHwpErrParser.pl <output dir> <filename1> <filename2> ...\n");
    print ("  This perl script will parse HWP Error XML files and create\n");
    print ("  a file called fapiPlatHwpErrParser.H that contains functions to\n");
    print ("  parse the return code and FFDC data in HWP error logs\n");
    exit(1);
}

#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
use Digest::MD5 qw(md5_hex);
use XML::Simple;
my $xml = new XML::Simple (KeyAttr=>[]);

# Uncomment to enable debug output
#use Data::Dumper;

#------------------------------------------------------------------------------
# Open output files for writing
#------------------------------------------------------------------------------
my $rcFile = $ARGV[0];
$rcFile .= "/";
$rcFile .= "fapiPlatHwpErrParser.H";
open(TGFILE, ">", $rcFile);

#------------------------------------------------------------------------------
# Print start of file information
#------------------------------------------------------------------------------
print TGFILE "// fapiPlatHwpErrParser.H\n";
print TGFILE "// This file is generated by perl script fapiPlatCreateHwpErrParser.pl\n\n";
print TGFILE "#ifndef FAPIPLATHWPERRPARSER_H_\n";
print TGFILE "#define FAPIPLATHWPERRPARSER_H_\n\n";
print TGFILE "#ifdef PARSER\n\n";
print TGFILE "namespace fapi\n";
print TGFILE "{\n\n";
print TGFILE "void fapiParseHwpRc(ErrlUsrParser & i_parser,\n";
print TGFILE "                    void * i_pBuffer,\n";
print TGFILE "                    const uint32_t i_buflen)\n";
print TGFILE "{\n";
print TGFILE "    uint32_t l_rc = ntohl(*(static_cast<uint32_t *>(i_pBuffer)));\n\n";
print TGFILE "    switch(l_rc)\n";
print TGFILE "    {\n";

#------------------------------------------------------------------------------
# For each XML file
#------------------------------------------------------------------------------
foreach my $argnum (1 .. $#ARGV)
{
    #--------------------------------------------------------------------------
    # Read XML file
    #--------------------------------------------------------------------------
    my $infile = $ARGV[$argnum];
    my $errors = $xml->XMLin($infile, ForceArray => ['hwpError']);

    # Uncomment to get debug output of all errors
    #print "\nFile: ", $infile, "\n", Dumper($errors), "\n";

    #--------------------------------------------------------------------------
    # For each Error
    #--------------------------------------------------------------------------
    foreach my $err (@{$errors->{hwpError}})
    {
        #----------------------------------------------------------------------
        # Get the description, remove newlines, leading and trailing spaces and
        # multiple spaces
        #----------------------------------------------------------------------
        my $desc = $err->{description};
        $desc =~ s/\n/ /g;
        $desc =~ s/^ +//g;
        $desc =~ s/ +$//g;
        $desc =~ s/ +/ /g;

        #----------------------------------------------------------------------
        # Print the RC description
        # Note that this uses the same code to calculate the error enum value
        # as fapiParseErrorInfo.pl. This code must be kept in sync
        #----------------------------------------------------------------------
        my $errHash128Bit = md5_hex($err->{rc});
        my $errHash24Bit = substr($errHash128Bit, 0, 6);

        print TGFILE "    case 0x$errHash24Bit:\n";
        print TGFILE "        i_parser.PrintString(\"HWP Error description\", \"$desc\");\n";
        print TGFILE "        break;\n";
    }
}

#------------------------------------------------------------------------------
# Print end of fapiParseHwpRc function
#------------------------------------------------------------------------------
print TGFILE "    default:\n";
print TGFILE "        i_parser.PrintNumber(\"Unrecognized Error ID\", \"0x%x\", l_rc);\n";
print TGFILE "    }\n";
print TGFILE "}\n\n";

#------------------------------------------------------------------------------
# Print start of fapiParseHwpFfdc function
#------------------------------------------------------------------------------
print TGFILE "void fapiParseHwpFfdc(ErrlUsrParser & i_parser,\n";
print TGFILE "                      void * i_pBuffer,\n";
print TGFILE "                      const uint32_t i_buflen)\n";
print TGFILE "{\n";
print TGFILE "    const uint32_t CFAM_DATA_LEN = 4;\n";
print TGFILE "    const uint32_t SCOM_DATA_LEN = 8;\n";
print TGFILE "    uint8_t * l_pBuffer = static_cast<uint8_t *>(i_pBuffer);\n";
print TGFILE "    int32_t l_buflen = i_buflen;\n\n";
print TGFILE "    // The first uint32_t is the FFDC ID\n";
print TGFILE "    uint32_t * l_pFfdcId = static_cast<uint32_t *>(i_pBuffer);\n";
print TGFILE "    uint32_t l_ffdcId = ntohl(*l_pFfdcId);\n";
print TGFILE "    l_pBuffer += sizeof(l_ffdcId);\n";
print TGFILE "    l_buflen -= sizeof(l_ffdcId);\n";
print TGFILE "    switch(l_ffdcId)\n";
print TGFILE "    {\n";

#------------------------------------------------------------------------------
# For each XML file
#------------------------------------------------------------------------------
foreach my $argnum (1 .. $#ARGV)
{
    #--------------------------------------------------------------------------
    # Read XML file
    #--------------------------------------------------------------------------
    my $infile = $ARGV[$argnum];
    my $errors = $xml->XMLin($infile, ForceArray =>
        ['hwpError', 'ffdc', 'registerFfdc', 'cfamRegister', 'scomRegister']);

    # Uncomment to get debug output of all errors
    #print "\nFile: ", $infile, "\n", Dumper($errors), "\n";

    #--------------------------------------------------------------------------
    # If it is an FFDC section resulting from a <hwpError><ffdc> element, print
    # out the FFDC name and hexdump the data
    #--------------------------------------------------------------------------
    foreach my $err (@{$errors->{hwpError}})
    {
        foreach my $ffdc (@{$err->{ffdc}})
        {
            #------------------------------------------------------------------
            # Figure out the FFDC ID stored in the data. This is calculated in
            # the same way as fapiParseErrorInfo.pl. This code must be kept in
            # sync
            #------------------------------------------------------------------
            my $ffdcName = $err->{rc} . "_";
            $ffdcName = $ffdcName . $ffdc;
            my $ffdcHash128Bit = md5_hex($ffdcName);
            my $ffdcHash32Bit = substr($ffdcHash128Bit, 0, 8);

            print TGFILE "    case 0x$ffdcHash32Bit:\n";
            print TGFILE "        i_parser.PrintString(\"FFDC:\", \"$ffdcName\");\n";
            print TGFILE "        if (l_buflen) ";
            print TGFILE "{i_parser.PrintHexDump(l_pBuffer, l_buflen);}\n";
            print TGFILE "        break;\n";
        }
    }

    #--------------------------------------------------------------------------
    # If it is an FFDC section resulting from a <registerFfdc> element, print
    # out the ID and walk through the registers, printing each out
    #--------------------------------------------------------------------------
    foreach my $registerFfdc (@{$errors->{registerFfdc}})
    {
        #----------------------------------------------------------------------
        # Figure out the FFDC ID stored in the data. This is calculated in the
        # same way as fapiParseErrorInfo.pl. This code must be kept in sync
        #----------------------------------------------------------------------
        my $ffdcName = $registerFfdc->{id};
        my $ffdcHash128Bit = md5_hex($ffdcName);
        my $ffdcHash32Bit = substr($ffdcHash128Bit, 0, 8);
        print TGFILE "    case 0x$ffdcHash32Bit:\n";
        print TGFILE "        i_parser.PrintString(\"Register FFDC:\", \"$ffdcName\");\n";

        foreach my $cfamRegister (@{$registerFfdc->{cfamRegister}})
        {
            print TGFILE "        l_buflen -= CFAM_DATA_LEN;\n";
            print TGFILE "        if (l_buflen)\n";
            print TGFILE "        {\n";
            print TGFILE "            i_parser.PrintString(NULL, \"$cfamRegister\");\n";
            print TGFILE "            i_parser.PrintHexDump(l_pBuffer, CFAM_DATA_LEN);\n";
            print TGFILE "        }\n";
            print TGFILE "        l_pBuffer+= CFAM_DATA_LEN;\n";
        }

        foreach my $scomRegister (@{$registerFfdc->{scomRegister}})
        {
            print TGFILE "        l_buflen -= SCOM_DATA_LEN;\n";
            print TGFILE "        if (l_buflen)\n";
            print TGFILE "        {\n";
            print TGFILE "            i_parser.PrintString(NULL, \"$scomRegister\");\n";
            print TGFILE "            i_parser.PrintHexDump(l_pBuffer, SCOM_DATA_LEN);\n";
            print TGFILE "        }\n";
            print TGFILE "        l_pBuffer+= SCOM_DATA_LEN;\n";
        }

        print TGFILE "        break;\n";
    }
}

#------------------------------------------------------------------------------
# Print end of fapiParseHwpFfdc function
#------------------------------------------------------------------------------
print TGFILE "    default:\n";
print TGFILE "        i_parser.PrintNumber(\"Unrecognized FFDC\", \"0x%x\", l_ffdcId);\n";
print TGFILE "    }\n\n";
print TGFILE "}\n\n";

#------------------------------------------------------------------------------
# Print end of file info
#------------------------------------------------------------------------------
print TGFILE "}\n\n";
print TGFILE "#endif\n";
print TGFILE "#endif\n";

#------------------------------------------------------------------------------
# Close output file
#------------------------------------------------------------------------------
close(TGFILE);

OpenPOWER on IntegriCloud