From 502b2c28c14ab2bff31eb4f0777fdfd0efcf8bea Mon Sep 17 00:00:00 2001 From: Charles Vestal Date: Thu, 5 Nov 2026 19:59:57 +0100 Subject: [PATCH] M-UPGRADE 3.11 finds X0X again: ota.c answers its handshake with the identity's name, '_' and three digits, and the installers ask for the whole identity with the handshake's body 01 M-VAVE's M-UPGRADE 3.11.0318 (built 2026-11-03) checks the identity a device answers to its 0x11 handshake against [^_\t\r\n]+_[0-9]{1,3} and refuses a longer one ("Invalid device identity", then "A USB MIDI device is present but did not answer"). Every X0X release is FM-1_9 + XXYYZZ (1.2.0: FM-1_9010200), so M-UPGRADE found none of them, and nobody could go back to the stock firmware with it. firmware/src/ota.c, as felucca-bsp's chip/ota.c (41a6e86): ota_reply_identity(full) cuts the plain answer ("FM-1_9010200" -> "FM-1_901"; three digits or fewer stay) and ota_hs tells the plain query from the one with the one-byte body 01, which gets the whole identity; ota_read answers both between reads as ota_service does. The update loader (FELUCCA_LOADER) answers the plain query only, with its whole identity ("ota-FM-1_900" passes). tools/fm1_install.py, web/fm1ota.js, web/backup/index.html, as fm1-base's (3c4a57e): HS_FULL; the handshake asks with it when the plain answer is NAME_ and three digits (not a loader), and keeps the plain answer when nothing answers in 0.6 s (M-VAVE's firmware, older builds), so the check after an install and the backup page's X0X check still see the whole identity. The identity's text is read up to its first zero (felucca-bsp#29 puts the flash's JEDEC id in bytes 24..26). The installer page, the landing page and the manual: M-UPGRADE 3.11 finds this version, not older ones (docs/manual.html regenerated, with the PING WIDTH sentence it lacked). Tests: tests/ota_hs_test.c (felucca-bsp's tests/ota_test.c: a release's identity, a dev build's, the loader; run_tests.sh's ota-hs-*), ota_test.c (a release's identity: FM-1_901 to the plain query, the whole to 01), install_test.py, tests/host/installer_hs_test.mjs (fm1-base's: the web handshake against releases and dev builds with and without the fix, M-VAVE's firmware, the loader, #29's bytes), backup_page_test.mjs, x0x_backup_test.py's delays. LICENSING.md: the two test files, MPL-2.0. The scheme is PERF-1's (deamonSLINKY/PERF-1 775106b), so its installers and ours read each other's firmwares. --- LICENSING.md | 1 + docs/MANUAL.md | 2 + docs/manual.html | 4 +- firmware/src/ota.c | 51 ++++++++-- tests/host/backup_page_test.mjs | 23 ++++- tests/host/installer_hs_test.mjs | 67 +++++++++++++ tests/install_test.py | 49 +++++++-- tests/ota_hs_test.c | 165 +++++++++++++++++++++++++++++++ tests/ota_test.c | 16 ++- tests/run_tests.sh | 9 ++ tests/x0x_backup_test.py | 2 +- tools/fm1_install.py | 44 ++++++--- tools/make_pages.py | 3 +- web/backup/index.html | 37 ++++--- web/fm1ota.js | 37 +++++-- web/x0x_installer.html | 4 +- 16 files changed, 457 insertions(+), 57 deletions(-) create mode 100644 tests/host/installer_hs_test.mjs create mode 100644 tests/ota_hs_test.c diff --git a/LICENSING.md b/LICENSING.md index 5ac7d6a..6872172 100644 --- a/LICENSING.md +++ b/LICENSING.md @@ -22,6 +22,7 @@ recipients its complete corresponding source under the same licence. | The idea of a browser emulator for FM-1 firmware (`web/emu/`) | [Groove OS](https://www.groove-os.com/) by Peter Gombos, whose site runs its firmware in the browser; no code from it | credit only | | The screen reader's firmware side: `firmware/src/announce.c`, `tools/gen_words.py` | [fm1-base](https://github.com/charlesvestal/fm1-base) (`device/announce.c`, `tools/gen_words.py`), Copyright (C) 2026 Charles Vestal, copied by [fm1-reader](https://github.com/charlesvestal/fm1-reader)'s `tools/sync_announce.sh` | MPL-2.0 (compatible with the GPL: MPL-2.0 section 3.3) | | The flash parts the storage may use: `firmware/hal/fm1_flash_ok.h`, `tests/host/flash_ok_test.c` | [fm1-base](https://github.com/charlesvestal/fm1-base) (`device/fm1_flash_ok.h`, `tests/flash_ok_test.c`, fm1-base#35), Copyright (C) 2026 Laurens (@profikid) | MPL-2.0 (compatible with the GPL: MPL-2.0 section 3.3) | +| The update handshake's tests: `tests/ota_hs_test.c`, `tests/host/installer_hs_test.mjs` | [felucca-bsp](https://github.com/hugelton/felucca-bsp)'s `tests/ota_test.c` and [fm1-base](https://github.com/charlesvestal/fm1-base)'s `tests/installer_hs_test.mjs`, Copyright (C) 2026 Charles Vestal | MPL-2.0 (compatible with the GPL: MPL-2.0 section 3.3) | | Everything else in `firmware/src/{app,dsp,seq}`, `host/`, `tests/` | X0X | GPL-3.0-only | No recorded breaks are in this tree or in the default firmware: the built-in break loops are diff --git a/docs/MANUAL.md b/docs/MANUAL.md index 9b20682..270bac5 100644 --- a/docs/MANUAL.md +++ b/docs/MANUAL.md @@ -51,6 +51,8 @@ to X0X starts with an empty project. To keep it, save it to a file first (see **Go back:** "Back to the stock firmware", at the bottom of the same page, puts M-VAVE's firmware back (download the FM-1 file from the link there, choose it, press the button; if the FM-1 doesn't take it, use the V15 file from the second link). M-VAVE's own updater, M-UPGRADE, works too. +M-UPGRADE 3.11 finds this version of X0X, not older ones (it says "A USB MIDI device is present but did +not answer"): use the button for those. > Installing other firmware is at your own risk. If the FM-1 ever won't start, see > [Recovering an FM-1 that won't start](#recovering-an-fm-1-that-won-t-start). diff --git a/docs/manual.html b/docs/manual.html index 45d8592..16c7bd1 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -101,7 +101,7 @@ nav.contents li { break-inside: avoid; }

Try it first: the X0X emulator runs the same code in the browser, with sound, played with the mouse, a touch screen or the keyboard.

Install: open the web installer in Chrome or Edge, connect the FM-1 with a USB data cable and press Install. Don't unplug it while it's writing; when it finishes, the FM-1 restarts into X0X.

Update: the same way. An update keeps your project: the patterns, sounds, song and settings. Installing another firmware does not: it keeps its own things in the same memory, so coming back to X0X starts with an empty project. To keep it, save it to a file first (see Back up your project).

-

Go back: "Back to the stock firmware", at the bottom of the same page, puts M-VAVE's firmware back (download the FM-1 file from the link there, choose it, press the button; if the FM-1 doesn't take it, use the V15 file from the second link). M-VAVE's own updater, M-UPGRADE, works too.

