Commit Graph

323 Commits

Author SHA1 Message Date
David Brown 2cf522c3d8 scripts: assemble: Fix problem with missing output
Adding an os.unlink() call to remove the outfile results in an exception
being thrown if the file does not exist.  Fix this by trapping, and
checking for the specific error we get on a missing file.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-20 14:55:50 -06:00
David Brown dbc5727902 samples: Add a 'full.bin' target to Zephyr sample
This full.bin target demonstrates how to assemble all of the images into
a single file which can be flashed to the device.  As it is, it will
then boot into the first "primary" image.  The second image will be
present, but will not ever be run.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-20 14:55:50 -06:00
David Brown 51513afc07 samples: Add .gitignore to ignore output files
Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-20 14:55:50 -06:00
Fabio Utzig 253bf0f5e2 Merge pull request #87 from utzig/update-docs
Update docs
2017-07-20 17:53:30 -03:00
Fabio Utzig 095757c3ff Rename file
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 15:35:15 -03:00
Fabio Utzig f9d442829b Add 'Any' states for copy-done
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 15:05:13 -03:00
Fabio Utzig 227a97af52 Merge pull request #86 from kYc0o/riot_readme
Add README-RIOT.rst
2017-07-20 15:02:34 -03:00
kYc0o c5f4acf5b7 add README-RIOT.rst
Signed-off-by: kYc0o <fco.ja.ac@gmail.com>
2017-07-20 19:57:35 +02:00
Marti Bolivar 9203b1b9ed zephyr: nucleo_f401re: use flash defines from DTS
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-20 11:31:50 -06:00
Marti Bolivar 99b5b2cb56 zephyr: nrf52840_pca10056: use flash defines from DTS
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-20 11:31:50 -06:00
Marti Bolivar 63fa9cfd88 zephyr: 96b_nitrogen: use flash defines from DTS
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-20 11:31:50 -06:00
Marti Bolivar c868990ec6 zephyr: 96b_carbon: use flash defines from DTS
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-20 11:31:50 -06:00
Fabio Utzig 04cc4d7d3e Merge pull request #81 from utzig/fix-mcub59
Rework some of the handling of swap errors
2017-07-20 13:55:51 -03:00
Fabio Utzig dead387ab8 Add slack channel
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 13:47:05 -03:00
Fabio Utzig 756ca86f49 Fix sentence wording per review
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 13:38:22 -03:00
Fabio Utzig ac83496a53 Change references of Mynewt to mcuboot
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 13:20:48 -03:00
Fabio Utzig 2c305aab6b Fix trailer's status flags ordering
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 13:14:25 -03:00
Fabio Utzig 695d564797 Add handling for failure setting slot flags
This adds a check for failure writing flags after a swap. For now a
failure just panics the bootloader.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 12:31:48 -03:00
Fabio Utzig 740237405f Add IRC channel information
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 09:24:58 -03:00
Fabio Utzig 485f837dfc Move release notes to a more common format
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 09:20:18 -03:00
Fabio Utzig 097f76b3db Apply a few updates to README
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 08:59:51 -03:00
Fabio Utzig 5bd4e5848a Update design document to match implementation
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-20 08:55:38 -03:00
Fabio Utzig 1e56fcc447 Adds checking of image_ok before writing
When image is slot 1 had bad signature, the swap would fail and
try to write image_ok in slot 0 which if that was already a
permanent image would cause a overwrite in flash.

Fix warning/error when slot 0 validation is not enabled.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-17 15:39:14 -03:00
Fabio Utzig 645e514b79 Add test checking upgrade to image with bad signature
This test was added to exercise a bug which happens when a failure
verifying the image in slot 1 would cause a write to image_ok when
the image in slot 0 already was a permanent image.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-17 15:36:13 -03: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
Fabio Utzig db5bd3c186 Refactor finalize swap handling
After a swap operation is finished trailer control flags are written
according to the type of swap that was performed. The function names
that execute those operations were renamed to explicity reflect what
they do, and all "less deterministic" behaviors, of the type
"if flash is not set, set it", were removed.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-13 22:20:22 -03:00
Fabio Utzig d7d20756aa Fix improper revert on imgtool generated FW
This adds handling of the copy_done bit while evaluation a swap state.
Since copy_done is only ever written when a swap finishes, it can be
safely assumed that if copy_done is not set no swap was ever performed
and the image was written directly to flash, and thus no revert is run.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-13 21:24:03 -03:00
Fabio Utzig b5b2f551cd Simplify status management
This reworks much of the code, as well as tables, handling swap
state to make them simpler. Only states that require an actual
swap to be performed, perm/test/revert are checked for and acted
upon. Other possible states try to default to no operation
performed.

