Commit 3fbbdac5 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

sim: get status area size from bootutil

Add new bootutil function that returns the size of the status area.
The simulator was updated to remove the custom calculation and get
the size directly from bootutil, avoiding breakages the happen when
both are not in sync.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 07a9a036
Loading
Loading
Loading
Loading
+8 −1
Changes for boot/bootutil/src/bootutil_misc.c: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -147,11 +147,18 @@ boot_magic_compatible_check(uint8_t tbl_val, uint8_t val)
    }
}

uint32_t
boot_status_sz(uint32_t min_write_sz)
{
    return /* state for all sectors */
           BOOT_STATUS_MAX_ENTRIES * BOOT_STATUS_STATE_COUNT * min_write_sz;
}

uint32_t
boot_trailer_sz(uint32_t min_write_sz)
{
    return /* state for all sectors */
           BOOT_STATUS_MAX_ENTRIES * BOOT_STATUS_STATE_COUNT * min_write_sz +
           boot_status_sz(min_write_sz)           +
#ifdef MCUBOOT_ENC_IMAGES
           /* encryption keys */
           BOOT_ENC_KEY_SIZE * 2                  +
+1 −0
Changes for boot/bootutil/src/bootutil_priv.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -251,6 +251,7 @@ int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig,
                        size_t slen, uint8_t key_id);

int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val);
uint32_t boot_status_sz(uint32_t min_write_sz);
uint32_t boot_trailer_sz(uint32_t min_write_sz);
int boot_status_entries(int image_index, const struct flash_area *fap);
uint32_t boot_status_off(const struct flash_area *fap);
+7 −2
Changes for sim/mcuboot-sys/src/c.rs: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -36,10 +36,14 @@ pub fn boot_go(multiflash: &mut SimMultiFlash, areadesc: &AreaDesc,
    (result, asserts)
}

pub fn boot_trailer_sz(align: u8) -> u32 {
pub fn boot_trailer_sz(align: u32) -> u32 {
    unsafe { raw::boot_trailer_sz(align) }
}

pub fn boot_status_sz(align: u32) -> u32 {
    unsafe { raw::boot_status_sz(align) }
}

pub fn boot_magic_sz() -> usize {
    unsafe { raw::boot_magic_sz() as usize }
}
@@ -81,7 +85,8 @@ mod raw {
        // for information and tracking.
        pub fn invoke_boot_go(sim_ctx: *mut CSimContext, areadesc: *const CAreaDesc) -> libc::c_int;

        pub fn boot_trailer_sz(min_write_sz: u8) -> u32;
        pub fn boot_trailer_sz(min_write_sz: u32) -> u32;
        pub fn boot_status_sz(min_write_sz: u32) -> u32;

        pub fn boot_magic_sz() -> u32;
        pub fn boot_max_align() -> u32;
+2 −10
Changes for sim/src/image.rs: 2 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -657,19 +657,11 @@ impl Images {
    }

    fn trailer_sz(&self, align: usize) -> usize {
        c::boot_trailer_sz(align as u8) as usize
        c::boot_trailer_sz(align as u32) as usize
    }

    // FIXME: could get status sz from bootloader
    fn status_sz(&self, align: usize) -> usize {
        let bias = if Caps::EncRsa.present() || Caps::EncKw.present() ||
                Caps::EncEc256.present() {
            32
        } else {
            0
        };

        self.trailer_sz(align) - (16 + 32 + bias)
        c::boot_status_sz(align as u32) as usize
    }

    /// This test runs a simple upgrade with no fails in the images, but