Skip to content
Open
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
12 changes: 6 additions & 6 deletions extra/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ else
args="$*"
fi

# Check for debug flag and append
if [ x$2 == x"--debug" ]; then
args="$args -- -DEXTRA_CONF_FILE=../extra/debug.conf"
fi

echo
echo "Build target: $target $args"

Expand Down Expand Up @@ -99,11 +104,6 @@ extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -LF \
"+kheap_llext_heap" \
"+kheap__system_heap" \
"*sketch_base_addr=_sketch_start" \
"*sketch_max_size=_sketch_max_size" \
"malloc=__wrap_malloc" \
"free=__wrap_free" \
"realloc=__wrap_realloc" \
"calloc=__wrap_calloc" \
"random=__wrap_random" > ${VARIANT_DIR}/syms-static.ld
"*sketch_max_size=_sketch_max_size" > ${VARIANT_DIR}/syms-static.ld

cmake -P extra/gen_arduino_files.cmake $variant
29 changes: 29 additions & 0 deletions extra/debug.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: Apache-2.0
# Debug configuration for Arduino Core Zephyr

# Enable debug mode
CONFIG_DEBUG=y

# Enable assertions
CONFIG_ASSERT=y
#CONFIG_ASSERT_VERBOSE=y

# Enable stack overflow detection
CONFIG_STACK_SENTINEL=y
CONFIG_STACK_CANARIES=y

# Enable thread monitoring
CONFIG_THREAD_MONITOR=y
CONFIG_THREAD_NAME=y

# Disable compiler optimizations
#CONFIG_DEBUG_OPTIMIZATIONS=y

# Enable and configure the shell
CONFIG_SHELL=y
#CONFIG_NET_SHELL=y
#CONFIG_NET_L2_WIFI_SHELL=y
CONFIG_SHELL_STACK_SIZE=8192

# Enable heap runtime statistics for kernel heap command
CONFIG_SYS_HEAP_RUNTIME_STATS=y
8 changes: 8 additions & 0 deletions loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ FILE(GLOB app_sources *.c)
target_sources(app PRIVATE ${app_sources})
target_compile_definitions(app PUBLIC _XOPEN_SOURCE=700)

# Wrap malloc, free, calloc and realloc
zephyr_ld_options(
-Wl,--wrap=malloc
-Wl,--wrap=free
-Wl,--wrap=calloc
-Wl,--wrap=realloc
)

target_link_libraries(app PUBLIC blobs)
7 changes: 7 additions & 0 deletions loader/fixups.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include <cmsis_core.h>
#include <zephyr/init.h>

#ifndef CONFIG_CPP
void __cxa_pure_virtual() {
while (1)
;
}
#endif

