From f9bfddd685d0725e3e29abf5938eb1e7dd183be7 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Tue, 24 Apr 2018 14:28:33 -0400 Subject: [PATCH] Move max image sector config to mcuboot_config.h Take the opportunity to clean up a bit of platform cruft that has gotten into bootutil by moving it to mcuboot_config.h, and ensuring it is documented in the template config file. Signed-off-by: Marti Bolivar --- boot/bootutil/src/bootutil_priv.h | 10 +--------- .../include/mcuboot_config/mcuboot_config.h | 2 ++ boot/zephyr/include/mcuboot_config/mcuboot_config.h | 2 ++ samples/mcuboot_config/mcuboot_config.template.h | 4 ++++ sim/mcuboot-sys/build.rs | 1 + 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h index d7ab258d..b0dab08f 100644 --- a/boot/bootutil/src/bootutil_priv.h +++ b/boot/bootutil/src/bootutil_priv.h @@ -91,15 +91,7 @@ struct boot_swap_state { uint8_t image_ok; }; -#if defined(__BOOTSIM__) -#define BOOT_MAX_IMG_SECTORS 128 -#elif defined(__ZEPHYR__) -#define BOOT_MAX_IMG_SECTORS CONFIG_BOOT_MAX_IMG_SECTORS -#elif defined(MCUBOOT_MYNEWT) -#define BOOT_MAX_IMG_SECTORS MYNEWT_VAL(BOOTUTIL_MAX_IMG_SECTORS) -#else -#error "Invalid target OS" -#endif +#define BOOT_MAX_IMG_SECTORS MCUBOOT_MAX_IMG_SECTORS /* * The current flashmap API does not check the amount of space allocated when diff --git a/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h index 4e169abc..f0842a3e 100644 --- a/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h +++ b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h @@ -52,4 +52,6 @@ #define MCUBOOT_OVERWRITE_ONLY_FAST 1 #endif +#define MCUBOOT_MAX_IMG_SECTORS MYNEWT_VAL(BOOTUTIL_MAX_IMG_SECTORS) + #endif /* __MCUBOOT_CONFIG_H__ */ diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h index 7daa58f8..0b65cd00 100644 --- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h +++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h @@ -48,6 +48,8 @@ */ #define MCUBOOT_USE_FLASH_AREA_GET_SECTORS +#define MCUBOOT_MAX_IMG_SECTORS CONFIG_BOOT_MAX_IMG_SECTORS + #endif /* !__BOOTSIM__ */ #endif /* __MCUBOOT_CONFIG_H__ */ diff --git a/samples/mcuboot_config/mcuboot_config.template.h b/samples/mcuboot_config/mcuboot_config.template.h index e5f208ca..75ec5003 100644 --- a/samples/mcuboot_config/mcuboot_config.template.h +++ b/samples/mcuboot_config/mcuboot_config.template.h @@ -78,4 +78,8 @@ * See the flash APIs for more details. */ /* #define MCUBOOT_USE_FLASH_AREA_GET_SECTORS */ +/* Default maximum number of flash sectors per image slot; change + * as desirable. */ +#define MCUBOOT_MAX_IMG_SECTORS 128 + #endif /* __MCUBOOT_CONFIG_H__ */ diff --git a/sim/mcuboot-sys/build.rs b/sim/mcuboot-sys/build.rs index 599d5011..516741bd 100644 --- a/sim/mcuboot-sys/build.rs +++ b/sim/mcuboot-sys/build.rs @@ -17,6 +17,7 @@ fn main() { let mut conf = gcc::Build::new(); conf.define("__BOOTSIM__", None); conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None); + conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128")); if validate_slot0 { conf.define("MCUBOOT_VALIDATE_SLOT0", None);