Part 1
요약·해설
Zbus publish/subscribe, memory domain, CMake environment와 runtime output을 설명합니다.
ext1 · ext2 · ext3 · kext1
Memory domains
llext-edk + CMake
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
2ED3B32CCBC9465AC5E6C0CAFA856288136285F3508581CBC4B979AFBB2DD741
.. zephyr:code-sample:: llext-edk
:name: Linkable loadable extensions EDK
:relevant-api: llext
Enable linkable loadable extension development outside the Zephyr tree using
LLEXT EDK (Extension Development Kit).
Overview
********
This sample demonstrates how to use the Zephyr LLEXT EDK (Extension Development
Kit). It is composed of one Zephyr application, which provides APIs for the
extensions that it loads. The provided API is a simple publish/subscribe system,
based on :ref:`Zbus <zbus>`, which extensions use to communicate with each other.
The application is composed of a subscriber thread, which listens for events
published and republishes them via Zbus to the extensions that are
subscribers. There are four extensions, which are loaded by the application and
run in different contexts. Extensions ``ext1``, ``ext2`` and ``ext3`` run in
userspace, each demonstrating different application and Zephyr API usage, such as
semaphores, spawning threads to listen for events or simply publishing or
subscribing to events. Extension ``kext1`` runs in a kernel thread, albeit similar
to ``ext3``.
The application also creates different memory domains for each extension, thus
providing some level of isolation - although the kernel one still has access
to all of Zephyr kernel.
Note that the kernel extension is only available when the EDK is built with
the :kconfig:option:`CONFIG_LLEXT_EDK_USERSPACE_ONLY` option disabled.
The application is built using the Zephyr build system. The EDK is built using
the Zephyr build system as well, via ``llext-edk`` target. The EDK is then
extracted and the extensions are built using CMake.
Finally, the way the application loads the extensions is by including them
during build time, which is not really practical. This sample is about the EDK
providing the ability to build extensions independently from the application.
One could build the extensions in different directories, not related to the
Zephyr application - even on different machines, using only the EDK. At the
limit, one could even imagine a scenario where the extensions are built by
different teams, using the EDK provided by the application developer.
Building the EDK
****************
To build the EDK, use the ``llext-edk`` target. For example:
.. zephyr-app-commands::
:zephyr-app: samples/subsys/llext/edk/app
:board: qemu_cortex_r5
:goals: build llext-edk
:west-args: -p=always
:compact:
Copy the EDK to some place and extract it:
.. code-block:: console
mkdir /tmp/edk
cp build/zephyr/llext-edk.tar.xz /tmp/edk
cd /tmp/edk
tar -xf llext-edk.tar.xz
Then set ``LLEXT_EDK_INSTALL_DIR`` to the extracted directory:
.. code-block:: console
export LLEXT_EDK_INSTALL_DIR=/tmp/edk/llext-edk
This variable is used by the extensions to find the EDK.
Building the extensions
***********************
The :envvar:`ZEPHYR_SDK_INSTALL_DIR` environment variable is used by the
extensions to find the Zephyr SDK, so you need to ensure it's properly set:
.. code-block:: console
export ZEPHYR_SDK_INSTALL_DIR=</path/to/zephyr-sdk>
To build the extensions, in the ``ext1``, ``ext2``, ``ext3`` and ``kext1``
directories:
.. code-block:: console
cmake -B build
make -C build
Alternatively, you can set the ``LLEXT_EDK_INSTALL_DIR`` directly in the
CMake invocation:
.. code-block:: console
cmake -B build -DLLEXT_EDK_INSTALL_DIR=/tmp/edk/llext-edk
make -C build
Building the application
************************
Now, build the application, including the extensions, and run it:
.. zephyr-app-commands::
:zephyr-app: samples/subsys/llext/edk/app
:board: qemu_cortex_r5
:goals: build run
:west-args: -p=always
:compact:
You should see something like:
.. code-block:: console
[app]Subscriber thread [0x20b28] started.
[app]Loading extension [kext1].
[app]Thread 0x20840 created to run extension [kext1], at privileged mode.
[k-ext1]Waiting sem
[app]Thread [0x222a0] registered event [0x223c0]
[k-ext1]Waiting event
[app]Loading extension [ext1].
[app]Thread 0x20a30 created to run extension [ext1], at userspace.
[app]Thread [0x20a30] registered event [0x26060]
[ext1]Waiting event
[app]Loading extension [ext2].
[app]Thread 0x20938 created to run extension [ext2], at userspace.
[ext2]Publishing tick
[app][subscriber_thread]Got channel tick_chan
[ext1]Got event, reading channel
[ext1]Read val: 0
[ext1]Waiting event
[k-ext1]Got event, giving sem
[k-ext1]Got sem, reading channel
[k-ext1]Read val: 0
[k-ext1]Waiting sem
(...)
Part 3
한국어 전문 번역
개요
Zephyr tree 밖에서 linkable loadable extension을 개발할 수 있게 하는 LLEXT EDK(Extension Development Kit) 사용법을 보여 줍니다. 하나의 Zephyr application이 extension에 API를 제공하며, 이 API는 Zbus 기반의 단순 publish/subscribe system입니다.
Application의 subscriber thread는 publish된 event를 듣고 Zbus를 통해 subscriber extension에 다시 배포합니다. ext1, ext2, ext3는 각각 userspace에서 실행되며 semaphore, event 대기 thread 생성, publish·subscribe 같은 서로 다른 application·Zephyr API 사용법을 보여 줍니다. kext1은 ext3와 비슷하지만 kernel thread에서 실행됩니다.
Application은 extension마다 별도 memory domain을 만들어 어느 정도 격리합니다. 다만 kernel extension은 Zephyr kernel 전체에 접근할 수 있습니다. kext1은 EDK를 build할 때 CONFIG_LLEXT_EDK_USERSPACE_ONLY를 disable한 경우에만 제공됩니다.
Application과 EDK는 Zephyr build system으로 만들고 EDK는 llext-edk target으로 생성합니다. 압축을 푼 EDK를 사용해 extension은 CMake로 별도 build합니다. Sample은 편의를 위해 extension을 build time에 application에 포함하지만, 핵심 목적은 application과 무관한 별도 directory나 별도 machine, 별도 team에서도 EDK만으로 extension을 독립 개발할 수 있게 하는 것입니다.
EDK 빌드
qemu_cortex_r5 application을 항상 새로 구성하고 llext-edk target을 실행합니다.
west build -b qemu_cortex_r5 -p=always samples/subsys/llext/edk/app
west build -t llext-edk
생성된 build/zephyr/llext-edk.tar.xz를 원하는 위치에 복사해 풉니다.
mkdir /tmp/edk
cp build/zephyr/llext-edk.tar.xz /tmp/edk
cd /tmp/edk
tar -xf llext-edk.tar.xz
Extension이 EDK를 찾도록 압축을 푼 directory를 LLEXT_EDK_INSTALL_DIR에 설정합니다.
export LLEXT_EDK_INSTALL_DIR=/tmp/edk/llext-edk
Extension 빌드
Extension이 Zephyr SDK를 찾을 수 있도록 ZEPHYR_SDK_INSTALL_DIR가 올바르게 설정되어 있어야 합니다.
export ZEPHYR_SDK_INSTALL_DIR=</path/to/zephyr-sdk>
ext1, ext2, ext3, kext1 directory에서 CMake configure와 make를 실행합니다.
cmake -B build
make -C build
환경변수 대신 CMake 호출에 LLEXT_EDK_INSTALL_DIR를 직접 넘길 수도 있습니다.
cmake -B build -DLLEXT_EDK_INSTALL_DIR=/tmp/edk/llext-edk
make -C build
Application 빌드
Build한 extension을 포함해 application을 다시 build하고 QEMU에서 실행합니다.
west build -b qemu_cortex_r5 -p=always samples/subsys/llext/edk/app
west build -t run
출력은 subscriber thread 시작, privileged kernel extension kext1과 userspace extension ext1·ext2 loading, event 등록, tick_chan publish·read 흐름을 보여 줍니다. Address 값은 example run마다 달라질 수 있습니다.
[app]Subscriber thread [0x20b28] started.
[app]Loading extension [kext1].
[app]Thread 0x20840 created to run extension [kext1], at privileged mode.
[k-ext1]Waiting sem
[app]Thread [0x222a0] registered event [0x223c0]
[k-ext1]Waiting event
[app]Loading extension [ext1].
[app]Thread 0x20a30 created to run extension [ext1], at userspace.
[app]Thread [0x20a30] registered event [0x26060]
[ext1]Waiting event
[app]Loading extension [ext2].
[app]Thread 0x20938 created to run extension [ext2], at userspace.
[ext2]Publishing tick
[app][subscriber_thread]Got channel tick_chan
[ext1]Got event, reading channel
[ext1]Read val: 0
[ext1]Waiting event
[k-ext1]Got event, giving sem
[k-ext1]Got sem, reading channel
[k-ext1]Read val: 0
[k-ext1]Waiting sem
(...)
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.