Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ jobs:
- name: Assemble release images (dry run)
run: |
version="$(sed -nE 's/^#define MSNS_FW_VERSION "(.*)"/\1/p' include/version.h)"
python tools/release.py --tag "v${version}" --out dist
python tools/release.py --tag "v${version}" --out dist --site site
cat dist/manifest.json
- uses: actions/upload-artifact@v4
with:
name: firmware-images
path: dist/
- uses: actions/upload-artifact@v4
with:
name: web-flasher
path: site/
22 changes: 21 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name: Release
# MSNS_FW_VERSION in include/version.h.
#
# Flash with navkit: nav flash
# From a browser: the web flasher on GitHub Pages (see below)
# Or by hand: esptool --chip esp32 write-flash 0x0 msns-firmware-esp32dev-v0.2.0.bin

on:
Expand All @@ -25,8 +26,27 @@ jobs:
- run: pip install platformio "esptool>=5"
- run: python3 tools/check_boards.py
- run: pio run
- run: python tools/release.py --tag "$GITHUB_REF_NAME" --out dist
- run: python tools/release.py --tag "$GITHUB_REF_NAME" --out dist --site site
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" dist/* --title "$GITHUB_REF_NAME" --generate-notes
- uses: actions/upload-pages-artifact@v3
with:
path: site/

# Web flasher. Enable once: repository Settings → Pages → Source "GitHub
# Actions", then set the repository variable PAGES_DEPLOY=true.
pages:
needs: release
if: vars.PAGES_DEPLOY == 'true'
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
steps:
- id: deploy
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.vscode
.DS_Store
dist/
site/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Host output moved out of `main.cpp` into `src/transport.cpp`.

### Added
- **Web flasher** (`web/index.html`, built by `tools/release.py --site`):
flash any released board from Chrome or Edge with no install. Deployed to
GitHub Pages by the release workflow when `PAGES_DEPLOY=true`.
- **Board manifests** (`targets/<id>.json`): pins, flash layout and status
per board, applied to the build by `scripts/board.py`. Adding a board is
one JSON file and one PlatformIO environment. See `docs/boards.md`.
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ firmware/
├── tools/
│ ├── host/ # Host-side protocol tests + golden stream generator
│ ├── check_boards.py # CI check: manifests ↔ PlatformIO environments
│ └── release.py # Merges release images and writes manifest.json
│ └── release.py # Merges release images, writes manifest.json, builds the web flasher
├── web/index.html # Web flasher page (ESP Web Tools)
├── platformio.ini # PlatformIO build config
├── sdkconfig.defaults # ESP-IDF SDK overrides (task WDT tuning)
└── docs/
Expand All @@ -338,12 +339,22 @@ Managed by PlatformIO — no manual installation needed.

## Build & Flash

### Without a toolchain

