Commit Graph

346 Commits

Author SHA1 Message Date
Andrzej Puzdrowski 8a67dba367 fix default value for serial recovery mode detect port for nRFx devices .
Zephyr's SOC_FAMILY_NRF5 keyword was changed to SOC_FAMILY_NRF to
align with zephyr code-base.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-10 10:36:20 +02:00
Andrzej Puzdrowski 386b592109 use zephyr tincybor instead of mcuboot build-in tinycbor
Zephyr has build-in tinycbor code of version which doesn't
require newlib-c by default. Also the cborattr module is now
taken form the zephyr code.

This patch decrease flash consumption by 10 KB for serial recovery build.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-10 10:36:20 +02: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 30f6b2a908 Fix boot_serial to follow flash write alignment
This fixes an issue found on stm32f3 where newtmgr after writing an odd
sized packet, would hardfault on the next write due to trying to write an
odd address which is not valid on stm32f3 flash.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-04-03 11:42:58 -03:00
Fabio Utzig 1d46c944ed Always enable uart, use blocking mode
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-03-29 16:33:25 -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
Carles Cufi 0165be8ba8 boot_serial: zephyr: Use new base64 library
Instead of relying on mbedTLS' base64 codec, use the new Zephyr base64
library.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-27 10:12:11 -03:00
Marti Bolivar 58b321a89f zephyr: CMakeLists: allow users to specify DTC_OVERLAY_FILE fragments
Allow the user to add additional device tree overlays onto the default
one that sets up the code partition.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-03-26 12:46:40 -03:00
David Brown 57837b98e6 zephyr: arm: Use proper macro to set MSP
The macro _MspSet has gone away in Zephyr.  Change to use the __set_MSP
macro from the CMSIS code that has always been present.  This allows
mcuboot to build with Zephyr after:

    commit c028f88b37d2a033d6a85c8d365ef048e1e4d621
    Author: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
    Date:   Mon Mar 12 10:45:02 2018 +0100

        arch: arm: remove redundant asm inline headers

Fixes #246.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-03-14 10:09:55 -06:00
David Brown d9d28a78d4 zephyr: Fix overlay dir for Zephyr build
The Zephyr CMakeLists.txt uses its own logic to have board-specific
overlays, named boards/${BOARD}.prj.  However, the only overlay file we
have, arduino_101.conf, isn't in this boards directory, and this target
doesn't build.

Fix this by moving the target into the right directory.  Fixes #188.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-03-13 16:39:14 -06:00
Christopher Collins db974f2fc2 Mynewt app: Remove .OVERWITE suffix from pkg.deps
The boot loader app needs all the base dependencies, whether or not
`BOOT_SERIAL` is enabled.  Therefore, it makes sense for the serial boot
loader to add to, rather than replace, the dependency list.

This bug in the pkg.yml file went unnoticed ealier because of an issue
in newt: it used to effectively ignore the `.OVERWRITE` suffix when it
was applied to `pkg.deps`.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-23 20:50:37 -03:00
David Brown 3f9ec900c4 zephyr: Configure mbed TLS for PSS instead of V1.5
Although MCUboot has used PKCS#1 v2.1 (PSS) for some time now, the mbed
TLS config file was calling out v1.5.  This compiled because MCUboot
implements its own specialized version of the signature check, and only
needs the underlying primitives from mbed TLS.  (The general code in
mbed TLS is quite a bit larger).

To make it clear that we are always using PSS, change the mbed TLS
configuration to call this out explicitly.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-02-23 09:38:47 -07:00
Fabio Utzig 9f7c3d2096 Initialize "uart" only when boot_serial is enabled
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-02-22 15:51:39 -07:00
Andrzej Kaczmarek c49099c284 Make boot serial work on Mynewt
Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-02-22 15:51:39 -07:00
Fabio Utzig 1a2e41ae44 Fix serial boot functionality for Mynewt
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-02-22 15:51:39 -07: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
Fabio Utzig 84ed794d14 Fix configuration when RSA signature is used
This defines the correct "mbedtls" config files in both ECDSA256 and RSA
modes.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-02-16 16:31:38 -07:00
Ding Tao b664a082aa zephyr: mbedtls: Fix compile error no such file or directory
Upstream zephyr will automatically link mbedtls when CONFIG_MBEDTLS is
enabled.

If user chose to use ECDSA_P256 as signature type, will get a compile
error message in file ${ZEPHYR_BASE}/ext/lib/crypto/mbedtls/zephyr_init.c:
    fatal error: config-asn1.h: No such file or directory

