Use the new 64 bit root filesystem for the pi's

This also pulls in our RT kernel, and the script to build it.

We still need to package up and build the kernel module for the
adis16505, and enable the overlay.  Not a huge deal.

Change-Id: I1a100d8ec3ce4406af27af6b555fd08840fb71fd
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/starter/starter.sh b/aos/starter/starter.sh
index 7a25fc7..f18dfda 100755
--- a/aos/starter/starter.sh
+++ b/aos/starter/starter.sh
@@ -8,6 +8,43 @@
   ln -s /var/local/natinst/log/FRC_UserProgram.log /tmp/FRC_UserProgram.log
   ln -s /var/local/natinst/log/FRC_UserProgram.log "${ROBOT_CODE}/FRC_UserProgram.log"
 elif [[ "$(hostname)" == "pi-"* ]]; then
+  function chrtirq() {
+    ps -ef | grep "\\[$1\\]" | awk '{print $2}' | xargs chrt $2 -p $3
+  }
+
+  chrtirq "irq/20-fe00b880" -f 50
+  chrtirq "irq/66-xhci_hcd" -f 1
+  chrtirq "irq/50-VCHIQ do" -o 0
+  chrtirq "irq/27-DMA IRQ" -f 50
+  chrtirq "irq/51-mmc1" -o 0
+  chrtirq "irq/51-mmc0" -o 0
+  chrtirq "irq/51-s-mmc0" -o 0
+  chrtirq "irq/64-v3d" -o 0
+  chrtirq "irq/24-vc4 hvs" -o 0
+  chrtirq "irq/42-vc4 hdmi" -o 0
+  chrtirq "irq/43-vc4 hdmi" -o 0
+  chrtirq "irq/39-vc4 hdmi" -o 0
+  chrtirq "irq/39-s-vc4 hd" -o 0
+  chrtirq "irq/38-vc4 hdmi" -o 0
+  chrtirq "irq/38-s-vc4 hd" -o 0
+  chrtirq "irq/29-DMA IRQ" -f 50
+  chrtirq "irq/48-vc4 hdmi" -o 0
+  chrtirq "irq/49-vc4 hdmi" -o 0
+  chrtirq "irq/45-vc4 hdmi" -o 0
+  chrtirq "irq/45-s-vc4 hd" -o 0
+  chrtirq "irq/44-vc4 hdmi" -o 0
+  chrtirq "irq/44-s-vc4 hd" -o 0
+  chrtirq "irq/30-DMA IRQ" -f 50
+  chrtirq "irq/19-fe004000" -f 50
+  chrtirq "irq/34-vc4 crtc" -o 0
+  chrtirq "irq/35-vc4 crtc" -o 0
+  chrtirq "irq/36-vc4 crtc" -o 0
+  chrtirq "irq/35-vc4 crtc" -o 0
+  chrtirq "irq/37-vc4 crtc" -o 0
+  chrtirq "irq/23-uart-pl0" -o 0
+  chrtirq "irq/57-eth0" -f 10
+  chrtirq "irq/58-eth0" -f 10
+
   # We have systemd configured to handle restarting, so just exec.
   export PATH="${PATH}:/home/pi/robot_code"
   rm -rf /dev/shm/aos
