Separate building of chip data and parser data files

The PEL parser data files will eventually need to be put in a separate
location from the chip data binary files.

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I83fabd1da51ba04cae0d1cee07b5a820675e98a2
diff --git a/xml/meson.build b/xml/meson.build
index 5e603d7..4bc265e 100644
--- a/xml/meson.build
+++ b/xml/meson.build
@@ -2,7 +2,7 @@
 # Chip Data Files
 #-------------------------------------------------------------------------------
 
-build_cdb = find_program('build_chip_data_binary')
+build_cdb = find_program('parse_chip_data_xml')
 
 # The key for each entry in this dictionary is a subdirectory containing XML for
 # a chip model. The value for each entry contains the expected output files that
@@ -14,14 +14,14 @@
 cdb_files = {
     'p10' :
     [
-        'chip_data_p10_10.cdb', 'chip_parser_p10_10.json',
-        'chip_data_p10_20.cdb', 'chip_parser_p10_20.json',
+        'chip_data_p10_10.cdb',
+        'chip_data_p10_20.cdb',
     ],
 
     'explorer' :
     [
-        'chip_data_explorer_11.cdb', 'chip_parser_explorer_11.json',
-        'chip_data_explorer_20.cdb', 'chip_parser_explorer_20.json',
+        'chip_data_explorer_11.cdb',
+        'chip_data_explorer_20.cdb',
     ],
 }
 
@@ -37,7 +37,9 @@
 
     custom_target('build_cdb_' + chip_dir, build_by_default : true,
                   input : in_files, output : out_files,
-                  command : [ build_cdb, '-i', source_dir, '-o', build_dir ],
+                  command : [ build_cdb, '--cdb',
+                              '-i', source_dir,
+                              '-o', build_dir ],
                   install : true,
                   install_dir : join_paths(get_option('prefix'),
                                            get_option('datadir'),
diff --git a/xml/build_chip_data_binary b/xml/parse_chip_data_xml
similarity index 94%
rename from xml/build_chip_data_binary
rename to xml/parse_chip_data_xml
index 9667a95..77ed61e 100755
--- a/xml/build_chip_data_binary
+++ b/xml/parse_chip_data_xml
@@ -67,12 +67,19 @@
 Usage: $RealScript -h
        $RealScript -i <input_dir> -o <output_dir>
 
-Builds Chip Data Binary files from the input Chip Data XML.
+Generates specified data files from the input Chip Data XML.
 
-Options:
+General options:
+
  -h, --help     Prints this menu.
  -i, --input    Directory containing the Chip Data XML files.
- -o, --output   Directory that will contain the Chip Data Binary files.
+ -o, --output   Directory that will contain the data files.
+
+Data file options (must specify at least one):
+
+ --cdb          Generates Chip Data Binary files.
+ --json         Generates PEL Parser Data JSON files.
+
 EOF
 
     exit;
@@ -85,10 +92,14 @@
 help() unless @ARGV; # print help if no arguments
 
 # Get options
-my ( $help, $src_dir, $dest_dir );
-help() unless GetOptions( 'h|help'     => \$help,
-                          'i|input=s'  => \$src_dir,
-                          'o|output=s' => \$dest_dir );
+my ( $help, $src_dir, $dest_dir, $gen_cdb, $gen_json );
+help() unless GetOptions(
+    'h|help'     => \$help,
+    'i|input=s'  => \$src_dir,
+    'o|output=s' => \$dest_dir,
+    'cdb'        => \$gen_cdb,
+    'json'       => \$gen_json,
+);
 
 help() if @ARGV; # print usage if there are extra arguments
 
@@ -108,13 +119,19 @@
     die "ERROR> $message: $file\n";
 }
 
+# --cdb, --json
+unless ( $gen_cdb or $gen_json )
+{
+    die "ERROR> Must specify at least one data file option.";
+}
+
 #-------------------------------------------------------------------------------
 # Prototypes
 #-------------------------------------------------------------------------------
 
 sub importXML($);
 sub normalizeXML($);
-sub buildBinary($$);
+sub buildDataFiles($$);
 
 #-------------------------------------------------------------------------------
 # Main
@@ -128,7 +145,7 @@
 my $normalized_data = normalizeXML( $chip_data_xml );
 
 # The XML should now be in a format to start building the binary files.
-buildBinary( $dest_dir, $normalized_data );
+buildDataFiles( $dest_dir, $normalized_data );
 
 #-------------------------------------------------------------------------------
 # Helper functions
@@ -1167,7 +1184,7 @@
 
     my $data =
     {
-        'model_ec'  => $model_ec,
+        'model_ec'  => sprintf('%08x', $SUPPORTED_MODEL_EC->{$model_ec}),
         'node_name' => $nodes,
         'reg_name'  => $regs,
         'signature' => $sigs,
@@ -1178,7 +1195,7 @@
 
 #-------------------------------------------------------------------------------
 
-sub buildBinary($$)
+sub buildDataFiles($$)
 {
     my ( $dir, $data ) = @_;
 
@@ -1203,31 +1220,36 @@
 
         # Chip Data Binary files ###############################################
 
-        my $bin_file = "$dir/chip_data_" . lc $model_ec . ".cdb";
-        open my $bin_fh, '>', $bin_file or die "Cannot open $bin_file: $!";
-        binmode $bin_fh; # writes a binary file
+        if ( $gen_cdb )
+        {
+            my $bin_file = "$dir/chip_data_" . lc $model_ec . ".cdb";
+            open my $bin_fh, '>', $bin_file or die "Cannot open $bin_file: $!";
+            binmode $bin_fh; # writes a binary file
 
-        # Chip Data File metadata
-        __bin($bin_fh, 1, $_) for ( unpack("C*", "CHIPDATA") );
-        __bin($bin_fh, 4, $SUPPORTED_MODEL_EC->{$model_ec});
-        __bin($bin_fh, 1, $FILE_VERSION->{VER_01}         );
+            # Chip Data File metadata
+            __bin($bin_fh, 1, $_) for ( unpack("C*", "CHIPDATA") );
+            __bin($bin_fh, 4, $SUPPORTED_MODEL_EC->{$model_ec});
+            __bin($bin_fh, 1, $FILE_VERSION->{VER_01}         );
 
-        __printRegisters( $bin_fh, $chip->{register}  );
-        __printNodes(     $bin_fh, $chip->{node}      );
-        __printAttnTree(  $bin_fh, $chip->{attn_tree} );
+            __printRegisters( $bin_fh, $chip->{register}  );
+            __printNodes(     $bin_fh, $chip->{node}      );
+            __printAttnTree(  $bin_fh, $chip->{attn_tree} );
 
-        close $bin_fh;
+            close $bin_fh;
+        }
 
         # eBMC PEL parsing JSON ################################################
 
-        my $parser_file = "$dir/chip_parser_" . lc $model_ec . ".json";
-        open my $parser_fh, '>', $parser_file
-            or die "Cannot open $parser_file: $!";
+        if ( $gen_json )
+        {
+            my $file = "$dir/pel_parser_data_" . lc $model_ec . ".json";
+            open my $fh, '>', $file or die "Cannot open $file: $!";
 
-        __printParserData( $parser_fh, $model_ec, $chip->{signature},
-                           $chip->{register} );
+            __printParserData( $fh, $model_ec, $chip->{signature},
+                               $chip->{register} );
 
-        close $parser_fh;
+            close $fh;
+        }
     }
 }