Skip to content

Commit a2adb0c

Browse files
Merge pull request #166 from balena-labs-projects/mtoman/rpi5
Add support for Raspberry Pi 5
2 parents c8a7cfe + 9210545 commit a2adb0c

File tree

8 files changed

+76
-19
lines changed

8 files changed

+76
-19
lines changed

Dockerfile.template

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
ARG NODEJS_VERSION="16.19.1"
22

3-
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:${NODEJS_VERSION}-bullseye-run
4-
5-
# install required packages
6-
RUN install_packages \
7-
chromium-common \
8-
chromium \
9-
libgles2-mesa \
10-
lsb-release \
11-
mesa-vdpau-drivers \
12-
scrot \
13-
x11-xserver-utils \
14-
xserver-xorg-input-evdev \
15-
xserver-xorg-legacy \
16-
xserver-xorg-video-fbdev \
17-
xserver-xorg xinit \
18-
xinput \
19-
xterm
3+
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-node:${NODEJS_VERSION}-bookworm-run
4+
5+
# Install the necessary packages
6+
COPY ./build /usr/src/build
7+
RUN /usr/src/build/install_chromium "%%BALENA_MACHINE_NAME%%"
208

219
WORKDIR /usr/src/app
2210

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

48-
RUN ln -s /usr/bin/chromium /usr/bin/chromium-browser || true
49-
5036
# Set up the audio block. This won't have any effect if the audio block is not being used.
5137
RUN curl -skL https://raw.githubusercontent.com/balena-labs-projects/audio/master/scripts/alsa-bridge/debian-setup.sh| sh
5238
ENV PULSE_SERVER=tcp:audio:4317

balena.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ data:
5151
- raspberrypi3
5252
- raspberrypi3-64
5353
- raspberrypi400-64
54+
- raspberrypi5
5455
- intel-nuc
5556
- genericx86-64-ext

build/install_chromium

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# This script will install chromium to use with the browser block
4+
# If the device is a Raspberry Pi (any model), it will use the version
5+
# from the raspios repo (together with mesa and X), because
6+
# * Since Debian 12, the upstream chromium provided in Debian repos
7+
# does not work on armv7 at all
8+
# * The upstream chromium will not work on devices with < 1GB memory
9+
# namely the Pi3A and the PiZero2 even when using aarch64
10+
# * The Raspberry Pi 5 needs patched versions of mesa and X to work
11+
12+
BASE_DIR="/usr/src/build"
13+
CHROMIUM_PACKAGE="chromium"
14+
15+
MACHINE_NAME="$1"
16+
17+
# FORCE_RPI_REPO=0 never includes the repo
18+
# FORCE_RPI_REPO=1 always includes the repo
19+
# If the machine name starts with "raspberry", or if the machine
20+
# is a balenaFin, include the repo
21+
if [ "${FORCE_RPI_REPO}" != "0" ] && [ "${FORCE_RPI_REPO}" = "1" -o "${MACHINE_NAME:0:9}" = "raspberry" -o "${MACHINE_NAME}" = "fincm3" ]
22+
then
23+
echo "Enabling raspios repository"
24+
25+
cp -a "${BASE_DIR}/rpi/raspi.list" "/etc/apt/sources.list.d/"
26+
cp -a "${BASE_DIR}/rpi/raspberrypi-archive-stable.gpg" "/etc/apt/trusted.gpg.d/"
27+
28+
# The RPi-patched chromium package is called chromium-browser
29+
CHROMIUM_PACKAGE="chromium-browser"
30+
else
31+
# The node library launches /usr/bin/chromium-browser
32+
# which is not provided by the upstream package
33+
ln -s /usr/bin/chromium /usr/bin/chromium-browser
34+
fi
35+
36+
install_packages \
37+
${CHROMIUM_PACKAGE} \
38+
chromium-common \
39+
libgles2-mesa \
40+
lsb-release \
41+
mesa-vdpau-drivers \
42+
scrot \
43+
x11-xserver-utils \
44+
xserver-xorg-input-evdev \
45+
xserver-xorg-legacy \
46+
xserver-xorg-video-fbdev \
47+
xserver-xorg xinit \
48+
xinput \
49+
xterm

build/rpi/99-vc4.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Section "OutputClass"
2+
Identifier "vc4"
3+
MatchDriver "vc4"
4+
Driver "modesetting"
5+
Option "PrimaryGPU" "true"
6+
EndSection
1.16 KB
Binary file not shown.

build/rpi/raspi.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
deb http://archive.raspberrypi.com/debian/ bookworm main
2+
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
3+
#deb-src http://archive.raspberrypi.com/debian/ bookworm main

src/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ let launchChromium = async function(url) {
167167
ignoreDefaultFlags: true,
168168
chromeFlags: flags,
169169
port: REMOTE_DEBUG_PORT,
170+
connectionPollInterval: 1000,
171+
maxConnectionRetries: 120,
170172
userDataDir: '1' === PERSISTENT_DATA ? '/data/chromium' : undefined
171173
});
172174

src/start.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ then
4444
fi
4545
fi
4646

47+
# Inject X11 config on the RPi 5 as the defaults do not work
48+
# We do this in the startup script and only for the RPi 5 because
49+
# we build the images per-architecture and we do not want to break
50+
# other aarch64-based device types
51+
if [ "${BALENA_DEVICE_TYPE}" = "raspberrypi5" ]
52+
then
53+
echo "Raspberry Pi 5 detected, injecting X.org config"
54+
cp -a "/usr/src/build/rpi/99-vc4.conf" "/etc/X11/xorg.conf.d/"
55+
fi
56+
4757
# set up the user data area
4858
mkdir -p /data/chromium
4959
chown -R chromium:chromium /data

0 commit comments

Comments
 (0)