Commit Graph

295 Commits

Author SHA1 Message Date
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
Fabio Utzig 01ccb1997e Initial porting guide 2017-07-10 17:44:15 -06:00
Fabio Utzig ebeecef4b4 Refactor of main test code
- Some helper structs added to track state
- Add new trailer checking routine
- Add extra test for upgrade+revert with failure
- Misc improvements

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-10 16:31:47 -06:00
David Brown ada28e1b69 samples: Create a zephyr sample
Most of the meat of this is in the Makefile, which is able to build the
bootloader, and two small applications, along with instructions on how
to load these into flash and test that upgrades work.

JIRA: MCUB-62
Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-10 11:16:25 -06:00
Fabio Utzig e08f087ee5 Update imgtool to write trailer in new format
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-06 10:03:55 -06:00
Fabio Utzig a0bc9b5469 Update trailer format
This implements changes according to MCUB-14, easing the process
of making external apps parse and read/write the trailer.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-06 10:03:55 -06:00
Fabio Utzig 40b4aa07de Fix offset print writing to non-erased area
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-06 10:03:55 -06:00
aditihilbert ba5d3a7de8 Create RN1.0 2017-06-30 18:51:50 -07:00
Fabio Utzig 786a63786a Merge pull request #75 from utzig/fix-coverity-issue1
Fixes trying to close an invalid flash map handle
2017-06-29 23:45:42 -03:00
David Brown 98da04f0fd zephyr: frdm_k64f: Remove partition defines
Now that the partition table has been added to the device tree for the
frdm_k64f in upstream Zephyr, these symbols become redundant defines.
Remove them to fully use the partitions defined in Zephyr.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-06-29 08:56:23 -06:00
Fabio Utzig c08ed21fab Fix mynewt assert reading header from scratch
For mynewt flash map only accepts values for slot 0 and 1. This
code was trying to read the image header on the scratch area using
the same interface and was segfaulting when slot0 and slot1 had
similarly sized images.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-06-28 08:44:31 -06:00
Fabio Utzig b00d648841 Fix syntax error
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-06-28 08:44:31 -06:00
Fabio Utzig 0f22991880 Add PKCS#1 1.15 config option
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-06-28 08:44:31 -06:00
Fabio Utzig a7b19707c3 Fix syntax error
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-06-28 08:44:31 -06:00
David Brown 3e27386a12 Remove old 'imgtool' and 'zep2newt.py'
Now that script/imgtool.py contains all of the functionality of these
tools, remove the old tools from the tree.  The zep2newt.py was only
able to perform a limited set of signatures.  The 'imgtool' requires a
'Go' toolchain, which has been a hinderance to many users.

Please see `doc/imgtool.md` for directions on how to use this new tool
for image signing.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-06-28 08:29:33 -06:00
Fabio Utzig e768626d67 Fixes trying to close an invalid flash map handle
This error was catched by Coverity and it happens when a fail occurs
opening a flash map handle, which is not checked by the close
routine.

Right now this only affects Zephyr, but extra checking was added
assuming that in a future Mynewt implementation close could actually
be changed to do something.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-06-28 09:26:54 -03:00
David Brown e601417c17 Merge pull request #68 from d3zd3z/pr/dco
Add docs about DCO
2017-06-26 09:35:41 -06:00
David Brown 8d751b4ee3 Merge pull request #73 from jamike/fix_rsa_define
rsa: fix: use #ifdef MCU_BOOT_RSA_PKCS1_15 instead of #if
2017-06-26 09:35:21 -06:00
Michel Jaouen 74783c464d rsa: fix: use #ifdef MCU_BOOT_RSA_PKCS1_15 instead of #if
As this flag is tested with #ifdef everywhere else, use #ifdef in
image_rsa.c

Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
2017-06-26 16:55:10 +02:00
David Brown c208159284 Merge pull request #72 from jamike/disco_l475_iot1_support
zephyr: targets: add support for disco_l475_iot1
2017-06-23 10:49:28 -06:00
Michel Jaouen f710d21ca3 zephyr: targets: add support for disco_l475_iot1
Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
2017-06-23 10:31:31 +02:00
David Brown 9f8fe9e312 Merge pull request #69 from d3zd3z/pr/ctabs
sim: Match spacing on csupport/run.c
2017-06-21 08:50:34 -06:00
David Brown 7ad8088a57 sim: Match spacing on csupport/run.c
Re-tab run.c to match the rest of the files in the system.  This was
indented using Zephyr conventions (tabs for indent).  Re-indent using
spaces, with a 4-space indent level.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-06-20 15:30:36 -06:00
David Brown f1a78fc1c6 Add docs about DCO
Create a SubmittingPatches.md file similar to the one in Linux.  This
includes the Developer Certificate of Origin which clarifies the meaning
of the Signed-off-by trailer in the message.

Patches merged after this, should have Signed-off-by lines.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-06-20 12:57:27 -06:00
Fabio Utzig a27039767f Merge pull request #54 from mbolivar/sim-tweaks
Simulator tweaks
2017-06-20 13:36:35 -03:00
Marti Bolivar 51d36dd592 sim: add stricter write checking
Extend the flash emulation in the simulator to verify that the
bootloader explicitly erases flash before writing to it for a second
time.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-19 14:46:48 -06:00
Marti Bolivar 1acfa30497 bootutil_log: send simulator logs to stderr
This matches the behavior of Rust's logs.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-19 14:40:58 -06:00
Fabio Utzig 424d9a4f44 Merge pull request #66 from mbolivar/flash-map-updates
Flash map updates, redux
2017-06-19 15:10:59 -03:00
Fabio Utzig 0002bf8c85 Merge pull request #65 from d3zd3z/pr/fixpip
doc: Fix 'pip' example
2017-06-19 11:48:41 -03:00