Commit Graph

335 Commits

Author SHA1 Message Date
Fabio Utzig 38f5ffea35 Add key unwrap functionality using tinycrypt
This implements AES key unwrapping following RFC-3394 section 2.2.2
using tinycrypt for AES-128 decryption. It is enabled when ECDSA was
chosen as the signature algorithm.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-01-03 11:22:05 -02:00
Fabio Utzig 3b091f6afd Enable ASN1 parsing for KW
Signed-off-by: Fabio Utzig <utzig@apache.org>
2019-01-03 11:22:05 -02:00
Fabio Utzig d0533ed117 Add Zephyr config for boostrap feature
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-27 10:58:50 -02:00
Fabio Utzig 251ef1d98a Add rsa+kw testing support to simulator
Allows simulating images signed with RSA-2048 and encrypted with
AES-128-KW.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-27 10:58:50 -02:00
Fabio Utzig 338a19f70d Add boostrapping from slot1 support
This adds a new option that allows copying slot0, from the contents
of slot1, if slot0 is found out to be erased and not validated, and
the contents of slot1 are validated.

This mechanism basically enables a device to "bootstrap" from the
contents of an external flash that has a valid image, given that the
only flashed thing in the internal flash is the bootloader.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-27 10:58:50 -02:00
Rajavardhan Gundi 07ba28f058 MPU_ALLOW_FLASH_WRITE is defined only for ARM platforms.
Remove MPU_ALLOW_FLASH_WRITE from prj.conf and put it in
boot/zephyr/Kconfig enabling it only for every ARM_MPU
equipped device.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-27 08:13:41 -02:00
Rajavardhan Gundi 40c28e3676 Add support for intel_s1000 SoC which is based on Xtensa arch
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-27 08:13:41 -02:00
Rajavardhan Gundi 3b8b58dcb5 Add DT_SPI_NOR_DRV_NAME check towards sanitycheck in target.h
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-27 08:13:41 -02:00
Rajavardhan Gundi c3353b240e Call device binding for DT_FLASH_DEV_NAME only if it is defined
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-27 08:13:41 -02:00
Rajavardhan Gundi 1b8d7fb355 Use BUILD_ASSERT_MSG instead of _Static_assert in Zephyr
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-27 08:13:41 -02:00
Marko Kiiskila e5aeee4ad1 boot_serial; check CRC for RX only if all data has arrived.
Signed-off-by: Marko Kiiskila <marko@apache.org>
2018-12-24 08:47:25 -02:00
Marko Kiiskila 8e7b7ac9e0 boot_uart: mynewt; option for faster speed with serial.
Make RX buffer size configurable for UART. Allow incoming
interrupts while copying data out of that buffer.

Signed-off-by: Marko Kiiskila <marko@apache.org>
2018-12-24 08:47:25 -02:00
Timo Kröger e280e1166e Remove unused hal includes from bootutil
Signed-off-by: Timo Kröger <timokroeger93@gmail.com>
2018-12-21 06:47:40 -02:00
Fabio Utzig 2bd980a50d Add support for slots with different sector sizes
This adds bootutil support for slots on different flash devices
the happen to have different sector sizes.

It consists basically in relaxing the `boot_slots_compatible` to
allow swaps as long as the sectors that are required to fit both
images are able to fit inside scratch and both slot's sectors have
sizes that are multiple of each other.

This is now tested on the simulator and was tested in a Nordic's
pca10056 using slot0 in internal flash, and slot1 in the external
QSPI flash, configured with 4K, 8K and 16K sized sectors (the HW
is 4KB but Mynewt allows emulating multiples of that!)

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-18 15:16:11 -02:00
Fabio Utzig 4541b53a3a Increase Zephyr mempool size for encrypted images
For Zephyr the default mbedTLS mempool size for RSA-2048 signing was not
enough to allow for the calculations done by RSA-2048-OAEP (encrypted
images), so when encrypted image support is enabled, increase it to a
value that is known to work.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-17 14:41:02 -02:00
Fabio Utzig 2fc80df49f Fix handling of encrypted images
Encrypted images were known to be failing when the header size was larger
than 256 bytes because of incorrect handling of blocks sent to decryption
and hashing routines. An assert was previously added to check the header
and read block sizes matched to avoid incurring into the know error, but
it was incorrectly enabled also for non-encrypted images.

Now the handling of the header, which is not encrypted, is correctly
separated from the handling of the remaining image, when encryption is
used, to avoid ever sending header data into the decryption routines.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-17 14:41:02 -02:00
Fabio Utzig e641ea5ee5 Fix overwrite only encrypted to not use local var
Use existing global var instead of using locally declared variable,
reducing RAM usage.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-04 14:21:52 -02:00
Fabio Utzig 1c7d959eeb Fix rebase issue
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-12-04 14:21:52 -02:00
Andrzej Puzdrowski f50054d998 fix zephyr target: corrupted build after zephyr PR #11180
zephyrproject-rtos/zephyr#11180: Zephyr target was corrupted as
recently zephyr's device tree started adding DT_ prefix in
generated labels.

