Reduce nRF52 Companion flash and stream Reader chapters

Use a 960-byte constant-time Ed25519 base table, compact hash/scalar code and unused-library trims while retaining Reader, BLE P-256 and the 8 KiB stack. RAK4631 Full saves 57,496 flash bytes and 3,152 static RAM bytes versus preview3.

Support complete chapters and verse ranges with bounded app continuation replies and cooperative terminal output. Use nonblocking TCP writes under reader backpressure. Add scalar/signature comparisons and a linked ARM crypto/stack CI gate.

Validated clean RAK4631, T1000-E, T096 and V4 Full builds, host regressions, and physical RAK chapter/reconnect and signing comparisons. Physical signing averages 35.9 ms versus 14.4 ms with the original table.
This commit is contained in:
mikecarper committed 2026-10-13 01:02:30 -07:00
1 parent 65820d0dd2
commit d2bea5fb10
21 files changed
+803 -86

No files matched your search

+53
View File
@@ -315,6 +315,59 @@ refuses the loan; sync messages with an app first. USB/TCP source detach or
disconnect returns all 256 slots and releases the ESP32 proof/leaf scratch
buffers. The display and simultaneous USB, Bluetooth and WiFi remain enabled.
## nRF52 Companion flash savings
The common nRF52 Companion policy now retains a 960-byte Ed25519 fixed-base
table in place of the original 30,720-byte table. It evaluates the same signed
radix-16 digits with constant-time table selection, using more doublings instead
of storing 32 shifted rows. Compact SHA-512 and scalar arithmetic keep the same
outputs and wire format. The larger RAM-built table used by infrastructure
profiles is not enabled for Companions.
The policy also omits unused USB device MSC/HID/MIDI/vendor/video classes,
SparkFun's unused automatic NMEA cache and the invisible SSD1306 vendor splash.
For the exact hash-qualified CC310 archive, the domain wrapper retains P-256
for BLE Secure Connections and removes unused legacy curves. CDC, DFU, USB host,
GPS navigation, all Companion fonts, Meshtext, contacts, channels, the Reader
corpus and the 8 KiB loop stack remain available. Explicit board/user overrides
and `MESH_NRF52_COMPANION_TRIM=0` retain their requested values. Other platforms
do not receive this Companion policy.
The RAK4631 Full comparison uses the released 1.17.1.10 preview3 ELF at
`9ce2a076` and the same target with these changes and Reader chapter/range
support. Flash is initialized linked code/data; static RAM is `.data` plus
ordinary `.bss`, excluding separately reserved arenas.
| Measurement | Preview3 | With Companion trims and Reader ranges | Difference |
| --- | ---: | ---: | ---: |
| Linked flash bytes | 710,404 | 652,908 | 57,496 fewer (56.1 KiB) |
| Static RAM bytes | 157,028 | 153,876 | 3,152 fewer (3.1 KiB) |
| Linked heap capacity bytes | 78,484 | 81,636 | 3,152 more |
| UF2 space below the application ceiling | 2,048 | 59,648 | 57,600 more |
Physical RAK signing averaged 14.4 ms with the original table and 35.9 ms with
the smaller implementation. All 24 signatures per image, including SHA-512
block-boundary message lengths, matched byte for byte and verified independently.
The linked ARM emulator measures 1,928 bytes in signing versus 1,528 before;
these are crypto function frames only, excluding callers, interrupts and other
tasks. The loop stack stays at 8 KiB. A full firmware RAM check still applies.
CI runs `scripts/check_nrf52_companion_crypto.py` on the actual Full RAK ELF.
It checks the 960-byte table and retained Reader corpus, executes two RFC 8032
vectors, and rejects crypto function stack use above 2 KiB. Host tests compare
1,791 scalars and 128 keypair/signature/shared-secret cases against the original
implementation, plus scalar boundary/random and sanitizer tests. Clean Full
builds also cover T1000-E and T096. These builds are synthetic coverage for
those boards; the physical Reader/signing tests use the RAK4631.
Reader commands support `get reader 2` and `get reader 2:2-12`. Text terminals
stream at most 96 bytes per mesh loop, preserving progress under zero/short
writes. The TCP console uses one nonblocking socket-send attempt for the stream,
so a peer that stops reading cannot hold the mesh loop in WiFiClient retries.
App CLI replies remain bounded and supply a continuation command.
The physical RAK passed all 21 chapters, ranges, app-style continuation replies,
a paused USB reader exceeding the 4 KiB queue, and disconnect cancellation.
## Release evidence and regression tests
Full Companions without PSRAM also use
+13 -2
View File
@@ -200,10 +200,21 @@ ESP32 and nRF52 Full Companions include an offline World English Bible lookup:
```text
get reader 3:16
get reader 2
get reader 2:2-12
```
This returns a single complete verse from the embedded corpus, using plain ASCII punctuation
with unchanged wording and capitalization, through the local USB/TCP terminal.
These select a verse, an entire chapter, or an inclusive verse range from the
embedded corpus. Local USB/TCP/browser terminals stream the complete selection
in small chunks, keeping the radio loop running while the terminal drains.
A new command or disconnected session cancels unfinished output. Text uses
plain ASCII punctuation with unchanged wording and capitalization.
In the app's USB/BLE CLI, each reply stays within the existing frame limit.
Follow the displayed `Next: get reader ...` command to continue a long verse
or advance through the selected chapter/range. The optional final number is
the page within the first verse of that command, for example `get reader 21:17 2`.
The continuation command retains the requested range's end.
See [Reader lookup and compression](https://github.com/mikecarper/MeshCore/blob/keymindCascade/tools/bible/README.md) for the
source, supported build profiles and memory costs.