int disable_mpu_rasr_xn(void) {
uint32_t index;
/* Kept the max index as 8(irrespective of soc) because the sram
Expand Down
8 changes: 5 additions & 3 deletions loader/llext_exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ EXPORT_SYMBOL(usb_enable);
EXPORT_SYMBOL(usb_disable);
#endif

#if CONFIG_LOG
EXPORT_SYMBOL(z_log_msg_runtime_vcreate);
FORCE_EXPORT_SYM(log_const_sketch)
#endif

#if defined(CONFIG_LOG_RUNTIME_FILTERING)
FORCE_EXPORT_SYM(log_dynamic_sketch)
#endif

#if defined(CONFIG_NETWORKING)
FORCE_EXPORT_SYM(net_if_foreach);
Expand Down Expand Up @@ -271,10 +276,7 @@ FORCE_EXPORT_SYM(__aeabi_idivmod);
FORCE_EXPORT_SYM(__aeabi_ldivmod);
FORCE_EXPORT_SYM(__aeabi_ul2f);
FORCE_EXPORT_SYM(__aeabi_dcmpge);

#if defined (CONFIG_CPP)
FORCE_EXPORT_SYM(__cxa_pure_virtual);
#endif

#if defined(CONFIG_BOARD_ARDUINO_UNO_Q)
FORCE_EXPORT_SYM(matrixBegin);
Expand Down
25 changes: 25 additions & 0 deletions loader/malloc_wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2025 Arduino SA
*
* SPDX-License-Identifier: Apache-2.0
*
* Wrapper to redirect malloc/free to k_malloc/k_free using ld --wrap
*/

#include <zephyr/kernel.h>

void *__wrap_malloc(size_t size) {
return k_malloc(size);
}

void __wrap_free(void *ptr) {
k_free(ptr);
}

void *__wrap_calloc(size_t nmemb, size_t size) {
return k_calloc(nmemb, size);
}

void *__wrap_realloc(void *ptr, size_t size) {
return k_realloc(ptr, size);
}
2 changes: 1 addition & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ build.combine_command={build.link_command} {build.link_args.build-{build.link_mo

# link_args.* are included by any link_command depending on the link_mode
build.link_args.dynamic=-e main
build.link_args.static=-lc -lm -lgcc -Wl,--wrap=random -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=malloc -Wl,--wrap=realloc
build.link_args.static=-lc -lm -lgcc

# link_args.check-* are used to check the build. Only LLEXT needs these to emulate a static build (no -r!).
build.link_args.check-dynamic="-T{build.variant.path}/syms-dynamic.ld" "-T{build.ldscript.path}/memory-check.ld" "-T{build.ldscript.path}/build-static.ld"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y

CONFIG_LLEXT_STORAGE_WRITABLE=n
CONFIG_SHARED_MULTI_HEAP=y
CONFIG_HEAP_MEM_POOL_SIZE=24576
CONFIG_SHELL_STACK_SIZE=32768
CONFIG_HEAP_MEM_POOL_SIZE=102400
CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=128
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0

CONFIG_FPU=y
CONFIG_CPP=n
CONFIG_SHELL=n

CONFIG_FPU=y
CONFIG_ADC=y
CONFIG_DAC=y
CONFIG_PWM=y
Expand All @@ -39,13 +41,12 @@ CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=60000
CONFIG_MBEDTLS_HEAP_SIZE=80000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
CONFIG_MBEDTLS_CMAC=y

CONFIG_VIDEO=y
CONFIG_VIDEO_LOG_LEVEL_DBG=y
CONFIG_VIDEO_STM32_DCMI=y
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=3
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=614400
Expand Down Expand Up @@ -134,7 +135,4 @@ CONFIG_DNS_SERVER1="8.8.8.8"
CONFIG_NET_CONFIG_AUTO_INIT=n
CONFIG_NET_CONNECTION_MANAGER=y
#CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2

CONFIG_NET_SHELL=y
CONFIG_NET_L2_ETHERNET_MGMT=y
CONFIG_NET_L2_WIFI_SHELL=y
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ CONFIG_USBD_LOG_LEVEL_ERR=y
CONFIG_LLEXT_STORAGE_WRITABLE=n

CONFIG_FPU=y

CONFIG_USERSPACE=n
CONFIG_ARM_MPU=n

CONFIG_SHELL_STACK_SIZE=8192
CONFIG_CPP=n
CONFIG_SHELL=n

CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=128
CONFIG_HEAP_MEM_POOL_SIZE=32768
CONFIG_HEAP_MEM_POOL_SIZE=51200
CONFIG_ISR_STACK_SIZE=8192
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=8192
CONFIG_IDLE_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0

CONFIG_ADC=y
CONFIG_PWM=y

CONFIG_NET_CORE_LOG_LEVEL_DBG=y

CONFIG_NETWORKING=y
CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y
Expand Down Expand Up @@ -74,7 +74,7 @@ CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=60000
CONFIG_MBEDTLS_HEAP_SIZE=80000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
CONFIG_MBEDTLS_CMAC=y
Expand All @@ -85,7 +85,6 @@ CONFIG_NANOPB=y
CONFIG_NET_CONFIG_AUTO_INIT=n
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
CONFIG_NET_L2_WIFI_SHELL=y
CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=32

CONFIG_NET_IF_MAX_IPV4_COUNT=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ CONFIG_UART_LINE_CTRL=y
CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y

CONFIG_LLEXT_STORAGE_WRITABLE=n

CONFIG_SHARED_MULTI_HEAP=y
CONFIG_HEAP_MEM_POOL_SIZE=65536
CONFIG_HEAP_MEM_POOL_SIZE=143360
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0

CONFIG_CPP=n
CONFIG_SHELL=n

CONFIG_FPU=y
CONFIG_ICACHE=y
Expand All @@ -23,7 +26,6 @@ CONFIG_USERSPACE=n
CONFIG_ARM_MPU=y
CONFIG_MAX_THREAD_BYTES=4

CONFIG_SHELL_STACK_SIZE=32768
CONFIG_MAIN_STACK_SIZE=32768
CONFIG_LLEXT_HEAP_SIZE=128

Expand All @@ -40,13 +42,10 @@ CONFIG_SDHC_INIT_PRIORITY=75
CONFIG_SDIO_STACK=y
CONFIG_CYW4343W=y
CONFIG_WIFI=y
CONFIG_NET_L2_WIFI_SHELL=y

CONFIG_AIROC_WIFI_CUSTOM=y
CONFIG_STM32_MEMMAP=y

CONFIG_NET_CORE_LOG_LEVEL_DBG=y

CONFIG_NETWORKING=y
CONFIG_NET_IPV6=n
CONFIG_NET_IPV4=y
Expand Down Expand Up @@ -82,13 +81,12 @@ CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=60000
CONFIG_MBEDTLS_HEAP_SIZE=80000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
CONFIG_MBEDTLS_CMAC=y

CONFIG_VIDEO=y
CONFIG_VIDEO_LOG_LEVEL_DBG=y
CONFIG_VIDEO_STM32_DCMI=y
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=3
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=614400
Expand Down