Commit Graph

1912 Commits

Author SHA1 Message Date
Dominik Kilian 421730e846 boot: Update Nordic's license identifier tag
Nordic had changed its license identifier to new
more accurate id: LicenseRef-Nordic-5-Clause.
Old identifiers should be updated.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
2022-12-19 13:04:56 +01:00
Tamas Ban 04efc2e861 docs: fix FIH example command in design.md
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Change-Id: I3ce8177ad6ae8196b7deb4176c4441f41bbc475a
2022-12-16 13:06:11 +01:00
Tamas Ban 166075ef4b ci: fih: update TF-M version to 1.7.0 and adjust test suite
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Change-Id: I1a810bac6e0409ff06af80c8151b8d37a97effdc
2022-12-16 13:06:11 +01:00
Jamie McCrae ad1fb3dde2 boot_serial: Allow using a buffer larger than 512 bytes
There are 3 levels of buffers and only the first one seems to be
configurable, this fixes that issue.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-04 13:20:46 +01:00
Jamie McCrae 0b6d3439bb boot_serial: Fix rc not being returned as a signed value
Fixes an issue whereby rc is a signed variable but is returned as
an unsigned variable in the zcbor functions.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-02 22:52:48 +01:00
Mark Horvath 7ebf0e8277 bootutil: Fix bootutil_find_key return value
The return value of bootutil_find_key is used as the key_id in the
bootutil_img_validate function, and negative key_id value used in case
of errors. If MCUBOOT_HW_KEY is set, than the key hash is read by
boot_retrieve_public_key_hash function, but the exceptation is only to
return nonzero on failure, so its error code should not be propagated
up to the caller. Instead, bootutil_find_key should return -1 in case
of a platform error.

Change-Id: I8e2bd12a5cf53787e10ae45c2ab556e8a856692d
Signed-off-by: Mark Horvath <mark.horvath@arm.com>
2022-11-25 17:54:03 +01:00
Torsten Rasmussen 82ee5d0bb9 zephyr: fix handling of devicetree overlays in mcuboot
The current specific setting of devicetree overlay files using `set()`
has a couple of built-in flaws.

It keeps readding the overlay file on each subsequent CMake invocation.
The build command (make/ninja), will automatically invoke CMake if there
are any changes to files used as configure time dependencies.

This can easily be seen by manually re-invoking CMake:
```
 # First invocation
$ cmake -DBOARD=nrf52840dk_nrf52840  -DDTC_OVERLAY_FILE=custom.dts ..
Loading Zephyr default modules (Zephyr workspace).
-- Application: /projects/github/ncs/bootloader/mcuboot/boot/zephyr
...
-- Found devicetree overlay: custom.dts
-- Found devicetree overlay: bootloader/mcuboot/boot/zephyr/dts.overlay

 # Second invocation
$ cmake -DBOARD=nrf52840dk_nrf52840  -DDTC_OVERLAY_FILE=custom.dts ..
Loading Zephyr default modules (Zephyr workspace).
-- Application: /projects/github/ncs/bootloader/mcuboot/boot/zephyr
...
-- Found devicetree overlay: custom.dts
-- Found devicetree overlay: mcuboot/boot/zephyr/dts.overlay
-- Found devicetree overlay: mcuboot/boot/zephyr/dts.overlay
```

Zephyr has built-in support for application specific overlay config
which gets automatically applied when the overlay file is named:
`app.overlay`.

Therefore rename `dts.overlay` to `app.overlay`.
Ref: https://docs.zephyrproject.org/3.2.0/build/dts/howtos.html \
  #set-devicetree-overlays

