From: Petr Hodina <[email protected]> Show in the boot menu header the boot reason read from the Android Bootloader Control Block. Each field on the header line is independently optional (NULL on error/absent hardware) and simply skipped.
Signed-off-by: Petr Hodina <[email protected]> --- cmd/phonemenu.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cmd/phonemenu.c b/cmd/phonemenu.c index 7478661d049..8f29d8d704b 100644 --- a/cmd/phonemenu.c +++ b/cmd/phonemenu.c @@ -2,6 +2,7 @@ #include <android_ab.h> #include <ansi.h> +#include <bcb.h> #include <blk.h> #include <cli.h> #include <command.h> @@ -471,17 +472,53 @@ static const char *pm_slot(void) return slot == 0 ? "_a" : "_b"; } +/* + * Boot reason from the Android Bootloader Control Block on the "storage" + * device's misc partition. Maps the raw "command" field to short labels: + * "" -> "normal" + * "boot-recovery" -> "recovery" + * "bootonce-bootloader" -> "fastboot" + * "boot-fastboot" -> "fastbootd" + * anything else -> the raw command + */ +static const char *pm_reason(void) +{ + static char buf[32]; + char cmd[32]; + + if (bcb_find_partition_and_load(env_get("storage") ?: "scsi", 0, "misc")) + return "normal"; + if (bcb_get(BCB_FIELD_COMMAND, cmd, sizeof(cmd))) + return "normal"; + + if (!cmd[0]) + return "normal"; + if (!strncmp(cmd, "boot-recovery", sizeof(cmd))) + return "recovery"; + if (!strncmp(cmd, "bootonce-bootloader", sizeof(cmd))) + return "fastboot"; + if (!strncmp(cmd, "boot-fastboot", sizeof(cmd))) + return "fastbootd"; + + strlcpy(buf, cmd, sizeof(buf)); + return buf; +} + static int do_phonemenu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { static char slot_line[96]; const char *slot = pm_slot(); + const char *reason = pm_reason(); const char *sub = (argc > 1) ? argv[1] : "main"; int n = 0; if (slot) n += snprintf(slot_line + n, sizeof(slot_line) - n, "slot %s", slot); + if (reason) + n += snprintf(slot_line + n, sizeof(slot_line) - n, + "%s%s", n ? " - " : "", reason); if (!strcmp(sub, "advanced")) return pm_run(pm_advanced, ARRAY_SIZE(pm_advanced), -- 2.55.0
