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 authored and multiplemonomials committed Sep 24, 2023
1 parent bb0eba5 commit 9458dc3
Show file tree
Hide file tree
Showing 7 changed files with 33 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 @@ -2,6 +2,8 @@
* Copyright (c) 2017-2020 Arm Limited. All rights reserved.
* Copyright (c) 2020 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) 2017-2020 Arm Limited. All rights reserved.
* Copyright (c) 2020 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -69,12 +71,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

0 comments on commit 9458dc3

Please sign in to comment.