Commit Graph

433 Commits

Author SHA1 Message Date
David Brown cb1bb48bb5 imgtool: Fix ECDSA signatures
Earlier refactoring created a call for get_public_bytes() that was added
to the RSA class, but missed on the ECDSA class.  Add this call so that
ECDSA signatures will work again.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Fabio Utzig 9911b1864b Allow keyhash lengths smaller than 32 bytes
The keyhash should be able to have any size up to the maximum allowed
size of 32, but the assert was not allowing images created with newt to
be accepted as valid (newt currently uses only 4 bytes for keyhash).

Signed-off-by: Fabio Utzig <utzig@apache.org>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Fabio Utzig 36ec0e7bf4 Add #ifdef for non-used function in overwrite only
Signed-off-by: Fabio Utzig <utzig@apache.org>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Fabio Utzig 4649072b1b Adds total size of a swap to the trailer
When starting a swap upgrade, the total size of data to be swapped is
calculated only at the beginning and saved to the trailer. This avoids
having to use complicated heuristics to find the total swap size, which
might depend on data that was already moved. When resuming a swap, the
size is found in the trailer and used.

Also includes some small comment fixes and refactors.

Signed-off-by: Fabio Utzig <utzig@apache.org>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Fabio Utzig 2eebf110dd Fix return value of function
Signed-off-by: Fabio Utzig <utzig@apache.org>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Fabio Utzig de6edc3142 Fix tabulation
Signed-off-by: Fabio Utzig <utzig@apache.org>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
David Brown 3eaa2a1992 Rename misleading local variable
The local variable 'size' is actually the offset of the end, and not the
size.  Rename it to reflect this reality.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Marko Kiiskila 8dd56f3f14 Change IMAGE_TLV_RSA2048 -> IMAGE_TLV_RSA2048_PSS
Clarify the name of the TLV field to more fully describe the signature
type.

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Marko Kiiskila 22a46b2d4a Remove PKCSv1.5 sig format option from RSA
Since we are changing the image header format, there is no reason to
continue to support the old PKCS#1 v1.5 signatures.  Remove the
definitions, and conditional complication related to this, and only
support the newer PSS signatures.

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Marko Kiiskila 833005e2d0 Mynewt: compile time indicator telling that using new img format.
Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
David Brown 72e7a5176f Change the image header magic
Since we've changed the meaning of several fields in the header, bump
the header to a new magic number.  The fields that are still present are
in the same place, but all of the signature and TLV information is moved
into the TLV itself, which is still immediately after the image.

As of this commit, this defines the new image header/TLV format used for
1.0.

Based on work by Marko Kiiskila <marko@runtime.io>

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
David Brown f5b33d8b9d Place TLV size into TLV itself
To allow the signatures to be replaced, move the size of the TLV into a
small "info" header at the start of the TLV.

Note that this causes image swapping to lose robustness.  This is fixed
by a later commit.

Based on work by Marko Kiiskila <marko@runtime.io>

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
JIRA: MCUB-65
2017-09-06 16:16:58 -06:00
David Brown 43cda33c5a Move key_id from header into TLV
Remove the key_id field from the image header.  There are two problems
with this field.  First, it is only an integer offset, and so causes an
unnecessarily tight coupling between the particular keys built into the
bootloader, and the key that is used to sign.  Second, it makes the
key_id part of the image header, which is included in the signature.
This makes it impossible to later sign the image with a different
signature.

Instead of the key-id, add a TLV KEYHASH entry.  This will hold the
SHA256 of the public key that the signature is against.  Each signature
placed in the TLV should be preceeded by this entry to indicate the
public key used.

The signature check will check each signature, and if the KEYHASH is
known and the signature type is supported, it will be checked.  As long
as at least one signature is considered valid, the image will be
considered signed.  This also allows the image to be signed with
multiple signatures to support having different devices with possibly
different keys compiled into the bootloaders.

Based on work by Marko Kiiskila <marko@runtime.io>

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
David Brown 76528c4406 imgtool: Add rust language support to ECDSA
Generate rust code for ECDSA signatures, when requested (rather than
raising an exception)

Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
David Brown d36e91acc1 imgtool: Add rust pubkey generation
Add a `--rust` flag to the getpub subcommand to output the public key in
Rust format rather than C.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
David Brown 27648b8344 Renumber the TLV type values
In preparation for moving the signature related values out of the main
image header and into the TLV, renumber the existing TLV values to be
grouped together better.

The SHA256 is moved into the first group, at 0x10, and the signature
values themselves are moved to start with 0x20.

