Skip to content

tools(cv1): SMP image commands and a peripheral pin for the BLE bench central - #24813

Merged
Git-on-my-level merged 5 commits into
mainfrom
fw/cv1-ble-dfu
Nov 14, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
fw/cv1-ble-dfu

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Requested by David

What changed and why

The CV1 macOS BLE bench central (omi/firmware/tools/cv1/ble_central) gains MCUmgr SMP image commands (image-state, image-upload) and a CoreBluetooth peripheral pin.

Fielded 3.0.21 exposes no DIS serial, so the existing serial pin can't tell a bench unit from any other 3.0.21 pendant in Bluetooth range. That makes an upload from 3.0.21 unsafe. With --expect-peripheral UUID (the host's CoreBluetooth identifier):

  • Discovery ignores every other peripheral.
  • Each connection re-checks the identifier.
  • SMP access fails closed on a mismatch.

Receipts record the connected identifier, so it can be learned from a serial-matched run. image-upload and audio accept either pin.

The branch also carries the recovery-characteristic reader (tools(cv1), also on #24393), which the SMP commands build on. This is bench tooling only; no firmware changes.

Product invariants affected

none

How it was verified

  • sh omi/firmware/tools/cv1/ble_central/test.sh: 1094 pure Swift checks pass. These cover the pin parse/normalization, a wrong peripheral leaving no SMP access, a pin without serial allowing SMP, a pin plus serial still requiring the serial, and a mismatch never being rescued by later reads.
  • build.sh to a scratch bundle, then check_rejections.py against it: 32 pre-Bluetooth refusal cases pass, including a malformed --expect-peripheral and scan with a pin.
  • The SMP commands (serial pin) were used on the bench unit on 2026-11-07. They installed the 3.0.23 RC through the factory MCUboot (slot1 pending/permanent, then slot0 hash changed after reset).
  • Not yet exercised live: --expect-peripheral. The rebuilt bundle needs a fresh macOS Bluetooth grant on the bench host first.
  • An independent read-only review found no path to a wrong-device SMP write. Its two minor findings (re-check the pin on every connection, README overview wording) are fixed.

Tests

Tests.swift adds peripheral-pin cases to the parse and SMP gate checks. check_rejections.py adds the two refusal cases and the new peripheralMismatch receipt field.

UI evidence

UI-Evidence: none -- command-line bench tool, no UI

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 4 commits November 7, 2026 09:38
…tral

3.0.23 moves the 16-byte recovery state to 19B10042; SAFE exposes only that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fielded 3.0.21 exposes no DIS serial, so the serial pin cannot tell a bench
unit from another 3.0.21 pendant in range. --expect-peripheral takes the
host's CoreBluetooth identifier: discovery ignores every other peripheral,
each connection re-checks it, and SMP access fails closed on a mismatch.
Receipts record the connected identifier so it can be learned from a
serial-matched run. image-upload and audio accept either pin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level Git-on-my-level self-assigned this Nov 7, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T09:01:19.841775Z e3cd87d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 issues found across 6 files

Confidence score: 4/5

  • The pin tests in Tests.swift don’t check that access is revoked for a different ID after a successful pinned connection, so that regression could pass. Add the second beginConnection assertion.
  • The upload test in Tests.swift only checks that first-chunk metadata exists, so incorrect header values could pass. Assert the expected sha, image index, and len.
  • The Info.plist disclosure says nothing is sent over a network, but firmware is sent to the peripheral over BLE. Narrow the claim to say no data is sent over the internet.
  • The README.md says image-upload requires --expect-serial, which contradicts the supported peripheral-pinned invocation. Update the option documentation.
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/tools/cv1/ble_central/Info.plist">

<violation number="1" location="omi/firmware/tools/cv1/ble_central/Info.plist:14">
P2: The disclosure says nothing is sent over a network, but `image-upload` transmits the firmware to the peripheral over BLE. Replace this with a narrower claim such as “No data is sent over the internet” so the Bluetooth transfer is not misrepresented.</violation>
</file>

<file name="omi/firmware/tools/cv1/ble_central/check_rejections.py">

<violation number="1" location="omi/firmware/tools/cv1/ble_central/check_rejections.py:46">
P2: `chmod(0)` does not make this file unreadable when the helper runs with elevated privileges, so the test can proceed into Bluetooth instead of exercising the intended refusal path. Skip this case for privileged runners or use a test setup that guarantees the executable runs without read permission.</violation>
</file>

<file name="omi/firmware/tools/cv1/ble_central/README.md">

<violation number="1" location="omi/firmware/tools/cv1/ble_central/README.md:56">
P2: `image-upload` is incorrectly documented as requiring `--expect-serial`, so the new peripheral-pinned invocation appears unsupported even though the CLI accepts it and the preceding section recommends it for serial-less devices. Document the requirement as either `--expect-serial VALUE` or `--expect-peripheral UUID`.</violation>
</file>

<file name="omi/firmware/tools/cv1/ble_central/Tests.swift">

<violation number="1" location="omi/firmware/tools/cv1/ble_central/Tests.swift:219">
P2: This upload test checks only first-chunk metadata presence, not its values. Assert the exact `sha`, image index, and `len` values so an invalid upload header cannot pass the pure checks.</violation>

<violation number="2" location="omi/firmware/tools/cv1/ble_central/Tests.swift:249">
P2: The new pin test covers only `image-upload`, so a regression in audio’s peripheral-pin acceptance can pass this suite. Add an audio-only `Options.parse` case using the peripheral pin.</violation>

<violation number="3" location="omi/firmware/tools/cv1/ble_central/Tests.swift:259">
P2: The pin tests never re-check a previously authorized connection. Add a second `beginConnection` with `otherID` after the successful pinned connection and assert that access is revoked.</violation>

<violation number="4" location="omi/firmware/tools/cv1/ble_central/Tests.swift:392">
P2: The new receipt test never verifies `peripheralIdentifier`. A regression dropping or renaming the connected UUID would pass the suite and prevent operators from learning the pin from a serial-matched receipt; serialize a UUID and assert its JSON key and value.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

<key>NSPrincipalClass</key><string>NSApplication</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Bench-test an Omi CV1: scan matching advertisements, connect and read firmware, serial, features and diagnostics. The audio command subscribes to at most three seconds of audio notifications. Results stay in the selected local receipt; audio is saved locally only when explicitly requested. Nothing is uploaded.</string>
<string>Bench-test an Omi CV1: scan matching advertisements, connect and read firmware, serial, features and diagnostics. The audio command subscribes to at most three seconds of audio notifications. Image commands use SMP to inspect image state; image-upload writes firmware, marks test/confirm, and resets unless disabled. Bonds and pairing are never used. Results stay in the selected local receipt; audio is saved locally only when explicitly requested. Nothing is sent over the network.</string>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The disclosure says nothing is sent over a network, but image-upload transmits the firmware to the peripheral over BLE. Replace this with a narrower claim such as “No data is sent over the internet” so the Bluetooth transfer is not misrepresented.

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/tools/cv1/ble_central/Info.plist, line 14:

<comment>The disclosure says nothing is sent over a network, but `image-upload` transmits the firmware to the peripheral over BLE. Replace this with a narrower claim such as “No data is sent over the internet” so the Bluetooth transfer is not misrepresented.</comment>

<file context>
@@ -11,6 +11,6 @@
     <key>NSPrincipalClass</key><string>NSApplication</string>
     <key>NSBluetoothAlwaysUsageDescription</key>
-    <string>Bench-test an Omi CV1: scan matching advertisements, connect and read firmware, serial, features and diagnostics. The audio command subscribes to at most three seconds of audio notifications. Results stay in the selected local receipt; audio is saved locally only when explicitly requested. Nothing is uploaded.</string>
+    <string>Bench-test an Omi CV1: scan matching advertisements, connect and read firmware, serial, features and diagnostics. The audio command subscribes to at most three seconds of audio notifications. Image commands use SMP to inspect image state; image-upload writes firmware, marks test/confirm, and resets unless disabled. Bonds and pairing are never used. Results stay in the selected local receipt; audio is saved locally only when explicitly requested. Nothing is sent over the network.</string>
 </dict>
 </plist>
</file context>
Suggested change
<string>Bench-test an Omi CV1: scan matching advertisements, connect and read firmware, serial, features and diagnostics. The audio command subscribes to at most three seconds of audio notifications. Image commands use SMP to inspect image state; image-upload writes firmware, marks test/confirm, and resets unless disabled. Bonds and pairing are never used. Results stay in the selected local receipt; audio is saved locally only when explicitly requested. Nothing is sent over the network.</string>
<string>Bench-test an Omi CV1: scan matching advertisements, connect and read firmware, serial, features and diagnostics. The audio command subscribes to at most three seconds of audio notifications. Image commands use SMP to inspect image state; image-upload writes firmware, marks test/confirm, and resets unless disabled. Bonds and pairing are never used. Results stay in the selected local receipt; audio is saved locally only when explicitly requested. No data is sent over the internet.</string>

image.write_bytes(header + struct.pack('<HHHH', 0x6907, 40, 0x10, 32) + bytes(range(32)))
unreadable = root / 'unreadable.bin'
unreadable.write_bytes(image.read_bytes())
unreadable.chmod(0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: chmod(0) does not make this file unreadable when the helper runs with elevated privileges, so the test can proceed into Bluetooth instead of exercising the intended refusal path. Skip this case for privileged runners or use a test setup that guarantees the executable runs without read permission.

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/tools/cv1/ble_central/check_rejections.py, line 46:

<comment>`chmod(0)` does not make this file unreadable when the helper runs with elevated privileges, so the test can proceed into Bluetooth instead of exercising the intended refusal path. Skip this case for privileged runners or use a test setup that guarantees the executable runs without read permission.</comment>

<file context>
@@ -33,10 +35,37 @@ def run(args, code):
+        image.write_bytes(header + struct.pack('<HHHH', 0x6907, 40, 0x10, 32) + bytes(range(32)))
+        unreadable = root / 'unreadable.bin'
+        unreadable.write_bytes(image.read_bytes())
+        unreadable.chmod(0)
+        image_flags = ['--file', str(image), '--mode', 'test']
+        result = run(['image-upload', '--seconds', '1', '--output', str(fresh)] + image_flags, 2)
</file context>


`image-state` discovers Device Information (`180A`, firmware `2A26`, serial `2A25`) and SMP service `8D53DC1D-1DB7-4CD3-868B-8A527460AA84` and characteristic `DA2E7828-FBCE-4E01-AE9E-261174997C48`. Both write without response and notify properties are required on the SMP characteristic. DIS firmware is required and recorded under each connection's `reads`; serial may be absent only when no serial was expected. All available DIS reads and any identity check must finish before subscription. After subscription acknowledgment it sends OS bootloader info (read, group 0/id 8, empty map), image state (read, group 1/id 0), and OS echo (write, group 0/id 0). It unsubscribes and requires disconnect acknowledgment before passing.

`image-upload` requires `--expect-serial VALUE`, a readable MCUboot-signed binary and explicit `--mode test|confirm`. Local parsing requires the MCUboot header and a single 32-byte SHA256 TLV (tag `0x10`), skipping the protected TLV area when present; it does not verify the signature. A raw application binary, ZIP, or missing hash is refused before any receipt/Bluetooth initialization. The supplied file is read once. Its whole-file SHA256 is used for upload-session `sha`; the distinct image SHA256 from the TLV is used for the image state write's `hash`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: image-upload is incorrectly documented as requiring --expect-serial, so the new peripheral-pinned invocation appears unsupported even though the CLI accepts it and the preceding section recommends it for serial-less devices. Document the requirement as either --expect-serial VALUE or --expect-peripheral UUID.

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/tools/cv1/ble_central/README.md, line 56:

<comment>`image-upload` is incorrectly documented as requiring `--expect-serial`, so the new peripheral-pinned invocation appears unsupported even though the CLI accepts it and the preceding section recommends it for serial-less devices. Document the requirement as either `--expect-serial VALUE` or `--expect-peripheral UUID`.</comment>

<file context>
@@ -27,25 +27,47 @@ open -n -W /path/CV1BLECentral.app --args audio --seconds 3 --expect-serial EXPE
+
+`image-state` discovers Device Information (`180A`, firmware `2A26`, serial `2A25`) and SMP service `8D53DC1D-1DB7-4CD3-868B-8A527460AA84` and characteristic `DA2E7828-FBCE-4E01-AE9E-261174997C48`. Both write without response and notify properties are required on the SMP characteristic. DIS firmware is required and recorded under each connection's `reads`; serial may be absent only when no serial was expected. All available DIS reads and any identity check must finish before subscription. After subscription acknowledgment it sends OS bootloader info (read, group 0/id 8, empty map), image state (read, group 1/id 0), and OS echo (write, group 0/id 0). It unsubscribes and requires disconnect acknowledgment before passing.
+
+`image-upload` requires `--expect-serial VALUE`, a readable MCUboot-signed binary and explicit `--mode test|confirm`. Local parsing requires the MCUboot header and a single 32-byte SHA256 TLV (tag `0x10`), skipping the protected TLV area when present; it does not verify the signature. A raw application binary, ZIP, or missing hash is refused before any receipt/Bluetooth initialization. The supplied file is read once. Its whole-file SHA256 is used for upload-session `sha`; the distinct image SHA256 from the TLV is used for the image state write's `hash`.
+
+After DIS and the required identity check, the sequence is image state read → image 0 upload (write, group 1/id 1) → image state write (`hash`, `confirm` true for confirm mode, false for test) → image state read → OS reset (write, group 0/id 5). `--no-reset` ends after the second state read and acknowledged unsubscribe/disconnect. Otherwise a successful reset response must precede a device disconnect. After a one-second reboot delay the tool reconnects to that same in-memory peripheral once, rereads DIS firmware and serial and repeats the identity check before subscribing again, reads bootloader info and image state, sends echo, then unsubscribes/disconnects. All steps share the overall deadline; missing reset responses/disconnects and reconnect failures fail the run. No alternate target or failed-operation retry is attempted. `passed` proves the SMP exchange and cleanup completed, **not** that MCUboot installed the image; compare the recorded slots/hashes before and after reset. Overwrite-only MCUboot may reject test semantics or expose different pending/permanent flags: the tool records the firmware response and never substitutes confirm mode.
</file context>
Suggested change
`image-upload` requires `--expect-serial VALUE`, a readable MCUboot-signed binary and explicit `--mode test|confirm`. Local parsing requires the MCUboot header and a single 32-byte SHA256 TLV (tag `0x10`), skipping the protected TLV area when present; it does not verify the signature. A raw application binary, ZIP, or missing hash is refused before any receipt/Bluetooth initialization. The supplied file is read once. Its whole-file SHA256 is used for upload-session `sha`; the distinct image SHA256 from the TLV is used for the image state write's `hash`.
`image-upload` requires `--expect-serial VALUE` or `--expect-peripheral UUID`, a readable MCUboot-signed binary and explicit `--mode test|confirm`. Local parsing requires the MCUboot header and a single 32-byte SHA256 TLV (tag `0x10`), skipping the protected TLV area when present; it does not verify the signature. A raw application binary, ZIP, or missing hash is refused before any receipt/Bluetooth initialization. The supplied file is read once. Its whole-file SHA256 is used for upload-session `sha`; the distinct image SHA256 from the TLV is used for the image state write's `hash`.

rejected(["scan"] + base + ["--file", input])
// 3.0.21 has no DIS serial: a CoreBluetooth peripheral pin can stand in for it.
let pinID = "8E3B7C1A-2F4D-4B6E-9A1C-0D2E3F405162", otherID = "00000000-0000-0000-0000-000000000000"
let pinned = try Options.parse(["image-upload"] + base + ["--file", input, "--mode", "confirm", "--expect-peripheral", pinID.lowercased()])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new pin test covers only image-upload, so a regression in audio’s peripheral-pin acceptance can pass this suite. Add an audio-only Options.parse case using the peripheral pin.

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/tools/cv1/ble_central/Tests.swift, line 249:

<comment>The new pin test covers only `image-upload`, so a regression in audio’s peripheral-pin acceptance can pass this suite. Add an audio-only `Options.parse` case using the peripheral pin.</comment>

<file context>
@@ -150,7 +150,246 @@ enum Tests {
+        rejected(["scan"] + base + ["--file", input])
+        // 3.0.21 has no DIS serial: a CoreBluetooth peripheral pin can stand in for it.
+        let pinID = "8E3B7C1A-2F4D-4B6E-9A1C-0D2E3F405162", otherID = "00000000-0000-0000-0000-000000000000"
+        let pinned = try Options.parse(["image-upload"] + base + ["--file", input, "--mode", "confirm", "--expect-peripheral", pinID.lowercased()])
+        check(pinned.expectPeripheral == pinID && pinned.expectSerial == nil, "Peripheral pin normalizes and stands in for serial")
+        rejected(["image-upload"] + base + ["--file", input, "--mode", "test", "--expect-peripheral", "not-a-uuid"])
</file context>
Suggested change
let pinned = try Options.parse(["image-upload"] + base + ["--file", input, "--mode", "confirm", "--expect-peripheral", pinID.lowercased()])
let pinned = try Options.parse(["image-upload"] + base + ["--file", input, "--mode", "confirm", "--expect-peripheral", pinID.lowercased()])
let audioPinned = try Options.parse(["audio", "--seconds", "3", "--output", root.appendingPathComponent("audio.json").path, "--expect-peripheral", pinID.lowercased()])
check(audioPinned.expectPeripheral == pinID && audioPinned.expectSerial == nil, "Audio accepts peripheral pin")

var receipt = Receipt(startedAt: "synthetic", requestedSeconds: 1, deadlineSeconds: 1, progress: Progress(command: options.command))
receipt.postResetFirmware = decodeText(Data("synthetic-2".utf8))
let json = try JSONSerialization.jsonObject(with: JSONEncoder().encode(receipt)) as! [String: Any]
check((json["postResetFirmware"] as? [String: Any])?["text"] as? String == "synthetic-2", "Post-reset DIS firmware serialized in receipt")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new receipt test never verifies peripheralIdentifier. A regression dropping or renaming the connected UUID would pass the suite and prevent operators from learning the pin from a serial-matched receipt; serialize a UUID and assert its JSON key and value.

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/tools/cv1/ble_central/Tests.swift, line 392:

<comment>The new receipt test never verifies `peripheralIdentifier`. A regression dropping or renaming the connected UUID would pass the suite and prevent operators from learning the pin from a serial-matched receipt; serialize a UUID and assert its JSON key and value.</comment>

<file context>
@@ -150,7 +150,246 @@ enum Tests {
+        var receipt = Receipt(startedAt: "synthetic", requestedSeconds: 1, deadlineSeconds: 1, progress: Progress(command: options.command))
+        receipt.postResetFirmware = decodeText(Data("synthetic-2".utf8))
+        let json = try JSONSerialization.jsonObject(with: JSONEncoder().encode(receipt)) as! [String: Any]
+        check((json["postResetFirmware"] as? [String: Any])?["text"] as? String == "synthetic-2", "Post-reset DIS firmware serialized in receipt")
+    }
     static func tryParse(_ args: [String]) -> Bool { (try? Options.parse(args)) != nil }
</file context>

check(pinPlan.access == nil, "Wrong peripheral leaves no SMP access")
try pinPlan.beginConnection(discovered: [UUIDs.firmware], peripheral: pinID)
try pinPlan.consumeDIS(uuid: UUIDs.firmware, data: Data("3.0.21".utf8))
check(pinPlan.access?.allowsSMP == true && pinPlan.access?.identity.status == .matched, "Pinned peripheral without serial allows SMP")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The pin tests never re-check a previously authorized connection. Add a second beginConnection with otherID after the successful pinned connection and assert that access is revoked.

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/tools/cv1/ble_central/Tests.swift, line 259:

<comment>The pin tests never re-check a previously authorized connection. Add a second `beginConnection` with `otherID` after the successful pinned connection and assert that access is revoked.</comment>

<file context>
@@ -150,7 +150,246 @@ enum Tests {
+        check(pinPlan.access == nil, "Wrong peripheral leaves no SMP access")
+        try pinPlan.beginConnection(discovered: [UUIDs.firmware], peripheral: pinID)
+        try pinPlan.consumeDIS(uuid: UUIDs.firmware, data: Data("3.0.21".utf8))
+        check(pinPlan.access?.allowsSMP == true && pinPlan.access?.identity.status == .matched, "Pinned peripheral without serial allows SMP")
+        var both = IdentityCheck(expectedSerial: "synthetic-bench", expectedPeripheral: pinID)
+        both.connected(to: pinID)
</file context>
Suggested change
check(pinPlan.access?.allowsSMP == true && pinPlan.access?.identity.status == .matched, "Pinned peripheral without serial allows SMP")
check(pinPlan.access?.allowsSMP == true && pinPlan.access?.identity.status == .matched, "Pinned peripheral without serial allows SMP")
mustThrow("Accepted another peripheral after reconnect") { try pinPlan.beginConnection(discovered: [UUIDs.firmware], peripheral: otherID) }
check(pinPlan.access == nil, "Wrong peripheral leaves no SMP access after reconnect")

check(total <= 2475 && !bytes.isEmpty, "Chunk fits netbuf including header")
check(total <= (maximum > 2475 ? 2475 : (2475 / maximum) * maximum), "Chunk respects write-sized reassembly budget")
check(bytes == image.data.subdata(in: offset..<(offset + bytes.count)), "Exact upload bytes")
check((chunk["sha"] != nil) == (offset == 0) && (chunk["image"] != nil) == (offset == 0), "First chunk metadata only")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This upload test checks only first-chunk metadata presence, not its values. Assert the exact sha, image index, and len values so an invalid upload header cannot pass the pure checks.

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/tools/cv1/ble_central/Tests.swift, line 219:

<comment>This upload test checks only first-chunk metadata presence, not its values. Assert the exact `sha`, image index, and `len` values so an invalid upload header cannot pass the pure checks.</comment>

<file context>
@@ -150,7 +150,246 @@ enum Tests {
+                check(total <= 2475 && !bytes.isEmpty, "Chunk fits netbuf including header")
+                check(total <= (maximum > 2475 ? 2475 : (2475 / maximum) * maximum), "Chunk respects write-sized reassembly budget")
+                check(bytes == image.data.subdata(in: offset..<(offset + bytes.count)), "Exact upload bytes")
+                check((chunk["sha"] != nil) == (offset == 0) && (chunk["image"] != nil) == (offset == 0), "First chunk metadata only")
+            }
+        }
</file context>
Suggested change
check((chunk["sha"] != nil) == (offset == 0) && (chunk["image"] != nil) == (offset == 0), "First chunk metadata only")
if offset == 0 {
check(chunk["sha"] == CBOR.bytes(hash) && chunk["image"] == CBOR.uint(0) && chunk["len"] == CBOR.uint(UInt64(image.data.count)), "First chunk metadata")
} else {
check(chunk["sha"] == nil && chunk["image"] == nil && chunk["len"] == nil, "First chunk metadata")
}

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)
@Git-on-my-level
Git-on-my-level merged commit 14c9c33 into main Nov 14, 2026
48 checks passed
@Git-on-my-level
Git-on-my-level deleted the fw/cv1-ble-dfu branch November 14, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant