Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (CONFIG_ARDUINO_API)
endif()
endif()

if (CONFIG_ARDUINO_API AND NOT CONFIG_LLEXT)
if (CONFIG_ARDUINO_API AND NOT CONFIG_LLEXT_EDK)
add_subdirectory(cores)
add_subdirectory(libraries)
zephyr_include_directories(${variant_dir})
Expand Down
6 changes: 3 additions & 3 deletions cores/arduino/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ extern "C" __attribute__((section(".entry_point"), used)) void entry_point(struc
extern uintptr_t _ebss;
extern uintptr_t __heap_start;
extern uintptr_t __heap_end;
extern uintptr_t kheap_llext_heap;
extern uintptr_t kheap_llext_heap_size;
extern uintptr_t kheap__sketch_heap;
extern uintptr_t kheap__sketch_heap_size;

//__asm volatile ("cpsie i");

printk("System Heap end: %p\n", &__heap_end);
printk("System Heap start: %p\n", &__heap_start);
printk("Sketch Heap start: %p, size %p\n", &kheap_llext_heap, &kheap_llext_heap_size);
printk("Sketch Heap start: %p, size %p\n", &kheap__sketch_heap, &kheap__sketch_heap_size);

memcpy(&_sdata, &_sidata, (&_edata - &_sdata) * sizeof(uint32_t));
memset(&_sbss, 0, (&_ebss - &_sbss) * sizeof(uint32_t));
Expand Down
13 changes: 10 additions & 3 deletions extra/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ cp ${BUILD_DIR}/zephyr/zephyr.dts firmwares/zephyr-$variant.dts
cp ${BUILD_DIR}/zephyr/.config firmwares/zephyr-$variant.config

# Generate the provides.ld file for linked builds
echo "Generating exported symbol scripts"
extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -L > ${VARIANT_DIR}/syms-dynamic.ld
echo "Generating exported symbol scripts for dynamic builds"
extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -L \
"kheap_llext_heap=kheap__sketch_heap" \
"kheap_llext_heap_size=kheap__sketch_heap_size" > ${VARIANT_DIR}/syms-dynamic.ld

echo "Generating exported symbol scripts for static builds"
extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -LF \
"+kheap_llext_heap" \
-R '__device_dts_ord_\d+' \
"+kheap__sketch_heap" \
"+kheap__system_heap" \
"kheap_llext_heap=kheap__sketch_heap" \
"kheap_llext_heap_size=kheap__sketch_heap_size" \
"*sketch_base_addr=_sketch_start" \
"*sketch_max_size=_sketch_max_size" \
"*loader_max_size=_loader_max_size" \
Expand Down
10 changes: 8 additions & 2 deletions extra/gen_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def main():
argparser.add_argument('-F', '--funcs',
action='store_true',
help='Extract all public functions')
argparser.add_argument('-R', '--regexp',
action='append',
default=[],
help='Extract all public symbols matching regexp')
argparser.add_argument('file',
help='ELF file to parse')
argparser.add_argument('syms', nargs='*',
Expand Down Expand Up @@ -198,6 +202,9 @@ def main():
llext_sym_addr = sym['st_value']
name = get_str_at(elf, get_ptr_at(elf, llext_sym_addr))
value = get_ptr_at(elf, llext_sym_addr + NativePtr.length)
elif args.regexp and any(map(lambda x: re.match(x, name), args.regexp)):
comment = "regexp_sym"
value = sym['st_value']

if name in deref_syms:
value = get_ptr_at(elf, value)
Expand All @@ -221,8 +228,7 @@ def main():
out_syms[name + "_size"] = (sym['st_size'], [f"size of {name}"])

if not out_syms:
sys.stderr.write("No symbols found matching the criteria.\n")
fail = True
sys.stderr.write("Warning: No symbols found matching the criteria.\n")

if fail:
sys.exit(1)
Expand Down
1 change: 1 addition & 0 deletions loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ target_sources(app PRIVATE ${app_sources})
target_compile_definitions(app PUBLIC _XOPEN_SOURCE=700)

target_link_libraries(app PUBLIC blobs)

10 changes: 10 additions & 0 deletions loader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# SPDX-License-Identifier: Apache-2.0
#

config LLEXT_HEAP_SIZE
int
default SKETCH_HEAP_SIZE

source "Kconfig.zephyr"

config LLEXT_HEAP_REGION
Expand All @@ -17,3 +21,9 @@ config MAIN_STACK_REGION
depends on CODE_DATA_RELOCATION
help
Specify the memory region for main stack.

config SKETCH_HEAP_SIZE
int "Sketch heap size in KB"
default 32
help
Specify the size in KB for the sketch heap
19 changes: 11 additions & 8 deletions loader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ __attribute__((retain)) const uintptr_t sketch_max_size = DT_REG_SIZE(DT_NODELAB
#endif
__attribute__((retain)) const uintptr_t loader_max_size = LOADER_MAX_SIZE;

#ifdef CONFIG_LLEXT
extern struct k_heap llext_heap;
#define SKETCH_HEAP llext_heap
#else
K_HEAP_DEFINE(_sketch_heap, CONFIG_SKETCH_HEAP_SIZE << 10);
#define SKETCH_HEAP _sketch_heap
#endif

static int loader(const struct shell *sh) {
const struct flash_area *fa;
int rc;
Expand Down Expand Up @@ -266,16 +274,15 @@ static int loader(const struct shell *sh) {
#endif
#endif

extern struct k_heap llext_heap;
typedef void (*entry_point_t)(struct k_heap *heap, size_t heap_size);
entry_point_t entry_point = (entry_point_t)(base_addr + HEADER_LEN + 1);
entry_point(&llext_heap, llext_heap.heap.init_bytes);
entry_point(&SKETCH_HEAP, CONFIG_SKETCH_HEAP_SIZE << 10);
// should never reach here
for (;;) {
k_sleep(K_FOREVER);
}
}

#ifdef CONFIG_LLEXT
#if defined(CONFIG_LLEXT_STORAGE_WRITABLE)
uint8_t *sketch_buf = k_aligned_alloc(4096, sketch_buf_len);

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

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

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

#ifdef CONFIG_USERSPACE
/*
Expand Down Expand Up @@ -350,12 +355,10 @@ static int loader(const struct shell *sh) {
k_thread_join(&llext_thread, K_FOREVER);
#else

#ifdef CONFIG_LLEXT
llext_bootstrap(ext, main_fn, NULL);
#endif

#endif

#endif // CONFIG_LLEXT
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions loader/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CONFIG_LLEXT_EXPORT_DEVICES=y
CONFIG_LLEXT_RODATA_NO_RELOC=y

CONFIG_LLEXT_EDK=y
CONFIG_LLEXT_EDK_EXPORT_SYMS=y
CONFIG_LLEXT_EDK_FORMAT_TAR_ZSTD=y

CONFIG_GPIO=y
Expand Down
4 changes: 2 additions & 2 deletions variants/_ldscripts/memory-check.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ PROVIDE(__heap_end = 0x50000000);
PROVIDE(kheap__system_heap = 0x40000000);
PROVIDE(kheap__system_heap_size = 0x10000000);

PROVIDE(kheap_llext_heap = 0x60000000);
PROVIDE(kheap_llext_heap_size = 0x10000000);
PROVIDE(kheap__sketch_heap = 0x60000000);
PROVIDE(kheap__sketch_heap_size = 0x10000000);
2 changes: 1 addition & 1 deletion variants/_ldscripts/memory-static.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MEMORY
{
/* 16 below compensates for the zsk header that is added before the .bin */
FLASH (rx) : ORIGIN = _sketch_start + 16, LENGTH = _sketch_max_size - 16
RAM (rwx) : ORIGIN = kheap_llext_heap, LENGTH = kheap_llext_heap_size
RAM (rwx) : ORIGIN = kheap__sketch_heap, LENGTH = kheap__sketch_heap_size
}

PROVIDE(__heap_start = kheap__system_heap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CONFIG_PWM=y

CONFIG_LLEXT_STORAGE_WRITABLE=n
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_LLEXT_HEAP_SIZE=128
CONFIG_SKETCH_HEAP_SIZE=128
CONFIG_MAIN_STACK_SIZE=16384

CONFIG_FPU=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

CONFIG_MAIN_STACK_SIZE=16000
CONFIG_HEAP_MEM_POOL_SIZE=112000
CONFIG_LLEXT_HEAP_SIZE=64
CONFIG_SKETCH_HEAP_SIZE=64
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_FPU=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ CONFIG_ADC=y

CONFIG_LLEXT_STORAGE_WRITABLE=n
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_LLEXT_HEAP_SIZE=15
CONFIG_SKETCH_HEAP_SIZE=15
CONFIG_MAIN_STACK_SIZE=2048
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONFIG_LOG_BACKEND_UART_AUTOSTART=n
CONFIG_LOG_DEFAULT_LEVEL=2

CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=128
CONFIG_SKETCH_HEAP_SIZE=128
CONFIG_HEAP_MEM_POOL_SIZE=32768
CONFIG_ISR_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CONFIG_ARM_MPU=y
CONFIG_MAX_THREAD_BYTES=4

CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=128
CONFIG_SKETCH_HEAP_SIZE=128

CONFIG_CODE_DATA_RELOCATION=y
CONFIG_MAIN_STACK_REGION="DTCM"
Expand Down
Loading