Skip to content

Commit 8e1016d

Browse files
agnerssairon
andauthored
Initial Raspberry Pi 5 support (#2914)
* Add initial Raspberry Pi 5 buildroot config * Add machine-id support via cmdline.txt * Add new entry if entry is missing * Don't overwrite cmdline.txt when adding machine-id Use sed to append the new cmdline parameter to the first line. * Skeleton script for RAUC custom bootloader interface * Deploy kernel/device-tree into a RAUC slot specific directory This allows us to use the os_prefix feature to switch between slot A and B. Compared to the boot_partition option, this option allows to use a shared config.txt and cmdline.txt, which makes it more like how HAOS currently works on other Raspberry Pis. * Deploy new kernel/device-tree to correct slot on installation * Increase boot size to 128MB This makes sure we can store up to three kernels (slot A, B and an temporary one while installing the OTA update). * Initial tryboot implementation using os_prefix * Make sure to delete the old slot completely * Add Busybox xargs for tryboot bootloader script * Compare tryboot bootloader file silently * Revert "Increase boot size to 128MB" This reverts commit 7f2c69b. * Use compressed kernel * Address shellcheck * Address shellcheck issue in rauc-hook * Fix shellcheck for rpi-tryboot.sh * Do not follow source - it gets checked separately * Correctly set the slot to boot * Apply suggestions from code review Co-authored-by: Jan Čermák <[email protected]> * Drop serial console from default cmdline.txt * Resync rpi5_64_defconfig with rpi4_64_defconfig * Improve machine-id match Only match actual hexadecimal characters. * Deploy firmware overlays to OS prefix directory * Add Raspberry Pi 5 to documentation * Bump buildroot * buildroot fd1dc86f40...f13ad03408 (1): > linux: add in-tree device tree overlay support * Install device tree overlays from Kernel sources * Drop RPi RF modules for now No Raspberry Pi 5 specific device tree overlays are available, drop RPi RF mod for now. * Use Raspberry 5 specific identifiers for Supervisor/OS Agent * Bump buildroot * buildroot f13ad03408...07e08e01b2 (1): > linux: fix add in-tree device tree overlay support * Revert "Drop RPi RF modules for now" This reverts commit 46fc170. --------- Co-authored-by: Jan Čermák <[email protected]>
1 parent ac089a2 commit 8e1016d

File tree

16 files changed

+406
-11
lines changed

16 files changed

+406
-11
lines changed

Documentation/boards/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
The following boards/devices are supported:
66

77
- Raspberry Pi
8+
- Pi 5 ([4 GB](https://www.raspberrypi.com/products/raspberry-pi-5/?variant=raspberry-pi-5-4gb) and [8 GB](https://www.raspberrypi.com/products/raspberry-pi-5/?variant=raspberry-pi-5-8gb) model) 64-bit
89
- Pi 4 Model B ([1 GB](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/?variant=raspberry-pi-4-model-b-1gb), [2 GB](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/?variant=raspberry-pi-4-model-b-2gb), [4 GB](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/?variant=raspberry-pi-4-model-b-4gb) and [8 GB](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/?variant=raspberry-pi-4-model-b-8gb) model) 32-bit or 64-bit (recommended)
910
- [Pi 3 Model B](https://www.raspberrypi.com/products/raspberry-pi-3-model-b/) and [B+](https://www.raspberrypi.com/products/raspberry-pi-3-model-b-plus/) 32-bit or 64-bit (recommended)
1011
- [Pi 2](https://www.raspberrypi.com/products/raspberry-pi-2-model-b/) (not recommended)
@@ -39,6 +40,7 @@ Notes:
3940

4041
|Board|Build|Config|Docs|
4142
|-----|----|------|----|
43+
|Pi5 64-bit |`make rpi5_64` |[rpi5_64](../../buildroot-external/configs/rpi5_64_defconfig)|[raspberrypi](./raspberrypi/)|
4244
|Pi4B 64-bit |`make rpi4_64` |[rpi4_64](../../buildroot-external/configs/rpi4_64_defconfig)|[raspberrypi](./raspberrypi/)|
4345
|Pi4B 32-bit |`make rpi4` |[rpi4](../../buildroot-external/configs/rpi4_defconfig)|[raspberrypi](./raspberrypi/)|
4446
|Pi3B 64-bit |`make rpi3_64` |[rpi3_64](../../buildroot-external/configs/rpi3_64_defconfig)|[raspberrypi](./raspberrypi/)|

Documentation/boards/raspberrypi/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
| Raspberry Pi 2 B |2015 | not recommended | [rpi2](../../../buildroot-external/configs/rpi2_defconfig) |
99
| Raspberry Pi 3 B/B+ |2016/2018 | yes | [rpi3](../../../buildroot-external/configs/rpi3_defconfig) / [rpi3_64](../../../buildroot-external/configs/rpi3_64_defconfig) |
1010
| Raspberry Pi 4 B |2019 | yes | [rpi4](../../../buildroot-external/configs/rpi4_defconfig) / [rpi4_64](../../../buildroot-external/configs/rpi4_64_defconfig) |
11+
| Raspberry Pi 5 |2023 | yes (beta) | [rpi5_64](../../../buildroot-external/configs/rpi5_64_defconfig) |
1112

1213
## Serial console
1314

Documentation/kernel.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Default Kernel tree: 6.1
1111
| Raspberry Pi 2 | 6.1.63 |
1212
| Raspberry Pi 3 | 6.1.63 |
1313
| Raspberry Pi 4 | 6.1.63 |
14+
| Raspberry Pi 5 | 6.1.63 |
1415
| Home Assistant Yellow | 6.1.63 |
1516
| Home Assistant Green | 6.1.67 |
1617
| Tinker Board | 6.1.67 |

buildroot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zram.enabled=1 zram.num_devices=3 rootwait cgroup_enable=memory fsck.repair=yes console=tty1 root=PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd rootfstype=squashfs ro rauc.slot=A
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# For more options and information see
2+
# http://rptl.io/configtxt
3+
# Some settings may impact device functionality. See link above for details
4+
5+
# Uncomment some or all of these to enable the optional hardware interfaces
6+
#dtparam=i2c_arm=on
7+
#dtparam=i2s=on
8+
#dtparam=spi=on
9+
10+
# Enable audio (loads snd_bcm2835)
11+
dtparam=audio=on
12+
13+
# Additional overlays and parameters are documented
14+
# /boot/firmware/overlays/README
15+
16+
# Automatically load overlays for detected cameras
17+
camera_auto_detect=1
18+
19+
# Automatically load overlays for detected DSI displays
20+
display_auto_detect=1
21+
22+
# Automatically load initramfs files, if found
23+
auto_initramfs=1
24+
25+
# Enable DRM VC4 V3D driver
26+
dtoverlay=vc4-kms-v3d
27+
max_framebuffers=2
28+
29+
# Don't have the firmware create an initial video= setting in cmdline.txt.
30+
# Use the kernel's default instead.
31+
disable_fw_kms_setup=1
32+
33+
# Run in 64-bit mode
34+
arm_64bit=1
35+
36+
# Disable compensation for displays with overscan
37+
disable_overscan=1
38+
39+
# Run as fast as firmware / board allows
40+
arm_boost=1
41+
42+
# Use OS prefix for A/B slot (RAUC)
43+
os_prefix=slot-A/
44+
cmdline=/cmdline.txt
45+
46+
[cm4]
47+
# Enable host mode on the 2711 built-in XHCI USB controller.
48+
# This line should be removed if the legacy DWC2 controller is required
49+
# (e.g. for USB device mode) or if USB support is not required.
50+
otg_mode=1
51+
52+
[all]
53+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC2155
3+
4+
function hassos_pre_image() {
5+
local BOOT_DATA="$(path_boot_dir)"
6+
7+
mkdir -p "${BOOT_DATA}/slot-A/"
8+
cp "${BINARIES_DIR}"/*.dtb "${BOOT_DATA}/slot-A/"
9+
gzip --stdout "${BINARIES_DIR}"/Image > "${BOOT_DATA}/slot-A/kernel_2712.img"
10+
cp -r "${BINARIES_DIR}/overlays/" "${BOOT_DATA}/slot-A/"
11+
cp "${BINARIES_DIR}"/*.dtbo "${BOOT_DATA}/slot-A/overlays/" 2>/dev/null || true
12+
cp "${BOARD_DIR}/config.txt" "${BOOT_DATA}/config.txt"
13+
cp "${BOARD_DIR}/cmdline.txt" "${BOOT_DATA}/cmdline.txt"
14+
}
15+
16+
17+
function hassos_post_image() {
18+
convert_disk_image_xz
19+
}
20+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BOARD_ID=rpi5-64
2+
BOARD_NAME="RaspberryPi 5 64bit"
3+
CHASSIS=embedded
4+
BOOTLOADER=tryboot
5+
KERNEL_FILE=Image
6+
BOOT_SYS=gpt
7+
BOOT_SIZE=64M
8+
BOOT_SPL=false
9+
BOOT_ENV_SIZE=0x4000
10+
SUPERVISOR_MACHINE=raspberrypi5-64
11+
SUPERVISOR_ARCH=aarch64
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# shellcheck shell=sh
2+
# Shell script functions to manipulate kernel cmdline
3+
4+
# Function to get the value of a key from a command line string
5+
get_value() {
6+
key="$1"
7+
cmdline_string="$2"
8+
9+
# Split the command line string by whitespace and then by '=' using xargs
10+
echo "$cmdline_string" | xargs -n1 | grep "^$key=" | cut -d= -f2-
11+
}
12+
13+
# Function to set or update the value of a key in a command line string
14+
set_value() {
15+
key="$1"
16+
new_value="$2"
17+
cmdline_string="$3"
18+
19+
# Use sed to replace the value of the key if it exists, or add a new key-value pair
20+
if echo "$cmdline_string" | grep -q "$key="; then
21+
echo "$cmdline_string" | sed "s/$key=[^ ]*/$key=$new_value/"
22+
else
23+
echo "$cmdline_string $key=$new_value"
24+
fi
25+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/sh
2+
3+
# shellcheck source=/dev/null # Our GitHub Actions tests this separately
4+
. /usr/lib/rauc/cmdline.sh
5+
6+
# RAUC hook script for Raspberry Pi firmwaree tryboot
7+
# Meant to be usesd as a RAUC bootloader-custom-backend script.
8+
9+
boot_dir="/mnt/boot"
10+
root_slot_a="PARTUUID=8d3d53e3-6d49-4c38-8349-aff6859e82fd"
11+
root_slot_b="PARTUUID=a3ec664e-32ce-4665-95ea-7ae90ce9aa20"
12+
13+
case "$1" in
14+
get-primary)
15+
# Actions to be performed when getting the primary bootloader
16+
# Example: Output the path to the current primary bootloader
17+
echo "tryboot get-primary" >&2
18+
cmdline=$(head -n1 "${boot_dir}/cmdline.txt")
19+
get_value rauc.slot "${cmdline}"
20+
;;
21+
22+
set-primary)
23+
# Actions to be performed when setting the primary bootloader
24+
# Example: Set the specified bootloader as the primary one
25+
slot_bootname="$2"
26+
echo "tryboot set-primary $slot_bootname" >&2
27+
cmdline=$(head -n1 "${boot_dir}/cmdline.txt")
28+
if [ "${slot_bootname}" = "A" ]; then
29+
cmdline=$(set_value root "${root_slot_a}" "${cmdline}")
30+
elif [ "${slot_bootname}" = "B" ]; then
31+
cmdline=$(set_value root "${root_slot_b}" "${cmdline}")
32+
else
33+
exit 1
34+
fi
35+
cmdline=$(set_value rauc.slot "${slot_bootname}" "${cmdline}")
36+
echo "${cmdline}" > "${boot_dir}/cmdline-tryboot.txt"
37+
sed -e "s/^\(os_prefix=\)slot-[A-Z]\/$/\1slot-${slot_bootname}\//" \
38+
-e "s/^\(cmdline=\).*$/\1\/cmdline-tryboot.txt/" \
39+
"${boot_dir}/config.txt" > "${boot_dir}/tryboot.txt"
40+
# Use tryboot to try booting the new primary on reboot
41+
echo "0 tryboot" > /run/systemd/reboot-param
42+
;;
43+
44+
get-state)
45+
# Actions to be performed when getting the bootloader state
46+
# Example: Output the current state of the bootloader
47+
# You need to implement logic to determine the state (good or bad) based on the slot.bootname
48+
slot_bootname="$2"
49+
echo "tryboot get-state $slot_bootname" >&2
50+
if [ -f "${boot_dir}/slot-${slot_bootname}/.good" ]; then
51+
echo "returning good" >&2
52+
echo "good"
53+
else
54+
echo "returning bad" >&2
55+
echo "bad"
56+
fi
57+
;;
58+
59+
set-state)
60+
# Actions to be performed when setting the bootloader state
61+
# Example: Set the specified state for the bootloader
62+
slot_bootname="$2"
63+
new_state="$3"
64+
echo "tryboot set-state $slot_bootname $new_state" >&2
65+
if [ "${new_state}" = "good" ]; then
66+
touch "${boot_dir}/slot-${slot_bootname}/.good"
67+
else
68+
rm -f "${boot_dir}/slot-${slot_bootname}/.good"
69+
exit 0
70+
fi
71+
72+
# It seems we call set-state in any case. Use this to "commit" tryboot
73+
# state...
74+
75+
# Check if tryboot is active
76+
if ! cmp -s -n 4 /proc/device-tree/chosen/bootloader/tryboot /dev/zero; then
77+
cmdline_tryboot=$(head -n1 "${boot_dir}/cmdline-tryboot.txt")
78+
tryboot_slot=$(get_value rauc.slot "${cmdline_tryboot}")
79+
if [ "${tryboot_slot}" != "${slot_bootname}" ]; then
80+
echo "tryboot doesn't reflect the expected boot slot, not committing." >&2
81+
exit 1
82+
fi
83+
echo "Committing tryboot state to primary boot" >&2
84+
mv "${boot_dir}/tryboot.txt" "${boot_dir}/config.txt"
85+
mv "${boot_dir}/cmdline-tryboot.txt" "${boot_dir}/cmdline.txt"
86+
fi
87+
;;
88+
89+
get-current)
90+
# We don't have a better detection then /proc/cmdline...
91+
echo "Cannot reliably determine current slot with tryboot" >&2
92+
exit 1
93+
;;
94+
95+
*)
96+
echo "Unknown operation: $1"
97+
exit 1
98+
;;
99+
esac
100+
101+
exit 0

buildroot-external/busybox.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ CONFIG_GREP=y
480480
# CONFIG_EGREP is not set
481481
# CONFIG_FGREP is not set
482482
# CONFIG_FEATURE_GREP_CONTEXT is not set
483-
# CONFIG_XARGS is not set
483+
CONFIG_XARGS=y
484484
# CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION is not set
485485
# CONFIG_FEATURE_XARGS_SUPPORT_QUOTES is not set
486486
# CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT is not set

0 commit comments

Comments
 (0)