Commit Graph

157 Commits

Author SHA1 Message Date
Fabio Utzig 178be54bd6 Test erased flash with "flash_area_read_is_empty()"
Mynewt has recently added an encrypted flash layer driver, that runs
transparently on any flash, handling reads and writes, and bypassing
other flash operations to the HW driver. As a result of this change,
checking for erased data cannot be done by read + compare to erased_val
but need to be routed to an empty check on the lower level. To do this
Mynewt added a new flash_map function called "flash_area_read_is_empty"
which checks for erased blocks (and reads/decrypts the data as well).

This commit uses `flash_area_read_is_empty` to determine if magic,
flags and swap status are erased. For Zephyr/sim commits were added
previously that mimic this functionality by simply doing the
read/compare.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-10-01 21:42:20 -03:00
Fabio Utzig 08fa267260 Fix copy_done setting
This compliments the previous change on `image_ok` and also removes
`flash_area_erased_val` call that is not needed anymore.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-09-27 10:52:33 -03:00
Łukasz Rymanowski a1927f4d6b Fix setting confirm flag
It was impossible to set confirm flag due to incorrect comparison.
In this point of time state->image_ok is already decoded and contains
one of following values:

If BOOT_FLAG_UNSET then we are ok to set a confirm flag.

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2018-09-26 12:20:17 -03:00
Hovland, Sigvart 1d96f36d01 Fix the wrong size of array of magic word in bootutil_misc
This will fix #335 by defining the array size of the magic word and
give it to the relevant functions.

Signed-off-by: Hovland, Sigvart <sigvart.hovland@nordicsemi.no>
2018-09-26 13:22:03 +02:00
Fabio Utzig 3900001c87 Add support for flash devices erased at 0
This extends mcuboot to allow use on devices which don't follow the
typical erased at 0xff. This was tested on some previously supported
devices (erased at 0xff) and STM32L1/L0 which are erased at 0.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-09-17 12:42:49 -03:00
Fabio Utzig 03dc9a09a3 Avoid touching the swap status area in overwrite-only
The swap status area is used to maintain information that allows
recovery when interrupted in the middle of a swap. This area has no
usefulness when doing a overwrite-only upgrade, which always copies the
entire slot.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-06-13 10:42:40 -07:00
Fabio Utzig 48841f28ce Remove per file log level configs
This removes settings of log level on a per file basis. The log level
should be set by the global config, while per file log configuration can
still be set, don't enforce them.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-06-04 06:54:39 -03:00
Fabio Utzig a8e4e9714f Update logging to use per platform log macros
Now bootutil_log.h was converted to use per platform logging primitives
defined according to documentation established on the template file.

Some "null" macros were left to avoid breaking per source logging level
definition when MCUBOOT_HAVE_LOGGING was not defined.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-06-04 06:54:39 -03:00
Andrzej Puzdrowski b788c71c08 Replace mcuboot flash_map by zephyr flash_map
The patch introduce usage of zephyr flas_map module instead
of mcuboot zephyr-only implementation. Unused flash_area_to_sectors
API of former flash_map was removed as well.
Size of sector-status-update-map entry is now defined thanks to the
minimum write size supported by the flash driver.

For avoid ambiguity former zephyr-only files flash_map.c
were renamed to flash_map_extended.c (its code now implements
only addition to this what zephyr flash_map implements).

flash_map.h header include is now warped by flash_map_backedn.h headre
because implementations and include pathes are diferent in Zephyr and Mynewt.

Usage of hal_flash_align() were replaced by usage flash_area_align().
This provide consistency between MyNewt and Zephyr implementation as
this API is available in both RTOSes.

flash_map.h was moved to the simulator c-support files as now missing in
the boot/zephyr subdirectories.

f. boot_scratch_fa_device_id was removed as unused.
f. boot_img_fa_device_id was and expanded the only use of it
(on loader.c).

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-05-16 16:05:17 -03:00
Fabio Utzig b5b59f16a5 Fix leftovers from image_header v1
This removes the old "TLV size" and "keyId" fields that used to exist
in the old image header format and updates it to use `load_addr`. Also
fixes the name of reserved fields to index from 1.

