From 470ae15cedfd51e05db1691750932bc053effcc8 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Tue, 3 Nov 2026 08:31:02 -0647 Subject: [PATCH 1/6] reboot-to, omamobile-modem: a deliberate restart doesn't cost the next boot its modem reboot-to restarts at once, so systemd never stops omamobile-modem.service, its --stopped never removes modem-up, and the next boot skipped the modem as if the last one had hung (#390). bin/omamobile push ends this way. reboot-to now writes and syncs the boot ID it ends to /var/lib/omamobile/deliberate-restart before rebooting (best effort: nothing in the initramfs, where that folder doesn't exist). omamobile-modem-start treats a modem-up marker from the boot the note names as a clean stop: it removes the marker, its refused copies and the note, and starts. A hang or reset leaves no note and is still refused, and so is a bring-up that never reached ONLINE. Every device package's copy of reboot-to.c changes the same way (cheetah, tegu, husky, felix, panther, lynx, raven), since their tests hold them to cheetah's; each package's version moves up one. On a phone without the modem stack the note is written and never read. The 9a's own start (#372) will use the note too. --- .../omamobile-device-cheetah/src/reboot-to.c | 44 +++++++++++++++++++ .../omamobile-device-felix/src/reboot-to.c | 44 +++++++++++++++++++ packages/omamobile-device-felix/version | 2 +- .../omamobile-device-husky/src/reboot-to.c | 44 +++++++++++++++++++ packages/omamobile-device-husky/version | 2 +- .../omamobile-device-lynx/src/reboot-to.c | 44 +++++++++++++++++++ packages/omamobile-device-lynx/version | 2 +- .../omamobile-device-panther/src/reboot-to.c | 44 +++++++++++++++++++ .../omamobile-device-raven/src/reboot-to.c | 44 +++++++++++++++++++ packages/omamobile-device-raven/version | 2 +- .../omamobile-device-tegu/src/reboot-to.c | 44 +++++++++++++++++++ .../omamobile-modem/lib/omamobile-modem-start | 12 +++++ packages/omamobile-modem/test/all | 19 ++++++++ packages/omamobile-modem/version | 2 +- 14 files changed, 344 insertions(+), 5 deletions(-) diff --git a/packages/omamobile-device-cheetah/src/reboot-to.c b/packages/omamobile-device-cheetah/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-cheetah/src/reboot-to.c +++ b/packages/omamobile-device-cheetah/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-felix/src/reboot-to.c b/packages/omamobile-device-felix/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-felix/src/reboot-to.c +++ b/packages/omamobile-device-felix/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-felix/version b/packages/omamobile-device-felix/version index c946ee616..11808190d 100644 --- a/packages/omamobile-device-felix/version +++ b/packages/omamobile-device-felix/version @@ -1 +1 @@ -0.1.6 +0.1.7 diff --git a/packages/omamobile-device-husky/src/reboot-to.c b/packages/omamobile-device-husky/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-husky/src/reboot-to.c +++ b/packages/omamobile-device-husky/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-husky/version b/packages/omamobile-device-husky/version index 11808190d..699c6c6d4 100644 --- a/packages/omamobile-device-husky/version +++ b/packages/omamobile-device-husky/version @@ -1 +1 @@ -0.1.7 +0.1.8 diff --git a/packages/omamobile-device-lynx/src/reboot-to.c b/packages/omamobile-device-lynx/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-lynx/src/reboot-to.c +++ b/packages/omamobile-device-lynx/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-lynx/version b/packages/omamobile-device-lynx/version index ee1372d33..717903969 100644 --- a/packages/omamobile-device-lynx/version +++ b/packages/omamobile-device-lynx/version @@ -1 +1 @@ -0.2.2 +0.2.3 diff --git a/packages/omamobile-device-panther/src/reboot-to.c b/packages/omamobile-device-panther/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-panther/src/reboot-to.c +++ b/packages/omamobile-device-panther/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-raven/src/reboot-to.c b/packages/omamobile-device-raven/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-raven/src/reboot-to.c +++ b/packages/omamobile-device-raven/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-raven/version b/packages/omamobile-device-raven/version index 013adb716..db7a48047 100644 --- a/packages/omamobile-device-raven/version +++ b/packages/omamobile-device-raven/version @@ -1 +1 @@ -0.1.30 +0.1.31 diff --git a/packages/omamobile-device-tegu/src/reboot-to.c b/packages/omamobile-device-tegu/src/reboot-to.c index f79e948ed..5feb6f1ef 100644 --- a/packages/omamobile-device-tegu/src/reboot-to.c +++ b/packages/omamobile-device-tegu/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,52 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + */ +#define NOTE_DIR "/var/lib/omamobile" +#define NOTE NOTE_DIR "/deliberate-restart" + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-modem/lib/omamobile-modem-start b/packages/omamobile-modem/lib/omamobile-modem-start index aea70393d..478fd69f8 100755 --- a/packages/omamobile-modem/lib/omamobile-modem-start +++ b/packages/omamobile-modem/lib/omamobile-modem-start @@ -61,6 +61,7 @@ MARK=${OMAMOBILE_MODEM_LATCH:-/var/lib/omamobile/modem-bringup-started} UP=${OMAMOBILE_MODEM_UP_MARK:-/var/lib/omamobile/modem-up} HOLD=${OMAMOBILE_MODEM_HOLD:-/etc/omamobile/modem-hold} REFUSED=${OMAMOBILE_MODEM_REFUSED:-/run/omamobile/modem-refused} +NOTE=${OMAMOBILE_DELIBERATE_RESTART:-/var/lib/omamobile/deliberate-restart} LIB=/usr/lib/omamobile-vendor # What tools/phone-provision puts on the phone (the unit's conditions name # the same three): without them the modem can't start, so nothing is @@ -140,6 +141,17 @@ if [[ -e $MARK ]]; then say "the last bring-up ($(cat "$MARK")) never reached ONLINE; skipping the modem (omamobile-modem-start --retry)" refuse "Off: last bring-up hung" fi +# reboot-to notes the boot it ends (/var/lib/omamobile/deliberate-restart), +# since it skips systemd's shutdown and so the unit's stop: a modem-up marker +# from that very boot ended on purpose (bin/omamobile push, a reboot to the +# bootloader), not in a hang or a reset, so it counts as a clean stop. The +# note records that the restart was asked for, not that it finished: a hang +# in the restart itself is the same gap a clean systemctl reboot has. +if [[ -e $UP && -s $NOTE ]] && grep -q "boot $(head -c 64 "$NOTE" | tr -d '\n')\$" "$UP"; then + say "the last boot with the modem up ($(cat "$UP")) ended with reboot-to, as a clean stop does: $UP removed" + rm -f "$UP" "$UP".refused-* "$NOTE" + sync +fi [[ -e $UP ]] && refuse_unclean # Past the marker decision. The test's stop point (see the header): nothing diff --git a/packages/omamobile-modem/test/all b/packages/omamobile-modem/test/all index 70f5ae26d..9ad2b0b38 100755 --- a/packages/omamobile-modem/test/all +++ b/packages/omamobile-modem/test/all @@ -263,6 +263,25 @@ out=$(start) && fail "the second unclean boot in a row is refused" [[ $(cat "$m/run/refused") == "Off after a hang or reset (held)" ]] || fail "the held reason for the tile: $(cat "$m/run/refused")" out=$(start) && fail "the held marker refuses the boot after too" [[ $out == *"no clean stop since the last refusal"* && -e $m/up && $(ls "$m"/up.refused-* | wc -l) -eq 1 ]] || fail "held: the marker and the one copy stay: $out" +# reboot-to's note (in a directory of its own, so the state above is kept): +# a modem-up marker from the boot the note names ended on purpose (push, a +# reboot to the bootloader) and counts as a clean stop: the marker, its +# refused copies and the note go, and the start gets past the markers. A note +# naming another boot changes nothing: the marker is refused as above. +n=$t/note-markers; mkdir -p "$n/run" +nstart() { OMAMOBILE_MODEM_LATCH=$n/latch OMAMOBILE_MODEM_UP_MARK=$n/up OMAMOBILE_MODEM_HOLD=$n/hold OMAMOBILE_MODEM_REFUSED=$n/run/refused \ + OMAMOBILE_DELIBERATE_RESTART=$n/note OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS=1 timeout 20 bash $s 2>&1; } +printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 00000000-0000-0000-0000-000000000000 > "$n/up" +printf '%s\n' 11111111-1111-1111-1111-111111111111 > "$n/note" +out=$(nstart) && fail "a note from another boot doesn't clear the marker: $out" +[[ -e $n/note && $out == *"ended without a clean stop"* && $out != *"ended with reboot-to"* ]] || fail "a note from another boot clears nothing: $out" +rm -f "$n"/up* "$n/note" +printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 00000000-0000-0000-0000-000000000000 > "$n/up" +: > "$n/up.refused-x" +printf '%s\n' 00000000-0000-0000-0000-000000000000 > "$n/note" +out=$(nstart) || fail "a deliberate restart gets past the markers (rc=$?): $out" +[[ $out == *"ended with reboot-to"* && $out == *"$stop_line"* && $out != *"ended without a clean stop"* ]] || fail "a deliberate restart isn't a hang: $out" +[[ ! -e $n/up && ! -e $n/up.refused-x && ! -e $n/note && ! -e $n/latch ]] || fail "the note clears the marker, its copies and itself, and writes no latch: $(ls "$n")" printf '%s boot %s\n' "$(date -Is)" "$(cat /proc/sys/kernel/random/boot_id)" > "$m/up" out=$(SERVICE_RESULT=success bash $s --stopped 2>&1) || fail "--stopped exits 0" [[ ! -e $m/up && -z $(ls "$m"/up.refused-* 2>/dev/null) ]] || fail "a clean stop of this boot's marker removes the refused copies: $(ls "$m")" diff --git a/packages/omamobile-modem/version b/packages/omamobile-modem/version index e8e277f2f..04c5555c6 100644 --- a/packages/omamobile-modem/version +++ b/packages/omamobile-modem/version @@ -1 +1 @@ -0.1.16 +0.1.17 From 170669888432669c5666ebf2c1c94bb7eb422762 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:45:15 -0647 Subject: [PATCH 2/6] reboot-to: note only a boot that has the modem up reboot-to noted every boot it ended, so a restart in a later boot without the modem replaced the note for the boot that had it up. On the palmtop on 2026-11-04 a boot with the CP ONLINE ended with a push while the boot unit was disabled for a sleep series; the next pushes rewrote the note, and when the unit was enabled again its start refused on that boot's latch as if it had hung. The note is now written only when this boot's modem marker (the 7 Pro's modem-up, the 9a's modem-bringup-started) names it. Checked with a build pointed at a scratch directory: no marker, no note; a marker naming this boot (either name), a note; a marker naming another boot, no note. --- .../omamobile-device-cheetah/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-cheetah/version | 2 +- .../omamobile-device-felix/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-felix/version | 2 +- .../omamobile-device-husky/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-husky/version | 2 +- .../omamobile-device-lynx/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-lynx/version | 2 +- .../omamobile-device-panther/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-panther/version | 2 +- .../omamobile-device-raven/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-raven/version | 2 +- .../omamobile-device-tegu/src/reboot-to.c | 34 +++++++++++++++++++ packages/omamobile-device-tegu/version | 2 +- 14 files changed, 245 insertions(+), 7 deletions(-) diff --git a/packages/omamobile-device-cheetah/src/reboot-to.c b/packages/omamobile-device-cheetah/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-cheetah/src/reboot-to.c +++ b/packages/omamobile-device-cheetah/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-cheetah/version b/packages/omamobile-device-cheetah/version index 6871b9e7a..6ee33ba22 100644 --- a/packages/omamobile-device-cheetah/version +++ b/packages/omamobile-device-cheetah/version @@ -1 +1 @@ -0.1.44 +0.1.45 diff --git a/packages/omamobile-device-felix/src/reboot-to.c b/packages/omamobile-device-felix/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-felix/src/reboot-to.c +++ b/packages/omamobile-device-felix/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-felix/version b/packages/omamobile-device-felix/version index 11808190d..699c6c6d4 100644 --- a/packages/omamobile-device-felix/version +++ b/packages/omamobile-device-felix/version @@ -1 +1 @@ -0.1.7 +0.1.8 diff --git a/packages/omamobile-device-husky/src/reboot-to.c b/packages/omamobile-device-husky/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-husky/src/reboot-to.c +++ b/packages/omamobile-device-husky/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-husky/version b/packages/omamobile-device-husky/version index 699c6c6d4..1a030947e 100644 --- a/packages/omamobile-device-husky/version +++ b/packages/omamobile-device-husky/version @@ -1 +1 @@ -0.1.8 +0.1.9 diff --git a/packages/omamobile-device-lynx/src/reboot-to.c b/packages/omamobile-device-lynx/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-lynx/src/reboot-to.c +++ b/packages/omamobile-device-lynx/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-lynx/version b/packages/omamobile-device-lynx/version index 717903969..abd410582 100644 --- a/packages/omamobile-device-lynx/version +++ b/packages/omamobile-device-lynx/version @@ -1 +1 @@ -0.2.3 +0.2.4 diff --git a/packages/omamobile-device-panther/src/reboot-to.c b/packages/omamobile-device-panther/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-panther/src/reboot-to.c +++ b/packages/omamobile-device-panther/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-panther/version b/packages/omamobile-device-panther/version index c946ee616..11808190d 100644 --- a/packages/omamobile-device-panther/version +++ b/packages/omamobile-device-panther/version @@ -1 +1 @@ -0.1.6 +0.1.7 diff --git a/packages/omamobile-device-raven/src/reboot-to.c b/packages/omamobile-device-raven/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-raven/src/reboot-to.c +++ b/packages/omamobile-device-raven/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-raven/version b/packages/omamobile-device-raven/version index db7a48047..28d007539 100644 --- a/packages/omamobile-device-raven/version +++ b/packages/omamobile-device-raven/version @@ -1 +1 @@ -0.1.31 +0.1.32 diff --git a/packages/omamobile-device-tegu/src/reboot-to.c b/packages/omamobile-device-tegu/src/reboot-to.c index 5feb6f1ef..c716d9465 100644 --- a/packages/omamobile-device-tegu/src/reboot-to.c +++ b/packages/omamobile-device-tegu/src/reboot-to.c @@ -20,10 +20,39 @@ * so it notes the boot it ends, before rebooting: the next start then knows * this boot ended on purpose. Best effort: without /var/lib/omamobile (the * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. */ +#ifndef NOTE_DIR #define NOTE_DIR "/var/lib/omamobile" +#endif #define NOTE NOTE_DIR "/deliberate-restart" +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + static void note_deliberate_restart(void) { char id[64]; @@ -37,6 +66,11 @@ static void note_deliberate_restart(void) return; } fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (fd < 0) return; diff --git a/packages/omamobile-device-tegu/version b/packages/omamobile-device-tegu/version index 1866a362b..13dead7eb 100644 --- a/packages/omamobile-device-tegu/version +++ b/packages/omamobile-device-tegu/version @@ -1 +1 @@ -0.2.9 +0.2.10 From 0833d978059f78e2156a7a80cf4c2e356909960c Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:15:41 -0643 Subject: [PATCH 3/6] omamobile-device-akita 0.1.2: reboot-to's note that it stops no unit, as in the cheetah package The Pixel 8a's device package came to main after this branch was cut. Its reboot-to.c is a copy of cheetah's and its test holds it to that, so it takes the same change. --- .../omamobile-device-akita/src/reboot-to.c | 78 +++++++++++++++++++ packages/omamobile-device-akita/version | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/packages/omamobile-device-akita/src/reboot-to.c b/packages/omamobile-device-akita/src/reboot-to.c index f79e948ed..c716d9465 100644 --- a/packages/omamobile-device-akita/src/reboot-to.c +++ b/packages/omamobile-device-akita/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,86 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. + */ +#ifndef NOTE_DIR +#define NOTE_DIR "/var/lib/omamobile" +#endif +#define NOTE NOTE_DIR "/deliberate-restart" + +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + snprintf(want, sizeof(want), "boot %s", id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason); diff --git a/packages/omamobile-device-akita/version b/packages/omamobile-device-akita/version index 17e51c385..d917d3e26 100644 --- a/packages/omamobile-device-akita/version +++ b/packages/omamobile-device-akita/version @@ -1 +1 @@ -0.1.1 +0.1.2 From 5c6e722b1da9b388f9c0cfc08a3da045924f09ca Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:22:34 -0643 Subject: [PATCH 4/6] omamobile-modem 0.1.20: the reboot-to note beside main's one counted unclean end Main's 0.1.19 (#634) starts the modem after one unclean end and holds it off after two in a row. The note still matters there: a reboot-to with the modem up would count as one of the two. The test now checks that a note naming another boot leaves the first unclean end counted and the second held, and that a note naming the marker's boot clears a counted copy too. AGENTS.md's stop-the-modem rule says what the note changes. --- AGENTS.md | 2 +- packages/omamobile-modem/lib/omamobile-modem-start | 3 ++- packages/omamobile-modem/test/all | 14 ++++++++++---- packages/omamobile-modem/version | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5736ccc2e..a8d547454 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ Omarchy Mobile runs native Omarchy (Arch Linux ARM, Hyprland, Omarchy's packages This leaves other people's staged and unstaged changes alone. - **Moving a feature from bring-up into a package:** bump the package `version`, enable nothing that isn't hang-safe, and delete the bring-up files from `/etc/modprobe.d` on the phone (`omamobile-*-bringup.conf`, and any hand-copied package file). A file in `/etc/modprobe.d` replaces the package's `/usr/lib/modprobe.d` file of the same name, so a stale `omamobile-aoc.conf` there hid the package's new blacklist. - **Kernel releases change with every push** (`7.3.0-rc6-omamobile-push1-NNNNN-g`). `bin/omamobile push` runs `modules-push` when the tarball's checksum differs. Without its modules a new kernel boots without its drivers, the GPU among them. `modules-push` replaces `/usr/lib/modules/` as a whole; on the 9a that once took a hand-installed panel driver with it, and the display stayed on the boot logo. It now refuses when the folder holds modules added or swapped by hand since the last push (it records what each push installed in `.omamobile-modules.sha256`), and `OMAMOBILE_MODULES_REPLACE=1` overrides that, wiping them. Pin a daily release whose folder carries hand-installed modules (`/usr/lib/modules/.omamobile-pinned`), and keep a copy before overriding (`tar -C /usr/lib/modules -cf … `). -- **Stop the modem before a `push` or a `reboot-to`.** `push` ends in `reboot-to`, a raw reboot syscall that stops no unit, so `omamobile-modem.service` never runs its clean stop and its `modem-up` marker stays. On the 7 Pro, where the modem starts at boot (device-cheetah 0.1.43+), the next boot counts that as an unclean end ("ended without a clean stop: a hang or a reset"); from `omamobile-modem` 0.1.19 it starts the modem all the same (before, it skipped the modem once), and a second such end before a clean stop holds it off until `omamobile-modem-start --retry`. So a skipped stop no longer costs a boot's modem, but it uses up the one unclean end the guard allows. This happened on 2026-11-08 after a `reboot-to bootloader` taken to charge a flat battery. So run `systemctl stop omamobile-modem` first, as part of the reboot the human said yes to; a reboot that needs no reason can be `systemctl reboot` instead, which stops it. The stop powers the CP off (one recovered UFS error-handler pass, as any reboot with the modem up costs) and, with the NV overlay on, captures its writes. For now it takes about 40 s and ends as "failed", with the CP's power-off logged as a crash; the marker is still removed ([#532](https://github.com/derekross/omarchy-mobile/issues/532)). This is not the restart the modem notes below forbid: nothing starts the modem again before the reboot. [#403](https://github.com/derekross/omarchy-mobile/pull/403), still open, would let the next boot start the modem after a `reboot-to`; the CP's ordered power-off and the NV capture would still come only from the unit's stop. [MODEM-PLAN](device/cheetah/MODEM-PLAN.md) M4.6b +- **Stop the modem before a `push` or a `reboot-to`.** `push` ends in `reboot-to`, a raw reboot syscall that stops no unit, so `omamobile-modem.service` never runs its clean stop and its `modem-up` marker stays. On the 7 Pro, where the modem starts at boot (device-cheetah 0.1.43+), the next boot counts that as an unclean end ("ended without a clean stop: a hang or a reset"); from `omamobile-modem` 0.1.19 it starts the modem all the same (before, it skipped the modem once), and a second such end before a clean stop holds it off until `omamobile-modem-start --retry`. So a skipped stop no longer costs a boot's modem, but it uses up the one unclean end the guard allows. This happened on 2026-11-08 after a `reboot-to bootloader` taken to charge a flat battery. So run `systemctl stop omamobile-modem` first, as part of the reboot the human said yes to; a reboot that needs no reason can be `systemctl reboot` instead, which stops it. The stop powers the CP off (one recovered UFS error-handler pass, as any reboot with the modem up costs) and, with the NV overlay on, captures its writes. For now it takes about 40 s and ends as "failed", with the CP's power-off logged as a crash; the marker is still removed ([#532](https://github.com/derekross/omarchy-mobile/issues/532)). This is not the restart the modem notes below forbid: nothing starts the modem again before the reboot. From `omamobile-modem` 0.1.20, with a device package whose `reboot-to` notes the boot it ends ([#403](https://github.com/derekross/omarchy-mobile/pull/403)), the next boot takes a marker from that boot as a clean stop, so a `reboot-to` no longer uses up the unclean end; the CP's ordered power-off and the NV capture still come only from the unit's stop, so the rule stands. [MODEM-PLAN](device/cheetah/MODEM-PLAN.md) M4.6b ## 3. How the tools fit together diff --git a/packages/omamobile-modem/lib/omamobile-modem-start b/packages/omamobile-modem/lib/omamobile-modem-start index 84249af42..2cb104a80 100755 --- a/packages/omamobile-modem/lib/omamobile-modem-start +++ b/packages/omamobile-modem/lib/omamobile-modem-start @@ -146,7 +146,8 @@ fi # reboot-to notes the boot it ends (/var/lib/omamobile/deliberate-restart), # since it skips systemd's shutdown and so the unit's stop: a modem-up marker # from that very boot ended on purpose (bin/omamobile push, a reboot to the -# bootloader), not in a hang or a reset, so it counts as a clean stop. The +# bootloader), not in a hang or a reset, so it counts as a clean stop and not +# as an unclean end (two of those in a row would hold the modem off). The # note records that the restart was asked for, not that it finished: a hang # in the restart itself is the same gap a clean systemctl reboot has. if [[ -e $UP && -s $NOTE ]] && grep -q "boot $(head -c 64 "$NOTE" | tr -d '\n')\$" "$UP"; then diff --git a/packages/omamobile-modem/test/all b/packages/omamobile-modem/test/all index 9180036fc..54d2aa75a 100755 --- a/packages/omamobile-modem/test/all +++ b/packages/omamobile-modem/test/all @@ -315,16 +315,22 @@ out=$(start) && fail "the held marker refuses the boot after too" # reboot-to's note (in a directory of its own, so the state above is kept): # a modem-up marker from the boot the note names ended on purpose (push, a # reboot to the bootloader) and counts as a clean stop: the marker, its -# refused copies and the note go, and the start gets past the markers. A note -# naming another boot changes nothing: the marker is refused as above. +# refused copies and the note go, and the start gets past the markers, also +# where a counted unclean end would otherwise hold it. A note naming another +# boot changes nothing: the marker is counted as an unclean end as above, and +# with one already counted it is held. n=$t/note-markers; mkdir -p "$n/run" nstart() { OMAMOBILE_MODEM_LATCH=$n/latch OMAMOBILE_MODEM_UP_MARK=$n/up OMAMOBILE_MODEM_HOLD=$n/hold OMAMOBILE_MODEM_REFUSED=$n/run/refused \ OMAMOBILE_DELIBERATE_RESTART=$n/note OMAMOBILE_MODEM_TEST_STOP_AFTER_CHECKS=1 timeout 20 bash $s 2>&1; } printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 00000000-0000-0000-0000-000000000000 > "$n/up" printf '%s\n' 11111111-1111-1111-1111-111111111111 > "$n/note" -out=$(nstart) && fail "a note from another boot doesn't clear the marker: $out" +out=$(nstart) || fail "a note from another boot leaves the first unclean end to start as without it (rc=$?): $out" [[ -e $n/note && $out == *"ended without a clean stop"* && $out != *"ended with reboot-to"* ]] || fail "a note from another boot clears nothing: $out" -rm -f "$n"/up* "$n/note" +[[ ! -e $n/up && $(ls "$n"/up.refused-* | wc -l) -eq 1 ]] || fail "a note from another boot: the marker is counted as an unclean end: $(ls "$n")" +printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 00000000-0000-0000-0000-000000000000 > "$n/up" +out=$(nstart) && fail "a note from another boot doesn't save the second unclean end from the hold: $out" +[[ -e $n/note && -e $n/up && $out == *"no clean stop since the last refusal"* && $out != *"ended with reboot-to"* ]] || fail "a note from another boot, a second unclean end: held: $out" +rm -f "$n"/up* "$n/note" "$n/run/refused" printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 00000000-0000-0000-0000-000000000000 > "$n/up" : > "$n/up.refused-x" printf '%s\n' 00000000-0000-0000-0000-000000000000 > "$n/note" diff --git a/packages/omamobile-modem/version b/packages/omamobile-modem/version index d8a023ec1..baa983785 100644 --- a/packages/omamobile-modem/version +++ b/packages/omamobile-modem/version @@ -1 +1 @@ -0.1.19 +0.1.20 From 2c426e5d89caa273d9a3dba4e7b05c64bcefb3f6 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:32:54 -0643 Subject: [PATCH 5/6] reboot-to, omamobile-modem 0.1.21: no snprintf in reboot-to.c, and the note keeps a counted unclean end reboot-to.c is linked into the initramfs against musl with no compiler builtins when a device package has no bootctl, and musl's vfprintf needs them: with the snprintf line that link fails with undefined __addtf3, __extenddftf2 and seven more. The line is strcpy and strcat now, in all eight copies, and device-cheetah's test refuses a printf-family call in the file. The note no longer removes the modem-up marker's counted copies. It keeps a deliberate restart from being counted as an unclean end, but it doesn't end a streak: a hang, a push and a second hang are held, as the 9a's starter already does. Main took 0.1.20, so this is 0.1.21. --- AGENTS.md | 2 +- packages/omamobile-device-akita/src/reboot-to.c | 5 ++++- .../omamobile-device-cheetah/src/reboot-to.c | 5 ++++- packages/omamobile-device-cheetah/test/all | 11 +++++++++++ packages/omamobile-device-felix/src/reboot-to.c | 5 ++++- packages/omamobile-device-husky/src/reboot-to.c | 5 ++++- packages/omamobile-device-lynx/src/reboot-to.c | 5 ++++- .../omamobile-device-panther/src/reboot-to.c | 5 ++++- packages/omamobile-device-raven/src/reboot-to.c | 5 ++++- packages/omamobile-device-tegu/src/reboot-to.c | 5 ++++- .../omamobile-modem/lib/omamobile-modem-start | 14 ++++++++------ packages/omamobile-modem/test/all | 17 +++++++++++------ packages/omamobile-modem/version | 2 +- 13 files changed, 64 insertions(+), 22 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e43f2d531..33f49418b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ Omarchy Mobile runs native Omarchy (Arch Linux ARM, Hyprland, Omarchy's packages This leaves other people's staged and unstaged changes alone. - **Moving a feature from bring-up into a package:** bump the package `version`, enable nothing that isn't hang-safe, and delete the bring-up files from `/etc/modprobe.d` on the phone (`omamobile-*-bringup.conf`, and any hand-copied package file). A file in `/etc/modprobe.d` replaces the package's `/usr/lib/modprobe.d` file of the same name, so a stale `omamobile-aoc.conf` there hid the package's new blacklist. - **Kernel releases change with every push** (`7.3.0-rc6-omamobile-push1-NNNNN-g`). `bin/omamobile push` runs `modules-push` when the tarball's checksum differs. Without its modules a new kernel boots without its drivers, the GPU among them. `modules-push` replaces `/usr/lib/modules/` as a whole; on the 9a that once took a hand-installed panel driver with it, and the display stayed on the boot logo. It now refuses when the folder holds modules added or swapped by hand since the last push (it records what each push installed in `.omamobile-modules.sha256`), and `OMAMOBILE_MODULES_REPLACE=1` overrides that, wiping them. Pin a daily release whose folder carries hand-installed modules (`/usr/lib/modules/.omamobile-pinned`), and keep a copy before overriding (`tar -C /usr/lib/modules -cf … `). -- **Stop the modem before a `push` or a `reboot-to`.** `push` ends in `reboot-to`, a raw reboot syscall that stops no unit, so `omamobile-modem.service` never runs its clean stop and its `modem-up` marker stays. On the 7 Pro, where the modem starts at boot (device-cheetah 0.1.43+), the next boot counts that as an unclean end ("ended without a clean stop: a hang or a reset"); from `omamobile-modem` 0.1.19 it starts the modem all the same (before, it skipped the modem once), and a second such end before a clean stop holds it off until `omamobile-modem-start --retry`. So a skipped stop no longer costs a boot's modem, but it uses up the one unclean end the guard allows. This happened on 2026-11-08 after a `reboot-to bootloader` taken to charge a flat battery. So run `systemctl stop omamobile-modem` first, as part of the reboot the human said yes to; a reboot that needs no reason can be `systemctl reboot` instead, which stops it. The stop powers the CP off (one recovered UFS error-handler pass, as any reboot with the modem up costs) and, with the NV overlay on, captures its writes. For now it takes about 40 s and ends as "failed", with the CP's power-off logged as a crash; the marker is still removed ([#532](https://github.com/derekross/omarchy-mobile/issues/532)). This is not the restart the modem notes below forbid: nothing starts the modem again before the reboot. From `omamobile-modem` 0.1.20, with a device package whose `reboot-to` notes the boot it ends ([#403](https://github.com/derekross/omarchy-mobile/pull/403)), the next boot takes a marker from that boot as a clean stop, so a `reboot-to` no longer uses up the unclean end; the CP's ordered power-off and the NV capture still come only from the unit's stop, so the rule stands. [MODEM-PLAN](device/cheetah/MODEM-PLAN.md) M4.6b +- **Stop the modem before a `push` or a `reboot-to`.** `push` ends in `reboot-to`, a raw reboot syscall that stops no unit, so `omamobile-modem.service` never runs its clean stop and its `modem-up` marker stays. On the 7 Pro, where the modem starts at boot (device-cheetah 0.1.43+), the next boot counts that as an unclean end ("ended without a clean stop: a hang or a reset"); from `omamobile-modem` 0.1.19 it starts the modem all the same (before, it skipped the modem once), and a second such end before a clean stop holds it off until `omamobile-modem-start --retry`. So a skipped stop no longer costs a boot's modem, but it uses up the one unclean end the guard allows. This happened on 2026-11-08 after a `reboot-to bootloader` taken to charge a flat battery. So run `systemctl stop omamobile-modem` first, as part of the reboot the human said yes to; a reboot that needs no reason can be `systemctl reboot` instead, which stops it. The stop powers the CP off (one recovered UFS error-handler pass, as any reboot with the modem up costs) and, with the NV overlay on, captures its writes. For now it takes about 40 s and ends as "failed", with the CP's power-off logged as a crash; the marker is still removed ([#532](https://github.com/derekross/omarchy-mobile/issues/532)). This is not the restart the modem notes below forbid: nothing starts the modem again before the reboot. From `omamobile-modem` 0.1.21, with a device package whose `reboot-to` notes the boot it ends ([#403](https://github.com/derekross/omarchy-mobile/pull/403)), the next boot doesn't count a marker from that boot, so a `reboot-to` no longer uses up the unclean end (one already counted stays counted); the CP's ordered power-off and the NV capture still come only from the unit's stop, so the rule stands. [MODEM-PLAN](device/cheetah/MODEM-PLAN.md) M4.6b ## 3. How the tools fit together diff --git a/packages/omamobile-device-akita/src/reboot-to.c b/packages/omamobile-device-akita/src/reboot-to.c index c716d9465..7ba6f5a2f 100644 --- a/packages/omamobile-device-akita/src/reboot-to.c +++ b/packages/omamobile-device-akita/src/reboot-to.c @@ -43,7 +43,10 @@ static int marker_names_boot(const char *path, const char *id) n = fread(buf, 1, sizeof(buf) - 1, f); fclose(f); buf[n] = '\0'; - snprintf(want, sizeof(want), "boot %s", id); + /* No printf family here: the initramfs links this file against musl + * without compiler builtins, and musl's vfprintf needs them. */ + strcpy(want, "boot "); + strcat(want, id); for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { char end = p[strlen(want)]; diff --git a/packages/omamobile-device-cheetah/src/reboot-to.c b/packages/omamobile-device-cheetah/src/reboot-to.c index c716d9465..7ba6f5a2f 100644 --- a/packages/omamobile-device-cheetah/src/reboot-to.c +++ b/packages/omamobile-device-cheetah/src/reboot-to.c @@ -43,7 +43,10 @@ static int marker_names_boot(const char *path, const char *id) n = fread(buf, 1, sizeof(buf) - 1, f); fclose(f); buf[n] = '\0'; - snprintf(want, sizeof(want), "boot %s", id); + /* No printf family here: the initramfs links this file against musl + * without compiler builtins, and musl's vfprintf needs them. */ + strcpy(want, "boot "); + strcat(want, id); for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { char end = p[strlen(want)]; diff --git a/packages/omamobile-device-cheetah/test/all b/packages/omamobile-device-cheetah/test/all index 7f12e191f..01d3b48d3 100755 --- a/packages/omamobile-device-cheetah/test/all +++ b/packages/omamobile-device-cheetah/test/all @@ -17,6 +17,17 @@ pass "build stays inside the package directory" ./build "$tmp/build" || fail "C tools compile" pass "C tools compile" +# reboot-to.c is also linked into the initramfs, and for a phone without +# bootctl that link is against musl with no compiler builtins +# (bin/omamobile initramfs). musl's vfprintf needs those builtins +# (__addtf3, __extenddftf2 and others, for long double), so one printf-family +# call stops that build with "reboot-to failed to link", and CI doesn't build +# that path. The other device packages hold their copy to this one. +if grep -nE '\&1; } @@ -363,7 +364,11 @@ printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 00000000-0000-0000-0000-00000000 printf '%s\n' 00000000-0000-0000-0000-000000000000 > "$n/note" out=$(nstart) || fail "a deliberate restart gets past the markers (rc=$?): $out" [[ $out == *"ended with reboot-to"* && $out == *"$stop_line"* && $out != *"ended without a clean stop"* ]] || fail "a deliberate restart isn't a hang: $out" -[[ ! -e $n/up && ! -e $n/up.refused-x && ! -e $n/note && ! -e $n/latch ]] || fail "the note clears the marker, its copies and itself, and writes no latch: $(ls "$n")" +[[ ! -e $n/up && ! -e $n/note && ! -e $n/latch ]] || fail "the note clears the marker and itself, and writes no latch: $(ls "$n")" +[[ -e $n/up.refused-x ]] || fail "the note keeps an unclean end already counted: $(ls "$n")" +printf '%s boot %s\n' 2026-01-01T00:00:00+00:00 22222222-2222-2222-2222-222222222222 > "$n/up" +out=$(nstart) && fail "a hang, a deliberate restart and a second hang are held: $out" +[[ -e $n/up && $out == *"no clean stop since the last refusal"* ]] || fail "the streak outlives a deliberate restart: $out" printf '%s boot %s\n' "$(date -Is)" "$(cat /proc/sys/kernel/random/boot_id)" > "$m/up" out=$(SERVICE_RESULT=success bash $s --stopped 2>&1) || fail "--stopped exits 0" [[ ! -e $m/up && -z $(ls "$m"/up.refused-* 2>/dev/null) ]] || fail "a clean stop of this boot's marker removes the refused copies: $(ls "$m")" diff --git a/packages/omamobile-modem/version b/packages/omamobile-modem/version index baa983785..790629964 100644 --- a/packages/omamobile-modem/version +++ b/packages/omamobile-modem/version @@ -1 +1 @@ -0.1.20 +0.1.21 From 160c5fd06669950645ba954f2e6562cd25974998 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 11 Nov 2026 10:26:25 -0644 Subject: [PATCH 6/6] omamobile-device-oriole: its reboot-to.c follows the cheetah source The Pixel 6's package came to main with its own copy of reboot-to.c (#222), held to the 7 Pro's by its test. This pull request changes that source (the note for a deliberate restart, no printf family), so the ninth copy gets the same file. --- .../omamobile-device-oriole/src/reboot-to.c | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/packages/omamobile-device-oriole/src/reboot-to.c b/packages/omamobile-device-oriole/src/reboot-to.c index f79e948ed..7ba6f5a2f 100644 --- a/packages/omamobile-device-oriole/src/reboot-to.c +++ b/packages/omamobile-device-oriole/src/reboot-to.c @@ -3,7 +3,9 @@ // e.g. "reboot-to bootloader" lands in fastboot. // The kernel's syscon-reboot-mode driver stores the reason in the PMU // before the reset; busybox reboot can't pass one. +#include #include +#include #include #include @@ -12,10 +14,89 @@ #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +/* + * The modem's start refuses after a boot that ended with the modem up and + * no clean stop (a hang or a reset). This restart skips systemd's shutdown, + * so it notes the boot it ends, before rebooting: the next start then knows + * this boot ended on purpose. Best effort: without /var/lib/omamobile (the + * initramfs) there is no note, and the start refuses as before. + * + * Only a boot with the modem up writes the note: its marker (the 7 Pro's + * modem-up, the 9a's modem-bringup-started) names this boot. A restart in + * a later boot without the modem would otherwise replace the note, and the + * boot that had the modem up would read as a hang at the next start. + */ +#ifndef NOTE_DIR +#define NOTE_DIR "/var/lib/omamobile" +#endif +#define NOTE NOTE_DIR "/deliberate-restart" + +static int marker_names_boot(const char *path, const char *id) +{ + char buf[512], want[80]; + FILE *f = fopen(path, "r"); + size_t n; + char *p; + + if (!f) + return 0; + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + /* No printf family here: the initramfs links this file against musl + * without compiler builtins, and musl's vfprintf needs them. */ + strcpy(want, "boot "); + strcat(want, id); + for (p = strstr(buf, want); p; p = strstr(p + 1, want)) { + char end = p[strlen(want)]; + + if (end == '\n' || end == '\0') + return 1; + } + return 0; +} + +static void note_deliberate_restart(void) +{ + char id[64]; + FILE *f = fopen("/proc/sys/kernel/random/boot_id", "r"); + int fd, dir; + + if (!f) + return; + if (!fgets(id, sizeof(id), f)) { + fclose(f); + return; + } + fclose(f); + id[strcspn(id, "\n")] = '\0'; + if (!marker_names_boot(NOTE_DIR "/modem-up", id) && + !marker_names_boot(NOTE_DIR "/modem-bringup-started", id)) + return; + strcat(id, "\n"); + fd = open(NOTE ".new", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); + if (fd < 0) + return; + if (write(fd, id, strlen(id)) != (ssize_t)strlen(id) || fsync(fd)) { + close(fd); + unlink(NOTE ".new"); + return; + } + close(fd); + if (rename(NOTE ".new", NOTE)) + return; + dir = open(NOTE_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (dir >= 0) { + fsync(dir); + close(dir); + } +} + int main(int argc, char **argv) { const char *reason = argc > 1 ? argv[1] : "bootloader"; + note_deliberate_restart(); sync(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reason);