diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/README.md b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/README.md index 5b03c916e63..20196bcb4d5 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/README.md +++ b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/README.md @@ -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 diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/flash_layout.h b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/flash_layout.h index 97561f51a97..582d855ee61 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/flash_layout.h +++ b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/flash_layout.h @@ -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 diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/region_defs.h b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/region_defs.h index a1441a8dc22..704e73e7485 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/region_defs.h +++ b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/partition/region_defs.h @@ -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 @@ -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) diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/s_veneers.o b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/s_veneers.o index c963835056b..da13cd5e8fb 100644 Binary files a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/s_veneers.o and b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/s_veneers.o differ diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.axf b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.axf index c623aedfdb2..0b98be608fd 100644 Binary files a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.axf and b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.axf differ diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.bin b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.bin index 321ac85e755..9bdac860b6b 100644 Binary files a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.bin and b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/tfm_s.bin differ diff --git a/targets/TARGET_NUVOTON/scripts/NUVOTON.py b/targets/TARGET_NUVOTON/scripts/NUVOTON.py index e5b080671d1..5fd79845445 100644 --- a/targets/TARGET_NUVOTON/scripts/NUVOTON.py +++ b/targets/TARGET_NUVOTON/scripts/NUVOTON.py @@ -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