diff options
author | Mike Jones <mjjones@us.ibm.com> | 2011-11-17 19:38:31 -0600 |
---|---|---|
committer | MIKE J. JONES <mjjones@us.ibm.com> | 2011-11-21 12:07:50 -0600 |
commit | 11c80c5abcf203e5a65098ea047fd6d2a6e607cc (patch) | |
tree | 1e1a5246e8ed0b25b66e6e1e34bba7622f63bbea /src/usr/hwpf/fapi | |
parent | b9d93e82a069b6650f3bd7b43abe6aecc0bf2e4e (diff) | |
download | blackbird-hostboot-11c80c5abcf203e5a65098ea047fd6d2a6e607cc.tar.gz blackbird-hostboot-11c80c5abcf203e5a65098ea047fd6d2a6e607cc.zip |
HWPF: Only support initfile attributes in fapiGetInitFileAttr()
Change-Id: Ia1ffa854d55b68f0e32595080bba323cd52e23a3
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/503
Tested-by: Jenkins Server
Reviewed-by: Andrew J. Geissler <andrewg@us.ibm.com>
Reviewed-by: CAMVAN T. NGUYEN <ctnguyen@us.ibm.com>
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/usr/hwpf/fapi')
-rwxr-xr-x | src/usr/hwpf/fapi/fapiCreateIfAttrService.pl | 264 | ||||
-rwxr-xr-x | src/usr/hwpf/fapi/fapiParseAttributeInfo.pl | 95 |
2 files changed, 269 insertions, 90 deletions
diff --git a/src/usr/hwpf/fapi/fapiCreateIfAttrService.pl b/src/usr/hwpf/fapi/fapiCreateIfAttrService.pl new file mode 100755 index 000000000..ab71d80e0 --- /dev/null +++ b/src/usr/hwpf/fapi/fapiCreateIfAttrService.pl @@ -0,0 +1,264 @@ +#!/usr/bin/perl +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/hwpf/fapi/fapiCreateIfAttrService.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 Attribute XML files and +# initfile attr files and create the fapiGetInitFileAttr() function +# in a file called fapiAttributeService.C +# +# Author: Mike Jones +# +# Change Log ********************************************************** +# +# Flag Track# Userid Date Description +# ---- -------- -------- -------- ----------- +# mjjones 11/15/11 Copied from fapiParseAttributeInfo +# +# End Change Log ****************************************************** + +use strict; + +#------------------------------------------------------------------------------ +# Print Command Line Help +#------------------------------------------------------------------------------ +my $numArgs = $#ARGV + 1; +if ($numArgs < 4) +{ + print ("Usage: fapiCreateIfAttrService.pl <output dir>\n"); + print (" <if-attr-file1> [<if-attr-file2> ...]\n"); + print (" -a <attr-xml-file1> [<attr-xml-file2> ...]\n"); + print (" This perl script will parse initfile attr files and attribute XML\n"); + print (" files and create the fapiGetInitFileAttr() function in a file\n"); + print (" called fapiAttributeService.C\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 file for writing +#------------------------------------------------------------------------------ +my $asFile = $ARGV[0]; +$asFile .= "/"; +$asFile .= "fapiAttributeService.C"; +open(ASFILE, ">", $asFile); + +#------------------------------------------------------------------------------ +# Print Start of file information to fapiAttributeService.C +#------------------------------------------------------------------------------ +print ASFILE "// fapiAttributeService.C\n"; +print ASFILE "// This file is generated by perl script fapiCreateIfAttrService.pl\n\n"; +print ASFILE "#include <fapiAttributeService.H>\n\n"; +print ASFILE "namespace fapi\n"; +print ASFILE "{\n\n"; +print ASFILE "ReturnCode fapiGetInitFileAttr(const AttributeId i_id,\n"; +print ASFILE " const Target * i_pTarget,\n"; +print ASFILE " uint64_t & o_val,\n"; +print ASFILE " const uint32_t i_arrayIndex1,\n"; +print ASFILE " const uint32_t i_arrayIndex2,\n"; +print ASFILE " const uint32_t i_arrayIndex3,\n"; +print ASFILE " const uint32_t i_arrayIndex4)\n"; +print ASFILE "{\n"; +print ASFILE " ReturnCode l_rc;\n\n"; + +my $xmlFiles = 0; +my $attCount = 0; +my @attrIds; + +#------------------------------------------------------------------------------ +# For each argument +#------------------------------------------------------------------------------ +foreach my $argnum (1 .. $#ARGV) +{ + my $infile = $ARGV[$argnum]; + + if ($infile eq '-a') + { + # Start of attribute XML files + $xmlFiles = 1; + next; + } + + if ($xmlFiles == 0) + { + #---------------------------------------------------------------------- + # Process initfile attr file. This file contains the HWPF attributes + # that the initfile uses. + #---------------------------------------------------------------------- + open(ATTRFILE, "<", $infile); + + # Read each line of the file (each line contains an attribute) + while(my $fileAttrId = <ATTRFILE>) + { + # Remove newline + chomp($fileAttrId); + + # Store the attribute in @attrIds if it does not already exist + my $match = 0; + + foreach my $attrId (@attrIds) + { + if ($fileAttrId eq $attrId) + { + $match = 1; + last; + } + } + + if (!($match)) + { + push(@attrIds, $fileAttrId); + } + } + + close(ATTRFILE); + } + else + { + #---------------------------------------------------------------------- + # Process XML file + #---------------------------------------------------------------------- + my $attributes = $xml->XMLin($infile); + + #---------------------------------------------------------------------- + # For each Attribute + #---------------------------------------------------------------------- + foreach my $attr (@{$attributes->{attribute}}) + { + #------------------------------------------------------------------ + # Check that the AttributeId exists + #------------------------------------------------------------------ + if (! exists $attr->{id}) + { + print ("fapiParseAttributeInfo.pl ERROR. Att 'id' missing\n"); + exit(1); + } + + #------------------------------------------------------------------ + # Find if the attribute is used by any initfile + #------------------------------------------------------------------ + my $match = 0; + + foreach my $attrId (@attrIds) + { + if ($attr->{id} eq $attrId) + { + $match = 1; + last; + } + } + + if (!($match)) + { + # Look at the next attribute in the XML file + next; + } + + #------------------------------------------------------------------ + # Figure out the number of attribute array dimensions + #------------------------------------------------------------------ + my $numArrayDimensions = 0; + if ($attr->{array}) + { + # Remove leading whitespace + my $dimText = $attr->{array}; + $dimText =~ s/^\s+//; + + # Split on commas or whitespace + my @vals = split(/\s*,\s*|\s+/, $dimText); + + $numArrayDimensions=@vals; + } + + #------------------------------------------------------------------ + # Print the attribute get code to fapiAttributeService.C + #------------------------------------------------------------------ + if ($attCount > 0) + { + print ASFILE " else "; + } + else + { + print ASFILE " "; + } + $attCount++; + + print ASFILE "if (i_id == $attr->{id})\n"; + print ASFILE " {\n"; + print ASFILE " $attr->{id}_Type l_attr;\n"; + print ASFILE " l_rc = FAPI_ATTR_GET($attr->{id}, i_pTarget, l_attr);\n"; + print ASFILE " o_val = l_attr"; + + if ($numArrayDimensions >= 5) + { + print ("fapiParseAttributeInfo.pl ERROR. More than 4 array dimensions!!\n"); + exit(1); + } + else + { + for (my $i = 0; $i < $numArrayDimensions; $i++) + { + print ASFILE "[i_arrayIndex"; + print ASFILE $i+1; + print ASFILE "]"; + } + } + + print ASFILE ";\n"; + print ASFILE " }\n"; + } + } +} + +#------------------------------------------------------------------------------ +# Print End of file information to fapiAttributeService.C +#-------------------------------------------------------------------------- +if ($attCount > 0) +{ + print ASFILE " else\n"; +} +print ASFILE " {\n"; +print ASFILE " FAPI_ERR(\"fapiGetInitFileAttr: Unrecognized attr: %d\", i_id);\n"; +print ASFILE " ReturnCodeFfdc::addEIFfdc(l_rc, static_cast<uint32_t>(i_id));\n"; +print ASFILE " l_rc = FAPI_RC_INVALID_ATTR_GET;\n"; +print ASFILE " }\n\n"; +print ASFILE " if (l_rc)\n"; +print ASFILE " {\n"; +print ASFILE " FAPI_ERR(\"fapiGetInitFileAttr: Error getting attr\");\n"; +print ASFILE " }\n\n"; +print ASFILE " return l_rc;\n"; +print ASFILE "}\n\n"; +print ASFILE "}\n"; + + +#------------------------------------------------------------------------------ +# Close output file +#------------------------------------------------------------------------------ +close(ASFILE); diff --git a/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl b/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl index 333e68440..e493255ec 100755 --- a/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl +++ b/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl @@ -47,13 +47,11 @@ # camvanng 10/20/11 Changed i_pTarget to "const" ptr # camvanng 11/09/11 Prepend "ENUM_" to attribute # enums +# mjjones 11/15/11 Move gen of fapiAttributeService.C +# to a different file # # End Change Log ****************************************************** -# -# Usage: -# fapiParseAttributeInfo.pl <output dir> <filename1> <filename2> ... - use strict; #------------------------------------------------------------------------------ @@ -62,7 +60,7 @@ use strict; my $numArgs = $#ARGV + 1; if ($numArgs < 2) { - print ("Usage: fapiParseAttributeInfo.pl <output dir> <filename1> <filename2> ...\n"); + print ("Usage: fapiParseAttributeInfo.pl <output dir> <attr-xml-file1> [<attr-xml-file2> ...]\n"); print (" This perl script will parse attribute XML files and add\n"); print (" attribute information to a file called fapiAttributeIds.H\n"); exit(1); @@ -78,18 +76,13 @@ my $xml = new XML::Simple (KeyAttr=>[]); #use Data::Dumper; #------------------------------------------------------------------------------ -# Open output files for writing +# Open output file for writing #------------------------------------------------------------------------------ my $aiFile = $ARGV[0]; $aiFile .= "/"; $aiFile .= "fapiAttributeIds.H"; open(AIFILE, ">", $aiFile); -my $asFile = $ARGV[0]; -$asFile .= "/"; -$asFile .= "fapiAttributeService.C"; -open(ASFILE, ">", $asFile); - #------------------------------------------------------------------------------ # Print Start of file information to fapiAttributeIds.H #------------------------------------------------------------------------------ @@ -105,24 +98,6 @@ print AIFILE " *\/\n"; print AIFILE "enum AttributeId\n{\n"; #------------------------------------------------------------------------------ -# Print Start of file information to fapiAttributeService.C -#------------------------------------------------------------------------------ -print ASFILE "// fapiAttributeService.C\n"; -print ASFILE "// This file is generated by perl script fapiParseAttributeInfo.pl\n\n"; -print ASFILE "#include <fapiAttributeService.H>\n\n"; -print ASFILE "namespace fapi\n"; -print ASFILE "{\n\n"; -print ASFILE "ReturnCode fapiGetInitFileAttr(const AttributeId i_id,\n"; -print ASFILE " const Target * i_pTarget,\n"; -print ASFILE " uint64_t & o_val,\n"; -print ASFILE " const uint32_t i_arrayIndex1,\n"; -print ASFILE " const uint32_t i_arrayIndex2,\n"; -print ASFILE " const uint32_t i_arrayIndex3,\n"; -print ASFILE " const uint32_t i_arrayIndex4)\n"; -print ASFILE "{\n"; -print ASFILE " ReturnCode l_rc;\n\n"; - -#------------------------------------------------------------------------------ # For each XML file #------------------------------------------------------------------------------ foreach my $argnum (1 .. $#ARGV) @@ -287,47 +262,6 @@ foreach my $argnum (1 .. $#ARGV) # Print newline between each attribute's info to fapiAttributeIds.H #---------------------------------------------------------------------- print AIFILE "\n"; - - #---------------------------------------------------------------------- - # Print the attribute get code to fapiAttributeService.C - # *** TODO *** - # Currently, all attributes are supported in fapiGetInitFileAttr() in - # fapiAttributeService.C. Ideally only the initfile attributes should - # be supported to minimize code size. Need to figure out how to do this - #---------------------------------------------------------------------- - if ($attCount > 0) - { - print ASFILE " else "; - } - else - { - print ASFILE " "; - } - $attCount++; - - print ASFILE "if (i_id == $attr->{id})\n"; - print ASFILE " {\n"; - print ASFILE " $attr->{id}_Type l_attr;\n"; - print ASFILE " l_rc = FAPI_ATTR_GET($attr->{id}, i_pTarget, l_attr);\n"; - print ASFILE " o_val = l_attr"; - - if ($numArrayDimensions >= 5) - { - print ("fapiParseAttributeInfo.pl ERROR. More than 4 array dimensions!!\n"); - exit(1); - } - else - { - for (my $i = 0; $i < $numArrayDimensions; $i++) - { - print ASFILE "[i_arrayIndex"; - print ASFILE $i+1; - print ASFILE "]"; - } - } - - print ASFILE ";\n"; - print ASFILE " }\n"; }; } @@ -338,25 +272,6 @@ print AIFILE "}\n\n"; print AIFILE "#endif\n"; #------------------------------------------------------------------------------ -# Print End of file information to fapiAttributeService.C -#-------------------------------------------------------------------------- -print ASFILE " else\n"; -print ASFILE " {\n"; -print ASFILE " FAPI_ERR(\"fapiGetInitFileAttr: Unrecognized attr: %d\", i_id);\n"; -print ASFILE " ReturnCodeFfdc::addEIFfdc(l_rc, static_cast<uint32_t>(i_id));"; -print ASFILE " l_rc = FAPI_RC_INVALID_ATTR_GET;\n"; -print ASFILE " }\n\n"; -print ASFILE " if (l_rc)\n"; -print ASFILE " {\n"; -print ASFILE " FAPI_ERR(\"fapiGetInitFileAttr: Error getting attr\");\n"; -print ASFILE " }\n\n"; -print ASFILE " return l_rc;\n"; -print ASFILE "}\n\n"; -print ASFILE "}\n"; - - -#------------------------------------------------------------------------------ -# Close output files +# Close output file #------------------------------------------------------------------------------ close(AIFILE); -close(ASFILE); |