diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2017-06-06 14:56:45 -0500 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2017-06-23 10:08:26 -0400 |
commit | b22bfa0529a673baea56805fa4fcc1ba65c29666 (patch) | |
tree | 115ab6fda1d253fa595a20be96f44cb7b3e3480d /src | |
parent | ea259b6658e294b19cbf13a5c3b5f2170c4d0617 (diff) | |
download | talos-hostboot-b22bfa0529a673baea56805fa4fcc1ba65c29666.tar.gz talos-hostboot-b22bfa0529a673baea56805fa4fcc1ba65c29666.zip |
Create script to test modifying a section's size in the pnor xml
This can be used to quickly check if a resize is valid and print
all the new offsets
Change-Id: I36108ca23f743673279b8bad82629b25f886e222
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/41445
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@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>
Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com>
Reviewed-by: Martin Gloff <mgloff@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/build/buildpnor/PnorUtils.pm | 71 | ||||
-rwxr-xr-x | src/build/buildpnor/parse-pnor | 59 | ||||
-rwxr-xr-x | src/build/buildpnor/resize-pnor-section.pl | 175 |
3 files changed, 245 insertions, 60 deletions
diff --git a/src/build/buildpnor/PnorUtils.pm b/src/build/buildpnor/PnorUtils.pm index bcdf53af1..635af504c 100644 --- a/src/build/buildpnor/PnorUtils.pm +++ b/src/build/buildpnor/PnorUtils.pm @@ -30,8 +30,9 @@ use File::Basename; use Exporter 'import'; @EXPORT_OK = qw(loadPnorLayout getNumber traceErr trace run_command PAGE_SIZE loadBinFiles findLayoutKeyByEyeCatch checkSpaceConstraints - getSwSignatures getBinDataFromFile checkFile); + getSwSignatures getBinDataFromFile checkFile displayPnorLayout); use strict; +use Data::Dumper; my $TRAC_ERR = 0; # 0=errors, >0 for more traces, leaving at 1 to keep key milestone traces. @@ -89,7 +90,7 @@ sub loadPnorLayout my $numOfSides = scalar (@{$metadataEl->{side}}); my $sideSize = ($imageSize)/($numOfSides); - trace(1, " $this_func: metadata: imageSize = $imageSize, blockSize=$blockSize, arrangement = $arrangement, numOfSides: $numOfSides, sideSize: $sideSize, tocSize: $tocSize"); + 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 #stored in the layout xml @@ -113,7 +114,7 @@ sub loadPnorLayout $$i_pnorLayoutRef{metadata}{sides}{$sideId}{golden} = $golden; $count = $count + 1; - trace(1, "A-B-D: side:$sideId primaryTOC:$primaryTOC, backupTOC:$backupTOC, golden: $golden"); + trace(2, "A-B-D: side:$sideId primaryTOC:$primaryTOC, backupTOC:$backupTOC, golden: $golden"); } } elsif ($arrangement eq "A-D-B") @@ -132,7 +133,7 @@ sub loadPnorLayout $$i_pnorLayoutRef{metadata}{sides}{$sideId}{toc}{backup} = $backupTOC; $$i_pnorLayoutRef{metadata}{sides}{$sideId}{golden} = $golden; $count = $count + 1; - trace(1, "A-D-B: side:$sideId, primaryTOC:$primaryTOC, backupTOC:$backupTOC, golden: $golden"); + trace(2, "A-D-B: side:$sideId, primaryTOC:$primaryTOC, backupTOC:$backupTOC, golden: $golden"); } } else @@ -507,4 +508,66 @@ sub checkFile } } +############################################################################### +# Display Pnor Layout - Display XML pnor layout more simply +################################################################################ +sub displayPnorLayout +{ + my ($i_pnorLayoutRef, $i_gaps, $i_verbose) = @_; + + if (!$i_verbose) + { + print "-------------------------------------------------------- \n"; + print "Name-physicalOffset-physicalRegionSize-physicalRegionEnd \n"; + print "-------------------------------------------------------- \n"; + } + + my $curOffset = 0; + my $totalFree = 0; + # Iterate through all sections of PNOR, including TOC's + foreach my $section (sort {$a <=> $b} keys %{$$i_pnorLayoutRef{sections}}) + { + # Get hex format for each value + my $offset = sprintf("0x%X",$$i_pnorLayoutRef{sections}{$section}{physicalOffset}); + my $size = sprintf("0x%X",$$i_pnorLayoutRef{sections}{$section}{physicalRegionSize}); + my $end = sprintf("0x%X",hex($offset)+hex($size)); + + # Check if there is a gap between sections + if ($i_gaps && ($curOffset < hex($offset))) + { + print " > Gap Found: addr = ".sprintf("0x%X",$curOffset); + + # Display address and size of gap + my $gapSize = hex($offset)-$curOffset; + print " size = ".sprintf("0x%X",$gapSize)."\n"; + $totalFree += $gapSize; + $curOffset = hex($offset) + hex($size); + } + else + { + $curOffset += hex($size); + } + + # Print sections + if ($i_verbose) + { + print $$i_pnorLayoutRef{sections}{$section}{eyeCatch}."\n"; + print Dumper $$i_pnorLayoutRef{sections}{$section}; + print "\n"; + } + else + { + print $$i_pnorLayoutRef{sections}{$section}{eyeCatch}."-$offset-$size-$end\n"; + } + } + + # Display total free space + if($i_gaps) + { + my $hexVal = sprintf("0x%X",$totalFree); + my $kiloBytes = $totalFree/1024; + print "\n---Total Free Space = ".$totalFree." Bytes or ".$kiloBytes." KB"; + print " (".$hexVal.")\n"; + } +} 1; diff --git a/src/build/buildpnor/parse-pnor b/src/build/buildpnor/parse-pnor index 720c03ec5..eed96372c 100755 --- a/src/build/buildpnor/parse-pnor +++ b/src/build/buildpnor/parse-pnor @@ -6,7 +6,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2015,2016 +# Contributors Listed Below - COPYRIGHT 2015,2017 # [+] International Business Machines Corp. # # @@ -30,7 +30,7 @@ use Data::Dumper; use File::Basename; use Cwd qw(abs_path cwd); use lib dirname abs_path($0); -use PnorUtils qw(loadPnorLayout checkFile); +use PnorUtils qw(loadPnorLayout checkFile displayPnorLayout); use Getopt::Long qw(:config pass_through); ################################################################################ @@ -140,58 +140,5 @@ sub execute_display my $rc = loadPnorLayout($pnorFile, \%pnorLayout, \%PhysicalOffsets); die "Error detected from call to loadLayout()" if($rc); - if (!$verbose) - { - print "-------------------------------------------------------- \n"; - print "Name-physicalOffset-physicalRegionSize-physicalRegionEnd \n"; - print "-------------------------------------------------------- \n"; - } - - my $curOffset = 0; - my $totalFree = 0; - # Iterate through all sections of PNOR, including TOC's - foreach my $section (sort {$a <=> $b} keys %{$pnorLayout{sections}}) - { - # Get hex format for each value - my $offset = sprintf("0x%X",$pnorLayout{sections}{$section}{physicalOffset}); - my $size = sprintf("0x%X",$pnorLayout{sections}{$section}{physicalRegionSize}); - my $end = sprintf("0x%X",hex($offset)+hex($size)); - - # Check if there is a gap between sections - if ($gaps && ($curOffset < hex($offset))) - { - print " > Gap Found: addr = ".sprintf("0x%X",$curOffset); - - # Display address and size of gap - my $gapSize = hex($offset)-$curOffset; - print " size = ".sprintf("0x%X",$gapSize)."\n"; - $totalFree += $gapSize; - $curOffset = hex($offset) + hex($size); - } - else - { - $curOffset += hex($size); - } - - # Print sections - if ($verbose) - { - print $pnorLayout{sections}{$section}{eyeCatch}."\n"; - print Dumper $pnorLayout{sections}{$section}; - print "\n"; - } - else - { - print $pnorLayout{sections}{$section}{eyeCatch}."-$offset-$size-$end\n"; - } - } - - # Display total free space - if($gaps) - { - my $hexVal = sprintf("0x%X",$totalFree); - my $kiloBytes = $totalFree/1024; - print "\n---Total Free Space = ".$totalFree." Bytes or ".$kiloBytes." KB"; - print " (".$hexVal.")\n"; - } + displayPnorLayout(\%pnorLayout, $gaps, $verbose); } diff --git a/src/build/buildpnor/resize-pnor-section.pl b/src/build/buildpnor/resize-pnor-section.pl new file mode 100755 index 000000000..d793ab489 --- /dev/null +++ b/src/build/buildpnor/resize-pnor-section.pl @@ -0,0 +1,175 @@ +#!/usr/bin/perl +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/build/buildpnor/resize-pnor-section.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 strict; +use Getopt::Long qw(:config pass_through); +use Pod::Usage; +use Data::Dumper; +use PnorUtils qw(loadPnorLayout findLayoutKeyByEyeCatch checkFile displayPnorLayout); + +my $help = 0; +my $man = 0; +my %globals = (); + +## HANDLE INPUTS + +GetOptions( + "pnor-layout=s" => \$globals{pnorLayoutFile}, + "section=s" => \$globals{modifySection}, + "size=s" => \$globals{modifySectionSize}, + "help" => \$help, + "man" => \$man) || pod2usage(-verbose=>0); + +pod2usage(-verbose => 1) if $help; +pod2usage(-verbose => 2) if $man; + +## MAIN + +verify_inputs(); +modify_xml(); + +## FUNCTIONS + +sub modify_xml +{ + my %pnorLayout = (); + my %PhysicalOffsets = (); + + my $rc = loadPnorLayout($globals{pnorLayoutFile}, \%pnorLayout, \%PhysicalOffsets); + die "Error detected from call to loadPnorLayout()" if($rc); + + my $section_phys_offset = findLayoutKeyByEyeCatch($globals{modifySection}, + \%pnorLayout); + + my $size_diff = $globals{modifySectionSize} - $pnorLayout{sections}{$section_phys_offset}{physicalRegionSize}; + if ($size_diff <= 0) + { + print "Size the same or smaller than current size, no action needed\n"; + exit; + } + + print "Before Modification:\n"; + displayPnorLayout(\%pnorLayout); + + my $endOffset = 0; + # Iterate through all sections of PNOR, including TOC's + foreach my $section (sort {$a <=> $b} keys %{$pnorLayout{sections}}) + { + my $secOffset = $pnorLayout{sections}{$section}{physicalOffset}; + my $secSize = $pnorLayout{sections}{$section}{physicalRegionSize}; + + # Skip sections unaffected by size change + if ( $secOffset < $section_phys_offset ) + { + next; + } + + # Enter modified size for specified section + if ( $secOffset == $section_phys_offset ) + { + $secSize = $globals{modifySectionSize}; + } + # Shift physical offset of following sections in pnor layout if the size + # diff affects the offset + elsif ($secOffset < $endOffset) + { + $secOffset += $size_diff; + } + + + $pnorLayout{sections}{$section}{physicalRegionSize} = $secSize; + $pnorLayout{sections}{$section}{physicalOffset} = $secOffset; + $endOffset = $secOffset + $secSize; + } + + if ($endOffset > $pnorLayout{metadata}{imageSize}) + { + print STDERR "\nModification does not fit in current PNOR size of $pnorLayout{metadata}{imageSize}\n"; + die; + } + + print "\n========================================================\n\n"; + print "After Modification:\n"; + displayPnorLayout(\%pnorLayout); + +} + +sub verify_inputs +{ + if( checkFile($globals{pnorLayoutFile}) ) + { + print STDERR "Pnor layout file DNE or not XML=> $globals{pnorLayoutFile}\n\n"; + pod2usage(-verbose=>1); + } + + if( $globals{modifySection} eq "" ) + { + print STDERR "Pnor section not specified\n\n"; + pod2usage(-verbose=>1); + } + + if( $globals{modifySectionSize} !~ /^0x[0-9a-fA-F]+$/ ) + { + print STDERR "New pnor section size not a hex number\n\n"; + pod2usage(-verbose=>1); + } + # Convert hex string to decimal number + $globals{modifySectionSize} = hex($globals{modifySectionSize}); +} + +__END__ + +=head1 NAME + +resize-pnor-section.pl + +=head1 SYNOPSIS + +resize-pnor-section.pl + --pnor-layout=PNOR_XML_FILE + --section=PNOR_SECTION_TO_MODIFY + --size=NEW_PNOR_SECTION_SIZE[0x HEX prefix] + +=head1 OPTIONS + +=over 8 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=back + +=head1 DESCRIPTION + +B<resize-pnor-section> will determine if a modification to a pnor section's size +is feasible and prints the resulting offsets and sizes of all sections + +=cut |