|
| 1 | +.. _llext_modules: |
| 2 | + |
| 3 | +LLEXT Modules |
| 4 | +############# |
| 5 | + |
| 6 | +|SOF| support for loadable modules, using Zephyr LLEXT API. |
| 7 | + |
| 8 | +Zephyr LLEXT API |
| 9 | +**************** |
| 10 | + |
| 11 | +Please refer to https://docs.zephyrproject.org/latest/services/llext/index.html |
| 12 | +for detailed documentation. In short, the Zephyr Linkable Loadable Extensions |
| 13 | +(LLEXT) API implements support for run-time loading and unloading of ELF-format |
| 14 | +executable code and data. |
| 15 | + |
| 16 | +SOF Use of the LLEXT API |
| 17 | +************************ |
| 18 | + |
| 19 | +SOF has multiple ways to implement loadable modules. LLEXT is one of them. |
| 20 | +With it modules are built as shared or relocatable ELF objects with an addition |
| 21 | +of a cryptographic signature, using any user-supplied key, and a manifest. When |
| 22 | +loaded and instantiated, Zephyr LLEXT functionality is used to dynamically |
| 23 | +resolve module internal as well as SOF external code and data references. In the |
| 24 | +future support for inter-module linking will be added. |
| 25 | + |
| 26 | +Accessing the base firmware from LLEXT modules |
| 27 | +********************************************** |
| 28 | + |
| 29 | +LLEXT modules can access all code and data from the base firmware exported, |
| 30 | +using the ``EXPORT_SYMBOL()`` macro. Therefore writing LLEXT modules isn't very |
| 31 | +different from built-in ones. |
| 32 | + |
| 33 | +Implementing LLEXT modules |
| 34 | +************************** |
| 35 | + |
| 36 | +At the moment only modules, implementing the Module Adapter API |
| 37 | +:ref:`apps-comp-world` are supported. |
| 38 | + |
| 39 | +As explained above, LLEXT modules in general look very similar to native SOF |
| 40 | +code, with the only restriction of having no access to not-exported symbols. If |
| 41 | +any such symbols are needed to LLEXT modules, additionally exporting them can be |
| 42 | +considered. |
| 43 | + |
| 44 | +LLEXT modules should also contain a ``.buildinfo`` section, containing a |
| 45 | +``struct sof_module_api_build_info`` object and a ``.module`` section, |
| 46 | +containing a ``struct sof_man_module_manifest`` object. The latter should also |
| 47 | +contain a pointer to a module entry point function, returning a pointer to the |
| 48 | +module's ``struct module_interface`` instance. See |
| 49 | +src/samples/audio/smart_amp_test_ipc4.c for an example. |
| 50 | + |
| 51 | +A TOML configuration file is needed for building of LLEXT modules too. It is |
| 52 | +generated by the C preprocessor at build time from the same components, as would |
| 53 | +be used for a monolithic build. A small additional file to bring components |
| 54 | +together is needed too, similar to |
| 55 | +src/samples/audio/smart_amp_test_llext/llext.toml.h. |
| 56 | + |
| 57 | +Finally an additional CMakeLists.txt is needed similar to |
| 58 | +src/samples/audio/smart_amp_test_llext/CMakeLists.txt. Currently it contains a |
| 59 | +lot of open-coded instructions, later it will be ported to use Zephyr's |
| 60 | +``add_llext_target()`` function. |
| 61 | + |
| 62 | +With that in place, it is also possible to switch between monolithic and modular |
| 63 | +builds by specifying the module as "tristate" in its Kconfig and selecting "m" |
| 64 | +for modular builds, however, for modules, exclusively built as LLEXT objects, |
| 65 | +this might not be necessary. Thus it is possible to implement third party Module |
| 66 | +Adapter drivers, that would be built exclusively as loadable modules. |
| 67 | + |
| 68 | +Note, that a single LLEXT object file can also contain multiple Module Adapter |
| 69 | +modules. In that case an array of ``struct sof_module_api_build_info`` objects |
| 70 | +is needed and the TOML file should contain those multiple module entries too. |
| 71 | + |
| 72 | +Installation |
| 73 | +************ |
| 74 | + |
| 75 | +As specified in :ref:`intel_debug_introduction` the |SOF| Linux kernel driver |
| 76 | +loads SOF modules, using their UUIDs. For SOF internal modules the process |
| 77 | +of creation and installation of modules in a deployment tree is automated by the |
| 78 | +xtensa-build-zephyr.py script. |
0 commit comments