#!/usr/bin/perl # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/usr/hwpf/fapi/fapiParseErrorInfo.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 # FAPI code. The FAPI files created are: # # 1/ fapiHwpReturnCodes.H - HwpReturnCode enumeration # FfdcHwpToken enumeration # 2/ fapiCollectFfdc.C - fapiCollectFfdc function implementation # 3/ fapiErrorInfoMemInit.C - ErrorInfoRepositoryMem::init # implementation # # Author: CamVan Nguyen and Mike Jones # # Change Log ********************************************************** # # Flag Track# Userid Date Description # ---- -------- -------- -------- ----------- # camvanng 06/03/11 Created # mjjones 06/06/11 Minor updates for integration # mjjones 06/10/11 Added "use strict;" # mjjones 07/05/11 Take output dir as parameter # mjjones 08/08/11 Large update to create more code # # End Change Log ****************************************************** # # Usage: # fapiParseErrorInfo.pl ... use strict; #------------------------------------------------------------------------------ # Print Command Line Help #------------------------------------------------------------------------------ my $numArgs = $#ARGV + 1; if ($numArgs < 2) { print ("Usage: fapiParseErrorInfo.pl ...\n"); print (" This perl script will parse HWP Error XML files and create\n"); print (" required FAPI code\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 .= "fapiHwpReturnCodes.H"; open(RCFILE, ">", $rcFile); my $ffFile = $ARGV[0]; $ffFile .= "/"; $ffFile .= "fapiCollectFfdc.C"; open(FFFILE, ">", $ffFile); my $miFile = $ARGV[0]; $miFile .= "/"; $miFile .= "fapiErrorInfoMemInit.C"; open(MIFILE, ">", $miFile); #------------------------------------------------------------------------------ # Create arrays of FFDC HWPs and their data types #------------------------------------------------------------------------------ my @ffdcHwps; my @ffdcHwpsData; #------------------------------------------------------------------------------ # Print start of file information to fapiHwpReturnCodes.H #------------------------------------------------------------------------------ print RCFILE "// fapiHwpReturnCodes.H\n"; print RCFILE "// This file is generated by perl script fapiParseErrorInfo.pl\n\n"; print RCFILE "#ifndef FAPIHWPRETURNCODES_H_\n"; print RCFILE "#define FAPIHWPRETURNCODES_H_\n\n"; print RCFILE "namespace fapi\n"; print RCFILE "{\n\n"; print RCFILE "/**\n"; print RCFILE " * \@brief Enumeration of HWP return codes\n"; print RCFILE " *\/\n"; print RCFILE "enum HwpReturnCode\n"; print RCFILE "{\n"; print RCFILE " RC_SUCCESS,\n"; #------------------------------------------------------------------------------ # Print start of file information to fapiCollectFfdc.C #------------------------------------------------------------------------------ print FFFILE "// fapiCollectFfdc.C\n"; print FFFILE "// This file is generated by perl script fapiParseErrorInfo.pl\n\n"; print FFFILE "#include \n"; print FFFILE "#include \n"; print FFFILE "#include \n"; print FFFILE "#include \n"; print FFFILE "#include \n"; print FFFILE "#include \n\n"; print FFFILE "namespace fapi\n"; print FFFILE "{\n\n"; print FFFILE "ReturnCode fapiCollectFfdc(const FfdcHwpToken i_token,\n"; print FFFILE " const Target & i_target,\n"; print FFFILE " uint8_t * & o_pFfdc,\n"; print FFFILE " uint32_t & o_size)\n"; print FFFILE "{\n"; print FFFILE " ReturnCode l_rc;\n\n"; print FFFILE " switch (i_token)\n"; print FFFILE " {\n"; #------------------------------------------------------------------------------ # Print start of file information to fapiErrorInfoMemInit.C #------------------------------------------------------------------------------ print MIFILE "// fapiErrorInfoMemInit.C\n"; print MIFILE "// This file is generated by perl script fapiParseErrorInfo.pl\n\n"; print MIFILE "#include \n\n"; print MIFILE "namespace fapi\n"; print MIFILE "{\n\n"; print MIFILE "void ErrorInfoRepositoryMem::init()\n"; print MIFILE "{\n"; #------------------------------------------------------------------------------ # Element names #------------------------------------------------------------------------------ my $ffdc = 'ffdc'; my $callout = 'callout'; #------------------------------------------------------------------------------ # For each XML file #------------------------------------------------------------------------------ foreach my $argnum (1 .. $#ARGV) { my $infile = $ARGV[$argnum]; #-------------------------------------------------------------------------- # Read XML file. Note that there may be multiple ffdc and callout elements # so use the ForceArray option with these to ensure that XML::Simple # creates an array even for single elements of these types #-------------------------------------------------------------------------- # read XML file my $errors = $xml->XMLin($infile, ForceArray => [$ffdc, $callout]); # 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 return code to fapiHwpReturnCodes.H #---------------------------------------------------------------------- print RCFILE " $err->{rc},\n"; #---------------------------------------------------------------------- # Print the return code and description to fapiErrorInfoMemInit.C #---------------------------------------------------------------------- print MIFILE " {\n"; print MIFILE " ErrorInfoRecord l_record;\n"; print MIFILE " l_record.iv_rc = $err->{rc};\n"; print MIFILE " l_record.setDescription(\"$err->{description}\");\n"; #---------------------------------------------------------------------- # For each Callout element #---------------------------------------------------------------------- foreach my $callout (@{$err->{callout}}) { #------------------------------------------------------------------ # Check that expected fields are present #------------------------------------------------------------------ if (! exists $callout->{targetType}) { print ("fapiParseErrorInfo.pl ERROR. targetType missing\n"); exit(1); } if (! exists $callout->{targetPos}) { print ("fapiParseErrorInfo.pl ERROR. targetPos missing\n"); exit(1); } if (! exists $callout->{priority}) { print ("fapiParseErrorInfo.pl ERROR. priority missing\n"); exit(1); } #------------------------------------------------------------------ # Print the Callout data to fapiErrorInfoMemInit.C #------------------------------------------------------------------ print MIFILE " {\n"; print MIFILE " ErrorInfoCallout l_callout($callout->{targetType}, "; print MIFILE "$callout->{targetPos}, $callout->{priority});\n"; print MIFILE " l_record.iv_callouts.push_back(l_callout);\n"; print MIFILE " }\n"; } #---------------------------------------------------------------------- # For each FFDC element #---------------------------------------------------------------------- foreach my $ffdc (@{$err->{ffdc}}) { #------------------------------------------------------------------ # Check that expected fields are present #------------------------------------------------------------------ if (! exists $ffdc->{targetType}) { print ("fapiParseErrorInfo.pl ERROR. targetType missing\n"); exit(1); } if (! exists $ffdc->{targetPos}) { print ("fapiParseErrorInfo.pl ERROR. targetPos missing\n"); exit(1); } if (! exists $ffdc->{ffdcHwp}) { print ("fapiParseErrorInfo.pl ERROR. ffdcHwp missing\n"); exit(1); } if (! exists $ffdc->{ffdcHwpData}) { print ("fapiParseErrorInfo.pl ERROR. ffdcHwpData missing\n"); exit(1); } #------------------------------------------------------------------ # Print the FFDC data to fapiErrorInfoMemInit.C #------------------------------------------------------------------ print MIFILE " {\n"; print MIFILE " ErrorInfoFfdc l_ffdc($ffdc->{targetType}, "; print MIFILE "$ffdc->{targetPos}, $ffdc->{ffdcHwp}Token);\n"; print MIFILE " l_record.iv_ffdcs.push_back(l_ffdc);\n"; print MIFILE " }\n"; #------------------------------------------------------------------ # Record the FFDC HWP and its data if not already recorded #------------------------------------------------------------------ my $match = 0; foreach my $ffdcHwp (@ffdcHwps) { if ($ffdcHwp eq $ffdc->{ffdcHwp}) { $match = 1; } } if (!($match)) { push(@ffdcHwps, $ffdc->{ffdcHwp}); push(@ffdcHwpsData, $ffdc->{ffdcHwpData}); } } #---------------------------------------------------------------------- # Print the Error Information Record submit to fapiErrorInfoMemInit.C #---------------------------------------------------------------------- print MIFILE " iv_errorInfoRecords.push_back(l_record);\n"; print MIFILE " }\n\n"; } } #------------------------------------------------------------------------------ # Print end of HwpReturnCode enum to fapiHwpReturnCodes.H #------------------------------------------------------------------------------ print RCFILE "};\n\n"; #------------------------------------------------------------------------------ # Print FfdcHwpToken enum to fapiHwpReturnCodes.H #------------------------------------------------------------------------------ print RCFILE "/**\n"; print RCFILE " * \@brief Enumeration of tokens representing FFDC HWPs\n"; print RCFILE " *\/\n"; print RCFILE "enum FfdcHwpToken\n"; print RCFILE "{\n"; foreach my $ffdcHwp (@ffdcHwps) { print RCFILE " $ffdcHwp", "Token,\n"; } print RCFILE "};\n\n"; #------------------------------------------------------------------------------ # Print end of file information to fapiHwpReturnCodes.H #------------------------------------------------------------------------------ print RCFILE "}\n\n"; print RCFILE "#endif\n"; #------------------------------------------------------------------------------ # Print FFDC function calls to fapiCollectFfdc.C #------------------------------------------------------------------------------ for (my $i = 0; $i < scalar(@ffdcHwps); $i++) { print FFFILE " case $ffdcHwps[$i]Token:\n"; print FFFILE " {\n"; print FFFILE " $ffdcHwpsData[$i] l_ffdc;\n"; print FFFILE " FAPI_EXEC_HWP(l_rc, $ffdcHwps[$i], i_target, l_ffdc);\n\n"; print FFFILE " if (!l_rc)\n"; print FFFILE " {\n"; print FFFILE " o_pFfdc = new uint8_t[sizeof(l_ffdc)];\n"; print FFFILE " o_size = sizeof(l_ffdc);\n"; print FFFILE " memcpy(o_pFfdc, &l_ffdc, sizeof(l_ffdc));\n"; print FFFILE " }\n"; print FFFILE " }\n"; print FFFILE " break;\n"; } print FFFILE " default:\n"; print FFFILE " l_rc = FAPI_RC_FFDC_HWP_NOT_FOUND;\n"; print FFFILE " break;\n"; print FFFILE " }\n\n"; print FFFILE " return l_rc;\n"; print FFFILE "}\n\n"; #------------------------------------------------------------------------------ # Print end of file information to fapiCollectFfdc.C #------------------------------------------------------------------------------ print FFFILE "}\n\n"; #------------------------------------------------------------------------------ # Print end of file information to fapiErrorInfoMemInit.C #------------------------------------------------------------------------------ print MIFILE "}\n\n}\n"; #------------------------------------------------------------------------------ # Close output files #------------------------------------------------------------------------------ close(RCFILE); close(FFFILE); close(MIFILE);