Commit Graph

1065 Commits

Author SHA1 Message Date
Antonio de Angelis cf36d670c9 bootutil/crypto: Add license disclaimer to ecdsa_p256.h
The ecdsa abstraction layer header does not have a license header.
Add it in preparation for the merge with ecdsa.h

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: Ibb906c7f6bb3b50387e4816e1a95b31d3c8b515f
2023-04-26 13:57:53 +02:00
Antonio de Angelis 557451d28d bootutil/crypto: Add a generic signature validation module for ECDSA
Add a dedicated signature validation module for generic ECDSA signatures,
and a corresponding cryptographic abstraction backend based on PSA Crypto
APIs. This signature verification backend is enabled by defining the
option MCUBOOT_SIGN_ECDSA

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I47da70629da0a5681ec7c4dcceed875a997b071b
2023-04-26 13:57:53 +02:00
Roland Mikhel 63d2346da4 bootutil: Remove curve specific ECDSA TLVs
Remove those TLVs that are tied to a specific curve and update
the image validation logic to look for the new generic TLV

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I924f2742424bc255fbed1b0941648baa88f60147
2023-04-26 13:27:44 +02:00
Roland Mikhel b08e77e0f3 bootutil: Create new generic ECDSA TLV
Create a new generic ECDSA TLV type that can be used
to store any signatures irrespective of the curve type.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I2aeb885251fd25e23f5430328b8cc64b8cc8d7be
2023-04-26 13:27:44 +02:00
Jeppe Odgaard 1558e7ab0a boot: zephyr: remove stm32 watchdog defines
The stm32 defines is somewhat redundant due to the generic watchdog
defines which uses the watchdog0 alias. Therefore they are removed in
this commit.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2023-04-26 13:15:51 +02:00
Jeppe Odgaard 4420bb663f boot: zephyr: setup watchdog
The Zephyr watchdog API defines a setup function. This function needs to
be executed before the watchdog is functional in some cases. This commit
adds MCUBOOT_WATCHDOG_SETUP when using the generic watchdog0 alias
otherwise it is an empty define.

Fixes https://github.com/mcu-tools/mcuboot/issues/1659

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2023-04-26 13:15:51 +02:00
Jamie McCrae 393af79ef1 boot_serial: Update zcbor files from zcbor 0.7.0
Updates zcbor files from version 0.7.0, needed for size variable
support.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-26 13:11:56 +02:00
Marek Pieta a95a41b3e1 boot: bootutil: loader: Let image version comparison use build number
Change allows using build number in image version comparison.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-04-25 12:04:27 +02:00
David Brown 3cbb79c25f boot: Fix DOS line endings
This file made it into the repo with DOS line endings. Fix this to match
everything else.

Signed-off-by: David Brown <david.brown@linaro.org>
2023-04-24 11:47:14 +02:00
Jamie McCrae f7d8660e85 boot_serial: Fix include paths for zephyr builds
Fixes include paths for zephyr builds to use the system zcbor_*
files rather than the local files.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-24 11:34:28 +02:00
Roland Mikhel c7835371a0 bootutil: Add FIH for ED25519 sig verification
Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: If43ff9a7c3d755a32b310230e05d01235868392d
2023-04-24 08:36:14 +02:00
Roland Mikhel 186ac88583 bootutil: Fix FIH return type for EC256
For bootutil_verify_sig the declaration expects fih_ret
as the return type not fih_int, this has now been fixed.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: If5943758bebdbf401b1eb387de334fa19a3a7781
2023-04-24 08:36:14 +02:00
Dominik Ermel 5397c13d24 zephyr: serial_recovery: Fix broken CDC device selection
When using CDC only and CONFIG_SERIAL is not enabled in Zephyr,
but there is chosen zephyr,mcumgr-uart, the chosen
takes precedence over CDC and directs MCUmgr to that uart.
This causes two issues: first the CDC is ignored if chosen exists,
and makes build fail because drivers are not built.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-19 14:38:02 +02:00
Dominik Ermel 918da26a67 bootutil: Provide boot_set_next function
Commit provides boot_set_next function that allows to set next
application slot to boot by flash area object pointer, describing
the slot.
The function also takes active which is supposed to indicate whether
running application is being set for next boot and confirm parameter
that allows to confirm the image.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-14 15:51:27 +02:00
Jamie McCrae 6902abba27 zephyr: Create common boot serial enter function
Creates a common function for enterial serial recovery mode.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-13 20:07:55 +02:00
Jamie McCrae 35941feacd boot: zephyr: Add pin reset serial recovery entrance method
Adds an optional method for entering serial recovery mode by use
of a pin reset.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-13 20:07:55 +02:00
Jamie McCrae fd79db3a9f zephyr: boot: serial_recovery: Add no application entrace method
Adds a bootloader serial recovery entrance mode that will allow
recovering a module if there is no application that can be booted.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-13 20:07:55 +02:00
Jamie McCrae b3e3ce39f3 boot: zephyr: serial_recovery: Add boot mode enter ability
Adds an optional entrance method for mcuboot's serial recovery by
using Zephyr's boot mode retention system, this allows for an
application to set the retained data and reboot into the bootloader.
This also adds a selection of how to enter serial recovery mode, it
no longer requires having a GPIO entrance mechanism. Entrance
methods have been added under a new Kconfig menu.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-13 20:07:55 +02:00
Jamie McCrae e5c57dd134 boot_serial: Only have build number if non-zero
Only returns the build number in versions responses if the value
is non-zero.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-13 19:25:42 +02:00
Roland Mikhel 8a3b32ce6c bootutil: Refactor signature verification
The current ECDSA-P256 implementation code contains
a lot of code that is tied to a specific condition being met.
The aim of this commit is to cleanup the main verification
logic to be unified between crypto backends and move the
conditional code where it is relevant.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I06b050a263b2b88b08708defb6aa1001a08ba2ae
2023-04-12 17:58:42 +02:00
Roland Mikhel 206b914852 bootutil: Remove P224 curve
Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I49fad7ede202de4e3c710bf4aa1df195a310b037
2023-04-11 07:05:38 +02:00
Jamie McCrae 827118f2e4 boot: serial_recovery: Add image hash support
Adds support for outputting the image hash TLV in serial recovery
mode, which is needed to comply with the img_mgmt MCUmgr group
requirements.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-23 10:25:38 +01:00
Piotr Dymacz f5e7753b9e boot_serial: support fragmentation for outgoing SMP packets
The mcumgr packet sent over serial should be fragmented into frames of
up to 127 bytes, including 2-bytes frame start header and 1-byte for
terminating newline [1], resulting in up to 124 bytes for the base64
encoded payload.

