17
17
18
18
unset src sources
19
19
20
+ check_fw_setup () {
21
+ if ! is_efi_system; then
22
+ zdebug " efivarfs unsupported"
23
+ return 1
24
+ elif [ ! -r /sys/firmware/efi/efivars/OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
25
+ zdebug " OsIndicationsSupported unsupported"
26
+ return 1
27
+ elif [ ! -r /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
28
+ zdebug " OsIndications unsupported"
29
+ return 1
30
+ fi
31
+
32
+ # Check if the EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x01 bit is set
33
+ if ! (( $(od - An - t u1 - j4 - N1 \
34
+ /sys/firmware/efi/efivars/OsIndicationsSupported-8 be4 df61 -93 ca-11 d2 -aa0 d-00 e098032 b8 c \
35
+ | tr -dc '0 -9 ') & 1 )) ; then
36
+ zdebug " EFI reboot to firmware setup unsupported"
37
+ return 1
38
+ fi
39
+ }
40
+
41
+ set_fw_setup () {
42
+ mount_efivarfs rw
43
+ if [ ! -w /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
44
+ zdebug " OsIndications not writable"
45
+ return 1
46
+ fi
47
+
48
+ mapfile -t osindications < <( od -An -t x1 -v -w1 \
49
+ /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c | tr -dc ' [:alnum:]\n' )
50
+
51
+ # Set the EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x01 bit if not already set
52
+ if ! (( "${osindications[4]} " & 0x01 )) ; then
53
+ printf -v osindications[4] ' %02x' $(( 0 x"${osindications[4]} " | 0x01 ))
54
+
55
+ printf -v bytes ' \\x%02x' " ${osindications[@]} "
56
+ printf ' %b' " $bytes " \
57
+ > /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c
58
+ fi
59
+ }
60
+
20
61
case " ${0##*/ } " in
21
62
reboot)
22
63
trigger=" b"
23
64
;;
24
65
shutdown|poweroff)
25
66
trigger=" o"
26
67
;;
68
+ firmware-setup)
69
+ if ! check_fw_setup || ! set_fw_setup; then
70
+ echo -e " \033[0;31mWARNING: Reboot to UEFI firmware UI unsupported; unable to proceed\033[0m"
71
+ exit 1
72
+ fi
73
+ trigger=" b"
74
+ ;;
27
75
* )
28
76
exit
29
77
;;
@@ -34,7 +82,7 @@ while read -r _pool; do
34
82
done <<< " $( zpool list -H -o name )"
35
83
36
84
sysrq=" /proc/sysrq-trigger"
37
- if [ -e " ${sysrq} " ] && [ -w " ${sysrq} " ]; then
85
+ if [ -e " ${sysrq} " ] && [ -w " ${sysrq} " ]; then
38
86
echo " ${trigger} " > /proc/sysrq-trigger
39
87
else
40
88
echo " ${sysrq} does not exist, hard reset system"
0 commit comments