Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nrf noup] bootutil: loader: fix a hardfault when the external second… #208

Open
wants to merge 129 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
014f42d
zephyr: Replace DT_FLASH_DEV_NAME with DT_CHOSEN_ZEPHYR_FLASH_CONTROL…
galak Apr 8, 2020
8cd5dc5
zephyr: convert DT_JEDEC_SPI_NOR_0_LABEL to new dt macros
galak Apr 8, 2020
39d1aef
Revert "zephyr: convert DT_JEDEC_SPI_NOR_0_LABEL to new dt macros"
nvlsianpu May 7, 2020
48b8ef0
Revert "Revert "zephyr: convert DT_JEDEC_SPI_NOR_0_LABEL to new dt ma…
nvlsianpu May 7, 2020
5657d00
mergeup: merge up to upstream 82c5f7c
nvlsianpu May 7, 2020
b7254d1
zephyr: Change DT_FLASH_AREA_ macros to FLASH_AREA_
galak May 8, 2020
322b11a
zephyr: Change DT_FLASH_AREA_ macros to FLASH_AREA for multimage
nvlsianpu May 11, 2020
1f181dd
sim: Fixup devicetree.h for changes to mcuboot
galak May 11, 2020
e88113b
scripts/assemble: Rework to use EDT library to get devicetree data
galak May 11, 2020
f625267
kconfig: Update to CONFIG_FLOAT to CONFIG_FPU rename in zephyr
joerchan May 19, 2020
4bb0f95
cmake: use find_package to locate Zephyr
tejlmand May 28, 2020
ba7748d
Convert from Zephyr to C99 types
galak May 27, 2020
60cc568
Revert "zephyr: Change DT_FLASH_AREA_ macros to FLASH_AREA_"
nvlsianpu Jun 8, 2020
032eb72
mergeup: merge up to upstream 9b48d08
nvlsianpu Jun 8, 2020
d52aff5
mergeup: merge up to upstream 33fbef5
nvlsianpu Jun 19, 2020
9920005
zephyr: serial: Align with new callback signature
carlescufi Jul 20, 2020
813d29c
mergeup: merge up to upstream 1cb076c
nvlsianpu Aug 3, 2020
0f2c585
mergeup: merge up to upstream 5a6e181
nvlsianpu Aug 14, 2020
3ab5ab3
sample: inclusive language: whitelist -> allow
nashif Aug 26, 2020
f78d1d0
imgtool: fix package's author email
utzig Aug 17, 2020
4804219
zephyr: struct device const-ification
utzig Sep 2, 2020
a5d79cf
boot: zephyr: Fix build issue for multiple conf files
MarekPieta Aug 12, 2020
e8bfc03
zephyr: Fix serial recovery compilation warnings
de-nordic Sep 11, 2020
e312fa2
synch with upstream 296949e
nvlsianpu Oct 7, 2020
e64c5f0
synch with upstream c625da4
nvlsianpu Oct 21, 2020
710ce7f
synch with upstream c74c551
nvlsianpu Oct 29, 2020
c71d218
Merge: Synchronized up to JuulLabs-OSS@c74c551
nvlsianpu Oct 29, 2020
b54f9ac
synch with upstream d2122bc
nvlsianpu Nov 18, 2020
6e3825f
Merge: Synchronized up to mcu-tools@d2122bc
nvlsianpu Nov 23, 2020
cb5a7b3
Merge: Synchronized up to mcu-tools/mcuboot@e512181
henrikbrixandersen Jan 13, 2021
c986a90
Merge: Synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu Jan 14, 2021
915a281
synch with upstream be64e6a
nvlsianpu Jan 14, 2021
6f48e0a
Merge: synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu Jan 14, 2021
52ff566
synch with upstream ce50334
nvlsianpu Jan 15, 2021
3f49b5a
Merge: synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu Jan 20, 2021
770fe67
synch with upstream a513b8e
nvlsianpu Jan 27, 2021
30e0c5a
Merge: synchronized up to mcu-tools@a513b8e
nvlsianpu Jan 27, 2021
2c0608f
synch with upstream 360763d
nvlsianpu Feb 5, 2021
3fc5941
Merge: Synchronized up to https://github.com/zephyrproject-rtos/mcubo…
nvlsianpu Feb 5, 2021
6a7449f
synch with upstream 5b7ed6a
nvlsianpu Mar 2, 2021
846b104
Merge: Synchronized up to 5b7ed6a
nvlsianpu Mar 4, 2021
df55337
synch with upsteram de51807
nvlsianpu Mar 22, 2021
5f00446
Merge synchronized up to de51807
nvlsianpu Mar 22, 2021
6eca8bb
Merge: synchronized up to e20e092
nvlsianpu Apr 30, 2021
3ad36f8
Merge: synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu May 7, 2021
2fce976
Merge: synchronized up to https://github.com/mcu-tools/mcuboot/commit…
nvlsianpu May 18, 2021
7a51968
Merge: synhronize up to https://github.com/mcu-tools/mcuboot/commit/6…
nvlsianpu Jun 9, 2021
62b78ff
boot: zephyr: add integration platforms to the allow list
ioannisg Jul 27, 2021
35576c6
zephyr: remove Kconfig option CONFIG_USB
jfischer-no Aug 2, 2021
3c5eb02
zephyr: get CDC ACM UART device from devicetree
jfischer-no Jul 30, 2021
ca01db4
zephyr: CDC ACM UART node to specific overlays
jfischer-no Aug 20, 2021
a671d92
synch witch upstream commit 85da97f
nvlsianpu Sep 8, 2021
a1d5aea
boot: bootutil: Fix memory alignment of RAM buffer
MarekPieta Jul 15, 2021
26bbc18
boot: Fix IS_ENCRYPTED macro definition
salomethirot-arm Jul 23, 2021
23c9c43
zephyr: update devicetree py package lib files include path in assembly
endiancj Jun 30, 2021
2282da3
cbor_encoder: fix str encoding macros
nvlsianpu Jul 28, 2021
8812dc8
zephyr: Kconfig: fix board references
mbolivar-nordic Jul 28, 2021
9ab84e5
zephyr: do not set defaults for LOG_IMMEDIATE Kconfig
mnkp Jul 24, 2021
f624600
boot_serial: Update cddl-gen version
oyvindronningstad Aug 2, 2021
ff55491
boot_serial: Reintroduce change from fc1ad8d
oyvindronningstad Aug 2, 2021
1e03343
boot: zephyr: Do not use `irq_lock()` if using arm cleanup
sigvartmh Aug 6, 2021
8b668c1
boot_serial: cbor_encode: Fix encoding data length
MarekPieta Aug 18, 2021
d465ab5
boot: zephyr: Fix misaligned #else for `irq_lock`
sigvartmh Aug 20, 2021
b549f67
zephyr/Kconfig: fix deadlock on cryptolib selectors
nvlsianpu Jul 23, 2021
70bfbd2
merge: synchronize up to 85da97f + cherry-pick upstream bugfixes for …
nvlsianpu Sep 14, 2021
9233aef
Preps for 1.8.0-rc2
d3zd3z Aug 27, 2021
1f51559
Merge tag 'v1.8.0-rc2' into zephyr-to-1.8
d3zd3z Oct 4, 2021
c615387
Merge pull request #60 from d3zd3z/zephyr-to-1.8
carlescufi Oct 6, 2021
2c19f9c
synchronize: up to 1a9c6d8495
nvlsianpu Nov 2, 2021
225b024
merge: synchronized with mcutool/mcuboot 1a9c6d8
nvlsianpu Nov 4, 2021
33906b4
Merge: synchronize up to mcu-tools/mcuboot/commit/caa1f6b
nvlsianpu Dec 10, 2021
399720d
Merge: synchronized up to 1eedec3e7936f74872aca43f3962246e7abe6439
nvlsianpu Dec 21, 2021
3f06d75
zephyr/boot_serial_extension: us BOOT_LOG instead of LOG_
nvlsianpu Jan 10, 2022
1c32a04
boot: serial: Adapt to Zephyr's new CRC APIs
carlescufi Feb 10, 2022
89936c3
Merge pull request #72 from nvlsianpu/fix/align_crc_api
carlescufi Feb 10, 2022
7b9e4ee
Merge pull request #73 from nvlsianpu/synch_07III2022
d3zd3z Mar 14, 2022
e86f575
Synch to upstream aa041a2
nvlsianpu Mar 29, 2022
56cd972
[nrf noup] ci: add downstream-only NCS customizations
thst-nordic Nov 23, 2018
4bc1017
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
bea230a
[nrf noup] zephyr: Remove duplication from cmake
sigvartmh Mar 26, 2019
66c554f
[nrf noup] boot: bootutil: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
6ee25a5
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
b35b55e
[nrf noup] boot: add 'minimal' configuration files
mbolivar-nordic Sep 3, 2021
866319a
[nrf noup] boot: zephyr: add support for Thingy:91
bjda Sep 20, 2019
8e09534
[nrf noup] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
ecc2a19
[nrf noup] bootutil: loader: work-around for multi-image builds
sigvartmh Mar 30, 2021
31a950a
[nrf noup] zephyr: Set at least provide EXT_API
Vge0rge Nov 8, 2021
8f69de7
[nrf noup] boot: zephyr: remove CONFIG_DEBUG=y in prj.conf
tejlmand Nov 27, 2020
894db97
[nrf noup] boot: zephyr: Enable zeroize ALT func
Vge0rge Feb 3, 2022
855dfff
[nrf noup] Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
129b631
[nrf noup] bootutil: loader: Add check for netcore addr if NSIB enabled
simon-iversen May 12, 2022
2df4d57
boot: zephyr: Disable CONFIG_USB_DEVICE_REMOTE_WAKEUP
MarekPieta Mar 28, 2022
30889ae
zephyr/Kconfig: fix CONFIG_MCUBOOT_INDICATION_LED usage
nvlsianpu Apr 1, 2022
ccd490c
bootutil: zephyr: Fix not including tinycrypt path when needed
May 3, 2022
75958ec
boot: zephyr: add Kconfig for arm cortex-m that implements a cache
XenuIsWatching May 21, 2022
13296b0
bootutil: zephyr: Fix not linking with mbedtls when needed
May 3, 2022
e58ea98
Merge pull request #78 from nvlsianpu/fixes/for_zephyr_3.1.0-rc2
d3zd3z May 25, 2022
df6249a
espressif:esp32: Move app entry point call back to iram_loader_seg re…
almir-okato May 6, 2022
e7415b5
Merge pull request #79 from nvlsianpu/fixes/cherry-pick-pr1362
d3zd3z May 31, 2022
f6f5f3a
Revert "[nrf noup] bootutil: loader: Add check for netcore addr if NS…
tejlmand Jun 24, 2022
d7f1f4e
Revert "[nrf noup] Restore default RTC user channel count"
tejlmand Jun 24, 2022
84ff3a1
Revert "[nrf noup] boot: zephyr: Enable zeroize ALT func"
tejlmand Jun 24, 2022
df074b1
Revert "[nrf noup] boot: zephyr: remove CONFIG_DEBUG=y in prj.conf"
tejlmand Jun 24, 2022
7d03038
Revert "[nrf noup] zephyr: Set at least provide EXT_API"
tejlmand Jun 24, 2022
5d7dafa
Revert "[nrf noup] bootutil: loader: work-around for multi-image builds"
tejlmand Jun 24, 2022
7be41ea
Revert "[nrf noup] do_boot: clean peripherals state before boot"
tejlmand Jun 24, 2022
6dd4767
Revert "[nrf noup] boot: zephyr: add support for Thingy:91"
tejlmand Jun 24, 2022
c7c8432
Revert "[nrf noup] boot: add 'minimal' configuration files"
tejlmand Jun 24, 2022
0743fd5
Revert "[nrf noup] boot: nrf53-specific customizations"
tejlmand Jun 24, 2022
a2b4569
Revert "[nrf noup] boot: bootutil: Add shared crypto for ECDSA and SHA"
tejlmand Jun 24, 2022
611e545
Revert "[nrf noup] zephyr: Remove duplication from cmake"
tejlmand Jun 24, 2022
757a974
Revert "[nrf noup] treewide: add NCS partition manager support"
tejlmand Jun 24, 2022
49b2a74
Revert "[nrf noup] ci: add downstream-only NCS customizations"
tejlmand Jun 24, 2022
225dc77
[nrf mergeup] Merge commit 'e7415b555134e671ba04f036b02f55cbc087d0e9'…
tejlmand Jun 24, 2022
5552af9
[nrf noup] ci: add downstream-only NCS customizations
thst-nordic Nov 23, 2018
7f6aa07
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
385c1a7
[nrf noup] zephyr: Remove duplication from cmake
sigvartmh Mar 26, 2019
330bc0d
[nrf noup] boot: bootutil: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
7500336
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
7df53bc
[nrf noup] boot: add 'minimal' configuration files
mbolivar-nordic Sep 3, 2021
ce62cee
[nrf noup] boot: zephyr: add support for Thingy:91
bjda Sep 20, 2019
302ad96
[nrf noup] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
428f92c
[nrf noup] bootutil: loader: work-around for multi-image builds
sigvartmh Mar 30, 2021
624ffaa
[nrf noup] zephyr: Set at least provide EXT_API
Vge0rge Nov 8, 2021
359165c
[nrf noup] boot: zephyr: remove CONFIG_DEBUG=y in prj.conf
tejlmand Nov 27, 2020
807df4f
[nrf noup] boot: zephyr: Enable zeroize ALT func
Vge0rge Feb 3, 2022
c967871
[nrf noup] Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
6097de2
[nrf noup] bootutil: loader: Add check for netcore addr if NSIB enabled
simon-iversen May 12, 2022
6d0edaf
[nrf noup] bootutil: loader: fix a hardfault when the external second…
aiminhua Jul 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Backport
on:
pull_request:
types:
- closed
- labeled

