dual-image: Add reset-cs0-aspeed to reset the CS
When BMC is running on the secondary flash, and the primary flash is
updated, the BMC needs to reboot to the primary flash.
On aspeed, this is done by clearing the wdt2 state register bit, and
could be implemented by writing non-zero to
/sys/class/watchdog/watchdog1/access_cs0.
But it has a side effect that the CS will be swapped back to normal,
which means the running rootfs will be swapped to the primary flash.
So this needs to be done after the rootfs is umounted.
Add reset-cs0-aspeed to insert a line in `/run/initramfs/shutdown`
to write non-zero to /sys/class/watchdog/watchdog1/access_cs0.
Tested: Verify that the BMC is reboot to the primary flash after
flashing in the secondary image.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I4c988017ed45131318625f349a84500e1831e171
diff --git a/meson.build b/meson.build
index 2e12de7..24abdc1 100644
--- a/meson.build
+++ b/meson.build
@@ -301,6 +301,11 @@
install_dir: get_option('bindir')
)
+install_data('reset-cs0-aspeed',
+ install_mode: 'rwxr-xr-x',
+ install_dir: get_option('bindir')
+)
+
install_data('software.conf',
install_dir: '/usr/lib/tmpfiles.d/'
)
diff --git a/reset-cs0-aspeed b/reset-cs0-aspeed
new file mode 100644
index 0000000..e2cf1e0
--- /dev/null
+++ b/reset-cs0-aspeed
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Write 1 to /sys/class/watchdog/watchdog1/access_cs0 to reset the boot code
+# selection and reset the chip select, so that the next boot is from the
+# primary chip.
+# This needs to be done in the shutdown script after umount the rootfs,
+# otherwise the filesystem will get error because the content is switched
+# back to CS0 chip.
+
+SHUTDOWN_EXTRA_SCRIPT="/run/initramfs/shutdown_task_after_umount"
+
+cat <<'EOF' >"${SHUTDOWN_EXTRA_SCRIPT}"
+#!/bin/sh
+ACCESS_CS0="/sys/class/watchdog/watchdog1/access_cs0"
+if [ -f "${ACCESS_CS0}" ]; then
+ echo "Reset aspeed chip select"
+ echo 1 > "${ACCESS_CS0}"
+fi
+EOF
+chmod +x "${SHUTDOWN_EXTRA_SCRIPT}"
+
+
+# Insert the shutdown_task_after_umount into the shutdown script
+# This change could be apply to obmc-shutdown.sh in obmc-phosphor-initfs.bb
+# if this is accepted.
+sed -i "s/echo Remaining mounts/\/run\/initramfs\/shutdown_task_after_umount\\necho Remaining mounts/" /run/initramfs/shutdown
diff --git a/static/obmc-flash-bmc-alt@.service.in b/static/obmc-flash-bmc-alt@.service.in
index f302e03..d507455 100644
--- a/static/obmc-flash-bmc-alt@.service.in
+++ b/static/obmc-flash-bmc-alt@.service.in
@@ -1,5 +1,5 @@
[Unit]
-Description=Flash image-bmc to the alt chip
+Description=Flash image-bmc to the alt chip and reset cs0
[Service]
Type=oneshot
@@ -11,3 +11,4 @@
ExecStartPost=-/usr/bin/obmc-flash-bmc static-altfs squashfs alt-rofs rofs-alt
ExecStartPost=-/usr/bin/obmc-flash-bmc static-altfs jffs2 alt-rwfs rwfs-alt
ExecStartPost=-/bin/systemctl start xyz.openbmc_project.Software.Sync.service
+ExecStartPost=-/usr/bin/reset-cs0-aspeed