Change FV creation to take a list of files instead of using fv_append()

This commit is contained in:
Trammell hudson 2018-02-02 11:02:56 -05:00
parent 764b3bfc22
commit 503688a835
Failed to extract signature
2 changed files with 26 additions and 24 deletions

View File

@ -55,37 +55,32 @@ GetOptions(
#my $guid = EFI::guid($guid_str) #my $guid = EFI::guid($guid_str)
# or die "$guid_str: Unable to parse GUID\n"; # or die "$guid_str: Unable to parse GUID\n";
my $fv = EFI::fv($compress_size || $size);
# Read entire files at a time and append a new file # Read entire files at a time and append a new file
# for each input read. # for each input read.
local $/ = undef; local $/ = undef;
my @ffs;
my $length_sum = 0;
while(<>) while(<>)
{ {
my $offset = EFI::fv_append(\$fv, $_) push @ffs, $_;
or die "$ARGV: Unable to append\n"; $length_sum += length $_;
warn sprintf "%s: 0x%x bytes offset %x\n", warn sprintf "%s: 0x%x bytes\n",
$ARGV, $ARGV,
length $_, length $_,
$offset
if $verbose > 1; if $verbose > 1;
} }
warn sprintf "%s: 0x%08x out of %08x bytes in FV%s\n", warn sprintf "%s: 0x%08x out of %08x bytes in FV%s\n",
$output, $output,
length($fv), $length_sum,
$compress_size || $size, $compress_size || $size,
$compress_size ? " (uncompressed)" : "", $compress_size ? " (uncompressed)" : "",
if $verbose > 0; if $verbose > 0;
EFI::fv_pad(\$fv) my $fv = EFI::fv($compress_size || $size, @ffs)
or die sprintf "%s: data size 0x%x > volume size 0x%x\n", or die "$output: Unable to create FV\n";
$output,
length $fv,
$compress_size || $size
;
if ($compress_size) if ($compress_size)
{ {
@ -98,14 +93,7 @@ if ($compress_size)
$size, $size,
if $verbose > 0; if $verbose > 0;
my $outer_fv = EFI::fv($size); my $outer_fv = EFI::fv($size, $ffs_lz)
EFI::fv_append(\$outer_fv, $ffs_lz)
or die sprintf "%s: Unable to append 0x%08x compressed bytes\n",
$output,
length($ffs_lz),
;
EFI::fv_pad(\$outer_fv)
or die sprintf "%s: Unable to append 0x%08x compressed bytes\n", or die sprintf "%s: Unable to append 0x%08x compressed bytes\n",
$output, $output,
length($ffs_lz), length($ffs_lz),

View File

@ -386,7 +386,7 @@ sub compress
} }
# Create a FV header for a given file size # Create a FV for a given file size with the included files
sub fv sub fv
{ {
my $size = shift; my $size = shift;
@ -423,10 +423,24 @@ sub fv
substr($fv_hdr, 0x32, 2) = pack("v", $sum & 0xFFFF); substr($fv_hdr, 0x32, 2) = pack("v", $sum & 0xFFFF);
return $fv_hdr; for my $ffs (@_)
{
next if fv_append(\$fv_hdr, $ffs);
warn "FV append failed\n";
return;
}
return $fv_hdr if fv_pad(\$fv_hdr);
warn "FV pad failed\n";
return;
} }
# Add files to an existing FV
# Append a file to an FV, adding an initial pad if necessary
# This is used internally by EFI::fv() and should not need to be called
# by users of the EFI library.
sub fv_append sub fv_append
{ {
my $fv_ref = shift; my $fv_ref = shift;