Skip to content

Commit 0daaefe

Browse files
committed
linked: enforce maximum size of sketch in linker script
Stop the build when a sketch exceeds the maximum size defined by the 'user_sketch' node in the device tree. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent fa13ca1 commit 0daaefe

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

extra/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -LF \
9595
"+kheap_llext_heap" \
9696
"+kheap__system_heap" \
9797
"*sketch_base_addr=_sketch_start" \
98+
"*sketch_max_size=_sketch_max_size" \
9899
"malloc=__wrap_malloc" \
99100
"free=__wrap_free" \
100101
"realloc=__wrap_realloc" \

loader/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void llext_entry(void *arg0, void *arg1, void *arg2)
6666

6767
__attribute__((retain)) const uintptr_t sketch_base_addr = DT_REG_ADDR(DT_GPARENT(DT_NODELABEL(user_sketch))) +
6868
DT_REG_ADDR(DT_NODELABEL(user_sketch));
69+
__attribute__((retain)) const uintptr_t sketch_max_size = DT_REG_SIZE(DT_NODELABEL(user_sketch));
6970

7071
static int loader(const struct shell *sh)
7172
{

variants/_linked/linker_script.ld

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
INCLUDE "provides.ld"
22

3-
PROVIDE(TEXT_LENGTH = 0x100000);
4-
53
MEMORY
64
{
7-
FLASH (rx) : ORIGIN = _sketch_start + 16, LENGTH = TEXT_LENGTH
5+
/* 16 below compensates for the zsk header that is added before the .bin */
6+
FLASH (rx) : ORIGIN = _sketch_start + 16, LENGTH = _sketch_max_size - 16
87
RAM (rwx) : ORIGIN = kheap_llext_heap, LENGTH = kheap_llext_heap_size
98
}
109

@@ -117,4 +116,4 @@ SECTIONS {
117116
.got : {
118117
KEEP(*(.got .got.* .got.plt .got.plt*))
119118
}
120-
}
119+
}

0 commit comments

Comments
 (0)