Skip to content

Commit

Permalink
Allow defining a partition with automatic starting offset
Browse files Browse the repository at this point in the history
If section does not have a starting offset, calculate starting
offset using previous section's offset/size, generate a new
output file with offsets and feed into existing tools, throw
error if any sections collide

Change-Id: I9adf3357b3751087535854a89fc634a415b870d0
RTC: 212219
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/80098
Reviewed-by: Nicholas E Bofferding <bofferdn@us.ibm.com>
Reviewed-by: Glenn Miles <milesg@ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Reviewed-by: William G Hoffa <wghoffa@us.ibm.com>
  • Loading branch information
megteo authored and wghoffa committed Aug 27, 2019
1 parent f877631 commit 845fb44
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 47 deletions.
111 changes: 88 additions & 23 deletions src/build/buildpnor/PnorUtils.pm
Expand Up @@ -39,6 +39,7 @@ my $TRAC_ERR = 0;
my $g_trace = 1;

use XML::Simple;

################################################################################
# Set PREFERRED_PARSER to XML::Parser. Otherwise it uses XML::SAX which contains
# bugs that result in XML parse errors that can be fixed by adjusting white-
Expand Down Expand Up @@ -90,6 +91,10 @@ sub loadPnorLayout
my $numOfSides = scalar (@{$metadataEl->{side}});
my $sideSize = ($imageSize)/($numOfSides);

my $currOffset = 0;
my $sectionNum = 0;
my $isStartingPartition = 1;

trace(2, " $this_func: metadata: imageSize = $imageSize, blockSize=$blockSize, arrangement = $arrangement, numOfSides: $numOfSides, sideSize: $sideSize, tocSize: $tocSize");

#determine the TOC offsets from the arrangement and side Information
Expand Down Expand Up @@ -170,6 +175,41 @@ sub loadPnorLayout
$physicalOffset = getNumber($physicalOffset);
$physicalRegionSize = getNumber($physicalRegionSize);

# if at first section, set starting offset
if ($isStartingPartition == 1)
{
$currOffset = $physicalOffset;
$isStartingPartition = 0;
}

# if physical offset does not exist, calculate it and create new element
my $hexOffset;
if ($physicalOffset == 0)
{
$physicalOffset = $currOffset;
$hexOffset = sprintf("0x%X", $physicalOffset);
trace(3, "$this_func: Calculated physicalOffset = $physicalOffset, for eyeCatch = $eyeCatch");
push @{$xml->{section}->[$sectionNum]->{physicalOffset}}, $hexOffset;
$currOffset = $currOffset + $physicalRegionSize;
}
else
{
# if sections overlap, throw error
if ($physicalOffset < $currOffset)
{
$hexOffset = sprintf("0x%X", $physicalOffset);
die "ERROR: Collision between sections detected at offset ".$hexOffset."";
}
$currOffset = $physicalOffset + $physicalRegionSize;
}
$sectionNum = $sectionNum + 1;

# align partition by minimum boundary
if ($currOffset % PAGE_SIZE != 0)
{
$currOffset = $currOffset + (PAGE_SIZE - $currOffset % PAGE_SIZE);
}

if($physicalRegionSize + $physicalOffset > $imageSize)
{
die "ERROR: $this_func: Image size ($imageSize) smaller than ".$eyeCatch."'s offset + ".$eyeCatch."'s size (".($physicalOffset + $physicalRegionSize)."). Aborting! ";
Expand Down Expand Up @@ -215,6 +255,22 @@ sub loadPnorLayout
checkForOverlap($i_pnorLayoutRef);
}

# write xml with offsets to new file
my $filename = basename($i_pnorFile, ".xml");
$filename = "${filename}WithOffsets.xml";

# writing to new file with error handling
eval
{
print XMLout($xml, RootName => "pnor", OutputFile => $filename);
1;
}
or do
{
my $err = $@;
die "ERROR: $this_func: Failed to create new XML file with corrected offsets, error = $err";
};

return 0;
}