jobs:
backport:
runs-on: ubuntu-18.04
name: Backport
steps:
- name: Backport Bot
uses: Gaurav0/[email protected]
with:
bot_username: NordicBuilder
bot_token: 151a9b45052f9ee8be5a59963d31ad7b92c3ecb5
bot_token_key: 67bb1f1f998d546859786a4088917c65415c0ebd
github_token: ${{ secrets.GITHUB_TOKEN }}
57 changes: 57 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# All these sections are optional, edit this file as you like.
[general]
ignore=title-trailing-punctuation, T3, title-max-length, T1, body-hard-tab, B3, B1
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
verbosity = 3
# By default gitlint will ignore merge commits. Set to 'false' to disable.
ignore-merge-commits=true
# Enable debug mode (prints more output). Disabled by default
debug = false

# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
extra-path=../../zephyr/scripts/gitlint

[title-max-length-no-revert]
line-length=72

[body-min-line-count]
min-line-count=1

[body-max-line-count]
max-line-count=200

[title-starts-with-subsystem]
regex = ^(?!subsys:)(([^:]+):)(\s([^:]+):)*\s(.+)$

[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
# will not cause a violation, but "WIP: my title" will.
words=wip

[title-match-regex]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit-msg title must be matched to.
# Note that the regex can contradict with other rules if not used correctly
# (e.g. title-must-not-contain-word).
#regex=^US[0-9]*

[max-line-length-with-exceptions]
# B1 = body-max-line-length
line-length=72

[body-min-length]
min-length=3

[body-is-missing]
# Whether to ignore this rule on merge commits (which typically only have a title)
# default = True
ignore-merge-commits=false

[body-changed-file-mention]
# List of files that need to be explicitly mentioned in the body when they are changed
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
#files=gitlint/rules.py,README.md
6 changes: 6 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library("CI_LIB") _

def pipeline = new ncs.sdk_mcuboot.Main()

pipeline.run(JOB_NAME)

43 changes: 43 additions & 0 deletions boot/bootutil/include/bootutil/crypto/ecdsa_p256.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#if (defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_CC310) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_MBED_TLS)) != 1
#error "One crypto backend must be defined: either CC310, TINYCRYPT, or MBED_TLS"
#endif
Expand All @@ -35,6 +36,11 @@
#define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8)
#endif

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#include <bl_crypto.h>
#define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (4 * 8)
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -158,6 +164,43 @@ static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx,
}
#endif /* MCUBOOT_USE_MBED_TLS */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
typedef uintptr_t bootutil_ecdsa_p256_context;