This change further allows users of mcuboot to place their mcuboot
configuration out-of-tree of the sample by using the
`APPLICATION_CONFIG_DIR` setting.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-11-24 08:55:20 +01:00
Fabio Utzig 08a716dc4e imgtool: fix --vector-to-sign usage
`--vector-to-sign` only exports the image payload, or digest, to be
signed externally; it doesn't require any keys to be provided. This
commit moves the code outside a key required block, after the payload
and digest were already calculated from "image + headers + protected
TLVs".

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-11-21 18:50:25 -03:00
Dominik Ermel e009e19bd9 zephyr: Explicitly select CONFIG_CRC for CONFIG_MCUBOOT_SERIAL
The serial recovery depends on CRC from Zephyr, which it should
have been selecting explicitly.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-21 16:25:34 +01:00
Antonio de Angelis 7ba01c0de7 imgtool: Fix PEP8 warnings on modules in this PR
Fix the remaining PEP8 warnings that appear on image.py, ecdsa.py
or main.py for imgtool.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2022-11-16 14:02:19 -03:00
Antonio de Angelis c6e7e9be7a imgtool: Improve ECDSA key generation
This patch improves the existing ECDSA key generation feature
in the imgtool by:
 - Fix a bug in the 'minimal' representation of PKCS#8 keys where
   the resulting ASN.1 DER encoding is not compliant
 - Add the option to export ECDSA private keys in SEC1 format by
   providing a command line option -f or --format that can be
   'openssl' (for SEC1 format) or 'pkcs8'. This format ends up in
   key encodings which are generally smaller than PKCS#8.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2022-11-16 14:02:19 -03:00
Antonio de Angelis 284b8fe3dd imgtool: Add filename to some common prints
Common prints such as the one that happens when an image is signed
are clearer if the source of print is added (i.e. filename), especially
for those build integration flows where imgtool is invoked as part of
a set of operations.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2022-11-16 14:02:19 -03:00
Kamil Piszczek a1de4e55ef boot: zephyr: remove thingy53_nrf5340_cpuapp.conf board configuration
Removed the board configuration for Thingy:53 Application Core as it
contains references to the Kconfig modules that are not available in
the upstream Zephyr. The current configuration is set up to work
in the nRF Connect SDK environment and should be moved there.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2022-11-15 10:41:36 +01:00
Xiang Xiao 36bac4f6a5 Fix error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-14 11:10:08 -03:00
Thomas Stranger aa217e2313 boot: zephyr: prefer swap move if scratch_partition not enabled
With the exception of nrf targets BOOT_SWAP_USING_SCRATCH mode was
still the default algorithm.

Changing the preferred mode in cases where no scratch_partition is
defined will allow successfully building mcuboot for such boards w/o
the need for any board specific overlays.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-11-14 14:38:41 +01:00
Almir Okato fc1eabf6bb boot_serial: espressif: ESP32-S3 serial recovery mode interface
Add the serial adapter for ESP32-S3 for boot recovery and MCUMGR
communication.

Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-11-11 11:22:00 -03:00
Almir Okato 4099583c12 boot_serial: espressif: ESP32-S2 serial recovery mode interface
Add the serial adapter for ESP32-S2 for boot recovery and MCUMGR
communication.

Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-11-11 11:22:00 -03:00
Almir Okato 7d3622ffbb boot_serial: espressif: change CRC call for esp chips general compatibility
Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-11-11 11:22:00 -03:00
Andrés Sánchez Pascual 6ea3e9bd17 boot: nuttx: Support application specific
wdg initialization.

Signed-off-by: Andrés Sánchez Pascual <tito97_sp@hotmail.com>
2022-11-10 09:34:43 -03:00
Andrés Sánchez Pascual 246aca368e Fix sign-comparison issue
Signed-off-by: Andrés Sánchez Pascual <tito97_sp@hotmail.com>
2022-11-07 19:26:24 -03:00
Gregory Shue 900da13865 Add west.yml to make manifest-module.
Extending mcuboot to be a Zephyr manifest-module enables
mcuboot integration consistent with Zephyr's example-application.

Verified by:

```
west init https://github.com/$my_account/mcuboot \
     --mr $my_branch ~/$my_wksp && \
cd ~/$my_wksp && \
west update && \
source zephyr/zephyr_env.sh && \
west build -p always -b nrf52840dk_nrf52840 mcuboot/boot/zephyr
```

Fixes #1496

Signed-off-by: Gregory Shue <gregory.shue@legrand.com>
2022-10-27 10:19:34 -06:00
Gregory Shue e82b370ca5 Explicitly set module name in `zephyr/module.yml`
Follow Zephyr v3.2.0 new recommendation to explicitly set module
names to enable usage of ZEPHYR_<module-name-upper>_MODULE_DIR by
other modules.

Verification:

