Skip to content

Commit

Permalink
all scripts for hdat pnor partition
Browse files Browse the repository at this point in the history
Change-Id: Ied9c154d544d65eebfe5cfb0185ccb26545ee130
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/67144
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: Jayashankar Padath <jayashankar.padath@in.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
sampmisr authored and dcrowell77 committed Nov 27, 2018
1 parent 4288e39 commit ac53c27
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/build/buildpnor/defaultPnorLayout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,13 @@ Layout Description
<readOnly/>
<ecc/>
</section>
<section>
<description>HDAT Data (16K)</description>
<eyeCatch>HDAT</eyeCatch>
<physicalOffset>0x3BD0000</physicalOffset>
<physicalRegionSize>0x4000</physicalRegionSize>
<side>sideless</side>
<sha512Version/>
<ecc/>
</section>
</pnor>
3 changes: 3 additions & 0 deletions src/build/mkrules/dist.targets.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ COPY_FILES = \
src/build/buildpnor/memd_creation.pl:openpower \
src/usr/targeting/common/processMrw.pl:openpower \
src/usr/targeting/common/Targets.pm:openpower \
src/usr/targeting/common/genHDATstructures.pl:openpower \
src/usr/hdat/genHdatBin.pl:openpower \
src/usr/targeting/common/filter_out_unwanted_attributes.pl:openpower \
src/usr/targeting/common/xmltohb/mergexml.sh:openpower \
src/usr/targeting/common/xmltohb/attribute_types.xml:openpower \
Expand All @@ -96,6 +98,7 @@ COPY_FILES = \
src/usr/targeting/common/xmltohb/simics_CUMULUS_CDIMM.system.xml:openpower \
src/usr/targeting/common/xmltohb/simics_AXONE.system.xml:openpower \
src/usr/targeting/common/xmltohb/xmltohb.pl:openpower \
src/usr/hdat/hdatBinLayout.xml:openpower \
src/usr/targeting/xmltohb/updatetempsxml.pl:openpower \
src/include/usr/vmmconst.h:openpower \
src/usr/targeting/common/xmltohb/bios.xsd:openpower \
Expand Down
3 changes: 2 additions & 1 deletion src/include/usr/pnor/pnor_const.H
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2015,2017 */
/* Contributors Listed Below - COPYRIGHT 2015,2018 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -74,6 +74,7 @@ enum SectionId
MEMD, /**< Memory configuration data */
TESTLOAD, /**< Secureboot test load */
CENTAUR_HW_IMG, /**< Centaur HCODE Reference image */
HDAT, /**< HDAT data */
#endif
NUM_SECTIONS, /**< Number of defined sections */

Expand Down
166 changes: 166 additions & 0 deletions src/usr/hdat/genHdatBin.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/hdat/genHdatBin.pl $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2017,2018
# [+] 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 strict;
use warnings;
use XML::LibXML;
use feature 'say';
use Class::Struct;
use File::stat;
use File::Copy;

my $cfgBigEndian = 1;

################################################################################
# Pack 2 byte value into a buffer using configured endianness
################################################################################

sub pack4byte {
my($value) = @_;

my $binaryData;
if($cfgBigEndian)
{
$binaryData = pack("N",$value);
}
else # Little endian
{
$binaryData = pack("V",$value);
}

return $binaryData;
}

my $layoutFile = 'hdatBinLayout.xml';
my $dom = XML::LibXML->load_xml(location => $layoutFile);

# verify if collective bins size if less than max size

validateMaxSize($dom);
my %toc = createToc($dom);
my $chkSum = createChecksum($dom);
my $ver = '104q';
my $hdatBin = "hdat.bin";
open ( my $hdatBinfh , '>', $hdatBin)
or die "Can't open > $hdatBin: $!";
binmode($hdatBinfh);
print $hdatBinfh $ver;
print $hdatBinfh $chkSum;
foreach my $my_key ( sort keys %toc )
{
print $hdatBinfh $my_key;
print $hdatBinfh $toc{$my_key};
}
seek($hdatBinfh,0x1014,0);

my $tmpFile = "./tempFile";
open my $totbinfh , '<', $tmpFile;
binmode($totbinfh);
local $/;
my $buffer = <$totbinfh>;
print $hdatBinfh $buffer;
close $totbinfh;
close $hdatBinfh;

sub validateMaxSize
{
my $dom = shift;
my $totSize = 0;
my $headerSize = 0x1014; #tocsize + checksum size + version size
foreach my $binFile ( $dom->findnodes('/hdat/section'))
{
if (-e $binFile->findvalue('./fileName'))
{
say $binFile->findvalue('./fileName');
$totSize += (stat($binFile->findvalue('./fileName')))->size;
}
else
{
say $binFile->findvalue('./fileName'), "doesnt exist";
}
}
my $maxsize = hex($dom->findvalue('/hdat/metadata/maxSize'));
say $maxsize;
if($maxsize < ($totSize + $headerSize))
{
#say $dom->findvalue('/hdat/metaData/maxSize');
#say ($totSize + $headerSize);
die " collective size of binaries is more than max size , $totSize";
}

}

sub createToc
{
my $dom = shift;
my %toc = ();
my $offset = 0x1014;
foreach my $binFile ( $dom->findnodes('/hdat/section')){
if (-e $binFile->findvalue('./fileName'))
{
$toc{pack4byte($offset)} = pack4byte((stat($binFile->findvalue('./fileName')))->size);
$offset += ((stat($binFile->findvalue('./fileName')))->size);
}
else
{
$toc{pack4byte($offset)} = pack4byte(0);
$offset += 4; #its a hash, so bump up by 4 bytes for uniqueness
}
}
return %toc;
}



sub createChecksum
{
my $dom = shift;
my $tmpFile = "./tempFile";
open my $totbinfh , '>', $tmpFile;
binmode($totbinfh);
foreach my $section ( $dom->findnodes('/hdat/section')){
if (-e $section->findvalue('./fileName'))
{
local $/;
open my $sectBinfh, '<', $section->findvalue('./fileName');
binmode($sectBinfh);
my $data = <$sectBinfh>;
print $totbinfh $data;
close $sectBinfh;
say $section->findvalue('./fileName');
}
else
{
print $totbinfh pack4byte(0); # if the file doesn't exist,fill 4 byte 0's.
say $section->findvalue('./fileName'), "is empty";
}
}
my @md5= split / /, `md5sum ./tempFile`;
close $tmpFile;
say 'checksum is'.$md5[0];
return $md5[0];
}

0 comments on commit ac53c27

Please sign in to comment.