Skip to content

Commit

Permalink
M2354: Fix Mbed Studio Debug failure
Browse files Browse the repository at this point in the history
Mbed Studio Debug, 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

Related issue:
ARMmbed#15417
  • Loading branch information
ccli8 committed May 22, 2023
1 parent b5692fd commit dc59ec2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Below summarize the copy paths from TF-M into Mbed:
- trusted-firmware-m/cmake_build/install/outputs/NUVOTON/M2354/tfm_s.bin → tfm_s.bin
- trusted-firmware-m/cmake_build/install/interface/lib/s_veneers.o → s_veneers.o
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/flash_layout.h → partition/flash_layout.h
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/partition_M2354.h → partition/partition_M2354_im.h
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/region_defs.h → partition/region_defs.h
- trusted-firmware-m/cmake_build/install/image_signing/layout_files/signing_layout_s.o → partition/signing_layout_s_preprocessed.h
- trusted-firmware-m/cmake_build/install/image_signing/layout_files/signing_layout_ns.o → partition/signing_layout_ns_preprocessed.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,35 @@
* by the bootloader.
*/
#ifdef BL2
#define BL2_HEADER_SIZE (0x400) /* 1 KB */
#define BL2_TRAILER_SIZE (0x800) /* 2 KB */
#define BL2_HEADER_SIZE (0x1000) /* 4 KB */
/* Evaluate image trailer size for 'SWAP' upgrade strategy
*
* Check the link below for necessary trailer size:
* https://www.mcuboot.com/documentation/design/
*
* With the formula:
* Swap status (BOOT_MAX_IMG_SECTORS * min-write-size * 3)
*
* Where for the platform:
* BOOT_MAX_IMG_SECTORS = 512 (= 1MiB / 2KiB)
* min-write-size = 4 bytes
* Swap status = 512 * 4 * 3 = 6KiB
*
* 6KiB plus other fields for image trailer plus TLV, we reserve 8KiB in total.
*
* Notes for above estimation:
* 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.
* 2. 2KiB is taken from smaller of internal/external Flash's sector sizes.
* 3. Continuing above, SDH Flash's sector size should have adapted to larger from 512 bytes.
* 4. BL2_TRAILER_SIZE must include TLV area, though not mentioned.
* 5. For consistency, BL2_TRAILER_SIZE doesn't change across 'OVERWRITE_ONLY' and "SWAP" upgrade strategies.
* 6. For consistency, (BL2_HEADER_SIZE + BL2_TRAILER_SIZE) doesn't change across w/ and w/o BL2.
*/
#define BL2_TRAILER_SIZE (0x2000) /* 8 KB */
#else
/* No header if no bootloader, but keep IMAGE_CODE_SIZE the same */
#define BL2_HEADER_SIZE (0x0)
#define BL2_TRAILER_SIZE (0x800)
#define BL2_TRAILER_SIZE (0x3000)
#endif /* BL2 */

#define IMAGE_S_CODE_SIZE (FLASH_S_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion targets/TARGET_NUVOTON/scripts/NUVOTON.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def tfm_sign_image(tfm_import_path, signing_key, signing_key_1, non_secure_bin):
#"--pad",
"--pad-header",
"-H",
'0x400',
'0x1000',
"--overwrite-only",
"-s",
'auto', # Or modified_timestamp
Expand Down
2 changes: 1 addition & 1 deletion tools/targets/NU_M2354.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def m2354_tfm_bin(t_self, non_secure_image, secure_bin):
#"--pad",
"--pad-header",
"-H",
'0x400',
'0x1000',
"--overwrite-only",
"-s",
'auto', # Or modified_timestamp
Expand Down

0 comments on commit dc59ec2

Please sign in to comment.