static inline void bootutil_ecdsa_p256_init(bootutil_ecdsa_p256_context *ctx)
{
(void)ctx;
}

static inline void bootutil_ecdsa_p256_drop(bootutil_ecdsa_p256_context *ctx)
{
(void)ctx;
}

static inline int bootutil_ecdsa_p256_verify(bootutil_ecdsa_p256_context *ctx,
uint8_t *pk, size_t pk_len,
uint8_t *hash,
uint8_t *sig, size_t sig_len)
{
(void)ctx;
(void)pk_len;
(void)sig_len;

/* As described on the compact representation in IETF protocols,
* the first byte of the key defines if the ECC points are
* compressed (0x2 or 0x3) or uncompressed (0x4).
* We only support uncompressed keys.
*/
if (pk[0] != 0x04)
return -1;

pk++;

return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE,
pk, sig);
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
32 changes: 32 additions & 0 deletions boot/bootutil/include/bootutil/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#if (defined(MCUBOOT_USE_MBED_TLS) + \
defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_CC310)) != 1
#error "One crypto backend must be defined: either CC310, MBED_TLS or TINYCRYPT"
#endif
Expand Down Expand Up @@ -139,6 +140,37 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
}
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)

#include <bl_crypto.h>

typedef bl_sha256_ctx_t bootutil_sha256_context;