+

Go back: "Back to the stock firmware", at the bottom of the same page, puts M-VAVE's firmware back (download the FM-1 file from the link there, choose it, press the button; if the FM-1 doesn't take it, use the V15 file from the second link). M-VAVE's own updater, M-UPGRADE, works too. M-UPGRADE 3.11 finds this version of X0X, not older ones (it says "A USB MIDI device is present but did not answer"): use the button for those.

Installing other firmware is at your own risk. If the FM-1 ever won't start, see Recovering an FM-1 that won't start.

Install from the command line

Download the firmware file (for example x0x-1.0.fwsc) from the releases page, get the X0X source from GitHub, install Python 3 with pip3 install mido python-rtmidi, and run:

@@ -235,7 +235,7 @@ nav.contents li { break-inside: avoid; }
The FX screen: REVERB and DELAY sends for 909, 808, 303A, 303B and BRK as bars; DELAY 1/8. TAPE, FEEDBACK 40%, REVERB 57. The REVERB knobs: DECAY 73, TONE 57.
FX

There is one reverb and one delay, and every part can send to both: each part's sends are on the mixer's PARTS page (LFO), each drum track's on 909 MIX and 808 MIX. FX shows how much every part sends, and has two pages:

-

In SEL's list, under MORE: each effect's low cut and return level, and PING WIDTH, which bounces the echoes between left and right: 0 is off, 127 puts them hard left and right, and between, closer together.

+

In SEL's list, under MORE: each effect's low cut and return level, and PING WIDTH, which bounces the echoes between left and right: 0 is off, 127 puts them hard left and right, and between, closer together. A new project starts at 20, a narrow bounce.


14Mix and master

