Skip to content

Commit 728ea39

Browse files
authored
Merge pull request #1987 from tlaurion/bugfix-reboot_using_syscall
initrd/bin/reboot bugfix: switch from sysrq instant reset to busybox' s reboot kernel syscall (so tpm2.0 does not increment TPM DA counter by one)
2 parents d0350e0 + d343c53 commit 728ea39

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

config/busybox.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ CONFIG_FEATURE_XARGS_SUPPORT_ARGS_FILE=y
500500
# CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE is not set
501501
# CONFIG_HALT is not set
502502
# CONFIG_POWEROFF is not set
503-
# CONFIG_REBOOT is not set
503+
CONFIG_REBOOT=y
504504
# CONFIG_FEATURE_WAIT_FOR_INIT is not set
505505
# CONFIG_FEATURE_CALL_TELINIT is not set
506506
CONFIG_TELINIT_PATH=""

initrd/bin/reboot

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33

44
TRACE_FUNC
55

6-
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ]; then
7-
#Generalize user prompt to continue reboot or go to recovery shell
8-
read -r -n 1 -s -p "Press any key to continue reboot or 'r' to go to recovery shell: " REPLY
9-
echo
10-
if [ "$REPLY" = "r" ] || [ "$REPLY" = "R" ]; then
11-
recovery "Reboot call bypassed to go into recovery shell to debug"
12-
fi
13-
fi
14-
156
# Shut down TPM
167
if [ "$CONFIG_TPM" = "y" ]; then
178
tpmr shutdown
@@ -23,5 +14,26 @@ echo s > /proc/sysrq-trigger
2314
# Remount all mounted filesystems in read-only mode
2415
echo u > /proc/sysrq-trigger
2516

26-
# Immediately reboot the system, without unmounting or syncing filesystems
27-
echo b > /proc/sysrq-trigger
17+
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ]; then
18+
#Generalize user prompt to continue reboot or go to recovery shell
19+
read -r -n 1 -s -p "Press any key to continue reboot or 'r' to go to recovery shell: " REPLY
20+
echo
21+
if [ "$REPLY" = "r" ] || [ "$REPLY" = "R" ]; then
22+
recovery "Reboot call bypassed to go into recovery shell to debug"
23+
fi
24+
fi
25+
26+
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ]; then
27+
DEBUG "DEBUG: TPM shutdown and filesystem operations complete"
28+
read -r -p "Press Enter to issue final reboot syscall: "
29+
fi
30+
31+
# Use busybox reboot explicitly (symlinks removed to avoid conflicts)
32+
if busybox --help 2>&1 | grep -q reboot; then
33+
DEBUG "Using busybox reboot syscall for orderly shutdown"
34+
busybox reboot -f
35+
else
36+
# Fallback to sysrq if busybox doesn't have reboot support
37+
DEBUG "Busybox reboot not available, falling back to sysrq"
38+
echo b > /proc/sysrq-trigger
39+
fi

modules/busybox

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ $(initrd_bin_dir)/busybox: $(build)/$(busybox_dir)/.build
3232
| tee -a $(build)/log/busybox.log \
3333
$(VERBOSE_REDIRECT) \
3434
)
35+
# Remove busybox's reboot symlink that conflicts with our custom script
36+
$(call do,RM-SYMLINKS,bin/busybox,\
37+
rm -f $(initrd_bin_dir)/../sbin/reboot \
38+
$(VERBOSE_REDIRECT) \
39+
)
3540
@touch $< # ensure that our build file is still newer
3641

3742

0 commit comments

Comments
 (0)