Commit Graph

150 Commits

Author SHA1 Message Date
Thomas Altenbach 2cd6ce9fb9 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>
(cherry picked from commit 60806bce8e)
2024-11-04 14:23:28 +00: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 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
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
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
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
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 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 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
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
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
Raef Coles f11de6494c boot: enable partial multi-image booting
Signed-off-by: Raef Coles <raef.coles@arm.com>
2021-11-05 09:38:10 -06:00
David Brown 5f4e1484b7 sim: mcuboot-sys: Avoid duplicate C files
When building mcuboot-sys, the build script currently adds some
duplicate files.  When used as a library, this works, because the code
is linked in as a library.  However, when mcuboot-sys is tested itself,
all specified files will be brought in, which results in duplicate
symbols for these files.

Fix this by keeping track of all of the files that we've added, and
making sure to add each file once.  Additionally, instead of using the
orphaned files in mbedtls-asn1, just always use the verions in the main
mbedtls library.  There are some configurations of the code that end up
using both the extracted files and the full mbed TLS.  Avoid that
conflict by just always using the full tree.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-27 15:22:09 -06:00
David Brown 115ce57de7 sim: Allow 'large-write' in mcuboot-sys
When collected together as a workspace, the test framework ends up
running all of the configurations on each project.  One configuration
option `large-write` doesn't really mean anything to mcuboot-sys, but
adding support for the feature allows this package to be tested along
with all of the other packages.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-27 15:22:09 -06:00
David Brown f17d39112f sim: Test ram-loading with DIRECT_XIP
Combine all of the pieces to be able to test ram loading with multiple
images.  We construct a model `RamData` that indicates where each image
should be loaded into RAM.  This has to be made early enough to compute
signatures on the images, and then used later to verify that the images
were loaded properly.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 8a4e23bb6b sim: Basic ram-load test
Test the basic configuration for ram loading.  Instead of a fixed
address for RAM, the values come dynamically from a thread-local
variable (allowing the tests to run in parallel).  The size of the ram
along with the address of the buffer in the test address space are
passed in this way.

This tests the single-image configurations of ram loading.  Testing
multi-image will take additional work, as the RAM will need to be large
enough for both images, and the second image will need a meaningful
offset address in RAM.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 11ffa0a56b sim: Support direct-xip configuration
Add simulator support for building the direct-xip configuration.
Although this builds, there are no tests that test any of the
functionality, so all current tests trivially pass.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 7e377ab17b sim: Enable sim building with ram-load
Allow the sim to test configurations with MCUBOOT_RAM_LOAD defined.
This does not define any tests for this mode.

This adds definitions for simulated RAM offsets to the simulator.  This
will define the offset (from `IMAGE_RAM_BASE`) to where the simulated
RAM will be located.  For now, just give these somewhat reasonable
values so that we are able to at least compile the RAM_LOADING code in
the simulator.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 4b82c671cf sim: Implement function in sim
The function `flash_area_id_from_image_slot` is used in the RAM_LOAD and
DIRECT_XIP configurations.  Define a version for use in the simulator.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown d82de8c7de sim: Allow access to the boot response
When the bootloader completes, it fills a response structure with
various information.  Move this into the BootGoResult and provide an
accessor for it.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 6d47d42eb6 sim: Make BootGoResult into an enum
Now that this result is abstracted, take the special case for a sim stop
and make it its own field.  This hides the magic number we use to
indicate this to be entirely within mcuboot-sys.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown c423ac4517 sim: Return abstract value from boot_go
Instead of a tuple of values that is matched, return an abstract type
that has methods for querying the information we need.  Abstracting this
will allow us to return additional information without having to change
all of the code that matches against these patterns.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown d216b20883 sim: Pass boot_rsp down from the simulator
Instead of having this struct at a fairly low level in the simulator,
with the filled-in values effectively discarded after each call, pass
the value from higher up in the simulator.  This prepares us for being
able to use the resulting data in upcoming tests.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown f1ae694fa1 sim: Fix flash_area_get_device_id in sim
commit c304a7f84a
(refs/bisect/good-c304a7f84a7e7e345457e23b179fa302b8732fb9)
Author: Dominik Ermel <dominik.ermel@nordicsemi.no>
Date:   Mon Jun 14 16:08:42 2021 +0000

    sim: Add flash_area_get_device_id implementation

Adds an implementation for this function in the simulator that just
returns 0.  Fix this to return the proper ID so that when tests start
checking for this, it will return the right value.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
Sherry Zhang f4580cb672 Update mbedtls to mbedtls-3.0.0
Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: If406625c09949cca7575d234807e49c00cbc2fa7
2021-07-16 09:42:57 +02:00
Dominik Ermel c304a7f84a sim: Add flash_area_get_device_id implementation
With switch to getter functions the implementation of the function
is now required.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-07-06 14:42:53 -06:00
Salome Thirot 6fdbf55756 Sim: Add testcases for AES256 image encryption
Signed-off-by: Salome Thirot <salome.thirot@arm.com>
2021-05-18 07:25:12 -03:00
Andrzej Puzdrowski 137d797177 sim: emits *_SWAP_USING_SCRATCH macros
Emits either MCUBOOT_SWAP_USING_SCRATCH and
CONFIG_BOOT_SWAP_USING_SCRATCH when swap using scratch
algorithm is expected.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-05-14 14:19:56 +02:00
Fabio Utzig 6c553d6741 sim: add Mbed TLS EC256 encrypted image support
Add new feature that allows testing EC256 encrypted images using the
Mbed TLS backend.

Move config-ecdsa.h to config-ec.h because definitions are very similar
between ECDSA and ECDH with Mbed TLS so resort to a single config file.

Add new feature and fix the build; add proper Mbed TLS memory
initialization when enc-ec256-mbedtls is used.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2021-05-06 21:05:47 -03:00
David Brown c20bbb22e3 sim: Remove useless `return`s
Apply clippy suggestions to directly result in values instead of
returning those values at the end of a function.  Better matches common
Rust style.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 8608c53f6e sim: Clarify condition
Clippy suggests using an if instead of using a map on an option.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 4bbb93d9ce sim: Clarify condition with is_empty()
Clippy suggests `.is_empty()` over `.len() == 0`.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 7cc4526db6 sim: unsafe cleanup
Cleanup some of the unsafe usage in mcuboot-sys.  In one case, add a
safety comment to the function documentation.  In the other, move the
unsafe to a narrower scope, reducing the number of instances of unsafe
needed.  From clippy suggestions.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown fc8e3c5b69 sim: Implement Default for a few types
Clippy suggests implementing Default when the `new` function for that
type just initializes the type to default values.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 50b5a12c31 sim: Remove pointless use lines
Top-level crates are available by name.  A use of these names is
redundant, so remove these.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 1997f539f7 sim: Remove extraneous static
According to clippy, `&'static` can just be `&` for static definitions,
which always have a static lifetime.  Clean this up in the arrays in the
code, as well as generation code in imgtool.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00