1 /* 2 * Copyright (c) 2024 Arduino SA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL 8 #include <zephyr/logging/log.h> 9 LOG_MODULE_REGISTER(app); 10 11 #include <zephyr/llext/llext.h> 12 #include <zephyr/llext/buf_loader.h> 13 14 static uint8_t llext_buf[] = { 15 #include "hello_world_ext.inc" 16 }; 17 main(void)18int main(void) 19 { 20 LOG_INF("Calling hello world as a module"); 21 22 size_t llext_buf_len = ARRAY_SIZE(llext_buf); 23 struct llext_buf_loader buf_loader = LLEXT_BUF_LOADER(llext_buf, llext_buf_len); 24 struct llext_loader *ldr = &buf_loader.loader; 25 26 struct llext_load_param ldr_parm = LLEXT_LOAD_PARAM_DEFAULT; 27 struct llext *ext; 28 int res; 29 30 res = llext_load(ldr, "ext", &ext, &ldr_parm); 31 if (res != 0) { 32 LOG_ERR("Failed to load extension, return code %d\n", res); 33 return res; 34 } 35 36 void (*hello_world_fn)() = llext_find_sym(&ext->exp_tab, "hello_world"); 37 38 if (hello_world_fn == NULL) { 39 LOG_ERR("Failed to find symbol\n"); 40 return -1; 41 } 42 43 hello_world_fn(); 44 45 return llext_unload(&ext); 46 } 47