Commit Graph

376 Commits

Author SHA1 Message Date
Thomas Altenbach 60806bce8e sim: Fix MCUBOOT_SWAP_USING_SCRATCH defined in direct-xip and ram-load
When 'direct-xip' or 'ram-load' features were enabled,
CONFIG_BOOT_SWAP_USING_SCRATCH and MCUBOOT_SWAP_USING_SCRATCH were
defined even though swap using scratch wasn't used. This commit fixes
the issue.

Signed-off-by: Thomas Altenbach <thomas.altenbach@legrand.com>
2024-07-15 20:03:21 -03:00
David Brown c06f7bb367 Revert "boot: Add MCUBOOT_HW_KEY support for image encryption"
This reverts commit 0fa46270c0.

This breaks:

    samples/synchronization/sample.kernel.synchronization on
    b_u585i_iot02a/stm32u585xx/ns error

as this TF-M configuration uses its own keys.  This change is an API
change that needs to be coordinated with TF-M changes.

Before this revert, compiling this test results in:

    .../encrypted.c:447: undefined reference to
    `boot_enc_retrieve_private_key`

Signed-off-by: David Brown <david.brown@linaro.org>
2024-07-09 09:19:43 -06:00
David Brown a706317769 sim: Increase jmpbuf size
Increase the size of the jmpbuf to accomodate other architectures.
Unfortunately, the size of this is not available in the libc crate.
Increase this so encompass any platforms we wish to support, including
aarch64 on both Linux and MacOS.

Increasing an array beyond 32 means there is no default offered, so
implement this manually.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-06-26 16:43:56 -06:00
David Brown 847548a9ac sim: Put "C" on externs
Many of these extern functions are missing the "C". It doesn't seem to matter on
any of our targets, but this does make the code more correct, and might be a
problem in the future.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-06-26 16:43:56 -06:00
David Brown 9cc8dac569 sim: Put AreaDesc in an Rc
Since there are references to this struct passed to C code, put it into an Rc so
that it won't move around when the data is moved.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-06-26 16:43:56 -06:00
David Brown 5d155132dc sim: Don't take address of movable struct
This struct was having addresses taken of fields within it, and then being
returned.  It is platform-specific whether this causes a move.  It seems to be
working on x86_64, but causes a segfault on aarch64.  Box the struct so that it
isn't moved after being initialized.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-06-26 16:43:56 -06:00
Dinesh Kumar K 0fa46270c0 boot: Add MCUBOOT_HW_KEY support for image encryption
Currently encryption supports only private key embed
in mcuboot itself. To support MCUBOOT_HW_KEY for image
encryption boot_retrieve_private_key() hook is added.

This hook helps retrieving private key from trusted
sources like OTP, TPM.

Signed-off-by: Dinesh Kumar K <dinesh@linumiz.com>
2024-06-12 15:17:54 -06:00
Tomi Fontanilles d4394c2f9b mbedtls config: fix too early check_config.h includes
check_config.h was included manually by custom configuration files.
This caused compilation errors when updating MbedTLS to 3.6.0
because check_config.h was processed too early, before the whole
configuration is defined, effectively causing configuration check errors.

MbedTLS already takes care of including check_config.h at the right time.
Remove those erroneous manual check_config.h includes.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-04-25 11:05:54 +02:00
David Brown 80704f874b sim: Allow slow tests to be skipped
The normal simulation test takes several hours to run on most machines. Allow a
few very slow tests to be skipped by setting the environment variable
`MCUBOOT_SKIP_SLOW_TESTS` to some value. For obvious reasons, this shouldn't be
done if these power failure simulation tests are needed.

With this change, on my desktop Linux machine, the test time with the skipping
goes from about 2 hours, to around 5 minutes.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-04-19 11:50:52 -06:00
Roland Mikhel fb5507b4a4 sim: Replace hash with SHA384 when P384 is used
Currently all the hashing functionality is done with SHA256
but if we would like to use ECDSA-P384 that requires SHA384
as the hashing algorithm. However, MCUboot is using SHA256
for image hashing and public key hashing. This commit modifies
the hashing operations to use SHA384 thus SHA256 can be omitted
which is beneficial from a code size standpoint.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I364eefe334e4fe6668b8a3b97991b5dbb0c80104
2023-09-12 16:29:11 +02:00
Roland Mikhel 5899face4d sim: PSA Crypto ECDSA enablement
This commit enables ECDSA signature verification using
PSA Crypto API.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I33f559ecdd59b1ce41c6a2d5f315212300d585e3
2023-09-12 16:29:11 +02:00
Roland Mikhel 23fdb0d20b sim: Revert changes to cap values
This commits reverts the changes made to cap values in 75c7c31.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: Ibbbf66e89d059ef4e4b45218a8a39778c849f21b
2023-06-30 18:02:20 +02:00
Roland Mikhel 6945bb6cb4 sim: Add new ram-load test cases
Adds new test cases to various ram-load related logic.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I3a0ca951b2c720be4e6fe2ed0e5d1830fcfb240c
2023-06-29 13:21:30 +02:00
Roland Mikhel 820e9ccef5 sim: fix encryption for ram-load related tests
If ram-load is being used with encryption and
the higher version image is loaded from the primary slot the
verification will fail as the image is always non-encrypted
and will produce an invalid hash. This fix puts encrypted images
into both slots to prevent this issue.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I4ac9f332434a95d140c5572096b8a9161db2d217
2023-06-29 13:21:30 +02:00
Matthew Dalzell 34d5a6915f Tests: Enable psa-crypto-api feature
This patch enables psa-crypto-api feature

