Commit Graph

366 Commits

Author SHA1 Message Date
David Brown 695e591cf5 boot: Warning fixups after dual image XIP/ram-load
This change introduced a few warnings that weren't caught until enabling
simulator builds with these features enabled.  Add some simple
workarounds to avoid the warnings.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 812a84b0f9 Add capability for DIRECT_XIP feature
Add capability detection for the MCUBOOT_DIRECT_XIP feature.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 9bd7f90e3f boot: Add a RAM base to support testing
Add a macro `IMAGE_RAM_BASE` that will support a simulated device RAM
that can be different per test.  This will be zero on targets.  Define
an invalid value (3) in the simulator environment.  As there are not yet
tests of this configuration, all tests will continue to pass.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 94ed12c401 boot: Fix ifdefs in DIRECT_XIP and RAM_LOAD case
The function `boot_erase_region` is used in some cases when DIRECT_XIP
or RAM_LOAD are defined, however it is specifically not compiled in in
these cases.  Correct the ifdefs so this function will be available.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown dcea564e0a boot: Add capability for ram loading
The MCUBOOT_RAM_LOAD feature supports configurations where code is
loaded from flash into RAM before execution.  As such, it is not
necessary for upgrades to move data around in flash.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 122f9e7099 boot: Add some missing unused arguments
In MCUBOOT_RAM_LOAD mode, bootutil_img_hash has some arguments that end
up being unused, which creates warnings.  Add these to the list of
variables intentionally unused.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
Marek Pieta e51ec0707b boot: bootutil: Fix memory alignment of RAM buffer
Change fixes memory alignment of the RAM buffer that is used to
temporarily store data during swap. Some FLASH drivers require
word-aligned input data buffer. Using unaligned buffer results
in FLASH write error.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-07-16 13:26:43 -06:00
Gustavo Henrique Nihei 8c5ec5a6cf bootutil: Prevent the redefinition of ASSERT
Some OSes may also define the ASSERT macro.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-07-16 13:09:34 -06:00
Gustavo Henrique Nihei 82350d2b0e bootutil: Include missing header on bootutil_public.h
It is required to include "mcuboot_config.h" header for the evaluation
of the MCUBOOT_HAVE_ASSERT_H definition. Otherwise it will implicitly
depend on that header being included somewhere else.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-07-16 13:09:34 -06:00
Sherry Zhang b111f98f62 boot: Add the support of MBEDTLS version 3.0.0
Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: Idd7ce989fe259e9003732e80beaf3dccdedd3050
2021-07-16 09:42:57 +02:00
Sherry Zhang 50b06aeaa4 boot: Fix build time error in DIRECT_XIP mode
Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: I18ce06e008f858a1fef246bf1a4e527320ba6912
2021-07-15 14:22:09 +02:00
Dominik Ermel 260ae0906a boot: Modify common code access for flash_area objects
The commit changes direct access to flash_area, and flash_structure,
objects via filed names to access via getter functions
Purpose of this change is to make common code agnostic to internal
implementation of flash_area, and flash_sector, objects.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-07-06 14:42:53 -06:00
Andrzej Puzdrowski 85da97f2fb bootutil/bootutil_public: Treat unreachable image swap state as empty
Treat state of unreachable image device as if it is empty image.

This is required for boot the primary image if it is still available.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-07-06 12:11:03 -06:00
Andrzej Puzdrowski 54b4ad9fd7 bootutil/loader: Allow not working secondary image device
Let's distinguish a case when secondary image device has a malfunction
from case when primary has a such.
It might be still possible to boot the primary image.

This make sens especially if the secondary image resides in an
external flash which might be damaged while SoC is still working.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-07-06 12:11:03 -06:00
David Vincze 1c4562473e boot: Correct MCUBOOT_DIRECT_XIP_REVERT enablement
To avoid potential errors caused by misconfiguration make sure the
conditionally compiled snippets of code surrounded by the
MCUBOOT_DIRECT_XIP_REVERT macro are only used when direct-xip mode
is selected.

Change-Id: I6178d8186a7ca05887bc7590f5fa0c8f83f3d731
Signed-off-by: David Vincze <david.vincze@arm.com>
2021-07-01 10:22:23 +02:00
David Vincze dd6a84e330 boot: Check shared area more carefully before init
When the shared data area is not exclusively used by MCUboot, but also
by other boot stages it is inappropriate to initialize (erase) the
shared area based on a global variable. It must check the magic value
at the beginning of the area plus it should sanity-check other
available values for a case when memory garbage matches the magic
value.

