Moving raspberry pi rootfs creation to frc971 and updating
Upgrade to opencv 4.5, and using legacy camera driver for now
Added some additional comments and a timestamp / tracker on changes to the image
Change-Id: Iaf22f8e527b8147a5d73161a7292f78ce3114801
Signed-off-by: Jim Ostrowski <yimmy13@gmail.com>
diff --git a/y2020/vision/rootfs/99-usb-mount.rules b/frc971/raspi/rootfs/99-usb-mount.rules
similarity index 100%
rename from y2020/vision/rootfs/99-usb-mount.rules
rename to frc971/raspi/rootfs/99-usb-mount.rules
diff --git a/frc971/raspi/rootfs/README.md b/frc971/raspi/rootfs/README.md
new file mode 100644
index 0000000..a9c7251
--- /dev/null
+++ b/frc971/raspi/rootfs/README.md
@@ -0,0 +1,50 @@
+This modifies a stock debian root filesystem to be able to operate as a vision
+pi. It is not trying to be reproducible, but should be good enough for FRC
+purposes.
+
+The default hostname and IP is pi-971-1, 10.9.71.101.
+ Username pi, password raspberry.
+
+Download 2021-10-30-raspios-bullseye-armhf-lite.img (or any newer
+bullseye version, as a .zip file) from
+`https://www.raspberrypi.org/downloads/raspberry-pi-os/`, extract
+(unzip) the .img file, and edit `modify_rootfs.sh` to point to it.
+
+Run modify_rootfs.sh to build the filesystem (you might need to hit
+return in a spot or two and will need sudo privileges to mount the
+partition):
+ * `modify_root.sh`
+
+VERY IMPORTANT NOTE: Before doing the next step, use `lsblk` to find
+the device and make absolutely sure this isn't your hard drive or
+something else. It will target /dev/sda by default, which in some
+computers is your default hard drive.
+
+After confirming the target device, edit the `make_sd.sh` script to point to the correct IMAGE filename, and run the `make_sd.sh` command,
+which takes the name of the pi as an argument:
+ * `make_sd.sh pi-971-1`
+
+OR, if you want to manually run this, you can deploy the image by
+copying the contents of the image to the SD card. You can do this
+manually, via
+ `dd if=2020-02-13-raspbian-bullseye-lite-frc-mods.img of=/dev/sdX bs=1M`
+
+From there, transfer the SD card to the pi, log in, `sudo` to `root`,
+and run `/root/bin/change_hostname.sh` to change the hostname to the
+actual target.
+
+
+A couple additional notes on setting this up:
+ * You'll likely need to install (`sudo apt install`) the emulation packages `proot` and `qemu-user-static` (or possibly `qemu-arm-static`)
+ * If the modify_root.sh script fails, you may need to manually unmount the image (`sudo umount ${PARTITION}` and `rmdir ${PARTITION}`) before running it again
+ * Don't be clever and try to link to the image file in a different folder. These scripts need access directly to the file and will fail otherwise
+
+
+Things to do once the SD card is complete, and you've booted a PI with it:
+
+ * Download the code:
+ Once this is completed, you can boot the pi with the newly flashed SD
+ card, and download the code to the pi using:
+ `bazel run -c opt --cpu=armv7 //y2022:pi_download_stripped -- PI_IP_ADDR
+
+ where PI_IP_ADDR is the IP address of the target pi, e.g., 10.9.71.101
diff --git a/y2020/vision/rootfs/change_hostname.sh b/frc971/raspi/rootfs/change_hostname.sh
similarity index 100%
rename from y2020/vision/rootfs/change_hostname.sh
rename to frc971/raspi/rootfs/change_hostname.sh
diff --git a/y2020/vision/rootfs/dhcpcd.conf b/frc971/raspi/rootfs/dhcpcd.conf
similarity index 100%
rename from y2020/vision/rootfs/dhcpcd.conf
rename to frc971/raspi/rootfs/dhcpcd.conf
diff --git a/y2020/vision/rootfs/frc971.service b/frc971/raspi/rootfs/frc971.service
similarity index 100%
rename from y2020/vision/rootfs/frc971.service
rename to frc971/raspi/rootfs/frc971.service
diff --git a/y2020/vision/rootfs/logind.conf b/frc971/raspi/rootfs/logind.conf
similarity index 100%
rename from y2020/vision/rootfs/logind.conf
rename to frc971/raspi/rootfs/logind.conf
diff --git a/frc971/raspi/rootfs/make_sd.sh b/frc971/raspi/rootfs/make_sd.sh
new file mode 100755
index 0000000..81f7727
--- /dev/null
+++ b/frc971/raspi/rootfs/make_sd.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+set -e
+
+# 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"
+IMAGE=`echo ${ORIG_IMAGE} | sed s/.img/-frc-mods.img/`
+DEVICE="/dev/sda"
+
+if mount | grep "${DEVICE}" >/dev/null ;
+then
+ echo "Overwriting a mounted partition, is ${DEVICE} the sd card?"
+ exit 1
+fi
+
+sudo dd if=${IMAGE} of=${DEVICE} bs=1M status=progress
+
+PARTITION="${IMAGE}.partition"
+
+mkdir -p "${PARTITION}"
+sudo mount "${DEVICE}2" "${PARTITION}"
+
+function target() {
+ HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@"
+}
+
+if [ "${1}" == "" ]; then
+ echo "No hostname specified, so skipping setting it."
+ echo "You do this manually on the pi by running /root/bin/change_hostname.sh PI_NAME"
+else
+ target /root/bin/change_hostname.sh "${1}"
+fi
+
+echo "Starting a shell for any manual configuration"
+target /bin/bash --rcfile /root/.bashrc
+
+# Put a timestamp on when this card got created and by whom
+TIMESTAMP_FILE="${PARTITION}/home/pi/.DiskFlashedDate.txt"
+date > "${TIMESTAMP_FILE}"
+git rev-parse HEAD >> "${TIMESTAMP_FILE}"
+whoami >> "${TIMESTAMP_FILE}"
+
+# Found I had to do a lazy force unmount ("-l" flag) to make it work reliably
+sudo umount -l "${PARTITION}"
+rmdir "${PARTITION}"
diff --git a/y2020/vision/rootfs/modify_rootfs.sh b/frc971/raspi/rootfs/modify_rootfs.sh
similarity index 77%
rename from y2020/vision/rootfs/modify_rootfs.sh
rename to frc971/raspi/rootfs/modify_rootfs.sh
index 1367314..a340c64 100755
--- a/y2020/vision/rootfs/modify_rootfs.sh
+++ b/frc971/raspi/rootfs/modify_rootfs.sh
@@ -2,8 +2,8 @@
set -xe
-# Full path to Raspberry Pi Buster disk image
-IMAGE="2020-08-20-raspios-buster-armhf-lite.img"
+# Full path to Raspberry Pi Bullseye disk image
+IMAGE="2021-10-30-raspios-bullseye-armhf-lite.img"
BOOT_PARTITION="${IMAGE}.boot_partition"
PARTITION="${IMAGE}.partition"
@@ -34,8 +34,11 @@
if ! grep "gpu_mem=128" "${BOOT_PARTITION}/config.txt"; then
echo "gpu_mem=128" | 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"
-sudo umount "${BOOT_PARTITION}"
+# Seeing a race condition with umount, so doing lazy umount
+sudo umount -l "${BOOT_PARTITION}"
rmdir "${BOOT_PARTITION}"
if mount | grep "${PARTITION}" >/dev/null ;
@@ -86,10 +89,21 @@
target /bin/mkdir -p /home/pi/.ssh/
cat ~/.ssh/id_rsa.pub | target tee /home/pi/.ssh/authorized_keys
+# Downloads and installs our target libraries
target /bin/bash /tmp/target_configure.sh
+# Add a file to show when this image was last modified and by whom
+TIMESTAMP_FILE="${PARTITION}/home/pi/.ImageModifiedDate.txt"
+date > "${TIMESTAMP_FILE}"
+git rev-parse HEAD >> "${TIMESTAMP_FILE}"
+whoami >> "${TIMESTAMP_FILE}"
+
# Run a prompt as root inside the target to poke around and check things.
target /bin/bash --rcfile /root/.bashrc
-sudo umount "${PARTITION}"
+sudo umount -l "${PARTITION}"
rmdir "${PARTITION}"
+
+# Move the image to a different name, to indicated we've modified it
+MOD_IMAGE_NAME=`echo ${IMAGE} | sed s/.img/-frc-mods.img/`
+mv ${IMAGE} ${MOD_IMAGE_NAME}
diff --git a/y2020/vision/rootfs/rt.conf b/frc971/raspi/rootfs/rt.conf
similarity index 100%
rename from y2020/vision/rootfs/rt.conf
rename to frc971/raspi/rootfs/rt.conf
diff --git a/y2020/vision/rootfs/sctp.conf b/frc971/raspi/rootfs/sctp.conf
similarity index 100%
rename from y2020/vision/rootfs/sctp.conf
rename to frc971/raspi/rootfs/sctp.conf
diff --git a/y2020/vision/rootfs/target_configure.sh b/frc971/raspi/rootfs/target_configure.sh
similarity index 78%
rename from y2020/vision/rootfs/target_configure.sh
rename to frc971/raspi/rootfs/target_configure.sh
index 9f2e289..3fd4d40 100755
--- a/y2020/vision/rootfs/target_configure.sh
+++ b/frc971/raspi/rootfs/target_configure.sh
@@ -19,28 +19,29 @@
git \
python3-pip \
cpufrequtils \
- libopencv-calib3d3.2 \
- libopencv-contrib3.2 \
- libopencv-core3.2 \
- libopencv-features2d3.2 \
- libopencv-flann3.2 \
- libopencv-highgui3.2 \
- libopencv-imgcodecs3.2 \
- libopencv-imgproc3.2 \
- libopencv-ml3.2 \
- libopencv-objdetect3.2 \
- libopencv-photo3.2 \
- libopencv-shape3.2 \
- libopencv-stitching3.2 \
- libopencv-superres3.2 \
- libopencv-video3.2 \
- libopencv-videoio3.2 \
- libopencv-videostab3.2 \
- libopencv-viz3.2 \
+ libopencv-calib3d4.5 \
+ libopencv-contrib4.5 \
+ libopencv-core4.5 \
+ libopencv-features2d4.5 \
+ libopencv-flann4.5 \
+ libopencv-highgui4.5 \
+ libopencv-imgcodecs4.5 \
+ libopencv-imgproc4.5 \
+ libopencv-ml4.5 \
+ libopencv-objdetect4.5 \
+ libopencv-photo4.5 \
+ libopencv-shape4.5 \
+ libopencv-stitching4.5 \
+ libopencv-superres4.5 \
+ libopencv-video4.5 \
+ libopencv-videoio4.5 \
+ libopencv-videostab4.5 \
+ libopencv-viz4.5 \
python3-opencv \
libnice10 \
pmount \
- libnice-dev
+ libnice-dev \
+ feh
echo 'GOVERNOR="performance"' > /etc/default/cpufrequtils
diff --git a/y2020/vision/rootfs/usb-mount@.service b/frc971/raspi/rootfs/usb-mount@.service
similarity index 100%
rename from y2020/vision/rootfs/usb-mount@.service
rename to frc971/raspi/rootfs/usb-mount@.service
diff --git a/y2020/vision/rootfs/README.md b/y2020/vision/rootfs/README.md
deleted file mode 100644
index 0f66864..0000000
--- a/y2020/vision/rootfs/README.md
+++ /dev/null
@@ -1,32 +0,0 @@
-This modifies a stock debian root filesystem to be able to operate as a vision
-pi. It is not trying to be reproducible, but should be good enough for FRC
-purposes.
-
-The default hostname and IP is pi-8971-1, 10.89.71.101.
- Username pi, password raspberry.
-
-Download 2020-08-20-raspios-buster-armhf-lite.img (or any newer buster
-version, as a .zip file) from
-`https://www.raspberrypi.org/downloads/raspberry-pi-os/` (or
-`https://downloads.raspberrypi.org/raspios_lite_armhf/images/` for
-older images), extract (unzip) the .img file, and edit
-`modify_rootfs.sh` to point to it.
-
-Run modify_rootfs.sh to build the filesystem (you might need to hit
-return in a spot or two and will need sudo privileges to mount the
-partition).
-
-After confirming the target device, deploy by copying the contents of the image
-to the SD card.
-
- `dd if=2020-02-13-raspbian-buster-lite.img of=/dev/sdX bs=1M`
-
-Use `lsblk` to find the device and make absolutely sure this isn't your hard
-drive or something else.
-
-From there, log in, `sudo` to `root`, and run `/root/bin/change_hostname.sh` to
-change the hostname to the actual target.
-
-A couple additional notes on setting this up:
- * You'll likely need to install (`sudo apt install`) the emulation packages `proot` and `qemu-user-static` (or possibly `qemu-arm-static`)
- * If the modify_root.sh script fails, you may need to manually unmount the image (`sudo umount ${IMAGE}`) before running it again
diff --git a/y2020/vision/rootfs/make_sd.sh b/y2020/vision/rootfs/make_sd.sh
deleted file mode 100755
index eba47bc..0000000
--- a/y2020/vision/rootfs/make_sd.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-
-set -e
-
-IMAGE="2020-08-20-raspios-buster-armhf-lite.img"
-DEVICE="/dev/sda"
-
-if mount | grep "${DEVICE}" >/dev/null ;
-then
- echo "Overwriting a mounted partition, is ${DEVICE} the sd card?"
- exit 1
-fi
-
-sudo dd if=${IMAGE} of=${DEVICE} bs=1M status=progress
-
-PARTITION="${IMAGE}.partition"
-
-mkdir -p "${PARTITION}"
-sudo mount "${DEVICE}2" "${PARTITION}"
-
-function target() {
- HOME=/root/ USER=root sudo proot -0 -q qemu-arm-static -w / -r "${PARTITION}" "$@"
-}
-
-target /root/bin/change_hostname.sh "${1}"
-
-echo "Starting a shell for any manual configuration"
-target /bin/bash --rcfile /root/.bashrc
-
-sudo umount "${PARTITION}"