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: David Brown <david.brown@linaro.org>
diff --git a/boot/bootutil/include/bootutil/bootutil.h b/boot/bootutil/include/bootutil/bootutil.h
index 5d48124..92a9efc 100644
--- a/boot/bootutil/include/bootutil/bootutil.h
+++ b/boot/bootutil/include/bootutil/bootutil.h
@@ -50,8 +50,7 @@
/** 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 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];
};
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 711dbe6..ee89444 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -53,7 +53,6 @@
(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;
diff --git a/sim/mcuboot-sys/csupport/run.c b/sim/mcuboot-sys/csupport/run.c
index d355c6e..dd63d55 100644
--- a/sim/mcuboot-sys/csupport/run.c
+++ b/sim/mcuboot-sys/csupport/run.c
@@ -449,3 +449,8 @@
}
}
}
+
+uint32_t boot_max_align(void)
+{
+ return BOOT_MAX_ALIGN;
+}
diff --git a/sim/mcuboot-sys/src/c.rs b/sim/mcuboot-sys/src/c.rs
index 6f92c34..3d2f3ea 100644
--- a/sim/mcuboot-sys/src/c.rs
+++ b/sim/mcuboot-sys/src/c.rs
@@ -45,7 +45,7 @@
}
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 @@
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,