Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<sha>`). `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/<release>` 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 … <release>`).
- **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.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

Expand Down
81 changes: 81 additions & 0 deletions packages/omamobile-device-akita/src/reboot-to.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-device-akita/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
81 changes: 81 additions & 0 deletions packages/omamobile-device-cheetah/src/reboot-to.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions packages/omamobile-device-cheetah/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -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 '\<v?(f|s|sn|d|as)?printf[[:space:]]*\(' src/reboot-to.c; then
fail "reboot-to.c calls the printf family, which doesn't link in the initramfs of a phone without bootctl"
fi
pass "reboot-to.c calls nothing from the printf family"

# omamobile-bootctl against a synthetic devinfo: dump works, and a dry run
# of mark-successful plans exactly one flag byte and writes nothing
python3 - "$tmp/devinfo" <<'PY'
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-device-cheetah/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.50
0.1.51
81 changes: 81 additions & 0 deletions packages/omamobile-device-felix/src/reboot-to.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-device-felix/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.6
0.1.7
Loading