Commit Graph

27 Commits

Author SHA1 Message Date
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
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
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 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
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
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
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 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
Fabio Utzig 19356bf45f Make mcuboot less mynewt style
Remove most of mynewt specific stuff to a separate port package. This
should make mcuboot less "mynewt'y" and slightly easier to port to.

- Mynewt specific stuff moved to boot/mynewt.
- Sample app moved from apps/boot to boot/mynewt.
- Use MYNEWT_VAL macro only on mynewt port.
- BOOTUTIL_* and MYNEWT_VAL() usage moved to MCUBOOT_ defines.
2017-06-02 10:55:27 -07:00
David Brown 1d9f185b62 Revert "Merge pull request #49 from mbolivar/flash-map-updates"
This reverts commit a52d7a21f0, reversing
changes made to d21abaaa35.

Premature merge.  Will bring this back in after #41 merges.
2017-05-23 10:32:22 -06:00
Marti Bolivar fa264cbeb7 flash_map: distinguish between areas and sectors
The current flash_map.h API treats flash areas and flash sectors
synonymously.  This isn't totally 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-05-08 10:24:31 -04:00
Marti Bolivar f6603066c0 flash_map: add flash_device_base()
This accessor returns the physical base address of a flash device,
given its ID.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-08 10:24:31 -04:00
Marti Bolivar 2bcf7c1cb4 flash_map.h: add docstrings
Add Doxygen docstrings to struct flash_area fields.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-05-08 10:24:31 -04:00
David Brown e629bf3745 Generalize SHA256 code to allow tinycrypt support
When building with ECDSA P-256 as the signature algorithm, we are still
bringing in SHA256 and some ASN.1 code from mbed TLS.  Fix part of this
by wrapping the hash functions with general routines (inline functions)
allowing to select between mbed TLS and Tinycrypt for the
implementation.

Update the Zephyr config files so that the Tinycrypt version is used
when building the ECDSA P-256 signing variant.
2017-04-27 16:31:12 -06:00
David Brown d7e350df7d zephyr: Fix up mbed TLS configuration
There are some problems with how mbed TLS is configured in Zephyr.
First, include the makefile stub in the Makefile that uses these
defines.  This makes sure the right definitions get made so that our
custom config gets used for all compiled files, rather than a mixed set.

Also, fix up the wrappers on the custom configs so that each is
different, making it easier to detect if multiple configs are being
included.

Lastly, only include the right header in the image validation.  The mbed
TLS includes don't seem to want to allow both RSA and ECDSA to be used
(due to the key size), and including the wrong header results in a
compilation error.
2017-04-27 16:31:04 -06:00
Marti Bolivar 29d3a77d3b zephyr: fix flash_area_to_sectors()
This fixes MCUB-39.

On Zephyr targets, flash_area_to_sectors() assumes that the flash
device's sector size is equal to the size of the scratch area.

That breaks swap and rollback when scratch size doesn't divide image
size, since the image flash areas will not be correctly configured.
This is a valid configuration supported by the rest of mcuboot.

The best way to fix this would be to get the flash layout from Zephyr,
but that's not possible yet.

Instead, provide a new FLASH_AREA_IMAGE_SECTOR_SIZE define from
target.h. This must be the sector size for these areas:

       - FLASH_AREA_IMAGE_0
       - FLASH_AREA_IMAGE_1
       - FLASH_AREA_IMAGE_SCRATCH

Other areas on the device may have sizes different than
FLASH_AREA_IMAGE_SECTOR_SIZE.

This won't work on platforms where those areas have nonuniform sector
sizes, but we'll cross that bridge when we come to it. (At that point,
an upstream Zephyr change to the flash API really seems needed.)

Revert to the old/buggy behavior when FLASH_AREA_IMAGE_SECTOR_SIZE
isn't provided, but emit a warning. Additionally, touch up the logging
and error handling while we're here.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-03-21 15:48:15 -04:00
Marti Bolivar 51181cf34f zephyr: add "real" target header
MCUBOOT_TARGET_CONFIG is included in several places now,
not just boot/zephyr/main.c. This seems likely to continue.

Let's avoid trouble and make it a real header file, target.h, that
pulls in MCUBOOT_TARGET_CONFIG. That done, include target.h instead
everywhere MCUBOOT_TARGET_CONFIG is included.

This will make it easier to provide values at an SoC/family level
later.  We can expect different Zephyr boards to have the same SoC and
thus likely the same mcuboot flash layout, so this will avoid
duplication.

All supported boards are compile-tested.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-03-21 15:39:46 -04:00
Marti Bolivar 2649aafa55 flash_map: delete obsolete flash_map* declarations
The following declarations are undefined and unused in both simulator
and zephyr builds (96b_nitrogen, 96b_carbon, frdm_k64f):

- flash_map
- flash-map_entries
- flash_map_init()

Delete them.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-02-10 16:44:41 -05:00
David Brown 3869e76090 zephyr: Support RSA, and ECDSA P-256 signing
Make it clear in the top-level Makefile how to configure mcuboot for
Zephyr for a particular signing algorithm.  Currently supported, are the
RSA signatures, and ECDSA with the P-256 curve.  These configuration
lines will select the code built in the bootloader, as well as which
public key gets included with the image.

This also adds a demo public key for the P-256 signatures.
2017-02-02 08:39:18 -07:00
David Brown e7c66635cf zephyr: Include mbedtls config file
Rather than commit our specific mbedtls config file into the Zephyr
tree, include it here, and add a path early in the make process so that
it will get picked up when building the library.
2017-01-10 09:51:39 -07:00
David Brown 299245d7de zephyr: Move code under 'boot' directory
The Zephyr build systems makes some assumptions about the directory
layout, and encounters problems if the necessary path contains "../..".
To help this, place the zephyr directory next to the bootutil directory
so that the Makefile can just refer to "../bootutil".  This keeps all of
the build artifacts under the proper top-level directory.
2017-01-10 09:49:47 -07:00