# shellcheck shell=bash disable=SC2034  # vars consumed by ../ARM
# Raspberry Pi 5 Model B. Other Pi models may need different kernels
# and boot configuration.
#
# Stock aarch64 tarball ships linux-aarch64 + U-Boot which don't boot
# the Pi 5; swap to the foundation kernel + firmware.

ARCHIVE="ArchLinuxARM-rpi-aarch64-latest.tar.gz"
TARBALL_URL="http://os.archlinuxarm.org/os/${ARCHIVE}"

BOARD_CHROOT='
	pacman -Rns --noconfirm linux-aarch64 uboot-raspberrypi
	pacman -S --noconfirm linux-rpi raspberrypi-bootloader firmware-raspberrypi
'

board_finish() {
	# leftover U-Boot script files (NOT kernel files, linux-rpi manages those)
	rm -f "$MNT"/boot/boot.scr "$MNT"/boot/boot.txt "$MNT"/boot/mkscr
	# skip firmware os check, don't overwrite whatever config.txt is there
	grep -q "os_check" "$MNT/boot/config.txt" || \
		sed -i '1i os_check=0' "$MNT/boot/config.txt"
	echo "root=PARTUUID=${ROOT_PARTUUID} rw rootwait console=tty1 console=ttyAMA10,115200 quiet loglevel=0 audit=0" \
		> "$MNT/boot/cmdline.txt"
}