One extra state, BOOT_SWAP_TYPE_PANIC, was added to differentiate
between "soft" errors and unrecoverable ones (as flash read/write
errors).

Non well defined state changes after swap failures, as described
in MCUB-59 were also clean up.

This should also fix situations as described in MCUB-63, where
images generated using imgtool (magic + image_ok set) are written
to slot 0 and cause an incorrect "revert".

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-13 21:24:03 -03:00
Fabio Utzig 7b47ef7b70 Test imgtool generated FW written to slot0
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-13 21:24:03 -03:00
David Brown 52eee56746 Reload headers before verifying signature
After performing any kind of swap, reload the headers from the image(s)
before verifying the new image.
2017-07-13 17:52:20 -06:00
David Brown 554c52e64c Always validate slot 0 when requested
The MCUBOOT_VALIDATE_SLOT0 feature only verifies the signature when
there is no swapping happening.  The assumption was that if there is a
swap being done, the code will verify the signature of slot 1 before
doing the slot.

However, either due to bugs, or intentional trickery, it may be possible
to confuse the code into continuing a swap operation.  If the data is
modified before this, the bootloader can be tricked into booting the
resulting image in slot 0 without having verified the signature.

Fix this by always verifying slot 0's signature before booting it.

JIRA: MCUB-64
Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-13 17:52:20 -06:00
David Brown 046a0a6224 sim: Upgrade docopt dependency
The docopt package has moved from rustc-serialize to serde.  Move to
this version, upgrading the custom deserialize we use for the alignment
argument.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 19:04:18 -06: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 0b693c0c74 sim: Enable -Werror
Enable -Werror in the build of the C code (also remove an unneeded TODO
comment).

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 704ac6f570 sim: Conditionalize rsa signature checking
Allow a build with sig-rsa set or not set.  Only add the signature to
the TLV if we are building with the signature checking.
2017-07-12 15:00:57 -06:00
David Brown f52272c76d sim: Flatten 'area' module in mcuboot-sys
It isn't necessary for the 'area' module to be exposed.  Re-export the
two definitions from the crate at the top level, and make the module
private.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown d2b1853f02 sim: Move csupport into mcuboot-sys
This C code is also part of the binding.  Move it into the binding crate
to reflect this.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 82bf7c2d09 sim: Move mbedtls into mcuboot-sys
The mbedtls library is used by the binding crate, so move the submodule
into this directory as well.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 6390277f64 sim: Naive move of binding into mcuboot-sys
Create a crate `mcuboot-sys` to hold the building and binding of the
mcuboot code.  There aren't any substantive code changes here, just
moving the code into a separate crate.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 7e701d8ca3 sim: Add RSA signature verification to simulator
Using the published debug keypair, generate a signature with it, to add
to the TLV.  This verifies that signature verification works as
expected.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 1e15859951 sim: Switch to bitflags from enumflags
The bitflags crate seems to be better supported, and doesn't have the
problems getting the results back into the enum type.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 4243ab09f8 sim: Capture payload in TLV code
Since the signing code will also need a copy of the message, make a
local copy of it in the signature verification code, and compute the
digest all in one shot.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 8054ce281a sim: Change to `ring` instead of `rust-crypto`
The ring crate's SHA256 is slightly slower than the one from
rust-crypto, but is much cleaner to use.  It also has all of the hashing
operations we need.

This crate is somewhat opinionated, e.g. will not sign messages without
also performing the signature itself.  Unfortunately, this means we'll
end up computing signatures of the same data many times, and perhaps
this should be improved, since we're always using the same data.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 187dd889dc sim: Validate the SHA256 verification
Instead of stubbing out the image validation code, compile it, and add
the SHA256 TLV to the buffer.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -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
David Brown 7ddec0b5cc sim: Move 'Flash' into a trait
Make 'Flash' a trait, and move the current functionality into a type
called 'SimFlash'.  The code that runs the simulation only uses the
trait.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown bdb6db723d sim: Move flash pointer up into Rust
Move the reference to the Flash device up into the Rust code instead of
trying to pass it back and forth to C.  This will allow a future change
to use a fat pointer (such as a trait pointer), which ultimately will
allow different kinds of flash devices.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
David Brown 2784a2e2f2 sim: Update gcc dependency
Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-12 15:00:57 -06:00
Fabio Utzig 41d18853d7 Fix remaining initial porting guide's issues 2017-07-10 17:44:15 -06:00
Fabio Utzig e2d99f8630 Fix review issues 2017-07-10 17:44:15 -06:00