This fixes #279

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-05-10 08:43:52 -03:00
Christopher Collins 2844faaccc Mynewt unit tests - Add repo prefix to dep lists.
The unit tests depend on a few Mynewt packages (`test/testutil` and
`sys/console/stub`).  If there is no repo prefix in the dependency
specifier, newt assumes the package is in the local repo (mcuboot)`.
This commit adds the `@apache-mynewt-core/` prefix to these
dependencies.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-05-01 15:05:57 -03:00
Marti Bolivar 248da08849 Move bootsim-specific assert behavior behind mcuboot_config.h
Continue removing platform-specific conditional compilation from
bootutil by adding a new MCUBOOT_HAVE_ASSERT_H configuration option
and associated header file. Right now, that's only used by the
simulator.

That leaves just bootutil_log.h with platform-specific contents, but
since it's meant to be an abstraction layer for logging, we'll let it
stand for now.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-04-25 18:44:03 -03:00
Marti Bolivar f9bfddd685 Move max image sector config to mcuboot_config.h
Take the opportunity to clean up a bit of platform cruft that has
gotten into bootutil by moving it to mcuboot_config.h, and ensuring it
is documented in the template config file.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-04-25 18:44:03 -03:00
Marti Bolivar f91bca51a6 Mandate the presence of mcuboot_config/mcuboot_config.h
Mynewt uses this file to convert MYNEWT_VAL(xxx) to MCUBOOT_xxx config
options. Zephyr currently adds config options via the compiler command
line, but it should use this instead.

As prep work for that conversion, add an empty mcuboot_config.h to the
Zephyr port, and include this file unconditionally wherever it's
needed. This takes care of the simulator as well, since that puts
boot/zephyr/include on its C file include path.

This turned up a couple of files (bootutil_priv.h and caps.c) that
were using the MCUBOOT_xxx config values without including the
file. Add the includes there, as they'll be needed later.

To make this official, add it to the requirements in the porting guide
and provide a template file porters can use while getting started.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>

fixup! Mandate the presence of mcuboot_config/mcuboot_config.h
2018-04-25 18:44:03 -03:00
Fabio Utzig 1b2f5ceb57 tabs -> spaces
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-04-05 18:15:35 -03:00
Fabio Utzig a1fae67d8a Add config for BOOT_MAX_IMG_SECTORS
This still defaults to 128 for compatibility, but allows users to
specify less elements to save space, or more elements for devices that
have massive flash size and/or too small sectors.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-04-05 18:15:35 -03:00
Fabio Utzig 2a33aa26ed Add logging support for Mynewt
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-03-29 16:33:25 -03:00
Fabio Utzig 6771601435 Fix printf size warning
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-03-29 16:33:25 -03:00
Johann Fischer ed8461b604 bootutil: loader: fix BOOT_STATUS_ASSERT macro
BOOT_STATUS_ASSERT increments the variable if the macro argument
is evaluated as true, which is incorrect behavior compared to the
ASSERT macro.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-02-16 16:44:17 -07:00
David Brown 785dc4c9b3 Fix RSA sigs for mbed TLS 2.7.0
In 2f8f06aa25

    commit 2f8f06aa25e9d5ee4fc9fe217543c872b39e4d05
    Author: Hanno Becker <hanno.becker@arm.com>
    Date:   Fri Sep 29 11:47:26 2017 +0100

        Don't always recompute context length in mbedtls_rsa_get_len

mbed TLS begins assuming that the 'len' field of the context has been
set properly.  Previously, we relied on this not being true, and various
tests fail for all keys without setting this.

The fix is to simply set the length based on the value we read.

fixes #235.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-02-13 15:10:36 -07:00
Fabio Utzig f70e302617 Fix warn in overwrite-only with slot0 validation
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-01-10 10:35:10 -07:00
Fabio Utzig 891f4fb023 Fix EC API usage due to change in mbed-TLS
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-01-10 10:34:45 -07:00
Fabio Utzig 9c25fa76e5 Avoid using uninitialized memory in split go
Since boot_read_image_headers only failed when reading headers from
both Slots failed, it could happen that even with a failure reading
Slot 1, this data would still be used by split booting. Now when
reading image headers an extra parameter allows the caller to ask
for failure when any slot read failed.

JIRA: MCUB-56
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-01-04 10:35:26 -07:00
Fabio Utzig 539860453c Remove duplicated copy/paste residue
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-01-04 10:35:26 -07:00
Fabio Utzig 57c40f7164 Fix assert abstraction in sim
Assertions that are expected to fail under sim test, are now marked as such
using the macro ASSERT which allows to programmatically switch between normal
assert() behavior and captured assertion.

Assertion changes were moved to more appropriate owners and code duplication
was removed.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:36:34 -07:00
Fabio Utzig a0e1cce57a Enable ignoring write failures to status area
The rationale behind this change is that while performing a swap
operation, writes to the status area are not important enough
to abort the operation. If the swap is not interrupted, status
writes are ignored. If the swap is interrupted, failures to write
status area are detected during the next boot and an appropriate
measure is taken.

If MCUBOOT_VALIDATE_SLOT0 is set we ignore the status write fail
and allow slot0 to be validated by its hash/signature. Otherwise,
the old behavior is maintained, which is to abort on any write
failures.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:36:34 -07:00
Fabio Utzig 9b0ee9034a Enable capturing asserts inside simulator
When building in simulator mode, mock assert() to call an simulator
function which will enable other code to check if some path failed.

The assert checking interface, was added to boot_go which now
returns the low-level invocation results as well as the number of
asserts triggered.

Some new added tests check for assert() and expect it to happen. To not
abort tests, assert() was changed under sim env to not call c assert()
and instead just do some internal calculation which could be checked
by the simulator after a bootloader run and assert() catching behavior
was made optional (each test choses the behavior it needs).

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:36:34 -07:00
Fabio Utzig ac18eec773 Add Mynewt support for bundled tinycrypt + mbedtls
This commit removes the pseudo tinycrypt package based on symlinks
by adding a new pkg.yml to ext/tinycrypt and using it directly. It
also uses the new mbed-tls bundled ASN1 parser when EC256 is selected.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:32:59 -07:00
Fabio Utzig 1a927dd591 Update bootutil_sig_verify to receive slen as size_t
This fixes a comparison issue that was previously fixed by doing a
cast. Since tinycrypt and mbed-tls both already use an unsigned for
the size, the mcuboot interface was updated to also use an unsigned
value (size_t to be more precise!).

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-13 14:26:08 -07:00
Fabio Utzig aaf767cf8a Fix warning in overwrite only
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-13 14:26:08 -07:00
Fabio Utzig cd5774b7ba Fix for gcc warnings
Fixes warnings treated as errors when upgrading gcc crate to 0.3.54.
Warnings are due to non-used variables and comparison between signed
and unsigned.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-05 09:55:36 -02:00
Marti Bolivar c1f939d63f bootutil: fix edge case when not validating slot 0
When not validating slot 0, we could be booting into an empty
chip. This means we jump based on garbage data.

Try to make this better by at least checking the magic number. Without
this patch, booting with just the bootloader fails the Zephyr release
tests.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-20 18:10:29 -07:00
Marti Bolivar bf909a1fcc zephyr: port build system to CMake
Convert the Zephyr build to the new CMake-based sytem.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-20 18:10:29 -07:00
Fabio Utzig 13d9e35d52 Add faster copy/erase to overwrite-only mode
This add a new option to overwrite-only mode that enables copy/erase of
only the amount of sectors that are required to store the source image.

This is enabled by default when overwrite-only mode is used.

MCUB-70

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-10-19 09:28:37 -06:00
Fabio Utzig 33fa8ad78c Avoid memcpy'ing a public key by reusing buf
This implements a TODO, removing a memcpy of the public key by doing all
buffer calculation in place.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-10-19 09:27:45 -06:00
Szymon Janc 161848825d This requires Tinycrypt 0.2.7.
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-10-10 14:34:17 -03:00
Fabio Utzig b6297af620 Log error message when slot fails validation
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-10-09 16:42:01 -03:00
David Brown 6b1b3b9246 Fix warning on overwrite-only
This function is unused in overwrite-only mode.  Clang seems to catch
this, whereas gcc does not.  Add the proper ifdefs so that the
simulator tests all pass on MacOS.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-19 10:00:05 -06:00
Fabio Utzig c6a7b0c7a0 Fixes use of invalid header data
Fixes a bug when MCUBOOT_VALIDATE_SLOT0 is enabled which caused the
header in Slot 1 to be used for calculating the bootstrap offset. This
bug is masked when MCUBOOT_OVERWRITE_ONLY is not enabled because both
slots have the same header size (usually!). With MCUBOOT_OVERWRITE_ONLY
Slot 1 was erased and the header size would be read as 0xffff resulting
in a jump to the wrong address.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-09-13 17:14:22 -06:00
Fabio Utzig 8d0e5884a0 Remove trailer management for overwrite-only
When building in overwrite-only, there is no status/trailer management.
This commit fixes an issue where there was a write to image_ok/copy_done
where those flags where already set (copied from slot 1) which would
cause a write over non-erased flash.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-09-13 17:14:22 -06:00
Fabio Utzig 6a537ee361 Fix formatting warning
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-09-13 17:14:22 -06:00
Fabio Utzig a8e23e26ea Updates mynewt port to use bundled tinycrypt
This removes the dependency on tinycrypt lib provided by mynewt and
switches to the one bundled in mcuboot. Also fixes a bug where tc
was only being used when eliptic curve 256 was selected as sign
algorithm.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-09-11 18:05:45 -03:00
David Brown 6417d06ae4 Define the load_addr header field
Add a flag `IMAGE_F_RAM_LOAD` and an associated header field
`ih_load_addr` to indicate that a particular image should be loaded into
RAM instead of being executed directly out of flash.  If the flag is not
set, this field will be ignored.  If it is set, and this feature is
supported by the bootloader, the image will be loaded into RAM at the
address specified in the new header field.

None of this functionality is implemented at this time.  This is merely
to define the header format to avoid having to change the image format
later.

JIRA: MCUB-79
Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-08 16:38:56 -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