Skip to content

Commit

Permalink
Fix BPM flash image script to properly calculate line length
Browse files Browse the repository at this point in the history
Before this commit, the flash image script made certain assumptions
about the flash image file when calculating the number of bytes on a
line. Those assumptions aren't always true. Therefore, this commit adds
a function to properly determine the number of bytes on a line for any
arbitrary amount of extraneous characters on the line by stripping them
all off prior to calculation.

Change-Id: Ibeea1f62177109a512920be1434557ac55510743
RTC:212448
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/81947
Reviewed-by: Christian R Geddes <crgeddes@us.ibm.com>
Reviewed-by: William G Hoffa <wghoffa@us.ibm.com>
Reviewed-by: Roland Veloz <rveloz@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-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>
Reviewed-by: Daniel M Crowell <dcrowell@us.ibm.com>
  • Loading branch information
MRaybuck authored and dcrowell77 committed Aug 9, 2019
1 parent eb3d423 commit 0f0b7c6
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/build/buildpnor/buildBpmFlashImages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ sub generateFirmwareImage
use constant FW_START_ADDRESS_8000 => "\@8000";
use constant FW_START_ADDRESS_A000 => "\@A000";

# Each line is plain text where each byte is separated by spaces.
# To determine how many bytes are on the line divide by characters per byte
# and number of spaces between bytes. 2 characters per byte + 1 space = 3
use constant BYTES_PER_LINE_EXCLUDING_SPACES => 3;

# Spec for BPM updates says that the maximum size for the data portion of
# the payload is 16 bytes
use constant MAXIMUM_DATA_BYTES_FOR_PAYLOAD => 16;
Expand Down Expand Up @@ -211,7 +206,7 @@ sub generateFirmwareImage
# The length of the payload data. The maximum size of payload data is 16
# bytes which is conveniently the maximum size of any line in the file
# minus spaces and carriage return/line feeds.
my $dataLength = length($line) / BYTES_PER_LINE_EXCLUDING_SPACES;
my $dataLength = calculateDataLength($line);

if ($dataLength > MAXIMUM_DATA_BYTES_FOR_PAYLOAD)
{
Expand Down Expand Up @@ -374,11 +369,6 @@ sub generateConfigImage
use constant SEGMENT_B_START_ADDRESS => 0x100;
use constant SEGMENT_A_START_ADDRESS => 0x180;

# Each line is plain text where each byte is separated by spaces.
# To determine how many bytes are on the line, divide by characters per byte
# and number of spaces between bytes. 2 characters per byte + 1 space = 3
use constant BYTES_PER_LINE_EXCLUDING_SPACES => 3;

# Spec for BPM updates says that the maximum size for the data portion of
# the payload is 16 bytes
use constant MAXIMUM_DATA_BYTES_FOR_PAYLOAD => 16;
Expand Down Expand Up @@ -445,7 +435,7 @@ sub generateConfigImage
# Bytes: The bytes to write to the BPM config data dump buffer.

# The length of the line. The maximum size of any line is 16 bytes.
my $dataLength = length($line) / BYTES_PER_LINE_EXCLUDING_SPACES;
my $dataLength = calculateDataLength($line);

if ($dataLength > MAXIMUM_DATA_BYTES_FOR_PAYLOAD)
{
Expand Down Expand Up @@ -814,6 +804,29 @@ sub createFragment
return $fragment;
}

################################################################################
# @brief Calculates the data length of the line by stripping all spaces for it
# dividing by the number of bytes on the line.
#
# @param[in] i_line The line to calculate the length on.
#
# @return The number of bytes on the line (length).
################################################################################
sub calculateDataLength
{
my $i_line = shift;

# Strip all the spaces from the line.
$i_line =~ s/\s+//g;

# Each line is plain text where each byte is separated by spaces.
# To determine how many bytes are on the line, divide by characters per byte
use constant CHARS_PER_BYTE => 2;
my $dataLength = length($i_line) / CHARS_PER_BYTE;

return $dataLength;
}

__END__
=head1 NAME
Expand Down

0 comments on commit 0f0b7c6

Please sign in to comment.