2021-11-05 00:02:30 +00:00
#!/bin/bash
#
# The functions in this file can be run independently to build boards.
# For example:
#
2023-07-25 08:12:52 +01:00
# $ source tools/autobuild/build-boards.sh
# $ cd ports/rp2
# $ MICROPY_AUTOBUILD_MAKE="make -j8" build_rp2_boards -latest /tmp
#
# Or to build a single board:
#
# $ source tools/autobuild/build-boards.sh
# $ cd ports/rp2
# $ MICROPY_AUTOBUILD_MAKE="make -j8" build_board boards/PICO/board.json -latest /tmp uf2
function copy_artefacts {
local dest_dir = $1
local descr = $2
local fw_tag = $3
local build_dir = $4
shift 4
for ext in $@ ; do
dest = $dest_dir /$descr $fw_tag .$ext
if [ -r $build_dir /firmware.$ext ] ; then
mv $build_dir /firmware.$ext $dest
elif [ -r $build_dir /micropython.$ext ] ; then
# esp32 has micropython.elf, etc
mv $build_dir /micropython.$ext $dest
elif [ $ext = app-bin -a -r $build_dir /micropython.bin ] ; then
# esp32 has micropython.bin which is just the application
mv $build_dir /micropython.bin $dest
fi
done
}
2021-11-05 00:02:30 +00:00
2021-12-10 10:26:08 +00:00
function build_board {
2021-11-05 00:02:30 +00:00
# check/get parameters
if [ $# -lt 4 ] ; then
2021-12-10 10:26:08 +00:00
echo " usage: $0 <board-json-file> <fw-tag> <dest-dir> <exts...> "
2021-11-05 00:02:30 +00:00
return 1
fi
2023-07-25 08:12:52 +01:00
local board_json = $1
local fw_tag = $2
local dest_dir = $3
shift 3
2021-11-05 00:02:30 +00:00
2023-07-25 08:12:52 +01:00
local board = $( echo $board_json | awk -F '/' '{ print $2 }' )
local descr = $( cat $board_json | python3 -c " import json,sys; print(json.load(sys.stdin).get('id', ' $board ')) " )
2021-12-10 10:26:08 +00:00
2023-07-25 08:12:52 +01:00
# Build the "default" variant. For most boards this is the only thing we build.
2021-12-10 10:26:08 +00:00
echo " building $descr $board "
2023-07-25 08:12:52 +01:00
local build_dir = /tmp/micropython-build-$board
$MICROPY_AUTOBUILD_MAKE BOARD = $board BUILD = $build_dir && copy_artefacts $dest_dir $descr $fw_tag $build_dir $@
2021-12-10 10:26:08 +00:00
rm -rf $build_dir
2023-07-25 08:12:52 +01:00
2023-08-15 14:12:42 +01:00
# Query variants from board.json and build them. Ignore the special "IDF3"
2023-07-25 08:12:52 +01:00
# variant for ESP32 boards (this allows the downloads page to still have
# the idf3 files for older releases that used to be explicitly built).
2023-08-15 14:12:42 +01:00
for variant in ` cat $board_json | python3 -c "import json,sys; print(' '.join(v for v in json.load(sys.stdin).get('variants', {}).keys() if v != 'IDF3'))" ` ; do
2023-07-25 08:12:52 +01:00
local variant_build_dir = $build_dir -$variant
echo " building variant $descr $board $variant "
$MICROPY_AUTOBUILD_MAKE BOARD = $board BOARD_VARIANT = $variant BUILD = $variant_build_dir && copy_artefacts $dest_dir $descr -$variant $fw_tag $variant_build_dir $@
rm -rf $variant_build_dir
done
2021-12-10 10:26:08 +00:00
}
function build_boards {
# check/get parameters
if [ $# -lt 4 ] ; then
echo " usage: $0 <check-file> <fw-tag> <dest-dir> <exts...> "
return 1
fi
2023-07-25 08:12:52 +01:00
local check_file = $1
2021-12-10 10:26:08 +00:00
shift
2021-11-05 00:02:30 +00:00
# check we are in the correct directory
if [ ! -r $check_file ] ; then
echo " must be in directory containing $check_file "
return 1
fi
2021-12-10 10:26:08 +00:00
# build all boards that have a board.json file
for board_json in $( find boards/ -name board.json | sort) ; do
build_board $board_json $@
done
}
function build_esp32_boards {
2023-07-24 15:15:15 +01:00
build_boards modesp32.c $1 $2 bin elf map uf2 app-bin
2021-11-05 00:02:30 +00:00
}
2023-08-15 15:51:37 +01:00
function build_esp8266_boards {
build_boards modesp.c $1 $2 bin elf map
}
2021-11-05 00:02:30 +00:00
function build_mimxrt_boards {
2021-12-10 10:26:08 +00:00
build_boards modmimxrt.c $1 $2 bin hex
2021-11-05 00:02:30 +00:00
}
2022-07-12 21:48:39 +01:00
function build_nrf_boards {
2022-12-16 10:15:17 +00:00
build_boards nrfx_glue.h $1 $2 bin hex uf2
2022-07-12 21:48:39 +01:00
}
2022-05-06 09:15:21 +01:00
function build_renesas_ra_boards {
build_boards ra_it.c $1 $2 hex
}
2021-11-05 00:02:30 +00:00
function build_rp2_boards {
2021-12-10 10:26:08 +00:00
build_boards modrp2.c $1 $2 uf2
2021-11-05 00:02:30 +00:00
}
function build_samd_boards {
2021-12-10 10:26:08 +00:00
build_boards samd_soc.c $1 $2 uf2
2021-11-05 00:02:30 +00:00
}
2021-11-21 03:54:55 +00:00
function build_stm32_boards {
2021-12-10 10:26:08 +00:00
build_boards modpyb.c $1 $2 dfu hex
2021-11-21 03:54:55 +00:00
}