Skip to content

Commit

Permalink
Merge pull request #84 from tock/reserved-space-padding
Browse files Browse the repository at this point in the history
Use reserved space footer for padding
  • Loading branch information
ppannuto committed May 15, 2024
2 parents 2f0e2f0 + 45a5880 commit 48de07c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ pub fn elf_to_tbf(

let footers_initial_len = binary_index - tbfheader.binary_end_offset() as usize;

// Flag to track if we are guaranteed to have a reserved space footer.
let mut ensured_footer_reserved_space: bool = false;

// Make sure the footer is at least the minimum requested size.
if (minimum_footer_size as usize) > footers_initial_len {
let mut needed_footer_reserved_space = (minimum_footer_size as usize) - footers_initial_len;
Expand All @@ -885,6 +888,10 @@ pub fn elf_to_tbf(

// Add reserved space to the footer.
binary_index += needed_footer_reserved_space;

// Since we ensured there is room for the reserved space footer, we mark
// that that footer will be created.
ensured_footer_reserved_space = true;
}

// Optionally calculate the additional padding needed to ensure the app size
Expand Down Expand Up @@ -917,9 +924,10 @@ pub fn elf_to_tbf(
binary_index += pad;

// If there is room for a TbfFooterCredentials we will use that.
if pad
>= (mem::size_of::<header::TbfHeaderTlv>()
+ mem::size_of::<header::TbfFooterCredentialsType>())
if ensured_footer_reserved_space
|| pad
>= (mem::size_of::<header::TbfHeaderTlv>()
+ mem::size_of::<header::TbfFooterCredentialsType>())
{
0
} else {
Expand Down

0 comments on commit 48de07c

Please sign in to comment.