1 /* 2 * Copyright (c) 2024 BayLibre SAS 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_LLEXT_FS_LOADER_H 8 #define ZEPHYR_LLEXT_FS_LOADER_H 9 10 #include <zephyr/llext/loader.h> 11 #include <zephyr/fs/fs.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * @file 19 * @brief LLEXT filesystem loader implementation. 20 * 21 * @addtogroup llext_loader_apis 22 * @{ 23 */ 24 25 /** 26 * @brief Implementation of @ref llext_loader that reads from a filesystem. 27 */ 28 struct llext_fs_loader { 29 /** Extension loader */ 30 struct llext_loader loader; 31 32 /** @cond ignore */ 33 bool is_open; 34 const char *name; 35 struct fs_file_t file; 36 /** @endcond */ 37 }; 38 39 /** @cond ignore */ 40 int llext_fs_prepare(struct llext_loader *ldr); 41 int llext_fs_read(struct llext_loader *ldr, void *buf, size_t len); 42 int llext_fs_seek(struct llext_loader *ldr, size_t pos); 43 void llext_fs_finalize(struct llext_loader *ldr); 44 /** @endcond */ 45 46 /** 47 * @brief Initializer for an llext_fs_loader structure 48 * 49 * @param _filename Absolute path to the extension file. 50 */ 51 #define LLEXT_FS_LOADER(_filename) \ 52 { \ 53 .loader = \ 54 { \ 55 .prepare = llext_fs_prepare, \ 56 .read = llext_fs_read, \ 57 .seek = llext_fs_seek, \ 58 .peek = NULL, \ 59 .finalize = llext_fs_finalize, \ 60 }, \ 61 .is_open = false, \ 62 .name = (_filename), \ 63 } 64 65 /** 66 * @} 67 */ 68 69 #ifdef __cplusplus 70 } 71 #endif 72 73 #endif /* ZEPHYR_LLEXT_FS_LOADER_H */ 74