Skip to content

Commit e2e51df

Browse files
committed
wip: linked build
1 parent 03793bc commit e2e51df

File tree

13 files changed

+320
-75
lines changed

13 files changed

+320
-75
lines changed

boards.txt

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
menu.debug=Mode
1+
menu.mode=Mode
22

33
giga.name=Arduino Giga R1
44
giga.build.core=arduino
55
giga.build.crossprefix=arm-zephyr-eabi-
66
giga.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
77

8-
giga.menu.debug.false=Standard
9-
giga.menu.debug.true=Debug
8+
giga.menu.mode.llext=llext
9+
giga.menu.mode.linked=linked
1010

11-
giga.menu.debug.false.post_build_arg=
12-
giga.menu.debug.true.post_build_arg=debug
11+
giga.menu.mode.false.post_build_arg=
12+
giga.menu.mode.true.post_build_arg=debug
1313

1414
giga.build.variant=arduino_giga_r1_m7
1515
giga.build.mcu=cortex-m7
@@ -78,11 +78,11 @@ nano33ble.build.core=arduino
7878
nano33ble.build.crossprefix=arm-zephyr-eabi-
7979
nano33ble.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
8080

81-
nano33ble.menu.debug.false=Standard
82-
nano33ble.menu.debug.true=Debug
81+
nano33ble.menu.mode.false=Standard
82+
nano33ble.menu.mode.true=Debug
8383

84-
nano33ble.menu.debug.false.post_build_arg=
85-
nano33ble.menu.debug.true.post_build_arg=debug
84+
nano33ble.menu.mode.false.post_build_arg=
85+
nano33ble.menu.mode.true.post_build_arg=debug
8686

8787
nano33ble.build.variant=arduino_nano_33_ble_sense
8888
nano33ble.build.mcu=cortex-m4
@@ -148,11 +148,11 @@ ek_ra8d1.build.core=arduino
148148
ek_ra8d1.build.crossprefix=arm-zephyr-eabi-
149149
ek_ra8d1.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
150150

151-
ek_ra8d1.menu.debug.false=Standard
152-
ek_ra8d1.menu.debug.true=Debug
151+
ek_ra8d1.menu.mode.false=Standard
152+
ek_ra8d1.menu.mode.true=Debug
153153

154-
ek_ra8d1.menu.debug.false.post_build_arg=
155-
ek_ra8d1.menu.debug.true.post_build_arg=debug
154+
ek_ra8d1.menu.mode.false.post_build_arg=
155+
ek_ra8d1.menu.mode.true.post_build_arg=debug
156156

157157
ek_ra8d1.build.variant=ek_ra8d1
158158
ek_ra8d1.build.mcu=cortex-m85+nomve
@@ -214,11 +214,11 @@ frdm_mcxn947.build.core=arduino
214214
frdm_mcxn947.build.crossprefix=arm-zephyr-eabi-
215215
frdm_mcxn947.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
216216

217-
frdm_mcxn947.menu.debug.false=Standard
218-
frdm_mcxn947.menu.debug.true=Debug
217+
frdm_mcxn947.menu.mode.false=Standard
218+
frdm_mcxn947.menu.mode.true=Debug
219219

220-
frdm_mcxn947.menu.debug.false.post_build_arg=
221-
frdm_mcxn947.menu.debug.true.post_build_arg=debug
220+
frdm_mcxn947.menu.mode.false.post_build_arg=
221+
frdm_mcxn947.menu.mode.true.post_build_arg=debug
222222

223223
frdm_mcxn947.build.variant=frdm_mcxn947_mcxn947_cpu0
224224
frdm_mcxn947.build.mcu=cortex-m33
@@ -274,11 +274,11 @@ portentah7.build.core=arduino
274274
portentah7.build.crossprefix=arm-zephyr-eabi-
275275
portentah7.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
276276

277-
portentah7.menu.debug.false=Standard
278-
portentah7.menu.debug.true=Debug
277+
portentah7.menu.mode.false=Standard
278+
portentah7.menu.mode.true=Debug
279279

280-
portentah7.menu.debug.false.post_build_arg=
281-
portentah7.menu.debug.true.post_build_arg=debug
280+
portentah7.menu.mode.false.post_build_arg=
281+
portentah7.menu.mode.true.post_build_arg=debug
282282

283283
portentah7.build.variant=arduino_portenta_h7
284284
portentah7.build.mcu=cortex-m7
@@ -346,11 +346,11 @@ frdm_rw612.build.core=arduino
346346
frdm_rw612.build.crossprefix=arm-zephyr-eabi-
347347
frdm_rw612.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
348348

349-
frdm_rw612.menu.debug.false=Standard
350-
frdm_rw612.menu.debug.true=Debug
349+
frdm_rw612.menu.mode.false=Standard
350+
frdm_rw612.menu.mode.true=Debug
351351

352-
frdm_rw612.menu.debug.false.post_build_arg=
353-
frdm_rw612.menu.debug.true.post_build_arg=debug
352+
frdm_rw612.menu.mode.false.post_build_arg=
353+
frdm_rw612.menu.mode.true.post_build_arg=debug
354354

355355
frdm_rw612.build.variant=frdm_rw612
356356
frdm_rw612.build.mcu=cortex-m33+nodsp
@@ -405,11 +405,11 @@ niclasense.build.core=arduino
405405
niclasense.build.crossprefix=arm-zephyr-eabi-
406406
niclasense.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
407407

408-
niclasense.menu.debug.false=Standard
409-
niclasense.menu.debug.true=Debug
408+
niclasense.menu.mode.false=Standard
409+
niclasense.menu.mode.true=Debug
410410

411-
niclasense.menu.debug.false.post_build_arg=
412-
niclasense.menu.debug.true.post_build_arg=debug
411+
niclasense.menu.mode.false.post_build_arg=
412+
niclasense.menu.mode.true.post_build_arg=debug
413413

414414
niclasense.build.variant=arduino_nicla_sense_me
415415
niclasense.build.mcu=cortex-m4
@@ -481,11 +481,14 @@ portentac33.build.core=arduino
481481
portentac33.build.crossprefix=arm-zephyr-eabi-
482482
portentac33.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
483483

484-
portentac33.menu.debug.false=Standard
485-
portentac33.menu.debug.true=Debug
484+
portentac33.menu.mode.llext=llext
485+
portentac33.menu.mode.linked=linked
486486

487-
portentac33.menu.debug.false.post_build_arg=
488-
portentac33.menu.debug.true.post_build_arg=debug
487+
portentac33.menu.mode.linked.libc_ldflags=-lc -lm -lgcc -L{build.variant.path}
488+
portentac33.menu.mode.linked.llext_link_flags=
489+
portentac33.menu.mode.linked.build.suffix=noheader
490+
portentac33.menu.mode.linked.build.ldscript={runtime.platform.path}/variants/linked/linker_script.ld
491+
portentac33.menu.mode.linked.upload.externsion=bin
489492

490493
portentac33.build.variant=arduino_portenta_c33
491494
portentac33.build.mcu=cortex-m33
@@ -506,7 +509,7 @@ portentac33.compiler.zephyr.ldflags=-fno-exceptions -fno-rtti -fno-threadsafe-st
506509
portentac33.compiler.zephyr.cflags=-fno-strict-aliasing -fno-printf-return-value -fno-common -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop --specs=picolibc.specs -D_POSIX_THREADS -mlong-calls -nodefaultlibs
507510
portentac33.compiler.zephyr.cxxflags={compiler.zephyr.ldflags} -fdata-sections -ffunction-sections -fno-unwind-tables -fno-strict-aliasing -fno-printf-return-value -fno-common -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop --specs=picolibc.specs -D_POSIX_THREADS -mlong-calls -nodefaultlibs
508511
portentac33.compiler.zephyr.includes={build.variant.path}/includes.txt
509-
portentac33.compiler.zephyr.extra_ldflags=-lstdc++ -lsupc++ -lnosys -nostdlib
512+
portentac33.compiler.zephyr.extra_ldflags=-lstdc++ -lsupc++ -lnosys -nostdlib {libc_ldflags}
510513
portentac33.compiler.zephyr=
511514
portentac33.vid.0=0x2341
512515
portentac33.pid.0=0x0068

cores/arduino/main.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "Arduino.h"
8+
#include <cstdint>
89
#ifdef CONFIG_LLEXT
910
#include <zephyr/llext/symbol.h>
1011
#endif
@@ -36,4 +37,40 @@ int main(void) {
3637

3738
#ifdef CONFIG_LLEXT
3839
LL_EXTENSION_SYMBOL(main);
40+
#else
41+
42+
/* These magic symbols are provided by the linker. */
43+
extern void (*__preinit_array_start []) (void) __attribute__((weak));
44+
extern void (*__preinit_array_end []) (void) __attribute__((weak));
45+
extern void (*__init_array_start []) (void) __attribute__((weak));
46+
extern void (*__init_array_end []) (void) __attribute__((weak));
47+
48+
void __libc_init_array (void)
49+
{
50+
size_t count;
51+
size_t i;
52+
53+
count = __preinit_array_end - __preinit_array_start;
54+
for (i = 0; i < count; i++)
55+
__preinit_array_start[i] ();
56+
57+
count = __init_array_end - __init_array_start;
58+
for (i = 0; i < count; i++)
59+
__init_array_start[i] ();
60+
}
61+
62+
extern "C" __attribute__((section(".entry_point"), used)) void entry_point(k_thread_stack_t* stack, size_t stack_size) {
63+
// copy .data in the right place
64+
// .bss should already be in the right place
65+
// call constructors
66+
extern uintptr_t _sidata;
67+
extern uintptr_t _sdata;
68+
extern uintptr_t _edata;
69+
extern uintptr_t _sbss;
70+
extern uintptr_t _ebss;
71+
memcpy(&_sdata, &_sidata, &_edata - &_sdata);
72+
memset(&_sbss, 0, &_ebss - &_sbss);
73+
__libc_init_array();
74+
main();
75+
}
3976
#endif

extra/build.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ set -e
66

77
board=$1
88
variant=$2
9-
shield=$3
9+
third_arg=$3
10+
extra_args=""
1011

1112
if [[ $# -eq 0 ]]; then
1213
board=arduino_giga_r1//m7
@@ -15,13 +16,15 @@ fi
1516

1617
source venv/bin/activate
1718

18-
if [ -n "$shield" ]; then
19-
shield_arg="--shield $shield"
20-
else
21-
shield_arg=""
19+
if [ "$third_arg" != "linked" ]; then
20+
extra_args="--shield $shield"
2221
fi
2322

24-
(west build loader -b $board -p $shield_arg && west build -t llext-edk)
23+
if [ "$third_arg" == "linked" ]; then
24+
extra_args="-DCONF_FILE=boards/${1}_linked.conf"
25+
fi
26+
27+
(west build loader -b $board -p $extra_args && west build -t llext-edk)
2528
(tar xfp build/zephyr/llext-edk.tar.xz --directory variants/$variant/)
2629

2730
(cp build/zephyr/zephyr.elf firmwares/zephyr-$variant.elf)
@@ -31,3 +34,13 @@ elif [ -f build/zephyr/zephyr.hex ]; then
3134
cp build/zephyr/zephyr.hex firmwares/zephyr-$variant.hex
3235
fi
3336

37+
# Generate the provides.ld file for linked builds
38+
if [ "$third_arg" == "linked" ]; then
39+
echo "Exporting provides.ld"
40+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep FUNC | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' > variants/$variant/provides.ld
41+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep llext_stack | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld
42+
arm-none-eabi-readelf --wide -s build/zephyr/zephyr.elf | c++filt | grep llext_stack | awk -F' ' '{print "PROVIDE(llext_stack_size = "$3");"}' >> variants/$variant/provides.ld
43+
cat build/zephyr/zephyr.map | grep __device_dts_ord | grep -v rodata | awk -F' ' '{print "PROVIDE("$2" = "$1");"}' >> variants/$variant/provides.ld
44+
TEXT_START=`cat loader/boards/$variant.overlay | grep user_sketch: | cut -f2 -d"@" | cut -f1 -d"{"`
45+
echo "PROVIDE(_sketch_start = 0x$TEXT_START);" >> variants/$variant/provides.ld
46+
fi

loader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
88

99
project(app LANGUAGES C CXX)
1010

11-
include(${CMAKE_CURRENT_SOURCE_DIR}/blobs/CMakeLists.txt)
11+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/blobs)
1212

1313
FILE(GLOB app_sources *.c)
1414
target_sources(app PRIVATE ${app_sources})

loader/blobs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (CONFIG_BOARD_ARDUINO_PORTENTA_C33)
66
set(gen_dir ${gen_inc_dir}/c33_bl_patch)
77
generate_inc_file_for_target(
88
${ZEPHYR_CURRENT_LIBRARY}
9-
${CMAKE_CURRENT_SOURCE_DIR}/blobs/c33_bl.bin
9+
${CMAKE_CURRENT_SOURCE_DIR}/c33_bl.bin
1010
${gen_dir}/c33_bl.bin.inc
1111
)
1212
endif()

loader/boards/arduino_giga_r1_m7.overlay

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -331,29 +331,11 @@
331331
};
332332
};
333333

334-
/ {
335-
soc {
336-
flash-controller@52002000 {
337-
flash0: flash@8000000 {
338-
compatible = "st,stm32-nv-flash", "soc-nv-flash";
339-
write-block-size = <32>;
340-
erase-block-size = <DT_SIZE_K(128)>;
341-
/* maximum erase time for a 128K sector */
342-
max-erase-time = <4000>;
343-
344-
reg = <0x08000000 DT_SIZE_K(1024)>;
345-
status = "okay";
346-
347-
partitions {
348-
compatible = "fixed-partitions";
349-
#address-cells = <1>;
350-
#size-cells = <1>;
351-
352-
user_sketch: partition@e0000 {
353-
reg = <0x0E0000 0x20000>;
354-
};
355-
};
356-
};
334+
335+
&flash0 {
336+
partitions {
337+
user_sketch: partition@e0000 {
338+
reg = <0x0E0000 0x20000>;
357339
};
358340
};
359341
};

loader/boards/arduino_portenta_c33.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
pwm-pin-gpios = <&ioport6 0 0>;
7474

75-
serials = <&cdc_acm_uart0>,<&sci9>;
75+
serials = <&cdc_acm_uart0>,<&uart9>;
7676
cdc-acm = <&cdc_acm_uart0>;
7777
i2cs = <&iic1>;
7878
spis = <&spi1>;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
CONFIG_USB_DEVICE_STACK_NEXT=y
2+
CONFIG_USB_DEVICE_PRODUCT="Arduino Portenta C33"
3+
CONFIG_USB_DEVICE_MANUFACTURER="Arduino"
4+
CONFIG_USB_DEVICE_VID=0x2341
5+
CONFIG_USB_DEVICE_PID=0x0068
6+
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
7+
8+
CONFIG_LLEXT=n
9+
CONFIG_FLASH=y
10+
CONFIG_FLASH_MAP=y
11+
12+
CONFIG_SERIAL=y
13+
CONFIG_UART_LINE_CTRL=y
14+
CONFIG_USBD_CDC_ACM_CLASS=y
15+
CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y
16+
CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y
17+
18+
CONFIG_LLEXT_STORAGE_WRITABLE=n
19+
20+
CONFIG_FPU=y
21+
22+
CONFIG_USERSPACE=n
23+
CONFIG_ARM_MPU=n
24+
25+
CONFIG_SHELL_STACK_SIZE=32768
26+
CONFIG_MAIN_STACK_SIZE=32768
27+
CONFIG_LLEXT_HEAP_SIZE=128
28+
29+
CONFIG_ADC=n
30+
CONFIG_PWM=y
31+
32+
CONFIG_NET_CORE_LOG_LEVEL_DBG=y
33+
34+
CONFIG_NETWORKING=y
35+
CONFIG_NET_IPV6=n
36+
CONFIG_NET_IPV4=y
37+
CONFIG_NET_ARP=y
38+
CONFIG_NET_UDP=y
39+
CONFIG_NET_DHCPV4=y
40+
CONFIG_NET_DHCPV4_OPTION_CALLBACKS=y
41+
CONFIG_DNS_RESOLVER=y
42+
CONFIG_DNS_SERVER_IP_ADDRESSES=y
43+
CONFIG_DNS_SERVER1="8.8.8.8"
44+
45+
CONFIG_INIT_STACKS=y
46+
47+
CONFIG_NET_SOCKETS=y
48+
CONFIG_NET_SOCKETS_NET_MGMT=y
49+
#CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
50+
CONFIG_NET_MGMT=y
51+
CONFIG_NET_MGMT_EVENT=y
52+
CONFIG_NET_L2_ETHERNET=y
53+
CONFIG_NET_L2_ETHERNET_MGMT=y
54+
55+
CONFIG_NET_TX_STACK_SIZE=8192
56+
CONFIG_NET_RX_STACK_SIZE=8192
57+
CONFIG_NET_TCP_WORKQ_STACK_SIZE=8192
58+
CONFIG_NET_MGMT_EVENT_STACK_SIZE=8192
59+
CONFIG_NET_TCP=y
60+
CONFIG_NET_SOCKETS=y
61+
CONFIG_POSIX_API=y
62+
63+
#CONFIG_MBEDTLS=y
64+
#CONFIG_MBEDTLS_BUILTIN=y
65+
#CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
66+
#CONFIG_MBEDTLS_ENABLE_HEAP=y
67+
#CONFIG_MBEDTLS_HEAP_SIZE=60000
68+
#CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=7168
69+
#CONFIG_MBEDTLS_HASH_ALL_ENABLED=y
70+
#CONFIG_MBEDTLS_CMAC=y

loader/boards/arduino_portenta_h7_m7.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#address-cells = <1>;
5656
#size-cells = <1>;
5757

58-
user_sketch: partition@0 {
58+
user_sketch: partition@e0000 {
5959
reg = <0x0E0000 0x20000>;
6060
};
6161
};

loader/fixups.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int smh_init(void) {
102102
SYS_INIT(smh_init, POST_KERNEL, CONFIG_CLOCK_CONTROL_PWM_INIT_PRIORITY);
103103
#endif
104104

105-
#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_C33)
105+
#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_C33) && defined(CONFIG_LLEXT)
106106
#include <zephyr/kernel.h>
107107
#include <zephyr/storage/flash_map.h>
108108

0 commit comments

Comments
 (0)