The MIX screen with the compressor pumping: the output's waveform, a gain reduction meter (GR), COMP -14dB, PUMP 11.5dB, AUDIO LOAD 0%. The MASTER knobs: DRIVE 41, COMP 78%, PUMP 11.5 dB, FILTER OFF.
MIX, with the compressor pumping
diff --git a/firmware/src/ota.c b/firmware/src/ota.c index f03b453..c63f637 100644 --- a/firmware/src/ota.c +++ b/firmware/src/ota.c @@ -3,7 +3,15 @@ /* M-UPGRADE update entry. * * The updater talks SysEx (F0 pack7(00 59 cmd len24 body chk) F7): - * cmd 0x11 handshake -> we answer our package identity (FELUCCA_ID) + * cmd 0x11 handshake -> we answer our package identity (FELUCCA_ID), 27 bytes, the text then zeros: to the + * plain query (no body: M-UPGRADE's) its name, '_' and the first three digits only ("FM-1_9010200" + * -> "FM-1_901"), because M-UPGRADE 3.11 takes NAME_ and 1-3 digits and refuses the rest ("Invalid + * device identity"); to the query with the one-byte body 01 the whole identity, version included + * (the installers ask so when the plain answer is NAME_ and three digits; the stock firmware, the + * update loader and builds before this don't answer it, so they keep the plain answer). The scheme + * is PERF-1's (deamonSLINKY/PERF-1 775106b), as felucca-bsp's chip/ota.c (41a6e86). The update + * loader (FELUCCA_LOADER) answers the plain query only, with its whole identity ("ota-FM-1_900" + * passes M-UPGRADE 3.11). A host reads the text up to its first zero * F0 22 24 35 7F F7 upgrade -> ota_session(): pull parts of the package * with cmd 0x30 read requests, check them, stage the package's update * loader at 0xE0000 (outside Felucca's store), ask 0xE0000000 ("success"), @@ -125,13 +133,24 @@ static int ota_send_msg(uint32_t cmd, const uint8_t *body, uint32_t n) /* n <= return ota_wire_send(ota_wire, w); } -static void ota_reply_identity(void) +/* full 0: the name, '_' and three digits (M-UPGRADE 3.11's limit); 1: the whole identity. The loader's is whole */ +static void ota_reply_identity(int full) { static const char ID[] = FELUCCA_ID; /* == the package marker string */ uint8_t id[27]; - uint32_t i; + uint32_t i, n = sizeof ID - 1u; +#ifndef FELUCCA_LOADER + if (!full) { + for (i = 0; i < n && ID[i] != '_'; i++) + ; + if (i + 4u < n) + n = i + 4u; /* "FM-1_9010200" -> "FM-1_901"; "FM-1_900" stays */ + } +#else + (void)full; +#endif for (i = 0; i < sizeof id; i++) - id[i] = i < sizeof ID - 1u ? (uint8_t)ID[i] : 0; + id[i] = i < n ? (uint8_t)ID[i] : 0; ota_send_msg(0x11, id, sizeof id); } @@ -153,13 +172,29 @@ static uint32_t ota_take(void) return d; } +/* the decoded frame (d: its length) a handshake? 1 the plain query, 2 the one with the body 01 (not the loader's), + * 0 neither */ +static int ota_hs(uint32_t d) +{ + if (d < 7u || ota_dec[2] != 0x11) + return 0; + if (d == 7u) + return 1; +#ifndef FELUCCA_LOADER + if (d == 8u && ota_dec[6] == 1u) + return 2; +#endif + return 0; +} + /* main loop, outside a session: answer handshakes. Returns the frame's decoded length (0: none), the frame in * ota_dec, for the app's own commands (X0X: backup.c's 0x41 / 0x42) */ static uint32_t ota_service(void) { uint32_t d = ota_take(); - if (d == 7u && ota_dec[2] == 0x11) - ota_reply_identity(); + int hs = ota_hs(d); + if (hs) + ota_reply_identity(hs == 2); return d; } @@ -186,8 +221,8 @@ static int ota_read(uint32_t addr, uint8_t *dst, uint32_t len) d = ota_take(); if (!d) continue; - if (d == 7u && ota_dec[2] == 0x11) { - ota_reply_identity(); + if (ota_hs(d)) { + ota_reply_identity(ota_hs(d) == 2); continue; } if (d == len + 15u && ota_dec[2] == 0x30 && ota_rd24(ota_dec + 3) == len + 8u && diff --git a/tests/host/backup_page_test.mjs b/tests/host/backup_page_test.mjs index 5e58dac..ea26d00 100644 --- a/tests/host/backup_page_test.mjs +++ b/tests/host/backup_page_test.mjs @@ -18,7 +18,7 @@ const html = fs.readFileSync(path.join(root, "web/backup/index.html"), "utf8"); const m = /\/\/ --- backup protocol: begin[^\n]*\n([\s\S]*?)\/\/ --- backup protocol: end/.exec(html); if (!m) { console.log("FAIL no backup protocol markers in web/backup/index.html"); process.exit(1); } const PB = new Function(`"use strict";\n${m[1]}\nreturn PB;`)(); -Object.assign(PB.DELAY, { poll: 5, idle: 300, ask: 500, first: 300, hs: 100 }); +Object.assign(PB.DELAY, { poll: 5, idle: 300, ask: 500, first: 300, hs: 100, hsFull: 100 }); let fails = 0; const check = (ok, msg) => { console.log(`${ok ? "ok " : "FAIL"} ${msg}`); if (!ok) fails++; }; @@ -130,9 +130,19 @@ class FakeX0X { this.ask(...r.value); } rx(d) { + // newOta: ota.c from M-UPGRADE 3.11's fix on, NAME_ and three digits to HS_QUERY, the whole to HS_FULL + const reply = (text) => { + const t = [...Buffer.from(text), ...new Array(27 - text.length).fill(0)]; + t[24] = 0xB3, t[25] = 0x60, t[26] = 0x14; // felucca-bsp#29: the flash's JEDEC id after the text + this.q.push([0xF0, ...PB.pack7([0, 0x59, 0x11, 27, 0, 0, ...t, ~t.reduce((a, v) => a + v, 0) & 255]), 0xF7]); + }; if (same(d, PB.HS_QUERY)) { - const t = [...Buffer.from(this.identity)]; - this.q.push([0xF0, ...PB.pack7([0, 0x59, 0x11, 0, 0, 0, ...t, ...new Array(28 - t.length).fill(0)]), 0xF7]); + reply(this.newOta ? this.identity.slice(0, this.identity.indexOf("_") + 4) : this.identity); + return; + } + if (same(d, PB.HS_FULL)) { + this.hsFull = (this.hsFull || 0) + 1; + if (this.newOta) reply(this.identity); return; } const f = PB.parseFrame(d); @@ -207,6 +217,13 @@ check(PB.VERSION === 1 && (img[4] | img[5] << 8) === 1, "the device's backups: v const e = await err(connect(dev)); check(e && e.code === "model" && /not X0X/.test(e.message), "not X0X (Polly's identity): refused"); } +{ + const dev = new FakeX0X(img, { identity: "FM-1_9010200", newOta: true }); + const c = await connect(dev); + check(c && c.id === "FM-1_9010200" && dev.hsFull === 1, + "an X0X that answers FM-1_901 to the plain query (M-UPGRADE 3.11): its whole identity asked with 01"); + c.link.close(); +} { const dev = new FakeX0X(other, { stallAfter: 5 }); const e = await err(PB.restore((await connect(dev)).link, img)); diff --git a/tests/host/installer_hs_test.mjs b/tests/host/installer_hs_test.mjs new file mode 100644 index 0000000..a29250c --- /dev/null +++ b/tests/host/installer_hs_test.mjs @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright (C) 2026 Charles Vestal +// From fm1-base's tests/installer_hs_test.mjs (3c4a57e). +// The web installer's handshake (web/fm1ota.js) against fake FM-1s: what each firmware answers. A firmware on +// firmware/src/ota.c from M-UPGRADE 3.11's fix on answers the plain query with its name, '_' and three digits +// ("FM-1_901": M-UPGRADE 3.11 takes NAME_ and 1-3 digits only) and its whole identity to the query with the body 01 +// (PERF-1's scheme, deamonSLINKY/PERF-1 775106b); the installer has to see the whole one, and every other firmware as +// before. +import { Updater, HS_FULL, pack7, unpack7 } from "../../web/fm1ota.js"; + +const HS_QUERY = [0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7]; +const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]); +// an identity reply: the text, zeros, felucca-bsp#29's flash JEDEC id in bytes 24..26 (jedec), the checksum +const idPkt = (text, jedec) => { + const t = [...text].map((c) => c.charCodeAt(0)).concat(new Array(27 - text.length).fill(0)); + if (jedec) t[24] = 0xB3, t[25] = 0x60, t[26] = 0x14; + return [0xF0, ...pack7([0, 0x59, 0x11, 27, 0, 0, ...t, ~t.reduce((a, v) => a + v, 0) & 0xFF]), 0xF7]; +}; + +// one port called FM-1: answer(query) -> the identity text to send back, or null +function access(answer, jedec) { + const input = { name: "FM-1", state: "connected", onmidimessage: null, open: async () => {} }; + const output = { + name: "FM-1", state: "connected", open: async () => {}, sent: [], + send(b) { + this.sent.push(Array.from(b)); + const t = answer(Array.from(b)); + if (t !== null) setTimeout(() => input.onmidimessage && input.onmidimessage({ data: idPkt(t, jedec) }), 5); + }, + }; + return { inputs: new Map([[1, input]]), outputs: new Map([[1, output]]), output }; +} + +let bad = 0; +function check(what, cond) { console.log((cond ? "ok " : "FAIL ") + what); if (!cond) bad++; } + +const cut = (t) => t.slice(0, t.indexOf("_") + 4); +const fixed = (t) => (q) => same(q, HS_QUERY) ? cut(t) : same(q, HS_FULL) ? t : null; // chip/ota.c with the fix +const before = (t) => (q) => same(q, HS_QUERY) ? t : null; // everything else +const cases = [ + ["a release with the fix: FM-1_901, then its whole identity", fixed("FM-1_9010200"), "FM-1_9010200", true, true], + ["a release before it: its whole identity to the plain query", before("FM-1_9010200"), "FM-1_9010200", false, false], + ["a dev build with the fix: FM-1_900", fixed("FM-1_900"), "FM-1_900", true, false], + ["a dev build before it: FM-1_900, no answer to 01", before("FM-1_900"), "FM-1_900", true, false], + ["M-VAVE's firmware: FM-1_015, no answer to 01", before("FM-1_015"), "FM-1_015", true, false], + ["the update loader: ota-FM-1_900, never asked with 01", before("ota-FM-1_900"), "ota-FM-1_900", false, false], +]; +for (const [what, answer, want, asksFull, jedec] of cases) { + const a = access(answer, jedec); + const dev = await new Updater(a).find(); + if (dev) dev.link.close(); + check(`${what}: ${want}`, dev && dev.id.text === want); + check(` ${asksFull ? "asked with 01" : "never asked with 01"}`, a.output.sent.some((q) => same(q, HS_FULL)) === asksFull); +} +{ + const a = access(fixed("FM-1_9010200"), true); + const dev = await new Updater(a).find(); + if (dev) dev.link.close(); + check("felucca-bsp#29's bytes after the text: the text up to its first zero", dev && dev.id.text === "FM-1_9010200" && + dev.id.model === "FM-1" && dev.id.version === 9010200); +} +// the bytes of the query with 01, as chip/ota.c checks them (ota_take: header, length, checksum) +check("HS_FULL is 00 59 11, length 1, body 01, checksum FE", + same(HS_FULL, [0xF0, ...pack7([0, 0x59, 0x11, 1, 0, 0, 1, 0xFE]), 0xF7]) && + same(unpack7(HS_FULL.slice(1, -1)).slice(0, 8), [0, 0x59, 0x11, 1, 0, 0, 1, 0xFE])); +if (bad) { console.log(`${bad} FAILED`); process.exit(1); } +console.log("installer handshake tests passed"); diff --git a/tests/install_test.py b/tests/install_test.py index 086afa0..a0908ce 100755 --- a/tests/install_test.py +++ b/tests/install_test.py @@ -21,7 +21,7 @@ ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "tools")) import fm1_install as I # noqa: E402 -I.DELAY.update(open=0, start=0.01, reply=0, loader=0.01, reboot=0.01, retry=0.02, poll=0.05, hs=0.1, +I.DELAY.update(open=0, start=0.01, reply=0, loader=0.01, reboot=0.01, retry=0.02, poll=0.05, hs=0.1, hs_full=0.1, idle_check=0.4, idle_write=0.4, wait_loader=2, wait_reboot=2) failed = 0 @@ -67,10 +67,11 @@ class FakeFM1: """a MIDI backend with one FM-1 on it""" def __init__(self, image, identity="FM-1_015", name="FM-1", unplug_after=None, after_write="FM-1_900", - stall_after=None, bad_addr=None): + stall_after=None, bad_addr=None, new_ota=(), jedec=0): self.image, self.unplug_after, self.after_write = image, unplug_after, after_write self.stall_after, self.bad_addr = stall_after, bad_addr - self.served = self.bad = self.upgrades = 0 + self.new_ota, self.jedec = set(new_ota), jedec # identities whose ota.c cuts the plain answer; bsp#29's bytes + self.served = self.bad = self.upgrades = self.hs_full = 0 self.sent, self.links, self.gen, self.lock = [], [], 0, threading.Lock() self.boot(identity, name) @@ -97,10 +98,19 @@ class FakeFM1: if link.gen == self.gen and not link.closed: link.q.put(bytes(pkt)) + def ident(self, text): + b = bytearray(text.encode() + bytes(27 - len(text))) + b[24:27] = self.jedec.to_bytes(3, "big") + self.tx(b"\xF0" + I.pack7(bytes([0, 0x59, 0x11, 27, 0, 0]) + b + bytes([~sum(b) & 0xFF])) + b"\xF7") + def rx(self, d): + new = self.identity in self.new_ota # ota.c from M-UPGRADE 3.11's fix on: NAME_ + 3 digits to HS_QUERY if d == I.HS_QUERY: - t = self.identity.encode() - self.tx(b"\xF0" + I.pack7(bytes([0, 0x59, 0x11, 0, 0, 0]) + t + bytes(28 - len(t))) + b"\xF7") + self.ident(self.identity[:self.identity.index("_") + 4] if new else self.identity) + elif d == I.HS_FULL: + self.hs_full += 1 + if new: + self.ident(self.identity) elif d == I.UPGRADE: self.upgrades += 1 first = self.bad_addr if self.bad_addr is not None else 0 @@ -178,6 +188,13 @@ def wire(): and ~sum(u[6:17]) & 0xFF == u[17], "response: header, address, data, checksum") raw = package("FM-1_906") ok(I.product_of(raw) == "FM-1_906" and len(I.logical_image(raw)) == len(raw) - 20, "product_of / logical_image (synthetic)") + ok(I.HS_FULL == b"\xF0" + I.pack7(bytes([0, 0x59, 0x11, 1, 0, 0, 1, 0xFE])) + b"\xF7" + and I.unpack7(I.HS_FULL[1:-1])[:8] == bytes([0, 0x59, 0x11, 1, 0, 0, 1, 0xFE]), + "HS_FULL: 00 59 11, length 1, body 01, checksum FE") + b = bytearray(b"FM-1_9010200" + bytes(15)) + b[24:27] = b"\xB3\x60\x14" # felucca-bsp#29: the flash's JEDEC id after the text + i = I.parse_identity(b"\xF0" + I.pack7(bytes([0, 0x59, 0x11, 27, 0, 0]) + b + bytes([~sum(b) & 0xFF])) + b"\xF7") + ok(i and i.text == "FM-1_9010200" and i.version == 9010200, "parse_identity: the text up to its first zero (#29's bytes after it)") raw = package("FM-1_9001000") # X0X from 0.10: major, minor, patch, two digits each ok(I.product_of(raw) == "FM-1_9001000", "product_of: a 12-character identity") @@ -212,7 +229,27 @@ def installs(): dev = FakeFM1(image, identity="ota-FM-1_900", name="Felucca Update") rc, out, err = cli(["--info"], dev) - ok(rc == 0 and "update loader" in out, "--info: device in update mode") + ok(rc == 0 and "update loader" in out and dev.hs_full == 0, "--info: device in update mode (never asked with 01)") + + # M-UPGRADE 3.11 takes NAME_ and 1-3 digits: ota.c answers HS_QUERY with FM-1_901, HS_FULL with the whole + rawl = package("FM-1_9010201") + dev = FakeFM1(I.logical_image(rawl), identity="FM-1_9010200", name="FM-1", after_write="FM-1_9010201", + new_ota={"FM-1_9010200", "FM-1_9010201"}, jedec=0xB36014) + rc, out, err = cli([pkgfile("long.fwsc", rawl), "--yes"], dev) + ok(rc == 0 and dev.bad == 0 and "device: FM-1_9010200" in out and "done: the FM-1 runs FM-1_9010201" in out, + "install: FM-1_901 to the plain query, the whole identity to HS_FULL") + rawl = package("FM-1_9010200") + dev = FakeFM1(I.logical_image(rawl), identity="FM-1_9010100", name="FM-1", after_write="FM-1_9010200", + new_ota={"FM-1_9010200"}) + rc, out, err = cli([pkgfile("long.fwsc", rawl), "--yes"], dev) + ok(rc == 0 and dev.bad == 0 and "done: the FM-1 runs FM-1_9010200" in out, + "install: from a build before it (whole identity to the plain query) to one after") + dev = FakeFM1(image, identity="FM-1_900", name="FM-1", new_ota={"FM-1_900"}) + rc, out, err = cli(["--info"], dev) + ok(rc == 0 and "FM-1_900" in out and dev.hs_full == 1, "--info: a dev build's FM-1_900: its whole identity") + dev = FakeFM1(image, identity="FM-1_015", name="FM-1") + rc, out, err = cli(["--info"], dev) + ok(rc == 0 and "FM-1_015" in out and dev.hs_full == 1, "--info: M-VAVE's firmware doesn't answer HS_FULL: its plain answer") def errors(): diff --git a/tests/ota_hs_test.c b/tests/ota_hs_test.c new file mode 100644 index 0000000..c45ce14 --- /dev/null +++ b/tests/ota_hs_test.c @@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: MPL-2.0 + * Copyright (C) 2026 Charles Vestal */ +/* firmware/src/ota.c's handshake (cmd 0x11) on the host, its hooks a fake wire: the plain query (no body, + * M-UPGRADE's) gets the identity cut to its name, '_' and three digits (M-UPGRADE 3.11 refuses more), the query with + * the body 01 the whole identity, any other body nothing; the same during a session (ota_read answers a handshake + * between reads). + * The update loader (-DFELUCCA_LOADER) answers the plain query with its whole identity and not the one with 01. + * The scheme is PERF-1's (deamonSLINKY/PERF-1 775106b). From felucca-bsp's tests/ota_test.c (41a6e86). Not the + * session: tests/ota_test.c serves it a real package. + * + * cc -std=c11 -O1 -Wall -Wextra -Werror -Wno-unused-function [-DTEST_ID='"FM-1_600"'] [-DFELUCCA_LOADER=1] + * tests/ota_hs_test.c -o ota_hs_test && ./ota_hs_test */ +#include +#include +#include + +#ifndef TEST_ID +#ifdef FELUCCA_LOADER +#define TEST_ID "ota-FM-1_900" +#else +#define TEST_ID "FM-1_9010200" /* a release's: FM-1_9 and XXYYZZ (X0X 1.2.0) */ +#endif +#endif +#define FELUCCA_ID TEST_ID +#define FELUCCA_OTA_DRYRUN 1 + +static uint8_t rx[64]; /* one pending host frame (7-bit bytes) */ +static uint32_t rx_len, rx_full; +static uint8_t tx[8][64]; /* what the device sent, decoded */ +static uint32_t tx_len[8], tx_n; +static uint32_t now_ms; + +static void host_send(const uint8_t *body, uint32_t n) /* the host's 0x11 with this body (n bytes) */ +{ + uint8_t m[16]; + uint32_t i, s = 0, acc = 0, nb = 0; + m[0] = 0, m[1] = 0x59, m[2] = 0x11, m[3] = (uint8_t)n, m[4] = 0, m[5] = 0; + for (i = 0; i < n; i++) + s += m[6 + i] = body[i]; + m[6 + n] = (uint8_t)~s; + rx_len = 0; + for (i = 0; i < 7u + n; i++) { /* pack7, LSB first */ + acc |= (uint32_t)m[i] << nb; + for (nb += 8u; nb >= 7u; nb -= 7u, acc >>= 7) + rx[rx_len++] = (uint8_t)(acc & 0x7Fu); + } + if (nb) + rx[rx_len++] = (uint8_t)(acc & 0x7Fu); + rx_full = 1; +} + +static int ota_wire_send(const uint8_t *p, uint32_t n) +{ + uint32_t acc = 0, nb = 0, o = 0, i; + if (tx_n < 8u) { + for (i = 1; i + 1u < n; i++) { /* unpack7 between F0 and F7 */ + acc |= (uint32_t)(p[i] & 0x7Fu) << nb; + nb += 7u; + if (nb >= 8u) { + if (o < sizeof tx[0]) + tx[tx_n][o] = (uint8_t)acc; + o++; + acc >>= 8; + nb -= 8u; + } + } + tx_len[tx_n++] = o; + } + return 0; +} +static int ota_frame_get(const uint8_t **p, uint32_t *n) +{ + if (!rx_full) + return 0; + *p = rx; + *n = rx_len; + return 1; +} +static void ota_frame_done(void) { rx_full = 0; } +static uint32_t ota_now_ms(void) { return now_ms += 100u; } +static void ota_idle(void) {} +static int ota_erase(uint32_t off) { (void)off; return 0; } +static int ota_prog(uint32_t off, const void *p, uint32_t n) { (void)off, (void)p, (void)n; return 0; } +static int ota_fread(uint32_t off, void *p, uint32_t n) { (void)off; memset(p, 0xFF, n); return 0; } +static void ota_show(uint32_t step, int32_t code) { (void)step, (void)code; } +static void ota_commit(const uint8_t *parm) { (void)parm; } + +#include "../firmware/src/ota.c" + +static int fails; +static void want(const char *what, int ok) +{ + printf(" %s %s\n", ok ? "ok " : "FAIL", what); + fails += !ok; +} + +/* the k-th reply an identity frame (34 bytes: 00 59 11, length 27, the text, zeros, checksum) holding text */ +static int ident_is(uint32_t k, const char *text) +{ + const uint8_t *m = tx[k]; + uint32_t i, s = 0, n = (uint32_t)strlen(text); + if (k >= tx_n || tx_len[k] != 34u || m[0] != 0 || m[1] != 0x59 || m[2] != 0x11 || m[3] != 27u) + return 0; + for (i = 0; i < 27u; i++) + s += m[6 + i]; + return (uint8_t)~s == m[33] && !memcmp(m + 6, text, n) && !m[6 + n] && m[6 + 26] == 0; +} + +int main(void) +{ + static const uint8_t one[1] = {1}, two[1] = {2}, onetwo[2] = {1, 2}; + char cut[16]; +#ifdef FELUCCA_LOADER + snprintf(cut, sizeof cut, "%s", TEST_ID); +#else + snprintf(cut, sizeof cut, "%.*s", (int)(strchr(TEST_ID, '_') - TEST_ID) + 4, TEST_ID); +#endif + printf("identity %s, to the plain query %s\n", TEST_ID, cut); + + tx_n = 0; + host_send(NULL, 0); + want("ota_service: the plain query answered with the cut identity", ota_service() == 7u && tx_n == 1u && + ident_is(0, cut)); + want("the cut identity is NAME_ and 1-3 digits (M-UPGRADE 3.11)", + strlen(strchr(cut, '_') + 1) >= 1u && strlen(strchr(cut, '_') + 1) <= 3u); + tx_n = 0; + host_send(one, 1); +#ifdef FELUCCA_LOADER + want("ota_service: the loader leaves the query with 01 alone", ota_service() == 8u && tx_n == 0u); +#else + want("ota_service: the query with 01 answered with the whole identity", ota_service() == 8u && tx_n == 1u && + ident_is(0, TEST_ID)); +#endif + tx_n = 0; + host_send(two, 1); + want("ota_service: body 02 not answered", ota_service() == 8u && tx_n == 0u); + host_send(onetwo, 2); + want("ota_service: body 01 02 not answered", ota_service() == 9u && tx_n == 0u); + + /* in a session: ota_read sends its read request, then a handshake comes in before the host's data */ + { + uint8_t b[8]; + tx_n = 0; + now_ms = 0; + host_send(one, 1); + want("ota_read gives up (no data), having answered the handshake as ota_service does", + ota_read(0, b, 8) == -1 && +#ifdef FELUCCA_LOADER + tx_n == 3u && tx[0][2] == 0x30 && tx[1][2] == 0x30 && tx[2][2] == 0x30 +#else + tx_n == 4u && tx[0][2] == 0x30 && ident_is(1, TEST_ID) && tx[2][2] == 0x30 +#endif + ); + tx_n = 0; + now_ms = 0; + host_send(NULL, 0); + want("ota_read: the plain query answered with the cut identity", + ota_read(0, b, 8) == -1 && tx_n == 4u && ident_is(1, cut)); + } + if (fails) + printf("%d FAILED\n", fails); + else + printf("ota tests passed\n"); + return fails != 0; +} diff --git a/tests/ota_test.c b/tests/ota_test.c index cc8d0c2..200653f 100644 --- a/tests/ota_test.c +++ b/tests/ota_test.c @@ -10,7 +10,7 @@ #include #include -#define FELUCCA_ID "FM-1_900" +#define FELUCCA_ID "FM-1_9010200" /* a release's: the plain handshake answers FM-1_901 */ #define FELUCCA_OTA_DRYRUN 0 static uint8_t nor[0x100000]; @@ -174,8 +174,18 @@ int main(int argc, char **argv) host_reply(m, 7); ota_service(); bad += check("handshake answered", ident_replies == 1); - bad += check("identity frame is " FELUCCA_ID, - ota_msg[2] == 0x11 && !memcmp(ota_msg + 6, FELUCCA_ID, sizeof FELUCCA_ID - 1)); + bad += check("plain query: FM-1_901 (M-UPGRADE 3.11: NAME_ + 1-3 digits)", + ota_msg[2] == 0x11 && !memcmp(ota_msg + 6, "FM-1_901", 8) && ota_msg[6 + 8] == 0); + } + reset_dev(); + { + uint8_t m[8] = {0, 0x59, 0x11, 1, 0, 0, 1, 0xFE}; /* body 01: the whole identity */ + host_reply(m, 8); + ota_service(); + bad += check("asked with 01: answered", ident_replies == 1); + bad += check("asked with 01: the whole identity " FELUCCA_ID, + ota_msg[2] == 0x11 && !memcmp(ota_msg + 6, FELUCCA_ID, sizeof FELUCCA_ID - 1) && + ota_msg[6 + sizeof FELUCCA_ID - 1] == 0); } /* full session */ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index d7deb2f..c5fc571 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -69,7 +69,16 @@ run x0x-backup python3 tests/x0x_backup_test.py $OUT/backup.x0b if command -v node >/dev/null 2>&1; then run backup-page sh -c "python3 tests/x0x_backup_record.py $OUT/backup.x0b $OUT/backup_transcript.json && \ node tests/host/backup_page_test.mjs $OUT/backup_transcript.json" + # the web installer's handshake (web/fm1ota.js): an X0X that answers M-UPGRADE 3.11's query short and its whole + # identity to the one with 01, older builds, M-VAVE's firmware, the loader + run installer-hs node tests/host/installer_hs_test.mjs fi +# the M-UPGRADE handshake (firmware/src/ota.c): a release's identity cut to NAME_ and three digits for the plain +# query (M-UPGRADE 3.11), the whole one for the query with body 01; a dev build's; the update loader's, whole +for m in long short loader; do + case $m in long) f="" ;; short) f="-DTEST_ID='\"FM-1_900\"'" ;; loader) f="-DFELUCCA_LOADER=1" ;; esac + run "ota-hs-$m" sh -c "$CC -std=c11 -O1 -Wall -Wextra -Werror -Wno-unused-function $f -o $OUT/ota_hs_$m tests/ota_hs_test.c && $OUT/ota_hs_$m" +done # the update path, against the firmware package (Felucca's tests; needs ./build.sh) if [ -f build/x0x.fwsc ]; then run ota-entry sh -c "$CC -o $OUT/ota_test tests/ota_test.c && $OUT/ota_test build/x0x.fwsc" diff --git a/tests/x0x_backup_test.py b/tests/x0x_backup_test.py index 536bf34..f8738b2 100644 --- a/tests/x0x_backup_test.py +++ b/tests/x0x_backup_test.py @@ -22,7 +22,7 @@ sys.path.insert(0, str(ROOT / "tools")) import fm1_install as I # noqa: E402 import x0x_backup as B # noqa: E402 -I.DELAY.update(open=0, hs=0.1, retry=0.02) +I.DELAY.update(open=0, hs=0.1, hs_full=0.1, retry=0.02) B.DELAY.update(poll=0.02, idle=0.3, ask=0.5, first=0.3) failed = 0 diff --git a/tools/fm1_install.py b/tools/fm1_install.py index 21c0791..a3430a7 100755 --- a/tools/fm1_install.py +++ b/tools/fm1_install.py @@ -26,6 +26,11 @@ import sys import time HS_QUERY = bytes([0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7]) +# the handshake with the one-byte body 01 (00 59 11, length 1, 01, checksum FE): firmware/src/ota.c answers HS_QUERY +# with its name, '_' and three digits only ("FM-1_901": M-UPGRADE 3.11 refuses more) and this one with its whole +# identity ("FM-1_9010200"). M-VAVE's firmware, the update loaders and older builds don't answer it. +# (PERF-1's scheme, as felucca-bsp's and fm1-base's: their installers and ours ask the same way) +HS_FULL = bytes([0xF0, 0x00, 0x32, 0x45, 0x08, 0x00, 0x00, 0x40, 0x00, 0x7E, 0x01, 0xF7]) UPGRADE = bytes([0xF0, 0x22, 0x24, 0x35, 0x7F, 0xF7]) FINISH_CHECK, FINISH_WRITE = 0xE0000000, 0xF0000000 MAXDATA = 512 @@ -35,7 +40,7 @@ PORT_RE = re.compile(r"fm-1|felucca|ota|composite|sinco|usb-midi", re.I) # nev # seconds; the tests shorten them DELAY = {"open": 0.3, "start": 2.0, "reply": 0.01, "loader": 3.0, "reboot": 3.0, "retry": 1.0, - "poll": 1.0, "hs": 1.0, "idle_check": 8.0, "idle_write": 180.0, + "poll": 1.0, "hs": 1.0, "hs_full": 0.6, "idle_check": 8.0, "idle_write": 180.0, "wait_loader": 30.0, "wait_reboot": 40.0} EXIT = {"usage": 2, "badpkg": 2, "notfound": 3, "model": 6, "lost": 4, "stopped": 4, "badreq": 4, @@ -109,7 +114,7 @@ def parse_identity(pkt): d = unpack7(pkt[1:-1]) if len(d) != 34 or d[:3] != b"\x00\x59\x11": return None - txt = d[6:33].rstrip(b"\0").decode("latin-1") + txt = d[6:33].split(b"\0", 1)[0].decode("latin-1") # the text up to its first zero (bytes after it may carry data) m = re.fullmatch(r"([^_]+)_(\d+)", txt) return Identity(txt, m[1], int(m[2])) if m else None @@ -217,19 +222,36 @@ class Device: self.link, self.id, self.name = link, ident, name +def ask(link, query, secs): + """send a handshake -> the identity answered, None (no answer in secs), False (the send failed)""" + if not link.send(query): + return False + end = time.monotonic() + secs + while (left := end - time.monotonic()) > 0: + p = link.read(left) + if p is None: + break + ident = parse_identity(p) + if ident: + return ident + return None + + def handshake(link, tries=3): + """the identity: HS_QUERY, then HS_FULL when the answer is NAME_ and three digits (a firmware on ota.c from + M-UPGRADE 3.11's fix on tells its whole identity so); the plain answer when nothing answers HS_FULL (M-VAVE's, + an older build)""" link.drain() for _ in range(tries): - if not link.send(HS_QUERY): + ident = ask(link, HS_QUERY, DELAY["hs"]) + if ident is False: return None - end = time.monotonic() + DELAY["hs"] - while (left := end - time.monotonic()) > 0: - p = link.read(left) - if p is None: - break - ident = parse_identity(p) - if ident: - return ident + if ident is None: + continue + if ident.loader or not re.fullmatch(r"[^_]+_\d{3}", ident.text): + return ident + full = ask(link, HS_FULL, DELAY["hs_full"]) + return full if full and full.model == ident.model and full.text.startswith(ident.text) else ident return None diff --git a/tools/make_pages.py b/tools/make_pages.py index 1270d55..71410e1 100644 --- a/tools/make_pages.py +++ b/tools/make_pages.py @@ -94,7 +94,8 @@ at your own risk. SourceGitHub, GPL-3.0. Built on Felucca by Hügelton Instruments.

To go back to the official firmware, use M-VAVE's updater, M-UPGRADE, from -m-vave.com/download. M-VAVE and FM-1 are trademarks of their owners.

+m-vave.com/download (M-UPGRADE 3.11 finds v__VERSION__, not older +versions; for those, use the installer's "Back to the stock firmware"). M-VAVE and FM-1 are trademarks of their owners.

diff --git a/web/backup/index.html b/web/backup/index.html index e3ebf8d..537bed6 100644 --- a/web/backup/index.html +++ b/web/backup/index.html @@ -96,13 +96,15 @@ // --- backup protocol: begin (tools/x0x_backup.py, firmware/src/backup.c; tested by tests/host/backup_page_test.mjs) const PB = (() => { const HS_QUERY = [0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7]; // fm1_install.py / fm1ota.js + // the one with the body 01: the whole identity (HS_QUERY gets NAME_ and three digits, M-UPGRADE 3.11's limit) + const HS_FULL = [0xF0, 0x00, 0x32, 0x45, 0x08, 0x00, 0x00, 0x40, 0x00, 0x7E, 0x01, 0xF7]; const RS_REQ = 0x41, BU_REQ = 0x42, BU_END = 0x43; const OK_ADDR = 0xC0000000, ASK_ADDR = 0xC1000000, FAIL_ADDR = 0xCF000000; const MAGIC = [0x58, 0x30, 0x58, 0x42], VERSION = 1, NOBJ = 6, HEAD = 16, REC = 8, PAYLOAD_MAX = 3840, MAXDATA = 512; // "X0XB" const OBJ_IDS = [0, 1, 2, 3, 5, 6]; // OBJ_SET, OBJ_SOUND, OBJ_PAT0, OBJ_PAT1, OBJ_SONG, OBJ_MOTION (not OBJ_PANEL) const PLAYING = 10, DECLINED = 11; const X0X = "FM-1_9"; // X0X's package identity - const DELAY = { poll: 500, idle: 10000, ask: 75000, first: 3000, hs: 1000 }; // ms, as x0x_backup.py + const DELAY = { poll: 500, idle: 10000, ask: 75000, first: 3000, hs: 1000, hsFull: 600 }; // ms, as x0x_backup.py const ERRORS = { 1: "the file's size", 2: "the transfer (a piece of the file did not arrive)", 3: "the file's head", 4: "a part's header", 5: "a part's check (a byte changed on the way)", 6: "the whole file's check", @@ -178,7 +180,8 @@ const PB = (() => { if (pkt.length < 2 || pkt[0] !== 0xF0 || pkt[pkt.length - 1] !== 0xF7) return null; const d = unpack7(pkt.slice(1, -1)); if (d.length !== 34 || d[0] !== 0 || d[1] !== 0x59 || d[2] !== 0x11) return null; - const txt = String.fromCharCode(...d.slice(6, 33)).replace(/\0+$/, ""); + const z = d.indexOf(0, 6); // the text up to its first zero (bytes after it may carry data) + const txt = String.fromCharCode(...d.slice(6, z < 0 || z > 33 ? 33 : z)); return /^[^_]+_\d+$/.test(txt) ? txt : null; } @@ -215,17 +218,29 @@ const PB = (() => { return `${parts.length ? parts.join(", ") : "an empty project"} (${total.toLocaleString("en")} bytes)`; } + // send a handshake -> the identity answered, null (no answer in ms), false (the send failed) + async function ask(link, query, ms) { + if (!link.send(query)) return false; + const end = Date.now() + ms; + while (Date.now() < end) { + const p = await link.read(end - Date.now()); + if (!p) break; + const id = parseIdentity(p); + if (id) return id; + } + return null; + } + // the identity (fm1ota.js handshake): HS_QUERY, then HS_FULL when the answer is NAME_ and three digits; the plain + // answer when nothing answers HS_FULL (M-VAVE's, an older build) async function handshake(link, tries = 2) { link.drain(); for (let t = 0; t < tries; t++) { - if (!link.send(HS_QUERY)) return null; - const end = Date.now() + DELAY.hs; - while (Date.now() < end) { - const p = await link.read(end - Date.now()); - if (!p) break; - const id = parseIdentity(p); - if (id) return id; - } + const id = await ask(link, HS_QUERY, DELAY.hs); + if (id === false) return null; + if (id === null) continue; + if (/^ota-/i.test(id) || !/^[^_]+_\d{3}$/.test(id)) return id; + const full = await ask(link, HS_FULL, DELAY.hsFull); + return full && full.split("_")[0] === id.split("_")[0] && full.startsWith(id) ? full : id; } return null; } @@ -320,7 +335,7 @@ const PB = (() => { } } - return { HS_QUERY, RS_REQ, BU_REQ, BU_END, OK_ADDR, ASK_ADDR, FAIL_ADDR, MAGIC, VERSION, NOBJ, PLAYING, DECLINED, X0X, DELAY, ERRORS, + return { HS_QUERY, HS_FULL, RS_REQ, BU_REQ, BU_END, OK_ADDR, ASK_ADDR, FAIL_ADDR, MAGIC, VERSION, NOBJ, PLAYING, DECLINED, X0X, DELAY, ERRORS, pack7, unpack7, crc32, frame, parseFrame, response, parseRequest, parseIdentity, parse, summary, find, backup, restore }; })(); // --- backup protocol: end diff --git a/web/fm1ota.js b/web/fm1ota.js index 3260605..8c59012 100644 --- a/web/fm1ota.js +++ b/web/fm1ota.js @@ -7,6 +7,11 @@ // the device sends cmd 0x30 read requests on the logical image and we answer. const HS_QUERY = [0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7]; +// the handshake with the one-byte body 01 (00 59 11, length 1, 01, checksum FE): firmware/src/ota.c answers HS_QUERY +// with its name, '_' and three digits only ("FM-1_901": M-UPGRADE 3.11 refuses more) and this one with its whole +// identity ("FM-1_9010200"). M-VAVE's firmware, the update loaders and older builds don't answer it. +// (PERF-1's scheme, as felucca-bsp's and fm1-base's: their installers and ours ask the same way) +export const HS_FULL = [0xF0, 0x00, 0x32, 0x45, 0x08, 0x00, 0x00, 0x40, 0x00, 0x7E, 0x01, 0xF7]; const UPGRADE = [0xF0, 0x22, 0x24, 0x35, 0x7F, 0xF7]; const MAXDATA = 512; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); @@ -59,7 +64,8 @@ function parseRequest(pkt) { function parseIdentity(pkt) { const d = unpack7(pkt.slice(1, -1)); if (d.length !== 34 || d[0] !== 0 || d[1] !== 0x59 || d[2] !== 0x11) return null; - const txt = String.fromCharCode(...d.slice(6, 33)).replace(/\0+$/, ""); + const z = d.indexOf(0, 6); // the text up to its first zero (bytes after it may carry data) + const txt = String.fromCharCode(...d.slice(6, z < 0 || z > 33 ? 33 : z)); const m = /^([^_]+)_(\d+)$/.exec(txt); return m ? { text: txt, model: m[1], version: parseInt(m[2], 10) } : null; } @@ -92,17 +98,30 @@ class Link { close() { this.input.onmidimessage = null; } } +// send a handshake -> the identity answered, null (no answer in ms), false (the send failed) +async function ask(link, query, ms) { + if (!link.send(query)) return false; + const end = Date.now() + ms; + while (Date.now() < end) { + const p = await link.read(end - Date.now()); + if (!p) break; + const id = parseIdentity(p); + if (id) return id; + } + return null; +} + +// the identity: HS_QUERY, then HS_FULL when the answer is NAME_ and three digits (a firmware on ota.c from M-UPGRADE +// 3.11's fix on tells its whole identity so); the plain answer when nothing answers HS_FULL (M-VAVE's, an older build) async function handshake(link, tries = 3) { link.drain(); for (let t = 0; t < tries; t++) { - if (!link.send(HS_QUERY)) return null; - const end = Date.now() + 1000; - while (Date.now() < end) { - const p = await link.read(end - Date.now()); - if (!p) break; - const id = parseIdentity(p); - if (id) return id; - } + const id = await ask(link, HS_QUERY, 1000); + if (id === false) return null; + if (id === null) continue; + if (IS_OTA(id) || !/^[^_]+_\d{3}$/.test(id.text)) return id; + const full = await ask(link, HS_FULL, 600); + return full && full.model === id.model && full.text.startsWith(id.text) ? full : id; } return null; } diff --git a/web/x0x_installer.html b/web/x0x_installer.html index e7d1990..5041a99 100644 --- a/web/x0x_installer.html +++ b/web/x0x_installer.html @@ -85,7 +85,7 @@ const TEXT = { brick: "万一 FM-1 が起動しなくなった場合は、Mac から標準ファームウェアに戻せます:", bricklink: "起動しない FM-1 の復旧(マニュアル)", beta: "これはベータ版で、不安定な場合があります。このカスタムファームウェアを使ったことで FM-1 が壊れたり不具合が起きたりしても、作者は一切の責任を負いません。自己責任でお使いください。", - back: "公式ファームウェアに戻すには、このページ下の「純正ファームウェアに戻す」か、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)を使います。", + back: "公式ファームウェアに戻すには、このページ下の「純正ファームウェアに戻す」か、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)を使います。M-UPGRADE 3.11 はこのページのバージョンを見つけますが、それより古いバージョンは見つけられません(「A USB MIDI device is present but did not answer」と表示されます)。その場合はこのページ下のボタンを使ってください。", stockh: "純正ファームウェアに戻す", stockwhy: "M-VAVE の FM-1 ファームウェア(V15 または V16)を、X0X(またはそのセーフモード)から同じ USB ケーブルで書き込みます。X0X で保存したパターンは消えることがあります。", keep: "他のファームウェアを入れると、X0X のプロジェクトは消えます。先にファイルに保存しておけます:", @@ -125,7 +125,7 @@ const TEXT = { brick: "If the FM-1 no longer starts, a Mac can put the stock firmware back:", bricklink: "recovering an FM-1 that won't start (manual)", beta: "This is a beta and may be unstable. The author accepts no responsibility if your FM-1 is damaged or misbehaves because of this custom firmware. Use it at your own risk.", - back: "To go back to the official firmware, use \"Back to the stock firmware\" below, or M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE).", + back: "To go back to the official firmware, use \"Back to the stock firmware\" below, or M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE). M-UPGRADE 3.11 finds the version on this page, not older ones (it says \"A USB MIDI device is present but did not answer\"): use the button below for those.", stockh: "Back to the stock firmware", stockwhy: "This writes M-VAVE's own FM-1 firmware (V15 or V16) back, from X0X (or its safe mode, or Felucca) over the same USB cable. Patterns saved in X0X may be lost.", keep: "Installing other firmware replaces X0X's project. To keep it, save it to a file first:",