summaryrefslogtreecommitdiffstats
path: root/src/build/buildpnor/memd_creation.pl
diff options
context:
space:
mode:
authorElizabeth Liner <eliner@us.ibm.com>2017-08-03 17:44:15 -0500
committerDaniel M. Crowell <dcrowell@us.ibm.com>2017-08-14 11:07:58 -0400
commita53e82a1e8b7efdaff172087101c2eec0d547333 (patch)
tree9d4b46779eaad8d2499d451e9d6315e09f02e8b3 /src/build/buildpnor/memd_creation.pl
parent170106ac6e137d460743cc28ae0082bd76d0a93e (diff)
downloadtalos-hostboot-a53e82a1e8b7efdaff172087101c2eec0d547333.tar.gz
talos-hostboot-a53e82a1e8b7efdaff172087101c2eec0d547333.zip
Adding script to generate Memd header and binary file
Change-Id: Ia16626a5a3370256bf7f1af0cec3f01545c93590 RTC:175158 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/44196 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Reviewed-by: Martin Gloff <mgloff@us.ibm.com> Reviewed-by: Stephen M. Cprek <smcprek@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/build/buildpnor/memd_creation.pl')
-rwxr-xr-xsrc/build/buildpnor/memd_creation.pl176
1 files changed, 176 insertions, 0 deletions
diff --git a/src/build/buildpnor/memd_creation.pl b/src/build/buildpnor/memd_creation.pl
new file mode 100755
index 000000000..aa0298988
--- /dev/null
+++ b/src/build/buildpnor/memd_creation.pl
@@ -0,0 +1,176 @@
+#!/usr/bin/perl
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/build/buildpnor/memd_creation.pl $
+#
+# OpenPOWER HostBoot Project
+#
+# Contributors Listed Below - COPYRIGHT 2017
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+use Pod::Usage;
+use Getopt::Long qw(:config pass_through);
+use strict;
+use File::Basename;
+
+### CONSTANTS ###
+use constant ROUNDING_DIVISOR => 1000;
+use constant HEADER_INPUT_LOCATION => 12;
+
+print "Creating MEMD binary...\n";
+
+# Header format:
+# uint32_t eyecatch /* Eyecatch to determine validity "OKOK" */
+# uint32_t header_version /* What version of the header this is in */
+# uint32_t memd_version /* What version of the MEMD this includes */
+# uint32_t expected_size /* Size in megabytes of the biggest MEMD section */
+# uint16_t expected_num /* Number of MEMD instances in this section */
+
+my $memd_dir = "";
+my $memd_output = "";
+my $help = 0;
+my $man = 0;
+
+GetOptions(
+ "memd_dir=s" => \$memd_dir,
+ "memd_output=s" => \$memd_output,
+ "help" => \$help,
+ "man" => \$man) || pod2usage(-verbose=>0);
+
+pod2usage(-verbose => 1) if $help;
+pod2usage(-verbose => 2) if $man;
+
+# Find files
+my @memd_files = glob($memd_dir . '/*');
+
+# Get the max file size - offset for each file binary
+my $max_file_size = 0;
+foreach my $file (@memd_files)
+{
+ my $cur_size = (stat $file)[7];
+ if($cur_size > $max_file_size)
+ {
+ $max_file_size = $cur_size;
+ }
+}
+$max_file_size /= ROUNDING_DIVISOR;
+$max_file_size = int($max_file_size) + 1;
+
+# Get the number of files - (expected_num)
+my $number_of_files = scalar(@memd_files);
+
+# Generate header - add to file
+my $header = "OKOK"; # shows that the memd partition is valid
+$header .= "01.0"; # current metadata header version
+$header .= "01.0"; # current memd version
+$header .= "0000"; # expected size of each memd blob (in KB's) placeholder
+$header .= "00"; # number of memd instances placeholder
+$header .= "00000000"; # padding for the future
+$header .= "000000"; # rounding up to 16 bytes
+
+# Create offset
+my $offset = length $header;
+
+# Create file
+open(my $fh, '>', $memd_output) or die "Could not open file '$memd_output' $!";
+print $fh $header;
+
+# Add in the actual size and the number of memd instances
+seek($fh, HEADER_INPUT_LOCATION, 0);
+my $size_bin = pack('N', $max_file_size);
+print $fh $size_bin;
+my $num_bin = pack('n', $number_of_files);
+print $fh $num_bin;
+
+# Every max file size - rounded to an even number + headersize.
+# Read in the MEMD binary, and concatenate to this file.
+foreach my $file (@memd_files)
+{
+ seek($fh, $offset, 0);
+ print "Writing the file $file...\n";
+ open(my $in_file, '<', $file) or die "Cound not open file '$file' $!";
+
+ while ( <$in_file> )
+ {
+ print $fh $_;
+ }
+ close $in_file;
+ $offset = $offset + ($max_file_size * ROUNDING_DIVISOR);
+}
+
+
+close $fh;
+print "Done. Memd binary is $memd_output.\n";
+
+############### HELPER FUNCTIONS ############################
+# Function to first print, and then run a system command. Erroring out if the
+# command does not complete successfully
+sub run_command {
+ my $command = shift;
+ print "$command\n";
+ my $rc = system($command);
+ if ($rc != 0){
+ die "Error running command: $command. Nonzero return code of ($rc) returned.\n";
+ }
+ return $rc;
+}
+
+# Function to remove leading and trailing whitespace before returning that string
+sub trim_string {
+ my $str = shift;
+ $str =~ s/^\s+//;
+ $str =~ s/\s+$//;
+ return $str;
+}
+
+__END__
+
+=head1 NAME
+
+memd_creation.pl
+
+=head1 SYNOPSIS
+
+memd_creation.pl
+ --memd_dir=DATA_DIRECTORY
+ --memd_output=DATA_OUTPUT_NAME
+
+=item B<--help>
+
+Prints a brief help message and exits
+
+=item B<--man>
+
+Prints the manual page and exists
+
+=item B<--memd_dir>=DIRECTORY
+
+Directory of MEMD binary files.
+
+=item B<--memd_output>=FILENAME
+
+Location and name of the resulting output binary.
+
+=head1 DESCRIPTION
+
+B<memd_creation.pl> will generate a binary image for the MEMD
+section of the PNOR. It will generate a header based on the
+input binary files and concatenate them together.
+
+=cut
+
OpenPOWER on IntegriCloud