This path aligns flash name macro used.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-11-14 14:56:35 +01:00
Emanuele Di Santo 865777ddc9 boot: zephyr: add MCUBOOT config
Add a hidden MCUBOOT config entry to mark a project as MCUBOOT.
It is useful when other parts of the system need to be aware
that they are, in fact, the bootloader.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
2018-11-09 14:08:56 +01:00
Yiping Peng 3393992943 Fixed an issue that supported later versions of mbedtls than mbedtls-2.6.1
Signed-off-by: Yiping Peng <836885645@qq.com>
Signed-off-by: Yiping Peng <yibingp@internal.synopsys.com>
2018-11-09 08:12:29 -03:00
Emanuele Di Santo 4d20525195 boot: zephyr: cleanup nrf52840_pca10059 configuration
Cleanup board configuration.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
2018-11-03 12:07:51 +01:00
Emanuele Di Santo fcfff58417 boot: zephyr: add missing sys_clock_disable declaration
Add missing declaration of sys_clock_disable() to fix compiler warning.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
2018-11-03 12:07:51 +01:00
Emanuele Di Santo 4a60ee7c76 zephyr: add support for pca10059
This commit adds a project configuration for the upcoming
nrf52840_pca10059 board.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-10-30 18:17:23 +01:00
Emanuele Di Santo c4bf78009c zephyr: selectable serial device for recovery
This commit adds a choice for the device to use for serial recovery.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>

fixup
2018-10-30 18:17:23 +01:00
Fabio Utzig 0d16482be8 Add mbedtls config with nist_kw enabled
This adds a mbedtls config that will enable the simulator to run tests
for the kw based encrypted images.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-10-12 13:36:13 -03:00
Fabio Utzig 5fe874c34e Add Zephyr support for encrypted images
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-10-12 13:36:13 -03:00
Fabio Utzig 0170f26de1 Add Mynewt config for encrypted images
Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-10-12 13:36:13 -03:00
Fabio Utzig ba829049ea Add bootutil support for encrypted images
This allows storing encrypted images in slot1, that are automatically
decrypted when copying to slot0 and re-encrypted when copying from slot0
to slot1.

The encryption works by applying AES-CTR-128 on the image blocks
(excluding the header and TLVs) using a random key. This random key
is itself encrypted using either RSA-OAEP-2048 or AES-KW-128 (AES keywrap
as defined by RFC3394), and appended to the image as newly defined TLVs.

AES-CTR-128 was chosen primarily for having stream cipher proporties,
which basically means that any block being encrypted/decrypted does not
depend on any other previous blocks results.

The TLV adds about 256 bytes to the image in RSA-OAEP-2048 mode, and 24
bytes in AES-KW-128 mode. Resulting sizes for a Mynewt generated mcuboot
(frdm-k64f):

- swap mode and no signing: 12KB
- adding encryption with RSA-OAEP-2048: 28KB
- adding encryption with AES-KW-128: 20KB

Some extra comments:

- AES-KW-128 requires a fairly new mbedtls with nist_kw support.
- An alternative methods which could be added later are ECIES.
- Key-wrapping seems easy enough to implement using just standard
  AES-ECB mode that it should be straight-forward to also add support to
  tinycrypt.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-10-12 13:36:13 -03:00
Andrzej Puzdrowski 5f81b127e1 zephyr: fix flash_area_read_is_empty
Implementation of flash_area_read_is_empty introduced recently
uses deprecated hal_flash_read API which caused build failure.

This patch uses zephyr's native flash_area_read() API which
solves the bug.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-10-09 12:45:09 +02:00
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 cea90f970f Add flash_area_read_is_empty to Zephyr port
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 42ad446fb0 Add `flash_area_erased_val` "mock" for Zephyr
For Zephyr assume flash is always erased to 0xff. This allows backward
compatibility of the new flash erased to 0 support.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-09-17 12:42:49 -03: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
Marti Bolivar 5de83b1e47 zephyr: config-rsa.h: remove copypasta
MCUboot doesn't need mbedTLS's entropy code (you don't need random
numbers to check a digital signature), but it enables it. This causes
really scary warnings when building entropy.c, since the test entropy
source is enabled:

    [113/197] Building C object zephyr/ext/lib/crypto/mbedtls/CMakeFiles/ext__lib__crypto__mbedtls.dir/library/entropy.c.obj
    /home/mbolivar/src/zephyr/ext/lib/crypto/mbedtls/library/entropy.c:31:2: warning: #warning "**** WARNING!  MBEDTLS_TEST_NULL_ENTROPY defined! " [-Wcpp]
     #warning "**** WARNING!  MBEDTLS_TEST_NULL_ENTROPY defined! "
      ^~~~~~~
    /home/mbolivar/src/zephyr/ext/lib/crypto/mbedtls/library/entropy.c:32:2: warning: #warning "**** THIS BUILD HAS NO DEFINED ENTROPY SOURCES " [-Wcpp]
     #warning "**** THIS BUILD HAS NO DEFINED ENTROPY SOURCES "
      ^~~~~~~
    /home/mbolivar/src/zephyr/ext/lib/crypto/mbedtls/library/entropy.c:33:2: warning: #warning "**** THIS BUILD IS *NOT* SUITABLE FOR PRODUCTION USE " [-Wcpp]
     #warning "**** THIS BUILD IS *NOT* SUITABLE FOR PRODUCTION USE "
      ^~~~~~~

