Commit Graph

1143 Commits

Author SHA1 Message Date
Fabio Utzig 1e4284b358 Allow encrypted images in multi-image setting
Add extra encryption storage; add macro to access correct encryption
data for image being handled.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig 6f49c27a56 Add boot_serial support for multi-images
This updates `image list` and `image upload` objects to support
multi-images. The information about which image is being handled was
added to the CBOR as "image" field, which when not available, is
considered to have value 0.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig 61f08a04ae Add basic multi-image support for Mynewt
Allow Mynewt to be used in multi-image builds. Primary and secondary
slots of image 1 are hard-coded to FLASH_AREA_IMAGE_2 and FLASH_AREA_IMAGE_3.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig b63d995641 Remove function that marks encr keys invalid
Just use existing zeroize function, which also takes care of zeroing out
the encryption key data.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig ea0de009c4 Enable already fixed test in Travis-CI
Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig 268ace0f6b Zero AES key when marking invalid
Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig 6ace9ee95c Mark key_unwrap local function static
Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Fabio Utzig 81c467505b Fix build for multi-image using encrypted images
Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-09 10:00:09 -03:00
Håkon Øye Amundsen df8c8918b7 scripts: allow user to set load_addr
Allow the user to set the load_addr field of the header.
This could be useful in multi image situations to help
deduce the image number of an update without having to
look at the swap info.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2019-09-06 12:18:07 -03:00
Fabio Utzig 539d7662d1 Fix assemble.py tool for compatibility
This accounts for changes in the Zephyr build which include:

1) Flash areas are prefixed with `DT_`
2) The generated DTS was renamed to generated_dts_board_unfixed.h
3) The build tree has an extra "zephyr" dir.

Fixes #408

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-09-06 09:31:57 -03:00
Fabio Utzig 7eaaf67bbf Fix for CVE-2019-5477
https://nvd.nist.gov/vuln/detail/CVE-2019-5477

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-26 14:01:37 -03:00
Marti Bolivar f84cc4b309 zephyr: enable MULTITHREADING by default except on nRF
CONFIG_MULTITHREADING is generally assumed to be y by the zephyr
kernel, even though that's not reflected in the Kconfig. For example,
semaphores depend on it being y, but CMake will still build sem.c even
if it's n.

The sensible default for this option is thus y.

However, it's a size advantage to disable it if the platform drivers
are all aware of this option, such as nRF.

Let's re-work our use of this option to keep it disabled when we know
it's safe, but enable it by default so more platforms can be expected
to work out of the box.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-22 14:21:41 +02:00
Marti Bolivar f2a8b78c98 zephyr: delete arduino_101.conf
This board is no longer supported by Zephyr or its hardware
manufacturer.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-22 14:21:41 +02:00
Marti Bolivar 787b5cc2cd zephyr: remove ZEPHYR_BASE "bounce option" from Kconfig
These are not necessary anymore; kconfiglib evaluates $FOO in the
environment.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-22 14:21:41 +02:00
David Brown fe5ab1c35b sim: Generalize test image dumping
Decode the MCUBOOT_DEBUG_DUMP environment variable into a series of
comma-separated strings, and create debug dumps for any test that
matches one of these strings.  Also, the special string 'all' will match
every test, causing every image under test to be dumped.

The dumped images will contain an atomic counter, so that all of the
generated files will be unique for a given run.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-15 14:23:37 -05:00
David Brown 297029ab72 sim: Add debugging ptable to image dumps
Add a `debug_dump()` method to `Images` to allow the images to be
written to a file.  The dependency test will call this if the
environment variable MCUBOOT_DEBUG_DUMP is set.

In order to make these debug dumps more useful, add a simple partition
table to the beginning of the image (where MCUboot would reside on
target).  This has a simple header, and then entries for each partition,
using the partition ids used within the simulator.  This allows the
image to be more easily used by external tools.

