Skip to content

Firmware: clear all CV1 compiler warnings and fix the dead Opus size check - #24137

Open
rgr4y wants to merge 8 commits into
BasedHardware:mainfrom
rgr4y:fix/firmware-warnings-opus-check
Open

rgr4y wants to merge 8 commits into
BasedHardware:mainfrom
rgr4y:fix/firmware-warnings-opus-check

Conversation

@rgr4y

@rgr4y rgr4y commented Oct 30, 2026 •

Copy link
Copy Markdown

What

Clears every compiler warning in the CV1 app firmware (24 on main, 0 after) and fixes one real bug the warnings were hiding: the Opus encoder size check in codec.c could never fail.

The real bug

ASSERT_TRUE(x) expanded to if (!x), so ASSERT_TRUE(a == b) became (!a) == b. For the == OPUS_OK calls that happens to be equivalent, but the encoder size check compared !opus_encoder_get_size(...) with the buffer size, which is always false (-Wbool-compare, -Wlogical-not-parentheses). If the encoder ever outgrew m_opus_encoder the check would not catch it.

  • utils.h: parenthesize the macro argument.
  • codec.c: check the real invariant (encoder size <= buffer), and log the needed size once at startup. On a CV1 this logs 7180 of 10916 bytes.
  • codec.c also picked OPUS_ENCODER_SIZE with #if CONFIG_OPUS_MODE_CELT/HYBRID, which aren't defined in that file, so both branches matched and the hybrid size always won (with a redefinition warning). The size is now defined once with the same value, so behavior is unchanged.

The rest (no behavior change)

  • Declare battery functions before use (implicit declarations in battery.c, transport.c).
  • Compile the speaker write handler and its UUID only when the speaker is enabled.
  • Remove unused statics and declarations in transport.c, battery.c, haptic.c, imu.c, button.c, main.c (dead button counters, unused boot LED sequences, an undefined haptic_ccc_cfg_changed declaration).
  • Remove return 0 from void check_button_level().

8 commits, one concern each, +16/-87.

Verification

  • Built CV1 (NCS v2.9.0, west build -b omi/nrf5340/cpuapp omi/firmware/omi --sysbuild) on origin/main (c532e20) and on this branch: 24 unique C warnings before, 0 after. FLASH 31.8%, RAM 65.3% after.
  • clang-format --dry-run on the changed files: no new findings (battery.c has 13 pre-existing ones, unchanged).
  • On hardware: these commits run on my CV1 as part of a personal build on top of main. The startup log shows the encoder needing 7180 of 10916 bytes. Audio streaming, SD offline storage and button handling work as before. This exact rebased branch was built, not flashed.
  • No new tests: firmware has no host test harness for codec.c today; the bug is a compile-time-visible precedence error, which the now warning-free build guards against.

Product invariants affected

  • INV-CAP-1: not changed. No audio path behavior changes; the encoder, transport and storage paths only lose dead code and gain a correct size check.

Failure-Class: none

https://claude.ai/code/session_0174v6pPK88CzUTnS62swCzM

rgr4y added 8 commits October 30, 2026 15:03
boot_led_sequence() and boot_ready_sequence() have no callers anywhere in
the firmware tree under any Kconfig option.

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
threshold, inc_count_0/inc_count_1 and reset_count() were never read or
called; the counters were only touched by reset_count() itself.

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
- battery.c: power_pin gpio spec is never used
- haptic.c: haptic_ccc_cfg_changed() was declared but never defined or
  referenced (the haptic service has no CCC)
- imu.c: lsm6dsl_timestamp_disable() has no callers

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
offset, use_storage, recent_file_size_updated and heartbeat_count are not
referenced anywhere in transport.c, including code under disabled Kconfig
options.

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
audio_characteristic_speaker_uuid and audio_data_write_handler() are only
used by the speaker characteristic, which is already behind
CONFIG_OMI_ENABLE_SPEAKER. Move them under the same guard and drop the
two unused locals in the handler. No behavior change in either config.

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
transport.c called battery_get_millivolt, battery_get_percentage and
battery_charge_start without including battery.h, and battery.c called
battery_charging_state_read before its definition. Signatures already
match, so this only removes the implicit declarations.

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
ASSERT_TRUE expanded to if (!result), so ASSERT_TRUE(a == b) became
(!a) == b. For the == OPUS_OK checks that is equivalent, but the encoder
size check compared !size against the buffer size and could never fail.
Parenthesize the argument, check that the encoder fits in the buffer
(the real invariant), and log the needed size once at startup.

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
codec.c chose OPUS_ENCODER_SIZE with #if on CONFIG_OPUS_MODE_CELT/HYBRID,
which are not defined there, so both branches matched and the hybrid size
always won (with a redefinition warning). Define that size once; behavior
is unchanged. Also remove return 0 from void check_button_level().