Change-Id: I3a4552ad2863a61d81de9374ef6302ae0609f7bf
Signed-off-by: David Vincze <david.vincze@arm.com>
2021-07-01 10:22:23 +02:00
Carlos Falgueras García ae13c3c183 bootutil: Fix some misspelling variables
There are a couple of misspelled variables (slot -> active_slot).

fix #1028

Signed-off-by: Carlos Falgueras García <carlos.falgueras@wslw.es>
2021-06-25 11:34:36 -06:00
Carlos Falgueras García afb424dd49 bootutil: Fix bug defining slot_usage_t structure
There is a missing semicolon.

Signed-off-by: Carlos Falgueras García <carlos.falgueras@wslw.es>
2021-06-23 16:24:14 +02:00
Mariusz Poslinski d5e9902352 zephyr: Fix for issue with path length on windows
Switch to use zephyr_library_named() which creates a shorter library name.

Signed-off-by: Mariusz Poslinski <mariusz.poslinski@nordicsemi.no>
2021-06-16 14:21:26 +02:00
Dominik Ermel 51c8d761f6 bootutil: Reduce boot_initialize_area variants
The commit removes implementation of boot_initialize_area
specific for flash_area_to_sectors, and applies changes to
the flash_area_get_sectors using variant, to make it
alternatively work with flash_area_to_sectors.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-06-08 07:39:01 -03:00
Dominik Ermel 7d7472343a bootutil: Use uin32_t instead of size_t to count sectors
The change aligns type of "sector counter" to the type
used for *cnt parameter of flash_area_get_sectors.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-06-08 07:39:01 -03:00
Mark Horvath ccaf7f8814 boot: Multi-image boot for direct-xip and ram-load
Multiple image boot support is implemented for direct-xip and ram-load
strategies. Dependency checking is also added, and for ram-load more
executable ram regions can be set.
Wrapper functions are intoduced to all boot strategies.

Change-Id: I59b346277dcb2c17cef4800f1e556b4ea9144845
Signed-off-by: Mark Horvath <mark.horvath@arm.com>
2021-06-08 07:37:43 -03:00
Dominik Ermel 29aed1d8bd bootutil: Application of boot_read_swap_state
The commit reorganizes logic of the boot_swap_sectors and
the boot_set_pending_multi to use the boot_read_swap_state,
instead of previously used boot_read_swap_state_by_id, to utilize
the flash area object the functions area obtaining.

It also fixes double a flash_area_open that happened implicitly within
the boot_swap_sectors, as it has been calling boot_read_swap_state_by_id
on the FLASH_AREA_IMAGE_SCRATCH, after it has already opened the area.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-05-30 08:14:04 -03:00
Dominik Ermel 0ab87b617a bootutil: Remove area ID parameter from fixup_revert
The fixup_revert has been switched to use boot_read_swap_state,
from boot_read_swap_state_by_id, and no longer needs the ID
parameter.  It can now get swap state information by flash_area
object pointer, which is provided as 3rd parameter.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-05-30 08:14:04 -03:00
Dominik Ermel 8115998cb5 bootutil_public: Make boot_read_swap_state declaration public
The function itself is not static within bootutil and may be used
to operate on flash areas, for which the flash_area object has
already been obtained.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-05-30 08:14:04 -03:00
Salome Thirot 0f64197aff boot: Add AES256 support for image encryption
Support only works when using mbedtls as the cryptographic library.

Signed-off-by: Salome Thirot <salome.thirot@arm.com>
2021-05-18 07:25:12 -03:00
George Beckstein d4d90f8eea Fix version comparison result causing boot failure
The variable `rc` is used in `context_boot_go` for a number of operations, mostly checking return codes for an error. It is also used to store the result of comparing the installed application version numbers (using `boot_version_cmp`).

At the end of `context_boot_go`, `rc` is returned as the result of the operation.

In some configurations, namely direct XIP (without revert or any other extra boot checks), it is possible for the comparison result to be the last value of `rc`. In most cases, this will cause `context_boot_go` to report a failure (ie: non-zero return code), as the value of `rc` will be 1 or -1 if the installed applications aren't the same version.

This commit resets the value of `rc` to 0 after the version comparison has taken place.

Fixes #976

