Skip to content

Commit 157b706

Browse files
committed
Add more options for SparkFun builds.
Can now specify board variants, frozen manifest files, and user C modules. Also, building mpy-cross is now a single dedicated step instead of a build option.
1 parent 8babb64 commit 157b706

File tree

1 file changed

+66
-33
lines changed

1 file changed

+66
-33
lines changed

sparkfun_build.sh

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function create_frozen_data_fs {
5353

5454
# Now we will use freezefs to create a self-extracting archive from the _frozen_data directory
5555
echo "Creating self-extracting archive from ${FROZEN_DATA_DIR}"
56-
python -m freezefs ${FROZEN_DATA_DIR} $2
56+
python3 -m freezefs ${FROZEN_DATA_DIR} $2
5757
if [ $? -ne 0 ]; then
5858
echo "Error creating frozen data filesystem. Please check the freezefs documentation for more information."
5959
exit 1
@@ -86,54 +86,84 @@ function add_frozen_data_to_boot_for_port {
8686

8787
# Builds all SparkFun boards for the given port
8888
# Options:
89-
# $1: Port name
90-
# $2: [Optional] Prefix for the SparkFun board directories for port(default: "-SPARKFUN_")
89+
# -n: Port name
90+
# -p: [Optional] Prefix for the SparkFun board directories for port (default: "SPARKFUN_")
91+
# -f: [Optional] Frozen manifest file to use (default: none)
92+
# -v: [Optional] Board variant to build (default: none)
93+
# -m: [Optional] User C modules to include (default: none)
9194
function build_for_port {
92-
local TARGET_PORT_NAME=$1
93-
local SPARKFUN_PREFIX=${2:-SPARKFUN_}
95+
local TARGET_PORT_NAME
96+
local SPARKFUN_PREFIX="SPARKFUN_"
97+
local FROZEN_MANIFEST
98+
local BOARD_VARIANT
99+
local USER_C_MODULES
100+
101+
OPTIND=1
102+
while getopts "n:p:f:v:m:" opt; do
103+
echo "Processing option: $opt with argument: $OPTARG"
104+
case ${opt} in
105+
n )
106+
TARGET_PORT_NAME=$OPTARG
107+
;;
108+
p )
109+
SPARKFUN_PREFIX=$OPTARG
110+
;;
111+
f )
112+
FROZEN_MANIFEST=$OPTARG
113+
;;
114+
v )
115+
BOARD_VARIANT=$OPTARG
116+
;;
117+
m )
118+
USER_C_MODULES=$OPTARG
119+
;;
120+
esac
121+
done
122+
123+
echo "TARGET_PORT_NAME: ${TARGET_PORT_NAME}"
124+
echo "SPARKFUN_PREFIX: ${SPARKFUN_PREFIX}"
125+
echo "FROZEN_MANIFEST: ${FROZEN_MANIFEST}"
126+
echo "BOARD_VARIANT: ${BOARD_VARIANT}"
127+
echo "USER_C_MODULES: ${USER_C_MODULES}"
128+
94129
local SPARKFUN_BOARD_PREFIX="ports/${TARGET_PORT_NAME}/boards/${SPARKFUN_PREFIX}*"
95130

96131
for board in $SPARKFUN_BOARD_PREFIX; do
132+
# If BOARD_VARIANT is set, check if the variant file exists. If not, skip this board.
133+
if [ -n "$BOARD_VARIANT" ] && [ ! -f "${board}/mpconfigvariant_${BOARD_VARIANT}.cmake" ]; then
134+
echo "Skipping $(basename $board)"
135+
continue
136+
fi
137+
echo "Building $(basename $board)"
138+
97139
BOARD_TO_BUILD=${SPARKFUN_PREFIX}${board#$SPARKFUN_BOARD_PREFIX}
98-
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD clean
99-
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD submodules
100-
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD
140+
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD BOARD_VARIANT=$BOARD_VARIANT FROZEN_MANIFEST=$FROZEN_MANIFEST USER_C_MODULES=$USER_C_MODULES clean
141+
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD BOARD_VARIANT=$BOARD_VARIANT FROZEN_MANIFEST=$FROZEN_MANIFEST USER_C_MODULES=$USER_C_MODULES submodules
142+
make ${MAKEOPTS} -C ports/${TARGET_PORT_NAME} BOARD=$BOARD_TO_BUILD BOARD_VARIANT=$BOARD_VARIANT FROZEN_MANIFEST=$FROZEN_MANIFEST USER_C_MODULES=$USER_C_MODULES
101143
done
102144
}
103145