1. (Pass) west build -p always -b nrf52840dk_nrf52840 bootloader/mcuboot/boot/zephyr/
2. (Pass) ./zephyr/scripts/twister --testsuite-root zephyr/tests/subsys/dfu/
3. (Pass) ./zephyr/scripts/twister --testsuite-root zephyr/samples/subsys/mgmt/mcumgr/smp_svr/
4. (Pass) ./zephyr/scripts/twister --testsuite-root bootloader/mcuboot/boot/zephyr/

Fixes #1491

Signed-off-by: Gregory Shue <gregory.shue@legrand.com>
2022-10-18 13:08:38 -06:00
Andrzej Puzdrowski a6a5c08f08 doc/redame-zephyr:
Public key is handled by the build-system
since a while.

This patch reflect this in the documentation.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Co-authored-by: Francesco Domenico Servidio <francesco.servidio@nordicsemi.no>
2022-10-17 16:58:45 +02:00
Andrzej Puzdrowski 7500156915 doc/readme-zephyr:
Zephyr-port has switched to use DT node labels instead of
label properties for partition assignment.

Also usage of west is recommended way to work with the project.

Documentation was actualized to reflect these principles.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Co-authored-by: Francesco Domenico Servidio <francesco.servidio@nordicsemi.no>
2022-10-17 16:58:45 +02:00
Gerard Marull-Paretas 4eca54f417 boot: serial: add missing Zephyr kernel.h include
boot_serial.c is using Zephyr Kernel APIs without including kernel.h.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-06 13:58:42 +02:00
honglin leng 37e4223413 sample:zephyr: decrease some hard code
Signed-off-by: honglin leng <a909204013@gmail.com>
2022-10-04 16:27:18 -06:00
Daniel DeGrasse e45744449b boot: zephyr: enable ram load for ARM
Enable ram loading for ARM, with correct handling of vector table when
code has moved to RAM.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-10-04 16:26:03 -06:00
Andrzej Puzdrowski 9324d2b896 sim: Added test for over-sized image update
Added test which checks whether too big update image
will be rejected.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 26d19d330a sim: Added test for over-sized image bootstrap
Added test for check whether the bootstrap will fail for too big
image.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 5b90dc891e sim: image trailer size differentiation
Differentiated image trailer size for swap-using-scratch with
max-align-32 feature and without it.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 5310d554dd sim: corrected maximal image size calculation
Corrected the maximal image size calculation for
the swap using scratch mode. Previously the vale which
is appropriate for the swap using move mode was used.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Andrzej Puzdrowski 334b6a60ab boot: add precise check of the image size
It is possible that image in the slot is so big
that MCUboot swap metadata will interfere with
its content during the swap operation.

This patch introduces additional check to the image
validation procedure.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-10-04 23:02:36 +02:00
Yonatan Schachter b22eb6a30d zephyr: Explicitly include cmsis.h
main.c uses CMSIS functions such as __set_MSP, which require
cmsis.h to be included. Up until now, that file was included
indirectly through other ARM headers. This patch explicitly
includes cmsis.h, for platforms on which those indirect includes
do not work.

Signed-off-by: Yonatan Schachter <yonatan.schachter@gmail.com>
Signed-off-by: David Brown <david.brown@linaro.org>
2022-10-04 12:42:36 -06:00
Jerzy Kasenberg b8801fc0ac zephyr/Kconfig: Add downgrade prevention to swaps
Downgrade prevention for swap upgrades that was added to
mcuboot is now configurable in zephyr.

It may be using software version number from image in slot 0,
or security counter from the image in slot 0 (for limited downgrade
availability).

Hardware base security counter check remains unchanged.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
2022-10-04 08:52:57 -06:00
Jerzy Kasenberg e3f895d7ef Add downgrade prevention for swaps
Currently, downgrade prevention was limited to overwrite only
builds (version check) or devices with hardware storage for
security counter.

This extends downgrade prevention to be used when swap update
is selected.
Unlike MCUBOOT_HW_ROLLBACK_PROT option it does not require user
code to provide external way to store security counter.
Security counter from slot 1 image is used for comparison.
With security counter usage it is possible to have limited
software rollback if security counter was not incremented.

It is possible to use image version where strict rule for
image version comparison prevents any downgrades.

Downgrade prevention is also added to mynewt configuration.

If image in slot 1 is marked as pending and downgrade prevention
is in place, image will be deleted to avoid check on next boot.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
2022-10-04 08:52:57 -06:00
Fabio Utzig 4e2cdfe82f imgtool: change getpub exporting format parameter
Update a previous PR were PEM exporting was added to the `--lang`
parameter, even though PEM is not a source code language per se.