Signed-off-by: George Beckstein <george.beckstein@gmail.com>
2021-05-14 14:57:17 -06:00
Andrzej Puzdrowski 414f915518 boot: Don't examine scratch in BOOT_UPGRADE_ONLY mode
During fetching of swap-status scratch was examined unnecessary
in swap_status_source(). Scratch area shouldn't be needed in this mode.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-05-14 14:19:56 +02:00
Sherry Zhang fbeef9b944 bootutil_public.c: add two user APIs
Add boot_set_pending_multi() and boot_set_confirmed_multi() APIs so
that the user can set the image with given index as pending, confirmed.

Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: Ifca04d396b38c6c64581703794071f6b42e9dfbf
2021-05-14 06:51:38 -03:00
Andrzej Puzdrowski 22b856beea bootutil_public: allow to confirm padded image without copy-done flag
This patch is for fixing:
https://github.com/zephyrproject-rtos/zephyr/issues/34683

copy-done flag is used to design completely copied image.
It is used to recognize whether need to complete image upgrade.
If image is running then:
1) it was already verified and copied by MCUboot
   copy-done flag is set for sure.
2) or it was programmed directly using programming interface

For case 2) when image contains magic but not copy-done flag it was
impossible to confirm it. This patch removes needs of having copy-done
flag set while confirming. This make API behavior similar to situation
when the not-padded image was programmed.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-05-07 13:53:00 +02:00
Fabio Utzig 74c3bab496 crypto: ecdh: define NUM_ECC_BYTES for Mbed TLS
This is a define from Tinycrypt that was being used in the Mbed TLS
EC256 encrypted images implementation so properly define it.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2021-05-06 21:05:47 -03:00
Dominik Ermel 48281627e1 bootutil: Fix boot_write_trailer write alignment
The commit fixes alignment issue in boot_write_trailer, that would
occur in case when input buffer length would be greater than
alignment parameter of flash.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-25 11:40:39 +01:00
Dominik Ermel a7f9e9f530 bootutil: Remove duplicated code from bootutil_misc.c
Duplicated functions, existing in bootutil_public.c have been removed
from bootutil_misc.c.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-25 11:40:39 +01:00
Bohdan Kovalchuk 25c7a0f475 Bootutil/Crypto: add encryption with mbedTLS
Signed-off-by: Bohdan Kovalchuk <bohd@cypress.com>
Signed-off-by: Roman Okhrimenko <roman.okhrimenko@infineon.com>
2021-03-16 21:38:06 -03:00
Roman Okhrimenko 2f045a252e bootutil: Align mbedtls_ecdsa signature verification with cypress mbedtls hw accel implementation
Signed-off-by: Roman Okhrimenko <roman.okhrimenko@cypress.com>
Signed-off-by: Roman Okhrimenko <roman.okhrimenko@infineon.com>
2021-03-12 14:17:28 -07:00
David Brown 641af4530c boot: Support Mbed TLS ECDSA for signatures
Add Mbed TLS ECDSA signature verification as an option (in addition to
Tinycrypt and the CC310 hardware version).  Although the Mbed TLS ECDSA
verification code is both larger and slower, this will still save space
if there is another reason that the Mbed TLS code is already being
brought in for another reason (such as certificate management, for
example).

Mbed TLS's ECDSA verification works at a different level than the other
two libraries, so this takes a bit of reworking.  There are some
additional parameters passed to the various functions, and a new define
MCUBOOT_ECDSA_NEED_ASN1_SIG to indicate that the ecdsa verification
wants the original ASN1 signature, not a decoded key.

