summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiCreateHwpErrorTags.pl
blob: 572d7360e0742fe6821c97c6b01e14cbb1266595 (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
#!/usr/bin/perl
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/usr/hwpf/plat/fapiCreateHwpErrorTags.pl $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2011
#
#  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

#
# Purpose:  This perl script will parse HWP Error XML files and create required
#           HostBoot ReasonCodes and Error Log Tags. It creates file
#           fapiHwpReasonCodes.H:
#
# Author: Mike Jones
#

use strict;

#------------------------------------------------------------------------------
# Print Command Line Help
#------------------------------------------------------------------------------
my $numArgs = $#ARGV + 1;
if ($numArgs < 2)
{
    print ("Usage: fapiCreateHwpErrorTags.pl <output dir> <filename1> <filename2> ...\n");
    print ("  This perl script will parse HWP Error XML files and create\n");
    print ("  required HostBoot ReasonCodes and Error Log tags\n");
    exit(1);
}

#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
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 .= "fapiHwpReasonCodes.H";
open(TGFILE, ">", $rcFile);

#------------------------------------------------------------------------------
# Print start of file information
#------------------------------------------------------------------------------
print TGFILE "// fapiHwpReasonCodes.H\n";
print TGFILE "// This file is generated by perl script fapiCreateHwpErrorTags.pl\n\n";
print TGFILE "#ifndef FAPIHWPREASONCODES_H_\n";
print TGFILE "#define FAPIHWPREASONCODES_H_\n\n";
print TGFILE "#include <fapiHwpReturnCodes.H>\n\n";
print TGFILE "namespace fapi\n";
print TGFILE "{\n\n";
print TGFILE "enum hwpReasonCode\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);

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

    #--------------------------------------------------------------------------
    # For each Error
    #--------------------------------------------------------------------------
    foreach my $err (@{$errors->{hwpError}})
    {
        #----------------------------------------------------------------------
        # Check that expected fields are present
        #----------------------------------------------------------------------
        if (! exists $err->{rc})
        {
            print ("fapiParseErrorInfo.pl ERROR. rc missing\n");
            exit(1);
        }

        if (! exists $err->{description})
        {
            print ("fapiParseErrorInfo.pl ERROR. description missing\n");
            exit(1);
        }

        #----------------------------------------------------------------------
        # Print the ReasonCode
        #----------------------------------------------------------------------
        print TGFILE "    __$err->{rc} = HWPF_COMP_ID | $err->{rc},\n";
    }
}

#------------------------------------------------------------------------------
# Print end of reason code enumeration and fapi namespace
#------------------------------------------------------------------------------
print TGFILE "};\n\n";
print TGFILE "}\n\n";

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

    #--------------------------------------------------------------------------
    # For each Error
    #--------------------------------------------------------------------------
    foreach my $err (@{$errors->{hwpError}})
    {
        #----------------------------------------------------------------------
        # Print the Error Log tag
        #----------------------------------------------------------------------
        print TGFILE "/*\@\n";
        print TGFILE " * \@errortype\n";
        print TGFILE " * \@moduleid     MOD_HWP_RC_TO_ERRL\n";
        print TGFILE " * \@reasoncode   __$err->{rc}\n";
        print TGFILE " * \@devdesc      $err->{description}\n";
        print TGFILE " */\n\n";
    }
}

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

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

OpenPOWER on IntegriCloud