samples/tfm_integration/tfm_ipc/README.html · samples/tfm_integration/tfm_ipc/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · TF-M

TF-M IPC

PSA call·reboot 권한과 board별 secure/non-secure image 배포를 연결합니다.

Official pathsamples/tfm_integration/tfm_ipc/README.html
Source filesamples/tfm_integration/tfm_ipc/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

IPC Mode와 Library Mode의 차이, BL2 chainload와 platform별 flash 절차를 설명합니다.

Boundary

TF-M Secure · Zephyr Non-secure

Transport

IPC Mode

Targets

MPS2 · STM32 · LPC · Nordic

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 4E90AC6B05CA80D04B6BEDC6740FACA266B35E7E8A10F46075C0FE5AB8D7A0D3
.. _tfm_ipc:

TF-M IPC
########

Overview
********

This is a simple TF-M integration example that can be used with an ARMv8-M
supported board.

It uses **IPC Mode** for communication, where TF-M API calls are made to the
secure image via an IPC mechanism, as opposed to **Library Mode**, where the
IPC mechanism is bypassed in favor of direct calls.

Zephyr uses Trusted Firmware (TF-M) Platform Security Architecture (PSA) APIs
to run this sample in a secure configuration, with Zephyr itself running in a
non-secure configuration.

The sample prints test info to the console either as a single-thread or
multi-thread application.

The sample reboots after 5 seconds to demonstrate rebooting with TF-M.
The sys_reboot call is routed to TF-M, since the nonsecure app is not allowed
to perform the reboot directly.

Building and Running
********************

This project outputs test status and info to the console. It can be built and
executed on MPS2+ AN521 and ST Nucleo L552ZE Q.

On MPS2+ AN521:
===============

#. Build Zephyr with a non-secure configuration (``-DBOARD=mps2/an521/cpu0/ns``).

   .. code-block:: bash

      cd $ZEPHYR_ROOT/samples/tfm_integration/tfm_ipc/
      mkdir build
      cd build
      cmake -DBOARD=mps2/an521/cpu0/ns ..
      make

You can also use west as follows:

   .. code-block:: bash

      $ west build -p -b mps2/an521/cpu0/ns zephyr/samples/tfm_integration/tfm_ipc


#. Copy application binary files (mcuboot.bin and tfm_sign.bin) to ``<MPS2 device name>/SOFTWARE/``.
#. Open ``<MPS2 device name>/MB/HBI0263C/AN521/images.txt``. Edit the ``AN521/images.txt`` file as follows:

   .. code-block:: bash

      TITLE: Versatile Express Images Configuration File

      [IMAGES]
      TOTALIMAGES: 2 ;Number of Images (Max: 32)

      IMAGE0ADDRESS: 0x10000000
      IMAGE0FILE: \SOFTWARE\mcuboot.bin  ; BL2 bootloader

      IMAGE1ADDRESS: 0x10080000
      IMAGE1FILE: \SOFTWARE\tfm_sign.bin ; TF-M with application binary blob

#. Reset MPS2+ board.

If you get the following error when running cmake:

   .. code-block:: bash

      CMake Error at cmake/Common/FindGNUARM.cmake:121 (message):
      arm-none-eabi-gcc can not be found.  Either put arm-none-eabi-gcc on the
      PATH or set GNUARM_PATH properly.

You may need to edit the ``CMakeLists.txt`` file in the ``tfm_ipc`` project
folder to update the ``-DGNUARM_PATH=/opt/toolchain/arm-none-eabi`` path.

On QEMU:
========

The MPS2+ AN521 target (``mps2/an521/cpu0/ns``), which is based on a
dual core ARM Cortex-M33 setup, also allows you to run TF-M tests using QEMU if
you don't have access to a supported ARMv8-M development board.

As part of the normal build process above, a binary is also produced that can
be run via ``qemu-system-arm``. The binary can be executed as follows:

   .. code-block:: bash

      qemu-system-arm -M mps2-an521 -device loader,file=build/zephyr/tfm_merged.hex -serial stdio

You can also run the binary as part of the ``west`` build process by appending
the ``-t run`` flag to the end of your build command, or in the case of
ninja or make, adding the ``run`` commands:

   .. code-block:: bash

      $ west build -b mps2/an521/cpu0/ns zephyr/samples/tfm_integration/tfm_ipc -t run

Or, post build:

   .. code-block:: bash

      $ ninja run

On ST Nucleo L552ZE Q or STM32L562E-DK Discovery:
=================================================