Expand Down Expand Up @@ -377,8 +433,7 @@ sub checkSpaceConstraints
if ($eyeCatch eq "HBI")
{
print "Adjusting HBI size - ran out of space for test cases\n";
my $stopKey = findLayoutKeyByEyeCatch("TEST", \%$i_pnorLayoutRef);
adjustSecPhysSize(\%sectionHash, $layoutKey, $filesize, $stopKey);
adjustSecPhysSize(\%sectionHash, $layoutKey, $filesize);
}
else
{
Expand All @@ -389,37 +444,48 @@ sub checkSpaceConstraints
trace(1, "Done checkSpaceConstraints");
}


###############################################################################
# adjustSecPhysSize - Adjust section physical size when running test cases
# and fix up physical offsets between partitions
# (for example HBI and TEST)
################################################################################
# sub adjustSecPhysSize
#
# Adjust section physical size when running test cases and fix up physical
# offsets between partitions (for example HBI and all partitions that follow)
#
# @param [in] i_sectionHashRef - PNOR layout as a hash table reference
# @param [in] i_initPartKey - key of initial partition whose physical size will
# be adjusted
# @param [in] i_filesize - final file size of partition (note: actual final size
# may be larger than this as the size is adjusted by increments of PAGE_SIZE)
# @return - N/A
#
sub adjustSecPhysSize
{
my ($i_sectionHashRef, $i_secKey, $i_filesize, $i_stopKey) = @_;
my ($i_sectionHashRef, $i_initPartKey, $i_filesize) = @_;
my $this_func = (caller(0))[3];

my %sectionHash = %$i_sectionHashRef;

# Increment HBI physical size by PAGE_SIZE until the HBI file can fit
my $sec_old = $sectionHash{$i_secKey}{physicalRegionSize};
while ($i_filesize > $sectionHash{$i_secKey}{physicalRegionSize})
# Increment initial partition physical size by PAGE_SIZE until the initial
# partition file can fit
my $initPart_old = $sectionHash{$i_initPartKey}{physicalRegionSize};
while ($i_filesize > $sectionHash{$i_initPartKey}{physicalRegionSize})
{
$sectionHash{$i_secKey}{physicalRegionSize} += PAGE_SIZE;
$sectionHash{$i_initPartKey}{physicalRegionSize} += PAGE_SIZE;
}
my $sec_move = $sectionHash{$i_secKey}{physicalRegionSize} - $sec_old;
my $sec_end = $sectionHash{$i_secKey}{physicalRegionSize} + $sec_move;
my $initPart_move = $sectionHash{$i_initPartKey}{physicalRegionSize} - $initPart_old;

# Fix up physical offset affected by HBI size change
# Fix up physical offsets affected by initial partition size change
foreach my $section (keys %sectionHash)
{
# Only fix partitions after HBI and before $i_stopKey
if ($sectionHash{$section}{physicalOffset} > $sectionHash{$i_secKey}{physicalOffset}
&& $sectionHash{$section}{physicalOffset} < $sectionHash{$i_stopKey}{physicalOffset})
# Only fix partitions after initial partition
if ( $sectionHash{$section}{physicalOffset} >
$sectionHash{$i_initPartKey}{physicalOffset} )
{
my $new_location = $sectionHash{$section}{physicalOffset} + $sec_move;
print "Moving section $sectionHash{$section}{eyeCatch} forward by $sec_move bytes to $new_location\n";
$sectionHash{$section}{physicalOffset} = $new_location;
my $origoffset = $sectionHash{$section}{physicalOffset};
$sectionHash{$section}{physicalOffset} += $initPart_move;
trace(3, "$this_func: Section $sectionHash{$section}{eyeCatch} : " . sprintf("%X",$origoffset) . " --> " . sprintf("%X",$sectionHash{$section}{physicalOffset}));
}
else
{
printf "$this_func: Section $sectionHash{$section}{eyeCatch} : unchanged";
}
}
}
Expand Down Expand Up @@ -559,7 +625,6 @@ sub checkForOverlap
}
}


