Part 1
요약·해설
User memory domain 추가, llext_find_sym cast, unload lifetime과 DEBUG·MMU/MPU·GDB 조사 절차를 설명합니다.
llext_loader
llext_find_sym
llext_unload
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
A4EF8348A33A8840E2D72660B37084078B33B6E2F2554B87D5D29DE7D952E39D
Loading extensions
##################
Once an extension is built and the ELF file is available, it can be loaded into
the Zephyr application using the LLEXT API, which provides a way to load the
extension into memory, access its symbols and call its functions.
Loading an extension
====================
An extension may be loaded using any implementation of a :c:struct:`llext_loader`
which has a set of function pointers that provide the necessary functionality
to read the ELF data. A loader also provides some minimal context (memory)
needed by the :c:func:`llext_load` function. An implementation over a buffer
containing an ELF in addressable memory in memory is available as
:c:struct:`llext_buf_loader`.
The extensions are loaded with a call to the :c:func:`llext_load` function,
passing in the extension name and the configured loader. Once that completes
successfully, the extension is loaded into memory and is ready to be used.
.. note::
When :ref:`User Mode <usermode_api>` is enabled, the extension will not be
included in any user memory domain. To allow access from user mode, the
:c:func:`llext_add_domain` function must be called.
Accessing code and data
=======================
To interact with the newly loaded extension, the host application must use the
:c:func:`llext_find_sym` function to get the address of the exported symbol.
The returned ``void *`` can then be cast to the appropriate type and used.
A wrapper for calling a function with no arguments is provided in
:c:func:`llext_call_fn`.
Cleaning up after use
=====================
The :c:func:`llext_unload` function must be called to free the memory used by
the extension once it is no longer required. After this call completes, all
pointers to symbols in the extension that were obtained will be invalid.
Troubleshooting
###############
This feature is being actively developed and as such it is possible that some
issues may arise. Since linking does modify the binary code, in case of errors
the results are difficult to predict. Some common issues may be:
* Results from :c:func:`llext_find_sym` point to an invalid address;
* Constants and variables defined in the extension do not have the expected
values;
* Calling a function defined in an extension results in a hard fault, or memory
in the main application is corrupted after returning from it.
If any of this happens, the following tips may help understand the issue:
* Make sure :kconfig:option:`CONFIG_LLEXT_LOG_LEVEL` is set to ``DEBUG``, then
obtain a log of the :c:func:`llext_load` invocation.
* If possible, disable memory protection (MMU/MPU) and see if this results in
different behavior.
* Try to simplify the extension to the minimum possible code that reproduces
the issue.
* Use a debugger to inspect the memory and registers to try to understand what
is happening.
.. note::
When using GDB, the ``add_symbol_file`` command may be used to load the
debugging information and symbols from the ELF file. Make sure to specify
the proper offset (usually the start of the ``.text`` section, reported
as ``region 0`` in the debug logs.)
If the issue persists, please open an issue in the GitHub repository, including
all the above information.
Part 3
한국어 전문 번역
Extension을 build해 ELF file이 준비되면 LLEXT API로 Zephyr application memory에 load하고 symbol에 접근해 function을 호출할 수 있습니다.
Extension load
Extension은 llext_loader implementation이라면 어느 것이든 사용해 load할 수 있습니다. Loader에는 ELF data를 읽는 데 필요한 function pointer 묶음과 llext_load()에 필요한 최소 context memory가 있습니다. Addressable memory의 ELF buffer를 읽는 implementation으로 llext_buf_loader가 제공됩니다.
Extension name과 configured loader를 llext_load()에 전달합니다. 호출이 성공하면 extension이 memory에 올라가 사용할 준비가 됩니다.
Code와 data 접근
Host application은 llext_find_sym()으로 exported symbol address를 얻어 extension과 상호작용합니다. 반환된 void *를 알맞은 type으로 cast해 사용합니다.
Argument 없는 function을 호출하는 wrapper로 llext_call_fn()이 제공됩니다.
사용 후 정리
Extension이 더 이상 필요하지 않으면 llext_unload()를 호출해 사용한 memory를 해제해야 합니다. 호출이 끝나면 이전에 얻은 extension symbol pointer는 모두 invalid가 됩니다.
Troubleshooting
LLEXT는 활발히 개발 중이며 linking이 binary code를 수정하므로 오류 결과를 예측하기 어려울 수 있습니다. 흔한 증상은 다음과 같습니다.
llext_find_sym()결과가 invalid address를 가리킵니다.- Extension에서 정의한 constant와 variable 값이 예상과 다릅니다.
- Extension function 호출이 hard fault를 일으키거나 return 뒤 main application memory가 손상됩니다.
문제가 생기면 다음 순서로 조사합니다.
CONFIG_LLEXT_LOG_LEVEL=DEBUG로 설정하고llext_load()호출 log를 확보합니다.- 가능하면 memory protection(MMU/MPU)을 끄고 동작 차이가 있는지 확인합니다.
- 문제를 재현하는 최소 code까지 extension을 줄입니다.
- Debugger로 memory와 register를 조사합니다.
문제가 계속되면 위 정보를 모두 포함해 Zephyr GitHub repository에 issue를 등록합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.