Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f78a46c

Browse files
committedApr 15, 2025·
Add Teensy build to release. cherry-picks from build_sparkfun (d41af30,a10cef3e)
1 parent 052dde3 commit f78a46c

28 files changed

+303
-1215
lines changed
 

‎.github/workflows/biome.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎.github/workflows/code_formatting.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎.github/workflows/code_size.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎.github/workflows/code_size_comment.yml

Lines changed: 0 additions & 105 deletions
This file was deleted.

‎.github/workflows/codespell.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎.github/workflows/commit_formatting.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎.github/workflows/docs.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎.github/workflows/examples.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎.github/workflows/mpremote.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎.github/workflows/mpy_format.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎.github/workflows/ports_cc3200.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎.github/workflows/ports_esp32.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎.github/workflows/ports_esp8266.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎.github/workflows/ports_mimxrt.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎.github/workflows/ports_nrf.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎.github/workflows/ports_powerpc.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎.github/workflows/ports_qemu.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎.github/workflows/ports_renesas-ra.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎.github/workflows/ports_rp2.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎.github/workflows/ports_samd.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎.github/workflows/ports_sparkfun.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: sparkfun ports
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
defaults:
15+
run:
16+
working-directory: 'micropython repo'
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
path: 'micropython repo'
21+
- name: Install RP2 package
22+
run: source tools/ci.sh && ci_rp2_setup
23+
# - name: Install mimxrt package # Currently redundant since it does the same arm setup as rp2, but in future if these diverge, uncomment this...
24+
# run: source tools/ci.sh && ci_mimxrt_setup
25+
- id: idf_ver
26+
name: Read the ESP-IDF version (including Python version)
27+
run: source tools/ci.sh && echo "IDF_VER=${IDF_VER}-py${PYTHON_VER}" | tee "$GITHUB_OUTPUT"
28+
- name: Install ESP-IDF packages
29+
run: source tools/ci.sh && ci_esp32_idf_setup
30+
- name: Build
31+
run: source sparkfun_build.sh && build_sparkfun -o sparkfun_release -p "MICROPYTHON_" -q qwiic_lib
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
- name: Upload Release Assets
35+
uses: shogo82148/actions-upload-release-asset@v1
36+
with:
37+
asset_path: "micropython repo/sparkfun_release/*"
38+
github_token: ${{ secrets.GITHUB_TOKEN }}
39+
upload_url: ${{ github.event.release.upload_url }}
40+

‎.github/workflows/ports_stm32.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎.github/workflows/ports_unix.yml

Lines changed: 0 additions & 264 deletions
This file was deleted.

‎.github/workflows/ports_webassembly.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎.github/workflows/ports_windows.yml

Lines changed: 0 additions & 151 deletions
This file was deleted.

