2025-10-09 19:49:53 +02:00
#!/bin/bash
mydir = $( readlink -f " $0 " )
mydir = $( dirname " $mydir " )
2025-10-24 18:58:52 +02:00
codebasedir = $( readlink -f " $mydir " /..) # build process needs absolute paths
2025-05-07 10:24:33 +02:00
2025-05-17 19:14:07 +02:00
target = " $1 "
buildtype = " $2 "
2025-11-22 10:17:54 +01:00
if [ -z " $target " ] ; then
echo " Usage: $0 target "
echo " Usage: $0 <esp32 or unix or macOS> "
echo " Example: $0 unix "
echo " Example: $0 macOS "
echo " Example: $0 esp32 "
2026-02-13 15:29:25 +01:00
echo " Example: $0 esp32s3 "
2025-05-17 19:14:07 +02:00
exit 1
fi
2025-05-07 10:24:33 +02:00
2025-10-24 18:58:52 +02:00
# This assumes all the git submodules have been checked out recursively
echo "Fetch tags for lib/SDL, otherwise lvgl_micropython's make.py script can't checkout a specific tag..."
pushd " $codebasedir " /lvgl_micropython/lib/SDL
2025-10-24 19:29:51 +02:00
git fetch --unshallow origin 2>/dev/null # will give error if already done
2025-10-24 18:58:52 +02:00
# Or fetch all refs without unshallowing (keeps it shallow but adds refs)
2025-10-24 19:38:39 +02:00
git fetch origin 'refs/tags/*:refs/tags/*'
2025-10-24 18:58:52 +02:00
popd
idfile = " $codebasedir " /lvgl_micropython/lib/micropython/ports/esp32/main/idf_component.yml
2026-01-07 14:40:59 +01:00
echo " Patching $idfile " ...
2026-02-16 16:12:06 +01:00
echo " Check need to add esp32-camera to $idfile "
2025-10-24 19:07:07 +02:00
if ! grep esp32-camera " $idfile " ; then
2025-10-24 18:58:52 +02:00
echo " Adding esp32-camera to $idfile "
2026-01-13 18:24:48 +01:00
echo " mpos/esp32-camera:
2025-10-24 18:58:52 +02:00
git: https://github.com/MicroPythonOS/esp32-camera" >> " $idfile "
else
echo " No need to add esp32-camera to $idfile "
fi
2026-02-16 16:12:06 +01:00
echo " Check need to add adc_mic to $idfile "
2026-02-16 21:52:38 +01:00
if ! grep adc_mic " $idfile " ; then
echo " Adding adc_mic to $idfile "
2026-02-16 16:12:06 +01:00
echo ' espressif/adc_mic: "*"' >> " $idfile "
else
echo " No need to add adc_mic to $idfile "
fi
echo " Resulting $idfile file: "
2026-01-13 18:24:48 +01:00
cat " $idfile "
2025-10-24 18:58:52 +02:00
2025-10-26 08:02:50 +01:00
echo "Check need to add lvgl_micropython manifest to micropython-camera-API's manifest..."
camani = " $codebasedir " /micropython-camera-API/src/manifest.py
2025-10-26 08:05:28 +01:00
rellvglmani = lvgl_micropython/build/manifest.py
2025-10-26 09:13:05 +01:00
abslvglmani = " $codebasedir " /" $rellvglmani "
2025-10-26 08:44:28 +01:00
if ! grep " $rellvglmani " " $camani " ; then
2025-10-26 08:05:28 +01:00
echo " Adding include(\" $abslvglmani \") to $camani "
2025-10-26 08:24:50 +01:00
echo >> " $camani " # needs newline because file doesn't have newline at the end
2025-10-26 08:05:28 +01:00
echo " include(\" $abslvglmani \") # workaround to prevent micropython-camera-API from overriding the lvgl_micropython manifest... " >> " $camani "
2025-10-26 08:24:50 +01:00
echo "Resulting file:"
cat " $camani "
2025-10-26 08:02:50 +01:00
else
2025-10-26 08:05:28 +01:00
echo " No need to add include(\" $abslvglmani \") to $camani "
2025-10-26 08:02:50 +01:00
fi
2025-10-24 18:58:52 +02:00
echo "Check need to add asyncio..."
2025-10-24 19:29:51 +02:00
manifile = " $codebasedir " /lvgl_micropython/lib/micropython/ports/unix/variants/manifest.py
2025-10-24 19:07:07 +02:00
if ! grep asyncio " $manifile " ; then
2025-10-24 18:58:52 +02:00
echo " Adding asyncio to $manifile "
echo 'include("$(MPY_DIR)/extmod/asyncio") # needed to have asyncio, which is used by aiohttp, which has used by websockets' >> " $manifile "
2025-10-26 08:24:50 +01:00
echo "Resulting file:"
cat " $manifile "
2025-10-24 18:58:52 +02:00
else
echo " No need to add asyncio to $manifile "
fi
# unix and macOS builds need these symlinks because make.py doesn't handle USER_C_MODULE arguments for them:
echo "Symlinking secp256k1-embedded-ecdh for unix and macOS builds..."
ln -sf ../../secp256k1-embedded-ecdh " $codebasedir " /lvgl_micropython/ext_mod/secp256k1-embedded-ecdh
echo "Symlinking c_mpos for unix and macOS builds..."
ln -sf ../../c_mpos " $codebasedir " /lvgl_micropython/ext_mod/c_mpos
2025-11-23 14:02:49 +01:00
# Only for MicroPython 1.26.1 workaround:
#echo "Applying lvgl_micropython i2c patch..."
#patch -p0 --forward < "$codebasedir"/patches/i2c_ng.patch
2025-10-24 18:58:52 +02:00
2025-11-22 10:17:54 +01:00
echo "Refreshing freezefs..."
" $codebasedir " /scripts/freezefs_mount_builtin.sh
2025-10-09 19:49:53 +02:00
2026-02-26 21:01:11 +01:00
if [ " $target " = = "esp32" -o " $target " = = "esp32s3" ] ; then
2026-02-18 18:10:14 +01:00
extra_configs = ""
2026-02-13 15:29:25 +01:00
if [ " $target " = = "esp32" ] ; then
BOARD = ESP32_GENERIC
BOARD_VARIANT = SPIRAM
2026-02-26 21:01:11 +01:00
else # esp32s3
2026-02-13 15:29:25 +01:00
BOARD = ESP32_GENERIC_S3
BOARD_VARIANT = SPIRAM_OCT
2026-02-26 21:01:11 +01:00
# These options disable hardware AES, SHA and MPI because they give warnings in QEMU: [AES] Error reading from GDMA buffer
# There's a 25% https download speed penalty for this, but that's usually not the bottleneck.
extra_configs = "CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_SHA=n CONFIG_MBEDTLS_HARDWARE_MPI=n"
2026-02-26 21:57:42 +01:00
# --py-freertos: add MicroPython FreeRTOS module to expose internals
extra_configs = " $extra_configs --py-freertos "
2026-02-13 15:29:25 +01:00
fi
2025-11-22 10:17:54 +01:00
manifest = $( readlink -f " $codebasedir " /manifests/manifest.py)
2026-02-23 23:34:08 +01:00
frozenmanifest = " FROZEN_MANIFEST= $manifest " # Comment this out if you want to make a build without any frozen files, just an empty MicroPython + whatever files you have on the internal storage
2025-11-22 10:17:54 +01:00
echo "Note that you can also prevent the builtin filesystem from being mounted by umounting it and creating a builtin/ folder."
2026-02-13 15:29:25 +01:00
pushd " $codebasedir " /lvgl_micropython/
rm -rf lib/micropython/ports/esp32/build-$BOARD -$BOARD_VARIANT
# For more info on the options, see https://github.com/lvgl-micropython/lvgl_micropython
2025-05-17 19:14:07 +02:00
# --ota: support Over-The-Air updates
# --partition size: both OTA partitions are 4MB
# --flash-size: total flash size is 16MB
2026-02-23 23:33:48 +01:00
# --debug: enable debugging from ESP-IDF but makes copying files to it very slow so that's not added
2025-05-17 19:14:07 +02:00
# --dual-core-threads: disabled GIL, run code on both CPUs
# --task-stack-size={stack size in bytes}
# CONFIG_* sets ESP-IDF options
2025-05-20 08:08:37 +02:00
# listing processes on the esp32 still doesn't work because no esp32.vtask_list_threads() or something
2025-05-17 19:14:07 +02:00
# CONFIG_FREERTOS_USE_TRACE_FACILITY=y
# CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
2026-02-26 21:01:11 +01:00
# CONFIG_ADC_MIC_TASK_CORE=1 because with the default (-1) it hangs the CPU
# CONFIG_SPIRAM_XIP_FROM_PSRAM: load entire firmware into RAM to reduce SD vs PSRAM contention (recommended at https://github.com/MicroPythonOS/MicroPythonOS/issues/17)
2026-02-13 15:29:25 +01:00
python3 make.py --ota --partition-size= 4194304 --flash-size= 16 esp32 BOARD = $BOARD BOARD_VARIANT = $BOARD_VARIANT \
2026-02-12 14:02:11 +01:00
USER_C_MODULE = " $codebasedir " /micropython-camera-API/src/micropython.cmake \
USER_C_MODULE = " $codebasedir " /secp256k1-embedded-ecdh/micropython.cmake \
USER_C_MODULE = " $codebasedir " /c_mpos/micropython.cmake \
CONFIG_FREERTOS_USE_TRACE_FACILITY = y \
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID = y \
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS = y \
2026-02-20 15:36:54 +01:00
CONFIG_ADC_MIC_TASK_CORE = 1 \
2026-02-26 21:39:45 +01:00
$extra_configs \
2026-02-12 14:02:11 +01:00
" $frozenmanifest "
2026-02-13 15:29:25 +01:00
2025-10-08 16:19:26 +02:00
popd
2025-10-20 22:44:57 +02:00
elif [ " $target " = = "unix" -o " $target " = = "macOS" ] ; then
2025-11-22 10:17:54 +01:00
manifest = $( readlink -f " $codebasedir " /manifests/manifest.py)
frozenmanifest = " FROZEN_MANIFEST= $manifest "
2025-12-03 23:11:22 +01:00
# Comment out @micropython.viper decorator for Unix/macOS builds
# (cross-compiler doesn't support Viper native code emitter)
echo "Temporarily commenting out @micropython.viper decorator for Unix/macOS build..."
stream_wav_file = " $codebasedir " /internal_filesystem/lib/mpos/audio/stream_wav.py
2025-12-08 12:09:39 +01:00
sed -i.backup 's/^@micropython\.viper$/#@micropython.viper/' " $stream_wav_file "
2025-12-03 23:11:22 +01:00
2026-01-09 15:08:26 +01:00
# If it's still running, kill it, otherwise "text file busy"
pkill -9 -f /lvgl_micropy_unix
2026-01-07 15:06:21 +01:00
# LV_CFLAGS are passed to USER_C_MODULES (compiler flags only, no linker flags)
2025-06-05 12:34:56 +02:00
# STRIP= makes it so that debug symbols are kept
2025-10-24 18:58:52 +02:00
pushd " $codebasedir " /lvgl_micropython/
2025-10-16 17:36:32 +02:00
# USER_C_MODULE doesn't seem to work properly so there are symlinks in lvgl_micropython/extmod/
2026-02-13 15:29:25 +01:00
python3 make.py " $target " LV_CFLAGS = "-g -O0 -ggdb" STRIP = DISPLAY = sdl_display INDEV = sdl_pointer " $frozenmanifest "
2025-10-08 16:19:26 +02:00
popd
2025-12-03 23:11:22 +01:00
# Restore @micropython.viper decorator after build
echo "Restoring @micropython.viper decorator..."
2025-12-08 12:09:39 +01:00
sed -i.backup 's/^#@micropython\.viper$/@micropython.viper/' " $stream_wav_file "
2025-05-20 08:08:37 +02:00
else
echo " invalid target $target "
2025-05-10 17:44:31 +02:00
fi
2025-05-09 17:49:16 +02:00