###############################################################################
# Display Pnor Layout - Display XML pnor layout more simply
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/build/buildpnor/buildpnor.pl
Expand Up @@ -6,7 +6,7 @@
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2012,2018
# Contributors Listed Below - COPYRIGHT 2012,2019
# [+] International Business Machines Corp.
#
#
Expand Down
24 changes: 1 addition & 23 deletions src/build/buildpnor/defaultPnorLayout.xml
Expand Up @@ -89,7 +89,6 @@ Layout Description
<section>
<description>Guard Data (20K)</description>
<eyeCatch>GUARD</eyeCatch>
<physicalOffset>0x2C000</physicalOffset>
<physicalRegionSize>0x5000</physicalRegionSize>
<side>sideless</side>
<ecc/>
Expand All @@ -98,7 +97,7 @@ Layout Description
<description>DIMM JEDEC (288K)</description>
<eyeCatch>DJVPD</eyeCatch>
<!--NOTE: MUST update standalone.simics if offset changes -->
<physicalOffset>0x31000</physicalOffset>
<physicalOffset>0x31000</physicalOffset>
<physicalRegionSize>0x48000</physicalRegionSize>
<side>sideless</side>
<ecc/>
Expand All @@ -124,7 +123,6 @@ Layout Description
<section>
<description>Hostboot Base (1MB)</description>
<eyeCatch>HBB</eyeCatch>
<physicalOffset>0x151000</physicalOffset>
<physicalRegionSize>0x100000</physicalRegionSize>
<side>sideless</side>
<sha512Version/>
Expand All @@ -133,7 +131,6 @@ Layout Description
<section>
<description>Hostboot Data (2MB)</description>
<eyeCatch>HBD</eyeCatch>
<physicalOffset>0x251000</physicalOffset>
<physicalRegionSize>0x200000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -142,7 +139,6 @@ Layout Description
<section>
<description>Hostboot Extended image (14.22MB w/o ECC)</description>
<eyeCatch>HBI</eyeCatch>
<physicalOffset>0x451000</physicalOffset>
<physicalRegionSize>0x1000000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -151,7 +147,6 @@ Layout Description
<section>
<description>SBE-IPL (Staging Area) (752K)</description>
<eyeCatch>SBE</eyeCatch>
<physicalOffset>0x1451000</physicalOffset>
<physicalRegionSize>0xBC000</physicalRegionSize>
<sha512perEC/>
<sha512Version/>
Expand All @@ -161,7 +156,6 @@ Layout Description
<section>
<description>HCODE Ref Image (1.125MB)</description>
<eyeCatch>HCODE</eyeCatch>
<physicalOffset>0x150D000</physicalOffset>
<physicalRegionSize>0x120000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -170,7 +164,6 @@ Layout Description
<section>
<description>Hostboot Runtime Services for Sapphire (7.0MB)</description>
<eyeCatch>HBRT</eyeCatch>
<physicalOffset>0x162D000</physicalOffset>
<physicalRegionSize>0x700000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -179,7 +172,6 @@ Layout Description
<section>
<description>Payload (19.875MB)</description>
<eyeCatch>PAYLOAD</eyeCatch>
<physicalOffset>0x1D2D000</physicalOffset>
<physicalRegionSize>0x0600000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -188,7 +180,6 @@ Layout Description
<section>
<description>Special PNOR Test Space (36K)</description>
<eyeCatch>TEST</eyeCatch>
<physicalOffset>0x310D000</physicalOffset>
<physicalRegionSize>0x9000</physicalRegionSize>
<testonly/>
<side>sideless</side>
Expand All @@ -199,7 +190,6 @@ Layout Description
from skipping header. Signing is forced in build pnor phase -->
<description>Special PNOR Test Space with Header (36K)</description>
<eyeCatch>TESTRO</eyeCatch>
<physicalOffset>0x3116000</physicalOffset>
<physicalRegionSize>0x9000</physicalRegionSize>
<side>sideless</side>
<testonly/>
Expand All @@ -210,7 +200,6 @@ Layout Description
<section>
<description>Hostboot Bootloader (28K)</description>
<eyeCatch>HBBL</eyeCatch>
<physicalOffset>0x311F000</physicalOffset>
<!-- Physical Size includes Header rounded to ECC valid size -->
<!-- Max size of actual HBBL content is 20K and 22.5K with ECC -->
<physicalRegionSize>0x7000</physicalRegionSize>
Expand All @@ -221,23 +210,20 @@ Layout Description
<section>
<description>Ref Image Ring Overrides (20K)</description>
<eyeCatch>RINGOVD</eyeCatch>
<physicalOffset>0x3126000</physicalOffset>
<physicalRegionSize>0x5000</physicalRegionSize>
<side>sideless</side>
<ecc/>
</section>
<section>
<description>SecureBoot Key Transition Partition (16K)</description>
<eyeCatch>SBKT</eyeCatch>
<physicalOffset>0x312B000</physicalOffset>
<physicalRegionSize>0x4000</physicalRegionSize>
<side>sideless</side>
<ecc/>
</section>
<section>
<description>OCC Lid (1.125M)</description>
<eyeCatch>OCC</eyeCatch>
<physicalOffset>0x312F000</physicalOffset>
<physicalRegionSize>0x120000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -248,7 +234,6 @@ Layout Description
<!-- We need 266KB per module sort, going to support
40 tables by default, plus ECC -->
<eyeCatch>WOFDATA</eyeCatch>
<physicalOffset>0x324F000</physicalOffset>
<!-- TODO RTC: 208004
Reduced by MB total to allow HBI + tests to
fit in PNOR, need to increase back 1 MB once HBI size
Expand All @@ -261,15 +246,13 @@ Layout Description
<section>
<description>FIRDATA (12K)</description>
<eyeCatch>FIRDATA</eyeCatch>
<physicalOffset>0x3D4F000</physicalOffset>
<physicalRegionSize>0x3000</physicalRegionSize>
<side>sideless</side>
<ecc/>
</section>
<section>
<description>Memory Data (128K)</description>
<eyeCatch>MEMD</eyeCatch>
<physicalOffset>0x3D52000</physicalOffset>
<physicalRegionSize>0x20000</physicalRegionSize>
<side>sideless</side>
<sha512Version/>
Expand All @@ -278,7 +261,6 @@ Layout Description
<section>
<description>Secureboot Test Load (12K)</description>
<eyeCatch>TESTLOAD</eyeCatch>
<physicalOffset>0x3D72000</physicalOffset>
<physicalRegionSize>0x3000</physicalRegionSize>
<side>sideless</side>
<sha512Version/>
Expand All @@ -287,7 +269,6 @@ Layout Description
<section>
<description>Centaur Hw Ref Image (12K)</description>
<eyeCatch>CENHWIMG</eyeCatch>
<physicalOffset>0x3D75000</physicalOffset>
<physicalRegionSize>0x3000</physicalRegionSize>
<sha512Version/>
<side>sideless</side>
Expand All @@ -296,7 +277,6 @@ Layout Description
<section>
<description>Secure Boot (144K)</description>
<eyeCatch>SECBOOT</eyeCatch>
<physicalOffset>0x3D78000</physicalOffset>
<physicalRegionSize>0x24000</physicalRegionSize>
<side>sideless</side>
<ecc/>
Expand All @@ -305,7 +285,6 @@ Layout Description
<section>
<description>Open CAPI Memory Buffer (OCMB) Firmware (300K)</description>
<eyeCatch>OCMBFW</eyeCatch>
<physicalOffset>0x3D9C000</physicalOffset>
<physicalRegionSize>0x4B000</physicalRegionSize>
<side>sideless</side>
<sha512Version/>
Expand All @@ -315,7 +294,6 @@ Layout Description
<section>
<description>HDAT Data (16K)</description>
<eyeCatch>HDAT</eyeCatch>
<physicalOffset>0x3DE7000</physicalOffset>
<physicalRegionSize>0x4000</physicalRegionSize>
<side>sideless</side>
<sha512Version/>
Expand Down

0 comments on commit 845fb44

Please sign in to comment.