diff --git a/bin/create-fv b/bin/create-fv index 310f262..b6d84e1 100755 --- a/bin/create-fv +++ b/bin/create-fv @@ -55,37 +55,32 @@ GetOptions( #my $guid = EFI::guid($guid_str) # 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 # for each input read. local $/ = undef; +my @ffs; +my $length_sum = 0; while(<>) { - my $offset = EFI::fv_append(\$fv, $_) - or die "$ARGV: Unable to append\n"; + push @ffs, $_; + $length_sum += length $_; - warn sprintf "%s: 0x%x bytes offset %x\n", + warn sprintf "%s: 0x%x bytes\n", $ARGV, length $_, - $offset if $verbose > 1; } warn sprintf "%s: 0x%08x out of %08x bytes in FV%s\n", $output, - length($fv), + $length_sum, $compress_size || $size, $compress_size ? " (uncompressed)" : "", if $verbose > 0; -EFI::fv_pad(\$fv) - or die sprintf "%s: data size 0x%x > volume size 0x%x\n", - $output, - length $fv, - $compress_size || $size - ; +my $fv = EFI::fv($compress_size || $size, @ffs) + or die "$output: Unable to create FV\n"; if ($compress_size) { @@ -98,14 +93,7 @@ if ($compress_size) $size, if $verbose > 0; - my $outer_fv = EFI::fv($size); - 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) + my $outer_fv = EFI::fv($size, $ffs_lz) or die sprintf "%s: Unable to append 0x%08x compressed bytes\n", $output, length($ffs_lz), diff --git a/lib/EFI.pm b/lib/EFI.pm index f3d5500..bf0d484 100755 --- a/lib/EFI.pm +++ b/lib/EFI.pm @@ -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 { my $size = shift; @@ -423,10 +423,24 @@ sub fv 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 { my $fv_ref = shift;