This change is the first in a series of changes toward the new v1.0
image format.  The intermediate results are all internally consistent
(meaning that the simulator, and the builtin imgtool.py will all work
together), but until all patches are applied, the image format is not
valid with any external tools.

Based on work by Marko Kiiskila <marko@runtime.io>.

Signed-off-by: Marko Kiiskila <marko@runtime.io>
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-06 16:16:58 -06:00
Carles Cufi d783809566 zephyr: doc: Mention the DT flash description
In order to build for a particular Zephyr board, the Device Tree
definition for it in the Zephyr tree must include the flash description.

Additionally mention that a .hex version of the image is available,
useful for those flash tools that deal with Intel Hex files.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-01 08:22:42 -06:00
Marti Bolivar f4d0e1adf2 zephyr: turn off I2C
Upstream Zephyr is making a habit of enabling subsystems on any board
that supports them. That's a potential security risk if any of those
allow interference with the running bootloader, and is currently
exceeding mcuboot's flash allowance on some STM32 targets,
e.g. 96b_carbon. Turn off I2C to restore the build for those.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-31 08:29:53 -06:00
Marti Bolivar 4094813181 zephyr: force mcuboot to fit in the boot partition
Add a DTC overlay file which uses the boot partition as the code
partition.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-31 08:29:53 -06:00
Tyler Baker 6cff59a616 zephyr: add nrf52_blenano2 target
Adds a new zephyr target for the nrf52_blenano2. This is the BLE
Nano 2 board created by Red Bear which contains a NRF52832 MCU.

Signed-off-by: Tyler Baker <tyler.baker@linaro.org>
2017-08-24 13:19:11 -06:00
David Brown fd1f76648e zephyr: Add Hexiwear k64 support
The hexiwear k64 is very similar to the frdm_k64, as far as mcuboot is
concerned.  The partitions are now defined in DTS in Zephyr, and this
target file just needs the device name, sector size, and alignment.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-08-24 07:07:56 -06:00
David Brown 35fd554d4f Anchor mynewt ignored directories
Without the leading slash, these ignore lines will ignore these names in
any subdirectory.  This was ignoring Zephyr targets files, because of
the same name.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-08-24 07:07:56 -06:00
Fabio Utzig 9521a38165 Merge pull request #104 from mbolivar/design-doc-fixups
Design doc fixups
2017-08-10 10:01:51 -03:00
Marti Bolivar d9072bc3c8 zephyr: s/BLUETOOTH/BT/
Upstream has made a breaking namespace change. Keep up.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-09 15:43:09 -06:00
Marti Bolivar 048d8d8aa9 doc: design: rewrite state space in terms of "swap types"
The current "boot states" description doesn't make sense and shouldn't
be used.

For one thing, with three possible pending states, two possible
confirmed states, and two image slots each with a combined (pending,
confirmed) state, the total number of boot states is 36, but the
document says there are "four possible states".

For another, the actual bits on flash map to the "boot states" in a
way that is carefully designed to ensure that only those 4 are the
"outcome" of a boot.

The fact that this map does not cover the entire space of what is
being presented as the "logical" states of the device is a strong
indication that the pending/confirmed state space is a bad choice, not
connected with the actual operation of the bootloader.

A state space that is better for describing how the bootloader behaves
is given the by the enumeration of "swap types" which appear under
each of the tables in the "IMAGE TRAILERS" section, as well as the
bootloader code itself.

To help fix the description of the bootloader' operation, rewrite the
"boot states" portions of the design document, deleting the
pending/confirmed "states" and replacing them with swap types.

There is still more work to do here:

- There is still an "important caveat" to describing things in
  terms of swap types, which means it's not quite right.

- It's strange to say that "none" is a swap type.

- This doesn't provide a clean explanation for how mcuboot handles an
  interrupted swap.

But it's another step.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 19:31:15 -04:00
Marti Bolivar 1dcb685143 doc: design: fixes and improvements for swap status definition
The swap status field definition claims image data are swapped one
sector at a time, but that's not true: image data are actually swapped
around in increments equal to the size of the scratch area, which
can be multiple sectors in length.

Its contents are also misleading in claiming that it's a series of
single byte records, which ignores padding when min-write-size > 1.

It also assumes the reader knows how images are swapped, but that's
not explained until later on in the document.

Finally, the paragraph is in a list of "definitions" of the image
trailer's fields, but it doesn't actually define the contents; it's
just a high level description of what the field is for.

