diff --git a/.github/workflows/sim.yaml b/.github/workflows/sim.yaml index 3811c4ed16..77c1339a3a 100644 --- a/.github/workflows/sim.yaml +++ b/.github/workflows/sim.yaml @@ -18,17 +18,17 @@ jobs: features: - "sig-ecdsa,sig-ecdsa-mbedtls,sig-ed25519,enc-kw,bootstrap" - "sig-rsa,sig-rsa3072,overwrite-only,validate-primary-slot,swap-move,swap-offset" - - "enc-rsa,enc-rsa max-align-32" - - "enc-aes256-rsa,enc-aes256-rsa max-align-32" - - "enc-ec256,enc-ec256 overwrite-only validate-primary-slot max-align-16,enc-ec256 max-align-32" - - "enc-aes256-ec256,enc-aes256-ec256 max-align-32" - - "enc-x25519,enc-x25519 max-align-32" - - "enc-aes256-x25519,enc-aes256-x25519 max-align-32" + - "enc-rsa,enc-rsa max-align-32,enc-rsa max-align-64,enc-rsa max-align-128" + - "enc-aes256-rsa,enc-aes256-rsa max-align-32,enc-aes256-rsa max-align-64,enc-aes256-rsa max-align-128" + - "enc-ec256,enc-ec256 overwrite-only validate-primary-slot max-align-16,enc-ec256 max-align-32,enc-ec256 max-align-64,enc-ec256 max-align-128" + - "enc-aes256-ec256,enc-aes256-ec256 max-align-32,enc-aes256-ec256 max-align-64,enc-aes256-ec256 max-align-128" + - "enc-x25519,enc-x25519 max-align-32,enc-x25519 max-align-64,enc-x25519 max-align-128" + - "enc-aes256-x25519,enc-aes256-x25519 max-align-32,enc-aes256-x25519 max-align-64,enc-aes256-x25519 max-align-128" - "sig-rsa overwrite-only,sig-ecdsa overwrite-only,sig-ecdsa-mbedtls overwrite-only,multiimage overwrite-only" - "sig-rsa validate-primary-slot,sig-ecdsa validate-primary-slot,sig-ecdsa-mbedtls validate-primary-slot,sig-rsa multiimage validate-primary-slot" - - "enc-kw overwrite-only,enc-kw overwrite-only max-align-32" - - "enc-rsa overwrite-only,enc-rsa overwrite-only max-align-32" - - "enc-aes256-kw overwrite-only,enc-aes256-kw overwrite-only max-align-32" + - "enc-kw overwrite-only,enc-kw overwrite-only max-align-32,enc-kw overwrite-only max-align-64,enc-kw overwrite-only max-align-128" + - "enc-rsa overwrite-only,enc-rsa overwrite-only max-align-32,enc-rsa overwrite-only max-align-64,enc-rsa overwrite-only max-align-128" + - "enc-aes256-kw overwrite-only,enc-aes256-kw overwrite-only max-align-32,enc-aes256-kw overwrite-only max-align-64,enc-aes256-kw overwrite-only max-align-128" - "sig-rsa enc-rsa validate-primary-slot,swap-move enc-rsa sig-rsa validate-primary-slot bootstrap,swap-offset enc-rsa sig-rsa validate-primary-slot bootstrap" - "sig-rsa enc-kw validate-primary-slot bootstrap,sig-ed25519 enc-x25519 validate-primary-slot" - "sig-ecdsa enc-kw validate-primary-slot" @@ -84,7 +84,7 @@ jobs: - "ram-load enc-aes256-kw multiimage" - "ram-load enc-aes256-kw sig-ecdsa-mbedtls multiimage" - "custom-crypto,custom-crypto overwrite-only,custom-crypto validate-primary-slot,custom-crypto swap-offset" - - "custom-enc-crypto,custom-enc-crypto validate-primary-slot,custom-enc-crypto swap-offset validate-primary-slot max-align-32" + - "custom-enc-crypto,custom-enc-crypto validate-primary-slot,custom-enc-crypto swap-offset validate-primary-slot max-align-32,custom-enc-crypto swap-offset validate-primary-slot max-align-64,custom-enc-crypto swap-offset validate-primary-slot max-align-128" runs-on: ubuntu-latest env: MULTI_FEATURES: ${{ matrix.features }} diff --git a/boot/bootutil/include/bootutil/bootutil_public.h b/boot/bootutil/include/bootutil/bootutil_public.h index a0ee5872aa..026153f4e3 100644 --- a/boot/bootutil/include/bootutil/bootutil_public.h +++ b/boot/bootutil/include/bootutil/bootutil_public.h @@ -79,7 +79,7 @@ extern "C" { #ifdef MCUBOOT_BOOT_MAX_ALIGN #if defined(MCUBOOT_SWAP_USING_MOVE) || defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_OFFSET) -_Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32, +_Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 128, "Unsupported value for MCUBOOT_BOOT_MAX_ALIGN for SWAP upgrade modes"); #endif diff --git a/docs/imgtool.md b/docs/imgtool.md index dfc59e2e16..c7ae7ec880 100644 --- a/docs/imgtool.md +++ b/docs/imgtool.md @@ -117,10 +117,10 @@ primary slot and adds a header and trailer that the bootloader is expecting: --public-key-format [hash|full] In what format to add the public key to the image manifest: full key or hash of the key. - --max-align [8|16|32] Maximum flash alignment. Set if flash + --max-align [8|16|32|64|128] Maximum flash alignment. Set if flash alignment of the primary and secondary slot differ and any of them is larger than 8. - --align [1|2|4|8|16|32] Alignment used by swap update modes. + --align [1|2|4|8|16|32|64|128] Alignment used by swap update modes. -v, --version TEXT [required] -s, --security-counter TEXT Specify the value of security counter. Use the `auto` keyword to automatically generate diff --git a/scripts/imgtool/image.py b/scripts/imgtool/image.py index 06d9caf082..ebaa18755c 100755 --- a/scripts/imgtool/image.py +++ b/scripts/imgtool/image.py @@ -861,7 +861,7 @@ def _trailer_size(self, write_size, max_sectors, overwrite_only, enckey, if overwrite_only: return self.max_align * 2 + magic_align_size else: - if write_size not in set([1, 2, 4, 8, 16, 32]): + if write_size not in set([1, 2, 4, 8, 16, 32, 64, 128]): raise click.BadParameter(f"Invalid alignment: {write_size}") m = DEFAULT_MAX_SECTORS if max_sectors is None else max_sectors trailer = m * 3 * write_size # status area diff --git a/scripts/imgtool/main.py b/scripts/imgtool/main.py index a9d9acbc43..1bc9c3da0c 100755 --- a/scripts/imgtool/main.py +++ b/scripts/imgtool/main.py @@ -473,11 +473,12 @@ def convert(self, value, param, ctx): help='Specify the value of security counter. Use the `auto` ' 'keyword to automatically generate it from the image version.') @click.option('-v', '--version', callback=validate_version, required=True) -@click.option('--align', type=click.Choice(['1', '2', '4', '8', '16', '32']), +@click.option('--align', type=click.Choice(['1', '2', '4', '8', '16', '32', + '64', '128']), default='1', required=False, help='Alignment used by swap update modes.') -@click.option('--max-align', type=click.Choice(['8', '16', '32']), +@click.option('--max-align', type=click.Choice(['8', '16', '32','64', '128']), required=False, help='Maximum flash alignment. Set if flash alignment of the ' 'primary and secondary slot differ and any of them is larger ' diff --git a/sim/Cargo.toml b/sim/Cargo.toml index cb206e0437..c76e6345ef 100644 --- a/sim/Cargo.toml +++ b/sim/Cargo.toml @@ -36,6 +36,8 @@ direct-xip = ["mcuboot-sys/direct-xip"] downgrade-prevention = ["mcuboot-sys/downgrade-prevention"] max-align-16 = ["mcuboot-sys/max-align-16"] max-align-32 = ["mcuboot-sys/max-align-32"] +max-align-64 = ["mcuboot-sys/max-align-64"] +max-align-128 = ["mcuboot-sys/max-align-128"] hw-rollback-protection = ["mcuboot-sys/hw-rollback-protection"] check-load-addr = ["mcuboot-sys/check-load-addr"] custom-crypto = ["mcuboot-sys/custom-crypto"] diff --git a/sim/mcuboot-sys/Cargo.toml b/sim/mcuboot-sys/Cargo.toml index 26e98cddaf..f7511d8fcb 100644 --- a/sim/mcuboot-sys/Cargo.toml +++ b/sim/mcuboot-sys/Cargo.toml @@ -102,6 +102,12 @@ max-align-16 = [] # Support images with 32-byte maximum write alignment value. max-align-32 = [] +# Support images with 64-byte maximum write alignment value. +max-align-64 = [] + +# Support images with 128-byte maximum write alignment value. +max-align-128 = [] + # Use logical sectors. Enable exactly one of the sized features; each # implies the `logical-sectors` umbrella that code can test against # without caring about the size. diff --git a/sim/mcuboot-sys/build.rs b/sim/mcuboot-sys/build.rs index cb7d449ca3..bf9eacd687 100644 --- a/sim/mcuboot-sys/build.rs +++ b/sim/mcuboot-sys/build.rs @@ -41,6 +41,8 @@ fn main() { let direct_xip = env::var("CARGO_FEATURE_DIRECT_XIP").is_ok(); let max_align_16 = env::var("CARGO_FEATURE_MAX_ALIGN_16").is_ok(); let max_align_32 = env::var("CARGO_FEATURE_MAX_ALIGN_32").is_ok(); + let max_align_64 = env::var("CARGO_FEATURE_MAX_ALIGN_64").is_ok(); + let max_align_128 = env::var("CARGO_FEATURE_MAX_ALIGN_128").is_ok(); let hw_rollback_protection = env::var("CARGO_FEATURE_HW_ROLLBACK_PROTECTION").is_ok(); let check_load_addr = env::var("CARGO_FEATURE_CHECK_LOAD_ADDR").is_ok(); let custom_crypto = env::var("CARGO_FEATURE_CUSTOM_CRYPTO").is_ok(); @@ -56,7 +58,11 @@ fn main() { conf.conf.define("MCUBOOT_HAVE_ASSERT_H", None); conf.conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128")); - if max_align_32 { + if max_align_128 { + conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("128")); + } else if max_align_64 { + conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("64")); + } else if max_align_32 { conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("32")); } else if max_align_16 { conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("16")); diff --git a/sim/src/image.rs b/sim/src/image.rs index 19754b7840..7f8082779f 100644 --- a/sim/src/image.rs +++ b/sim/src/image.rs @@ -798,6 +798,26 @@ impl ImagesBuilder { flash.insert(dev_id, dev); (flash, Rc::new(areadesc), &[Caps::SwapUsingScratch, Caps::OverwriteUpgrade, Caps::SwapUsingMove, Caps::RamLoad, Caps::DirectXip]) } + DeviceName::RA6M3 => { + // Renesas Flash: 8 sectors of 8K, 30 sectors of 32K (1MB variant). + let dev = SimFlash::new(vec![ + //First 8 sectors of 8K (64K), these are usually used to store mcuboot + 8 * 1024, 8 * 1024, 8 * 1024, 8 * 1024, 8 * 1024, 8 * 1024, 8 * 1024, 8 * 1024, + //Next 30 sectors of 32K (960K), these are usually used to store the images + 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, + 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, + 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024, 32*1024 ], + align as usize, erased_val); + let dev_id = 0; + let mut areadesc = AreaDesc::new(); + areadesc.add_flash_sectors(dev_id, &dev); + areadesc.add_image(0x020000, 0x020000, FlashId::Image0, dev_id); + areadesc.add_image(0x040000, 0x020000, FlashId::Image1, dev_id); + areadesc.add_image(0x060000, 0x020000, FlashId::ImageScratch, dev_id); + let mut flash = SimMultiFlash::new(); + flash.insert(dev_id, dev); + (flash, Rc::new(areadesc), &[Caps::SwapUsingMove, Caps::SwapUsingOffset]) + } } } @@ -2713,7 +2733,7 @@ pub struct SlotInfo { pub dev_id: u8, } -#[cfg(all(not(feature = "max-align-16"), not(feature = "max-align-32")))] +#[cfg(all(not(feature = "max-align-16"), not(feature = "max-align-32"), not(feature = "max-align-64"), not(feature = "max-align-128")))] const MAGIC: &[u8] = &[0x77, 0xc2, 0x95, 0xf3, 0x60, 0xd2, 0xef, 0x7f, 0x35, 0x52, 0x50, 0x0f, @@ -2731,6 +2751,18 @@ const MAGIC: &[u8] = &[0x20, 0x00, 0x2d, 0xe1, 0x8d, 0x77, 0x67, 0x9c, 0x11, 0x0f, 0x1f, 0x8a]; +#[cfg(feature = "max-align-64")] +const MAGIC: &[u8] = &[0x40, 0x00, 0x2d, 0xe1, + 0x5d, 0x29, 0x41, 0x0b, + 0x8d, 0x77, 0x67, 0x9c, + 0x11, 0x0f, 0x1f, 0x8a]; + +#[cfg(feature = "max-align-128")] +const MAGIC: &[u8] = &[0x80, 0x00, 0x2d, 0xe1, + 0x5d, 0x29, 0x41, 0x0b, + 0x8d, 0x77, 0x67, 0x9c, + 0x11, 0x0f, 0x1f, 0x8a]; + // Replicates defines found in bootutil.h const BOOT_MAGIC_GOOD: Option = Some(1); const BOOT_MAGIC_UNSET: Option = Some(3); @@ -2808,7 +2840,7 @@ pub fn show_sizes() { } } -#[cfg(all(not(feature = "max-align-16"), not(feature = "max-align-32")))] +#[cfg(all(not(feature = "max-align-16"), not(feature = "max-align-32"),not(feature = "max-align-64"), not(feature = "max-align-128")))] fn test_alignments() -> &'static [usize] { &[1, 2, 4, 8] } @@ -2823,6 +2855,15 @@ fn test_alignments() -> &'static [usize] { &[32] } +#[cfg(feature = "max-align-64")] +fn test_alignments() -> &'static [usize] { + &[64] +} + +#[cfg(feature = "max-align-128")] +fn test_alignments() -> &'static [usize] { + &[128] +} /// For testing, some of the tests are quite slow. This will query for an /// environment variable `MCUBOOT_SKIP_SLOW_TESTS`, which can be set to avoid /// running these tests. diff --git a/sim/src/lib.rs b/sim/src/lib.rs index 9eb4b877fb..a49a135907 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -64,7 +64,7 @@ struct Args { #[derive(Copy, Clone, Debug, Deserialize)] pub enum DeviceName { Stm32f4, Stm32f4SpiFlash, Stm32f769, K64f, K64fBig, K64fMulti, Nrf52840, Nrf52840SpiFlash, - Nrf52840UnequalSlots, Nrf52840UnequalSlotsLargerSlot1,PSOCEdgeE8x, SmallPages, + Nrf52840UnequalSlots, Nrf52840UnequalSlotsLargerSlot1, PSOCEdgeE8x, SmallPages, RA6M3, } pub static ALL_DEVICES: &[DeviceName] = &[ @@ -80,6 +80,7 @@ pub static ALL_DEVICES: &[DeviceName] = &[ DeviceName::Nrf52840UnequalSlotsLargerSlot1, DeviceName::PSOCEdgeE8x, DeviceName::SmallPages, + DeviceName::RA6M3 ]; impl fmt::Display for DeviceName { @@ -97,6 +98,7 @@ impl fmt::Display for DeviceName { DeviceName::Nrf52840UnequalSlotsLargerSlot1 => "Nrf52840UnequalSlotsLargerSlot1", DeviceName::PSOCEdgeE8x => "PSOCEdgeE8x", DeviceName::SmallPages => "smallpages", + DeviceName::RA6M3 => "RA6M3", }; f.write_str(name) }