[PATCH v5 5/5] power: reset: pscrr: record reason for userspace-initiated reboots

From: Faruque Ansari

Date: Mon Nov 23 2026 - 02:05:54 EST


Userspace can request different reboot targets, such as
bootloader, recovery, OTA update, EDL and factory reset.

Add dedicated reset reason codes for these reboot targets to
preserve the requested reboot mode across system resets.

Signed-off-by: Faruque Ansari <faruque.ansari@xxxxxxxxxxxxxxxx>
---
drivers/power/reset/pscrr/pscrr.c | 9 ++++----
include/linux/power/power_on_reason.h | 5 +++++
include/linux/reboot.h | 21 ++++++++++++++++++
kernel/reboot.c | 40 +++++++++++++++++++++++++++++++++++
4 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/drivers/power/reset/pscrr/pscrr.c b/drivers/power/reset/pscrr/pscrr.c
index 9e6dd3e17382..8e345d07269e 100644
--- a/drivers/power/reset/pscrr/pscrr.c
+++ b/drivers/power/reset/pscrr/pscrr.c
@@ -498,18 +498,19 @@ static void pscrr_record_current(void)
}

static int pscrr_reboot_notifier(struct notifier_block *nb,
- unsigned long action, void *unused)
+ unsigned long action, void *cmd)
{
guard(mutex)(&pscrr_lock);

/*
* A reboot, halt or power-off that reaches here with no more specific
- * reason is software-initiated by definition. Record it as such rather
- * than leaving it unattributed; a real cause set earlier (thermal,
+ * reason is attributed from the userspace reboot(2) command string
+ * (e.g. "bootloader", "recovery", "ota-update") when present, or recorded as
+ * software-initiated otherwise. A real cause set earlier (thermal,
* under-voltage, ...) is already latched and left untouched.
*/
if (get_psc_reason() == PSCR_UNKNOWN)
- set_psc_reason(PSCR_SOFTWARE);
+ set_psc_reason(psc_reason_from_reboot_cmd(cmd));

pscrr_record_current();

diff --git a/include/linux/power/power_on_reason.h b/include/linux/power/power_on_reason.h
index 9bcce23c81e9..9bd903594f41 100644
--- a/include/linux/power/power_on_reason.h
+++ b/include/linux/power/power_on_reason.h
@@ -24,5 +24,10 @@
#define POWER_ON_REASON_WATCHDOG_PRETIMEOUT "watchdog pretimeout"
#define POWER_ON_REASON_HARD_LOCKUP "hard lockup"
#define POWER_ON_REASON_SOFT_LOCKUP "soft lockup"
+#define POWER_ON_REASON_REBOOT_BOOTLOADER "reboot to bootloader"
+#define POWER_ON_REASON_REBOOT_RECOVERY "reboot to recovery"
+#define POWER_ON_REASON_REBOOT_OTA "reboot for OTA update"
+#define POWER_ON_REASON_EDL "reboot to emergency download mode"
+#define POWER_ON_REASON_REBOOT_FACTORY_RESET "reboot to factory reset"

#endif /* POWER_ON_REASON_H */
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index 45e64bcad37e..5723852135f2 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -254,6 +254,21 @@ extern void orderly_reboot(void);
* task) detected by the kernel's softlockup watchdog, before it
* escalated to panic.
*
+ * @PSCR_BOOTLOADER: Userspace-requested reboot into the bootloader
+ * (e.g. "reboot bootloader" / fastboot).
+ *
+ * @PSCR_RECOVERY: Userspace-requested reboot into the recovery image
+ * (e.g. "reboot recovery").
+ *
+ * @PSCR_OTA: Userspace-requested reboot to apply an OTA update
+ * (e.g. "reboot ota-update").
+ *
+ * @PSCR_EDL: Userspace-requested reboot into Emergency Download Mode
+ * (e.g. "reboot edl").
+ *
+ * @PSCR_FACTORY_RESET: Userspace-requested reboot to perform a factory
+ * reset (e.g. "reboot factory-reset").
+ *
* @PSCR_REASON_COUNT: Number of defined power state change reasons. This
* value is useful for range checking and potential future extensions
* while maintaining compatibility.
@@ -281,6 +296,11 @@ enum psc_reason {
PSCR_WATCHDOG_PRETIMEOUT,
PSCR_KERNEL_WATCHDOG_HARDLOCKUP,
PSCR_KERNEL_WATCHDOG_SOFTLOCKUP,
+ PSCR_BOOTLOADER,
+ PSCR_RECOVERY,
+ PSCR_OTA,
+ PSCR_EDL,
+ PSCR_FACTORY_RESET,

/* Number of reasons */
PSCR_REASON_COUNT,
@@ -291,6 +311,7 @@ enum psc_reason {
const char *psc_reason_to_str(enum psc_reason reason);
const char *psc_reason_to_token(enum psc_reason reason);
int psc_reason_from_token(const char *token, enum psc_reason *reason);
+enum psc_reason psc_reason_from_reboot_cmd(const char *cmd);

/**
* enum hw_protection_action - Hardware protection action
diff --git a/kernel/reboot.c b/kernel/reboot.c
index b748153d18cc..73655bd2b02b 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -1113,6 +1113,11 @@ static const struct psc_reason_desc psc_reason_descs[] = {
[PSCR_WATCHDOG_PRETIMEOUT] = { "watchdog-pretimeout", POWER_ON_REASON_WATCHDOG_PRETIMEOUT },
[PSCR_KERNEL_WATCHDOG_HARDLOCKUP] = { "hardlockup", POWER_ON_REASON_HARD_LOCKUP },
[PSCR_KERNEL_WATCHDOG_SOFTLOCKUP] = { "softlockup", POWER_ON_REASON_SOFT_LOCKUP },
+ [PSCR_BOOTLOADER] = { "bootloader", POWER_ON_REASON_REBOOT_BOOTLOADER },
+ [PSCR_RECOVERY] = { "recovery", POWER_ON_REASON_REBOOT_RECOVERY },
+ [PSCR_OTA] = { "ota-update", POWER_ON_REASON_REBOOT_OTA },
+ [PSCR_EDL] = { "edl", POWER_ON_REASON_EDL },
+ [PSCR_FACTORY_RESET] = { "factory-reset", POWER_ON_REASON_REBOOT_FACTORY_RESET },
};

/**
@@ -1168,6 +1173,41 @@ int psc_reason_from_token(const char *token, enum psc_reason *reason)
}
EXPORT_SYMBOL_GPL(psc_reason_from_token);

+/**
+ * psc_reason_from_reboot_cmd - Map a userspace reboot(2) command string to a
+ * power-state-change reason.
+ * @cmd: Command string passed via LINUX_REBOOT_CMD_RESTART2 (e.g.
+ * "bootloader", "recovery", "ota-update", "edl", "factory-reset"), or
+ * NULL.
+ *
+ * Return: The specific reason for a recognized command, or PSCR_SOFTWARE for
+ * an unrecognized or absent command.
+ */
+enum psc_reason psc_reason_from_reboot_cmd(const char *cmd)
+{
+ static const struct {
+ const char *cmd;
+ enum psc_reason reason;
+ } cmd_reasons[] = {
+ { "bootloader", PSCR_BOOTLOADER },
+ { "recovery", PSCR_RECOVERY },
+ { "ota-update", PSCR_OTA },
+ { "edl", PSCR_EDL },
+ { "factory-reset", PSCR_FACTORY_RESET },
+ };
+ int i;
+
+ if (!cmd)
+ return PSCR_SOFTWARE;
+
+ for (i = 0; i < ARRAY_SIZE(cmd_reasons); i++)
+ if (!strcmp(cmd, cmd_reasons[i].cmd))
+ return cmd_reasons[i].reason;
+
+ return PSCR_SOFTWARE;
+}
+EXPORT_SYMBOL_GPL(psc_reason_from_reboot_cmd);
+
/**
* __hw_protection_trigger - Trigger an emergency system shutdown or reboot
*

--
2.34.1