Fix all of these issues by re-working this paragraph.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar 4281803259 doc: design: clear up definition of an image trailer
The design document says that image trailers can be located in
scratch. That's not true: the contents in scratch are just a subset of
the complete image trailer.

Fix this up by making it clear that image trailers are at the end of
image areas, and sometimes some of their data is copied into and out
of scratch.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar a91674f1ed doc: design: overwrite-based upgrades are possible
The discussion about image slots assumes that the bootloader swaps,
but that is not all it can do. Clear this up.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar 4e64d56e4d doc: design: clarifications to "FLASH MAP" section
Distinguish between flash areas and flash area IDs. Say what the
bootloader area is, since that's not discussed anywhere else.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar 7c057e9e74 doc: design: fix image flags
Copy up to date image flags from image.h. Fixes for:

- Wrong comment for IMAGE_F_ECDSA224_SHA256
- Missing definition for IMAGE_F_PKCS1_PSS_RSA2048_SHA256

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar 49b2917c7f doc: design: trivial fixes
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar 3597312065 bootutil: trivial fixes
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:13 -04:00
Marti Bolivar 2bcdca6811 bootutil: fix comment for BOOT_SWAP_TYPE_NONE
The comment for BOOT_SWAP_TYPE_NONE says "Just boot whatever is in
slot 0". That's not correct: if configured to do so (and this the
strongly recommended configuration), mcuboot will first
cryptographically validate the contents of slot 0 before booting it.

Fix the comment to be more accurate.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 17:45:12 -04:00
Marti Bolivar f95427fe0f bootutil: cosmetic fixes to image flags
Adjust alignment and add missing leading zero to
IMAGE_F_PKCS1_PSS_RSA2048_SHA256. This needed some comment changes to
keep things 80 column clean.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-04 14:45:51 -04:00
Marti Bolivar b9f5a68dac samples: zephyr: use unified application
Replace the hello1 and hello2 applications with hello-world.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-03 07:19:06 -06:00
Marti Bolivar 7135410196 samples: zephyr: trivial Makefile fixes
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-03 07:19:06 -06:00
Marti Bolivar eba58fa360 samples: zephyr: add hello-world
This is a minimal example application that works on various boards,
without target-specific definitions, device tree overlay files, etc.

It's been tested on frdm_k64f, 96b_carbon, and 96b_nitrogen.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-03 07:19:06 -06:00
David Brown b6efee9deb Bump to version 0.9.0
Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-28 16:43:06 -06:00
Fabio Utzig 86fe4b27c4 Update design doc for compliance with implementation
Fixes: MCUB-67

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-28 16:40:29 -06:00
Fabio Utzig 69713bcb70 Fix repository for v0.9.0 2017-07-28 15:31:21 -06:00
Fabio Utzig d7f6c765d0 Add mynewt testplan
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-28 14:56:08 -06:00
David Brown 9a95b9691f Zephyr: Document testplan
This document describes the manual testing done on Zephyr.  It uses a
bunch of git patches to make modifications to the code, where each is
then tried and then backed out.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-28 12:29:28 -06:00
David Brown 8ae61c05a5 imgtool.py: Fix some errors in ecdsa key generation
There are two easy to fix problems with the ecdsa key generation code.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-28 12:29:28 -06:00
David Brown b189f1048d zephyr: Enable flash writing on ECDSA sig check
This flag was added to the RSA config file, but not the ECDSA file.  It
is needed to configure the MPU to allow the flash device to be written
to.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-28 12:29:28 -06:00
David Brown a3be264077 Bump version to 0.9.0-rc2
Version is stored in repository.yaml for mynewt.  Otherwise, put a
single mention of it in the README.md.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-26 19:02:33 -06:00
Fabio Utzig 5271b79151 Fix macro in comment
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-26 19:00:58 -06:00
Fabio Utzig 32d68f0c61 Fix names of Mynewt config options
Also documents config option to use PKCS#1 v1.5 as images generated by
newt.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-26 18:58:44 -06:00
Fabio Utzig 83e59291e2 Fix Slack's URL info
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-26 18:57:44 -06:00
Fabio Utzig 2e86e138a4 Add travis results to #builds channel in Slack
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-26 18:49:19 -06:00
David Brown 0d1b0b952e zephyr: Enable MPU flash writing
Recent Zephyr trees require this config option to be set in order to be
able to write to the flash device.  Without it, targets with an MPU
enabled will abort during startup, usually before even printing a
message to the UART.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-07-26 18:42:29 -06:00