Update build instructions and handle image filename better

Allow user to call function twice, and detect modified image filename
Updated image creation instructions to include IMU adis16505.ko

Change-Id: I33d0323b21ec1d4e2db26537149a5b2cdc091a60
Signed-off-by: Jim Ostrowski <yimmy13@gmail.com>
diff --git a/frc971/raspi/rootfs/README.md b/frc971/raspi/rootfs/README.md
index b972038..a349eb5 100644
--- a/frc971/raspi/rootfs/README.md
+++ b/frc971/raspi/rootfs/README.md
@@ -10,7 +10,7 @@
 ## Build the real-time kernel using `build_kernel.sh`
 
 - Checkout the real-time kernel source code, e.g.,
-  `cd CODE_DIR`
+  `cd CODE_DIR`, where CODE_DIR is the directory containing the FRC971 code
   `git clone git@github.com:frc971/linux.git`
   `git checkout frc971-5.10-pi4-rt branch`
 
@@ -18,6 +18,13 @@
   `cd ROOTFS_DIR` (where ROOTFS_DIR -> //frc971/raspi/rootfs)
   `./build_kernel.sh CODE_DIR/linux kernel_5.10.tar.gz`
 
+## Build the ADIS16505 overlay file (adis16505.ko)
+
+- Make sure the linux kernel source code is checked out at CODE_DIR/linux
+- cd //y2022/localizer/kernel
+- `make`
+- copy that file to this directory (//frc971/raspi/rootfs)
+
 ## Download the Raspberry Pi OS
 
 Download the appropriate Raspberry Pi OS image, e.g.,
diff --git a/frc971/raspi/rootfs/modify_rootfs.sh b/frc971/raspi/rootfs/modify_rootfs.sh
index 15bdd80..c3582ea 100755
--- a/frc971/raspi/rootfs/modify_rootfs.sh
+++ b/frc971/raspi/rootfs/modify_rootfs.sh
@@ -4,6 +4,19 @@
 
 # Full path to Raspberry Pi Bullseye disk image
 IMAGE="2022-01-28-raspios-bullseye-arm64-lite.img"
+MOD_IMAGE_NAME=`echo ${IMAGE} | sed s/.img/-frc-mods.img/`
+
+if [ ! -f "$IMAGE" ]; then
+    echo "Attempting to use already modified image"
+    if [ ! -f "$MOD_IMAGE_NAME" ]; then
+        echo "Must provide image filename."
+        echo "Couldn't find $IMAGE or $MOD_IMAGE_NAME"
+        exit 1
+    fi
+    echo "Using already modified image: ${MOD_IMAGE_NAME}"
+    IMAGE=$MOD_IMAGE_NAME
+fi
+
 # Kernel built with build_kernel.sh
 KERNEL="kernel_5.10.tar.gz"
 BOOT_PARTITION="${IMAGE}.boot_partition"
@@ -116,6 +129,7 @@
 # Add a file to show when this image was last modified and by whom
 TIMESTAMP_FILE="${PARTITION}/home/pi/.ImageModifiedDate.txt"
 echo "Date modified:"`date` > "${TIMESTAMP_FILE}"
+echo "Image file: ${IMAGE}"  >> "${TIMESTAMP_FILE}"
 echo "Git tag: "`git rev-parse HEAD` >> "${TIMESTAMP_FILE}"
 echo "User: "`whoami` >> "${TIMESTAMP_FILE}"
 
@@ -125,6 +139,7 @@
 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}
+# Move the image to a different name, to indicate we've modified it
+if [ ${IMAGE} != ${MOD_IMAGE_NAME} ]; then
+  mv ${IMAGE} ${MOD_IMAGE_NAME}
+fi