Commit e0bb1f95 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

Change BOOT_MAX_ALIGN to #define

BOOT_MAX_ALIGN is defined as

    extern const uint32_t BOOT_MAX_ALIGN;

and is assigned a value in a single file.  This causes extra work when
this is used as the size of a local variable in a function.

The value was made a constant in order for the simulator to be able to
access the value.  Instead of making it a "real" constant, keep it as a
define, unifying the value of FLASH_MAX_ALIGN and this one, and provide
an accessor function for the test code to be able to access this value.

This causes a minor improvement in the code generated in
`boot_write_status`, but more importantly, eliminates a VLA from the
code, which increases the possible compilers supported by MCUboot.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 510fddb8
Loading
Loading
Loading
Loading
+4 −5
Changes for boot/bootutil/include/bootutil/bootutil.h: 4 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -50,8 +50,7 @@ extern "C" {
/** Swapping encountered an unrecoverable error */
#define BOOT_SWAP_TYPE_PANIC    0xff

#define MAX_FLASH_ALIGN         8
extern const uint32_t BOOT_MAX_ALIGN;
#define BOOT_MAX_ALIGN          8

struct image_header;
/**
@@ -75,11 +74,11 @@ struct boot_rsp {
 */
struct image_trailer {
    uint8_t swap_type;
    uint8_t pad1[MAX_FLASH_ALIGN - 1];
    uint8_t pad1[BOOT_MAX_ALIGN - 1];
    uint8_t copy_done;
    uint8_t pad2[MAX_FLASH_ALIGN - 1];
    uint8_t pad2[BOOT_MAX_ALIGN - 1];
    uint8_t image_ok;
    uint8_t pad3[MAX_FLASH_ALIGN - 1];
    uint8_t pad3[BOOT_MAX_ALIGN - 1];
    uint8_t magic[16];
};

+0 −1
Changes for boot/bootutil/src/bootutil_misc.c: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ const uint32_t boot_img_magic[] = {
    (sizeof boot_img_magic / sizeof boot_img_magic[0])

const uint32_t BOOT_MAGIC_SZ = sizeof boot_img_magic;
const uint32_t BOOT_MAX_ALIGN = MAX_FLASH_ALIGN;

struct boot_swap_table {
    uint8_t magic_primary_slot;
+5 −0
Changes for sim/mcuboot-sys/csupport/run.c: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -449,3 +449,8 @@ void sim_assert(int x, const char *assertion, const char *file, unsigned int lin
        }
    }
}

uint32_t boot_max_align(void)
{
    return BOOT_MAX_ALIGN;
}
+2 −2
Changes for sim/mcuboot-sys/src/c.rs: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ pub fn boot_magic_sz() -> usize {
}

pub fn boot_max_align() -> usize {
    unsafe { raw::BOOT_MAX_ALIGN as usize }
    unsafe { raw::boot_max_align() as usize }
}

pub fn rsa_oaep_encrypt(pubkey: &[u8], seckey: &[u8]) -> Result<[u8; 256], &'static str> {
@@ -84,7 +84,7 @@ mod raw {
        pub fn boot_trailer_sz(min_write_sz: u8) -> u32;

        pub static BOOT_MAGIC_SZ: u32;
        pub static BOOT_MAX_ALIGN: u32;
        pub fn boot_max_align() -> u32;

        pub fn rsa_oaep_encrypt_(pubkey: *const u8, pubkey_len: libc::c_uint,
                                 seckey: *const u8, seckey_len: libc::c_uint,