Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 111 additions & 43 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#syntax=docker/dockerfile:1.4
# Global config
ARG toltec_image=ghcr.io/toltec-dev/base:v3.1
ARG rm2_stuff_tag=v0.1.2
Expand All @@ -11,13 +12,29 @@ ARG linux_image=ghcr.io/timower/rm-docker-linux:main
# Step 1: Build Linux for the emulator
FROM $toltec_image AS linux-builder

RUN apt-get update && \
apt-get install -y bison bc lzop libssl-dev flex
RUN <<EOT
set -ex
export DEBIAN_FRONTEND="noninteractive"
apt-get update
apt-get install -y \
bison \
bc \
lzop \
libssl-dev \
flex
rm -rf /var/lib/apt/lists/*
EOT

ARG linux_release

RUN curl -o linux.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$linux_release.tar.xz && \
mkdir -p /opt/linux && cd /opt/linux && tar -xf /linux.tar.xz && rm /linux.tar.xz
RUN <<EOT
set -ex
curl -o linux.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$linux_release.tar.xz
mkdir -p /opt/linux
cd /opt/linux
tar -xf /linux.tar.xz
rm /linux.tar.xz
EOT

WORKDIR /opt/linux/linux-$linux_release

Expand All @@ -26,15 +43,17 @@ ADD ./imx7d-rm.dts arch/arm/boot/dts/
RUN sed -i 's/imx7d-sbc-imx7.dtb/imx7d-sbc-imx7.dtb imx7d-rm.dtb/' arch/arm/boot/dts/Makefile

# Default imx7 config, enable uinput and disable all modules
RUN make O=imx7 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v6_v7_defconfig && \
sed -i 's/# CONFIG_INPUT_UINPUT is not set/CONFIG_INPUT_UINPUT=y/' imx7/.config && \
sed -i 's/=m/=n/' imx7/.config

# Build, Copy the output files and clean
RUN make O=imx7 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j $(nproc) && \
cp imx7/arch/arm/boot/zImage /opt && \
cp imx7/arch/arm/boot/dts/imx7d-rm.dtb /opt && \
RUN <<EOT
set -ex
make O=imx7 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v6_v7_defconfig
sed -i 's/# CONFIG_INPUT_UINPUT is not set/CONFIG_INPUT_UINPUT=y/' imx7/.config
sed -i 's/=m/=n/' imx7/.config
make O=imx7 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j $(nproc)
cp imx7/arch/arm/boot/zImage /opt
cp imx7/arch/arm/boot/dts/imx7d-rm.dtb /opt
rm -rf imx7
EOT

# This container just needs to kernel and device tree
FROM scratch AS linux-build
Expand All @@ -52,20 +71,27 @@ ARG TARGETARCH
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Install dependencies
RUN apt-get update && \
RUN <<EOT
set -ex
apt-get update
apt-get install -y --no-install-recommends \
git \
build-essential \
pkg-config \
fuse \
libfuse-dev \
libz-dev && \
libz-dev
rm -rf /var/lib/apt/lists/*
uv venv --python 3.13
EOT

ARG fw_version
RUN uv pip install https://github.com/Jayy001/codexctl.git && \
.venv/bin/codexctl download $fw_version --hardware rm2 --out /tmp/firmware && \
RUN <<EOT
set -ex
uv pip install https://github.com/Jayy001/codexctl.git
.venv/bin/codexctl download $fw_version --hardware rm2 --out /tmp/firmware
.venv/bin/codexctl extract --out /opt/rootfs.ext4 /tmp/firmware/*
EOT

# Make the rootfs image
ADD make_rootfs.sh /opt
Expand All @@ -74,10 +100,14 @@ RUN ./make_rootfs.sh /opt/rootfs.ext4 $fw_version
# Step3: Qemu!
FROM debian:bookworm AS qemu-debug

RUN apt-get update && \
RUN <<EOT
set -ex
export DEBIAN_FRONTEND="noninteractive"
apt-get update
apt-get install --no-install-recommends -y qemu-system-arm qemu-utils ssh netcat-openbsd

RUN mkdir -p /opt/root
rm -rf /var/lib/apt/lists/*
mkdir -p /opt/root
EOT

COPY --from=linux-image /zImage /opt
COPY --from=linux-image /imx7d-rm.dtb /opt
Expand All @@ -89,11 +119,14 @@ ENV PATH=/opt/bin:$PATH
FROM qemu-debug AS qemu-base

# First boot, disable xochitl and reboot service, and save state
RUN run_vm -serial null -daemonize && \
wait_ssh && \
in_vm systemctl mask remarkable-fail && \
in_vm systemctl mask xochitl && \
RUN <<EOT
set -ex
run_vm -serial null -daemonize
wait_ssh
in_vm systemctl mask remarkable-fail
in_vm systemctl mask xochitl
save_vm
EOT

# Mount to presist rootfs
VOLUME /opt/root
Expand All @@ -113,29 +146,53 @@ FROM qemu-base AS qemu-toltec
# * Firsts make sure the time is synced, so https works correctly.
# * Next, make sure home is mounted, as xochitl does it since they introduced encrypted data.
# * Finally, download and run the bootstrap script.
RUN run_vm -serial null -daemonize && \
wait_ssh && \
in_vm 'while ! timedatectl status | grep "synchronized: yes"; do sleep 1; done' && \
in_vm 'systemctl is-active home.mount || mount /dev/mmcblk2p4 /home' && \
in_vm wget https://raw.githubusercontent.com/timower/toltec/refs/heads/feat/wget-update/scripts/bootstrap/bootstrap && \
in_vm env bash bootstrap --force && \
RUN <<EOT
set -ex
run_vm -serial null -daemonize
wait_ssh
in_vm 'while ! timedatectl status | grep "synchronized: yes"; do sleep 1; done'
in_vm 'systemctl is-active home.mount || mount /dev/mmcblk2p4 /home'
in_vm wget https://raw.githubusercontent.com/timower/toltec/refs/heads/feat/wget-update/scripts/bootstrap/bootstrap
in_vm env bash bootstrap --force
in_vm rm bootstrap
save_vm
EOT

# Step 4: Build rm2fb-emu for the debian host...
FROM debian:bookworm AS rm2fb-host

RUN apt-get update && \
apt-get install -y git clang cmake ninja-build libsdl2-dev libevdev-dev libsystemd-dev

RUN apt-get install -y xxd git-lfs
RUN <<EOT
set -ex
apt-get update
apt-get install -y \
git \
clang \
cmake \
ninja-build \
libsdl2-dev \
libevdev-dev \
libsystemd-dev \
xxd \
git-lfs
rm -rf /var/lib/apt/lists/*
EOT

ARG rm2_stuff_tag
RUN mkdir -p /opt && \
git clone https://github.com/timower/rM2-stuff.git /opt/rm2-stuff && \
cd /opt/rm2-stuff && git reset --hard $rm2_stuff_tag && git lfs pull
RUN <<EOT
set -ex
mkdir -p /opt
git clone https://github.com/timower/rM2-stuff.git /opt/rm2-stuff
cd /opt/rm2-stuff
git reset --hard $rm2_stuff_tag
git lfs pull
EOT
WORKDIR /opt/rm2-stuff

RUN cmake --preset dev-host && cmake --build build/host --target rm2fb-emu
RUN <<EOT
set -ex
cmake --preset dev-host
cmake --build build/host --target rm2fb-emu
EOT

# Step 5: Integrate
FROM qemu-toltec AS qemu-rm2fb
Expand All @@ -145,13 +202,24 @@ RUN mkdir -p /opt/rm2fb
COPY --from=rm2fb-host /opt/rm2-stuff/build/host/tools/rm2fb-emu/rm2fb-emu /opt/bin

ARG rm2_stuff_tag
RUN run_vm -serial null -daemonize && \
wait_ssh && \
in_vm wget https://github.com/timower/rM2-stuff/releases/download/$rm2_stuff_tag/rm2display.ipk && \
in_vm opkg install rm2display.ipk && \
RUN <<EOT
set -ex
run_vm -serial null -daemonize
wait_ssh
in_vm wget https://github.com/timower/rM2-stuff/releases/download/$rm2_stuff_tag/rm2display.ipk
in_vm opkg install rm2display.ipk
in_vm rm rm2display.ipk
save_vm

RUN apt-get update && \
apt-get install -y libevdev2 libsdl2-2.0-0
EOT

RUN <<EOT
set -ex
export DEBIAN_FRONTEND="noninteractive"
apt-get update
apt-get install -y \
libevdev2 \
libsdl2-2.0-0
rm -rf /var/lib/apt/lists/*
EOT

CMD run_xochitl
Loading