Deploy IMU driver and configure IRQs
The IRQs didn't match the existing IRQs. Update them to be more
flexible and not depend on IRQ numbers since those appear to change.
wiringpi wasn't building for me, so I built the .deb and installed that
in the rootfs so I could make progress again.
While we are here, deploy to ~/bin instead of ~/robot_code/ so it is in
the path everywhere. To make things actually easy to use, we need to
change how the config is found, but until then, this gets us closer to
easy to use.
Change-Id: Ib2f900f59bb6cc3de8f97e7687e723f6c8d003e7
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/frc971/raspi/rootfs/BUILD b/frc971/raspi/rootfs/BUILD
new file mode 100644
index 0000000..ee5984a
--- /dev/null
+++ b/frc971/raspi/rootfs/BUILD
@@ -0,0 +1 @@
+exports_files(["chrt.sh"])
diff --git a/frc971/raspi/rootfs/chrt.sh b/frc971/raspi/rootfs/chrt.sh
new file mode 100755
index 0000000..535f4c6
--- /dev/null
+++ b/frc971/raspi/rootfs/chrt.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+set -e
+
+function chrtirq() {
+ PIDS="$(ps -ef | grep "\\[$1\\]" | awk '{print $2}')"
+
+ for PID in $PIDS; do
+ chrt $2 -p $3 "${PID}"
+
+ ps -q "${PID}" -o comm= | tr -d '[:space:]'
+ echo -n " "
+ chrt -p "${PID}"
+ done
+
+ if [ -z "${PID}" ]; then
+ echo "No such IRQ ${1}"
+ fi
+}
+
+chrtirq "irq/[0-9]*-fe00b880" -f 50
+chrtirq "irq/[0-9]*-fe204000" -f 60
+chrtirq "irq/[0-9]*-adis1650" -f 61
+chrtirq "irq/[0-9]*-xhci_hcd" -f 1
+chrtirq "irq/[0-9]*-VCHIQ do" -o 0
+chrtirq "irq/[0-9]*-DMA IRQ" -f 50
+chrtirq "irq/[0-9]*-mmc1" -o 0
+chrtirq "irq/[0-9]*-mmc0" -o 0
+chrtirq "irq/[0-9]*-s-mmc0" -o 0
+chrtirq "irq/[0-9]*-v3d" -o 0
+chrtirq "irq/24-vc4 hvs" -o 0
+chrtirq "irq/[0-9]*-vc4 hdmi" -o 0
+chrtirq "irq/[0-9]*-s-vc4 hd" -o 0
+chrtirq "irq/19-fe004000" -f 50
+chrtirq "irq/[0-9]*-vc4 crtc" -o 0
+chrtirq "irq/23-uart-pl0" -o 0
+chrtirq "irq/[0-9]*-eth0" -f 10
diff --git a/frc971/raspi/rootfs/enable_imu.sh b/frc971/raspi/rootfs/enable_imu.sh
new file mode 100755
index 0000000..3725207
--- /dev/null
+++ b/frc971/raspi/rootfs/enable_imu.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+CONFIG=/boot/config.txt
+
+if grep -q adis16505 "${CONFIG}"; then
+ echo "Already enabled"
+ exit 0;
+fi
+
+sed -i '1h;1!H;$!d;x;s/.*dtparam=spi[^\n]*/&\n\n# Enable the IMU\ndtoverlay=adis16505/' "${CONFIG}"
+
+echo "Enabled 16505"
diff --git a/frc971/raspi/rootfs/frc971.service b/frc971/raspi/rootfs/frc971.service
index cdfb347..be6b37f 100644
--- a/frc971/raspi/rootfs/frc971.service
+++ b/frc971/raspi/rootfs/frc971.service
@@ -7,8 +7,8 @@
User=pi
Group=pi
Type=simple
-WorkingDirectory=/home/pi/robot_code
-ExecStart=/home/pi/robot_code/starter.sh
+WorkingDirectory=/home/pi/bin
+ExecStart=/home/pi/bin/starter.sh
KillMode=mixed
TimeoutStopSec=10
LimitRTPRIO=60
diff --git a/frc971/raspi/rootfs/frc971chrt.service b/frc971/raspi/rootfs/frc971chrt.service
index cc68934..6086fa0 100644
--- a/frc971/raspi/rootfs/frc971chrt.service
+++ b/frc971/raspi/rootfs/frc971chrt.service
@@ -3,7 +3,7 @@
[Service]
Type=oneshot
-ExecStart=/home/pi/robot_code/chrt.sh
+ExecStart=/home/pi/bin/chrt.sh
[Install]
WantedBy=multi-user.target
diff --git a/frc971/raspi/rootfs/modify_rootfs.sh b/frc971/raspi/rootfs/modify_rootfs.sh
index fd9bec9..15bdd80 100755
--- a/frc971/raspi/rootfs/modify_rootfs.sh
+++ b/frc971/raspi/rootfs/modify_rootfs.sh
@@ -36,8 +36,13 @@
if ! grep "gpu_mem=128" "${BOOT_PARTITION}/config.txt"; then
echo "gpu_mem=128" | sudo tee -a "${BOOT_PARTITION}/config.txt"
fi
+if ! grep "enable_uart=1" "${BOOT_PARTITION}/config.txt"; then
+ echo "enable_uart=1" | sudo tee -a "${BOOT_PARTITION}/config.txt"
+fi
# 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"
+# Enable SPI.
+sudo sed -i s/^.*dtparam=spi=on/dtparam=spi=on/ "${BOOT_PARTITION}/config.txt"
sudo tar -zxvf "${KERNEL}" --strip-components 2 -C ${BOOT_PARTITION}/ ./fat32
@@ -80,11 +85,17 @@
sudo mount -o loop,offset=${OFFSET} "${IMAGE}" "${PARTITION}"
fi
+if [[ ! -e wiringpi-2.70-1.deb ]]; then
+ wget --continue https://software.frc971.org/Build-Dependencies/wiringpi-2.70-1.deb
+fi
+
sudo cp target_configure.sh "${PARTITION}/tmp/"
+sudo cp wiringpi-2.70-1.deb "${PARTITION}/tmp/"
sudo cp dhcpcd.conf "${PARTITION}/tmp/dhcpcd.conf"
sudo cp sctp.conf "${PARTITION}/etc/sysctl.d/sctp.conf"
sudo cp logind.conf "${PARTITION}/etc/systemd/logind.conf"
sudo cp change_hostname.sh "${PARTITION}/tmp/change_hostname.sh"
+sudo cp enable_imu.sh "${PARTITION}/tmp/"
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"
@@ -96,6 +107,8 @@
sudo rm -rf "${PARTITION}/lib/modules/"*
sudo tar -zxvf "${KERNEL}" --strip-components 4 -C "${PARTITION}/lib/modules/" ./ext4/lib/modules/
+sudo cp adis16505.ko "${PARTITION}/lib/modules/5.10.78-rt55-v8+/kernel/"
+target /usr/sbin/depmod 5.10.78-rt55-v8+
# 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 6d9171e..388d291 100755
--- a/frc971/raspi/rootfs/target_configure.sh
+++ b/frc971/raspi/rootfs/target_configure.sh
@@ -9,9 +9,12 @@
# And provide a script to change it.
cp /tmp/change_hostname.sh /root/bin/
+cp /tmp/enable_imu.sh /root/bin/
chmod a+x /root/bin/change_hostname.sh
+chmod a+x /root/bin/enable_imu.sh
chown -R pi.pi /home/pi/.ssh
+chown -R pi.pi /home/pi/bin
apt-get update
@@ -41,13 +44,7 @@
libnice-dev \
feh
-# Install WiringPi gpio for PWM control
-if [[ ! -e "/usr/bin/gpio" ]]; then
- cd /tmp
- git clone https://github.com/WiringPi/WiringPi.git
- cd WiringPi
- ./build
-fi
+dpkg -i /tmp/wiringpi-2.70-1.deb
echo 'GOVERNOR="performance"' > /etc/default/cpufrequtils