Skip to content

Commit

Permalink
zfsbootmenu/bin/firmware-setup: new utility
Browse files Browse the repository at this point in the history
reboots to UEFI firmware setup if supported

fixes #423
  • Loading branch information
classabbyamp committed Mar 17, 2024
1 parent 406cf45 commit f1add08
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions zfsbootmenu/bin/firmware-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

source /lib/zfsbootmenu-core.sh >/dev/null 2>&1 || exit 1

if ! is_efi_system; then
zdebug "efivarfs unsupported"
return 1
elif [ ! -r /sys/firmware/efi/efivars/OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
zdebug "OsIndicationsSupported unsupported"
return 1
elif [ ! -r /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
zdebug "OsIndications unsupported"
return 1
fi

# Check if the EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x01 bit is set
if ! (( $(od -An -t u1 -j4 -N1 \
/sys/firmware/efi/efivars/OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c \
| tr -dc '0-9') & 1 )); then
zdebug "EFI reboot to firmware UI unsupported"
return 1
fi

mount_efivarfs rw
if [ ! -w /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
zdebug "OsIndications not writable"
return 1
fi

mapfile -t osindications < <(od -An -t x1 -v -w1 \
/sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c | tr -dc '[:alnum:]\n')

# set the required flags:
# EFI_VARIABLE_NON_VOLATILE = 0x01
# EFI_VARIABLE_BOOTSERVICE_ACCESS = 0x02
# EFI_VARIABLE_RUNTIME_ACCESS = 0x04
osindications[0]=$(( 0x"${osindications[0]}" | 0x07 ))

# Set the EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x01 bit
osindications[4]=$(( 0x"${osindications[4]}" | 0x01 ))

printf "$(printf '\\x%02x' "${osindications[@]}")" > /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c

reboot

0 comments on commit f1add08

Please sign in to comment.