aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/tools/autobuild
diff options
context:
space:
mode:
Diffstat (limited to 'circuitpython/tools/autobuild')
-rwxr-xr-xcircuitpython/tools/autobuild/build-boards.sh116
-rwxr-xr-xcircuitpython/tools/autobuild/build-downloads.py58
2 files changed, 174 insertions, 0 deletions
diff --git a/circuitpython/tools/autobuild/build-boards.sh b/circuitpython/tools/autobuild/build-boards.sh
new file mode 100755
index 0000000..4b5259b
--- /dev/null
+++ b/circuitpython/tools/autobuild/build-boards.sh
@@ -0,0 +1,116 @@
+#!/bin/bash
+#
+# The functions in this file can be run independently to build boards.
+# For example:
+#
+# $ source build-boards.sh
+# $ MICROPY_AUTOBUILD_MAKE=make build_rp2_boards -latest /tmp
+
+function build_board {
+ # check/get parameters
+ if [ $# -lt 4 ]; then
+ echo "usage: $0 <board-json-file> <fw-tag> <dest-dir> <exts...>"
+ return 1
+ fi
+
+ board_json=$1
+ fw_tag=$2
+ dest_dir=$3
+ shift
+ shift
+ shift
+
+ board=$(echo $board_json | awk -F '/' '{ print $2 }')
+ descr=$(cat $board_json | python3 -c "import json,sys; print(json.load(sys.stdin).get('id', '$board'))")
+ build_dir=/tmp/micropython-build-$board
+
+ echo "building $descr $board"
+ $MICROPY_AUTOBUILD_MAKE BOARD=$board BUILD=$build_dir && (
+ for ext in $@; do
+ dest=$dest_dir/$descr$fw_tag.$ext
+ if [ -r $build_dir/firmware.$ext ]; then
+ mv $build_dir/firmware.$ext $dest
+ else
+ # esp32 has micropython.elf and micropython.map
+ mv $build_dir/micropython.$ext $dest
+ fi
+ done
+ )
+ rm -rf $build_dir
+}
+
+function build_boards {
+ # check/get parameters
+ if [ $# -lt 4 ]; then
+ echo "usage: $0 <check-file> <fw-tag> <dest-dir> <exts...>"
+ return 1
+ fi
+
+ check_file=$1
+ shift
+
+ # check we are in the correct directory
+ if [ ! -r $check_file ]; then
+ echo "must be in directory containing $check_file"
+ return 1
+ fi
+
+ # 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 {
+ # check/get parameters
+ if [ $# != 2 ]; then
+ echo "usage: $0 <fw-tag> <dest-dir>"
+ return 1
+ fi
+
+ fw_tag=$1
+ dest_dir=$2
+
+ # check we are in the correct directory
+ if [ ! -r modesp32.c ]; then
+ echo "must be in esp32 directory"
+ return 1
+ fi
+
+ # build the boards, based on the IDF version
+ for board_json in $(find boards/ -name board.json | sort); do
+ mcu=$(cat $board_json | python3 -c "import json,sys; print(json.load(sys.stdin).get('mcu', 'unknown'))")
+ if idf.py --version | grep -q v4.2; then
+ if [ $mcu = esp32 ]; then
+ # build standard esp32-based boards with IDF v4.2
+ if echo $board_json | grep -q GENERIC; then
+ # traditionally, GENERIC and GENERIC_SPIRAM boards used manifest_release.py
+ MICROPY_AUTOBUILD_MAKE="$MICROPY_AUTOBUILD_MAKE FROZEN_MANIFEST=$(pwd)/boards/manifest_release.py" build_board $board_json $fw_tag $dest_dir bin elf map
+ else
+ build_board $board_json $fw_tag $dest_dir bin elf map
+ fi
+ fi
+ else
+ if [ $mcu != esp32 ]; then
+ # build esp32-s2/s3/c3 based boards with IDF v4.4+
+ build_board $board_json $fw_tag $dest_dir bin elf map
+ fi
+ fi
+ done
+}
+
+function build_mimxrt_boards {
+ build_boards modmimxrt.c $1 $2 bin hex
+}
+
+function build_rp2_boards {
+ build_boards modrp2.c $1 $2 uf2
+}
+
+function build_samd_boards {
+ build_boards samd_soc.c $1 $2 uf2
+}
+
+function build_stm32_boards {
+ build_boards modpyb.c $1 $2 dfu hex
+}
diff --git a/circuitpython/tools/autobuild/build-downloads.py b/circuitpython/tools/autobuild/build-downloads.py
new file mode 100755
index 0000000..0f532e8
--- /dev/null
+++ b/circuitpython/tools/autobuild/build-downloads.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+import glob
+import json
+import os
+import sys
+
+
+def main(repo_path, output_path):
+ boards_index = []
+ board_ids = set()
+
+ for board_json in glob.glob(os.path.join(repo_path, "ports/*/boards/*/board.json")):
+ # Relative path to the board directory (e.g. "ports/stm32/boards/PYBV11").
+ board_dir = os.path.dirname(board_json)
+ # Relative path to the port (e.g. "ports/stm32")
+ port_dir = os.path.dirname(os.path.dirname(board_dir))
+
+ with open(board_json, "r") as f:
+ blob = json.load(f)
+
+ # Use "id" if specified, otherwise default to board dir (e.g. "PYBV11").
+ # We allow boards to override ID for the historical build names.
+ blob["id"] = blob.get("id", os.path.basename(board_dir))
+
+ # Check for duplicate board IDs.
+ if blob["id"] in board_ids:
+ print("Duplicate board ID: '{}'".format(blob["id"]), file=sys.stderr)
+ board_ids.add(blob["id"])
+
+ # Add in default fields.
+ blob["port"] = os.path.basename(port_dir)
+ blob["build"] = os.path.basename(board_dir)
+ boards_index.append(blob)
+
+ # Create the board markdown, which is the concatenation of the
+ # default "board.md" file (if exists), as well as any flashing
+ # instructions.
+ board_markdown = os.path.join(board_dir, "board.md")
+ with open(os.path.join(output_path, blob["id"] + ".md"), "w") as f:
+ if os.path.exists(board_markdown):
+ with open(board_markdown, "r") as fin:
+ f.write(fin.read())
+
+ if blob["deploy"]:
+ f.write("\n\n## Installation instructions\n")
+ for deploy in blob["deploy"]:
+ with open(os.path.join(board_dir, deploy), "r") as fin:
+ f.write(fin.read())
+
+ # Write the full index for the website to load.
+ with open(os.path.join(output_path, "index.json"), "w") as f:
+ json.dump(boards_index, f, indent=4, sort_keys=True)
+ f.write("\n")
+
+
+if __name__ == "__main__":
+ main(sys.argv[1], sys.argv[2])