Skip to content

Commit

Permalink
Add support for Raspberry Pi 5
Browse files Browse the repository at this point in the history
The Raspberry Pi 5 does not work with upstream mesa or X server,
it needs a bump to Debian 12 and packages from raspios repos.

Change-type: minor
Signed-off-by: Michal Toman <[email protected]>
  • Loading branch information
mtoman committed Jan 11, 2024
1 parent c8a7cfe commit 9210545
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 19 deletions.
24 changes: 5 additions & 19 deletions Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
ARG NODEJS_VERSION="16.19.1"

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:${NODEJS_VERSION}-bullseye-run

# install required packages
RUN install_packages \
chromium-common \
chromium \
libgles2-mesa \
lsb-release \
mesa-vdpau-drivers \
scrot \
x11-xserver-utils \
xserver-xorg-input-evdev \
xserver-xorg-legacy \
xserver-xorg-video-fbdev \
xserver-xorg xinit \
xinput \
xterm
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:${NODEJS_VERSION}-bookworm-run

# Install the necessary packages
COPY ./build /usr/src/build
RUN /usr/src/build/install_chromium "%%BALENA_MACHINE_NAME%%"

WORKDIR /usr/src/app

Expand Down Expand Up @@ -45,8 +33,6 @@ COPY ./public-html /home/chromium
RUN echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
RUN usermod -a -G audio,video,tty chromium

RUN ln -s /usr/bin/chromium /usr/bin/chromium-browser || true

# Set up the audio block. This won't have any effect if the audio block is not being used.
RUN curl -skL https://raw.githubusercontent.com/balena-labs-projects/audio/master/scripts/alsa-bridge/debian-setup.sh| sh
ENV PULSE_SERVER=tcp:audio:4317
Expand Down
1 change: 1 addition & 0 deletions balena.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ data:
- raspberrypi3
- raspberrypi3-64
- raspberrypi400-64
- raspberrypi5
- intel-nuc
- genericx86-64-ext
49 changes: 49 additions & 0 deletions build/install_chromium
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# This script will install chromium to use with the browser block
# If the device is a Raspberry Pi (any model), it will use the version
# from the raspios repo (together with mesa and X), because
# * Since Debian 12, the upstream chromium provided in Debian repos
# does not work on armv7 at all
# * The upstream chromium will not work on devices with < 1GB memory
# namely the Pi3A and the PiZero2 even when using aarch64
# * The Raspberry Pi 5 needs patched versions of mesa and X to work

BASE_DIR="/usr/src/build"
CHROMIUM_PACKAGE="chromium"

MACHINE_NAME="$1"

# FORCE_RPI_REPO=0 never includes the repo
# FORCE_RPI_REPO=1 always includes the repo
# If the machine name starts with "raspberry", or if the machine
# is a balenaFin, include the repo
if [ "${FORCE_RPI_REPO}" != "0" ] && [ "${FORCE_RPI_REPO}" = "1" -o "${MACHINE_NAME:0:9}" = "raspberry" -o "${MACHINE_NAME}" = "fincm3" ]
then
echo "Enabling raspios repository"

cp -a "${BASE_DIR}/rpi/raspi.list" "/etc/apt/sources.list.d/"
cp -a "${BASE_DIR}/rpi/raspberrypi-archive-stable.gpg" "/etc/apt/trusted.gpg.d/"

# The RPi-patched chromium package is called chromium-browser
CHROMIUM_PACKAGE="chromium-browser"
else
# The node library launches /usr/bin/chromium-browser
# which is not provided by the upstream package
ln -s /usr/bin/chromium /usr/bin/chromium-browser
fi

install_packages \
${CHROMIUM_PACKAGE} \
chromium-common \
libgles2-mesa \
lsb-release \
mesa-vdpau-drivers \
scrot \
x11-xserver-utils \
xserver-xorg-input-evdev \
xserver-xorg-legacy \
xserver-xorg-video-fbdev \
xserver-xorg xinit \
xinput \
xterm
6 changes: 6 additions & 0 deletions build/rpi/99-vc4.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Section "OutputClass"
Identifier "vc4"
MatchDriver "vc4"
Driver "modesetting"
Option "PrimaryGPU" "true"
EndSection
Binary file added build/rpi/raspberrypi-archive-stable.gpg
Binary file not shown.
3 changes: 3 additions & 0 deletions build/rpi/raspi.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
deb http://archive.raspberrypi.com/debian/ bookworm main
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.com/debian/ bookworm main
2 changes: 2 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ let launchChromium = async function(url) {
ignoreDefaultFlags: true,
chromeFlags: flags,
port: REMOTE_DEBUG_PORT,
connectionPollInterval: 1000,
maxConnectionRetries: 120,
userDataDir: '1' === PERSISTENT_DATA ? '/data/chromium' : undefined
});

Expand Down
10 changes: 10 additions & 0 deletions src/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ then
fi
fi

# Inject X11 config on the RPi 5 as the defaults do not work
# We do this in the startup script and only for the RPi 5 because
# we build the images per-architecture and we do not want to break
# other aarch64-based device types
if [ "${BALENA_DEVICE_TYPE}" = "raspberrypi5" ]
then
echo "Raspberry Pi 5 detected, injecting X.org config"
cp -a "/usr/src/build/rpi/99-vc4.conf" "/etc/X11/xorg.conf.d/"
fi

# set up the user data area
mkdir -p /data/chromium
chown -R chromium:chromium /data
Expand Down

0 comments on commit 9210545

Please sign in to comment.