Signed-off-by: Matthew Dalzell <matthew.dalzell@arm.com>
Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2023-06-28 15:24:06 +02:00
Antonio de Angelis 65eb35c2c7 sim: Initialize PSA Crypto subsystem based on psa-crypto-api feature
If the psa-crypto-api feature is defined, the simulator will
initialize the PSA Crypto API exactly once. It needs also to
enable the test external RNG as the assumption is that the
PSA subsystem is configured to use MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG

Signed-off-by: David Brown <david.brown@linaro.org>
Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Signed-off-by: Matthew Dalzell <matthew.dalzell@arm.com>
Change-Id: Id02727b8673867ecf1e4fbbdfa3c4b6d6f98f8df
2023-06-28 15:24:06 +02:00
Roland Mikhel d6703520d1 sim: Add hw-rollback-protection feature
This commit adds simulator support to test the
hw-rollback-protection feature which is using
nv-counters. In the simulator they are stored in Rust
to prevent any race conditions from happening due to
the parallel execution of the tests.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I445fc50615ed1f0c06e5933b16811c24d9d302fc
2023-06-27 14:42:34 +02:00
Antonio de Angelis 02bf072d2d bootutil/crypto: Refactor the RSA signature verification and encryption
This patch refactor the RSA operations done by the signature verification
module and by the encrypted images decryption module. Previous solution is
tightly coupled with Mbed TLS, while this patch provides an abstraction of
the RSA functionalities in a dedicated crypto abstraction header, crypto/rsa.h
that supports both Mbed TLS APIs and PSA Crypto APIs. In case of PSA Crypto,
the verification scheme is directly provided by the crypto backend hence it
simplifies the operations done in the image verification module.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I973bc3374b62eee2d7717c2368bce7611d37a0c8
2023-06-09 14:35:28 +02:00
David Vincze 4395b80976 boot: Restore and extend the usage of 0x22 TLV (ECDSA256)
The IMAGE_TLV_ECDSA256 TLV has been put out of use by
commit 63d2346da4.
This commit reverts this part of that patch and at the
same time it extends the usage of this TLV to cover all types
of curves (replacing the newly introduced 0x25 TLV type)
while retaining its value (0x22) for backward compatibility.
Rename IMAGE_TLV_ECDSA256 to IMAGE_TLV_ECDSA_SIG.

Change-Id: I904f292db775c38f26a5e9a87c5f414165efc173
Signed-off-by: David Vincze <david.vincze@arm.com>
2023-04-28 11:40:31 +02:00
Antonio de Angelis 10529d3032 bootutil/crypto: Have a single ECDSA verification module
Remove the generic ECDSA verification module and keep the
existing one, just renaming it image_ecdsa.c. Make sure
that the abstraction layer is generically called ecdsa.h
and the abstraction names are not P256 specific.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I6f78cfc1b1c2851cdad67efa91c6cb49498187bb
2023-04-26 13:57:53 +02:00
Roland Mikhel 30978516d3 sim: Remove curve specific ECDSA TLVs
Remove those TLVs that are tied to a specific curve and modify the
code to use the new generic ECDSA TLV.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: Iffe9052580c99e75118cf5df4286e0e9a2af4a8c
2023-04-26 13:27:44 +02:00
Roland Mikhel 6205c10fea sim: Add generic ECDSA TLV support
Add support to the simulator so that
the generic ECDSA TLV can be tested.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I3322ed829d150ff35abfaaa8ecf69ab7017bd7cf
2023-04-26 13:27:44 +02:00
Roland Mikhel 75c7c310dc sim: Remove P224 curve references
MCUBoot dropped P224 curve support as
there is little interest in using it.
The simulator threw an error as P224
was never supported, this was removed.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I96011e9b00dbc3a6f7590db365a5f480d85394e1
2023-04-11 07:05:38 +02:00
Dominik Ermel b1d4e00186 sim: Add flash_area_get_sector
Commits adds implementation of flash_area_get_sector that
is supposed to replace flash_area_sector_from_off.
The flash_area_get_sector gets additional parameter of flash_area
type, while flash_area_sector_from_off uses hardcoded flash_area.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-14 08:13:20 -06:00
Dominik Ermel 453e8bd7de flash_map_backend: Remove flash_area_id_to_image_slot
The function has not been in use and some ports have not been
implementing it anyway.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 16:40:21 -07:00
Andrzej Puzdrowski 9324d2b896 sim: Added test for over-sized image update
Added test which checks whether too big update image
will be rejected.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 26d19d330a sim: Added test for over-sized image bootstrap
Added test for check whether the bootstrap will fail for too big
image.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 5b90dc891e sim: image trailer size differentiation
Differentiated image trailer size for swap-using-scratch with
max-align-32 feature and without it.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 5310d554dd sim: corrected maximal image size calculation
Corrected the maximal image size calculation for
the swap using scratch mode. Previously the vale which
is appropriate for the swap using move mode was used.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 453b0dd790 sim: added flash_area_sector_from_off() API implementation
Added implementation of the above API function.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-06-14 11:25:02 +02:00
Andrzej Puzdrowski cc547a76da sim/mcuboot-sys: provide sim-own porting files
The sim platform was sharing a few header
files with the zephyr-rtos port. This patch provides
sim own headers.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-06-14 11:25:02 +02:00
Andrzej Puzdrowski a914048bee sim/mcuboot-sys: mbedtls configuations
copied configurations form the zephyr port

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-06-14 11:25:02 +02:00
David Brown 93d02179b3 sim: Trivial dependency updates
Update dependencies that don't require any code changes.  This leaves
'aes' and 'cipher' which will require code changes to support newer
versions.