As an example, `scripts/mcubin.bt` is a binary template for the [010
Editor](https://www.sweetscape.com/010editor/), allowing it to decode
and show the details of images from MCUboot.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-15 14:23:37 -05:00
Andrzej Puzdrowski ceb43f5f98 zephyr: add minimal footprint configuration for nrf52
Added Kconfig project configuration whit shows the
minimal flash footprint on nRF2832 SoC targets.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-08-13 15:44:17 +02:00
Andrzej Puzdrowski 960a2d616d zephyr: allow to disable timers supports
For some basic mcuboot configurations the zephyr timers are
not required which reduce the flash footprint significantly.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-08-13 15:44:17 +02:00
Fabio Utzig f0dbd422cc Return error if swap_type is not identified
While iterating over the swap table looking for swap type,
avoid asserting on errors; let caller handle error handling.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig d638b1778d Remove image_header parameter from boot_read_image_size
`boot_read_image_size` was already receiving the bootloader state and
slot; since the image_header is part of the state and can be gathered
from it, it was removed from the list of parameters.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig 1a1ec17103 Refactor trailer writing routines
This adds a single trailer writing routine that can write any amount of
data (upto BOOT_MAX_ALIGN); the functions that were writing to the
trailer now just call this one passing the offset and data/len.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig 4e8113b6ce Refactor trailer offset functions
Update each function to calculate the offset based on a previous
function offset, so that if one has to be changed not all functions have
to be updated.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig df0cc505b3 Refactor routines that read swap status data
When doing a swap some of the information required by the process
is temporarily written to the status area; previously each data
writing routines tried to find the correct area by looking for the
magic and assuming that data is located there (because everything
fits a single sector). This moves the code to find the magic into
a separate routine that is now used by others.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig 9d160091fa Remove assert from boot_status_entries
Just move error handling to caller routine.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig 15c1467fa2 Return error from boot_find_key instead of asserting
When the hash key length parameter is invalid (bigger than allowed) just
return an error for the caller routines; this will work like a not found
key and allows the removal of assert() code in this module.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Fabio Utzig c962135f1a Add macro to get TLVs offset from header
TLV offset was determined by manually adding the header and image
size in many places; this makes the addition into a macro receiving
a image_header to ease future changes.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-13 09:44:41 -03:00
Christian Skubich f13db126bd bugfix imgtool verify()
Signed-off-by: Christian Skubich <christian@skubware.de>
2019-08-09 06:58:18 -03:00
Marek Pieta e955510d13 scripts: Show image version while verifying
Change adds showing image version while verifying.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-08-08 12:00:21 -03:00
Fabio Utzig 8000e325f1 Remove global test thread locking
With the recent changes in bootutil, now there is no need to lock the
test threads to run sequentially, so the global lock was removed. The
locking now happens to access resources such as flash, flash params,
simulator context, etc on a per thread basis. Some of the global
variables that were used by the simulator itself (FFI) were made into a
context struct passed in to invoke_go.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-07 14:33:36 -03:00
Fabio Utzig 10ee648145 Update bootutil to reduce amount of global state
The boot loader state currently exists as global variable (boot_data)
which is accessed by all routines; this updates all routines that
require access to the state to receive it by parameter.

Variables that are declared as "static" (globals) were #ifdef'ed to
only use static when building a native bootloader, to avoid stack
allocation. When bootutil is built to run in the simulator they are
stack allocated to avoid thread share.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-07 14:33:36 -03:00
Fabio Utzig b0f0473352 Remove current_image global and macro updates
Currently to determine which image is being operated on, there is a global
variable called current_image which is used by most macros and APIs to
correctly access the flash areas required by the bootloader. This moves
this variable to the already existing state struct and refactors all
macros and APIs to receive the current image by parameters. To maintain
compatibility some of the macros were not updated and use image 0 when
called.

The definitions of FLASH_AREA_IMAGE_PRIMARY and FLASH_AREA_IMAGE_SECONDARY
for Mynewt compatibility were moved out of bootutil sources to a Mynewt
specific include file.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-07 14:33:36 -03:00
Fabio Utzig abec073f0f Use macro for iterating over images
Only iterates over images when BOOT_IMAGE_NUMBER > 1.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-07 14:33:36 -03:00
David Brown f9aec954e3 sim: Simplify verification methods
There are three methods that verify multiple images that essentially
manually implement the `all` and `any` methods of `Iterator`.  It makes
it difficult to understand what these do, as there is an early return of
true or false, with various negations of the check.

Replace these with calls directly to `any` or `all` so that it is
clearer what each function is doing.  The generated code should be the
same.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-07 11:30:05 -05:00
Fabio Utzig 78cc1261f3 Add Mynewt option to enable the watchdog
For Mynewt, if a watchdog driver is available, it is always used and feed
during a swap operation. Since the swap operation is able to resist resets,
the watchdog can stay disabled to preserve some flash space (watchdog
driver), with the side-effect that a swap might take longer because of
having to resume interrupted operations.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-08-06 14:25:04 -03:00
David Brown cb47dd7415 sim: Add a readable header to test images
Rather than just make the test images entirely pseudorandom data, add a
small textual header to the front that describes some key information
about each image.  This can be helpful when debugging, to determine what
exactly is in each image slot.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-06 11:26:09 -05:00
David Brown c3898d6168 sim: Add dependency tests to simulator
Create a trait `Depender` which is passed down to the image create and
verification to check and test for various types of dependency
resolution.  Add a test that uses this to test the simple case of unmet
dependencies preventing an upgrade.

The actual test is disabled (with an `if false ...`) because the code
under test loops forever in this configuration.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-06 11:26:09 -05:00
David Brown 7a81c4b61f sim: Add dependency encoding to TLV generator
The dependencies are kind of a special case, since they have to be
protected by the hashes.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-06 11:26:09 -05:00
David Brown 91d6863edc sim: Use byteorder for multi-byte values
Instead of manually expanding multi-byte encoding, use the byteorder
crate which has its own extension methods to do this.  This both makes
the code a bit clearer, and also makes it clear that these encodings are
specific to little endian platforms.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-08-06 11:26:09 -05:00
David Brown 3b09021269 sim: Simplify `slot` parameters
Many places in the image code pass a pair of

    slots: &[SlotInfo], slot: usize,

around as arguments.  Simplify this by just passing a `&SlotInfo`.  For
the few instances where code needs to know the index of a slot, add an
index field to the `SlotInfo` struct for these to use.  This eliminates
an argument from 4 functions/methods, and the numerous places they are
called.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-07-31 09:59:53 -05:00
David Brown eebf502277 sim: Allow arguments to test entrypoints
Instead of a growing number of no-argument methods that just call other
methods with fixed arguments, change the `sim_test` macro to pass
through arguments to the test methods.  This will make it easier to
further parameterize the test entrypoints.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-07-31 09:59:53 -05:00
David Brown bd7925e39e image: use explitic padding on dependency version
This struct currently relies on padding being done by the C compiler.
Although this is generally done the same across targets, this isn't
required, and it is better to make any padding explicit.  This also
makes it clear that there is extra space in this structure that can be
used for another purpose.

The python imgtool is also fixed to match.  It was using a 32-bit int,
which only worked in the little endian case.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-07-31 09:59:38 -05:00
Fabio Utzig 3901d32ead Add extra multi-image testing to Travis-CI
Enable testing of sig-rsa + multi-image + validation on Travis.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-07-30 11:39:09 -05:00
Fabio Utzig ed4a53635a Fix test/revert upgrade flash count
When doing a test with fails, the total number of flash accesses is
first calculated doing an upgrade without fails, which is then used to
fail/resume at all test points. The count was always considering the
setting of a permanent upgrade, which added 1 to the total count in a
non-permanent upgrade. This amount was being discounted when running
the test/revert with fails, although the discount was only ok for single
images. This adds a new image constructor that does not run a permanent
upgrade and thus gets the correct number of flash accesses for a
test/revert no matter how many images are being tested.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-07-30 11:39:09 -05:00
Fabio Utzig 8af7f793ae Add copy_done check after first boot
This was previously removed because it failed on multi-image tests due
to some image having finished an upgrade and having it's flag already
set. A new method was added that checks that at least one copy_done flag
is unset, thus not all upgrades have finished.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-07-30 11:39:09 -05:00
David Brown 358ca1ae4f Use Ninja instead of Makefiles for Zephyr
Zephyr builds use 'cmake' which can generate either makefiles, or use
the Ninja build tools.  There are several significant advantages to
using Ninja as the build tool:

  - It is significantly faster.  Ninja reads a directory and stats the
    files in it once.  Make often stats a given directory thousands of
    times, many for files that don't even exist.

  - It has better output.  Ninja collects commands together with their
    error output.  When doing multi-cpu builds, Ninja prints a status
    indicator, and only prints fully verbose commands when that command
    fails.  Instead of having to try an piece together a given command
    with its errors, they will always be together.

  - Make's support of multiple CPUs is a crude hack.  Make forks off
    multiple processes to use multiple CPUs.  These processes don't
    communicate with each other (very much), which causes make to often
    continue after enountering errors.  It is common for a multi-CPU
    make invocation to print hundreds or thousands of additional lines
    after an error message.

Nearly all distros have a version of Ninja available in their package
manager, making this change of low cost.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-07-29 11:29:21 -05:00
David Brown 1e1be9b368 Update Cargo.lock files
Recent versions of the Rust compile tool `cargo` insert a comment at the
top of `Cargo.lock` indicating that this file is auto-generated.  Commit
versions of these files with this comment in, so that users of recent
versions of Rust will not have sprious diffs everytime they compile.

Older versions of Rust will remove these lines.  However, this is less
likely to be an issue, as we now depend on at least Rust 1.31 in order
to have Rust 2018 support.  We recommend using 'rustup' to keep the Rust
install up to date.

Signed-off-by: David Brown <david.brown@linaro.org>
2019-07-25 16:24:20 -05:00
Håkon Øye Amundsen cbf3047d48 docs: fix typos in design.md
Minor typo fixes.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2019-07-24 07:02:20 -03:00
Tamas Ban 0c9266f66a sim: Remove copy_done check from revert_with_fails test
In case of multi image boot this check fails, because
copy_done flag set per images when an image swap has finished.
When second image update is interrupted then copy_done flag
already has set for first image.

Change-Id: Ic97dd5e4c5cdb5a5a94971f3ca84bfe0d7583dd4
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Signed-off-by: David Vincze <david.vincze@arm.com>
2019-07-23 09:11:34 -05:00
David Vincze e32483f10f Boot: Add dependency check to multi-image boot
This patch adds the capability to check image dependencies in case
of multi-image boot. The dependencies are described with a new type
of TLV in the manifest.

Change-Id: If45f81a00d4324c881634f50156f9939e1bf8707
Signed-off-by: David Vincze <david.vincze@arm.com>
2019-07-23 09:11:34 -05:00
David Vincze ba3bd606be Boot: Enable multi-image boot
This patch adds the capability to handle multiple firmware images,
to update them independently. Also update the design documentation.
It separates the completion of aborted image swap operations and the
update of images even more as these should be happening at different
stages of the boot process according to the design proposal of
the multiple image support:
https://github.com/JuulLabs-OSS/mcuboot/pull/317.

Change-Id: I7eb5f632298bb08c805bfaee0359703b2ae19e9d
Signed-off-by: David Vincze <david.vincze@arm.com>
2019-07-23 09:11:34 -05:00