Skip to content

Commit 750678e

Browse files
authored
synchronized up to the mcu-tool/mcuboot 4427e4c
Synchronized to: mcu-tools/mcuboot@4427e4c Changes included: boot: zephyr: allow timeout based recovery with CDC ACM boot: zephyr: Only call sys_clock_disable when supported imgtool: fix getpriv format type for keys mynewt: add flash sector requirement for swap move ci: add Mynewt test target for swap move ci: Fix compatibility with packaging==22 boot_serial: Add unaligned stack buffer writing doc: espressif: Add warning note for Flash Encryption with Serial Recovery usage Note: The following commits exists in both branches boot: zephyr: boards: nrf52840dk: Fix overlay espressif: add downgrade prevention feature boot: Update Nordic's license identifier tag docs: fix FIH example command in design.md ci: fih: update TF-M version to 1.7.0 and adjust test suite merged using GitHub web gui. Signed-off-by: Joakim Andersson <[email protected]>
2 parents dd59d90 + 4427e4c commit 750678e

File tree

17 files changed

+313
-82
lines changed

17 files changed

+313
-82
lines changed

boot/boot_serial/src/boot_serial.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,38 @@ bs_upload(char *buf, int len)
511511

512512
BOOT_LOG_INF("Writing at 0x%x until 0x%x", curr_off, curr_off + img_chunk_len);
513513
/* Write flash aligned chunk, note that img_chunk_len now holds aligned length */
514+
#if defined(MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE) && MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE > 0
515+
if (flash_area_align(fap) > 1 &&
516+
(((size_t)img_chunk) & (flash_area_align(fap) - 1)) != 0) {
517+
/* Buffer address incompatible with write address, use buffer to write */
518+
uint8_t write_size = MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE;
519+
uint8_t wbs_aligned[MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE];
520+
521+
while (img_chunk_len >= flash_area_align(fap)) {
522+
if (write_size > img_chunk_len) {
523+
write_size = img_chunk_len;
524+
}
525+
526+
memset(wbs_aligned, flash_area_erased_val(fap), sizeof(wbs_aligned));
527+
memcpy(wbs_aligned, img_chunk, write_size);
528+
529+
rc = flash_area_write(fap, curr_off, wbs_aligned, write_size);
530+
531+
if (rc != 0) {
532+
goto out;
533+
}
534+
535+
curr_off += write_size;
536+
img_chunk += write_size;
537+
img_chunk_len -= write_size;
538+
}
539+
} else {
540+
rc = flash_area_write(fap, curr_off, img_chunk, img_chunk_len);
541+
}
542+
#else
514543
rc = flash_area_write(fap, curr_off, img_chunk, img_chunk_len);
544+
#endif
545+
515546
if (rc == 0 && rem_bytes) {
516547
/* Non-zero rem_bytes means that last chunk needs alignment; the aligned
517548
* part, in the img_chunk_len - rem_bytes count bytes, has already been

boot/mynewt/flash_map_backend/include/flash_map_backend/flash_map_backend.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sysflash/sysflash.h>
1111
#include <flash_map/flash_map.h>
1212
#include <mcuboot_config/mcuboot_config.h>
13+
#include <unistd.h> /* off_t */
1314

1415
#if (MCUBOOT_IMAGE_NUMBER == 1)
1516

@@ -40,6 +41,13 @@
4041
int flash_area_id_from_multi_image_slot(int image_index, int slot);
4142
int flash_area_id_to_multi_image_slot(int image_index, int area_id);
4243

44+
struct flash_sector {
45+
uint32_t fs_off;
46+
uint32_t fs_size;
47+
};
48+
49+
int flash_area_sector_from_off(off_t off, struct flash_sector *sector);
50+
4351
static inline uint8_t flash_area_get_id(const struct flash_area *fa)
4452
{
4553
return fa->fa_id;
@@ -60,4 +68,9 @@ static inline uint32_t flash_area_get_size(const struct flash_area *fa)
6068
return fa->fa_size;
6169
}
6270

71+
static inline uint32_t flash_sector_get_off(const struct flash_sector *fs)
72+
{
73+
return fs->fs_off;
74+
}
75+
6376
#endif /* __FLASH_MAP_BACKEND_H__ */

boot/mynewt/flash_map_backend/src/flash_map_extended.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <flash_map/flash_map.h>
2121
#include <flash_map_backend/flash_map_backend.h>
22+
#include <hal/hal_bsp.h>
23+
#include <hal/hal_flash_int.h>
2224

2325
int flash_area_id_from_multi_image_slot(int image_index, int slot)
2426
{
@@ -42,3 +44,36 @@ int flash_area_id_to_multi_image_slot(int image_index, int area_id)
4244
}
4345
return 255;
4446
}
47+
48+
int flash_area_sector_from_off(off_t off, struct flash_sector *sector)
49+
{
50+
const struct flash_area *fa;
51+
const struct hal_flash *hf;
52+
uint32_t start;
53+
uint32_t size;
54+
int rc;
55+
int i;
56+
57+
rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa);
58+
if (rc != 0) {
59+
return -1;
60+
}
61+
62+
rc = -1;
63+
hf = hal_bsp_flash_dev(fa->fa_device_id);
64+
for (i = 0; i < hf->hf_sector_cnt; i++) {
65+
hf->hf_itf->hff_sector_info(hf, i, &start, &size);
66+
if (start < fa->fa_off) {
67+
continue;
68+
}
69+
if (off >= start - fa->fa_off && off <= (start - fa->fa_off) + size) {
70+
sector->fs_off = start - fa->fa_off;
71+
sector->fs_size = size;
72+
rc = 0;
73+
break;
74+
}
75+
}
76+
77+
flash_area_close(fa);
78+
return rc;
79+
}