‎.github/workflows/ports_zephyr.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎.github/workflows/ruff.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎sparkfun_build.sh

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
if which nproc > /dev/null; then
2+
MAKEOPTS="-j$(nproc)"
3+
else
4+
MAKEOPTS="-j$(sysctl -n hw.ncpu)"
5+
fi
6+
7+
# Downloads the latest Qwiic release from the SparkFun Qwiic_Py repository and extracts the contents to the given directory
8+
# Options:
9+
# $1: Output directory
10+
function download_qwiic_release {
11+
local LATEST_RELEASE=`gh release -R sparkfun/Qwiic_Py list --json name,isLatest --jq '.[] | select(.isLatest)|.name'`
12+
curl -sL -o pylibs.zip https://github.com/sparkfun/Qwiic_Py/releases/latest/download/qwiic-py-py-${LATEST_RELEASE}.zip
13+
unzip pylibs.zip -d .
14+
15+
mkdir -p $1
16+
cp -r qwiic-py-py-${LATEST_RELEASE}/lib/* $1
17+
}
18+
19+
# Builds all SparkFun boards for the given port
20+
# Options:
21+
# $1: Port name
22+
# $2: [Optional] Prefix for the SparkFun board directories for port(default: "-SPARKFUN_")
23+
function build_for_port {
24+
local TARGET_PORT_NAME=$1
25+
local SPARKFUN_PREFIX=${2:-SPARKFUN_}
26+
local SPARKFUN_BOARD_PREFIX="ports/${TARGET_PORT_NAME}/boards/${SPARKFUN_PREFIX}*"
27+
28+
for board in $SPARKFUN_BOARD_PREFIX; do
29+
BOARD_TO_BUILD=${SPARKFUN_PREFIX}${board#$SPARKFUN_BOARD_PREFIX}
30+
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD clean
31+
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD submodules
32+
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD
33+
done
34+
}
35+
36+
# Builds all SparkFun RP2 boards (might break into a build_for_port function that we pass the port to later if ESP32 takes the exact same build coms)
37+
# Options:
38+
# $1: Whether to build the cross compiler
39+
function build_all_sparkfun_boards_rp2 {
40+
if $1; then
41+
make ${MAKEOPTS} -C mpy-cross
42+
fi
43+
44+
build_for_port "rp2"
45+
}
46+
47+
# Builds all SparkFun ESP32 boards
48+
# Options:
49+
# $1: Whether to build the cross compiler
50+
function build_all_sparkfun_boards_esp32 {
51+
source esp-idf/export.sh
52+
53+
if $1; then
54+
make ${MAKEOPTS} -C mpy-cross
55+
fi
56+
57+
build_for_port "esp32"
58+
}
59+
60+
# Builds all Teensy mimxrt boards
61+
# Options:
62+
# $1: Whether to build the cross compiler
63+
function build_all_sparkfun_boards_mimxrt {
64+
if $1; then
65+
make ${MAKEOPTS} -C mpy-cross
66+
fi
67+
68+
build_for_port "mimxrt" "TEENSY"
69+
}
70+
71+
# Copies all files with the given prefix from the SparkFun build directories to the output directory
72+
# Options:
73+
# $1: Output directory
74+
# $2: Port directory
75+
# $3: Build prefix
76+
# $4: File basename
77+
# $5: Extension
78+
# $6: Prefix to put on output files
79+
# $7: [Optional] Convert file to hex (default: false)
80+
function copy_all_for_prefix {
81+
local OUT_DIRECTORY=$1
82+
local PORT_DIRECTORY=$2 # The directory where the ports are located (e.g. ports/rp2)
83+
local BUILD_PREFIX=$3 # The prefix of the SparkFun build directories (e.g. build-SPARKFUN_)
84+
local FILE_BASENAME=$4 # the target base name of the file to copy from each SparkFun build directory (e.g. firmware)
85+
local EXTENSION=$5 # The extension of the file to copy (e.g. uf2)
86+
local OUTPUT_PREFIX=$6 # The prefix to put on the output files (e.g. MICROPYTHON_ or MINIMAL_MICROPYTHON_)
87+
local CONVERT_TO_HEX=${7:-false} # Whether to convert the file to hex (default: false)
88+
89+
90+
mkdir -p ${OUT_DIRECTORY}
91+
92+
for file in $(find ${PORT_DIRECTORY} -wholename "*${BUILD_PREFIX}*/*${FILE_BASENAME}.${EXTENSION}"); do
93+
echo "Moving $file to ${OUT_DIRECTORY}"
94+
# First, add the check to see if we need to convert the file to hex
95+
if $CONVERT_TO_HEX; then
96+
echo "Converting $file to hex"
97+
# Convert the file to hex using hex using the command objcopy -O ihex <file> <output_file>
98+
# We need to get the output file name from the input file name
99+
OUTPUT_FILE=${OUT_DIRECTORY}/${OUTPUT_PREFIX}$(echo $file | sed -n "s/.*${BUILD_PREFIX}\([^/]*\)\/${FILE_BASENAME}.${EXTENSION}/\1/p").hex
100+
# Use objcopy to convert the file to hex and move it to the output directory (maybe unnecessary if the .hex file is already available from the build)
101+
objcopy -O ihex $file $OUTPUT_FILE
102+
else
103+
# Just move the file without converting it
104+
mv $file ${OUT_DIRECTORY}/${OUTPUT_PREFIX}$(echo $file | sed -n "s/.*${BUILD_PREFIX}\([^/]*\)\/${FILE_BASENAME}.${EXTENSION}/\1/p").${EXTENSION}
105+
fi
106+
done
107+
}
108+
109+
# The esp32 has 3 different binaries that we need to put into a directory and then zip and then move to the output directory
110+
# Options:
111+
# $1: Output directory
112+
# $2: Port directory
113+
# $3: Build prefix
114+
# $4: Prefix to put on output files
115+
# We need to copy
116+
function copy_all_for_prefix_esp32 {
117+
local OUT_DIRECTORY=$1
118+
local PORT_DIRECTORY=$2 # The directory where the ports are located (e.g. ports/esp32)
119+
local BUILD_PREFIX=$3 # The prefix of the SparkFun build directories (e.g. build-SPARKFUN_)
120+
local OUTPUT_PREFIX=$4 # The prefix to put on the output files (e.g. MICROPYTHON_ or MINIMAL_MICROPYTHON_)
121+
122+
mkdir -p ${OUT_DIRECTORY}
123+
124+
for board in $(find ${PORT_DIRECTORY} -type d -name "${BUILD_PREFIX}*"); do
125+
BOARD_NAME=$(echo $board | sed -n "s/.*${BUILD_PREFIX}\([^/]*\)/\1/p")
126+
echo "Copying binaries for $BOARD_NAME"
127+
ZIP_DIR=${OUTPUT_PREFIX}${BOARD_NAME}
128+
mkdir -p ${ZIP_DIR}
129+
cp ${board}/micropython.bin ${ZIP_DIR}/micropython.bin
130+
cp ${board}/bootloader/bootloader.bin ${ZIP_DIR}/bootloader.bin
131+
cp ${board}/partition_table/partition-table.bin ${ZIP_DIR}/partition-table.bin
132+
133+
echo "Zipping binaries for $BOARD_NAME"
134+
zip -r ${ZIP_DIR}.zip ${ZIP_DIR}
135+
136+
echo "Moving zip file for $BOARD_NAME to ${OUT_DIRECTORY}"
137+
mv ${ZIP_DIR}.zip ${OUT_DIRECTORY}
138+
done
139+
}
140+
141+
# Adds the line freeze("<DIRECTORY_WHERE_WE_DOWNLOADED_QWIIC_STUFF>") to the manifest.py for each board
142+
# Options:
143+
# $1: Qwiic directory
144+
# $2: BOARD directory
145+
# $3: Board prefix
146+
# $4: The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk.) Default: mpconfigboard.cmake
147+
function add_qwiic_manifest {
148+
local QWIIC_DIRECTORY=$1 # The directory where the Qwiic drivers are located to be frozen
149+
local BOARD_DIRECTORY=$2 # The directory where the boards are located (e.g. ports/rp2/boards)
150+
local BOARD_PREFIX=$3 # The prefix of the SparkFun board directories (e.g. SPARKFUN_)
151+
local MPCONFIG_FILE="${4:-mpconfigboard.cmake}" # The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk. )
152+
153+
for board in $(find ${BOARD_DIRECTORY} -type d -name "${BOARD_PREFIX}*"); do
154+
echo "Adding Qwiic drivers to manifest.py for $board"
155+
if [ ! -f ${board}/manifest.py ]; then
156+
echo "Creating manifest.py for $board"
157+
echo "include(\"\$(PORT_DIR)/boards/manifest.py\")" > ${board}/manifest.py
158+
159+
# also add the necessary frozen manifest line to mpconfigboard.cmake: set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
160+
# We will use the optional MPCONFIG_FILE argument to determine if we should add this line
161+
162+
if [ -n "$MPCONFIG_FILE" ]; then
163+
if [[ $MPCONFIG_FILE == *.mk ]]; then
164+
# For TEENSY which use mpconfigboard.mk instead of mpconfigboard.cmake
165+
echo "Adding frozen manifest line to mpconfigboard.mk for $board"
166+
printf "\nFROZEN_MANIFEST ?= \$(BOARD_DIR)/manifest.py" >> ${board}/mpconfigboard.mk
167+
elif [[ $MPCONFIG_FILE == *.cmake ]]; then
168+
echo "Adding frozen manifest line to mpconfigboard.cmake for $board"
169+
printf "\nset(MICROPY_FROZEN_MANIFEST \"\${MICROPY_BOARD_DIR}/manifest.py\")" >> ${board}/mpconfigboard.cmake
170+
fi
171+
fi
172+
fi
173+
174+
echo "Adding freeze line to manifest.py for $board"
175+
printf "\nfreeze(\"${QWIIC_DIRECTORY}\")" >> ${board}/manifest.py
176+
177+
echo "Manifest.py for $board:"
178+
cat ${board}/manifest.py
179+
done
180+
}
181+
182+
# Assumes that MAKEOPTS environment variable is set
183+
# This is designed to be the user-facing function that will build all SparkFun boards
184+
# Options:
185+
# -p: Output file prefix
186+
# -o: Output directory
187+
# -q: Qwiic directory
188+
function build_sparkfun {
189+
local OUTPUT_FILE_PREFIX="MICROPYTHON_"
190+
local OUTPUT_DIRECTORY="sparkfun_release"
191+
local QWIIC_DIRECTORY="qwiic_lib"
192+
193+
while getopts "p:o:q:" opt; do
194+
case ${opt} in
195+
p )
196+
OUTPUT_FILE_PREFIX=$OPTARG
197+
;;
198+
o )
199+
OUTPUT_DIRECTORY=$OPTARG
200+
;;
201+
q )
202+
QWIIC_DIRECTORY=$OPTARG
203+
;;
204+
esac
205+
done
206+
207+
echo "OUTPUT_DIRECTORY: ${OUTPUT_DIRECTORY}"
208+
echo "Performing minimal SparkFun build for ESP32 and RP2"
209+
210+
# Perform minimal build for ESP32
211+
build_all_sparkfun_boards_esp32 true
212+
213+
# Perform minimal build for RP2
214+
build_all_sparkfun_boards_rp2 false
215+
216+
# Perform minimal build for mimxrt
217+
build_all_sparkfun_boards_mimxrt false
218+
219+
# Copy all esp32 binary files to the output directory
220+
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" "MINIMAL_${OUTPUT_FILE_PREFIX}"
221+
222+
# Copy all rp2 binary files to the output directory
223+
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/rp2" "build-SPARKFUN_" "firmware" "uf2" "MINIMAL_${OUTPUT_FILE_PREFIX}"
224+
225+
# Copy all mimxrt teensy binary files to the output directory
226+
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/mimxrt" "build-TEENSY" "firmware" "elf" "MINIMAL_${OUTPUT_FILE_PREFIX}TEENSY_" true
227+
228+
echo "Downloading Qwiic library and adding to manifest.py for SparkFun boards"
229+
# Perform Qwiic download
230+
download_qwiic_release ${QWIIC_DIRECTORY}
231+
232+
# This is an ugly way to pass the qwiic path. Should make it cleaner than a relative path...
233+
# Add the downloaded Qwiic drivers to the manifest.py for each esp32 board
234+
add_qwiic_manifest "../../../../${QWIIC_DIRECTORY}" "ports/esp32/boards" "SPARKFUN_"
235+
236+
# Add the downloaded Qwiic drivers to the manifest.py for each rp2 board
237+
add_qwiic_manifest "../../../../${QWIIC_DIRECTORY}" "ports/rp2/boards" "SPARKFUN_"
238+
239+
# Add the downloaded Qwiic drivers to the manifest.py for each mimxrt teensy board (this might not work because they might lose their 40 vs. 41 when added)
240+
add_qwiic_manifest "../../../../${QWIIC_DIRECTORY}" "ports/mimxrt/boards" "TEENSY40" "mpconfigboard.mk"
241+
add_qwiic_manifest "../../../../${QWIIC_DIRECTORY}" "ports/mimxrt/boards" "TEENSY41" "" # We don't need to add the frozen manifest line to mpconfigboard.mk for TEENSY41, it is already there
242+
243+
echo "Performing full SparkFun build for ESP32, RP2, and mimxrt"
244+
245+
# Perform Qwiic Build for ESP32
246+
build_all_sparkfun_boards_esp32 false
247+
248+
# Perform Qwiic Build for RP2
249+
build_all_sparkfun_boards_rp2 false
250+
251+
# Perform Qwiic build for mimxrt
252+
build_all_sparkfun_boards_mimxrt false
253+
254+
# Copy all esp32 binary files to the output directory
255+
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" ${OUTPUT_FILE_PREFIX}
256+
257+
# Copy all rp2 binary files to the output directory
258+
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/rp2" "build-SPARKFUN_" "firmware" "uf2" ${OUTPUT_FILE_PREFIX}
259+
260+
# Copy all mimxrt teensy binary files to the output directory
261+
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/mimxrt" "build-TEENSY" "firmware" "elf" "${OUTPUT_FILE_PREFIX}TEENSY_" true
262+
}
263+

0 commit comments

Comments
 (0)
Please sign in to comment.