Skip to content

Commit

Permalink
M2354: Fix debug failure in Mbed Studio
Browse files Browse the repository at this point in the history
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:
ARMmbed#15417
  • Loading branch information
ccli8 committed May 23, 2023
1 parent b5692fd commit d5690ef
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 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 (per flash_area_align())
* 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.
4 changes: 2 additions & 2 deletions targets/TARGET_NUVOTON/scripts/NUVOTON.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def tfm_sign_image(tfm_import_path, signing_key, signing_key_1, non_secure_bin):
"--public-key-format",
'full',
"--align",
'1',
'4',
# Reasons for removing padding and boot magic option "--pad":
# 1. PSA FWU API psa_fwu_install() will be responsible for writing boot magic to enable upgradeable.
# 2. The image size gets smaller instead of slot size.
#"--pad",
"--pad-header",
"-H",
'0x400',
'0x1000',
"--overwrite-only",
"-s",
'auto', # Or modified_timestamp
Expand Down
4 changes: 2 additions & 2 deletions tools/targets/NU_M2354.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def m2354_tfm_bin(t_self, non_secure_image, secure_bin):
"--public-key-format",
'full',
"--align",
'1',
'4',
# Reasons for removing padding and boot magic option "--pad":
# 1. PSA FWU API psa_fwu_install() will be responsible for writing boot magic to enable upgradeable.
# 2. The image size gets smaller instead of slot size.
#"--pad",
"--pad-header",
"-H",
'0x400',
'0x1000',
"--overwrite-only",
"-s",
'auto', # Or modified_timestamp
Expand Down

0 comments on commit d5690ef

Please sign in to comment.