From baee4197f1ccdddc520229a6015f62f59c6c091b Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Sat, 20 Sep 2025 15:53:38 -0400 Subject: [PATCH 01/10] Move imports to hopefully lower memory footprint on non-wifi models --- software/firmware/europi.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 056386a88..5a34869fd 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -30,7 +30,6 @@ from version import __version__ -from configuration import ConfigSettings from framebuf import FrameBuffer, MONO_HLSB from europi_config import load_europi_config, MODEL_PICO_2W, MODEL_PICO_W @@ -39,7 +38,6 @@ from europi_log import * from experimental.experimental_config import load_experimental_config -from experimental.wifi import WifiConnection, WifiError if sys.implementation.name == "micropython": @@ -127,6 +125,7 @@ def bootsplash(): # Connect to wifi, if supported if europi_config.PICO_MODEL == MODEL_PICO_W or europi_config.PICO_MODEL == MODEL_PICO_2W: try: + from experimental.wifi import WifiConnection, WifiError oled.centre_text( f"""WiFi connecting {experimental_config.WIFI_SSID} From efdedb4b838a75fd4708e12d409fd1635f5e9d02 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Tue, 25 Nov 2025 17:18:34 -0500 Subject: [PATCH 02/10] Linting --- software/firmware/europi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 5a34869fd..c0b3e968f 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -126,6 +126,7 @@ def bootsplash(): if europi_config.PICO_MODEL == MODEL_PICO_W or europi_config.PICO_MODEL == MODEL_PICO_2W: try: from experimental.wifi import WifiConnection, WifiError + oled.centre_text( f"""WiFi connecting {experimental_config.WIFI_SSID} From f8f69894648cec7f3265ddd176ff6134e3e1e1e6 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Thu, 11 Jun 2026 19:00:23 -0400 Subject: [PATCH 03/10] Upgrade micropython version used when building UF2 files. Strip comments and docstrings from bundled files to reduce disk usage --- software/uf2_build/Dockerfile | 5 ++- software/uf2_build/copy_and_compile.sh | 20 ++++++++-- software/uf2_build/strip_python.py | 51 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 software/uf2_build/strip_python.py diff --git a/software/uf2_build/Dockerfile b/software/uf2_build/Dockerfile index 8cc017209..f766235e6 100644 --- a/software/uf2_build/Dockerfile +++ b/software/uf2_build/Dockerfile @@ -3,11 +3,11 @@ FROM ubuntu:22.04 ENV TERM=xterm DEBIAN_FRONTEND=noninteractive RUN apt update && apt install -y \ - cmake git-core gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential wget python3 + cmake git-core gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential wget python3 sed WORKDIR / -RUN git clone -b v1.25.0 --depth=1 --recursive https://github.com/micropython/micropython.git +RUN git clone -b v1.28.0 --depth=1 --recursive https://github.com/micropython/micropython.git WORKDIR micropython @@ -25,6 +25,7 @@ BootloaderMenu(EUROPI_SCRIPTS).main()\n\ ' > ports/rp2/modules/main.py COPY software/uf2_build/copy_and_compile.sh / +COPY software/uf2_build/strip_python.py / WORKDIR / diff --git a/software/uf2_build/copy_and_compile.sh b/software/uf2_build/copy_and_compile.sh index 8ab4d0266..4606c8679 100644 --- a/software/uf2_build/copy_and_compile.sh +++ b/software/uf2_build/copy_and_compile.sh @@ -5,10 +5,22 @@ echo "Copying EuroPi firmware and scripts to container..." mkdir /micropython/ports/rp2/modules/contrib mkdir /micropython/ports/rp2/modules/experimental mkdir /micropython/ports/rp2/modules/tools -cp -r europi/software/firmware/*.py /micropython/ports/rp2/modules -cp -r europi/software/firmware/experimental/*.py /micropython/ports/rp2/modules/experimental -cp -r europi/software/firmware/tools/*.py /micropython/ports/rp2/modules/tools -cp -r europi/software/contrib/*.py /micropython/ports/rp2/modules/contrib +for pyfile in $(ls europi/software/firmware/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/$f" +done +for pyfile in $(ls europi/software/firmware/experimental/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/experimental/$f" +done +for pyfile in $(ls europi/software/firmware/tools/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/tools/$f" +done +for pyfile in $(ls europi/software/contrib/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/contrib/$f" +done echo "Compiling micropython and firmware modules..." cd /micropython/ports/rp2 diff --git a/software/uf2_build/strip_python.py b/software/uf2_build/strip_python.py new file mode 100644 index 000000000..a8cadcc13 --- /dev/null +++ b/software/uf2_build/strip_python.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +""" +Strip comments and docstrings from a file. + +Copied from https://gist.github.com/BroHui/aca2b8e6e6bdf3cb4af4b246c9837fa3 with modifications. +""" + +import sys, token, tokenize + + +def process_file(infile, outfile): + """ + Remove comments and docstrings from one file and write the result to another. + + @param infile The path to the file to process + @param outfile The path to the file we're generating + """ + source = open(infile, "r") + mod = open(outfile, "w") + + prev_toktype = token.INDENT + last_lineno = -1 + last_col = 0 + + tokgen = tokenize.generate_tokens(source.readline) + for toktype, ttext, (slineno, scol), (elineno, ecol), ltext in tokgen: + if 0: # Change to if 1 to see the tokens fly by. + print("%10s %-14s %-20r %r" % ( + tokenize.tok_name.get(toktype, toktype), + "%d.%d-%d.%d" % (slineno, scol, elineno, ecol), + ttext, ltext + )) + if slineno > last_lineno: + last_col = 0 + if scol > last_col: + mod.write(" " * (scol - last_col)) + if toktype == token.STRING and prev_toktype == token.INDENT: + # Docstring + mod.write("#--") + elif toktype == tokenize.COMMENT: + # Comment + mod.write("##") + else: + mod.write(ttext) + prev_toktype = toktype + last_col = ecol + last_lineno = elineno + + +if __name__ == '__main__': + process_file(sys.argv[1], sys.argv[2]) From 6a2b2d109f24d5cb8db74bca1da46bb3478fca70 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Sun, 28 Jun 2026 15:38:26 -0400 Subject: [PATCH 04/10] Fix quotation marks --- software/uf2_build/strip_python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/software/uf2_build/strip_python.py b/software/uf2_build/strip_python.py index a8cadcc13..97e73cf77 100644 --- a/software/uf2_build/strip_python.py +++ b/software/uf2_build/strip_python.py @@ -47,5 +47,5 @@ def process_file(infile, outfile): last_lineno = elineno -if __name__ == '__main__': +if __name__ == "__main__": process_file(sys.argv[1], sys.argv[2]) From ee9899ebdbe6f4704e7dbe9d15266f1f5a0393f2 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Sun, 28 Jun 2026 15:45:52 -0400 Subject: [PATCH 05/10] Linting of the strip_python script --- software/uf2_build/strip_python.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/software/uf2_build/strip_python.py b/software/uf2_build/strip_python.py index 97e73cf77..ed9fdfcec 100644 --- a/software/uf2_build/strip_python.py +++ b/software/uf2_build/strip_python.py @@ -24,12 +24,16 @@ def process_file(infile, outfile): tokgen = tokenize.generate_tokens(source.readline) for toktype, ttext, (slineno, scol), (elineno, ecol), ltext in tokgen: - if 0: # Change to if 1 to see the tokens fly by. - print("%10s %-14s %-20r %r" % ( - tokenize.tok_name.get(toktype, toktype), - "%d.%d-%d.%d" % (slineno, scol, elineno, ecol), - ttext, ltext - )) + if 0: # Change to if 1 to see the tokens fly by. + print( + "%10s %-14s %-20r %r" + % ( + tokenize.tok_name.get(toktype, toktype), + "%d.%d-%d.%d" % (slineno, scol, elineno, ecol), + ttext, + ltext, + ) + ) if slineno > last_lineno: last_col = 0 if scol > last_col: From fb7f12eaab20a3120aee123d29a2cbe212c1cd28 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Sat, 4 Jul 2026 13:12:00 -0400 Subject: [PATCH 06/10] Reduce code duplication in copy_and_compile.sh, use bash instead of sh for the entrypoint shell --- software/uf2_build/Dockerfile | 2 +- software/uf2_build/copy_and_compile.sh | 38 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/software/uf2_build/Dockerfile b/software/uf2_build/Dockerfile index f766235e6..00e74fe16 100644 --- a/software/uf2_build/Dockerfile +++ b/software/uf2_build/Dockerfile @@ -29,4 +29,4 @@ COPY software/uf2_build/strip_python.py / WORKDIR / -ENTRYPOINT [ "sh", "copy_and_compile.sh" ] +ENTRYPOINT [ "bash", "copy_and_compile.sh" ] diff --git a/software/uf2_build/copy_and_compile.sh b/software/uf2_build/copy_and_compile.sh index 4606c8679..b4920e7bf 100644 --- a/software/uf2_build/copy_and_compile.sh +++ b/software/uf2_build/copy_and_compile.sh @@ -5,21 +5,29 @@ echo "Copying EuroPi firmware and scripts to container..." mkdir /micropython/ports/rp2/modules/contrib mkdir /micropython/ports/rp2/modules/experimental mkdir /micropython/ports/rp2/modules/tools -for pyfile in $(ls europi/software/firmware/*.py); do - f=$(basename $pyfile) - python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/$f" -done -for pyfile in $(ls europi/software/firmware/experimental/*.py); do - f=$(basename $pyfile) - python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/experimental/$f" -done -for pyfile in $(ls europi/software/firmware/tools/*.py); do - f=$(basename $pyfile) - python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/tools/$f" -done -for pyfile in $(ls europi/software/contrib/*.py); do - f=$(basename $pyfile) - python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/contrib/$f" + +# Directories we copy stripped Python files _from_ +SRC_DIRS=(europi/software/firmware +europi/software/firmware/experimental +europi/software/firmware/tools +europi/software/contrib) + +# Directories we copy stripped Python files _to_ +# Order must match SRC_DIRS +DST_DIRS=(/micropython/ports/rp2/modules +/micropython/ports/rp2/modules/experimental +/micropython/ports/rp2/modules/tools +/micropython/ports/rp2/modules/contrib) + +for i in ${!SRC_DIRS[@]}; do + src_dir=${SRC_DIRS[i]} + dst_dir=${DST_DIRS[i]} + + for pyfile in $(ls ${src_dir}/*.py); do + f=$(basename $pyfile) + echo "Stripping $pyfile -> $dst_dir" + python3 /strip_python.py $pyfile ${dst_dir}/$f + done done echo "Compiling micropython and firmware modules..." From 339811996c27aa42cab591fd42e814cf1d4e6806 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Sat, 4 Jul 2026 22:36:07 -0400 Subject: [PATCH 07/10] Change the order of the boards, remove stale TODO, add a new TODO --- software/uf2_build/copy_and_compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/software/uf2_build/copy_and_compile.sh b/software/uf2_build/copy_and_compile.sh index b4920e7bf..d3fc1b738 100644 --- a/software/uf2_build/copy_and_compile.sh +++ b/software/uf2_build/copy_and_compile.sh @@ -34,8 +34,8 @@ echo "Compiling micropython and firmware modules..." cd /micropython/ports/rp2 # Pico W must be last; we need to remove some code to make it fit -# TODO: add RPI_PICO2_W once it's supported -BOARDS="RPI_PICO RPI_PICO2 RPI_PICO_W RPI_PICO2_W" +# TODO: What do we actually need to remove? +BOARDS="RPI_PICO2 RPI_PICO RPI_PICO2_W RPI_PICO_W" for b in $BOARDS; do echo "make BOARD=$b" From 6037ff9eac8594dc2b3b7a2bab1175a05c9c3916 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Mon, 7 Sep 2026 08:16:51 -0400 Subject: [PATCH 08/10] Bump micropython version for UF2 builds 1.28.0 -> 1.29.0 --- software/uf2_build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/software/uf2_build/Dockerfile b/software/uf2_build/Dockerfile index 00e74fe16..770e8201e 100644 --- a/software/uf2_build/Dockerfile +++ b/software/uf2_build/Dockerfile @@ -7,7 +7,7 @@ RUN apt update && apt install -y \ WORKDIR / -RUN git clone -b v1.28.0 --depth=1 --recursive https://github.com/micropython/micropython.git +RUN git clone -b v1.29.0 --depth=1 --recursive https://github.com/micropython/micropython.git WORKDIR micropython From 00ffbee21f396532bbfc9cc29580ef172f527791 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Mon, 7 Sep 2026 08:51:37 -0400 Subject: [PATCH 09/10] Include the EuroPi version number in the UF2 filename --- software/uf2_build/copy_and_compile.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/software/uf2_build/copy_and_compile.sh b/software/uf2_build/copy_and_compile.sh index d3fc1b738..1f60849ac 100644 --- a/software/uf2_build/copy_and_compile.sh +++ b/software/uf2_build/copy_and_compile.sh @@ -30,16 +30,22 @@ for i in ${!SRC_DIRS[@]}; do done done -echo "Compiling micropython and firmware modules..." -cd /micropython/ports/rp2 +# Extract the version number from the Python module +VERSION=$(python3 -c "import importlib.util; import sys; spec=importlib.util.spec_from_file_location('europi_version', '/micropython/ports/rp2/modules/version.py'); module=importlib.util.module_from_spec(spec); sys.modules['europi_version']=module; spec.loader.exec_module(module); print(module.__version__)") # Pico W must be last; we need to remove some code to make it fit # TODO: What do we actually need to remove? BOARDS="RPI_PICO2 RPI_PICO RPI_PICO2_W RPI_PICO_W" +echo +echo "==== BEGIN COMPILE ====" +echo "Compiling micropython and firmware modules for EuroPi $VERSION..." +echo + +cd /micropython/ports/rp2 for b in $BOARDS; do echo "make BOARD=$b" make BOARD=$b - echo "Moving firmware file to /europi/software/uf2_build/europi-$b-dev.uf2" - mv build-$b/firmware.uf2 /europi/software/uf2_build/europi-$b-dev.uf2 + echo "Moving firmware file to /europi/software/uf2_build/europi-$b-$VERSION.uf2" + mv build-$b/firmware.uf2 /europi/software/uf2_build/europi-$b-$VERSION.uf2 done From 1b85f775bc9856dfafd94752e18933bf57845d39 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Tue, 8 Sep 2026 19:42:44 -0400 Subject: [PATCH 10/10] Fix case for utf-8 encoding --- software/firmware/experimental/http_server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/software/firmware/experimental/http_server.py b/software/firmware/experimental/http_server.py index bc12e7a91..876c437b7 100644 --- a/software/firmware/experimental/http_server.py +++ b/software/firmware/experimental/http_server.py @@ -250,7 +250,7 @@ def check_requests(self): # Priority: u=0, i request = conn.recv(1024) - request = request.decode("UTF-8") + request = request.decode("utf-8") if request.startswith("GET"): self.get_callback(request=request, connection=conn) @@ -391,5 +391,5 @@ def send_response( for k in headers.keys(): header = f"{header}\r\n{k}={headers[k]}" - connection.send(f"{header}\r\n\r\n".encode("UTF-8")) - connection.send(response.encode("UTF-8")) + connection.send(f"{header}\r\n\r\n".encode("utf-8")) + connection.send(response.encode("utf-8"))