Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
14b9baf
Deck panel update: the panel reads its image and rules from a signed …
Skeyelab Nov 21, 2026
daa8546
Deck panel update: anything but a well-formed manifest is not read, c…
Skeyelab Nov 21, 2026
47783c1
Deck panel update: a manifest signed by a trusted key is taken; an un…
Skeyelab Nov 21, 2026
bc07a14
Deck panel update: nothing but a signed manifest comes first; image b…
Skeyelab Nov 21, 2026
47a4f15
Deck panel update: an image is streamed into the spare slot and set t…
Skeyelab Nov 21, 2026
96ebc3b
Deck panel update: an image altered, cut short or too long is refused…
Skeyelab Nov 21, 2026
65d652c
Deck panel update: below the floor or the manifest's lowest allowed, …
Skeyelab Nov 21, 2026
d04eaf5
Deck panel update: a switch names the floor to keep once the new imag…
Skeyelab Nov 21, 2026
53855ae
Deck panel update: the update connection takes framed bytes in any sp…
Skeyelab Nov 21, 2026
4c1cdd0
Deck panel update: frames over their caps are refused from the header…
Skeyelab Nov 21, 2026
5fd5b81
Deck panel update: a second sender is refused busy; idle, stalled or …
Skeyelab Nov 21, 2026
8e1b0f9
Deck panel update: a new image confirms itself once Wi-Fi (or setup m…
Skeyelab Nov 21, 2026
3ca43ee
Deck panel update: the panel trusts exactly the app's release keys, e…
Skeyelab Nov 21, 2026
8dc802f
CI: the Deck panel job checks the panel's release keys against the ap…
Skeyelab Nov 21, 2026
24d1a22
Deck panel update: the wire protocol written down for the app side (#…
Skeyelab Nov 21, 2026
46644bc
Deck panel update: the panel checks a release's Ed25519 signature wit…
Skeyelab Nov 21, 2026
c09c823
Deck panel update: the image's SHA-256 is libsodium's, fed chunk by c…
Skeyelab Nov 21, 2026
c8962d0
CI: the Deck panel job installs libsodium with a timeout and one retr…
Skeyelab Nov 21, 2026
c83e4ea
Deck panel update: a whole signed update through the session with lib…
Skeyelab Nov 21, 2026
bafd952
Merge remote-tracking branch 'origin/main' into 690-wifi-update
Skeyelab Nov 21, 2026
e3cf6cc
Deck panel update: the stored floor only ever rises, and only to a ve…
Skeyelab Nov 21, 2026
a9b49e7
Deck panel update: a zero-length read restarts the link's idle clock,…
Skeyelab Nov 21, 2026
1a31b79
Deck panel update: the board takes a signed update over Wi-Fi: TCP 33…
Skeyelab Nov 21, 2026
5287c62
Merge remote-tracking branch 'origin/main' into 690-wifi-update
Skeyelab Nov 23, 2026
5a0cd5d
Deck panel trusts the owner's release keys, the same pair as the upda…
Skeyelab Nov 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,27 @@ jobs:
key: deck-panel-pio-6.2.0-${{ hashFiles('tools/deck-panel/platformio.ini') }}
- name: PlatformIO
run: pip install platformio==6.2.0
# The host tests check release signatures and image hashes with the system libsodium (#690); the board links the
# copy in the ESP32 libs. Two builds of one library: the shared RFC 8032 and CryptoKit vectors tie them together.
# Same guard as the Arm toolchain (#640): a stalled transfer gives up after 30 s, an attempt over 2 minutes is cut
# off and tried once more, so it can't hang the merge queue.
- name: libsodium
run: |
apt="-o Acquire::http::Timeout=30 -o Acquire::Retries=3"
for attempt in 1 2; do
timeout 120 sudo apt-get $apt update && timeout 120 sudo apt-get $apt install -y --no-install-recommends \
libsodium-dev && break
[ "$attempt" = 2 ] && exit 1
echo "libsodium download attempt $attempt failed or stalled; trying once more"
done
echo "libsodium $(dpkg-query -W -f='${Version}' libsodium-dev)"
- name: Deck panel host tests
run: |
pio test -d tools/deck-panel -e native
python3 -I tools/deck-panel/test_secret_logs.py
python3 -I tools/deck-panel/check_secret_logs.py
python3 -I tools/deck-panel/test_deck_logo.py
python3 -I tools/deck-panel/test_release_keys.py
python3 -I tools/deck-panel/test_git_sha.py
# The panel keeps its Wi-Fi in NVS, set from a phone (#622): nothing to build in.
- name: Deck panel firmware build
Expand Down
79 changes: 79 additions & 0 deletions docs/DECK-PANEL-UPDATE-PROTOCOL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Deck panel update protocol

How the firmware updater (#691) sends a signed firmware release to a deck panel over Wi-Fi (#690). The signing and
the manifest are ADR 0012's; this is the wire between the Mac and the panel. The panel's side is
`tools/deck-panel/lib/update_link` and `lib/update_session`, tested in the native env.

## Connection

- TCP, port **3310** on the panel. The display feed is UDP; nothing else uses this port.
- **One connection at a time.** A second one gets `refused busy` and is closed; the first carries on.
- The connection is the update: it ends with a switch or a refusal, and the panel closes it.

## Frames, Mac to panel

Each frame is one type byte, a 4-byte **little-endian** length, then that many bytes.

| Type | Payload | Cap (checked from the header, before a byte is kept) |
|---|---|---|
| `M` | the release's `manifest.json`, its exact bytes | 32 KB |
| `S` | `manifest.sig`: the 64-byte Ed25519 signature over those bytes | exactly 64 |
| `I` | the next piece of the deck panel image | 4 KB |
| `D` | done: the image is all sent | 0 |

The order is always `M`, `S`, then `I`... and `D`. Any other order, an unknown type or a frame over its cap is
refused, and the connection is closed.

## Lines, panel to Mac

One text line per step, ending in `\n`:

| Line | When |
|---|---|
| `ok manifest` | the signature checked out and every rule passed; the panel has erased the image's size in its spare slot |
| `progress <bytes>` | after each `I` frame: image bytes taken so far |
| `ok switched <version>` | after `D`: size and SHA-256 match, the new image is set to boot. The panel then closes the connection and restarts into it |
| `refused <reason>` | anything else, then the panel closes the connection. The old firmware keeps running |

Reasons: `busy`, `no-manifest`, `too-large`, `unreadable`, `unknown-key`, `bad-signature`, `unknown-format`,
`no-image`, `too-old`, `too-big`, `mismatch`, `timeout`, `slot-error`.

## What the panel checks, in order

1. **Nothing touches flash before the signature.** Until `S` checks out, the only thing read from the manifest is
the name of the key that signed it.
2. **Signature:** the key the manifest names must be one the panel trusts (`lib/release_keys`, the same list as the
app's `ReleaseKeys.swift`; empty until the owner makes the keys, so every update is `unknown-key` until then).
The signature is checked over the manifest's exact bytes.
3. **Rules:**
- `format` must be 1.
- There must be a `deck-panel` file.
- Its version must not be below the panel's **floor** or the manifest's `lowest_allowed`. The floor is kept in
the panel's NVS and only ever raised: to the manifest's `lowest_allowed`, once the new image has confirmed
itself. So a validly signed older image can't be sent back after a security fix.
- It must fit the spare slot.
4. **Image:**
- It is hashed as it arrives.
- More bytes than the manifest's size are refused at the first extra byte.
- At `D`, the size and SHA-256 must equal the manifest's, or the update is `mismatch` and the slot is never booted.
5. **After the switch:**
- The new image boots as a trial.
- It confirms itself once what recovery needs is up, within 120 s: its saved Wi-Fi joined, or, with no saved
Wi-Fi, its setup network up. The update server must be listening too.
- If that doesn't happen, the panel restarts into the previous image.
- The display feed is not asked for, so an update with DeckBridge closed doesn't roll a good image back.

## Timeouts and a dropped link

- **Before the signature has checked out:** 3 s with nothing received ends the connection (`refused timeout`). A
stray connection can't hold `busy`.
- **Mid-image:** 10 s with nothing received ends it.
- **The connection closing before `ok switched`:** nothing is switched. The bytes written so far are dropped and the
old firmware keeps running. Power loss mid-transfer is the same: the boot slot was never changed.

## Open points for #691

- **Finding the panel.** Today the panel's address is shown on its waiting screen, so the app can take it typed in.
Later: an mDNS name or a UDP answer to a broadcast.
- **What the app shows during the update:** the panel shows a still "Updating" screen while it writes flash,
because flash writes make the picture tear.
4 changes: 3 additions & 1 deletion scripts/ci_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"tools/lc6000-display-fw/arm/upper_header.py"]
# What the Deck panel job (#615) builds and tests, and CI itself, so a change to the job runs it. The icon SVG the
# panel's logo is made from (#651), whose drift test the job runs (#669).
DECK_PANEL = ["tools/deck-panel/*", ".github/workflows/ci.yml", "design/icon/icon-1-deck-ring.svg"]
# The app's release keys, which the panel must trust too (#690).
DECK_PANEL = ["tools/deck-panel/*", ".github/workflows/ci.yml", "design/icon/icon-1-deck-ring.svg",
"Packages/FirmwareUpdaterKit/Sources/FirmwareRelease/ReleaseKeys.swift"]


def site_only(path):
Expand Down
4 changes: 4 additions & 0 deletions scripts/test_ci_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def test_the_icon_svg_the_logo_is_made_from_runs_it(self):
self.assertTrue(ci_changes.needs_deck_panel(["design/icon/icon-1-deck-ring.svg"]))
self.assertFalse(ci_changes.needs_deck_panel(["design/icon/menubar-deck-ring-16.svg"]))

def test_the_app_release_keys_run_it(self):
# the panel must trust the same keys (#690); test_release_keys.py, run by the Deck panel job, compares them
self.assertTrue(ci_changes.needs_deck_panel(["Packages/FirmwareUpdaterKit/Sources/FirmwareRelease/ReleaseKeys.swift"]))

def test_a_change_to_the_ci_workflow_runs_it(self):
self.assertTrue(ci_changes.needs_deck_panel([".github/workflows/ci.yml"]))

Expand Down
27 changes: 27 additions & 0 deletions tools/deck-panel/lib/release_check/release_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "release_check.h"

#include <sodium.h>

namespace release_check {

bool signature_ok(const uint8_t public_key[32], const uint8_t* message, size_t length, const uint8_t signature[64]) {
// sodium_init is safe to call again and returns 1 once it has run; -1 means libsodium can't be used.
if (sodium_init() < 0) return false;
static const uint8_t empty = 0;
return crypto_sign_verify_detached(signature, message ? message : &empty, length, public_key) == 0;
}

Sha256::Sha256() : state_() { start(); }

void Sha256::start() {
// libsodium asks for sodium_init before any call; SHA-256 has no setup that can fail, so its result doesn't matter here.
const int ready = sodium_init();
(void)ready;
crypto_hash_sha256_init(&state_);
}

void Sha256::update(const uint8_t* data, size_t length) { crypto_hash_sha256_update(&state_, data, length); }

void Sha256::finish(uint8_t out[32]) { crypto_hash_sha256_final(&state_, out); }

} // namespace release_check
28 changes: 28 additions & 0 deletions tools/deck-panel/lib/release_check/release_check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Checks a signed firmware release on the panel (#690, ADR 0012): the Ed25519 signature over the manifest's exact bytes.
#pragma once

#include <cstddef>
#include <cstdint>

#include <sodium.h>

#include "update_session.h"

namespace release_check {

/// Whether `signature` is `public_key`'s Ed25519 signature (RFC 8032) over exactly `message`.
bool signature_ok(const uint8_t public_key[32], const uint8_t* message, size_t length, const uint8_t signature[64]);

/// SHA-256 (FIPS 180-4) of an image that arrives in chunks: the session's hasher on the panel and in native tests.
class Sha256 : public update_session::Hasher {
public:
Sha256();
void start() override;
void update(const uint8_t* data, size_t length) override;
void finish(uint8_t out[32]) override;

private:
crypto_hash_sha256_state state_;
};

} // namespace release_check
32 changes: 32 additions & 0 deletions tools/deck-panel/lib/release_keys/release_keys.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "release_keys.h"

#include <cstring>

namespace release_keys {
namespace {

int nibble(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
return -1;
}

} // namespace

size_t trusted(const Listed* list, update_session::TrustedKey* out, size_t max) {
size_t n = 0;
for (const Listed* entry = list; entry->id && n < max; ++entry) {
if (std::strlen(entry->hex) != 64) continue;
update_session::TrustedKey key{entry->id, {}};
bool ok = true;
for (size_t i = 0; i < 32 && ok; ++i) {
const int hi = nibble(entry->hex[2 * i]), lo = nibble(entry->hex[2 * i + 1]);
ok = hi >= 0 && lo >= 0;
key.public_key[i] = static_cast<uint8_t>(hi * 16 + lo);
}
if (ok) out[n++] = key;
}
return n;
}

} // namespace release_keys
29 changes: 29 additions & 0 deletions tools/deck-panel/lib/release_keys/release_keys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// The release keys the panel trusts (#690, ADR 0012): the maintainer's primary key and the offline backup key, the
// same pairs as the updater app's ReleaseKeys.swift (test_release_keys.py checks they match).
//
// The owner made them on 2026-11-23 (#689, docs/FIRMWARE-RELEASE-SIGNING.md). Public halves only.
#pragma once

#include <cstddef>

#include "update_session.h"

namespace release_keys {

struct Listed {
const char* id;
const char* hex; ///< the public key as 64 hex characters, as `firmware-release public-key` prints it
};

// Each entry: {"primary", "<64 hex>"}, then {"backup", "<64 hex>"}. Ends with the {nullptr, nullptr} marker.
constexpr Listed kListed[] = {
{"primary", "26739c2c075965fd9a99330f97c3b09a28d11f85c1fa4d81bd5495cb67c1a5f8"},
{"backup", "2e972a79fd40b287a151166dcdc723d07e84afe9ffc933fb211c670873c07cbe"},
{nullptr, nullptr},
};

/// The keys in `list` (ending with the {nullptr, nullptr} marker) as the update session takes them: up to `max` into
/// `out`, leaving out any that isn't 64 lowercase hex characters. Returns how many.
size_t trusted(const Listed* list, update_session::TrustedKey* out, size_t max);

} // namespace release_keys
12 changes: 12 additions & 0 deletions tools/deck-panel/lib/update_boot/update_boot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "update_boot.h"

namespace update_boot {

Decision decide(const State& s) {
if (!s.trial) return Decision::nothing;
const bool network = s.saved_wifi ? s.wifi_joined : s.setup_network_up;
if (network && s.update_listening) return Decision::confirm;
return s.since_boot_ms >= kTrialMs ? Decision::roll_back : Decision::wait;
}

} // namespace update_boot
28 changes: 28 additions & 0 deletions tools/deck-panel/lib/update_boot/update_boot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Whether a newly switched-to image confirms itself (#690). It boots as a trial (ESP-IDF rollback); it confirms only
// once it has brought up what recovery needs, so a bad release can always be replaced over Wi-Fi:
// - with saved Wi-Fi: joined, and the update server listening;
// - with none (setup mode, #622): the setup network up, and the update server listening on it.
// Not the display feed: a panel updated with DeckBridge closed would otherwise roll a good image back every time.
// If that isn't reached within kTrialMs, the panel restarts into the previous image.
#pragma once

#include <cstdint>

namespace update_boot {

constexpr uint32_t kTrialMs = 120000;

struct State {
bool trial = false; ///< this image runs as a trial: switched to, not yet confirmed
bool saved_wifi = false;
bool wifi_joined = false;
bool setup_network_up = false;
bool update_listening = false;
uint32_t since_boot_ms = 0;
};

enum class Decision { nothing, wait, confirm, roll_back };

Decision decide(const State& state);

} // namespace update_boot
12 changes: 12 additions & 0 deletions tools/deck-panel/lib/update_floor/update_floor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "update_floor.h"

#include "update_session.h"

namespace update_floor {

std::string raised(const std::string& current, const std::string& pending) {
if (!update_session::is_version(pending) || update_session::below(pending, current)) return current;
return pending;
}

} // namespace update_floor
13 changes: 13 additions & 0 deletions tools/deck-panel/lib/update_floor/update_floor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// The panel's floor (#690, docs/DECK-PANEL-UPDATE-PROTOCOL.md): the lowest version it takes over Wi-Fi. The board keeps
// it in NVS; this says what to keep when a new image confirms itself with the floor its manifest asked for.
#pragma once

#include <string>

namespace update_floor {

/// The floor to keep: `pending` when it is a version not below `current`, else `current`. Never lower, and never
/// something that isn't a version (that would count every version below it and refuse every update for good).
std::string raised(const std::string& current, const std::string& pending);

} // namespace update_floor
Loading
Loading