Fix this by disable CONFIG_MBEDTLS  when ECDSA_P256 signature type is
selected.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2018-02-14 13:55:23 -02: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
Marti Bolivar 6f2857c2a7 zephyr: add compatibility shim for flash driver name
The upstream Zephyr project is renaming FLASH_DRIVER_NAME to
FLASH_DEV_NAME as part of some changes related to device tree.

Work around this for now by keeping the MCUboot name the same if
FLASH_DRIVER_NAME is not provided by Zephyr, but FLASH_DEV_NAME is.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-01 15:59:18 -07:00
Marti Bolivar aefbd46631 zephyr: try to mass erase when flashing
It's recommended practice to mass erase the flash chip before
reflashing mcuboot. Add a configuration option for Zephyr which does
this by default on some Zephyr runner backends which can support
this (pyOCD and dfu-util). Additional runners can be added as needed.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-01-30 16:17:52 -07:00
Marti Bolivar 388454880f zephyr: fix MCUBOOT_TARGET_CONFIG definition
When the target doesn't have good enough generic support for MCUBoot,
you can specify the flash layout etc on a per-board basis by creating
a header, boot/zephyr/targets/BOARD.h.

The build system tries to pick this up, but isn't doing it
correctly. Fix it.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-01-29 14:35:38 -07:00
Marti Bolivar dde1b1c481 zephyr: fix the build
Since the Kconfig file was moved in 51a0921006 ("zephyr: Move Kconfig
file to boot/zephyr"), the CMakeLists.txt reference to it needs updating.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-01-29 14:04:13 -07:00
Carles Cufi 67c792efbb zephyr: Enable flash page layout if available
Since not all ICs default to enabling flash page layout, enable it from
the MCUboot Kconfig options whenever it is available.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-29 12:22:48 -07:00
Carles Cufi 84ede5893f kconfig: Add new MCUboot device settings
Add a new MCUboot device settings option that enables or configures
features that are specific to a particular device.
Additionally enable software vector relay in Cortex-M0 CPUs that do not
have a hardware mechanism to relay or forward interrupts.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-29 12:22:48 -07:00
Carles Cufi 51a0921006 zephyr: Move Kconfig file to boot/zephyr
Since the Kconfig file is only relevant to Zephyr, move it from the root
folder into boot/zephyr, in order to keep all Zephyr-related files
together.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-29 12:22:48 -07:00
Sebastian Bøe 8680b90374 zephyr: boot: Use abs. path instead of rel. path for dts overlay
When a relative path was used the build would fail when CMake was
invoked with the -B -H flags. Using an absolute path for the
dts.overlay flags fixes #187.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-29 16:19:05 -02:00
Carles Cufi 90eda80838 doc: Fix MCUboot capitalization
The correct spelling is "MCUboot", so replace the instances that differ
from this.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-29 15:49:04 -02: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 28ee5b0ea9 Add Zephyr support for bundled mbed-tls ASN1 parser
When using EC256 for signing, Zephyr now uses the bundled tinycrypt
and mbed-tls ASN1 parser instead of relying on the one provided by
the OS.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-21 13:32:59 -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 c786540825 Add ecdsa to build
This enables building ecdsa feature using tinycrypt (mbed still built
for ASN1). The default mbed-tls config was update to use the MCUBOOT_SIGN_*
symbols.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-12-13 14:26:08 -07:00
Andrzej Puzdrowski 8e96b8352f enable serial recovery functionality on the zephyr mcuboot
This patch introduced serial bootloader functionality ported
from mynewt targets tree.

For achieving this following changes were applied:
- Modified boot_serial module for using, zephyr-os modules
  (crc driver, mbedtls-base64 library) and the zephyr serial adapter module
  introduced recently.
- Added service of boot serial recovery mode to main.
- Adapted the input parser to using static buffers.

Default serial-boot-pin configuration was added for nrf52_pca10040
and nrf52840_pca10056 boards.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-12-06 16:11:10 -07:00
Andrzej Puzdrowski 614c4e54a0 Add cboorattr library for zephyr
The library is needed for support mcuboot serial recovery interface.
This library wraps the tinycbor decoder with a attribute based decoder
suitable for decoding a binary version of json.

Origin: apache Mynewt
License: Apache-2.0
URL: https://github.com/apache/mynewt-core/tree/master/encoding/cborattr
commit: bf4b3f6f4cf293fc5a71d7787d5b81555434b6f8
Maintained-by: External

f. cbor_read_mbuf_attrs was removed as it was Mynewt specific.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-12-06 16:11:10 -07:00
Andrzej Puzdrowski 217c4e06e1 Add tinycbor library for zephyr
The library is needed for support mcuboot serial recovery interface.
Tinycbor lib from mynewt is imported because it is already modified for
Add tinycbor library for zephyr

mcuboot serial recovery protocol.

Origin: apache Mynewt
License: Apache-2.0
URL: https://github.com/apache/mynewt-core/tree/master/encoding/tinycbor
commit: bf4b3f6f4cf293fc5a71d7787d5b81555434b6f8
Maintained-by: External

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-12-06 16:11:10 -07:00
Andrzej Puzdrowski f6f652e204 Add serial adapter module for support serial communication for zephyr
Serial adapter uses the zephyr UART driver in interrupt mode for
providing communication capabilities needed for the boot serial
recovery mode.
This module provide API similar to mynewt console module.

Serial adapter module can not be compiled along with
the zephyr uart console module so this case is checked.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-12-06 16:11:10 -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
David Brown e9771ef62f Fix ECDSA Zephyr configuration of mbed TLS
The Zephyr configuration was enabling the memory buffer allocator (but
not using it) without defining enough other features to allow it to
compile (undefined reference to `exit()`).

Disable the memory buffer allocator when just using the ASN.1 library,
and conditionalize the heap itself to avoid using the RAM for that.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-11-14 19:12:53 -07:00
David Brown 0bae965fd8 Zephyr: Use mbed TLS allocator
Instead of the overly-simplistic allocator in Zephyr, use the still
simplistic allocator in mbed TLS.

On K64f, this saves 848 bytes of text, 44 bytes of data, and 208 bytes
of bss.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-10-30 22:33:08 -06: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
Marti Bolivar dc4c42bf62 boot: zephyr: fix flash page layout hacks
Zephyr now has proper page layout APIs in its flash driver. Use these
to implement flash_area_get_sectors() and flash_area_to_sectors() when
they are available. Leave the existing implementation behind as a
"legacy" version, for flash drivers which lack page layout support.

This lets us obtain all the target support we need for nRF and STM32
targets entirely from the operating system.

There are two cases where OS-level support is still not enough:

- NXP K6x targets still need an SoC family header, because their flash
  driver does not yet support CONFIG_FLASH_PAGE_LAYOUT.

- The arduino_101 target needs partition and flash alignment
  definitions in its DTS, and a flash driver with page layout support
  as well, so its board-specific header must remain for now.

Fixing these is left to future work. Once that is done,
boot/zephyr/targets/ can be removed completely.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-10 13:57:02 -06:00
Marti Bolivar 3d9e3eb974 boot: zephyr: obtain FLASH_DRIVER_NAME, FLASH_ALIGN from OS
Zephyr now provides defines for FLASH_DRIVER_NAME and
FLASH_WRITE_BLOCK_SIZE (which is what we call FLASH_ALIGN) in
the SoC headers for most targets supported by mcuboot. Use that
information when it's available, falling back on MCUBOOT_TARGET_CONFIG
otherwise.

The soc_family_foo.h files remain for FLASH_AREA_IMAGE_SECTOR_SIZE.  A
subsequent patch can remove these files when the relevant SoC flash
driver provides a page layout.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-10 13:57:02 -06:00
Fabio Utzig 3efe6b6206 Add tinycrypt 0.2.8
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-10-10 14:34:17 -03: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
Marti Bolivar 97d997a733 Silence build warning on x86
Move the declaration of zephyr_flash_area_warn_on_open where all
targets can see it.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-04 20:36:34 -04:00
Marti Bolivar 07cd2d053d zephyr: move Kinetis target config to soc_family_kinetis.h
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-04 20:36:34 -04:00
Marti Bolivar 382f64a882 zephyr: move STM32 target config to soc_family_stm32.h
This cleanup commit requires a bit more target-specific knowledge
that's a bit harder to read than board-specific headers, but it's
still an improvement over what we have now.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-04 20:36:34 -04:00
Marti Bolivar 61038df37f zephyr: move nRF5 target config into soc_family_nrf5.h
All of the information we need is in DTS or is the same across all
boards in the SoC family. There's no need for board-specific headers
for these targets.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-04 20:36:34 -04:00
Marti Bolivar 2da23ebcbe hotfix for "zephyr: force mcuboot to fit in the boot partition"
Commit 4094813 ("zephyr: force mcuboot to fit in the boot partition")
added a DTC overlay file that breaks the build on arduino_101. That
board doesn't have its flash partitions defined in DTS.

Keep things working for now without allowing other issues to creep in
on ARM targets by excluding the chosen node on x86 targets only.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-04 20:36:34 -04: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
David Brown 09ef1c4b06 zephyr: Reconfigure to use local tinycrypt
Disable the Zephyr-provided Tinycrypt, and use our local copy.  This
avoids problems with changing version across different Zephyr releases.

Signed-off-by: David Brown <david.brown@linaro.org>
2017-09-08 14:18:22 -06:00
Carles Cufi ef35f0adad zephyr: nrf5x: add nRF51 and nRF52832 dev kits as targets
Add the 2 official Nordic Development Kit targets that are missing from
the list in mcuboot, but supported in Zephyr.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-08 11:33:47 -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 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
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
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 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
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
Fabio Utzig 5271b79151 Fix macro in comment
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-26 19:00:58 -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
Fabio Utzig 358c93553b Fix warning building with overwrite only
Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-26 00:33:46 -06:00
Fabio Utzig ba1fbe607b Fix running newtmgr when building for mcuboot
This enables mynewt to use mcuboot as a remote repository, which is only
required when using newtmgr to manage images. Since mcuboot has slightly
changed the trailer format, newtmgr built against the bundled mynewt
bootloader writes the magic and flags to the wrong location.

To build a mynewt app the wants to run with mcuboot as the bootloader
and requires newtmgr one needs to change the app's pkg.yml dependencies
as follows:

-    - boot/bootutil
+    - "@mcuboot/boot/bootutil"

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-21 15:58:44 -03:00
Fabio Utzig d0116731a9 Remove incubator references from mynewt dev email
Also use a single email for all packages.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2017-07-21 12:06:44 -06: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 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 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 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
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
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 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
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
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
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
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
Marti Bolivar 83a3cef34d zephyr: warn on boot if flash areas are still open
Add reference counting to the flash areas, and a zephyr-only routine
which warns when areas are still open when none should be. Call the
warn routine right before chain-loading.

This prints warnings due to code in loader.c. Future work will be
needed to clean this up.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar eb9408051e Use flash_device_base() when booting.
Use flash_device_base() in the boot code to compute a real address,
given the offset returned by boot_go().

Provide an implementation on mynewt that preserves existing
behavior. If mynewt needs to support devices with nonzero flash base
addresses, this can be migrated to the core OS.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar 428cdbf756 Rename br_flash_id to br_flash_dev_id.
Similarly, it's confusing whether br_flash_id is a flash device ID or
a flash area ID. Make this unambiguous.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar 88f48d9140 Rename br_image_addr to br_image_off.
The boot response returns a flash offset, not a flash address. This is
causing confusion and leading to crashes on some platforms which don't
have flash at address 0.

Rename the field to make it more clear what its purpose is; future
patches can start fixing up usages.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar c50926f3c1 bootutil: optionally use flash_area_get_sectors()
Add a typedef which lets us use flash_sector or flash_area to contain
the sectors within the boot_data global. When
MCUBOOT_USE_FLASH_AREA_GET_SECTORS is defined, this is struct
flash_sector.

Also add struct boot_loader_state accessors to handle this case, and
make the appropriate changes to where the sectors are allocated to use
the new typedef.

Finally, ensure MCUBOOT_USE_FLASH_AREA_GET_SECTORS is defined in the
Zephyr Makefile, since flash_area_get_sectors() is already provided
there.

This lets mcuboot users convert to the new flash API gradually.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar e10a7399d9 bootutil: add accessor for write_sz
This finishes making the struct contents opaque.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar 135b8f6009 bootutil: consolidate helpers for old flash API
Move helpers which are needed for using flash_area_to_sectors() to the
end of file. This is just to keep things clean when we add support for
flash_area_get_sectors().

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar 8489865cb1 bootutil: tweak state representation
Make num_sectors a size_t in struct boot_loader_state.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar c0b47916f5 bootutil: keep image areas open while bootloading
Keep both image areas and the scratch area open while we are
bootloading. This fixes up a hack and will make it easier to use
flash_area_get_sectors() later.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar ea08887858 bootutil: add image and area offset abstractions
Add abstractions for calculating the starting offset of a sector from
the beginning of its image, and the starting offset of an image slot
from the beginning of its flash device.

Using this tweaks a check in boot_swap_sectors(), but doesn't change
its outcome.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar cca28a9a56 bootutil: add abstraction for area initialization
Add an abstraction for initializing bootloader state for a particular
flash area.

For now, we preserve some existing hacky behavior related to the
scratch area. This will get cleaned up more later in the series.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:15 -04:00
Marti Bolivar d3269fd67c bootutil: add accessors for sector size and number
Taking the opportunity to move some signed integers over to unsigned
size_t as we go. (Depending on compiler settings, signed / unsigned
comparisons can generate warnings, so it's nice to use the signedness
we mean when possible).

Having boot_img_set_num_sectors() is just an intermediate step; this
gets cleaned up as we go forward.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:14 -04:00
Marti Bolivar e258715a2a bootutil: add flash device ID accessor
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:14 -04:00
Marti Bolivar f804f62e1f bootutil: add private image header accessor
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:14 -04:00
Marti Bolivar 9b1f8bb553 bootutil: move loader state definition to private header
This begins some preparatory work to using flash_area_get_sectors() in
loader.c. Subsequent commits will add and use additional accessors for
the contents of this struct.

Making the struct contents opaque will allow it to contain struct
flash_area or struct flash_sector values in its sectors field. This
will allow use of either flash_area_get_sectors() or the
now-deprecated flash_area_to_sectors().

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:14 -04:00
Marti Bolivar 1c0ddca7b1 zephyr: implement flash_area_get_sectors()
Support the new flash API which better maps to the underlying
hardware.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-15 13:24:14 -04:00
Marti Bolivar ed2eaf1498 zephyr: implement flash_device_base()
Implement new flash API which allows users to learn the physical base
addresses of flash devices.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-14 17:07:54 -04:00
Marti Bolivar a2e1b03d09 flash_map: declare flash_area_get_sectors()
The current flash_map.h API treats flash areas and flash sectors
synonymously.  This isn't accurate; a flash area comprises one or more
sectors.

To distinguish them, add a new struct flash_sector, and a new
flash_area_get_sectors() which initializes an array of struct
flash_sector instead of struct flash area.

That done, deprecate flash_area_to_sectors().

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-14 17:07:54 -04:00
Marti Bolivar d5bf57015c flash_map: declare flash_device_base()
This accessor returns the physical base address of a flash device,
given its ID. This will be used to support flash devices with nonzero
base addresses in mcuboot.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-14 17:07:54 -04:00
Marti Bolivar f0d08f23a1 flash_map: add docstrings
Add Doxygen docstrings to struct flash_area fields.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-06-14 17:07:54 -04:00
David Brown cdb968f70a rsa: Allow RSA key to be larger than we need
Allow the size of bignums in mbed TLS to be configured larger than
needed for RSA2048.  This will waste memory holding the large numbers,
but will still work.
2017-06-13 16:02:48 -04:00
David Brown f4e904d4be rsa: Add support for RSA-PSS
The PKCS#1 standards, which define RSA signatures, are currently at
version 2.2.  Starting in v2.1, the standard defines a new signature
method RSA-PSS, which has a stronger security proof than the signature
method used in earlier versions.  The standard recommends that RSA-PSS
be used in new designs, instead of the older algorithm.

This patch implements RSA-PSS verification for a specific set of
parameters:

    - RSA-2048
    - SHA256 for both the message digest and the internal hash
    - 32-byte salt
    - 2047 bit message

Although RSA-PSS supports other parameters, due to size constraints,
this verificatino code only supports these specific parameters, and
signatures with other parameters will be considered invalid.

To encourage the use of the more secure algorithm, the default build
configuration is RSA-PSS.  BOOTUTIL_RSA_PKCS1_15 needs to be defined in
order to support the older signature algorithm.
2017-06-13 16:02:48 -04:00
Fabio Utzig b119424aa8 Merge pull request #64 from utzig/fix-build-config-leftovers
Fix some leftovers after mynewt move (PR #52)
2017-06-13 13:16:04 -03:00
David Brown d6369707b9 Merge pull request #63 from utzig/fix-tinycrypt-dependency
Fix importing tinycrypt dependency on mynewt
2017-06-13 12:14:13 -04:00
David Brown 9ebd1f5a38 Merge pull request #51 from d3zd3z/pr/logging
sim: Allow Rust logging level to control C logging
2017-06-13 12:09:26 -04:00
Fabio Utzig 3488eef598 Fix some leftovers after mynewt move (PR #52)
- caps.c was now updated (missed this one!).
- *_OVERWRITE_ONLY flag was now also updated.
2017-06-12 10:25:43 -03:00
Fabio Utzig 32befd5cb4 Fix importing tinycrypt dependency on mynewt 2017-06-12 10:08:43 -03:00
Fabio Utzig eed80b65a0 Fix broken Mynewt BOOTUTIL_ -> MCUBOOT_ mapping
Fix mapping of syscfg.yml BOOTUTIL_* vars to C #defines, which was broken
on most .c files for lacking inclusion of mynewt "config.h"
2017-06-10 08:03:05 -03:00