Current implementation doesn't fulfill above requirement and transmits
single frames, without considering their length. This change introduces
support for fragmenting as defined in 'SMP over console' specification.

[1] github.com/apache/mynewt-mcumgr/blob/master/transport/smp-console.md

Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
2023-03-21 15:10:12 +01:00
Dominik Ermel 1090d8ffc0 zephyr: Check zephyr,uart-mcumgr as candidate for serial recovery
The commit modifies selection of boot serial UART by first checking
the Zephyr chosen zephyr,uart-mcumgr and then reverting to the
zephyr,console, as a secondary candidate.
In case when both nodes are present and point to the same device,
error will be reported.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-20 17:16:42 +01:00
Dominik Ermel 143485e35b zephyr: Add missing Kconfig dependencies for USB DFU
USB DFU depends on MULTITHREADING and STREAM_FLASH, and these
should be explicitly selected.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-17 15:30:58 +01:00
Szymon Janc 874a0ab4d5 boot_serial: Fix Mynewt tests build
__packed may not be available in all environments. In such
case just fallback to  __attribute__((__packed__)).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-03-17 07:53:19 -03:00
Dominik Ermel c89a94f120 mynewt: Add flash_area_get_sector
Simple stub of flash_area_get_sector using system provided
flash_area_sector_from_off.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-15 20:15:58 +01:00
Stephane Le Roy 259d989f2e bootutil: Fix erase of trailer when located in scratch area
Trailer is temporary located in scratch when data of image goes up to last
sector of primary slot. At the end of the swap procedure, the temporary
trailer in scratch must be erased to prevent mcuboot from reading a stale
status from the scratch area. The erase tentative was not correct, this
is fixed.Issue is easily reproduced with an image size of one sector.

