Commit Graph

30 Commits

Author SHA1 Message Date
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 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 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 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 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 fd8b05eb6a sim: Upgrade to 0.7 API version of rand
There have been some revamping of the Rand API.  The Standard
distribution on floating point numbers will return a value in the
interval [0,1).

Signed-off-by: David Brown <david.brown@linaro.org>
2020-07-10 11:14:15 -06:00
Fabio Utzig 03cce47291 sim: update dependencies
Updates a few sim dependencies, reducing the amount of crates
required for a build; also gets rid of cases of more than one
version required for some crates. Results in depending on 76
crates instead of 89 before the PR.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2020-02-14 06:19:51 -03:00
David Brown e2acfaede5 sim: Add explicit copyright and licenses to the sim
Add an apache SPDX header and explicit license lines.  The date ranges
of the license lines is derived from the git history.  Having these
explicitly present will make contributions from other parties easier, as
they will simply be able to add their own copyright line, rather than
having to describe that it only covers modifications.

Signed-off-by: David Brown <david.brown@linaro.org>
2020-01-22 10:11:13 -07:00
Sam Bristow d0ca0ffc27 Fix up typos
Ran automated checker for common typos [1]. Most of these changes have
no functional change *except* for `./ci/sim_run.sh` where, previously
the `bootstrap` feature wasn't being selected properly.

I didn't touch anything in the `./ext/` folder as anything in there
should probably be fixed in the upstream repo.

[1] https://github.com/codespell-project/codespell

Signed-off-by: Sam Bristow <sam@bristow.nz>
2019-10-30 06:24:10 -03:00
David Brown 96eb0deb76 sim: simflash: Transition to failure
The Rust community has decided that 'failure' is the future, instead of
'error-chain'.  Migrate the flash simulator to this new error handling
package.  The changes are relatively minor, and the end result is a
similar `FlashError` type.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-04-17 11:20:21 +07:00
David Brown 761015712c sim: Rename `SimFlashMap` to `SimMultiFlash`
The name `SimFlashMap` is a bit misleading, as the Map part is more of
an implementation detail when the type really just represents multiple
flash devices.

This is just a rename, but the names `SimFlashMap` and the value
`flashmap` occur in a lot of places in the image module.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-04-17 11:20:21 +07:00
Fabio Utzig 25d7b0fa9f Update simulator dependencies
Since logging was broken due to incompatibility between log and
env_logger versions, those crates were updated to known to be compatible
versions. Update initialization of env_logger that does not return a
Result<> anymore.

Other crates were updated to remove duplicated versions as much as
possible.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-01-11 10:24:09 -07:00
David Brown ea25c41af3 sim: simflash: Rust 2018 idiom updates
Apply the changes suggested by

    cargo fix --edition-idioms

as well as a bit of cleanup of the results.  The result should be more
idiomatic Rust 2018 and a good starting point moving forward.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-01-03 21:39:50 +00:00
David Brown afabfcfe70 sim: simflash: Minimal 2018
Automatic migration to Rust 2018.  This is the result of running

    cargo fix --edition

The resulting code is compatible with both Rust 2015 and 2018.  Change
the edition field in the Cargo.toml file as well to begin a more
complete migration.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-01-03 21:39:50 +00:00
Fabio Utzig afb2bc90c6 Update main simulator routines for multi-flash
This adds an initial device with multiple flash (nrf52840 + SPI flash)
and updates all test routines to use a HashMap of flash devices (added
as type SimFlashMap).

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-18 15:16:11 -02:00
Fabio Utzig 1c9aea5814 Allow multiple flash devices in bootutil wrapper
A new type `FlashMap` that stores a HashMap of [device_id -> Flash trait]
was added, which enables multi-flash devices to be passed around.

The previously existing static FLASH value that was used to simulate the
raw device, was updated to using a FlashMap which enables bootutil to
interface with more than one flash device.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-18 15:16:11 -02:00
Fabio Utzig 269d28621d Remove redundant align/erased_val usage
A new align() function was added to SimFlash, and most functions that
were using/receiving align or erased_val parameters that had access to a
Flash trait were cleaned up so that they get the parameters directly
from the Flash device.

This will make it easier to extend for multiple Flash devices since
parameters should depend on the device in use.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-18 15:16:11 -02:00
Fabio Utzig ea0290b88b Add sim support for flash erased at 0
This extends the simulator to be able to test the bootloader in devices
which use flash technologies that erase flash at 0 instead of 0xff.
Two MCU devices that have this "property" are the STM32L0x and STM32L1x
lines from ST.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-09-17 12:42:49 -03:00
Fabio Utzig c354e4ac5e Update sim dependencies
This updates error-chain to remove a warning on recent rust distros.
`pem` was update to get fairly recent `error-chain` as well.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-07-10 11:11:29 -03:00
David Brown 59ae522541 sim: Remove extraneous `mut`
This value does not need to be mutable as it is just given to another
function immediately.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-01-04 10:36:07 -07:00
David Brown 3df2a0ea15 sim: Update some dependencies
Move to newer versions of some upstream packages, lazy_static, which is
now at 1.0 (no api change), and error-chain (0.11), which eliminates a
warning during compilation.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-01-04 10:36:07 -07:00
Fabio Utzig fa137fc83d Add option to disable verifying contents before writes
At the moment writes always checking that they are being
performed on an erased section of memory. This patch enables
a test to disable that, to enable looking for other error
causes.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:36:34 -07:00
Fabio Utzig f5c895e3fc Add configurable simulation of bad memory writes
Add new interface to enable configuring regions of the simulated
memory to fail probabilistically. An entry is based on an offset,
length and rate of failure. This only applies to write operatios
and throws an error that can be caught in tests.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:36:34 -07:00
Fabio Utzig 43685c211a Enable extra crates in simflash
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:36:34 -07:00
David Brown 3f687dc5bc sim: Move `areadesc` into `Images` struct
Move this struct into the images struct as well to avoid passing it
around with every call.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-11-07 09:39:45 -07:00
Fabio Utzig 65935d7111 Fix flash to not ignore write to non-erased area
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-17 15:34:36 -03:00
David Brown ccb2a1dd5e sim: Update most dependencies
Move most dependencies to the latest version at the time of this commit.
docopt is left at the current version as there is an api change in the
newer version.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 19:04:18 -06:00
David Brown 2cbc4708e9 sim: Move simflash to be its own crate
In preparation for moving the bootutil binding into a separate crate,
move the flash simulator into its own crate.  This will allow the
binding to have access to the simulator without creating a circular
dependency.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00