This PR adds `--encoding/-e` to `getpub` command, for exporting
in formats other than a language source code. `--lang` is left with
a deprecation message, so it could be removed in a future version.
The default behavior of exporting source code in C was preserved.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-09-29 19:31:02 -03:00
Almir Okato 09cca3815a boot_serial: espressif: ESP32-C3 serial recovery mode
Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-09-29 11:37:13 -03:00
Almir Okato 707a69d40c boot_serial: espressif: enable erase progressively option on serial recovery
Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-09-29 11:37:13 -03:00
Almir Okato 0dcdbab886 boot_serial: espressif: split serial adapter implementation for each chip
This commit also fixes array access on serial console read.

Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-09-29 11:37:13 -03:00
Almir Okato 90be6e6001 boot_serial: adding missing errno.h header
Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-09-29 11:37:13 -03:00
Andrzej Puzdrowski b25ba4bfa5 zephyr/Kconfig: fixed BOOT_WATCHDOG_FEED default value
This property should be enabled by default only when watchdog
driver is available.
This fixed build with pristine configuration on targets
with CONFIG_WATCHDOG=n.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-09-28 15:45:27 -06:00
David Brown 08a30a4158 zephyr: Add a bool Kconfig option for swap move
The Kconfig system used by Zephyr does not allow the defaults for choice
options to be overridden.  To compensate for this, create a new boolean
config option that will determine what the default is for the boot mode.

This allows the kconfig override file for various Zephyr boards to
change the default to swap move.

Signed-off-by: David Brown <david.brown@linaro.org>
2022-09-23 17:19:26 +02:00
Fabio Utzig 6f286779a6 imgtool: add option to export public PEM
Update `getpub` with new `lang` option, "pem", which allows exporting a
public key as a PEM file. This can later be distributed to be used for
encrypting an image, and gets away with having to use openssl for this
step.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-09-22 11:34:43 -06:00
Sigvart Hovland 3fd4cd4fac bootutil: loader: Add post copy hook to swap function
Currently the post copy hook is only called from the `copy_region`
function. However when another update method than `BOOT_UPGRADE_ONLY` is
selected this function is not called. This adds post copy hook to the
end of `boot_swap_image` when we know the swap is complete.

Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
2022-09-19 15:58:53 +02:00
Andrzej Puzdrowski 6e116e4340 zephyr/sample.yaml Limit allowed build platforms
Building sample.bootloader.mcuboot for many platforms
is not possible (for instance a qemu). The limit is need
as otherwise zephyr-rtos/zephyr CI is failing on any push to
main branch or nightly CI run.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-09-19 09:48:56 +02:00
Marek Pieta f1fd510563 boot: zephyr: Remove legacy serial recovery GPIO configuration
Change removes the legacy configuration. The legacy configuration
became problematic, because GPIO DTS nodes no longer support labels
that were used to identify nodes in MCUboot. Therefore we need to
use GPIO DTS node name with the legacy approach.

The GPIO should be configured by board's DTS, which is simpler.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2022-09-13 16:33:43 +02:00
Marek Pieta 2fa1190ff3 boot: zephyr: Add default values of boot detect pins
Change introduces default values of CONFIG_BOOT_SERIAL_DETECT_PIN
and CONFIG_BOOT_USB_DFU_DETECT_PIN. This is needed to prevent build
issues caused by uninitialized Kconfig.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2022-09-13 16:33:43 +02:00
Fabio Utzig 73d69e9b56 boot: zephyr: fix watchdog device typos
Fix typos for IWDG and watchdog0 alias feeding paths.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-09-12 11:13:54 +02:00
Fabio Utzig 4b90dfcf71 zephyr: ci: enable testing more watchdog paths
Enable tests to be run on frdm_k64f and disco_l475_iot1. The l475 uses
the STM32 IWDG by default, and the k64f can be used for the generic
watchdog path. Both boards also received a config to enable the
watchdog.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-09-12 11:13:54 +02:00
Georgij Cernysiov 4030aac594 boot: zephyr: fix xtensa define condition
Adds missing bracket to the xtensa node
exists condition.

Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
2022-09-09 11:16:15 +02:00