Skip to content

Commit ef3af33

Browse files
committed
[nrf mergeup]: Synchronize MCUboot with zephyrproject-rtos/mcuboot
Synchronize MCUboot up to upstream commit 3fc5941 Signed-off-by: Andrzej Puzdrowski <[email protected]>
2 parents 3384cd3 + 3fc5941 commit ef3af33

38 files changed

+485
-59
lines changed

boot/bootutil/include/bootutil/bootutil_public.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ extern "C" {
8888

8989
#define BOOT_MAGIC_SZ (sizeof boot_img_magic)
9090

91+
#define BOOT_EFLASH 1
92+
#define BOOT_EFILE 2
93+
#define BOOT_EBADIMAGE 3
94+
#define BOOT_EBADVECT 4
95+
#define BOOT_EBADSTATUS 5
96+
#define BOOT_ENOMEM 6
97+
#define BOOT_EBADARGS 7
98+
#define BOOT_EBADVERSION 8
99+
100+
/*
101+
* Extract the swap type and image number from image trailers's swap_info
102+
* filed.
103+
*/
104+
#define BOOT_GET_SWAP_TYPE(swap_info) ((swap_info) & 0x0F)
105+
#define BOOT_GET_IMAGE_NUM(swap_info) ((swap_info) >> 4)
106+
107+
/* Construct the swap_info field from swap type and image number */
108+
#define BOOT_SET_SWAP_INFO(swap_info, image, type) { \
109+
assert((image) < 0xF); \
110+
assert((type) < 0xF); \
111+
(swap_info) = (image) << 4 \
112+
| (type); \
113+
}
114+
#ifdef MCUBOOT_HAVE_ASSERT_H
115+
#include "mcuboot_config/mcuboot_assert.h"
116+
#else
117+
#include <assert.h>
118+
#define ASSERT assert
119+
#endif
120+
91121
struct boot_swap_state {
92122
uint8_t magic; /* One of the BOOT_MAGIC_[...] values. */
93123
uint8_t swap_type; /* One of the BOOT_SWAP_TYPE_[...] values. */

boot/bootutil/include/bootutil/enc_key.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,14 @@
3232
#include <flash_map_backend/flash_map_backend.h>
3333
#include "bootutil/crypto/aes_ctr.h"
3434
#include "bootutil/image.h"
35+
#include "bootutil/enc_key_public.h"
3536

3637
#ifdef __cplusplus
3738
extern "C" {
3839
#endif
3940

40-
#define BOOT_ENC_KEY_SIZE 16
4141
#define BOOT_ENC_KEY_SIZE_BITS (BOOT_ENC_KEY_SIZE * 8)
4242

43-
#define TLV_ENC_RSA_SZ 256
44-
#define TLV_ENC_KW_SZ 24
45-
#define TLV_ENC_EC256_SZ (65 + 32 + 16)
46-
#define TLV_ENC_X25519_SZ (32 + 32 + 16)
47-
48-
#if defined(MCUBOOT_ENCRYPT_RSA)
49-
#define BOOT_ENC_TLV_SIZE TLV_ENC_RSA_SZ
50-
#elif defined(MCUBOOT_ENCRYPT_EC256)
51-
#define BOOT_ENC_TLV_SIZE TLV_ENC_EC256_SZ
52-
#elif defined(MCUBOOT_ENCRYPT_X25519)
53-
#define BOOT_ENC_TLV_SIZE TLV_ENC_X25519_SZ
54-
#else
55-
#define BOOT_ENC_TLV_SIZE TLV_ENC_KW_SZ
56-
#endif
57-
5843
#define BOOT_ENC_TLV_ALIGN_SIZE \
5944
((((BOOT_ENC_TLV_SIZE - 1) / BOOT_MAX_ALIGN) + 1) * BOOT_MAX_ALIGN)
6045

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2018-2019 JUUL Labs
5+
* Copyright (c) 2019 Arm Limited
6+
* Copyright (c) 2021 Nordic Semiconductor ASA
7+
*
8+
* Original license:
9+
*
10+
* Licensed to the Apache Software Foundation (ASF) under one
11+
* or more contributor license agreements. See the NOTICE file
12+
* distributed with this work for additional information
13+
* regarding copyright ownership. The ASF licenses this file
14+
* to you under the Apache License, Version 2.0 (the
15+
* "License"); you may not use this file except in compliance
16+
* with the License. You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing,
21+
* software distributed under the License is distributed on an
22+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23+
* KIND, either express or implied. See the License for the
24+
* specific language governing permissions and limitations
25+
* under the License.
26+
*/
27+
28+
#ifndef BOOTUTIL_ENC_KEY_PUBLIC_H
29+
#define BOOTUTIL_ENC_KEY_PUBLIC_H
30+
#include <mcuboot_config/mcuboot_config.h>
31+
#ifdef __cplusplus
32+
extern "C" {
33+
#endif
34+
35+
#define BOOT_ENC_KEY_SIZE 16
36+
37+
#define TLV_ENC_RSA_SZ 256
38+
#define TLV_ENC_KW_SZ 24
39+
#define TLV_ENC_EC256_SZ (65 + 32 + 16)
40+
#define TLV_ENC_X25519_SZ (32 + 32 + 16)
41+
42+
#if defined(MCUBOOT_ENCRYPT_RSA)
43+
#define BOOT_ENC_TLV_SIZE TLV_ENC_RSA_SZ
44+
#elif defined(MCUBOOT_ENCRYPT_EC256)
45+
#define BOOT_ENC_TLV_SIZE TLV_ENC_EC256_SZ
46+
#elif defined(MCUBOOT_ENCRYPT_X25519)
47+
#define BOOT_ENC_TLV_SIZE TLV_ENC_X25519_SZ
48+
#else
49+
#define BOOT_ENC_TLV_SIZE TLV_ENC_KW_SZ
50+
#endif
51+
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif /* BOOTUTIL_ENC_KEY_PUBLIC_H */

boot/bootutil/src/bootutil_priv.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,8 @@
4747
extern "C" {
4848
#endif
4949

50-
#ifdef MCUBOOT_HAVE_ASSERT_H
51-
#include "mcuboot_config/mcuboot_assert.h"
52-
#else
53-
#include <assert.h>
54-
#define ASSERT assert
55-
#endif
56-
5750
struct flash_area;
5851

59-
#define BOOT_EFLASH 1
60-
#define BOOT_EFILE 2
61-
#define BOOT_EBADIMAGE 3
62-
#define BOOT_EBADVECT 4
63-
#define BOOT_EBADSTATUS 5
64-
#define BOOT_ENOMEM 6
65-
#define BOOT_EBADARGS 7
66-
#define BOOT_EBADVERSION 8
67-
6852
#define BOOT_TMPBUF_SZ 256
6953

7054
/** Number of image slots in flash; currently limited to two. */
@@ -169,21 +153,6 @@ _Static_assert(BOOT_IMAGE_NUMBER > 0, "Invalid value for BOOT_IMAGE_NUMBER");
169153

170154
#define BOOT_MAX_IMG_SECTORS MCUBOOT_MAX_IMG_SECTORS
171155

172-
/*
173-
* Extract the swap type and image number from image trailers's swap_info
174-
* filed.
175-
*/
176-
#define BOOT_GET_SWAP_TYPE(swap_info) ((swap_info) & 0x0F)
177-
#define BOOT_GET_IMAGE_NUM(swap_info) ((swap_info) >> 4)
178-
179-
/* Construct the swap_info field from swap type and image number */
180-
#define BOOT_SET_SWAP_INFO(swap_info, image, type) { \
181-
assert((image) < 0xF); \
182-
assert((type) < 0xF); \
183-
(swap_info) = (image) << 4 \
184-
| (type); \
185-
}
186-
187156
#define BOOT_LOG_IMAGE_INFO(slot, hdr) \
188157
BOOT_LOG_INF("%-9s slot: version=%u.%u.%u+%u", \
189158
((slot) == BOOT_PRIMARY_SLOT) ? "Primary" : "Secondary", \

boot/bootutil/src/bootutil_public.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@
4545

4646
#include "bootutil/image.h"
4747
#include "bootutil/bootutil_public.h"
48-
#include "bootutil_priv.h"
4948
#include "bootutil/bootutil_log.h"
5049
#ifdef MCUBOOT_ENC_IMAGES
51-
#include "bootutil/enc_key.h"
50+
#include "bootutil/enc_key_public.h"
5251
#endif
5352

5453
#ifdef CONFIG_MCUBOOT

boot/cypress/BlinkyApp/libs.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SOURCES_PDL := $(wildcard $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/source/*.c)
3535

3636
# Collect source files for Retarget-io
3737
SOURCES_RETARGET_IO := $(wildcard $(CUR_LIBS_PATH)/retarget-io/*.c)
38+
SOURCES_WATCHDOG := $(wildcard $(CUR_LIBS_PATH)/watchdog/*.c)
3839

3940
# Collect source files for HAL
4041
SOURCES_HAL := $(wildcard $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/*.c)
@@ -49,6 +50,7 @@ INCLUDE_DIRS_PDL += $(CUR_LIBS_PATH)/pdl/psoc6pdl/cmsis/include
4950

5051
# Retarget-io related include directories
5152
INCLUDE_DIRS_RETARGET_IO := $(CUR_LIBS_PATH)/retarget-io
53+
INCLUDE_DIRS_WATCHDOG := $(CUR_LIBS_PATH)/watchdog
5254

5355
# core-libs related include directories
5456
INCLUDE_DIRS_CORE_LIB := $(CUR_LIBS_PATH)/core-lib/include
@@ -63,12 +65,14 @@ INCLUDE_DIRS_HAL += $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/include/trigger
6365
SOURCES_LIBS := $(SOURCES_PDL)
6466
SOURCES_LIBS += $(SOURCES_PLATFORM)
6567
SOURCES_LIBS += $(SOURCES_RETARGET_IO)
68+
SOURCES_LIBS += $(SOURCES_WATCHDOG)
6669
SOURCES_LIBS += $(SOURCES_HAL)
6770

6871
# Collected include directories for libraries
6972
INCLUDE_DIRS_LIBS := $(addprefix -I,$(INCLUDE_DIRS_PDL))
7073
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_PLATFORM))
7174
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_RETARGET_IO))
75+
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_WATCHDOG))
7276
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_CORE_LIB))
7377
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_HAL))
7478

boot/cypress/BlinkyApp/main.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "cy_pdl.h"
2828
#include "cyhal.h"
2929
#include "cy_retarget_io.h"
30+
#include "watchdog.h"
3031

3132
/* Define pins for UART debug output */
3233

@@ -60,11 +61,14 @@ const cy_stc_gpio_pin_config_t LED_config =
6061
.vohSel = 0UL,
6162
};
6263

64+
#define WATCHDOG_UPD_MESSAGE "[BlinkyApp] Update watchdog timer started in MCUBootApp to mark successful start of user app\r\n"
65+
#define WATCHDOG_FREE_MESSAGE "[BlinkyApp] Turn off watchdog timer\r\n"
66+
6367
#ifdef BOOT_IMG
6468
#define BLINK_PERIOD (1000u)
6569
#define GREETING_MESSAGE_VER "[BlinkyApp] BlinkyApp v1.0 [CM4]\r\n"
6670
#define GREETING_MESSAGE_INFO "[BlinkyApp] Red led blinks with 1 sec period\r\n"
67-
#elif UPGRADE_IMG
71+
#elif defined(UPGRADE_IMG)
6872
#define BLINK_PERIOD (250u)
6973
#define GREETING_MESSAGE_VER "[BlinkyApp] BlinkyApp v2.0 [+]\r\n"
7074
#define GREETING_MESSAGE_INFO "[BlinkyApp] Red led blinks with 0.25 sec period\r\n"
@@ -74,8 +78,7 @@ const cy_stc_gpio_pin_config_t LED_config =
7478

7579
void check_result(int res)
7680
{
77-
if (res != CY_RSLT_SUCCESS)
78-
{
81+
if (res != CY_RSLT_SUCCESS) {
7982
CY_ASSERT(0);
8083
}
8184
}
@@ -109,6 +112,12 @@ int main(void)
109112

110113
printf(GREETING_MESSAGE_INFO);
111114

115+
/* Update watchdog timer to mark successful start up of application */
116+
printf(WATCHDOG_UPD_MESSAGE);
117+
cy_wdg_kick();
118+
printf(WATCHDOG_FREE_MESSAGE);
119+
cy_wdg_free();
120+
112121
for (;;)
113122
{
114123
/* Toggle the user LED periodically */

boot/cypress/MCUBootApp/libs.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ MBEDTLS_PATH = $(CURDIR)/../../ext
3333

3434
# Collect source files for PDL
3535
SOURCES_PDL := $(wildcard $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/source/*.c)
36+
SOURCES_WATCHDOG := $(wildcard $(CUR_LIBS_PATH)/watchdog/*.c)
3637

3738
# PDL related include directories
3839
INCLUDE_DIRS_PDL := $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/include
@@ -42,12 +43,14 @@ INCLUDE_DIRS_PDL += $(CUR_LIBS_PATH)/pdl/psoc6pdl/cmsis/include
4243

4344
# core-libs related include directories
4445
INCLUDE_DIRS_CORE_LIB := $(CUR_LIBS_PATH)/core-lib/include
46+
INCLUDE_DIRS_WATCHDOG := $(CUR_LIBS_PATH)/watchdog
4547

4648
SOURCES_HAL += $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/cyhal_crypto_common.c
4749
SOURCES_HAL += $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/cyhal_hwmgr.c
4850

4951
# Collected source files for libraries
5052
SOURCES_LIBS := $(SOURCES_PDL)
53+
SOURCES_LIBS += $(SOURCES_WATCHDOG)
5154
SOURCES_LIBS += $(SOURCES_PLATFORM)
5255
SOURCES_LIBS += $(SOURCES_HAL)
5356

@@ -61,6 +64,7 @@ INCLUDE_DIRS_HAL += $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/include/pin_pac
6164
INCLUDE_DIRS_LIBS := $(addprefix -I,$(INCLUDE_DIRS_PDL))
6265
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_PLATFORM))
6366
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_CORE_LIB))
67+
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_WATCHDOG))
6468
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_HAL))
6569

6670
################################################################################

boot/cypress/MCUBootApp/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
#include "bootutil/fault_injection_hardening.h"
4040

41+
#include "watchdog.h"
42+
43+
/* WDT time out for reset mode, in milliseconds. */
44+
#define WDT_TIME_OUT_MS 4000
45+
4146
/* Define pins for UART debug output */
4247
#define CYBSP_UART_ENABLED 1U
4348
#define CYBSP_UART_HW SCB5
@@ -121,6 +126,12 @@ int main(void)
121126
if (fih_eq(fih_rc, FIH_SUCCESS))
122127
{
123128
BOOT_LOG_INF("User Application validated successfully");
129+
/* initialize watchdog timer. it should be updated from user app
130+
* to mark successful start up of this app. if the watchdog is not updated,
131+
* reset will be initiated by watchdog timer and swap revert operation started
132+
* to roll back to operable image.
133+
*/
134+
cy_wdg_init(WDT_TIME_OUT_MS);
124135
do_boot(&rsp);
125136
boot_succeeded = true;
126137
}

0 commit comments

Comments
 (0)