104-
# 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)
146+
# Builds all SparkFun RP2 boards
105147
# Options:
106-
# $1: Whether to build the cross compiler
148+
# See build_for_port function for options
107149
function build_all_sparkfun_boards_rp2 {
108-
if $1; then
109-
make ${MAKEOPTS} -C mpy-cross
110-
fi
111-
112-
build_for_port "rp2"
150+
build_for_port -n rp2 $@
113151
}
114152

115153
# Builds all SparkFun ESP32 boards
116154
# Options:
117-
# $1: Whether to build the cross compiler
155+
# See build_for_port function for options
118156
function build_all_sparkfun_boards_esp32 {
119157
source esp-idf/export.sh
120158

121-
if $1; then
122-
make ${MAKEOPTS} -C mpy-cross
123-
fi
124-
125-
build_for_port "esp32"
159+
build_for_port -n esp32 $@
126160
}
127161

128162
# Builds all Teensy mimxrt boards
129163
# Options:
130-
# $1: Whether to build the cross compiler
164+
# See build_for_port function for options
131165
function build_all_sparkfun_boards_mimxrt {
132-
if $1; then
133-
make ${MAKEOPTS} -C mpy-cross
134-
fi
135-
136-
build_for_port "mimxrt" "TEENSY"
166+
build_for_port -n mimxrt -p TEENSY $@
137167
}
138168

139169
# Copies all files with the given prefix from the SparkFun build directories to the output directory
@@ -279,14 +309,17 @@ function build_sparkfun {
279309
echo "OUTPUT_DIRECTORY: ${OUTPUT_DIRECTORY}"
280310
echo "Performing minimal SparkFun build for ESP32 and RP2"
281311

312+
# Build the MicroPython cross compiler
313+
make ${MAKEOPTS} -C mpy-cross
314+
282315
# Perform minimal build for ESP32
283-
build_all_sparkfun_boards_esp32 true
316+
build_all_sparkfun_boards_esp32
284317

285318
# Perform minimal build for RP2
286-
build_all_sparkfun_boards_rp2 false
319+
build_all_sparkfun_boards_rp2
287320

288321
# Perform minimal build for mimxrt
289-
build_all_sparkfun_boards_mimxrt false
322+
build_all_sparkfun_boards_mimxrt
290323

291324
# Copy all esp32 binary files to the output directory
292325
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" "MINIMAL_${OUTPUT_FILE_PREFIX}"
@@ -325,13 +358,13 @@ function build_sparkfun {
325358
echo "Performing full SparkFun build for ESP32, RP2, and mimxrt"
326359

327360
# Perform Qwiic Build for ESP32
328-
build_all_sparkfun_boards_esp32 false
361+
build_all_sparkfun_boards_esp32
329362

330363
# Perform Qwiic Build for RP2
331-
build_all_sparkfun_boards_rp2 false
364+
build_all_sparkfun_boards_rp2
332365

333366
# Perform Qwiic build for mimxrt
334-
build_all_sparkfun_boards_mimxrt false
367+
build_all_sparkfun_boards_mimxrt
335368

336369
# Copy all esp32 binary files to the output directory
337370
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" ${OUTPUT_FILE_PREFIX}

0 commit comments

Comments
 (0)