Skip to content

Commit 3416a2a

Browse files
llext: adding missing heap when llext is disabled
When CONFIG_LLEXT=n llext_heap is not defined, thus raising compile time error when compiling with that option disabled. NOTE that the only way to use a sketch with a loader compiled with llext disabled is to use static linkage mode. This could help save up some space. Signed-off-by: Andrea Gilardoni <a.gilardoni@arduino.cc>
1 parent 2136da3 commit 3416a2a

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

loader/main.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ __attribute__((retain)) const uintptr_t sketch_max_size = DT_REG_SIZE(DT_NODELAB
110110
#endif
111111
__attribute__((retain)) const uintptr_t loader_max_size = LOADER_MAX_SIZE;
112112

113+
#ifdef CONFIG_LLEXT
114+
extern struct k_heap llext_heap;
115+
#define SKETCH_HEAP llext_heap
116+
#else
117+
K_HEAP_DEFINE(_sketch_heap, CONFIG_SKETCH_HEAP_SIZE << 10);
118+
#define SKETCH_HEAP _sketch_heap
119+
#endif
120+
113121
static int loader(const struct shell *sh) {
114122
const struct flash_area *fa;
115123
int rc;
@@ -266,16 +274,15 @@ static int loader(const struct shell *sh) {
266274
#endif
267275
#endif
268276

269-
extern struct k_heap llext_heap;
270277
typedef void (*entry_point_t)(struct k_heap *heap, size_t heap_size);
271278
entry_point_t entry_point = (entry_point_t)(base_addr + HEADER_LEN + 1);
272-
entry_point(&llext_heap, llext_heap.heap.init_bytes);
279+
entry_point(&SKETCH_HEAP, CONFIG_SKETCH_HEAP_SIZE << 10);
273280
// should never reach here
274281
for (;;) {
275282
k_sleep(K_FOREVER);
276283
}
277284
}
278-
285+
#ifdef CONFIG_LLEXT
279286
#if defined(CONFIG_LLEXT_STORAGE_WRITABLE)
280287
uint8_t *sketch_buf = k_aligned_alloc(4096, sketch_buf_len);
281288

@@ -294,7 +301,6 @@ static int loader(const struct shell *sh) {
294301
uint8_t *sketch_buf = (uint8_t *)base_addr;
295302
#endif
296303

297-
#ifdef CONFIG_LLEXT
298304
struct llext_buf_loader buf_loader = LLEXT_BUF_LOADER(sketch_buf, sketch_buf_len);
299305
struct llext_loader *ldr = &buf_loader.loader;
300306

@@ -315,7 +321,6 @@ static int loader(const struct shell *sh) {
315321
printk("Failed to find main function\n");
316322
return -ENOENT;
317323
}
318-
#endif
319324

320325
#ifdef CONFIG_USERSPACE
321326
/*
@@ -350,12 +355,10 @@ static int loader(const struct shell *sh) {
350355
k_thread_join(&llext_thread, K_FOREVER);
351356
#else
352357

353-
#ifdef CONFIG_LLEXT
354358
llext_bootstrap(ext, main_fn, NULL);
355359
#endif
356360

357-
#endif
358-
361+
#endif // CONFIG_LLEXT
359362
return 0;
360363
}
361364

0 commit comments

Comments
 (0)