dual-image: Detect the running image slot

Add detect-slot-aspeed to detect which slot it is running on, and
assign the member variable, which will be used in future commits.

Tested:
    * In normal case, verify the primary slot is 0 and secondary slot
      is 1.
    * Manually assign value 1 in /run/media/slot, and verify the slot
      number is reversed.
    * Manually trigger wdt2 timeout and verify in secondary flash that
      the slot number is correct, that the running slot is 1 and the
      other slot is 0.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I69edb1961b4c4bb79e7897c38b9ce8dded42f829
diff --git a/detect-slot-aspeed b/detect-slot-aspeed
new file mode 100644
index 0000000..231eb33
--- /dev/null
+++ b/detect-slot-aspeed
@@ -0,0 +1,17 @@
+#!/bin/bash
+set -eo pipefail
+
+# Check the /sys/class/watchdog/watchdog1/access_cs0 and tell if it's running on the primary or the secondary flash.
+
+ACCESS_CS0="/sys/class/watchdog/watchdog1/access_cs0"
+SLOT_FILE="/run/media/slot"
+
+# Create directory if not exist
+mkdir -p "$(dirname "${SLOT_FILE}")"
+
+# Write slot info
+if [ -f ${ACCESS_CS0} ]; then
+    echo "1" > ${SLOT_FILE}
+else
+    echo "0" > ${SLOT_FILE}
+fi