Delete the bits of the mbedTLS configuration that compile this
file (along with some testing code we don't care about either) to
clean up the warning. This looks like copy/paste code from the initial
mbedTLS config import into MCUboot.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-05 20:30:01 -03:00
Marti Bolivar 0e259097fb zephyr: prj.conf: disable CONFIG_BT_CTLR too
Various Zephyr boards (I'm looking at you, every-single-nRF-board)
set CONFIG_BT_CTLR=y as well as CONFIG_BT. Make sure it's disabled for
MCUboot's default prj.conf, where it's not needed and has been causing
very verbose Kconfiglib warnings:

    warning: BT_CTLR (defined at subsys/bluetooth/controller/Kconfig:10) was assigned the value 'y' but
    got the value 'n'. You can check symbol information (including dependencies) in the 'menuconfig'
    interface (see the Application Development Primer section of the manual), or in the Kconfig
    reference at http://docs.zephyrproject.org/reference/kconfig/CONFIG_BT_CTLR.html (which is updated
    regularly from the master branch). See the 'Setting configuration values' section of the Board
    Porting Guide as well.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-05 20:30:01 -03:00
Andrzej Puzdrowski c2e30cf2c3 serial recovery: always erase image status
It is possible that while flash was erased progressively
the flash image status page was not erased.
This patch check this case and performs additional eras
if it was required.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-08-04 09:13:23 -03:00
Emanuele Di Santo 205c8c6980 zephyr: erase flash pages progressively
This commit adds the option to erase flash pages while receiving
the firmware, opposed to bulk-erasing the whole image area at
the beginning of the DFU process. This is required on some
hardware that has long erase times, to prevent a long wait
and possibly a timeout during DFU.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-08-04 09:13:23 -03:00
Emanuele Di Santo d1fd3f92b7 zephyr: fix serial ISR in serial_adapter
The UART device ISR in serial_adapter expected the device
to fire an interrupt for each byte that was received.
Although this might have worked for some devices it wouldn't
work for USB. This commit fixed the issue by modifying the ISR
according to the uart.h documentation.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
2018-08-04 09:13:23 -03:00
Fabio Utzig 0f29c48e8d Initialize watchdog when running on Mynewt
On Mynewt some flash drivers on very slow devices tickle the watchdog to
avoid possible hangs; those were also trying to tickle the watchdog in
mcuboot when performing an upgrade or serial boot, without initializing
the watchdog, causing an invalid memory write and reset issue.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-07-30 08:33:00 -03:00
Carles Cufi 6400f0bf97 zephyr: serial_adapter: Cleanup queue variables
Remove the simple pointers and use the "&" operator throughout to
simplify the understanding of the code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-07-18 07:03:45 -03:00
Carles Cufi b124e39f79 zephyr: serial_adapter: Fix allocation of buffers
In order to avoid overwriting an existing allocated buffer that has not
yet been processed by the main loop, switch to a new command buffer
whenever we have received a complete one.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-07-18 07:03:45 -03:00
Szymon Janc c48e7f917e boot_serial: Fix build on Zephyr with ECDSA enabled
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-07-03 17:46:33 +02:00
Evan Gates 4632d8de5f include soc.h in main.c
While building with Zephyr 1.12 for the nucleo_f091rc I got undefined
reference to __set_MSP() during linking. Including soc.h fixes the
problem. Thanks carlesc.

Signed-off-by: Evan Gates <evan@gnarbox.com>
2018-06-29 11:18:18 -03:00
Fabio Utzig 3b69d6f845 Deinit timer after serial load is finished
This fixes an issue where the bootloader is activating a timer that is
later not used by the installed target image causing a non handled interrupt
fault.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2018-06-26 09:12:43 -03:00
Andrzej Puzdrowski 3011714194 zephyr: serial_adapter: preserve buffer list against lock
It was possible that free_queue locks on the self referencing
node.
This patch introduce check for this issue

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-20 16:08:58 +02:00
Andrzej Puzdrowski ec1e4d1bef boot_serial: preserve against buffer overflow for zephyr
For zephyr it was possible to make buffer overflow while decoding
incoming base64 sting. This patch correct the available
buffer size transferred to base64 decoding function, which mitigate the
issue.

Clean up boot_serial_start function from unwanted
execution constant pointers.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-20 16:08:58 +02:00