| Route | How |
|---|---|
| Terminal | `nav flash` from [Repo 2](https://github.com/multi-sensor-navigation-system/data-pipeline): detects the board, downloads the matching release image, verifies its SHA-256, flashes it |
| Browser | The web flasher published with each release (Chrome or Edge on a desktop): pick the board, press Flash |
| By hand | Download `msns-firmware-<board>-<tag>.bin` from Releases, then `esptool --chip esp32 write-flash 0x0 <file>` |

### From source

```bash
# Build and flash the default (binary) firmware
pio run -e esp32dev --target upload
```

Replace `esp32dev` with another board id from [`docs/boards.md`](docs/boards.md) to build for it. Released images can be flashed without PlatformIO: `nav flash` from [Repo 2](https://github.com/multi-sensor-navigation-system/data-pipeline) detects the board and downloads the right one.
Replace `esp32dev` with another board id from [`docs/boards.md`](docs/boards.md) to build for it.

The binary stream is not readable in a serial monitor; log it with the host logger from [Repo 2](https://github.com/multi-sensor-navigation-system/data-pipeline), which prints the firmware's messages and writes the CSV.

Expand Down
Binary file modified scripts/__pycache__/boards.cpython-313.pyc
Binary file not shown.
34 changes: 34 additions & 0 deletions tools/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

pio run # build every environment first
python tools/release.py --tag v0.2.0 --out dist
python tools/release.py --tag v0.2.0 --out dist --site site # also build the web flasher

Requires esptool >= 5 on PATH.
"""
import argparse
import hashlib
import json
import re
import shutil
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -60,12 +62,42 @@ def merge(board: dict, build_dir: Path, boot_app0: Path, out: Path) -> None:
subprocess.run(cmd, check=True)


# esptool chip id → ESP Web Tools chipFamily
CHIP_FAMILY = {"esp32": "ESP32", "esp32s2": "ESP32-S2", "esp32s3": "ESP32-S3",
"esp32c3": "ESP32-C3", "esp32c6": "ESP32-C6", "esp32h2": "ESP32-H2"}


def build_site(manifest: dict, dist: Path, site: Path) -> None:
"""The web flasher: web/index.html, the images, and one ESP Web Tools manifest per board.

The images are copied next to the page because browsers cannot fetch
GitHub release assets cross-origin.
"""
(site / "web").mkdir(parents=True, exist_ok=True)
shutil.copy(ROOT / "web" / "index.html", site / "index.html")
shutil.copy(dist / "manifest.json", site / "manifest.json")
for board_id, entry in manifest["boards"].items():
shutil.copy(dist / entry["image"], site / entry["image"])
web_manifest = {
"name": f"MSNS firmware — {entry['name']}",
"version": manifest["version"],
"new_install_prompt_erase": False,
"builds": [{
"chipFamily": CHIP_FAMILY[entry["chip"]],
"parts": [{"path": f"../{entry['image']}", "offset": 0}],
}],
}
(site / "web" / f"{board_id}.json").write_text(json.dumps(web_manifest, indent=2) + "\n")
print(f" web flasher → {site}")


def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--tag", required=True, help="release tag, e.g. v0.2.0")
ap.add_argument("--out", type=Path, default=ROOT / "dist")
ap.add_argument("--build-root", type=Path, default=ROOT / ".pio" / "build")
ap.add_argument("--boot-app0", type=Path, default=DEFAULT_BOOT_APP0)
ap.add_argument("--site", type=Path, help="also build the web flasher into this directory")
args = ap.parse_args()

fw_version = macro("version.h", "MSNS_FW_VERSION")
Expand Down Expand Up @@ -96,6 +128,8 @@ def main() -> int:

(args.out / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
print(f" manifest.json ({len(manifest['boards'])} boards, proto {manifest['proto']})")
if args.site:
build_site(manifest, args.out, args.site)
return 0


Expand Down
123 changes: 123 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flash firmware · Multi-Sensor Navigation System</title>
<style>
:root {
--bg: #f6f5f1; --card: #ffffff; --ink: #1b1d21; --muted: #5d6470; --line: #dedbd3;
--accent: #0f6b5c; --accent-ink: #ffffff; --warn-bg: #fff4d6; --warn-ink: #6b4a00;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #14161a; --card: #1d2026; --ink: #eceae4; --muted: #a2a8b3; --line: #30343c;
--accent: #4fc3ad; --accent-ink: #0c1f1b; --warn-bg: #3a2f10; --warn-ink: #f3d98a;
}
}
* { box-sizing: border-box; }
body {
margin: 0; background: var(--bg); color: var(--ink);
font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 720px; margin: 0 auto; padding: 48px 20px 64px; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.01em; }
.lede { color: var(--muted); margin: 0 0 28px; }
.meta { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); margin-bottom: 20px; }
.board {
background: var(--card); border: 1px solid var(--line); border-radius: 12px;
padding: 18px 20px; margin-bottom: 14px;
display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.board h2 { font-size: 1.05rem; margin: 0 0 2px; }
.board p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.board code { font-size: 0.82rem; }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px;
border: 1px solid var(--line); color: var(--muted); margin-left: 6px; vertical-align: 2px; }
button[slot="activate"] {
font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 8px;
padding: 10px 18px; background: var(--accent); color: var(--accent-ink);
}
button[slot="activate"]:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 12px 16px; margin: 0 0 20px; }
.steps { padding-left: 20px; color: var(--muted); }
.steps li { margin-bottom: 6px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
a { color: var(--accent); }
footer { margin-top: 36px; color: var(--muted); font-size: 0.9rem; }
</style>
<script type="module" src="https://unpkg.com/esp-web-tools@10/dist/web/install-button.js?module"></script>
</head>
<body>
<main>
<h1>Flash the firmware from your browser</h1>
<p class="lede">Plug the board in over USB, pick it below, and choose its serial port when the browser asks. Nothing to install.</p>

<p class="note" id="unsupported" hidden>
This browser cannot talk to serial devices. Use Chrome or Edge on a desktop computer,
or flash from a terminal with <code>nav flash</code>.
</p>

<div class="meta" id="meta">Loading firmware list…</div>
<div id="boards"></div>

<ol class="steps">
<li>If no port appears, the board's USB chip needs a driver (CP210x or CH340), or the cable is charge-only.</li>
<li>If flashing does not start, hold the board's BOOT button while it connects.</li>
<li>Flashing replaces whatever firmware is on the board.</li>
</ol>

<footer>
Prefer a terminal? <code>nav flash</code> from
<a href="https://github.com/multi-sensor-navigation-system/data-pipeline">navkit</a>
detects the board, verifies the download and flashes it.
Source: <a href="https://github.com/multi-sensor-navigation-system/firmware">firmware</a>.
</footer>
</main>

<script>
if (!("serial" in navigator)) document.getElementById("unsupported").hidden = false;

function el(tag, text, cls) {
const node = document.createElement(tag);
if (text) node.textContent = text;
if (cls) node.className = cls;
return node;
}

fetch("manifest.json")
.then((r) => { if (!r.ok) throw new Error("HTTP " + r.status); return r.json(); })
.then((m) => {
document.getElementById("meta").textContent =
"Firmware " + m.version + " · build " + m.git + " · wire protocol v" + m.proto;
const list = document.getElementById("boards");
// Boards that have run on hardware first.
const entries = Object.entries(m.boards).sort(
(a, b) => (a[1].status === "tested" ? 0 : 1) - (b[1].status === "tested" ? 0 : 1));
for (const [id, b] of entries) {
const card = el("div", null, "board");
const info = el("div");
const title = el("h2", b.name);
if (b.status && b.status !== "tested") title.appendChild(el("span", b.status, "tag"));
info.appendChild(title);
const line = el("p");
line.appendChild(el("code", id));
line.appendChild(document.createTextNode(" · " + (b.size / 1024).toFixed(0) + " kB"));
info.appendChild(line);
card.appendChild(info);

const install = document.createElement("esp-web-install-button");
install.setAttribute("manifest", "web/" + id + ".json");
const button = el("button", "Flash");
button.setAttribute("slot", "activate");
install.appendChild(button);
card.appendChild(install);
list.appendChild(card);
}
})
.catch((e) => {
document.getElementById("meta").textContent = "Could not load the firmware list (" + e.message + ").";
});
</script>
</body>
</html>
Loading