This adds the boot changes and simulator support to test this configuration.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-23 10:29:31 -07:00
Dominik Ermel 0c8c8d5325 boot: Direct-XIP: Add check for IMAGE_F_ROM_FIXED flag
The commit adds logic that checks if image, that has IMAGE_F_ROM_FIXED
flag set together with proper address in header, has not been mismatched
with slot.
This code will prevent attempting to boot image that has been build for
different ROM address than a slot it currently resides in.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-02-20 07:12:11 -03:00
Dominik Ermel 9590b42c48 boot: Add IMAGE_F_ROM_FIXED flag support to mcuboot
The IMAGE_F_ROM_FIXED, now supported by imgtool and mcumgr, allows to
use image_header.ih_load_addr to store fixed ROM address information.
The address is provided for Direct-XIP mcuboot to be able to verify
if it can boot an image in given slot, by checking if the address
the image has been built for corresponds to slot address.
This flag is not required to be set within image, in which case
the check will not happen, but is highly desired as it allows mcuboot
to detect images that have been mismatched with slot.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-02-20 07:12:11 -03:00
Dominik Ermel aee3be969e boot: Order IMAGE_F_* flags defintions
Little cleanup.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-02-20 07:12:11 -03:00
Andrzej Puzdrowski 360763d80b bootutil/includes/enc_key: move public part to enc_key_public.h
Part of defines which are needed for bootutil_public.c compilation
were moved to separate file, so the bootutil_public library doesn't
need to include cryptographic libraries headers anymore.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-02-05 12:13:32 +01:00
Andrzej Puzdrowski 3af607f4cb botutil: botutil_public.c shall not include bootutil_private.h
Objective for existence botutil_public.c is to provide common code
for MCUboot itself and for an chain-loaded application. Therefor
it shouldn't depend on MCUboot exclusive functions or so.

This path moves missing part of bootutil_private.h to bootutil_private.c

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-02-05 12:13:32 +01:00
Sherry Zhang 0cfe2ce382 bootutil: Modify boot_add_data_to_shared_area function scope
Modify the function boot_add_data_to_shared_area from static to global
thereby it can be used in the user interface boot_save_shared_data.

Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: Ic6a36eb526a0883a156f832942af3138bde86dd6
2021-01-13 17:09:37 -03:00
Andrzej Puzdrowski be64e6ade0 bootutil_public: made boot_read_swap_state_by_id() API
Made boot_read_swap_state_by_id() public API
function.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-01-13 17:49:49 +01:00
Andrzej Puzdrowski 14ef5763cc bootutil_public: documented module API
document API of the public, shared code module.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-01-13 17:49:49 +01:00
Andrzej Puzdrowski 4700b806ae bootutil_public: add function for determine image_ok flag
Added boot_read_image_ok() to public API as reading image_ok
might be used by the chain-loaded application for checking by
image itself its confirmation state.

Additionally extracted common code for determine a trailer flag to
boot_read_flash() function.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-01-13 17:49:49 +01:00
Andrzej Puzdrowski f573b392ec bootutil: extracted app common library from bootutil_misc
Part of code of boot/bootutil/ is re-implemented in zephyr-rtos
repository.
As some code are defined here and there it becomes problem when
need to include it with outstanding feature in a build.
It is possible to mitigate problem using #fdefry - but this was
rather temporary hack.

This patch introduce new module which is common for MCUBoot build
and application build.
Common code were extracted to bootutil_public.c source file and
bootutil_public.h header

MCUboot also select DISABLE_MCUBOOT_BOOTUTIL_LIB_OWN_LOG Kconfig
option, as it must define log configuration on its own for all its
sourcecode.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-01-13 17:49:49 +01:00
Raef Coles 81d19f017f bootutil: Add cmake build file
In order to allow other projects to include the bootutil files more
easily. Allows renaming and moving of bootutil files without breaking
external projects' file lists (if they include this cmake file instead
of directly listing the files they use). Prevents an issue where
moving/renaming bootutil files breaks the FIH CI test.

Signed-off-by: Raef Coles <raef.coles@arm.com>
Change-Id: Ic982413c6a26ea2039712437f2d511fbe202e1e4
2020-12-16 14:10:31 +01:00
Fabio Utzig 0f409b0589 ext: tinycrypt: update ctr mode to stream
Add an offset parameter to mode ctr so it can be properly used as a
streaming cipher, like required by the flash encryption algorithm.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-11-25 12:37:29 -03:00
Fabio Utzig d3838989d2 bootutil: crypto: avoid unuseful memset
Avoid memset'ing a buffer that does not hold a secret; it contains
the encryption of the counter.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-11-25 12:37:29 -03:00
Tamas Ban e4885a637b boot: Fix LOAD_IMAGE_DATA macro
If RAM_LOAD is defined then the return value of memcpy() is
always compared against its first parameter. By definition
memcpy() returns with its first paramter (destination) so
the not equal check is always false. The fix replaces this
runtime check with a comma operator assigning 0 to the
variable at build time, as a result compiler can be done
dead code elimination much better.

Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Change-Id: I8d0d6e68a931661fa19d395556beb20470d74fb1
2020-11-23 16:37:48 +01:00