diff mbox series

[meta-oe,01/10] android-tools: adbd: forward the reboot target to RESTART2

Message ID 20261110-android-tools-adbd-v1-1-cc2176f381c3@gmail.com
State New
Headers show
Series android-tools: adbd fixes and opt-in access control for Linux systems | expand

Commit Message

Alex Kiernan Nov. 10, 2026, 5:35 p.m. UTC
reboot_device() hard-codes the RESTART2 reason to "adb" on non-Android
builds and drops the requested target, so `adb reboot recovery` and
`adb reboot bootloader` are plain reboots on any board whose kernel picks
the boot mode from the reboot reason (reboot-mode, as on Rockchip).

AI-Generated: Claude Opus 5.5 (Claude Code)
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---
 ...dbd-forward-the-reboot-target-to-RESTART2.patch | 42 ++++++++++++++++++++++
 .../android-tools/android-tools_35.0.2.bb          |  1 +
 2 files changed, 43 insertions(+)
diff mbox series

Patch

diff --git a/meta-oe/recipes-devtools/android-tools/android-tools/0016-adbd-forward-the-reboot-target-to-RESTART2.patch b/meta-oe/recipes-devtools/android-tools/android-tools/0016-adbd-forward-the-reboot-target-to-RESTART2.patch
new file mode 100644
index 000000000000..02b7a44ed802
--- /dev/null
+++ b/meta-oe/recipes-devtools/android-tools/android-tools/0016-adbd-forward-the-reboot-target-to-RESTART2.patch
@@ -0,0 +1,42 @@ 
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Alex Kiernan <alex.kiernan@gmail.com>
+Date: Mon, 15 Jun 2026 00:00:00 +0000
+Subject: [PATCH] adbd: forward the reboot target to RESTART2
+
+On non-Android Linux builds reboot_device() hard-codes the RESTART2
+reboot reason to "adb" and throws away the requested target, so
+"adb reboot recovery", "adb reboot bootloader", etc. all collapse to a
+plain reboot.
+
+On Rockchip the reboot reason string is consumed by the kernel
+reboot-mode driver (drivers/power/reset/reboot-mode.c), which strcmp()s
+it against the device-tree "mode-*" entries (mode-recovery,
+mode-bootloader, mode-loader, ...) to pick the boot-mode magic written
+to the PMU syscon register that U-Boot reads on the next boot. With the
+reason fixed to "adb" nothing matches and it falls back to a normal
+boot.
+
+Pass the real target through instead. An empty target (bare
+"adb reboot") becomes "", which the kernel treats as "normal", matching
+the previous behaviour for that case.
+
+Upstream-Status: Pending
+
+Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
+---
+ packages/modules/adb/daemon/services.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/packages/modules/adb/daemon/services.cpp b/packages/modules/adb/daemon/services.cpp
+index 1b2731442a2a..968e9e74ffa4 100644
+--- a/packages/modules/adb/daemon/services.cpp
++++ b/packages/modules/adb/daemon/services.cpp
+@@ -219,7 +219,7 @@ static void remount_service(unique_fd fd) {
+     auto reboot_service = [name](unique_fd fd) {
+         sync();
+         if (syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
+-                    LINUX_REBOOT_CMD_RESTART2, "adb") != 0) {
++                    LINUX_REBOOT_CMD_RESTART2, name.c_str()) != 0) {
+             WriteFdFmt(fd.get(), "reboot (%s) failed: %s\n", name.c_str(), strerror(errno));
+             return;
+         }
diff --git a/meta-oe/recipes-devtools/android-tools/android-tools_35.0.2.bb b/meta-oe/recipes-devtools/android-tools/android-tools_35.0.2.bb
index e9785ac235de..4961a13963c4 100644
--- a/meta-oe/recipes-devtools/android-tools/android-tools_35.0.2.bb
+++ b/meta-oe/recipes-devtools/android-tools/android-tools_35.0.2.bb
@@ -60,6 +60,7 @@  SRC_URI = "https://deb.debian.org/debian/pool/main/a/android-platform-tools/andr
            file://0013-adb-sysdeps-provide-pread64-pwrite64-lseek64-fallba.patch \
            file://0014-daemon-auth-vendor-a-portable-b64_pton-for-non-glib.patch \
            file://0015-adbd-make-fs-config-opt-in-on-non-android-builds.patch \
+           file://0016-adbd-forward-the-reboot-target-to-RESTART2.patch \
            "
 
 SRC_URI[orig.md5sum] = "352376965cdef7bd7505d8fefdd43d50"