-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathbuild_mpos.sh
More file actions
executable file
·267 lines (236 loc) · 11.4 KB
/
build_mpos.sh
File metadata and controls
executable file
·267 lines (236 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/bin/bash
mydir=$(readlink -f "$0")
mydir=$(dirname "$mydir")
codebasedir=$(readlink -f "$mydir"/..) # build process needs absolute paths
target="$1"
buildtype="$2"
if [ -z "$target" ]; then
echo "Usage: $0 target"
echo "Usage: $0 <esp32 or esp32-small or unix or macOS>"
echo "Example: $0 unix"
echo "Example: $0 macOS"
echo "Example: $0 esp32"
echo "Example: $0 esp32-small"
echo "Example: $0 esp32s3"
echo "Example: $0 unphone"
echo "Example: $0 clean"
exit 1
fi
if [ "$target" == "clean" ]; then
rm -rf "$mydir"/../lvgl_micropython/lib/micropython/ports/unix/build-standard/
rm -rf "$mydir"/../lvgl_micropython/lib/micropython/ports/esp32/build-ESP32_GENERIC/
rm -rf "$mydir"/../lvgl_micropython/lib/micropython/ports/esp32/build-ESP32_GENERIC_S3-SPIRAM_OCT/
exit 0
fi
# 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
git fetch --unshallow origin 2>/dev/null # will give error if already done
# Or fetch all refs without unshallowing (keeps it shallow but adds refs)
git fetch origin 'refs/tags/*:refs/tags/*'
popd
idfile="$codebasedir"/lvgl_micropython/lib/micropython/ports/esp32/main/idf_component.yml
echo "Patching $idfile"...
echo "Check need to add esp32-camera to $idfile"
if ! grep esp32-camera "$idfile"; then
echo "Adding esp32-camera to $idfile"
echo " mpos/esp32-camera:
git: https://github.com/MicroPythonOS/esp32-camera" >> "$idfile"
else
echo "No need to add esp32-camera to $idfile"
fi
echo "Check need to add adc_mic to $idfile"
if ! grep adc_mic "$idfile"; then
echo "Adding adc_mic to $idfile"
echo ' espressif/adc_mic: "*"' >> "$idfile"
else
echo "No need to add adc_mic to $idfile"
fi
echo "Resulting $idfile file:"
cat "$idfile"
echo "Check need to add lvgl_micropython manifest to micropython-camera-API's manifest..."
camani="$codebasedir"/micropython-camera-API/src/manifest.py
rellvglmani=lvgl_micropython/build/manifest.py
abslvglmani="$codebasedir"/"$rellvglmani"
if ! grep "$rellvglmani" "$camani"; then
echo "Adding include(\"$abslvglmani\") to $camani"
echo >> "$camani" # needs newline because file doesn't have newline at the end
echo "include(\"$abslvglmani\") # workaround to prevent micropython-camera-API from overriding the lvgl_micropython manifest..." >> "$camani"
echo "Resulting file:"
cat "$camani"
else
echo "No need to add include(\"$abslvglmani\") to $camani"
fi
echo "Check need to add asyncio..."
manifile="$codebasedir"/lvgl_micropython/lib/micropython/ports/unix/variants/manifest.py
if ! grep asyncio "$manifile"; then
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"
echo "Resulting file:"
cat "$manifile"
else
echo "No need to add asyncio to $manifile"
fi
echo "Installing customized font sources to lvgl_micropython/lib/lvgl"
if ! cp "$codebasedir"/lvgl_micropython/lib_lvgl_src_font/* "$codebasedir"/lvgl_micropython/lib/lvgl/src/font/ ; then
echo "Could not install $codebasedir/lvgl_micropython/lib_lvgl_src_fonts/ so you probably need to update or re-clone the lvgl_micropython folder. See https://docs.micropythonos.com/os-development/"
exit 1
fi
# Remove deprecated simsun CJK fonts from the LVGL source (replaced by source-han-sans-sc).
# They contain #warning directives that fail with -Werror on the unix port.
rm -f "$codebasedir"/lvgl_micropython/lib/lvgl/src/font/lv_font_simsun_14_cjk.c
rm -f "$codebasedir"/lvgl_micropython/lib/lvgl/src/font/lv_font_simsun_16_cjk.c
# 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
echo "Applying lvgl_micropython esp32 uart repl enable/disable at runtime patch..."
pushd "$codebasedir"/lvgl_micropython/lib/micropython
patch -p1 --forward < ../../esp32_uart_repl_runtime.patch || true
popd
echo "Minifying and inlining HTML..."
pushd "$codebasedir"/webrepl/
python3 inline_minify_webrepl.py
result=$0
if [ $? -ne 0 ]; then
echo "ERROR: webrepl/inline_minify_webrepl.py failed with exit code $result, webrepl won't work"
else
mv webrepl_inlined_minified.html.gz ../internal_filesystem/builtin/html/
fi
popd
echo "Refreshing freezefs..."
"$codebasedir"/scripts/freezefs_mount_builtin.sh
if [ "$target" == "esp32" -o "$target" == "esp32s3" -o "$target" == "unphone" -o "$target" == "esp32-small" ]; then
echo "Applying lvgl_micropython esp32 inisetup warning patch..."
pushd "$codebasedir"/lvgl_micropython/lib/micropython
patch -p1 --forward < ../../esp32_inisetup_warn_and_format.patch || true
popd
partition_size="4194304"
flash_size="16"
otasupport="--ota"
extra_configs=""
if [ "$target" == "esp32" ]; then
BOARD=ESP32_GENERIC
BOARD_VARIANT=SPIRAM
elif [ "$target" == "esp32-small" ]; then
# No PSRAM, so do not set SPIRAM-specific options
BOARD=ESP32_GENERIC
BOARD_VARIANT=
partition_size="3900000"
flash_size="4"
otasupport="" # too small for 2 OTA partitions + internal storage
else # esp32s3 or unphone
if [ "$target" == "unphone" ]; then
flash_size="8"
otasupport="" # too small for 2 OTA partitions + internal storage
fi
BOARD=ESP32_GENERIC_S3
BOARD_VARIANT=SPIRAM_OCT
# 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"
# --py-freertos: add MicroPython FreeRTOS module to expose internals
#extra_configs="$extra_configs --py-freertos"
# Enable UART based REPL, in addition to the USB-CDC or JTAG REPL. Can be disabled with esp.uart_repl(False)
extra_configs="$extra_configs --enable-uart-repl=y"
fi
if [ "$BOARD_VARIANT" == "SPIRAM" -o "$BOARD_VARIANT" == "SPIRAM_OCT" ]; then
# Camera only works on boards configured with spiram, otherwise the build breaks
extra_configs="$extra_configs USER_C_MODULE=$codebasedir/micropython-camera-API/src/micropython.cmake"
fi
manifest=$(readlink -f "$codebasedir"/manifests/manifest.py)
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
echo "Note that you can also prevent the builtin filesystem from being mounted by umounting it and creating a builtin/ folder."
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
# --optimize-size: optimize for size
# --ota: support Over-The-Air updates
# --partition size: both OTA partitions are 4MB
# --flash-size: total flash size is 16MB
# --debug: enable debugging from ESP-IDF but makes copying files to it very slow so that's not added
# --dual-core-threads: disabled GIL, run code on both CPUs
# --task-stack-size={stack size in bytes}
# CONFIG_* sets ESP-IDF options
# listing processes on the esp32 still doesn't work because no esp32.vtask_list_threads() or something
# CONFIG_FREERTOS_USE_TRACE_FACILITY=y
# CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
# 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)
set -x
python3 make.py $otasupport --optimize-size --partition-size=$partition_size --flash-size=$flash_size esp32 BOARD=$BOARD BOARD_VARIANT=$BOARD_VARIANT \
USER_C_MODULE="$codebasedir"/secp256k1-embedded-ecdh/micropython.cmake \
USER_C_MODULE="$codebasedir"/c_mpos/micropython.cmake \
CONFIG_ADC_MIC_TASK_CORE=1 \
$extra_configs \
"$frozenmanifest"
set +x
popd
elif [ "$target" == "unix" -o "$target" == "macOS" ]; then
manifest=$(readlink -f "$codebasedir"/manifests/manifest.py)
frozenmanifest="FROZEN_MANIFEST=$manifest"
# Ensure WebREPL and dupterm are enabled for unix/macOS builds.
mpconfig_unix="$codebasedir"/lvgl_micropython/lib/micropython/ports/unix/mpconfigport.h
ensure_mpconfig_define() {
local name="$1"
if ! grep -q "$name" "$mpconfig_unix"; then
echo "Enabling $name in $mpconfig_unix"
python3 - "$mpconfig_unix" "$name" <<'PY'
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
name = sys.argv[2]
text = path.read_text()
needle = '#include "mpconfigvariant.h"'
insert = f"\n\n#ifndef {name}\n#define {name} (1)\n#endif\n"
if needle in text and name not in text:
path.write_text(text.replace(needle, needle + insert))
PY
else
echo "$name already configured in $mpconfig_unix"
fi
}
ensure_mpconfig_define MICROPY_PY_WEBREPL
ensure_mpconfig_define MICROPY_PY_OS_DUPTERM
# 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
sed -i.backup 's/^@micropython\.viper$/#@micropython.viper/' "$stream_wav_file"
# Suppress warnings that newer Clang (17+) treats as errors on macOS.
# GCC on Linux doesn't have -Wgnu-folding-constant so this must be skipped there.
unix_makefile="$codebasedir"/lvgl_micropython/lib/micropython/ports/unix/Makefile
if [ "$(uname -s)" = "Darwin" ]; then
echo "Temporarily suppressing Clang warnings for macOS build..."
sed -i.backup 's/^CWARN = -Wall -Werror$/CWARN = -Wall -Werror -Wno-error=gnu-folding-constant -Wno-error=missing-field-initializers/' "$unix_makefile"
fi
# If it's still running, kill it, otherwise "text file busy"
pkill -9 -f /lvgl_micropy_unix
# LV_CFLAGS are passed to USER_C_MODULES (compiler flags only, no linker flags)
# STRIP= makes it so that debug symbols are kept
pushd "$codebasedir"/lvgl_micropython/
# USER_C_MODULE doesn't seem to work properly so there are symlinks in lvgl_micropython/extmod/
# To avoid X11/Wayland being loaded dynamically at runtime, you can use: -DSDL_LOADSO=OFF
# but then those need to be provided at compile time, or excluded by using: -DSDL_WAYLAND=OFF -DSDL_X11=OFF
python3 make.py "$target" \
LV_CFLAGS="-g -O0 -ggdb" \
STRIP= \
DISPLAY=sdl_display \
INDEV=sdl_pointer \
SDL_FLAGS="-DSDL_OPENGL=OFF -DSDL_OPENGLES=OFF -DSDL_VULKAN=OFF -DSDL_KMSDRM=OFF -DSDL_IBUS=OFF -DSDL_DBUS=OFF -DSDL_ALSA=OFF -DSDL_PULSEAUDIO=OFF -DSDL_SNDIO=OFF -DSDL_LIBSAMPLERATE=OFF" \
"$frozenmanifest"
popd
# Restore @micropython.viper decorator after build
echo "Restoring @micropython.viper decorator..."
sed -i.backup 's/^#@micropython\.viper$/@micropython.viper/' "$stream_wav_file"
rm "$stream_wav_file".backup
# Restore original Makefile CWARN (only if we patched it on macOS)
if [ -f "$unix_makefile".backup ]; then
echo "Restoring unix Makefile CWARN..."
mv "$unix_makefile".backup "$unix_makefile"
fi
else
echo "invalid target $target"
fi