boot/zephyr/Kconfig.serial_recovery

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ config MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
5151
Note that 0 is default upload target when no explicit
5252
selection is done.
5353

54+
config BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
55+
int "Stack buffer for unaligned memory writes"
56+
default 64
57+
help
58+
Specifies the stack usage for a buffer which is used for unaligned
59+
memory access when data is written to a device with memory alignment
60+
requirements. Set to 0 to disable.
61+
5462
config BOOT_MAX_LINE_INPUT_LEN
5563
int "Maximum input line length"
5664
default 512
@@ -148,7 +156,7 @@ config BOOT_SERIAL_ENCRYPT_EC256
148156

149157
config BOOT_SERIAL_WAIT_FOR_DFU
150158
bool "Wait for a prescribed duration to see if DFU is invoked by receiving a mcumgr comand"
151-
depends on BOOT_SERIAL_UART
159+
depends on BOOT_SERIAL_UART || BOOT_SERIAL_CDC_ACM
152160
help
153161
If y, MCUboot waits for a prescribed duration of time to allow
154162
for DFU to be invoked. The serial recovery can be entered by receiving any

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
#define MCUBOOT_SERIAL_MAX_RECEIVE_SIZE CONFIG_BOOT_SERIAL_MAX_RECEIVE_SIZE
246246
#endif
247247

248+
#ifdef CONFIG_BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
249+
#define MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE CONFIG_BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
250+
#endif
251+
248252
/* Support 32-byte aligned flash sizes */
249253
#if DT_HAS_CHOSEN(zephyr_flash)
250254
#if DT_PROP_OR(DT_CHOSEN(zephyr_flash), write_block_size, 0) > 8

boot/zephyr/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ static void do_boot(struct boot_rsp *rsp)
190190
rsp->br_hdr->ih_hdr_size);
191191
#endif
192192

193-
sys_clock_disable();
193+
if (IS_ENABLED(CONFIG_SYSTEM_TIMER_HAS_DISABLE_SUPPORT)) {
194+
sys_clock_disable();
195+
}
194196

195197
#ifdef CONFIG_USB_DEVICE_STACK
196198
/* Disable the USB to prevent it from firing interrupts */

ci/compare_versions.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from packaging.version import parse, LegacyVersion
15+
from packaging.version import parse, InvalidVersion
1616
import argparse
1717
import sys
1818

19+
try:
20+
from packaging.version import LegacyVersion
21+
except ImportError:
22+
LegacyVersion = () # trick isinstance!
23+
1924
# exit with 0 if --new is equal to --old
2025
# exit with 1 on errors
2126
# exit with 2 if --new is newer than --old
@@ -30,9 +35,20 @@
3035
parser.print_help()
3136
exit(1)
3237

33-
old, new = parse(args.old), parse(args.new)
38+
# packaging>=22 only supports PEP-440 version numbers, and a non-valid version
39+
# will throw InvalidVersion. Previous packaging releases would create a
40+
# LegacyVersion object if the given version string failed to parse as PEP-440,
41+
# and since we use versions closer to semver, we want to fail in that case.
42+
43+
versions = []
44+
for version in [args.old, args.new]:
45+
try:
46+
versions.append(parse(version))
47+
except InvalidVersion:
48+
print("Invalid version parsed: {}".format(version))
49+
sys.exit(1)
3450

35-
# only accept versions that were correctly parsed
51+
old, new = versions[0], versions[1]
3652
for version in [old, new]:
3753
if isinstance(version, LegacyVersion):
3854
print("Invalid version parsed: {}".format(version))

ci/mynewt_targets/swap_move/pkg.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: "targets/swap_move"
21+
pkg.type: "target"
22+
pkg.description:
23+
pkg.author:
24+
pkg.homepage:
25+
26+
pkg.deps:
27+
- "@mcuboot/boot/mynewt"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
syscfg.vals:
20+
BOOT_SERIAL: 0
21+
BOOT_SERIAL_DETECT_PIN: 11
22+
BOOT_SERIAL_DETECT_PIN_VAL: 0
23+
BOOT_SERIAL_REPORT_PIN: 13
24+
BOOTUTIL_VALIDATE_SLOT0: 0
25+
BOOTUTIL_MAX_IMG_SECTORS: 256
26+
BOOTUTIL_SWAP_USING_MOVE: 1
27+
BOOTUTIL_SIGN_EC256: 0
28+
BOOTUTIL_SIGN_RSA: 0
29+
BOOTUTIL_ENCRYPT_RSA: 0
30+
BOOTUTIL_ENCRYPT_KW: 0
31+
BOOTUTIL_USE_MBED_TLS: 0
32+
BOOTUTIL_USE_TINYCRYPT: 1
33+
BOOTUTIL_OVERWRITE_ONLY: 0
34+
BOOTUTIL_OVERWRITE_ONLY_FAST: 1
35+
BOOTUTIL_HAVE_LOGGING: 0
36+
BOOTUTIL_NO_LOGGING: 1
37+
BOOTUTIL_LOG_LEVEL: 'BOOTUTIL_LOG_LEVEL_INFO'
38+
CONSOLE_COMPAT: 1
39+
CONSOLE_INPUT: 0
40+
CONSOLE_UART: 0
41+
CONSOLE_RTT: 0
42+
OS_CPUTIME_TIMER_NUM: 0
43+
TIMER_0: 1
44+
UART_0: 0
45+
BOOTUTIL_BOOTSTRAP: 0
46+
MBEDTLS_NIST_KW_C: 0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
target.app: "@mcuboot/boot/mynewt"
21+
target.bsp: "@apache-mynewt-core/hw/bsp/nordic_pca10056"
22+
target.build_profile: "optimized"

0 commit comments

Comments
 (0)