static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
{
bl_sha256_init(ctx);
}

static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)
{
(void)ctx;
}

static inline int bootutil_sha256_update(bootutil_sha256_context *ctx,
const void *data,
uint32_t data_len)
{
return bl_sha256_update(ctx, data, data_len);
}

static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
uint8_t *output)
{
bl_sha256_finalize(ctx, output);
return 0;
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 4 additions & 1 deletion boot/bootutil/src/image_ec256.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
#if defined(MCUBOOT_USE_CC310) || defined(MCUBOOT_USE_MBED_TLS)
#define NUM_ECC_BYTES (256 / 8)
#endif
#ifdef MCUBOOT_USE_NRF_EXTERNAL_CRYPTO
#define NUM_ECC_BYTES (256 / 8)
#endif
#if defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_CC310) || \
defined(MCUBOOT_USE_MBED_TLS)
defined(MCUBOOT_USE_MBED_TLS) || defined (MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#include "bootutil/sign_key.h"

#include "mbedtls/oid.h"
Expand Down
107 changes: 99 additions & 8 deletions boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include "bootutil/ramload.h"
#include "bootutil/boot_hooks.h"

#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(PM_CPUNET_B0N_ADDRESS)
#include <dfu/pcd.h>
#endif

#ifdef MCUBOOT_ENC_IMAGES
#include "bootutil/enc_key.h"
#endif
Expand Down Expand Up @@ -107,6 +111,15 @@ boot_read_image_headers(struct boot_loader_state *state, bool require_all,
*
* Failure to read any headers is a fatal error.
*/
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. The primary slot of the second image
* (image 1) will not contain a valid image header until an upgrade
* of mcuboot has happened (filling S1 with the new version).
*/
if (BOOT_CURR_IMG(state) == 1 && i == 0) {
continue;
}
#endif /* PM_S1_ADDRESS */
if (i > 0 && !require_all) {
return 0;
} else {
Expand Down Expand Up @@ -798,7 +811,24 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
goto out;
}

if (reset_value < pri_fa->fa_off || reset_value> (pri_fa->fa_off + pri_fa->fa_size)) {
uint32_t min_addr, max_addr;

#ifdef PM_CPUNET_APP_ADDRESS
/* The primary slot for the network core is emulated in RAM.
* Its flash_area hasn't got relevant boundaries.
* Therfore need to override its boundaries for the check.
*/
if (BOOT_CURR_IMG(state) == 1) {
min_addr = PM_CPUNET_APP_ADDRESS;
max_addr = PM_CPUNET_APP_ADDRESS + PM_CPUNET_APP_SIZE;
} else
#endif
{
min_addr = pri_fa->fa_off;
max_addr = pri_fa->fa_off + pri_fa->fa_size;
}

if (reset_value < min_addr || reset_value> (max_addr)) {
BOOT_LOG_ERR("Reset address of image in secondary slot is not in the primary slot");
BOOT_LOG_ERR("Erasing image from secondary slot");

Expand Down Expand Up @@ -882,6 +912,51 @@ boot_validated_swap_type(struct boot_loader_state *state,
int swap_type;
fih_int fih_rc = FIH_FAILURE;

#if defined(PM_S1_ADDRESS)
const struct flash_area *secondary_fa =
BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
struct image_header *hdr = (struct image_header *)secondary_fa->fa_off;
uint32_t vtable_addr = 0;
uint32_t *vtable = 0;
uint32_t reset_addr = 0;
/* Patch needed for NCS. Since image 0 (the app) and image 1 (the other
* B1 slot S0 or S1) share the same secondary slot, we need to check
* whether the update candidate in the secondary slot is intended for
* image 0 or image 1 primary by looking at the address of the reset
* vector. Note that there are good reasons for not using img_num from
* the swap info.
*/

if (hdr->ih_magic == IMAGE_MAGIC) {
vtable_addr = (uint32_t)hdr + hdr->ih_hdr_size;
vtable = (uint32_t *)(vtable_addr);
reset_addr = vtable[1];
#ifdef PM_S1_ADDRESS
#ifdef PM_CPUNET_B0N_ADDRESS
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
#endif
{
const struct flash_area *primary_fa;
int rc = flash_area_open(flash_area_id_from_multi_image_slot(
BOOT_CURR_IMG(state),
BOOT_PRIMARY_SLOT),
&primary_fa);

if (rc != 0) {
return BOOT_SWAP_TYPE_FAIL;
}
/* Get start and end of primary slot for current image */
if (reset_addr < primary_fa->fa_off ||
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
/* The image in the secondary slot is not intended for this image
*/
return BOOT_SWAP_TYPE_NONE;
}
}
#endif /* PM_S1_ADDRESS */
}
#endif /* PM_S1_ADDRESS */

swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
if (BOOT_IS_UPGRADE(swap_type)) {
/* Boot loader wants to switch to the secondary slot.
Expand All @@ -894,7 +969,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
} else {
swap_type = BOOT_SWAP_TYPE_FAIL;
}
}
}
}

return swap_type;
Expand Down Expand Up @@ -1485,7 +1560,7 @@ boot_verify_dependencies(struct boot_loader_state *state)
if (rc == 0) {
/* All dependencies've been satisfied, continue with next image. */
BOOT_CURR_IMG(state)++;
} else {
} else if (rc == BOOT_EBADIMAGE) {
/* Cannot upgrade due to non-met dependencies, so disable all
* image upgrades.
*/
Expand All @@ -1494,7 +1569,10 @@ boot_verify_dependencies(struct boot_loader_state *state)
BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
}
break;
}
} else {
/* Other error happened, images are inconsistent */
return rc;
}
}
return rc;
}
Expand Down Expand Up @@ -2093,10 +2171,23 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
}

#ifdef MCUBOOT_VALIDATE_PRIMARY_SLOT
FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_PRIMARY_SLOT, NULL);
if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
goto out;
}
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. If secure boot is enabled, then mcuboot
* will be stored in either partition S0 or S1. Image 1 primary
* will point to the 'other' Sx partition. Hence, image 1 primary
* does not contain a valid image until mcuboot has been upgraded.
* Note that B0 will perform validation of the active mcuboot image,
* so there is no security lost by skipping this check for image 1
* primary.
*/
if (BOOT_CURR_IMG(state) == 0)
#endif
{
FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_PRIMARY_SLOT, NULL);
if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
goto out;
}
}
#else
/* Even if we're not re-validating the primary slot, we could be booting
* onto an empty flash chip. At least do a basic sanity check that
Expand Down
13 changes: 13 additions & 0 deletions boot/bootutil/src/swap_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
int
boot_slots_compatible(struct boot_loader_state *state)
{
#ifdef PM_S1_ADDRESS
/* Patch needed for NCS. In this case, image 1 primary points to the other
* B1 slot (ie S0 or S1), and image 0 primary points to the app.
* With this configuration, image 0 and image 1 share the secondary slot.
* Hence, the primary slot of image 1 will be *smaller* than image 1's
* secondary slot. This is not allowed in upstream mcuboot, so we need
* this patch to allow it. Also, all of these checks are redundant when
* partition manager is in use, and since we have the same sector size
* in all of our flash.
*/
return 1;
#else
size_t num_sectors_pri;
size_t num_sectors_sec;
size_t sector_sz_pri = 0;
Expand Down Expand Up @@ -247,6 +259,7 @@ boot_slots_compatible(struct boot_loader_state *state)
}

return 1;
#endif /* PM_S1_ADDRESS */
}

#define BOOT_LOG_SWAP_STATE(area, state) \
Expand Down
Loading