Signed-off-by: David Brown <david.brown@linaro.org>
2022-04-12 08:11:57 +02:00
David Brown 42a7e545bf sim: Migrate to Rust 2021 edition
Change the edition in the various Cargo.toml to 2021.  There are no
changes to the code needed for this.  This will require Rust 1.56 in
order to build.

Signed-off-by: David Brown <david.brown@linaro.org>
2022-04-12 08:11:57 +02:00
David Brown 1bc106e44c sim: Homogenize max-align-32 feature check
This feature check was done statically instead of dynamically in the
build.rs file.  Change this to match the rest.  Perhaps we might want to
change all of them to be done at compile time, but that should be done
with all of the features.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-12-17 08:54:09 -03:00
Gustavo Henrique Nihei 7bfd14bbc5 sim: Fit unit tests to larger write align values
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-12-16 13:19:12 -07:00
Gustavo Henrique Nihei 4aa286d2db flash_map: Increase minimum supported write align via flash_area_align
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-12-16 13:19:12 -07:00
Fabio Utzig b3039fd659 sim: Remove unused variables
Fix warning running the simulator due to variables that are not being
used anymore.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2021-12-16 07:34:50 -03:00
Fabio Utzig 5577cbd833 sim: define stm32f4 with non-linear sectors slots
Change the flash layout of the stm32f4 simulated device to include
sectors of different sizes inside both slots; both slots have been
updated to still share the same layout. This layout changes allow for
testing and validation that a swap with scratch is possible even if not
all sectors inside a slot are the same size, as long as they all fit in
scratch.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2021-12-13 23:16:20 -03:00
Gustavo Henrique Nihei 1d7f496e1d sim: Calculate offsets from boot_max_align instead of hardcoding them
This patch prepares the simulator to execute images with a max align
value other than 8 bytes.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-11-30 13:42:52 -03:00
David Brown b408b43a9f sim: Reduce most false failures due to ECDSA size change
The encoding of ECDSA signatures is variable sized.  Better support this
by allowing the TLV size estimate to be off by as much as 6, but only in
the case of ECDSA signature.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown c8d62018b9 sim: Update Linaro copyrights
Update to current year for files modified.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown 7e0d3b427a sim: Remove profile config from mcuboot-sys
Having profile configuration in sub crates generates a warning every
time Cargo is run.  Remove these lines, as the top-level Cargo.toml file
defines these values.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown 07dd5f0ae1 sim: Test maximally sized images in some cases
When passed `Largest`, as the image size, compute the largest possible
image for the test.

This currently fails when 'swap-move' is enabled or
'overwrite-only,large-write' is enabled.  Allow this by not testing
maximal images in these cases.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown a62c3eb628 sim: Prepare for largest possible image sizes
Instead of just passing in a numeric value for the image size, create an
enum that can use a given size, or supports a `Largest` size.  Largest
is not implemented yet, but this gets the types in place for this.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown ef4f074c9b sim: Add size estimate to TLV
In order to generate images that match exact sizes, we need to know the
size of the TLV.  We can estimate this size before the payload is added
(since the payload doesn't directly affect the size).

This patch adds the size estimate, and compares it with the actual TLV
size.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown ac655bbddb sim: Functionalize the code a bit
Instead of setting a mutable variable and possibly assigning to it, just
set the variable to the result of the conditional.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown 0bd8c6bf2a sim: Add doc comment to `make_tlv`
Document this function.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown d8713a5d48 sim: Fix ordering on TlvFlags
This enum ended up with some fields out of order.  Fix the order.  No
impact to the code, as each enum entry has a specific value, this just
makes the whole enum more consistent.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
Raef Coles 3fd3ecca7a sim: add tests for partial ram-loading
Signed-off-by: Raef Coles <raef.coles@arm.com>
2021-11-05 09:38:10 -06:00