Skip to content
4 changes: 2 additions & 2 deletions software/firmware/europi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down Expand Up @@ -127,6 +125,8 @@ 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}
Expand Down
6 changes: 3 additions & 3 deletions software/firmware/experimental/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
7 changes: 4 additions & 3 deletions software/uf2_build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.29.0 --depth=1 --recursive https://github.com/micropython/micropython.git

WORKDIR micropython

Expand All @@ -25,7 +25,8 @@ 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 /

ENTRYPOINT [ "sh", "copy_and_compile.sh" ]
ENTRYPOINT [ "bash", "copy_and_compile.sh" ]
46 changes: 36 additions & 10 deletions software/uf2_build/copy_and_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,47 @@ 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

echo "Compiling micropython and firmware modules..."
cd /micropython/ports/rp2
# 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

# 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: 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"

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
55 changes: 55 additions & 0 deletions software/uf2_build/strip_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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])
Loading