Claude-Session: https://claude.ai/code/session_01KXqtaeuKYF4Ejz3T2htaVz
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: clean, well-scoped cleanup — the Opus size-check fix is correct, the macro analysis in the description checks out, and I found no blocking issues. A couple of small nits below.

Verified file by file:

  • utils.h — the parenthesization is the right fix: ASSERT_TRUE(a == b) used to expand to if ((!a) == b). I checked every ASSERT_TRUE call site under omi/src: the == OPUS_OK comparisons (codec.c:97–106) were coincidentally still correct because OPUS_OK is 0, and the single-call sites (led.c:18–20) are unaffected — so no hidden behavior change from the macro fix. Note devkit has its own utils.h with the old macro, so this fix is correctly scoped to the CV1 app only.
  • codec.c — keeping OPUS_ENCODER_SIZE at 10916 preserves effective behavior (both former #if branches matched since CONFIG_OPUS_MODE_CELT/_HYBRID were never defined, and the hybrid definition won with a redefinition warning); the comment explaining this is accurate. The new opus_size > 0 && (size_t) opus_size <= sizeof(m_opus_encoder) is the real invariant, and allowing buffer > needed is the right call.
  • transport.c — guarding audio_data_write_handler and audio_characteristic_speaker_uuid matches the pre-existing #ifdef CONFIG_OMI_ENABLE_SPEAKER around the GATT table entry (lines 164–170), so speaker-disabled builds stay consistent. The new lib/battery/battery.h include backs real calls (battery_get_millivolt/battery_get_percentage at :563–564, battery_charge_start at :1411). The removed offset/use_storage/recent_file_size_updated/heartbeat_count have no remaining references.
  • battery.c — the forward declaration of battery_charging_state_read (defined at :333, called from the charging callback at :135) matches the definition and isn't in any header, so a local declaration is the right minimal fix. power_pin removal is safe; the only remaining references are in the untouched lib/evt/battery.c.
  • haptic.c — haptic_ccc_cfg_changed was declared but never defined; removal is safe.
  • imu.c — lsm6dsl_timestamp_disable had no callers.
  • button.c — dead counters/threshold/reset_count() removed; return 0 correctly dropped from void check_button_level().
  • main.c — both boot LED sequences had no callers, so there is no user-visible LED behavior change.

Security: nothing sensitive touched. Blast radius: CV1 app firmware only; devkit is untouched.

USER IMPACT: none expected — all removed code was unreachable; the device now correctly verifies the Opus encoder buffer fits at codec start instead of running a check that could never fire.

What I'd still want:

  • The size log uses LOG_WRN and fires on every successful codec_start (7180 of 10916 bytes each time). Consider LOG_INF, or log only when the requirement crosses a fraction of the buffer.
  • Out of scope follow-up: devkit/src/codec.c:98 has the identical dead size check behind devkit's own old-style macro — the same fix would apply there if you fancy it.
  • Repo CI doesn't build firmware, so your local NCS v2.9.0 24→0 warnings result is noted as author-reported; the static diff is consistent with it.

Nice work — once you're happy with the nits (or as-is), marking it ready for review is the next step.

Automated maintainer-assistant review on behalf of the Omi maintainers; a human maintainer should give the final sign-off before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added firmware firmware work positive-signal Automation verified a genuine fix/quality contribution labels Oct 30, 2026
Git-on-my-level added a commit that referenced this pull request Nov 8, 2026
<!-- 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)
kriegcloud pushed a commit to kriegcloud/omi that referenced this pull request Nov 8, 2026
Combine PR BasedHardware#24137 at a1dfe21 and
PR BasedHardware#19469 at 666a2a3 with the reviewed
single-evaluation assertion and coherent long-read cache fixes.

Add a portable host regression entrypoint using actual production source and
explicit Zephyr/Opus/GATT shims. It covers codec bounds/failure handling,
packet/counter boundaries, snapshot coherence, offsets, lifecycle slot reuse,
concurrent cache/reset stress and the EATT rejection guard.

The host checks pass under UBSan. Earlier equivalent application bytes passed a
bounded CV1 boot/readback trial followed by verified baseline restoration.
BLE/GATT/audio/OTA acceptance remains unverified; no release claim is made.
@rgr4y
rgr4y marked this pull request as ready for review November 18, 2026 05:31
@rgr4y
rgr4y requested a review from TuEmb as a code owner November 18, 2026 05:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

firmware firmware work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants