|
1 |
| -if [ x$ZEPHYR_SDK_INSTALL_DIR == x"" ]; then |
2 |
| -export ZEPHYR_SDK_INSTALL_DIR=/ssd/zephyr-sdk-0.16.8/ |
3 |
| -fi |
| 1 | +#!/bin/bash |
4 | 2 |
|
5 | 3 | set -e
|
6 | 4 |
|
7 |
| -board=$1 |
8 |
| -variant=$2 |
9 |
| -third_arg=$3 |
10 |
| -extra_args="" |
| 5 | +if [ x$ZEPHYR_SDK_INSTALL_DIR == x"" ]; then |
| 6 | + SDK_PATH=$(west sdk list | grep path | tail -n 1 | cut -d ':' -f 2 | tr -d ' ') |
| 7 | + if [ x$SDK_PATH == x ]; then |
| 8 | + echo "ZEPHYR_SDK_INSTALL_DIR not set and no SDK found" |
| 9 | + exit 1 |
| 10 | + fi |
| 11 | + echo "ZEPHYR_SDK_INSTALL_DIR not set, using $SDK_PATH" |
| 12 | + export ZEPHYR_SDK_INSTALL_DIR=${SDK_PATH} |
| 13 | +fi |
11 | 14 |
|
12 | 15 | if [[ $# -eq 0 ]]; then
|
13 |
| -board=arduino_giga_r1//m7 |
14 |
| -variant=arduino_giga_r1_m7 |
| 16 | + board=arduino_giga_r1//m7 |
| 17 | +else |
| 18 | + board=$1 |
| 19 | + shift |
15 | 20 | fi
|
16 | 21 |
|
17 | 22 | source venv/bin/activate
|
18 | 23 |
|
19 |
| -if [ "$third_arg" != "" ]; then |
20 |
| - extra_args="--shield $third_arg" |
21 |
| -fi |
| 24 | +ZEPHYR_BASE=$(west topdir)/zephyr |
22 | 25 |
|
23 |
| -(west build loader -b $board -p $extra_args && west build -t llext-edk) |
24 |
| -(tar xfp build/zephyr/llext-edk.tar.xz --directory variants/$variant/) |
| 26 | +# Get the variant name (NORMALIZED_BOARD_TARGET in Zephyr) |
| 27 | +tmpdir=$(mktemp -d) |
| 28 | +variant=$(cmake -DBOARD=$board -P extra/get_variant_name.cmake | grep 'VARIANT=' | cut -d '=' -f 2) |
| 29 | +rm -rf ${tmpdir} |
25 | 30 |
|
26 |
| -(cp build/zephyr/zephyr.elf firmwares/zephyr-$variant.elf) |
27 |
| -if [ -f build/zephyr/zephyr.bin ]; then |
28 |
| - cp build/zephyr/zephyr.bin firmwares/zephyr-$variant.bin |
29 |
| -elif [ -f build/zephyr/zephyr.hex ]; then |
30 |
| - cp build/zephyr/zephyr.hex firmwares/zephyr-$variant.hex |
| 31 | +if [ -z "${variant}" ] ; then |
| 32 | + echo "Failed to get variant name from '$board'" |
| 33 | + exit 1 |
31 | 34 | fi
|
32 | 35 |
|
| 36 | +echo && echo && echo |
| 37 | +echo ${variant} |
| 38 | +echo ${variant} | sed -e 's/./=/g' |
| 39 | +echo |
| 40 | + |
| 41 | +# Build the loader |
| 42 | +BUILD_DIR=build/${variant} |
| 43 | +VARIANT_DIR=variants/${variant} |
| 44 | +rm -rf ${BUILD_DIR} |
| 45 | +west build -d ${BUILD_DIR} -b ${board} loader -t llext-edk $* |
| 46 | + |
| 47 | +# Extract the generated EDK tarball and copy it to the variant directory |
| 48 | +mkdir -p ${VARIANT_DIR} firmwares |
| 49 | +(set -e ; cd ${BUILD_DIR} && rm -rf llext-edk && tar xf zephyr/llext-edk.tar.Z) |
| 50 | +rsync -a --delete ${BUILD_DIR}/llext-edk ${VARIANT_DIR}/ |
| 51 | + |
| 52 | +# remove all inline comments in macro definitions |
| 53 | +# (especially from devicetree_generated.h and sys/util_internal.h) |
| 54 | +line_preproc_ok='^\s*#\s*(if|else|elif|endif)' # match conditional preproc lines |
| 55 | +line_comment_only='^\s*\/\*' # match lines starting with comment |
| 56 | +line_continuation='\\$' # match lines ending with '\' |
| 57 | +c_comment='\s*\/\*.*?\*\/' # match C-style comments and any preceding space |
| 58 | +perl -i -pe "s/${c_comment}//gs unless /${line_preproc_ok}/ || (/${line_comment_only}/ && !/${line_continuation}/)" $(find ${VARIANT_DIR}/llext-edk/include/ -type f) |
| 59 | +for ext in elf bin hex; do |
| 60 | + rm -f firmwares/zephyr-$variant.$ext |
| 61 | + if [ -f ${BUILD_DIR}/zephyr/zephyr.$ext ]; then |
| 62 | + cp ${BUILD_DIR}/zephyr/zephyr.$ext firmwares/zephyr-$variant.$ext |
| 63 | + fi |
| 64 | +done |
| 65 | + |
33 | 66 | # Generate the provides.ld file for linked builds
|
34 | 67 | echo "Exporting provides.ld"
|
35 | 68 | READELF=${ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/bin/arm-zephyr-eabi-readelf
|
36 |
| -$READELF --wide -s build/zephyr/zephyr.elf | c++filt | grep FUNC | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' > variants/$variant/provides.ld |
37 |
| -$READELF --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld |
38 |
| -$READELF --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE(kheap_llext_heap_size = "$3");"}' >> variants/$variant/provides.ld |
39 |
| -$READELF --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> variants/$variant/provides.ld |
40 |
| -$READELF --wide -s build/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE(kheap__system_heap_size = "$3");"}' >> variants/$variant/provides.ld |
41 |
| -cat build/zephyr/zephyr.map | grep __device_dts_ord | grep -v rodata | grep -v llext_const_symbol | awk -F' ' '{print "PROVIDE("$2" = "$1");"}' >> variants/$variant/provides.ld |
42 |
| -TEXT_START=`cat loader/boards/$variant.overlay | grep user_sketch: | cut -f2 -d"@" | cut -f1 -d"{"` |
43 |
| -echo "PROVIDE(_sketch_start = 0x$TEXT_START);" >> variants/$variant/provides.ld |
44 |
| - |
45 |
| -sed -i 's/PROVIDE(malloc =/PROVIDE(__wrap_malloc =/g' variants/$variant/provides.ld |
46 |
| -sed -i 's/PROVIDE(free =/PROVIDE(__wrap_free =/g' variants/$variant/provides.ld |
47 |
| -sed -i 's/PROVIDE(realloc =/PROVIDE(__wrap_realloc =/g' variants/$variant/provides.ld |
48 |
| -sed -i 's/PROVIDE(calloc =/PROVIDE(__wrap_calloc =/g' variants/$variant/provides.ld |
49 |
| -sed -i 's/PROVIDE(random =/PROVIDE(__wrap_random =/g' variants/$variant/provides.ld |
| 69 | +$READELF --wide -s ${BUILD_DIR}/zephyr/zephyr.elf | c++filt | grep FUNC | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' > ${VARIANT_DIR}/provides.ld |
| 70 | +$READELF --wide -s ${BUILD_DIR}/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> ${VARIANT_DIR}/provides.ld |
| 71 | +$READELF --wide -s ${BUILD_DIR}/zephyr/zephyr.elf | c++filt | grep kheap_llext_heap | awk -F' ' '{print "PROVIDE(kheap_llext_heap_size = "$3");"}' >> ${VARIANT_DIR}/provides.ld |
| 72 | +$READELF --wide -s ${BUILD_DIR}/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE("$8" = 0x"$2");"}' >> ${VARIANT_DIR}/provides.ld |
| 73 | +$READELF --wide -s ${BUILD_DIR}/zephyr/zephyr.elf | c++filt | grep kheap__system_heap | awk -F' ' '{print "PROVIDE(kheap__system_heap_size = "$3");"}' >> ${VARIANT_DIR}/provides.ld |
| 74 | +cat ${BUILD_DIR}/zephyr/zephyr.map | grep __device_dts_ord | grep -v rodata | grep -v llext_const_symbol | awk -F' ' '{print "PROVIDE("$2" = "$1");"}' >> ${VARIANT_DIR}/provides.ld |
| 75 | +TEXT_START=`cat variants/$variant/$variant.overlay | grep user_sketch: | cut -f2 -d"@" | cut -f1 -d"{"` |
| 76 | +echo "PROVIDE(_sketch_start = 0x$TEXT_START);" >> ${VARIANT_DIR}/provides.ld |
| 77 | + |
| 78 | +sed -i 's/PROVIDE(malloc =/PROVIDE(__wrap_malloc =/g' ${VARIANT_DIR}/provides.ld |
| 79 | +sed -i 's/PROVIDE(free =/PROVIDE(__wrap_free =/g' ${VARIANT_DIR}/provides.ld |
| 80 | +sed -i 's/PROVIDE(realloc =/PROVIDE(__wrap_realloc =/g' ${VARIANT_DIR}/provides.ld |
| 81 | +sed -i 's/PROVIDE(calloc =/PROVIDE(__wrap_calloc =/g' ${VARIANT_DIR}/provides.ld |
| 82 | +sed -i 's/PROVIDE(random =/PROVIDE(__wrap_random =/g' ${VARIANT_DIR}/provides.ld |
| 83 | + |
| 84 | +cmake -P extra/gen_arduino_files.cmake $variant |
0 commit comments