Signed-off-by: Stephane Le Roy <stephane.leroy@st.com>
Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
2023-03-15 15:12:24 -03:00
Jamie McCrae e8294b2af5 boot_serial: Add packed to struct
Adds a packed attribute to the nmgr struct to avoid issues on
architectures that do not support unaligned memory access.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-15 09:23:04 +01:00
Dominik Ermel 68dcc0ee10 zephyr: single_loader: Switch to flash_area_get_sector
Use flash_area_get_sector instead of flash_area_sector_from_off.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-14 08:13:20 -06:00
Dominik Ermel 2476988309 boot: Switch to flash_area_get_sector.
Replace flash_area_sector_from_off calls with flash_area_get_sector.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-14 08:13:20 -06:00
Dominik Ermel bd0d94ce4b espressif: Add flash_area_get_sector
Commits adds implementation of flash_area_get_sector that
is supposed to replace flash_area_sector_from_off.
The flash_area_get_sector gets additional parameter of flash_area
type, while flash_area_sector_from_off uses hardcoded flash_area.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-14 08:13:20 -06:00
Dominik Ermel 069aea48a2 zephry: Add flash_area_get_sector
Commits adds implementation of flash_area_get_sector that
is supposed to replace flash_area_sector_from_off.
The flash_area_get_sector gets additional parameter of flash_area
type, while flash_area_sector_from_off uses hardcoded flash_area.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-14 08:13:20 -06:00
Jamie McCrae 9551b6ef03 boot: zephyr: Remove deprecated GPIO Kconfig entries
Removes the old deprecated Kconfig items for configuring GPIO ports
and pins for entering serial recovery/USB DFU mode. These were
deprecated almost a year ago and should not be used as device tree
has long replaced them.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-13 13:22:37 +01:00
Jamie McCrae dc8ef87932 zephyr: serial_recovery: Use Zephyr manifest zcbor files
Switches from using the zcbor files in-tree to using the ones that
are part of the zephyr manifest, this prevents using old and
potentially buggy versions of the zcbor library.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-13 13:19:27 +01:00
Jamie McCrae b56a65f5cb zephyr: serial_recovery: Fix missing limit on buffer size
Fixes an issue whereby the unaligned memory buffer does not
have limits applied to it.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-01 15:39:54 +01:00
Dominik Ermel 0119cdb570 zephyr: Add missing flash_map.h to sysflash.h
The sysflash.h defines FLASH_AREA_ macros using FIXED_PARTITION
macros that are provided by flash_map.h, but it does not include
the required header.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-01 15:37:22 +01:00
INFINEON\DovhalA 94360d5b2f Fix possible array index overflow in loader.c: fill_rsp()
Signed-off-by: INFINEON\DovhalA <Artem.Dovhal@infineon.com>
2023-02-28 08:08:35 -07:00
Dominik Ermel 472d4c7fed bootutil: Pass flash_area to boot_read_swap_size
Modifies boot_read_swap_size and boot_read_enc_key to use
flash_area object pointer instead of image index.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-28 08:06:10 -07:00
Jamie McCrae 9e8eddcecb boot: zephyr: Clean up before chainloading by default
This changes the default mcuboot configuration for zephyr
applications to clean up before booting the user application. The
reason for this change is that mcuboot may configure protection (e.g.
MPU stack guard) which is then used by the user application during
its startup code prior to cleaning the configuration up, this can
lead to a unbootable application and potentially irrecoverable
module, therefore cleaning up is now being enabled by default.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-27 15:20:50 +01:00
Sherry Zhang 120b7182ae FIH: Fix possible static check error caused by FIH_DECLARE
Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: I970582777018094d0cbf83d3131a7d5c576035e5
2023-02-27 11:25:33 +01:00
Dominik Ermel c68a600403 bootutil: Little rework of boot_find_status
In rework:
  - size has been removed from array, as it has been making array
    at least of two elements, even if scratch partition not used;
  - some variables have been localized and some removed;
  - no longer returning rc codes from flash_area_ functions on
    failure, just single point of failure-exit - it made no sense
    anyway as we can not recover from flash failure;
  - flash area pointer is now NULLified on failure, or when
    status not found.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-22 08:51:18 -07:00
Dominik Ermel 23a7a2e61f bootutil: Move duplicate static inline functions to one header
The commit moves static common functions that have duplicate
definitions in bootutil_public.c and bootutil_misc.c to header
file to be included by both files.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-22 08:49:31 -07:00
Jamie McCrae aee388aefa zephyr: serial_recovery: Fix confusing/wrong Kconfig values
Fixes some confusing Kconfig values to have values that make
sense for the underlying SMP transport.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-17 15:53:57 +01:00
Jamie McCrae cde363926b zephyr: serial_recovery: Make receive buffers configurable
This allows making the number of receive buffers configurable
instead of being fixed at 2.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-17 15:53:57 +01:00
Dominik Ermel 453e8bd7de flash_map_backend: Remove flash_area_id_to_image_slot
The function has not been in use and some ports have not been
implementing it anyway.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 16:40:21 -07:00
Dominik Ermel b26fc487ee boot/boot_serial: Add boot_reset_request_hook to bs_reset
When hooks are enabled then boot_reset_request_hook will be
called to check whether it is allowed to reset a device.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 16:33:34 -07:00
Dominik Ermel ad35e2b227 boot/bootutil: Provide prototype for boot_reset_request_hook
Provide prototype for a new hook boot_reset_request_hook
which is called when device is requested to reboot.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 16:33:34 -07:00
Dominik Ermel a4c725109d zephyr: Remove FLASH_AREA_IMAGE_SCRATCH from single app config
Does not have to be set anymore when CONFIG_SINGLE_APPLICATION_SLOT
is set.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 08:42:15 -07:00
Dominik Ermel d546079707 bootutil: Don't default to scratch when single app is used
When MCUBOOT_SINGLE_APPLICATION_SLOT is set then the app can
only be overwritten with new image and scratch algorithm
is not used. The configuration logic would default
MCUBOOT_SWAP_USING_SCRATCH to 1 because it was lacking
check for MCUBOOT_SINGLE_APPLICATION_SLOT.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 08:42:15 -07:00