Commit Graph

321 Commits

Author SHA1 Message Date
David Brown 6d56cd8a5f sim: Move Cargo package to top level
Instead of having to cd into the 'sim' directory, create a top-level
Cargo.toml file that adds the sim as a workspace.

For the most part, this doesn't change how the simulator works.  It is
still possible to run `cargo test ...` within the `sim` directory.
However, the `target` directory will reside at the top-level of the tree
instead of within the sim directory.

One change is that running cargo commands at the top of the tree will
run those commands on all of the packages found within the tree.
Specific packages can be tested by either changing to the directory of
that package, or passing `-p <dir>` to the cargo test command (i.e.
`cargo test -p bootsim`).

The other visible change from this commit is that the 'target' directory
will always be at the top of the tree, rather than in particular
directory where the test is run.  Any scripts or tools that expect this
to be in a certainly location, will have to be modified.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-17 10:45:53 -06:00
David Brown 7f8c0a2c4e sim: Update various package dependencies
Refresh the package dependencies, bringing in the latest versions of
many packages.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-17 10:45:53 -06:00
David Brown 9c6322f721 sim: Dependency updates
Update the dependencies in the main sim to the latest versions.  There
are some minor changes in a few of the packages, and a fairly
significant change to the aes.  The aes_ctr crate has been merged into
the aes crate, along with some changes to how it initialized.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-17 10:45:53 -06:00
David Brown e182977199 Revert "Move Cargo.toml to top level"
This reverts commit 78e4441bd3.

Although it shouldn't, this change is provoking numerous errors in
CI.  In order to allow CI to continue, revert this change, and it can be
redone later, after fixing whatever is causing the CI build failures.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-08-19 09:28:04 +02:00
David Brown 78e4441bd3 Move Cargo.toml to top level
Instead of requiring cargo to be run in the sim directory, create a
top-level "workspace" Cargo file, that references the others.  The main
result of this is that cargo can now be run in the top of the workspace,
and the 'target' directory will be placed there, rather than in the sim
directory.

This is primarily of benefit to tools such as RLS, Rust-analyzer and
various IDEs that expect a crate at the top level of the tree.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-08-17 09:28:37 +02: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 bf32c27f14 sim: Add RamData for ram loading testing
This RamData is filled in with a mapping between partitions and
information about where the data should be loaded into RAM when booting
in RamLoad mode.  This commit creates the data, but does not yet use it.

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 0dfb810d36 sim: Test DIRECT_XIP configuration
Perform simplistic test of the DIRECT_XIP configuration (both with
single and multi-images).  This verifies that the bootloader indicates
the upgrade image should be booted.

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 812a84b0f9 Add capability for DIRECT_XIP feature
Add capability detection for the MCUBOOT_DIRECT_XIP feature.

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 6db44d7a00 sim: Skip (most) tests when flash is not modified
Some configurations of MCUboot do not modify the flash, but instead
MCUboot operates in a mode where it detects the best image to run.

Detect this, and skip what is currently a majority of the tests that
expect the upgrade to be moving data around in flash.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown dcea564e0a boot: Add capability for ram loading
The MCUBOOT_RAM_LOAD feature supports configurations where code is
loaded from flash into RAM before execution.  As such, it is not
necessary for upgrades to move data around in flash.

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
Salome Thirot 0f64197aff boot: Add AES256 support for image encryption
Support only works when using mbedtls as the cryptographic library.

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 26edaf3d12 sim: Change a match with empty arm to if let
This reads a little easier.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown f66b2050fa sim: Match structure definition better
This padding field is defined as a u8 and a u16.  Clarify the marshaling
code to match instead of just looping over bytes.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown cae9e2a85b sim: Remove extra blank line
Remove an extra blank line from this file.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 173e6caaea sim: Remove elided lifetime
This lifetime can be inferred by the compiler, so remove the explicit
one.  This makes the code a little easier to read.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 80f836d19d sim: Remove complexity from an if
Clippy suggests that having a closure in the condition of an if can be
confusing in regards to code formatting.  Move the conditional outside
of the if into a temp variable.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown d36f6b1c16 sim: Remove extraneous slice reference
Clippy suggests that the reference is unnecessary when making a
comparison.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 599b2db197 sim: Simplify printing blank line
Per clippy, `println!()` should be used instead of `println!("")`.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown fbc8f7c1c1 sim: Directly iterate instead of using an index
From a clippy suggestion, replace an index iterator over a slice, and
directly use a mutable iterator over the slice.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown aec56b2ba9 sim: Combine a split conditional
Instead of nesting ifs, just use the conditional with an and operator.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 8973f5551b sim: Use Option instead of Err<T, ()>
Instead of using an Err type with no meaningful error type, just use an
Option.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 2547c00e1d sim: Use range `contains` when possible
Clippy suggests using a range with `contains` in situations where we
test if a value is within a range.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07: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 4dfb33c7c1 sim: Simplify some struct initializers
In rust, if a struct field is initialized with a variable with the same
name as the field, it is redundant to say `field: field` as the
initializer, and just `field` is sufficient.  Fix the instances of this
that clippy suggests.

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
David Brown d602ed85cf sim: Update Cargo lock file
This incorporates changes both from the dependency changes in simflash,
as well as some minor changes that recent versions of Cargo make.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-26 10:13:57 -07:00
David Brown c51949d208 sim: simflash: Convert to thiserror
The thiserror crate seems to be getting more momentum in the community
than failure.  Switch to this for deriving our own error type.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-26 10:13:57 -07:00
David Brown 641af4530c boot: Support Mbed TLS ECDSA for signatures
Add Mbed TLS ECDSA signature verification as an option (in addition to
Tinycrypt and the CC310 hardware version).  Although the Mbed TLS ECDSA
verification code is both larger and slower, this will still save space
if there is another reason that the Mbed TLS code is already being
brought in for another reason (such as certificate management, for
example).

Mbed TLS's ECDSA verification works at a different level than the other
two libraries, so this takes a bit of reworking.  There are some
additional parameters passed to the various functions, and a new define
MCUBOOT_ECDSA_NEED_ASN1_SIG to indicate that the ecdsa verification
wants the original ASN1 signature, not a decoded key.

This adds the boot changes and simulator support to test this configuration.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-23 10:29:31 -07:00
Andrzej Puzdrowski f573b392ec bootutil: extracted app common library from bootutil_misc
Part of code of boot/bootutil/ is re-implemented in zephyr-rtos
repository.
As some code are defined here and there it becomes problem when
need to include it with outstanding feature in a build.
It is possible to mitigate problem using #fdefry - but this was
rather temporary hack.

This patch introduce new module which is common for MCUBoot build
and application build.
Common code were extracted to bootutil_public.c source file and
bootutil_public.h header

MCUboot also select DISABLE_MCUBOOT_BOOTUTIL_LIB_OWN_LOG Kconfig
option, as it must define log configuration on its own for all its
sourcecode.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-01-13 17:49:49 +01:00
Fabio Utzig 4b2e55f362 boot: bootutil: drop flash_area_read_is_empty
Removes the current `flash_area_read_is_empty` which lacked a bit of
clarity in its naming and error handling, as well as requiring an
extra API in the flash map, and switches to using an internal function
`bootutil_buffer_is_erased`.

Code that was previously using `flash_area_read_is_empty` must now be
updated to do a `flash_area_read` followed by a call to
`bootutil_buffer_is_erased` with the read buffer.

The proposal was previously discussed here:

https://github.com/zephyrproject-rtos/zephyr/pull/28519

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-10-08 20:47:56 -03:00