Skip to content

Commit

Permalink
Merge pull request #15427 from OpenNuvoton/nuvoton_m2354_mcuboot_head…
Browse files Browse the repository at this point in the history
…er_sector_boundary

M2354: Fix debug failure in Mbed Studio
  • Loading branch information
saheerb authored Jun 7, 2023
2 parents 9bff970 + 8b69a94 commit 3b07e53
Show file tree
Hide file tree
Showing 8 changed files with 35 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 @@ -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
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 3b07e53

Please sign in to comment.