Skip to content

Commit 8b69a94

Browse files
committed
M2354: Fix debug failure in Mbed Studio
In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary. Modification list: 1. Update TF-M import assets with MCUboot header padding to sector aligned 2. Following above, change header size argument (-H) in wrapper.py command line 3. Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line https://docs.mcuboot.com/design.html#image-trailer Related issue: #15417
1 parent 9bff970 commit 8b69a94

File tree

8 files changed

+35
-7
lines changed

8 files changed

+35
-7
lines changed

targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Below summarize the copy paths from TF-M into Mbed:
136136
- trusted-firmware-m/cmake_build/install/outputs/NUVOTON/M2354/tfm_s.bin → tfm_s.bin
137137
- trusted-firmware-m/cmake_build/install/interface/lib/s_veneers.o → s_veneers.o
138138
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/flash_layout.h → partition/flash_layout.h
139+
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/partition_M2354.h → partition/partition_M2354_im.h
139140
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/region_defs.h → partition/region_defs.h
140141
- trusted-firmware-m/cmake_build/install/image_signing/layout_files/signing_layout_s.o → partition/signing_layout_s_preprocessed.h
141142
- trusted-firmware-m/cmake_build/install/image_signing/layout_files/signing_layout_ns.o → partition/signing_layout_ns_preprocessed.h

targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/flash_layout.h

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (c) 2017-2020 Arm Limited. All rights reserved.
33
* Copyright (c) 2020 Nuvoton Technology Corp. All rights reserved.
44
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
57
* Licensed under the Apache License, Version 2.0 (the "License");
68
* you may not use this file except in compliance with the License.
79
* You may obtain a copy of the License at

targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/region_defs.h

+28-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (c) 2017-2020 Arm Limited. All rights reserved.
33
* Copyright (c) 2020 Nuvoton Technology Corp. All rights reserved.
44
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
57
* Licensed under the Apache License, Version 2.0 (the "License");
68
* you may not use this file except in compliance with the License.
79
* You may obtain a copy of the License at
@@ -69,12 +71,35 @@
6971
* by the bootloader.
7072
*/
7173
#ifdef BL2
72-
#define BL2_HEADER_SIZE (0x400) /* 1 KB */
73-
#define BL2_TRAILER_SIZE (0x800) /* 2 KB */
74+
#define BL2_HEADER_SIZE (0x1000) /* 4 KB */
75+
/* Evaluate image trailer size for 'SWAP' upgrade strategy
76+
*
77+
* Check the link below for necessary trailer size:
78+
* https://www.mcuboot.com/documentation/design/
79+
*
80+
* With the formula:
81+
* Swap status (BOOT_MAX_IMG_SECTORS * min-write-size * 3)
82+
*
83+
* Where for the platform:
84+
* BOOT_MAX_IMG_SECTORS = 512 (= 1MiB / 2KiB)
85+
* min-write-size = 4 bytes (per flash_area_align())
86+
* Swap status = 512 * 4 * 3 = 6KiB
87+
*
88+
* 6KiB plus other fields for image trailer plus TLV, we reserve 8KiB in total.
89+
*
90+
* Notes for above estimation:
91+
* 1. In image signing such as bl2/ext/mcuboot/CMakeLists.txt, `--align` must fix to 4 and `--max-sectors` must specify as 512 to catch trailer size overrun error.
92+
* 2. 2KiB is taken from smaller of internal/external Flash's sector sizes.
93+
* 3. Continuing above, SDH Flash's sector size should have adapted to larger from 512 bytes.
94+
* 4. BL2_TRAILER_SIZE must include TLV area, though not mentioned.
95+
* 5. For consistency, BL2_TRAILER_SIZE doesn't change across 'OVERWRITE_ONLY' and "SWAP" upgrade strategies.
96+
* 6. For consistency, (BL2_HEADER_SIZE + BL2_TRAILER_SIZE) doesn't change across w/ and w/o BL2.
97+
*/
98+
#define BL2_TRAILER_SIZE (0x2000) /* 8 KB */
7499
#else
75100
/* No header if no bootloader, but keep IMAGE_CODE_SIZE the same */
76101
#define BL2_HEADER_SIZE (0x0)
77-
#define BL2_TRAILER_SIZE (0x800)
102+
#define BL2_TRAILER_SIZE (0x3000)
78103
#endif /* BL2 */
79104

80105
#define IMAGE_S_CODE_SIZE (FLASH_S_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE)

targets/TARGET_NUVOTON/scripts/NUVOTON.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ def tfm_sign_image(tfm_import_path, signing_key, signing_key_1, non_secure_bin):
107107
"--public-key-format",
108108
'full',
109109
"--align",
110-
'1',
110+
'4',
111111
# Reasons for removing padding and boot magic option "--pad":
112112
# 1. PSA FWU API psa_fwu_install() will be responsible for writing boot magic to enable upgradeable.
113113
# 2. The image size gets smaller instead of slot size.
114114
#"--pad",
115115
"--pad-header",
116116
"-H",
117-
'0x400',
117+
'0x1000',
118118
"--overwrite-only",
119119
"-s",
120120
'auto', # Or modified_timestamp

tools/targets/NU_M2354.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ def m2354_tfm_bin(t_self, non_secure_image, secure_bin):
116116
"--public-key-format",
117117
'full',
118118
"--align",
119-
'1',
119+
'4',
120120
# Reasons for removing padding and boot magic option "--pad":
121121
# 1. PSA FWU API psa_fwu_install() will be responsible for writing boot magic to enable upgradeable.
122122
# 2. The image size gets smaller instead of slot size.
123123
#"--pad",
124124
"--pad-header",
125125
"-H",
126-
'0x400',
126+
'0x1000',
127127
"--overwrite-only",
128128
"-s",
129129
'auto', # Or modified_timestamp

0 commit comments

Comments
 (0)