Repository navigation
feat(firmware): CV1 safe mode so a bad release stays updatable - #24505
Conversation
…ronment Sysbuild does not forward -Domi_OMI_DEVELOPMENT_BUILD to the app image, so a jig fault build failed the release guard even with the opt-in set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion map Co-Authored-By: Claude Opus 5.5 <[email protected]>
A boot that faults immediately is shorter than one SWD sample, so the jig observer skipped boots. Default 0; fault injection stays rejected in release builds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
22 issues found across 47 files
Confidence score: 2/5
- On a cold boot where bootstate restore fails,
safe_mode.ccan clear the SAFE latch and discarddfu_pending, allowing normal startup or losing the fresh-trial intent. Preserve both until a successful bootstate read resolves them. - The SAFE SMP security posture in
safe-mode.mdis contradictory: it says unencrypted access is intentional but also marks the final permission setting unverified. Resolve the required posture and generated-config value before relying on this mode. - In
safe_mode_devices.c, the SD host can remain deferred because the guard does not match CV1's SDHC SPI configuration, while itsmmcchild is initialized; SD access may fail in SAFE. Guard against the actual SDHC SPI configuration.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="omi/firmware/tests/check_ota_slot_geometry.py">
<violation number="1" location="omi/firmware/tests/check_ota_slot_geometry.py:36">
P2: These guards are `assert` statements, which are removed under `python3 -O`, so the script would print the success line without checking the fielded map hash or the geometry. Replace them with an explicit check that calls `raise SystemExit(msg)` when the condition fails.</violation>
</file>
<file name="omi/firmware/tests/check_retained_ram.py">
<violation number="1" location="omi/firmware/tests/check_retained_ram.py:53">
P2: If neither map contains the RTT symbols, both dicts are empty and the equality assert passes without checking anything. Assert that `baseline_rtt` is non-empty before comparing.</violation>
</file>
<file name="omi/firmware/omi/sim/README.md">
<violation number="1" location="omi/firmware/omi/sim/README.md:135">
P3: "The review regression" is review-process wording that will confuse readers of a permanent README. Say "The safe-mode regression" to match the section heading.</violation>
</file>
<file name="omi/firmware/tests/stubs/hal/nrf_reset.h">
<violation number="1" location="omi/firmware/tests/stubs/hal/nrf_reset.h:9">
P2: The stub's RESETREAS bit positions look invented: RESETPIN is at bit 5 and SREQ at bit 4, while Nordic's RESETREAS layout places RESETPIN at bit 0. Derive these masks from the nRF hal header the production build uses, or the tests won't validate the real crash classification. Also define the `RESET_RESETREAS_SGERR_Msk`/`SDERR_Msk` macros here so the `#ifdef` branches in `safe_mode_early_boot` get exercised.</violation>
</file>
<file name="omi/firmware/omi/sim/run.py">
<violation number="1" location="omi/firmware/omi/sim/run.py:131">
P2: Writing `observation.json` after the milestone check means a failed boot leaves no report, since the file is unlinked at startup. Write it before the check, as the original code did, and keep the error message pointing at it.</violation>
</file>
<file name="omi/firmware/omi/dts/bindings/test/omi,safe-mode-fault.yaml">
<violation number="1" location="omi/firmware/omi/dts/bindings/test/omi,safe-mode-fault.yaml:1">
P2: This dev-only fault-witness binding is picked up by every build, because the node is declared unconditionally in `app.overlay`. Gate the node behind the same Kconfig (e.g. a conditional overlay or `#if` in the DTS) so release DTS carries no `omi,safe-mode-fault` node.</violation>
</file>
<file name="omi/firmware/tests/test_build_guard.py">
<violation number="1" location="omi/firmware/tests/test_build_guard.py:15">
P2: The fault-injection matrix does not cover an empty `CMAKE_BUILD_TYPE` with fault, debug and development all ON. The guard only denies named release types, so that combination is accepted. Add the case so the test pins the intended behavior, and consider switching the guard to an allowlist (`CMAKE_BUILD_TYPE STREQUAL "Debug"`).</violation>
<violation number="2" location="omi/firmware/tests/test_build_guard.py:18">
P2: The first loop inherits the caller's environment, so an exported `OMI_DEVELOPMENT_BUILD=1` (the jig opt-in) flips the expected-failure cases and makes `make test` fail. Pass an `env` copy with `OMI_DEVELOPMENT_BUILD` removed to every guard run in this loop.</violation>
</file>
<file name="omi/firmware/tests/Makefile">
<violation number="1" location="omi/firmware/tests/Makefile:2">
P3: `BUILD_DIR` hardcodes a macOS workstation path, and the `/tmp` fallback is a fixed, predictable directory where test binaries get executed. Default to a repo-local build directory, or to `mktemp -d`, so the Makefile does not depend on one machine's volume layout.</violation>
</file>
<file name="omi/firmware/omi/Kconfig">
<violation number="1" location="omi/firmware/omi/Kconfig:149">
P3: This `int` option has no `range`, unlike the other new integer options in this block. Add a bounded range so a negative value cannot turn the injected fault into an indefinite hang in `k_msleep()`.</violation>
</file>
<file name="omi/firmware/omi/sim/safe_mode_sim_mgmt.h">
<violation number="1" location="omi/firmware/omi/sim/safe_mode_sim_mgmt.h:20">
P2: `FIXED_PARTITION_ID(label)` returns `1` for every label, so native_sim cannot tell the application slot from any other partition. The SAFE upload-area check in `safe_mode.c` can never reject in the simulator. Map each label to a distinct ID, for example via token pasting, so the sim can exercise the rejection path.</violation>
</file>
<file name="omi/firmware/docs/safe-mode.md">
<violation number="1" location="omi/firmware/docs/safe-mode.md:26">
P1: The doc states SAFE SMP is intentionally unencrypted, but the Differences section says the final permission setting is unverified. State the required SAFE SMP security posture and the generated-config value that enforces it, so reviewers can confirm unauthenticated image-0 uploads are an accepted risk.</violation>
<violation number="2" location="omi/firmware/docs/safe-mode.md:149">
P3: This hash is the SHA256 of `tools/cv1/pinned-partitions.yml`, not a generated-map artifact. Rename the label or record a separate hash for the actual generated `partitions.yml` so archived evidence can be reproduced.</violation>
<violation number="3" location="omi/firmware/docs/safe-mode.md:190">
P3: These “from the checkout root” commands embed the author's workspace and volume paths, so they fail on other machines. Use an environment variable or placeholder for the workspace gate and cache path, as the simulator README does.</violation>
<violation number="4" location="omi/firmware/docs/safe-mode.md:242">
P2: The self-test witness is emitted with `printk()` on the configured console, not necessarily RTT; production `omi.conf` selects UART and disables logging. Require the selected console for `Safe mode self-test passed`, and reserve RTT requirements for the LOG milestones.</violation>
</file>
<file name="omi/firmware/omi/src/main.c">
<violation number="1" location="omi/firmware/omi/src/main.c:185">
P3: The startup log no longer names the reset cause; it only prints a raw `reset=0x...` hex value in the BOOTSTATE line. Decode the RESETREAS bits to readable text here, or keep the decoded messages in the boot log, so field diagnostics stay readable.</violation>
</file>
<file name="omi/firmware/omi/sim/stubs.c">
<violation number="1" location="omi/firmware/omi/sim/stubs.c:153">
P2: These SAFE milestones are synthetic, but they are printed without the `SIM:` label that this file requires for every synthetic milestone. Prefix them with `SIM: ` so the log does not present stub output as real SAFE startup.</violation>
</file>
<file name="omi/firmware/omi/src/lib/core/transport.c">
<violation number="1" location="omi/firmware/omi/src/lib/core/transport.c:1357">
P2: `transport_start_safe()` returns the `ensure_local_ble_identity()` error and aborts SAFE advertising. Normal `transport_start()` only logs this failure and continues. A transient identity failure here leaves SAFE without BLE and triggers the watchdog reset loop in `safe_mode_run()`.</violation>
</file>
<file name="omi/firmware/omi/src/safe_mode.c">
<violation number="1" location="omi/firmware/omi/src/safe_mode.c:155">
P1: An interrupted DFU loses its fresh-trial intent when bootstate restore fails: early boot clears the retained flag, and the restore error path clears it again. Preserve `dfu_pending` until a successful bootstate read and exempt pending DFU boots from `new_trial()`.</violation>
<violation number="2" location="omi/firmware/omi/src/safe_mode.c:224">
P1: A failed settings/NVS restore drops a persisted SAFE latch on cold boot and starts normal mode. Keep the RAM latch set, or fail closed into SAFE, until a successful bootstate read proves the persisted state is not SAFE.</violation>
</file>
<file name=".github/checks-manifest.yaml">
<violation number="1" location=".github/checks-manifest.yaml:291">
P2: This trigger set omits inputs that the command actually executes: changes under `omi/firmware/tools/cv1/**` skip the startup-replay test, and changes to this manifest entry itself do not run the check. Add both paths so the host check stays synchronized with its test inputs and definition.</violation>
</file>
<file name="omi/firmware/omi/src/safe_mode_devices.c">
<violation number="1" location="omi/firmware/omi/src/safe_mode_devices.c:50">
P1: The deferred SD host is never initialized because `CONFIG_SPI_SDHC` does not match the CV1 SDHC SPI configuration, leaving `sdhc0` deferred while its `mmc` child is initialized. Guard this entry with the actual SDHC SPI driver Kconfig symbol (or another build-verified condition) so normal `app_sd_init()` sees a ready host.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
|
||
| Main decides from CRC-validated retained RAM **before** `app_settings_init()`. | ||
| A valid latch enters SAFE without loading application settings, identities or | ||
| bonds. Unencrypted SMP is intentional (David's decision); recovery can create |
There was a problem hiding this comment.
P1: The doc states SAFE SMP is intentionally unencrypted, but the Differences section says the final permission setting is unverified. State the required SAFE SMP security posture and the generated-config value that enforces it, so reviewers can confirm unauthenticated image-0 uploads are an accepted risk.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/docs/safe-mode.md, line 26:
<comment>The doc states SAFE SMP is intentionally unencrypted, but the Differences section says the final permission setting is unverified. State the required SAFE SMP security posture and the generated-config value that enforces it, so reviewers can confirm unauthenticated image-0 uploads are an accepted risk.</comment>
<file context>
@@ -0,0 +1,382 @@
+
+Main decides from CRC-validated retained RAM **before** `app_settings_init()`.
+A valid latch enters SAFE without loading application settings, identities or
+bonds. Unencrypted SMP is intentional (David's decision); recovery can create
+an ephemeral BLE identity and accept a fresh unbonded central. Only invalid
+retained RAM restores a durable SAFE latch, via
</file context>
| resolve_dfu = valid && retained.dfu_pending; | ||
| crash = crash || (valid && retained.fatal != 0); | ||
| /* RESETREAS=0 is POR; RAM contents on cold boot are not a contract. */ | ||
| if (!valid || (!crash && !retained.latch_reason)) { |
There was a problem hiding this comment.
P1: An interrupted DFU loses its fresh-trial intent when bootstate restore fails: early boot clears the retained flag, and the restore error path clears it again. Preserve dfu_pending until a successful bootstate read and exempt pending DFU boots from new_trial().
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/omi/src/safe_mode.c, line 155:
<comment>An interrupted DFU loses its fresh-trial intent when bootstate restore fails: early boot clears the retained flag, and the restore error path clears it again. Preserve `dfu_pending` until a successful bootstate read and exempt pending DFU boots from `new_trial()`.</comment>
<file context>
@@ -0,0 +1,465 @@
+ resolve_dfu = valid && retained.dfu_pending;
+ crash = crash || (valid && retained.fatal != 0);
+ /* RESETREAS=0 is POR; RAM contents on cold boot are not a contract. */
+ if (!valid || (!crash && !retained.latch_reason)) {
+ new_trial();
+ }
</file context>
| retained.latch_reason = saved.reason ? saved.reason : 1; | ||
| } | ||
| } | ||
| restore_latch = false; |
There was a problem hiding this comment.
P1: A failed settings/NVS restore drops a persisted SAFE latch on cold boot and starts normal mode. Keep the RAM latch set, or fail closed into SAFE, until a successful bootstate read proves the persisted state is not SAFE.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/omi/src/safe_mode.c, line 224:
<comment>A failed settings/NVS restore drops a persisted SAFE latch on cold boot and starts normal mode. Keep the RAM latch set, or fail closed into SAFE, until a successful bootstate read proves the persisted state is not SAFE.</comment>
<file context>
@@ -0,0 +1,465 @@
+ retained.latch_reason = saved.reason ? saved.reason : 1;
+ }
+ }
+ restore_latch = false;
+ resolve_dfu = false;
+ retained.dfu_pending = 0;
</file context>
| #if defined(CONFIG_LSM6DSL) && DT_NODE_HAS_STATUS(DT_NODELABEL(lsm6ds3tr_c), okay) | ||
| DEVICE_DT_GET(DT_NODELABEL(lsm6ds3tr_c)), | ||
| #endif | ||
| #if defined(CONFIG_SPI_SDHC) && DT_NODE_HAS_STATUS(DT_NODELABEL(sdhc0), okay) |
There was a problem hiding this comment.
P1: The deferred SD host is never initialized because CONFIG_SPI_SDHC does not match the CV1 SDHC SPI configuration, leaving sdhc0 deferred while its mmc child is initialized. Guard this entry with the actual SDHC SPI driver Kconfig symbol (or another build-verified condition) so normal app_sd_init() sees a ready host.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/omi/src/safe_mode_devices.c, line 50:
<comment>The deferred SD host is never initialized because `CONFIG_SPI_SDHC` does not match the CV1 SDHC SPI configuration, leaving `sdhc0` deferred while its `mmc` child is initialized. Guard this entry with the actual SDHC SPI driver Kconfig symbol (or another build-verified condition) so normal `app_sd_init()` sees a ready host.</comment>
<file context>
@@ -0,0 +1,69 @@
+#if defined(CONFIG_LSM6DSL) && DT_NODE_HAS_STATUS(DT_NODELABEL(lsm6ds3tr_c), okay)
+ DEVICE_DT_GET(DT_NODELABEL(lsm6ds3tr_c)),
+#endif
+#if defined(CONFIG_SPI_SDHC) && DT_NODE_HAS_STATUS(DT_NODELABEL(sdhc0), okay)
+ DEVICE_DT_GET(DT_NODELABEL(sdhc0)),
+#endif
</file context>
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--generated", type=Path) | ||
| args = parser.parse_args() | ||
| assert hashlib.sha256(PINNED.read_bytes()).hexdigest() == PINNED_SHA, "fielded map changed" |
There was a problem hiding this comment.
P2: These guards are assert statements, which are removed under python3 -O, so the script would print the success line without checking the fielded map hash or the geometry. Replace them with an explicit check that calls raise SystemExit(msg) when the condition fails.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/tests/check_ota_slot_geometry.py, line 36:
<comment>These guards are `assert` statements, which are removed under `python3 -O`, so the script would print the success line without checking the fielded map hash or the geometry. Replace them with an explicit check that calls `raise SystemExit(msg)` when the condition fails.</comment>
<file context>
@@ -0,0 +1,52 @@
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--generated", type=Path)
+ args = parser.parse_args()
+ assert hashlib.sha256(PINNED.read_bytes()).hexdigest() == PINNED_SHA, "fielded map changed"
+ assert hashlib.sha256((FW / "boards/omi/pm_static.yml").read_bytes()).hexdigest() == SOURCE_SHA, "legacy PM source changed"
+ pinned = regions(PINNED)
</file context>
| @@ -0,0 +1,18 @@ | |||
| CC ?= cc | |||
| BUILD_DIR ?= $(if $(wildcard /Volumes/Ephemeral/scratch),/Volumes/Ephemeral/scratch,/tmp)/omi-safe-mode-host | |||
There was a problem hiding this comment.
P3: BUILD_DIR hardcodes a macOS workstation path, and the /tmp fallback is a fixed, predictable directory where test binaries get executed. Default to a repo-local build directory, or to mktemp -d, so the Makefile does not depend on one machine's volume layout.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/tests/Makefile, line 2:
<comment>`BUILD_DIR` hardcodes a macOS workstation path, and the `/tmp` fallback is a fixed, predictable directory where test binaries get executed. Default to a repo-local build directory, or to `mktemp -d`, so the Makefile does not depend on one machine's volume layout.</comment>
<file context>
@@ -0,0 +1,18 @@
+CC ?= cc
+BUILD_DIR ?= $(if $(wildcard /Volumes/Ephemeral/scratch),/Volumes/Ephemeral/scratch,/tmp)/omi-safe-mode-host
+CFLAGS = -pthread -std=c11 -O2 -Wall -Wextra -Werror
+CPPFLAGS = -Istubs -I../omi/sim -DCONFIG_OMI_NATIVE_SIM=1 -DOMI_SAFE_MODE_HOST=1 \
</file context>
| BUILD_DIR ?= $(if $(wildcard /Volumes/Ephemeral/scratch),/Volumes/Ephemeral/scratch,/tmp)/omi-safe-mode-host | |
| BUILD_DIR ?= $(CURDIR)/build |
| endchoice | ||
|
|
||
| config OMI_FAULT_INJECT_HARD_FAULT_DELAY_MS | ||
| int "Dwell before the injected fatal error" |
There was a problem hiding this comment.
P3: This int option has no range, unlike the other new integer options in this block. Add a bounded range so a negative value cannot turn the injected fault into an indefinite hang in k_msleep().
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/omi/Kconfig, line 149:
<comment>This `int` option has no `range`, unlike the other new integer options in this block. Add a bounded range so a negative value cannot turn the injected fault into an indefinite hang in `k_msleep()`.</comment>
<file context>
@@ -113,4 +113,45 @@ config OMI_WATCHDOG_TIMEOUT_MS
+endchoice
+
+config OMI_FAULT_INJECT_HARD_FAULT_DELAY_MS
+ int "Dwell before the injected fatal error"
+ depends on OMI_FAULT_INJECT_HARD_FAULT
+ default 0
</file context>
| int "Dwell before the injected fatal error" | |
| int "Dwell before the injected fatal error" | |
| range 0 60000 |
| /* Decide from validated RAM first. Only cold/invalid RAM (or an interrupted | ||
| * DFU commit) needs the isolated bootstate read. Never load app settings in SAFE. | ||
| */ | ||
| safe_mode_restore(); |
There was a problem hiding this comment.
P3: The startup log no longer names the reset cause; it only prints a raw reset=0x... hex value in the BOOTSTATE line. Decode the RESETREAS bits to readable text here, or keep the decoded messages in the boot log, so field diagnostics stay readable.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/omi/src/main.c, line 185:
<comment>The startup log no longer names the reset cause; it only prints a raw `reset=0x...` hex value in the BOOTSTATE line. Decode the RESETREAS bits to readable text here, or keep the decoded messages in the boot log, so field diagnostics stay readable.</comment>
<file context>
@@ -196,15 +169,38 @@ int main(void)
+ /* Decide from validated RAM first. Only cold/invalid RAM (or an interrupted
+ * DFU commit) needs the isolated bootstate read. Never load app settings in SAFE.
+ */
+ safe_mode_restore();
+ if (safe_mode_boot()) {
+ safe_mode_run();
</file context>
| From the checkout root, route tests/builds through the workspace gate: | ||
|
|
||
| ```sh | ||
| /Users/dazheng/workspace/omi/bin/omi-heavy run -- make -C omi/firmware/tests test |
There was a problem hiding this comment.
P3: These “from the checkout root” commands embed the author's workspace and volume paths, so they fail on other machines. Use an environment variable or placeholder for the workspace gate and cache path, as the simulator README does.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/docs/safe-mode.md, line 190:
<comment>These “from the checkout root” commands embed the author's workspace and volume paths, so they fail on other machines. Use an environment variable or placeholder for the workspace gate and cache path, as the simulator README does.</comment>
<file context>
@@ -0,0 +1,382 @@
+From the checkout root, route tests/builds through the workspace gate:
+
+```sh
+/Users/dazheng/workspace/omi/bin/omi-heavy run -- make -C omi/firmware/tests test
+/Users/dazheng/workspace/omi/bin/omi-heavy run -- \
+ python3 omi/firmware/omi/sim/run.py \
</file context>
| /Users/dazheng/workspace/omi/bin/omi-heavy run -- make -C omi/firmware/tests test | |
| "$OMI_HEAVY" run -- make -C omi/firmware/tests test |
| explicit linker reservation/assertions instead of shrinking `sram_primary`. | ||
|
|
||
| Source evidence: `tools/cv1/pinned-partitions.yml`, retained generated-map | ||
| SHA256 `345f6b77aa32407ed2aaf33c8d2d7809b37e37a68f920ad30fd5fb647a4d1f5a`: |
There was a problem hiding this comment.
P3: This hash is the SHA256 of tools/cv1/pinned-partitions.yml, not a generated-map artifact. Rename the label or record a separate hash for the actual generated partitions.yml so archived evidence can be reproduced.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At omi/firmware/docs/safe-mode.md, line 149:
<comment>This hash is the SHA256 of `tools/cv1/pinned-partitions.yml`, not a generated-map artifact. Rename the label or record a separate hash for the actual generated `partitions.yml` so archived evidence can be reproduced.</comment>
<file context>
@@ -0,0 +1,382 @@
+explicit linker reservation/assertions instead of shrinking `sram_primary`.
+
+Source evidence: `tools/cv1/pinned-partitions.yml`, retained generated-map
+SHA256 `345f6b77aa32407ed2aaf33c8d2d7809b37e37a68f920ad30fd5fb647a4d1f5a`:
+
+| Owner | SRAM range (end exclusive) |
</file context>
| SHA256 `345f6b77aa32407ed2aaf33c8d2d7809b37e37a68f920ad30fd5fb647a4d1f5a`: | |
| `pinned-partitions.yml` SHA256 `345f6b77aa32407ed2aaf33c8d2d7809b37e37a68f920ad30fd5fb647a4d1f5a`: |
lib/core/features.h shadowed glibc <features.h> under -I on Linux CI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…update (#24514) <!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} --> _Requested by **David**_ ## What changed and why This is a follow-up to #24505 (CV1 safe mode), from that PR's independent review. Suppose a DFU completes in SAFE and TRIAL commits to NVS, but a reset lands before RAM clears the latch. The next boot cleared `dfu_pending` before its narrow bootstate read. If that one read failed or hung, every later warm boot stayed in BLE-only SAFE, despite the committed update. The device stayed reachable, so a re-upload recovered it, but the app could report it as already up to date. `dfu_pending`, which is already CRC-covered, now holds a bounded retry state: - `0` is idle and `1` is pending. - `2`/`3` mean waiting or ready with two retries left; `4`/`5` mean waiting or ready with one. - The device makes at most three resolve attempts, on boots 1, 3 and 5. Each failed or hung attempt is followed by a boot that skips the backend read, so SAFE advertising is never blocked. - If the read finds TRIAL for this firmware, a fresh trial starts. - Any other successful read clears the budget. - Exhaustion leaves the device in SAFE and still reachable. - `safe_mode_persist` doesn't write SAFE while retries are outstanding, so a committed TRIAL is preserved. - Values above 5 are rejected by `retained_valid()`. The 48-byte record layout and its CRC coverage are unchanged, and a static assert pins them. The safe-mode doc now records the warm-reset retention measured on the jig through the installed MCUboot. ## Product invariants affected None. Only an interrupted SAFE-mode app DFU behaves differently. Normal startup and capture are unchanged. ## How it was verified - `make -C omi/firmware/tests test` passed. New host regressions cover: - transient failure then recovery, and success on the final retry; - read and init exhaustion, and a hang on every attempt; - cancellation; - CRC and range validation. All existing cases pass, including 222,745 audio-packing cases, the build guards and 18 startup-parser tests. - `make preflight` passed. - Independent read-only review: no bad transition among the accepted values, and attempts are bounded. Its one condition was warm-reset retention through the fielded MCUboot. The jig measured that on 2026-11-03: the CRC-valid count went 1 to 4 across watchdog and fatal resets in all four #24505 fault proofs, with the bootloader hash pinned. - Jig qualification of this exact change, with all four fault proofs rerun on the new `safe_mode.c`, comes with the 3.0.23 candidate before any release. Nothing is published by this PR. ## Failure class Failure-Class: none This hardens new recovery code before its first release; no fielded failure class exists yet. ## UI evidence (none) UI-Evidence: none -- firmware only, no app or web UI change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/24514?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/24514?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24514&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
<!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} -->
_Requested by **David**_
## Status 2026-11-08: verified, ready for release review
All the pre-release gates listed further down have passed. The one left
is David's go. After that, the rollout coordinator handles a staged OTA.
- **Field path proven:** 3.0.21 to 3.0.23 over BLE OTA, on the jig
running the factory 3.0.8 bootloader (the bootloader shipped units
have). Slot1 went to pending+permanent, and after reset slot0 ran the
new image, active and confirmed, with DIS reporting 3.0.23. An earlier
install from an RC start image also passed.
- **Safe mode:** the bench check and all four fault proofs (hard fault,
driver hang, settings hang, watchdog starvation) passed on 6a09d7c. Same
code hash as this head.
- **Host and CI:** firmware host suites, the OTA slot geometry check and
preflight pass. All required CI checks are green. The two red `Analyze`
jobs are CodeQL failing at the SARIF upload step with no alerts. They
aren't required checks and GitHub won't rerun them.
- **Why there is no separate 3.0.22:** safe mode was going to ship alone
as 3.0.22. Its OTA was never proven, because the jig's stock MCUboot
lacks the Omi SD init and erased slot1. Once the jig had the factory
bootloader, the full candidate was proven instead, so safe mode ships
inside 3.0.23.
- **Known telemetry gap:** the boot record decides the update outcome
from the DIS string plus the MCUboot header version, which is 0.0.0 on
every image. So a field unit's first 3.0.23 boot reports UNKNOWN, and a
same-version reinstall reports NOT_INSTALLED. The app's post-reset hash
check stays the authority. A follow-up will switch to image-hash
identity.
- **Still not measured on hardware:** current draw, charger behavior,
and storage after power loss.
Evidence:
`data/run-2026-11-07-cv1-rc/factory-bootloader-install-proof.md` in the
workspace repo. Bench tooling: #24813.
## Update 2026-11-07: safe-mode SD fix, boot telemetry, pinned flash
layout
Four commits on top of the 11-04 head:
- `7a7a6aaa9dd` Safe mode now brings up the SD card before anything
reads the NOR on the shared SPI3 bus. Without that, an uninitialized SD
card drives MISO and corrupts NOR reads. Also adds the persisted boot
record, the saved update outcome, and storage health counters (NOR
read-check failures, SD init failures). These are telemetry items 4-6.
Recovery characteristic `19B10042` moves to v2 (96 bytes, same 16-byte
prefix, version byte 2). `19B10041` is unchanged.
- `481bab7ead1` Docs: `docs/verification/2026-11-07-boot-telemetry.md`,
GATT map.
- `44180c0060a` Hang guard: if SD init hangs and the watchdog fires,
later SAFE boots skip SD init and count a failure instead of looping.
- `6a09d7cbbe5` Pins the app, littlefs, settings and EMPTY_0 partitions
in `boards/omi/pm_static.yml` to the fielded 3.0.21 map. The partition
manager orders the "before: end" partitions in a Python set, so without
the pin the layout depended on the hash seed.
`tests/check_ota_slot_geometry.py` now asserts the pinned map.
Bench evidence on the jig (6a09d7c): the bench check passed, and so did
all four fault proofs (hard fault, driver hang, settings hang, watchdog
starvation). ALL OK at 2026-11-06T22:18:12Z. The jig was restored to
3.0.21 afterwards.
Since proven (see Status above): the jig now runs the factory 3.0.8
bootloader, and a real 3.0.21 to 3.0.23 BLE install passed.
## 3.0.23: merged with safe mode (update 2026-11-04)
This head merges `origin/main` into the backlog candidate. Main now
carries CV1 safe mode (#24505) and its interrupted-update retry fix
(#24514). The version is bumped to **3.0.23**. The original plan was to
ship safe mode alone first, as 3.0.22. That was dropped, and safe mode
ships inside 3.0.23 (see Status above).
- `safe_mode.c`, the retained record layout, the app overlay and the
development-only fault guard match main exactly.
- The replacement SD host joins deferred initialization. The backlog
shutdown worker starts only in normal mode, so SAFE still skips all
application startup.
- **Diagnostics:** the service is registered once, after storage.
`19B10041` keeps the 25-byte telemetry the shipped app parses. Safe
mode's 16-byte recovery state moves to `19B10042`. SAFE exposes only
`42` and Zephyr's static recovery services. `gatt-map.md` matches the
code.
- The merge had seven conflicts: gatt-map, CMakeLists, Kconfig,
diagnostics.h, transport.c, main.c and settings.c. Both sides' behavior
is kept.
- Verified: the host firmware suite and backlog regressions pass, and
preflight passes all 37 checks. Native simulation was skipped because no
Docker daemon was available on the build host.
- **Before any release** (all done except David's go, 2026-11-08):
- An independent review of the merge.
- A build-only CI image of this exact head.
- A normal-mode jig cycle.
- All four safe-mode fault proofs, rerun on this image.
- An app DFU to the jig in SAFE.
- David's go.
## What changed and why
Release candidate for the next CV1 firmware. It combines separately
written PRs so they can be tested together, and fixes what only showed
up once they were combined.
| PR | Author | What it brings |
|---|---|---|
| #24381 (#24137, #19469) | @rgr4y, David | Compiler warning cleanup,
Opus size check, BLE device diagnostics |
| #20450 | David | Ring custody: audio is kept when connected but not
subscribed, and reclaimed only after the phone confirms it |
| #14293 | @apoorvdarshan | Mute survives disconnect and reboot |
| #22659 | @esixce | SD CMD12 reply fix |
| #19719 | David | Per-unit serial number over DIS |
| #13342 | @gianluca-disanto | Audio chunks bounded to ATT MTU |
| #20483 (battery part only) | David | Battery percent doesn't jump on
the charger, and reads correctly after unplugging |
| #23735 (adapted) | @ducanh3005 | BLE power control: resume, pause
capture, power off |
| #23743 (firmware part) | @ducanh3005 | A user-set device name that
persists and advertises |
Also adds `omi/firmware/docs/gatt-map.md`, which assigns each
characteristic UUID to one owner so open PRs stop colliding.
David chose #20450 as the retention fix, accepting that going back to
older firmware loses unsynced audio on the pendant. Release and OTA
publication still need David's go.
**Fixes made on top of the merges:**
- Queued audio could still reach the phone after a mute. A mute now
stops it before sending.
- An unreadable stored mute setting fell back to unmuted, which could
resume capture after a reboot. It now stays muted until an explicit
unmute rewrites the setting. The tradeoff is that a corrupted setting
pauses capture rather than risking recording a user who paused. The app
reads this state back.
- Failed batch media syncs now count as storage errors in diagnostics.
- `check_cv1_mtu.py` passed on its fallback simulation when its compile
failed. A compile failure now fails the check, and only a missing
compiler falls back.
- New `check_ota_slot_geometry.py` keeps OTA slots at the addresses in
every recorded baseline build. It fails on #13855's map.
**Changes from the original PRs:**
- #20483 keeps only the battery fix. Its new diagnostics characteristic
is out, because the existing 25-byte diagnostics packet already covers
this. Diagnostics now report the uncorrected ADC voltage, while critical
shutdown still uses the corrected one.
- #23735 moves from UUID `19B10014` to the allocated `19B10016`, and
from feature bit 9 to bit 11. Pause now uses the same persistent mute as
`19B10015`, so a disconnect or AAD wake can't clear it. Sampling may
continue while paused, with sending and storage both stopped, so this
pause doesn't promise a power saving. A write acknowledges that shutdown
was queued, not that it finished.
- #23743 keeps only the firmware. Its app changes don't apply on this
base, so no app can set a name yet. A name now loads only from a
complete NVS record, and Bluetooth RX can't change it during an
advertising update. A new name takes effect after disconnect, because
advertising is off while connected. The name also moves from the
advertising packet to the scan response, so a passive scanner won't see
it.
**Left out:** #13855, merged and then reverted here. It shrinks both OTA
slots from `0xf0000` to `0xe8000` and moves external network staging and
settings. MCUboot compiles its slot addresses in and OTA doesn't replace
it, while mcumgr uses the app's map. So from reading the design, an app
on that map would write later images and upgrade trailers where the
installed bootloader doesn't look, and OTAs would stop applying.
Settings would also move from `0xfc000`, losing bonds and mute on
update. This hasn't been reproduced on hardware. Generated baseline
builds already end the app at `0xf6000`, below littlefs and settings, so
#5400 needs a fix that keeps the slots where they are.
Also left out: #12102, because #20450 already keeps audio when the clock
is untrusted and its test doesn't link on this branch. Also #14156, held
because it keeps the mic on while connected and that battery cost hasn't
been measured, and #20838 (the retention alternative), #12943 and
#14240.
## Product invariants affected
- INV-CAP-1
This changes what happens to audio while connected but not subscribed,
which is the invariant's main case. Custody host harnesses pass, and the
RC ran on hardware through BLE install and safe-mode fault proofs.
## How it was verified
At `2810eaf`, this head, from a clean clone on the bench Mac, with no
device access:
- `quick-host` and `compile-only` against pinned NCS 2.9.0 pass.
- Host regressions and the OTA slot geometry check pass. The geometry
check also fails on #13855's map, as intended.
- The mute test passes, including new cases for an unreadable setting.
- Custody `make run` passes: `sd_card` and `storage` harnesses report 0
failures.
- The MTU check passes 15 of 15 on the production C seam.
An independent review covered how the merged PRs interact; its three
findings are fixed above. It was a static read and ran no tests.
At the merge of #20483, #23735 and #23743, on the bare CV1 board on the
jig: one app-only cycle passed. The exact image CI built at `07f3866`,
this head, also passed one (build-only run 41523746903, nothing
published). It flashed and verified this image, ran the 30-second boot
check, then restored and verified baseline 3.0.21. The generated slot
map matches the baseline. The same cycle also passed at `2810eaf`. It
proves the image boots and the board can be restored, and nothing about
BLE or audio. Host tests for all three additions pass, and their merge
compiles, links and signs for the real target.
**Not verified at that point (11-04):** anything on hardware beyond that
boot. BLE, GATT, OTA and safe-mode recovery have since been verified
(see Status above). Still open: the new power-off path, renaming,
charger behavior, storage after power loss, the v1 to v2 media upgrade,
and current draw. Going back to pre-#20450 firmware orphans unsynced
audio on the pendant.
## Tests
`omi/firmware/omi/tests/`: custody, `sd_card`, `storage`, capture mute,
OTA slot geometry and host regressions, plus
`omi/firmware/scripts/check_cv1_mtu.py`.
## Failure class
Carried from #14293, which brings these app changes:
Failure-Class: new
Failure-Class-ID: FC-device-mute-cleared-on-disconnect
Line-Count-Exception: app/lib/services/capture/capture_controller.dart |
4609 -> 4670 | Keep durable pendant mute confirmation in the existing
capture owner; unrelated ownership extraction is outside this privacy
fix.
Line-Count-Exception: app/lib/services/capture/capture_coordinator.dart
| 2964 -> 3017 | Confirm device mute before local policy and restore
winning hardware intent on supersession in the existing serialized
owner.
## UI evidence
UI-Evidence: none -- firmware only; the app changes come from #14293 and
aren't exercised in this PR's verification
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Requested by David
What changed and why
A CV1 release that repeatedly crashes or hangs during startup must remain reachable for application DFU. After three failed boots, 3.0.22 selects sticky BLE/SMP recovery on the fourth attempt, before application settings or capture startup. A continuous three-second P0.26 hold also enters recovery. Normal mode requires successful advertising and 60 seconds in its main loop before GOOD; a completed upload starts a fresh trial on the next boot, including for the same firmware version.
Count failures and start the watchdog at PRE_KERNEL_2. Validate the 48-byte retained record with CRC-32, firmware/magic checks and bounded count/reason/fatal/transaction fields. SAFE skips application settings and BT identity/bond loading; unencrypted SMP is intentional per David's decision. Restore durable SAFE only when retained RAM is invalid. A CRC-covered DFU intent permits a bootstate-only NVS read after an interrupted commit: persisted TRIAL for this firmware overrides stale RAM SAFE, while an older TRIAL cannot erase a later crash loop. Serialize SAFE/GOOD/TRIAL persistence and prevent late main-loop readiness or SAFE persistence from overwriting DFU recovery state. Match Zephyr's NULL callback name for an exact settings subtree match.
Use app-only
zephyr,deferred-initfor PDM/I2S, SAADC, I2C/IMU and SPI SD host/disk devices, then calldevice_init()in normal mode before use, bus before children. SAFE never initializes them. The software codec already starts only on the normal path. SPI3 and the external NOR holding the secondary slot remain eager. NCS 2.9.0's pinned Zephyr enables deferred init unconditionally: it has noCONFIG_DEVICE_DEFERRED_INITsymbol, so that undefined setting must not be added.Reject SAFE uploads whose requested image is not 0 or whose inspected destination is not the application secondary slot. Checking the destination also catches resumed network-core chunks with the image key omitted. Only a checked image-0 completion clears the latch; rejected, stopped, failed or unknown completions do not. A failed persistence attempt retains the RAM latch. SAFE attempts backend persistence once after advertising; warm resets skip a previously hung attempt.
Preserve MCUboot/config, partition geometry, UICR, network core, existing GATT attributes/order, advertising name/payload, RTT configuration/address contract and all nine normal milestone strings. Retained RAM stays in the existing app-only 64-byte reservation at 0x2006FF00. Diagnostics remain appended after normal dynamic services; SAFE exposes its minimal subset. The normal power-off path continues to System OFF when the nRF watchdog cannot stop. Merge the ten incoming
origin/maincommits without rebase or conflicts.Product invariants affected
INV-CAP-1 — SAFE does not sample audio or initialize/mutate the SD ring. Existing captured data stays in its existing storage. The red pulse and diagnostics identify recovery, which suspends new capture and does not promise to recover earlier recording gaps. Normal capture behavior is preserved.
How it was verified
Required verification runs use
/Users/dazheng/workspace/omi/bin/omi-heavy run --:make -C omi/firmware/tests test: PASS. Production state-machine tests cover 100 pre-settings crashes with zero NVS writes, one SAFE persistence attempt across recovery boots, cold reload, reset classes, uptime/advertising gates, version changes, saturation and sporadic resets. New cases corrupt each retained byte with magic intact, independently reseal out-of-range fields, prevent fatal handling from blessing corruption, reject image-1/resumed-target uploads, ignore stopped/unknown completions, reproduce committed-TRIAL/still-latched reset, and prevent late persistence/readiness from certifying the old boot. Existing 222745 audio-packing cases, OTA geometry, 8 release-injection guard configurations, 4 required-hook configurations and 18 startup-parser tests pass.python3 omi/firmware/omi/sim/run.py --cache /Volumes/Ephemeral/scratch/cv1-lab/safemode/sim --safe-mode: PASS. Normal startup, a real deferred-device init hang and SAFE bypass, unconditional app-settings-hang SAFE bypass, and durable SAFE reload → checked image-0 completion → TRIAL → next-boot GOOD all passed (645 seconds). Report:/Volumes/Ephemeral/scratch/cv1-lab/safemode/sim/observation.json.OMI_PR_BODY_FILE=/Volumes/Ephemeral/scratch/cv1-lab/safemode/pr.md make preflight: PASS, 18 checks on final committed code/documentation (57.38 seconds).omi/firmware/docs/safe-mode.md, including the post-TRIAL-write reset window, retained corruption, image-1 rejection and real deferred-driver/settings hangs.Native simulation uses the exact NCS 2.9.0 Zephyr revision and real simulated NVS. BLE/SMP delivery, WDT hardware and sensors are stubbed; forced RAM latches stand in for preceding watchdog resets. The hung process group is terminated by the runner. This establishes startup/deferred-init control flow, not RF or Nordic watchdog enforcement.
Jig qualification (CV1 bench, SWD + BLE)
Normal boot of the safe-mode build passed on the jig twice: flashed, booted, advertised, and accepted a BLE connection. The original image was then restored and verified.
All four development-only fault builds then passed the same flash, observe, BLE and restore cycle. In each run:
Safe mode initialized: BLE DFU only, thenSafe mode feed loop started, thenomi/bootstate=SAFE fw=<revision>. No normal initialization ran.Between those heads, only the development-only hard-fault option and docs changed.
safe_mode.chas the same hash throughout.The bench found two observer limits, which led to development-only settings:
CONFIG_OMI_FAULT_INJECT_HARD_FAULT_DELAY_MS(default 0) prints the witness and then dwells before the fatal.Fault builds are rejected in release builds by the existing CMake guard. Sysbuild does not forward an image-prefixed opt-in, so the guard now also accepts
OMI_DEVELOPMENT_BUILD=1from the environment.Still not qualified:
dfu_pending, so later warm boots stay in SAFE instead of resolving the committed TRIAL. The device remains BLE-reachable, and re-uploading recovers it. It is not a brick. The fix is a bounded retry of the resolve, which changessafe_mode.cand needs the jig fault proofs rerun, so it moves to the backlog release.Publishing a release from this branch needs David's go. The rollout plan is 1%, staged.
Failure class
Failure-Class: none
New recovery capability and its startup/DFU hardening, rather than an instance fix for an existing registered failure class. The related unstoppable-watchdog early return has an explicit System OFF jig regression.
UI evidence (none)
UI-Evidence: none -- firmware only, no app or web UI change.
🤖 Generated with Claude Code