Part 1
요약·해설
CONFIG_BUILD_WITH_TFM을 board variant가 제공하는 이유와 mps2_an521_ns memory mapping을 설명합니다.
Board _ns
Secure reservation
CONFIG_TFM_BOARD
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
92468BE0678D7B6697E6EBE72B07DA975C2CC34A868E4B75BDDE737CC7506DE7
Trusted Firmware-M Integration
##############################
The Trusted Firmware-M (TF-M) section contains information about the
integration between TF-M and Zephyr RTOS. Use this information to help
understand how to integrate TF-M with Zephyr for Cortex-M platforms and make
use of its secure run-time services in Zephyr applications.
Board Definitions
*****************
TF-M will be built for the secure processing environment along with Zephyr if
the :kconfig:option:`CONFIG_BUILD_WITH_TFM` flag is set to ``y``.
Generally, this value should never be set at the application level, however,
and all config flags required for TF-M should be set in a board variant with
the ``_ns`` suffix.
This board variant must define an appropriate flash, SRAM and peripheral
configuration that takes into account the initialisation process in the secure
processing environment. :kconfig:option:`CONFIG_TFM_BOARD` must also be set via
`modules/trusted-firmware-m/Kconfig.tfm <https://github.com/zephyrproject-rtos/zephyr/blob/main/modules/trusted-firmware-m/Kconfig.tfm>`__
to the board name that TF-M expects for this target, so that it knows which
target to build for the secure processing environment.
Example: ``mps2_an521_ns``
==========================
The ``mps2_an521`` target is a dual-core Arm Cortex-M33 evaluation board that,
when using the default board variant, would generate a secure Zephyr binary.
The optional ``mps2_an521_ns`` target, however, sets these additional
kconfig flags that indicate that Zephyr should be built as a
non-secure image, linked with TF-M as an external project, and optionally the
secure bootloader:
* :kconfig:option:`CONFIG_TRUSTED_EXECUTION_NONSECURE` ``y``
* :kconfig:option:`CONFIG_ARM_TRUSTZONE_M` ``y``
Comparing the ``mps2_an521.dts`` and ``mps2_an521_ns.dts`` files, we can see
that the ``_ns`` version defines offsets in flash and SRAM memory, which leave
the required space for TF-M and the secure bootloader:
::
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
/* The memory regions defined below must match what the TF-M
* project has defined for that board - a single image boot is
* assumed. Please see the memory layout in:
* https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/tree/platform/ext/target/mps2/an521/partition/flash_layout.h
*/
code: memory@100000 {
reg = <0x00100000 DT_SIZE_K(512)>;
};
ram: memory@28100000 {
reg = <0x28100000 DT_SIZE_M(1)>;
};
};
This reserves 1 MB of code memory and 1 MB of RAM for secure boot and TF-M,
such that our non-secure Zephyr application code will start at 0x10000, with
RAM at 0x28100000. 512 KB code memory is available for the NS zephyr image,
along with 1 MB of RAM.
This matches the flash memory layout we see in ``flash_layout.h`` in TF-M:
::
* 0x0000_0000 BL2 - MCUBoot (0.5 MB)
* 0x0008_0000 Secure image primary slot (0.5 MB)
* 0x0010_0000 Non-secure image primary slot (0.5 MB)
* 0x0018_0000 Secure image secondary slot (0.5 MB)
* 0x0020_0000 Non-secure image secondary slot (0.5 MB)
* 0x0028_0000 Scratch area (0.5 MB)
* 0x0030_0000 Protected Storage Area (20 KB)
* 0x0030_5000 Internal Trusted Storage Area (16 KB)
* 0x0030_9000 NV counters area (4 KB)
* 0x0030_A000 Unused (984 KB)
``mps2/an521`` will be passed in to Tf-M as the board target, specified via
:kconfig:option:`CONFIG_TFM_BOARD`.
Part 3
한국어 전문 번역
이 문서는 Cortex-M platform에서 TF-M secure runtime service를 Zephyr application과 통합하는 방법을 설명합니다.
Board Definitions
CONFIG_BUILD_WITH_TFM=y이면 TF-M은 secure processing environment용으로 build되고 Zephyr non-secure image와 함께 구성됩니다. 하지만 application이 이 flag를 직접 켜는 방식은 권장하지 않습니다. TF-M에 필요한 설정은 _ns suffix를 가진 board variant가 제공해야 합니다.
Non-secure variant는 secure environment가 먼저 수행하는 initialization을 고려해 flash, SRAM, peripheral layout을 정의해야 합니다. 또한 modules/trusted-firmware-m/Kconfig.tfm에서 CONFIG_TFM_BOARD를 TF-M이 기대하는 target name으로 설정해야 secure external project가 올바른 platform을 build합니다.
Example: mps2_an521_ns
mps2_an521은 dual-core Arm Cortex-M33 evaluation board입니다. 기본 variant는 secure Zephyr binary를 만들 수 있지만, mps2_an521_ns는 Zephyr를 non-secure image로 build하고 TF-M external project 및 선택 BL2와 연결합니다.
CONFIG_TRUSTED_EXECUTION_NONSECURE=y: Zephyr image를 non-secure execution용으로 만듭니다.CONFIG_ARM_TRUSTZONE_M=y: Armv8-M TrustZone partitioning 지원을 활성화합니다.
mps2_an521.dts와 mps2_an521_ns.dts를 비교하면 non-secure variant가 TF-M과 secure bootloader에 필요한 앞쪽 flash·SRAM을 비워 두고 Zephyr가 사용할 offset을 선언한 것을 볼 수 있습니다.
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
/* The memory regions defined below must match what the TF-M
* project has defined for that board - a single image boot is
* assumed. Please see the memory layout in:
* https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/tree/platform/ext/target/mps2/an521/partition/flash_layout.h
*/
code: memory@100000 {
reg = <0x00100000 DT_SIZE_K(512)>;
};
ram: memory@28100000 {
reg = <0x28100000 DT_SIZE_M(1)>;
};
};
이 정의는 secure boot와 TF-M에 code memory 1 MB와 RAM 1 MB를 예약합니다. 따라서 non-secure Zephyr code는 0x0010_0000에서 시작해 512 KB를 쓰고 RAM은 0x2810_0000에서 시작해 1 MB를 사용합니다. 원문의 ‘0x10000’ 표기는 code node와 아래 flash layout 기준으로 0x0010_0000을 뜻하는 문맥입니다.
Devicetree reservation은 TF-M의 platform/ext/target/mps2/an521/partition/flash_layout.h와 반드시 일치해야 합니다. Single-image boot를 가정한 공식 layout은 다음과 같습니다.
* 0x0000_0000 BL2 - MCUBoot (0.5 MB)
* 0x0008_0000 Secure image primary slot (0.5 MB)
* 0x0010_0000 Non-secure image primary slot (0.5 MB)
* 0x0018_0000 Secure image secondary slot (0.5 MB)
* 0x0020_0000 Non-secure image secondary slot (0.5 MB)
* 0x0028_0000 Scratch area (0.5 MB)
* 0x0030_0000 Protected Storage Area (20 KB)
* 0x0030_5000 Internal Trusted Storage Area (16 KB)
* 0x0030_9000 NV counters area (4 KB)
* 0x0030_A000 Unused (984 KB)
마지막으로 CONFIG_TFM_BOARD=mps2/an521가 TF-M build에 전달됩니다. Zephyr board 이름과 TF-M platform target 이름이 다르므로 이 mapping이 빠지면 secure image를 올바른 layout으로 만들 수 없습니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.