#!/bin/sh
#
# reboot-mode bootloader|recovery -- reboot into the bootloader's fastboot
# or into recovery, with a clean shutdown: the mode goes to /run/reboot-mode,
# reboot(8) runs runit's stage 3 (services stopped, file systems unmounted),
# and its last hook, /etc/runit/shutdown.d/95-reboot-mode.sh, restarts with
# the mode (/usr/libexec/makronix/reboot2).  Needs the mode-* properties on
# the PMIC's PON node in the DT; without them the phone just restarts.

case ${1:-} in
bootloader|recovery) ;;
*)	echo "usage: reboot-mode bootloader|recovery" >&2; exit 2 ;;
esac
[ -x /usr/libexec/makronix/reboot2 ] ||
	{ echo "reboot-mode: no /usr/libexec/makronix/reboot2" >&2; exit 1; }
echo "$1" > /run/reboot-mode || exit 1
exec reboot