diff --git a/frc971/raspi/rootfs/build_kernel.sh b/frc971/raspi/rootfs/build_kernel.sh
new file mode 100755
index 0000000..cd97902
--- /dev/null
+++ b/frc971/raspi/rootfs/build_kernel.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+# This script builds the kernel for the raspberry pi.
+#
+# git@github.com:frc971/linux.git
+#
+# We are using the frc971-5.10-pi4-rt branch
+#
+# Point it at the version of that repo you want to build, and it'll generate a
+# .tar.gz of the bits to install.
+
+
+set -ex
+
+echo $#
+if [[ $# -lt 2 ]];
+then
+  echo "Pass in the kernel directory and then the destination .tar.gz"
+  exit 1
+fi
+
+export OUTPUT="$(realpath $(dirname $2))/$(basename ${2})"
+export TMPDIR="${OUTPUT}_tmpdir"
+
+mkdir -p "${TMPDIR}"
+mkdir -p "${TMPDIR}/fat32/overlays"
+mkdir -p "${TMPDIR}/ext4"
+
+pushd "${1}"
+
+export KERNEL=kernel8
+
+make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs -j 60
+
+cp arch/arm64/boot/Image "${TMPDIR}/fat32/$KERNEL.img"
+cp arch/arm64/boot/dts/broadcom/*.dtb "${TMPDIR}/fat32/"
+cp arch/arm64/boot/dts/overlays/*.dtb* "${TMPDIR}/fat32/overlays/"
+cp arch/arm64/boot/dts/overlays/README "${TMPDIR}/fat32/overlays/"
+
+make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH="${TMPDIR}/ext4" modules_install
+
+cd "${TMPDIR}"
+tar cvzf "${OUTPUT}" --owner=0 --group=0 "./"
+
+popd
+
+rm -rf "${TMPDIR}"
+
+echo "Kernel is now available at: ${OUTPUT}"
diff --git a/frc971/raspi/rootfs/frc971chrt.service b/frc971/raspi/rootfs/frc971chrt.service
new file mode 100644
index 0000000..cc68934
--- /dev/null
+++ b/frc971/raspi/rootfs/frc971chrt.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Configure IRQs
+
+[Service]
+Type=oneshot
+ExecStart=/home/pi/robot_code/chrt.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/frc971/raspi/rootfs/make_sd.sh b/frc971/raspi/rootfs/make_sd.sh
index 81f7727..5f1a0e1 100755
--- a/frc971/raspi/rootfs/make_sd.sh
+++ b/frc971/raspi/rootfs/make_sd.sh
@@ -4,7 +4,7 @@
 
 # Disk image to use for creating SD card
 # NOTE: You MUST run modify_rootfs.sh on this image BEFORE running make_sd.sh
-ORIG_IMAGE="2021-10-30-raspios-bullseye-armhf-lite.img"
+ORIG_IMAGE="2022-01-28-raspios-bullseye-arm64-lite.img"
 IMAGE=`echo ${ORIG_IMAGE} | sed s/.img/-frc-mods.img/`
 DEVICE="/dev/sda"
 
@@ -22,7 +22,7 @@
 sudo mount "${DEVICE}2" "${PARTITION}"
 
 function target() {
-  HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@"
+  HOME=/root/ USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" "$@"
 }
 
 if [ "${1}" == "" ]; then
diff --git a/frc971/raspi/rootfs/modify_rootfs.sh b/frc971/raspi/rootfs/modify_rootfs.sh
index a340c64..0020f35 100755
--- a/frc971/raspi/rootfs/modify_rootfs.sh
+++ b/frc971/raspi/rootfs/modify_rootfs.sh
@@ -3,16 +3,18 @@
 set -xe
 
 # Full path to Raspberry Pi Bullseye disk image
-IMAGE="2021-10-30-raspios-bullseye-armhf-lite.img"
+IMAGE="2022-01-28-raspios-bullseye-arm64-lite.img"
+# Kernel built with build_kernel.sh
+KERNEL="kernel_5.10.tar.gz"
 BOOT_PARTITION="${IMAGE}.boot_partition"
 PARTITION="${IMAGE}.partition"
 
 function target() {
-  HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@"
+  HOME=/root/ USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" "$@"
 }
 
 function user_pi_target() {
-  USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" sudo -h 127.0.0.1 -u pi "$@"
+  USER=root sudo proot -0 -q qemu-aarch64-static -w / -r "${PARTITION}" sudo -h 127.0.0.1 -u pi "$@"
 }
 
 
@@ -37,6 +39,8 @@
 # For now, disable the new libcamera driver in favor of legacy ones
 sudo sed -i s/^camera_auto_detect=1/#camera_auto_detect=1/ "${BOOT_PARTITION}/config.txt"
 
+sudo tar -zxvf "${KERNEL}" --strip-components 2 -C ${BOOT_PARTITION}/ ./fat32
+
 # Seeing a race condition with umount, so doing lazy umount
 sudo umount -l "${BOOT_PARTITION}"
 rmdir "${BOOT_PARTITION}"
@@ -82,6 +86,7 @@
 sudo cp logind.conf "${PARTITION}/etc/systemd/logind.conf"
 sudo cp change_hostname.sh "${PARTITION}/tmp/change_hostname.sh"
 sudo cp frc971.service "${PARTITION}/etc/systemd/system/frc971.service"
+sudo cp frc971chrt.service "${PARTITION}/etc/systemd/system/frc971chrt.service"
 sudo cp rt.conf "${PARTITION}/etc/security/limits.d/rt.conf"
 sudo cp usb-mount@.service "${PARTITION}/etc/systemd/system/usb-mount@.service"
 sudo cp 99-usb-mount.rules "${PARTITION}/etc/udev/rules.d/99-usb-mount.rules"
@@ -89,6 +94,9 @@
 target /bin/mkdir -p /home/pi/.ssh/
 cat ~/.ssh/id_rsa.pub | target tee /home/pi/.ssh/authorized_keys
 
+sudo rm -rf "${PARTITION}/lib/modules/"*
+sudo tar -zxvf "${KERNEL}" --strip-components 4 -C "${PARTITION}/lib/modules/" ./ext4/lib/modules/
+
 # Downloads and installs our target libraries
 target /bin/bash /tmp/target_configure.sh
 
diff --git a/frc971/raspi/rootfs/target_configure.sh b/frc971/raspi/rootfs/target_configure.sh
index 3fd4d40..db3fb36 100755
--- a/frc971/raspi/rootfs/target_configure.sh
+++ b/frc971/raspi/rootfs/target_configure.sh
@@ -17,7 +17,6 @@
 
 apt-get install -y vim-nox \
   git \
-  python3-pip \
   cpufrequtils \
   libopencv-calib3d4.5 \
   libopencv-contrib4.5 \
@@ -37,7 +36,6 @@
   libopencv-videoio4.5 \
   libopencv-videostab4.5 \
   libopencv-viz4.5 \
-  python3-opencv \
   libnice10 \
   pmount \
   libnice-dev \
@@ -73,6 +71,7 @@
 
 systemctl enable ssh.service
 systemctl enable frc971.service
+systemctl enable frc971chrt.service
 
 # Default us to pi-971-1
 /root/bin/change_hostname.sh pi-971-1