This sample was tested on Ubuntu 18.04 with Zephyr SDK 0.11.3.

Build Zephyr with a non-secure configuration:

   Example, for building non-secure configuration for Nucleo L552ZE Q

   .. code-block:: bash

      $ west build -b nucleo_l552ze_q/stm32l552xx/ns samples/tfm_integration/tfm_ipc/

   Example, for building non-secure configuration for STM32L562E-DK Discovery

   .. code-block:: bash

      $ west build -b stm32l562e_dk/stm32l562xx/ns samples/tfm_integration/tfm_ipc/

The script to initialize the device is available in the ``build/tfm`` folder:

  - ``regression.sh``: Sets platform option bytes config and erase platform.

Run them in the following order to flash the board:

   .. code-block:: bash

      $ ./build/tfm/api_ns/regression.sh
      $ west flash

 .. note::
      Note that ``arm-none-eabi-gcc`` should be available in the PATH variable and that ``STM32_Programmer_CLI`` is required to run ``regression.sh`` (see https://www.st.com/en/development-tools/stm32cubeprog.html). If you are still having trouble running these scripts, check the Programming and Debugging section of the :ref:`nucleo_l552ze_q_board` or :ref:`stm32l562e_dk_board` documentation.

On LPCxpresso55S69:
===================

Build Zephyr with a non-secure configuration:

   .. code-block:: bash

      $ west build -p -b lpcxpresso55s69_ns samples/tfm_integration/tfm_ipc/ --

Make sure your board is set up with :ref:`lpclink2-jlink-onboard-debug-probe`,
since this isn't the debug interface boards ship with from the factory;

Next we need to manually flash the resulting image (``tfm_merged.bin``) with a
J-Link as follows:

   .. code-block:: console

      JLinkExe -device lpc55s69 -if swd -speed 2000 -autoconnect 1
      J-Link>r
      J-Link>erase
      J-Link>loadfile build/zephyr/tfm_merged.bin

Resetting the board and erasing it will unlock the board, this is useful in case
it's in an unknown state and can't be flashed.

We need to reset the board manually after flashing the image to run this code.

On nRF5340 and nRF9160:
=======================

Build Zephyr with a non-secure configuration
(``-DBOARD=nrf5340dk/nrf5340/cpuapp/ns`` or ``-DBOARD=nrf9160dk/nrf9160/ns``).

   Example, for nRF9160, using ``cmake`` and ``ninja``

   .. code-block:: bash

      cd <ZEPHYR_ROOT>/samples/tfm_integration/tfm_ipc/
      rm -rf build
      mkdir build && cd build
      cmake -GNinja -DBOARD=nrf9160dk/nrf9160/ns ..

If building with BL2 (MCUboot bootloader) enabled, manually flash
the MCUboot bootloader image binary (``bl2.hex``).

   Example, using ``nrfjprog`` on nRF9160:

   .. code-block:: bash

      nrfjprog -f NRF91 --program tfm/bin/bl2.hex --sectorerase

Finally, flash the concatenated TF-M + Zephyr binary.

   Example, for nRF9160, using ``cmake`` and ``ninja``

   .. code-block:: bash

      ninja flash

On BL5340:
==========

Build Zephyr with a non-secure configuration
(``-DBOARD=bl5340_dvk/nrf5340/cpuapp/ns``).

   Example using ``cmake`` and ``ninja``

   .. code-block:: bash

      cd <ZEPHYR_ROOT>/samples/tfm_integration/tfm_ipc/
      rm -rf build
      mkdir build && cd build
      cmake -GNinja -DBOARD=bl5340_dvk/nrf5340/cpuapp/ns ..

Flash the concatenated TF-M + Zephyr binary.

   Example using ``west``

   .. code-block:: bash

      west flash --hex-file zephyr/tfm_merged.hex

Sample Output
=============

.. code-block:: console

   [INF] Starting bootloader
   [INF] Swap type: none
   [INF] Bootloader chainload address offset: 0x80000
   [INF] Jumping to the first image slot
   [Sec Thread] Secure image initializing!
   TFM level is: 1 [Sec Thread] Jumping to non-secure code...
   **** Booting Zephyr OS build zephyr-v1.14.0-2904-g89616477b115 ****
   The version of the PSA Framework API is 256.
   The minor version is 1.
   Connect success!
   TFM service support minor version is 1.
   psa_call is successful!
   outvec1 is: It is just for IPC call test.
   outvec2 is: It is just for IPC call test.
   Connect success!
   Call IPC_INIT_BASIC_TEST service Pass Connect success!
   Call PSA RoT access APP RoT memory test service Pass
   TF-M IPC on (.*)


.. _TF-M build instruction:
   https://git.trustedfirmware.org/trusted-firmware-m.git/tree/docs/user_guides/tfm_build_instruction.rst

.. _TF-M secure boot:
   https://git.trustedfirmware.org/trusted-firmware-m.git/tree/docs/user_guides/tfm_secure_boot.rst

Part 3

한국어 전문 번역

개요

지원되는 ARMv8-M board에서 사용할 수 있는 간단한 TF-M integration example입니다.

통신에는 IPC Mode를 사용합니다. 이 mode에서는 IPC mechanism을 통해 secure image의 TF-M API를 호출합니다. IPC를 우회하고 함수를 직접 호출하는 Library Mode와 대비됩니다.

Zephyr는 Trusted Firmware-M(TF-M)의 Platform Security Architecture(PSA) API를 사용해 secure configuration을 구성하며, Zephyr 자체는 non-secure configuration에서 실행됩니다.

Sample은 single-thread 또는 multi-thread application으로 test 정보를 console에 출력합니다.

TF-M과 함께 reboot하는 방법을 보여 주기 위해 5초 뒤 system을 reboot합니다. Non-secure application은 직접 reboot할 권한이 없으므로 sys_reboot call은 TF-M으로 route됩니다.

빌드 및 실행

이 project는 test 상태와 정보를 console에 출력합니다. MPS2+ AN521과 ST Nucleo L552ZE Q에서 build하고 실행할 수 있으며, 아래에는 QEMU·LPCXpresso·Nordic·BL5340 경로도 함께 설명합니다.

MPS2+ AN521

  1. -DBOARD=mps2/an521/cpu0/ns로 non-secure configuration의 Zephyr를 build합니다.

    cd $ZEPHYR_ROOT/samples/tfm_integration/tfm_ipc/
    mkdir build
    cd build
    cmake -DBOARD=mps2/an521/cpu0/ns ..
    make

    west를 사용하려면 다음 command를 실행합니다.

    $ west build -p -b mps2/an521/cpu0/ns zephyr/samples/tfm_integration/tfm_ipc
  2. mcuboot.bin과 tfm_sign.bin application binary를 <MPS2 device name>/SOFTWARE/로 복사합니다.
  3. <MPS2 device name>/MB/HBI0263C/AN521/images.txt를 열고 다음처럼 수정합니다. BL2 bootloader는 0x10000000, TF-M과 application binary blob은 0x10080000에 놓습니다.

    TITLE: Versatile Express Images Configuration File
    
    [IMAGES]
    TOTALIMAGES: 2 ;Number of Images (Max: 32)
    
    IMAGE0ADDRESS: 0x10000000
    IMAGE0FILE: \SOFTWARE\mcuboot.bin  ; BL2 bootloader
    
    IMAGE1ADDRESS: 0x10080000
    IMAGE1FILE: \SOFTWARE\tfm_sign.bin ; TF-M with application binary blob
  4. MPS2+ board를 reset합니다.

CMake 실행 중 다음 오류가 나타날 수 있습니다.

CMake Error at cmake/Common/FindGNUARM.cmake:121 (message):
arm-none-eabi-gcc can not be found.  Either put arm-none-eabi-gcc on the
PATH or set GNUARM_PATH properly.

이 경우 tfm_ipc project folder의 CMakeLists.txt에서 -DGNUARM_PATH=/opt/toolchain/arm-none-eabi path를 실제 toolchain 위치에 맞게 갱신해야 할 수 있습니다.

QEMU

Dual-core ARM Cortex-M33 구성 기반의 MPS2+ AN521 target인 mps2/an521/cpu0/ns는 지원되는 ARMv8-M development board가 없어도 QEMU로 TF-M test를 실행할 수 있게 합니다.

앞의 일반 build 과정은 qemu-system-arm에서 실행할 수 있는 binary도 만듭니다. 다음 command로 그 binary를 실행합니다.

qemu-system-arm -M mps2-an521 -device loader,file=build/zephyr/tfm_merged.hex -serial stdio

west build command 끝에 -t run을 붙여 build 과정에서 바로 실행할 수도 있습니다.

$ west build -b mps2/an521/cpu0/ns zephyr/samples/tfm_integration/tfm_ipc -t run

Build가 끝난 뒤 ninja를 사용한다면 다음처럼 실행합니다. make에서도 같은 run target을 사용할 수 있습니다.

$ ninja run

ST Nucleo L552ZE Q 또는 STM32L562E-DK Discovery

이 sample은 Ubuntu 18.04와 Zephyr SDK 0.11.3에서 시험되었습니다. 먼저 non-secure configuration의 Zephyr를 build합니다.

Nucleo L552ZE Q용 build example입니다.

$ west build -b nucleo_l552ze_q/stm32l552xx/ns samples/tfm_integration/tfm_ipc/

STM32L562E-DK Discovery용 build example입니다.

$ west build -b stm32l562e_dk/stm32l562xx/ns samples/tfm_integration/tfm_ipc/

Device 초기화 script는 build/tfm folder에 있습니다. regression.sh는 platform option byte를 설정하고 platform을 erase합니다. 다음 순서로 실행해 board를 flash합니다.

$ ./build/tfm/api_ns/regression.sh
$ west flash

arm-none-eabi-gcc가 PATH에 있어야 하며, regression.sh 실행에는 STM32_Programmer_CLI가 필요합니다. Script가 계속 실패하면 해당 Nucleo 또는 Discovery board 문서의 Programming and Debugging 절을 확인합니다.

LPCXpresso55S69

다음 command로 non-secure configuration의 Zephyr를 build합니다.

$ west build -p -b lpcxpresso55s69_ns samples/tfm_integration/tfm_ipc/ --

Board 출고 시 기본 debug interface와 다르므로 onboard debug probe를 lpclink2-jlink로 설정해야 합니다.

그다음 결과 image인 tfm_merged.bin을 J-Link로 수동 flash합니다.

JLinkExe -device lpc55s69 -if swd -speed 2000 -autoconnect 1
J-Link>r
J-Link>erase
J-Link>loadfile build/zephyr/tfm_merged.bin

Board를 reset하고 erase하면 lock이 해제되므로 상태를 알 수 없어 flash하지 못할 때 유용합니다. Image를 flash한 뒤 code를 실행하려면 board를 수동 reset해야 합니다.

nRF5340과 nRF9160

-DBOARD=nrf5340dk/nrf5340/cpuapp/ns 또는 -DBOARD=nrf9160dk/nrf9160/ns로 non-secure configuration의 Zephyr를 build합니다.

다음은 nRF9160에서 cmake와 ninja를 사용하는 예입니다.

cd <ZEPHYR_ROOT>/samples/tfm_integration/tfm_ipc/
rm -rf build
mkdir build && cd build
cmake -GNinja -DBOARD=nrf9160dk/nrf9160/ns ..

BL2, 즉 MCUboot bootloader를 활성화했다면 MCUboot image binary인 bl2.hex를 수동 flash합니다. nRF9160의 nrfjprog example은 다음과 같습니다.

nrfjprog -f NRF91 --program tfm/bin/bl2.hex --sectorerase

마지막으로 TF-M과 Zephyr를 연결한 binary를 flash합니다.

ninja flash

BL5340

-DBOARD=bl5340_dvk/nrf5340/cpuapp/ns로 non-secure configuration의 Zephyr를 build합니다. 다음은 cmake와 ninja example입니다.

cd <ZEPHYR_ROOT>/samples/tfm_integration/tfm_ipc/
rm -rf build
mkdir build && cd build
cmake -GNinja -DBOARD=bl5340_dvk/nrf5340/cpuapp/ns ..

그런 다음 west로 TF-M과 Zephyr를 연결한 binary를 flash합니다.

west flash --hex-file zephyr/tfm_merged.hex

샘플 출력

출력에서는 BL2가 첫 image slot로 chainload하고 secure TF-M image를 초기화한 뒤 non-secure Zephyr code로 넘어갑니다. PSA Framework API version과 service minor version을 확인하고, IPC service에 connect한 뒤 psa_call과 Root of Trust memory test가 성공합니다.

[INF] Starting bootloader
[INF] Swap type: none
[INF] Bootloader chainload address offset: 0x80000
[INF] Jumping to the first image slot
[Sec Thread] Secure image initializing!
TFM level is: 1 [Sec Thread] Jumping to non-secure code...
**** Booting Zephyr OS build zephyr-v1.14.0-2904-g89616477b115 ****
The version of the PSA Framework API is 256.
The minor version is 1.
Connect success!
TFM service support minor version is 1.
psa_call is successful!
outvec1 is: It is just for IPC call test.
outvec2 is: It is just for IPC call test.
Connect success!
Call IPC_INIT_BASIC_TEST service Pass Connect success!
Call PSA RoT access APP RoT memory test service Pass
TF-M IPC on (.*)

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.