@esp-vision/device-core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +7 -7
- package/package.json +2 -2
- package/schemas/device-actions-v1.json +1 -1
- package/scripts/verify-registry.mjs +2 -2
- package/src/cli.js +14 -8
- package/src/firmware_feed.js +1 -0
- package/src/firmware_flash.js +39 -11
- package/src/firmware_updates.js +35 -9
- package/src/node.js +5 -0
- package/src/node_rom.js +1 -0
- package/src/node_rom.py +2 -0
- package/tests/check-package.mjs +2 -1
- package/tests/test-firmware-install.mjs +126 -0
- package/tests/test-release-verification.mjs +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Export the passive built-in `openNodeRom({ port, python?, signal? })` adapter from `/node` so Node SDK hosts and the CLI share the same ROM implementation.
|
|
8
|
+
|
|
9
|
+
- Explicit `mode: 'install'` on firmware check/update and CLI `--mode install` for blank-device ROM installation over USJ/UART, using qualified complete images with bootloader/partition/application hashes and flash-capacity checks. Default application-only updates retain their existing data-preservation contract; no automatic fallback or TCP OTA is introduced.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Allow up to 151 seconds of bounded metadata propagation backoff after npm accepts publication, with ten uncached verification reads and no repeated publish.
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Changed
|
package/README.md
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
| Visibility | Public; installation needs no npm login |
|
|
20
20
|
| Source location | `host/device-core` in the ESP-VISION firmware repository |
|
|
21
21
|
|
|
22
|
-
The `/node`
|
|
22
|
+
The `/node` byte transports and bundled checks require 0.1.1; complete installation and `/node` `openNodeRom` are introduced in 0.3.0. Check the registry for the published version. CI authenticates with the protected `NPM_PUBLISH_TOKEN` and verifies that `npm whoami` returns `esp-vision` before publishing. Tokens are not part of this package or its documentation.
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
|
-
npm install --save-exact @esp-vision/device-core@0.
|
|
25
|
+
npm install --save-exact @esp-vision/device-core@0.3.0 --registry=https://registry.npmjs.org/
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
EV-MUX v4 firmware is required. A v3 hello is rejected with `VERSION_MISMATCH`; applications should ask the user to update firmware. Core has no runtime dependency on the IDE, Agent, DOM or Node serial libraries. The host supplies the physical byte transport and discovery adapter; Core owns protocol parsing, session negotiation, REPL coordination and device operations.
|
|
@@ -31,7 +31,7 @@ EV-MUX v4 firmware is required. A v3 hello is rejected with `VERSION_MISMATCH`;
|
|
|
31
31
|
|
|
32
32
|
Read the Device Core guide in the **ESP-VISION Documentation Center**: [English](https://docs.espressif.com/projects/esp-vision/en/latest/esp32p4/device-core/index.html) | [简体中文](https://docs.espressif.com/projects/esp-vision/zh_CN/latest/esp32p4/device-core/index.html).
|
|
33
33
|
|
|
34
|
-
- [All application APIs](https://docs.espressif.com/projects/esp-vision/en/latest/esp32p4/device-core/api.html), including firmware version checks and
|
|
34
|
+
- [All application APIs](https://docs.espressif.com/projects/esp-vision/en/latest/esp32p4/device-core/api.html), including firmware version checks, application updates and blank-device installation.
|
|
35
35
|
- [Advanced exports](https://docs.espressif.com/projects/esp-vision/en/latest/esp32p4/device-core/advanced.html) and [TCP/Web Serial integration](https://docs.espressif.com/projects/esp-vision/en/latest/esp32p4/device-core/integration.html).
|
|
36
36
|
|
|
37
37
|
Documentation source lives in this repository under `docs/en/device-core/` and `docs/zh_CN/device-core/` and changes alongside SDK APIs in the same MR. The documentation site renders the RST as HTML; it does not redirect readers to npm or require downloading documentation. The npm package contains the runtime library and this README, not a second RST documentation distribution. Use the documentation center's version selector when reading a published firmware/documentation version; `latest` follows the current development documentation. These new chapter links become available after the corresponding documentation is deployed.
|
|
@@ -41,7 +41,7 @@ Documentation source lives in this repository under `docs/en/device-core/` and `
|
|
|
41
41
|
The npm package installs `esp-vision-device`. `inspect` combines passive wired/LAN enumeration and targeted queries. By default it lists USB serial candidates; `--all-ports` also includes native UART/Bluetooth ports. Explicit `--port` bypasses discovery filtering; `configure`, `control`, and `firmware check/update` cover management. See the [CLI guide](https://docs.espressif.com/projects/esp-vision/en/latest/esp32p4/device-core/cli.html) ([中文](https://docs.espressif.com/projects/esp-vision/zh_CN/latest/esp32p4/device-core/cli.html)).
|
|
42
42
|
|
|
43
43
|
```sh
|
|
44
|
-
npm install -g @esp-vision/device-core@0.
|
|
44
|
+
npm install -g @esp-vision/device-core@0.3.0
|
|
45
45
|
esp-vision-device inspect
|
|
46
46
|
esp-vision-device inspect --all-ports
|
|
47
47
|
esp-vision-device inspect --interface usj,usb --probe --json
|
|
@@ -49,7 +49,7 @@ esp-vision-device inspect --port COM3 --fields identity,capabilities
|
|
|
49
49
|
esp-vision-device inspect --tcp 192.168.1.100:3232 --fields network,storage --json
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Wired access/enumeration requires Python with pyserial (`--python` overrides the interpreter); LAN discovery uses optional `multicast-dns`, normally installed by npm. Windows/Linux/macOS paths are accepted. Passive enumeration never opens a serial port; `--probe` and targeted queries acquire a session and may interrupt Python. Unidentified ports, ROM candidates and USB-to-UART adapters remain numbered and visible. Board names are unknown until firmware identification; USB descriptors are hints only. Firmware versions are fetched automatically from dl.espressif.com. Firmware flashing uses the built-in serial adapter with separately installed Python esptool>=5.3,<6; no user loader module is required. Historical releases without qualified
|
|
52
|
+
Wired access/enumeration requires Python with pyserial (`--python` overrides the interpreter); LAN discovery uses optional `multicast-dns`, normally installed by npm. Windows/Linux/macOS paths are accepted. Passive enumeration never opens a serial port; `--probe` and targeted queries acquire a session and may interrupt Python. Unidentified ports, ROM candidates and USB-to-UART adapters remain numbered and visible. Board names are unknown until firmware identification; USB descriptors are hints only. Firmware versions are fetched automatically from dl.espressif.com. Firmware flashing uses the built-in serial adapter with separately installed Python esptool>=5.3,<6; no user loader module is required. Use `firmware update --mode install --board BOARD --port PORT --version VERSION` for blank-device installation over a ROM-capable USJ/UART port. Install replaces data within the complete image range; default updates preserve the existing layout. Historical releases without qualified metadata remain listed but cannot be installed by this flow. Check the registry version before installing a newly prepared release.
|
|
53
53
|
|
|
54
54
|
## Public device API
|
|
55
55
|
|
|
@@ -65,7 +65,7 @@ Import `createDevice` from the package root. Application code uses one device in
|
|
|
65
65
|
| Interactive Python | `python.input(data)` | Send terminal input without uploading a file |
|
|
66
66
|
| Python execution | `python.execute({ source, path, completion })` | Execute source or a device-side script |
|
|
67
67
|
| Files | `files.list/read/write/remove/mkdir(request)` | File and directory operations, with one object argument |
|
|
68
|
-
| Firmware | `firmware.check(request)`, `firmware.update(request)` | List board firmware versions, select an exact version and perform verified ROM application updates |
|
|
68
|
+
| Firmware | `firmware.check(request)`, `firmware.update(request)` | List board firmware versions, select an exact version and perform verified ROM application updates or explicit complete installation on blank devices |
|
|
69
69
|
| Capture | `capture({ source, format, quality })` | Capture an image from a supported source |
|
|
70
70
|
| Events | `on(event, handler)` | Subscribe; returns an unsubscribe function |
|
|
71
71
|
|
|
@@ -220,7 +220,7 @@ const image = await device.capture({ source: 'camera', format: 'jpeg', timeout:
|
|
|
220
220
|
|
|
221
221
|
Paths are absolute device paths. `files.list({ path: '/', recursive: false })` returns entries `{ name, path, type, size }`. `files.read({ path })` returns a `Uint8Array`; use `encoding: 'utf-8'` to return text, and `maxBytes` to bound a read. Writes default to `overwrite: true`; set it to `false` to require a new destination. Uploading and executing are separate operations; create an empty file with `files.write({ path, data: new Uint8Array() })` rather than a second touch API. Remove an empty directory with `files.remove({ path: '/models', type: 'directory' })`; there is no implicit recursive deletion. `files.mkdir({ path, recursive: true })` creates missing parents.
|
|
222
222
|
|
|
223
|
-
**Binary uploads (SDK 0.
|
|
223
|
+
**Binary uploads (SDK 0.3.0):** text, model and image uploads share reliable raw binary `file.write` frames with 16 KiB blocks, continuous native VFS writes and SHA-256 commit. Matching firmware must advertise `file.write.binary`; missing support rejects with a firmware-upgrade message, without a slow upload fallback. File progress is not a durable commit. FAT replacement preserves an old-file backup until ordinary publication succeeds, with rollback on ordinary rename failure; it is not a power-loss-atomic journal. The filesystem must be mounted and allow writing, with room for the temporary upload and any existing destination file. File reads and directory operations currently use the REPL.
|
|
224
224
|
|
|
225
225
|
`capture({ source: 'screen', format: 'jpeg' })` uses the dedicated `debug.capture_screen` RPC to encode the LCD's last submitted RGB565 framebuffer, including the display's scaling and letterboxing. It does not read the panel electronics or capture the camera. Camera capture uses `debug.capture_frame`. Both return binary JPEG responses correlated to the request; optional `quality` is an integer from 1 to 100. Missing firmware capabilities reject with `UNSUPPORTED_OPERATION`; an uninitialized display returns `DISPLAY_NOT_READY`, and a board without an LCD returns `NOT_SUPPORTED`. Preview is a separate real-time stream and may drop frames under congestion.
|
|
226
226
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esp-vision/device-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared EV-MUX, framed REPL, device session, and action contracts for ESP Vision clients.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"./firmware": "./src/firmware_flash.js",
|
|
14
14
|
"./discovery": "./src/network_discovery.js",
|
|
15
15
|
"./discovery/node": "./src/network_discovery_node.js",
|
|
16
|
-
"./node": "./src/
|
|
16
|
+
"./node": "./src/node.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"src/*.js",
|
|
@@ -8,7 +8,7 @@ export async function verifyPublishedIntegrity(url, integrity, {
|
|
|
8
8
|
wait = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)),
|
|
9
9
|
report = message => console.log(message),
|
|
10
10
|
} = {}) {
|
|
11
|
-
const attempts =
|
|
11
|
+
const attempts = 10
|
|
12
12
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
13
13
|
let response, transient
|
|
14
14
|
try {
|
|
@@ -29,7 +29,7 @@ export async function verifyPublishedIntegrity(url, integrity, {
|
|
|
29
29
|
transient = `HTTP ${response.status}`
|
|
30
30
|
}
|
|
31
31
|
assert.ok(attempt + 1 < attempts, `Published metadata verification unavailable after ${attempts} reads (${transient}); retry the CI job, not publication manually`)
|
|
32
|
-
const delay = 1000 * 2 ** attempt
|
|
32
|
+
const delay = Math.min(30000, 1000 * 2 ** attempt)
|
|
33
33
|
report(`Registry verification ${transient}; retrying read ${attempt + 2}/${attempts} in ${delay}ms`)
|
|
34
34
|
await wait(delay)
|
|
35
35
|
}
|
package/src/cli.js
CHANGED
|
@@ -21,9 +21,9 @@ esp-vision-device configure (--port PATH | --tcp HOST[:PORT])
|
|
|
21
21
|
esp-vision-device control (--port PATH | --tcp HOST[:PORT])
|
|
22
22
|
--action stop|reset|bootloader [--mode soft|hard]
|
|
23
23
|
esp-vision-device firmware check [--port PATH | --tcp HOST[:PORT]]
|
|
24
|
-
[--catalog FILE|HTTPS_URL] [--board BOARD --current-version VERSION] [--version VERSION]
|
|
24
|
+
[--catalog FILE|HTTPS_URL] [--board BOARD --current-version VERSION] [--version VERSION] [--mode update|install]
|
|
25
25
|
esp-vision-device firmware update [--port PATH | --tcp HOST[:PORT]]
|
|
26
|
-
[--catalog FILE|HTTPS_URL] --version VERSION [--image
|
|
26
|
+
[--catalog FILE|HTTPS_URL] --version VERSION [--image FIRMWARE.bin] [--mode update|install]
|
|
27
27
|
[--board BOARD --current-version VERSION]
|
|
28
28
|
Common: --timeout MS (default 3000 enumeration, 30000 command),
|
|
29
29
|
--probe-timeout MS (default 5000 per device), --role usb|usj|uart|unknown,
|
|
@@ -33,7 +33,10 @@ also includes native UART/Bluetooth ports. No serial
|
|
|
33
33
|
port is opened. --probe and targeted commands acquire a session and can interrupt
|
|
34
34
|
Python. Rows with unknown firmware remain visible; numbering is per invocation.
|
|
35
35
|
Firmware versions come from dl.espressif.com by default; local catalogs are advanced overrides.
|
|
36
|
-
Firmware update uses the built-in serial flasher (Python esptool>=5.3,<6). TCP is not OTA
|
|
36
|
+
Firmware update uses the built-in serial flasher (Python esptool>=5.3,<6). TCP is not OTA.
|
|
37
|
+
Default mode update preserves the existing layout/data; explicit mode install writes
|
|
38
|
+
a complete image, replacing data in its written range. Blank boards require --board
|
|
39
|
+
and a ROM-capable USJ/UART port, not an application USB-OTG interface.`
|
|
37
40
|
const error = (code, message) => Object.assign(new Error(message), { code })
|
|
38
41
|
const fields = ['identity', 'capabilities', 'runtime', 'network', 'storage']
|
|
39
42
|
export function parseCli(args) {
|
|
@@ -43,7 +46,7 @@ export function parseCli(args) {
|
|
|
43
46
|
if (v.help) return { help: true }
|
|
44
47
|
const command = p[0] ?? 'inspect', action = command === 'firmware' ? p[1] : null
|
|
45
48
|
if (!['inspect', 'configure', 'control', 'firmware'].includes(command) || p.length > (command === 'firmware' ? 2 : 1) || (command === 'firmware' && !['check', 'update'].includes(action))) throw error('ARGUMENT', 'Unknown command; use --help')
|
|
46
|
-
const allowed = { inspect: ['all-ports', 'select', 'fields', 'interface', 'probe', 'probe-timeout'], configure: ['ssid', 'forget-wifi', 'password-stdin', 'network-enabled'], control: ['action', 'mode'], firmware: ['catalog', 'board', 'current-version', 'version', 'image'] }[command]
|
|
49
|
+
const allowed = { inspect: ['all-ports', 'select', 'fields', 'interface', 'probe', 'probe-timeout'], configure: ['ssid', 'forget-wifi', 'password-stdin', 'network-enabled'], control: ['action', 'mode'], firmware: ['mode', 'catalog', 'board', 'current-version', 'version', 'image'] }[command]
|
|
47
50
|
for (const key of Object.keys(v)) if (!['json', 'port', 'tcp', 'python', 'timeout', 'role', ...allowed].includes(key)) throw error('ARGUMENT', `Option --${key} is not valid for ${command}`)
|
|
48
51
|
if ([v.port, v.tcp, v.select].filter(value => value !== undefined).length > 1) throw error('ARGUMENT', 'Select exactly one device address or number')
|
|
49
52
|
if (v.role && !['usb', 'usj', 'uart', 'unknown'].includes(v.role)) throw error('ARGUMENT', 'Invalid serial role')
|
|
@@ -74,6 +77,8 @@ export function parseCli(args) {
|
|
|
74
77
|
}
|
|
75
78
|
if (command === 'control' && (!['stop', 'reset', 'bootloader'].includes(v.action) || (v.action === 'reset' ? !['soft', 'hard'].includes(v.mode) : v.mode !== undefined))) throw error('ARGUMENT', 'Control requires action; reset requires mode soft or hard')
|
|
76
79
|
if (command === 'firmware') {
|
|
80
|
+
if (v.mode !== undefined && !['update', 'install'].includes(v.mode)) throw error('ARGUMENT', 'Firmware mode must be update or install')
|
|
81
|
+
if (v.mode === 'install' && !v.board) throw error('ARGUMENT', 'Firmware installation requires explicit --board')
|
|
77
82
|
if (!endpoint && !v.board) throw error('ARGUMENT', 'Firmware requires a connected device or --board')
|
|
78
83
|
if (action === 'update' && (!v.port || !v.version)) throw error('ARGUMENT', 'Firmware update requires local --port and explicit --version')
|
|
79
84
|
if (action === 'check' && v.image) throw error('ARGUMENT', 'Image applies only to firmware update')
|
|
@@ -108,9 +113,9 @@ export async function runCli(options, dependencies = {}) {
|
|
|
108
113
|
endpoint = listing.devices.find(row => row.number === options.select)
|
|
109
114
|
if (!endpoint) throw error('DEVICE_NOT_FOUND', 'Selected result number is unavailable in this enumeration')
|
|
110
115
|
}
|
|
111
|
-
const
|
|
116
|
+
const offline = options.command === 'firmware' && options.board
|
|
117
|
+
const device = makeDevice(endpoint && !offline ? { transport: (dependencies.transportFor ?? transportFor)(endpoint, options) } : {})
|
|
112
118
|
try {
|
|
113
|
-
const offline = options.command === 'firmware' && options.board
|
|
114
119
|
if (endpoint && !offline) await device.connect({ role: endpoint.interface === 'serial' ? 'unknown' : endpoint.interface, timeout: options.timeout, signal, ...(endpoint.advertisement ? { expectedDevice: endpoint.advertisement } : {}) })
|
|
115
120
|
if (options.command === 'inspect') return await device.inspect({ fields: options.fields, timeout: options.timeout, signal })
|
|
116
121
|
if (options.command === 'configure') {
|
|
@@ -123,10 +128,11 @@ export async function runCli(options, dependencies = {}) {
|
|
|
123
128
|
}
|
|
124
129
|
if (options.command === 'control') return await device.control({ action: options.action, ...(options.mode ? { mode: options.mode } : {}), timeout: options.timeout, signal })
|
|
125
130
|
let catalog = options.catalog
|
|
131
|
+
const mode = options.mode ?? 'update'
|
|
126
132
|
if (catalog !== undefined && !/^https:\/\//.test(catalog)) catalog = JSON.parse(await (dependencies.readFile ?? readFile)(catalog, 'utf8'))
|
|
127
|
-
const checked = await device.firmware.check({ catalog, ...(endpoint && !offline ? {} : { identity: { board: options.board, firmwareVersion: options['current-version'] ?? 'unknown' } }), ...(options.version ? { version: options.version } : {}), signal })
|
|
133
|
+
const checked = await device.firmware.check({ catalog, mode, ...(endpoint && !offline ? {} : { identity: { board: options.board, firmwareVersion: options['current-version'] ?? 'unknown' } }), ...(options.version ? { version: options.version } : {}), signal })
|
|
128
134
|
if (options.action === 'check') return checked
|
|
129
|
-
return await device.firmware.update({ release: checked.release, board: options.board, ...(options.image ? { data: new Uint8Array(await (dependencies.readFile ?? readFile)(options.image)) } : {}), openLoader: ({ signal }) => (dependencies.openLoader ?? openNodeRom)({ port: options.port, python: options.python, signal }), onPhase: dependencies.onPhase ?? (() => {}), signal })
|
|
135
|
+
return await device.firmware.update({ mode, release: checked.release, board: options.board, ...(options.image ? { data: new Uint8Array(await (dependencies.readFile ?? readFile)(options.image)) } : {}), openLoader: ({ signal }) => (dependencies.openLoader ?? openNodeRom)({ port: options.port, python: options.python, signal }), onPhase: dependencies.onPhase ?? (() => {}), signal })
|
|
130
136
|
} finally { await device.disconnect() }
|
|
131
137
|
}
|
|
132
138
|
const safe = value => String(value ?? '—').replace(/[\x00-\x1f\x7f-\x9f]/g, '?')
|
package/src/firmware_feed.js
CHANGED
|
@@ -23,6 +23,7 @@ export async function loadOfficialFirmware({ board, fetch: fetcher = globalThis.
|
|
|
23
23
|
if (metadata) {
|
|
24
24
|
const entry = await metadata.json()
|
|
25
25
|
if (entry.board !== name || entry.version !== version || new URL(entry.image?.url).origin !== 'https://dl.espressif.com') throw new TypeError('Official firmware metadata identity/URL mismatch')
|
|
26
|
+
if (entry.install && new URL(entry.install.url).origin !== 'https://dl.espressif.com') throw new TypeError('Official install URL mismatch')
|
|
26
27
|
releases.push(entry)
|
|
27
28
|
} else {
|
|
28
29
|
const file = web.binaryNameTemplate.replace('{board}', name).replace('{tag}', version)
|
package/src/firmware_flash.js
CHANGED
|
@@ -6,18 +6,37 @@ export async function firmwareSha256(bytes) {
|
|
|
6
6
|
return Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('')
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export function firmwareMode(mode = 'update') {
|
|
10
|
+
if (!['update', 'install'].includes(mode)) throw new TypeError('Firmware mode must be update or install')
|
|
11
|
+
return mode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function validateFirmwareImage(image, bytes, { mode = 'update' } = {}) {
|
|
15
|
+
firmwareMode(mode)
|
|
10
16
|
if (image.evMuxVersion !== 4) throw new Error('Only approved EV-MUX v4 firmware can be installed')
|
|
11
17
|
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== image.bytes) throw new Error('Firmware image size does not match the approved build')
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
const limit = mode === 'install' ? image.flashSize : image.partitionSize
|
|
19
|
+
if (!Number.isSafeInteger(image.offset) || !Number.isSafeInteger(limit)
|
|
20
|
+
|| image.offset < 0 || image.bytes <= 0 || image.bytes > limit || (mode === 'install' && image.offset !== 0)) throw new Error('Invalid firmware image bounds')
|
|
14
21
|
if (await firmwareSha256(bytes) !== image.sha256) throw new Error('Firmware SHA-256 does not match the approved build')
|
|
22
|
+
if (mode === 'install') {
|
|
23
|
+
const segments = [image.bootloader, image.partitionTable, image.application]
|
|
24
|
+
let end = 0
|
|
25
|
+
for (const segment of segments) {
|
|
26
|
+
if (!segment || !Number.isSafeInteger(segment.offset) || !Number.isSafeInteger(segment.bytes)
|
|
27
|
+
|| segment.offset < end || segment.bytes <= 0 || segment.offset + segment.bytes > bytes.byteLength
|
|
28
|
+
|| !/^[a-f0-9]{64}$/.test(segment.sha256 ?? '')) throw new Error('Complete image requires ordered, non-overlapping bootloader, partition table and application metadata')
|
|
29
|
+
if (await firmwareSha256(bytes.subarray(segment.offset, segment.offset + segment.bytes)) !== segment.sha256) throw new Error('Complete image does not contain the approved bootloader, partition table and application')
|
|
30
|
+
end = segment.offset + segment.bytes
|
|
31
|
+
}
|
|
32
|
+
}
|
|
15
33
|
return bytes
|
|
16
34
|
}
|
|
17
35
|
|
|
18
36
|
/** Loader injected by the browser host; no Web Serial or ROM protocol duplicated. */
|
|
19
37
|
export class FirmwareFlashSession {
|
|
20
|
-
constructor(loader, image, { reset = () => loader.hardReset() } = {}) {
|
|
38
|
+
constructor(loader, image, { reset = () => loader.hardReset(), mode = 'update' } = {}) {
|
|
39
|
+
this.mode = firmwareMode(mode)
|
|
21
40
|
this.loader = loader
|
|
22
41
|
this.reset = reset
|
|
23
42
|
this.image = image
|
|
@@ -29,7 +48,7 @@ export class FirmwareFlashSession {
|
|
|
29
48
|
if (this.state !== 'idle') throw new Error('Firmware loader is already in use')
|
|
30
49
|
this.state = 'connecting'
|
|
31
50
|
try {
|
|
32
|
-
await validateFirmwareImage(this.image, bytes)
|
|
51
|
+
await validateFirmwareImage(this.image, bytes, { mode: this.mode })
|
|
33
52
|
await this.loader.initialize()
|
|
34
53
|
const revisionMatches = this.image.chipRevision !== undefined ? this.loader.chipRevision === this.image.chipRevision
|
|
35
54
|
: Number.isInteger(this.image.chipRevisionMin) && Number.isInteger(this.image.chipRevisionMax) && this.loader.chipRevision >= this.image.chipRevisionMin && this.loader.chipRevision <= this.image.chipRevisionMax
|
|
@@ -43,9 +62,18 @@ export class FirmwareFlashSession {
|
|
|
43
62
|
const encrypted = security.flashCryptCnt.toString(2).replace(/0/g, '').length % 2 === 1
|
|
44
63
|
if ((security.flags & 1) !== 0 || encrypted) throw new Error('Secure boot or encrypted devices require their signed flashing workflow')
|
|
45
64
|
this.stub = await this.loader.runStub(true)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
if (this.mode === 'install') {
|
|
66
|
+
// JEDEC capacity byte encodes log2(bytes); shared with browser loaders.
|
|
67
|
+
if (typeof this.stub.flashId !== 'function') throw new Error('Installation requires ROM flash capacity detection (flashId)')
|
|
68
|
+
const id = await this.stub.flashId()
|
|
69
|
+
const capacity = (id >>> 16) & 0xff
|
|
70
|
+
if (!Number.isSafeInteger(id) || id <= 0 || id > 0xffffff || capacity < 18 || capacity > 30
|
|
71
|
+
|| 2 ** capacity < this.image.flashSize) throw new Error('Detected flash is unknown or smaller than the approved complete image layout')
|
|
72
|
+
} else {
|
|
73
|
+
const table = this.image.partitionTable
|
|
74
|
+
const existing = await this.stub.readFlash(table.offset, table.bytes)
|
|
75
|
+
if (await firmwareSha256(existing) !== table.sha256) throw new Error('Partition layout differs; select explicit install mode to replace the layout')
|
|
76
|
+
}
|
|
49
77
|
this.state = 'connected'
|
|
50
78
|
} catch (error) { await this.disconnect(); throw error }
|
|
51
79
|
}
|
|
@@ -54,11 +82,11 @@ export class FirmwareFlashSession {
|
|
|
54
82
|
if (this.state !== 'connected') throw new Error('Connect and validate the device before flashing')
|
|
55
83
|
this.state = 'flashing'
|
|
56
84
|
try {
|
|
57
|
-
await validateFirmwareImage(this.image, bytes)
|
|
58
|
-
onPhase('Writing application; bootloader, partition table, NVS and user files are preserved')
|
|
85
|
+
await validateFirmwareImage(this.image, bytes, { mode: this.mode })
|
|
86
|
+
onPhase(this.mode === 'install' ? 'Installing complete firmware; existing data in the written range will be replaced' : 'Writing application; bootloader, partition table, NVS and user files are preserved')
|
|
59
87
|
await this.stub.flashData(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength),
|
|
60
88
|
(written, total) => onProgress(total ? Math.min(80, Math.round(written / total * 80)) : 0), this.image.offset, false)
|
|
61
|
-
onPhase('Verifying the complete application image')
|
|
89
|
+
onPhase(this.mode === 'install' ? 'Verifying the complete installation image' : 'Verifying the complete application image')
|
|
62
90
|
// maxInFlight is a packet count: one 1 KiB packet bounds USB-JTAG backlog.
|
|
63
91
|
const readback = new Uint8Array(bytes.byteLength)
|
|
64
92
|
for (let offset = 0; offset < bytes.byteLength; offset += 65536) {
|
package/src/firmware_updates.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
*/
|
|
4
4
|
import { loadOfficialFirmware } from './firmware_feed.js'
|
|
5
|
-
import { FirmwareFlashSession, validateFirmwareImage } from './firmware_flash.js'
|
|
5
|
+
import { FirmwareFlashSession, validateFirmwareImage, firmwareMode } from './firmware_flash.js'
|
|
6
6
|
|
|
7
7
|
function record(value, keys, name) {
|
|
8
8
|
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError(`${name} must be an object`)
|
|
@@ -16,7 +16,7 @@ function identity(value) {
|
|
|
16
16
|
if (!value || typeof value.board !== 'string' || !value.board || typeof value.firmwareVersion !== 'string' || !value.firmwareVersion) throw new TypeError('An inspected identity with board and firmwareVersion is required')
|
|
17
17
|
return structuredClone(value)
|
|
18
18
|
}
|
|
19
|
-
function release(value) {
|
|
19
|
+
function release(value, mode = 'update') {
|
|
20
20
|
if (!value || typeof value.board !== 'string' || !value.board || typeof value.version !== 'string' || !value.version) throw new TypeError('Release requires board and version')
|
|
21
21
|
const image = value.image
|
|
22
22
|
const revisionValid = image?.chipRevision !== undefined
|
|
@@ -29,6 +29,23 @@ function release(value) {
|
|
|
29
29
|
|| !/^[a-f0-9]{64}$/.test(image.sha256 ?? '') || !Number.isSafeInteger(image.partitionTable?.offset) || image.partitionTable.offset < 0
|
|
30
30
|
|| !Number.isSafeInteger(image.partitionTable?.bytes) || image.partitionTable.bytes <= 0
|
|
31
31
|
|| !/^[a-f0-9]{64}$/.test(image.partitionTable?.sha256 ?? '')) throw new TypeError('Release requires complete EV-MUX v4 application/chip/partition/SHA-256 metadata')
|
|
32
|
+
if (mode === 'install') {
|
|
33
|
+
const install = value.install
|
|
34
|
+
if (!install || install.offset !== 0 || !Number.isSafeInteger(install.bytes) || install.bytes <= 0
|
|
35
|
+
|| !Number.isSafeInteger(install.flashSize) || install.flashSize < install.bytes || install.flashSize > 2 ** 30
|
|
36
|
+
|| !Number.isInteger(Math.log2(install.flashSize)) || install.flashSize < 2 ** 18
|
|
37
|
+
|| !/^[a-f0-9]{64}$/.test(install.sha256 ?? '') || !install.bootloader
|
|
38
|
+
|| !Number.isSafeInteger(install.chipRevisionMin) || !Number.isSafeInteger(install.chipRevisionMax)
|
|
39
|
+
|| install.chipRevisionMin < (image.chipRevision ?? image.chipRevisionMin) || install.chipRevisionMax > (image.chipRevision ?? image.chipRevisionMax)
|
|
40
|
+
|| install.chipRevisionMin < 0 || install.chipRevisionMax < install.chipRevisionMin) throw Object.assign(new TypeError('Release lacks qualified complete-install metadata'), { code: 'FIRMWARE_INSTALL_UNAVAILABLE' })
|
|
41
|
+
let end = 0
|
|
42
|
+
for (const part of [install.bootloader, image.partitionTable, image]) {
|
|
43
|
+
if (!Number.isSafeInteger(part.offset) || !Number.isSafeInteger(part.bytes) || part.bytes <= 0
|
|
44
|
+
|| part.offset < end || part.offset + part.bytes > install.bytes
|
|
45
|
+
|| !/^[a-f0-9]{64}$/.test(part.sha256 ?? '')) throw new TypeError('Invalid complete-install segment bounds or hashes')
|
|
46
|
+
end = part.offset + part.bytes
|
|
47
|
+
}
|
|
48
|
+
}
|
|
32
49
|
return structuredClone(value)
|
|
33
50
|
}
|
|
34
51
|
async function download(url, fetcher, signal) {
|
|
@@ -41,10 +58,11 @@ async function download(url, fetcher, signal) {
|
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
export async function checkFirmware(request = {}, connectedIdentity) {
|
|
44
|
-
record(request, ['catalog', 'identity', 'version', 'fetch', 'signal'], 'firmware.check')
|
|
61
|
+
record(request, ['catalog', 'identity', 'version', 'mode', 'fetch', 'signal'], 'firmware.check')
|
|
45
62
|
const { signal, fetch: fetcher = globalThis.fetch } = request
|
|
46
63
|
abort(signal)
|
|
47
64
|
if (request.version !== undefined && (typeof request.version !== 'string' || !request.version.trim())) throw new TypeError('version must be a non-empty firmware version string')
|
|
65
|
+
const mode = firmwareMode(request.mode)
|
|
48
66
|
const current = identity(connectedIdentity ?? request.identity)
|
|
49
67
|
const catalog = request.catalog === undefined ? await loadOfficialFirmware({ board: current.board, fetch: fetcher, signal }) : typeof request.catalog === 'string' ? await (await download(request.catalog, fetcher, signal)).json() : structuredClone(request.catalog)
|
|
50
68
|
abort(signal)
|
|
@@ -56,22 +74,30 @@ export async function checkFirmware(request = {}, connectedIdentity) {
|
|
|
56
74
|
return structuredClone(item)
|
|
57
75
|
})
|
|
58
76
|
if (new Set(candidates.map(item => item.version)).size !== candidates.length) throw new TypeError('Catalog must not contain duplicate versions for one board')
|
|
59
|
-
const selected = request.version === undefined ? candidates.find(item => item.compatible !== false) ?? null : candidates.find(item => item.version === request.version)
|
|
77
|
+
const selected = request.version === undefined ? candidates.find(item => item.compatible !== false && (mode !== 'install' || item.install)) ?? null : candidates.find(item => item.version === request.version)
|
|
60
78
|
if (request.version !== undefined && !selected) throw Object.assign(new Error('Requested firmware version is unavailable for this board'), { code: 'FIRMWARE_VERSION_UNAVAILABLE' })
|
|
61
79
|
if (selected?.compatible === false) throw Object.assign(new Error('This published version lacks approved v4 update metadata'), { code: 'FIRMWARE_INCOMPATIBLE' })
|
|
80
|
+
if (selected) release(selected, mode)
|
|
62
81
|
return { available: selected !== null && (selected.firmwareVersion ?? selected.version) !== current.firmwareVersion, currentVersion: current.firmwareVersion, release: selected, releases: candidates }
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
export async function updateFirmware(request, connectedIdentity, disconnect) {
|
|
66
|
-
record(request, ['release', 'board', 'data', 'fetch', 'openLoader', 'reset', 'onProgress', 'onPhase', 'signal'], 'firmware.update')
|
|
85
|
+
record(request, ['release', 'board', 'mode', 'data', 'fetch', 'openLoader', 'reset', 'onProgress', 'onPhase', 'signal'], 'firmware.update')
|
|
67
86
|
const { signal, fetch: fetcher = globalThis.fetch, openLoader, reset, onProgress = () => {}, onPhase = () => {} } = request
|
|
68
87
|
abort(signal)
|
|
69
88
|
if (typeof openLoader !== 'function' || typeof onProgress !== 'function' || typeof onPhase !== 'function' || (reset !== undefined && typeof reset !== 'function')) throw new TypeError('Firmware update requires openLoader and valid callbacks')
|
|
70
|
-
const
|
|
89
|
+
const mode = firmwareMode(request.mode)
|
|
90
|
+
const target = release(request.release, mode)
|
|
91
|
+
const image = mode === 'install' ? {
|
|
92
|
+
...target.image, offset: target.install.offset, bytes: target.install.bytes,
|
|
93
|
+
flashSize: target.install.flashSize, sha256: target.install.sha256, url: target.install.url,
|
|
94
|
+
bootloader: target.install.bootloader, application: target.image,
|
|
95
|
+
chipRevision: undefined, chipRevisionMin: target.install.chipRevisionMin, chipRevisionMax: target.install.chipRevisionMax,
|
|
96
|
+
} : target.image
|
|
71
97
|
const board = connectedIdentity?.board ?? request.board
|
|
72
98
|
if (!board || board !== target.board || (request.board !== undefined && request.board !== board)) throw new TypeError('Firmware release does not match the connected or explicitly selected board')
|
|
73
|
-
const bytes = request.data === undefined ? new Uint8Array(await (await download(
|
|
74
|
-
await validateFirmwareImage(
|
|
99
|
+
const bytes = request.data === undefined ? new Uint8Array(await (await download(image.url, fetcher, signal)).arrayBuffer()) : request.data instanceof Uint8Array ? request.data.slice() : request.data
|
|
100
|
+
await validateFirmwareImage(image, bytes, { mode })
|
|
75
101
|
abort(signal)
|
|
76
102
|
// Validate everything before releasing EV-MUX or acquiring a download port.
|
|
77
103
|
await disconnect()
|
|
@@ -80,7 +106,7 @@ export async function updateFirmware(request, connectedIdentity, disconnect) {
|
|
|
80
106
|
let session
|
|
81
107
|
try {
|
|
82
108
|
abort(signal)
|
|
83
|
-
session = new FirmwareFlashSession(loader,
|
|
109
|
+
session = new FirmwareFlashSession(loader, image, { mode, reset: reset ? () => reset(loader) : undefined })
|
|
84
110
|
await session.connect(bytes)
|
|
85
111
|
abort(signal)
|
|
86
112
|
// No interruption after writing starts: finish verification and reset policy.
|
package/src/node.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Node-only adapters. Creating them does not acquire a session or serial port.
|
|
4
|
+
export { tcpTransport, serialTransport } from './node_transport.js'
|
|
5
|
+
export { openNodeRom } from './node_rom.js'
|
package/src/node_rom.js
CHANGED
|
@@ -41,6 +41,7 @@ export function openNodeRom({ port, python = defaultPython, signal } = {}) {
|
|
|
41
41
|
try { Object.assign(loader, await rpc('initialize')) }
|
|
42
42
|
finally { signal?.removeEventListener('abort', cancelled) }
|
|
43
43
|
},
|
|
44
|
+
flashId: () => rpc('flashId'),
|
|
44
45
|
getSecurityInfo: () => rpc('security'),
|
|
45
46
|
async runStub() { await rpc('stub'); return loader },
|
|
46
47
|
async readFlash(offset, bytes) { return new Uint8Array(Buffer.from(await rpc('read', [offset, bytes]), 'base64')) },
|
package/src/node_rom.py
CHANGED
|
@@ -32,6 +32,8 @@ def main():
|
|
|
32
32
|
esp = esptool.run_stub(esp)
|
|
33
33
|
esptool.attach_flash(esp)
|
|
34
34
|
esp.change_baud(460800)
|
|
35
|
+
elif method == 'flashId':
|
|
36
|
+
result = esp.flash_id()
|
|
35
37
|
elif method == 'read':
|
|
36
38
|
result = base64.b64encode(esp.read_flash(*args)).decode('ascii')
|
|
37
39
|
elif method == 'write':
|
package/tests/check-package.mjs
CHANGED
|
@@ -38,7 +38,7 @@ try {
|
|
|
38
38
|
if (Object.keys(api).sort().join(',') !== 'createDevice') throw new Error('Root must expose only the application API');
|
|
39
39
|
const { DeviceSession } = await import('@esp-vision/device-core/session');
|
|
40
40
|
const { FirmwareFlashSession } = await import('@esp-vision/device-core/firmware');
|
|
41
|
-
const { tcpTransport, serialTransport } = await import('@esp-vision/device-core/node');
|
|
41
|
+
const { tcpTransport, serialTransport, openNodeRom } = await import('@esp-vision/device-core/node');
|
|
42
42
|
if (typeof tcpTransport !== 'function' || typeof serialTransport !== 'function') throw new Error('Missing public Node transports');
|
|
43
43
|
const { createNodeDiscovery } = await import('@esp-vision/device-core/discovery/node');
|
|
44
44
|
const { EventEmitter } = await import('node:events');
|
|
@@ -49,6 +49,7 @@ try {
|
|
|
49
49
|
const device = api.createDevice({ discovery: provider });
|
|
50
50
|
if (typeof provider.list !== 'function') throw new Error('Discovery providers must expose list()');
|
|
51
51
|
if ((await device.discover({ timeout: 50 })).length !== 0 || !queries) throw new Error('Device discovery did not call its provider');
|
|
52
|
+
if (typeof openNodeRom !== 'function' || typeof openNodeRom({ port: 'not-opened' }).initialize !== 'function') throw new Error('Missing passive Node ROM adapter');
|
|
52
53
|
// Constructors must be passive: these endpoints need not exist to create adapters.
|
|
53
54
|
api.createDevice({ transport: tcpTransport({ host: '127.0.0.1', port: 1 }) });
|
|
54
55
|
api.createDevice({ transport: serialTransport({ python: 'python3', serial: 'not-opened' }) });
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { test } from 'node:test'
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import { createDevice } from '../src/index.js'
|
|
6
|
+
import { firmwareSha256 } from '../src/firmware_flash.js'
|
|
7
|
+
import { parseCli, runCli } from '../src/cli.js'
|
|
8
|
+
|
|
9
|
+
async function fixture() {
|
|
10
|
+
const data = new Uint8Array(0x11000).fill(0xff), calls = []
|
|
11
|
+
data.set([0xe9, 1, 2, 3], 0x2000)
|
|
12
|
+
data.set([0xaa, 0x50, 4, 5], 0x8000)
|
|
13
|
+
data.set([0xe9, 6, 7, 8], 0x10000)
|
|
14
|
+
const part = async offset => ({ offset, bytes: 4, sha256: await firmwareSha256(data.subarray(offset, offset + 4)) })
|
|
15
|
+
const release = { board: 'BOARD', version: 'new', image: {
|
|
16
|
+
evMuxVersion: 4, chipFamily: 0x3280, chipRevision: 302, ...(await part(0x10000)),
|
|
17
|
+
partitionSize: 4096, partitionTable: await part(0x8000), url: 'https://example.test/app.bin',
|
|
18
|
+
}, install: { offset: 0, bytes: data.length, flashSize: 0x1000000, chipRevisionMin: 302, chipRevisionMax: 302,
|
|
19
|
+
sha256: await firmwareSha256(data), bootloader: await part(0x2000), url: 'https://example.test/full.bin' } }
|
|
20
|
+
const flash = new Uint8Array(data.length).fill(0xff)
|
|
21
|
+
const loader = {
|
|
22
|
+
chipFamily: 0x3280, chipRevision: 302,
|
|
23
|
+
async initialize() { calls.push('initialize') },
|
|
24
|
+
async getSecurityInfo() { return { flags: 0, flashCryptCnt: 0 } },
|
|
25
|
+
async runStub() { calls.push('stub'); return loader },
|
|
26
|
+
async flashId() { calls.push('capacity'); return 0x1840ef },
|
|
27
|
+
async flashData(buffer, progress, offset) { calls.push(['write', offset]); flash.set(new Uint8Array(buffer), offset); progress(buffer.byteLength, buffer.byteLength) },
|
|
28
|
+
async readFlash(offset, count) { calls.push(['read', offset]); return flash.slice(offset, offset + count) },
|
|
29
|
+
async readRegister() { return 0 },
|
|
30
|
+
async hardReset() { calls.push('reset') },
|
|
31
|
+
async disconnect() { calls.push('close') },
|
|
32
|
+
}
|
|
33
|
+
const device = createDevice(), request = { mode: 'install', release, board: 'BOARD', data, async openLoader() { calls.push('open'); return loader } }
|
|
34
|
+
return { data, calls, release, loader, device, request, flash }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
test('blank device installs through ROM without an EV-MUX transport or existing partition table', async () => {
|
|
38
|
+
const f = await fixture(), progress = []
|
|
39
|
+
const result = await f.device.firmware.update({ ...f.request, onProgress: value => progress.push(value) })
|
|
40
|
+
assert.equal(result.verified, true); assert.equal(result.reconnected, false)
|
|
41
|
+
assert.deepEqual(f.flash, f.data)
|
|
42
|
+
assert.deepEqual(f.calls, ['open', 'initialize', 'stub', 'capacity', ['write', 0], ['read', 0], ['read', 65536], 'reset', 'close'])
|
|
43
|
+
assert.equal(progress.at(-1), 100)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('default application update refuses blank layout and never falls back to installing', async () => {
|
|
47
|
+
const f = await fixture()
|
|
48
|
+
await assert.rejects(f.device.firmware.update({ ...f.request, mode: undefined, data: f.data.slice(65536, 65540) }), /Partition layout/)
|
|
49
|
+
assert.ok(!f.calls.some(call => Array.isArray(call) && call[0] === 'write'))
|
|
50
|
+
assert.ok(!f.calls.includes('capacity'))
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('complete image is downloaded from install URL with the requested cancellation signal', async () => {
|
|
54
|
+
const f = await fixture(), controller = new AbortController()
|
|
55
|
+
await f.device.firmware.update({ ...f.request, data: undefined, signal: controller.signal,
|
|
56
|
+
async fetch(url, options) { assert.equal(url, f.release.install.url); assert.equal(options.signal, controller.signal); return { ok: true, arrayBuffer: async () => f.data.buffer } },
|
|
57
|
+
})
|
|
58
|
+
assert.deepEqual(f.flash, f.data)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('install selection skips app-only releases and rejects explicit unqualified versions', async () => {
|
|
62
|
+
const f = await fixture(), appOnly = { ...f.release, version: 'app-only', install: undefined }
|
|
63
|
+
const request = { mode: 'install', identity: { board: 'BOARD', firmwareVersion: 'unknown' }, catalog: { schemaVersion: 1, releases: [appOnly, f.release] } }
|
|
64
|
+
const result = await f.device.firmware.check(request)
|
|
65
|
+
assert.equal(result.release.version, 'new'); assert.equal(result.releases.length, 2)
|
|
66
|
+
await assert.rejects(f.device.firmware.check({ ...request, version: 'app-only' }), { code: 'FIRMWARE_INSTALL_UNAVAILABLE' })
|
|
67
|
+
const updates = await f.device.firmware.check({ ...request, mode: 'update' })
|
|
68
|
+
assert.equal(updates.release.version, 'app-only')
|
|
69
|
+
assert.deepEqual(f.calls, [])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
for (const change of ['hash', 'bootloader', 'table', 'application', 'overlap', 'bounds', 'revision-range', 'missing-metadata', 'mode', 'board']) {
|
|
73
|
+
test(`invalid ${change} rejects installation before opening or releasing a port`, async () => {
|
|
74
|
+
const f = await fixture()
|
|
75
|
+
if (change === 'hash') f.data[1] = 0
|
|
76
|
+
if (change === 'bootloader') f.release.install.bootloader.sha256 = '0'.repeat(64)
|
|
77
|
+
if (change === 'table') f.release.image.partitionTable.sha256 = '0'.repeat(64)
|
|
78
|
+
if (change === 'application') f.release.image.sha256 = '0'.repeat(64)
|
|
79
|
+
if (change === 'overlap') f.release.install.bootloader.bytes = 0x8000
|
|
80
|
+
if (change === 'bounds') f.release.install.offset = 0x1000
|
|
81
|
+
if (change === 'revision-range') f.release.install.chipRevisionMin = 301
|
|
82
|
+
if (change === 'missing-metadata') delete f.release.install
|
|
83
|
+
if (change === 'mode') f.request.mode = 'auto'
|
|
84
|
+
if (change === 'board') f.request.board = 'WRONG'
|
|
85
|
+
await assert.rejects(f.device.firmware.update(f.request))
|
|
86
|
+
assert.deepEqual(f.calls, [])
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const change of ['wrong-chip', 'wrong-revision', 'secure-boot', 'encryption', 'small-flash', 'unknown-flash', 'missing-capacity']) {
|
|
91
|
+
test(`physical ${change} refuses installation before any write`, async () => {
|
|
92
|
+
const f = await fixture()
|
|
93
|
+
if (change === 'wrong-chip') f.loader.chipFamily = 0x3253
|
|
94
|
+
if (change === 'wrong-revision') f.loader.chipRevision = 301
|
|
95
|
+
if (change === 'secure-boot') f.loader.getSecurityInfo = async () => ({ flags: 1, flashCryptCnt: 0 })
|
|
96
|
+
if (change === 'encryption') f.loader.getSecurityInfo = async () => ({ flags: 0, flashCryptCnt: 1 })
|
|
97
|
+
if (change === 'small-flash') f.loader.flashId = async () => 0x1740ef
|
|
98
|
+
if (change === 'unknown-flash') f.loader.flashId = async () => 0xffffff
|
|
99
|
+
if (change === 'missing-capacity') delete f.loader.flashId
|
|
100
|
+
await assert.rejects(f.device.firmware.update(f.request))
|
|
101
|
+
assert.ok(!f.calls.some(call => Array.isArray(call) && call[0] === 'write'))
|
|
102
|
+
assert.equal(f.calls.at(-1), 'close')
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test('installation with damaged readback does not reset or report success', async () => {
|
|
107
|
+
const f = await fixture(); f.loader.readFlash = async (_offset, count) => new Uint8Array(count)
|
|
108
|
+
await assert.rejects(f.device.firmware.update(f.request), /verification failed/)
|
|
109
|
+
assert.ok(!f.calls.includes('reset')); assert.equal(f.calls.at(-1), 'close')
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('CLI install uses ROM directly and passes mode through both check and update', async () => {
|
|
113
|
+
const f = await fixture(), checked = []
|
|
114
|
+
const options = parseCli(['firmware', 'update', '--mode', 'install', '--board', 'BOARD', '--port', '/dev/ttyACM0', '--version', 'new'])
|
|
115
|
+
const result = await runCli(options, {
|
|
116
|
+
transportFor: () => { throw new Error('No application transport should be acquired') },
|
|
117
|
+
async readFile() { throw new Error('No user catalog required') },
|
|
118
|
+
createDevice: () => ({ firmware: {
|
|
119
|
+
async check(request) { checked.push(request.mode); return { release: f.release } },
|
|
120
|
+
async update(request) { assert.equal(request.mode, 'install'); return { verified: true } },
|
|
121
|
+
}, async disconnect() {} }),
|
|
122
|
+
})
|
|
123
|
+
assert.equal(result.verified, true); assert.deepEqual(checked, ['install'])
|
|
124
|
+
assert.throws(() => parseCli(['firmware', 'update', '--mode', 'install', '--port', 'COM3', '--version', 'new']), /explicit --board/)
|
|
125
|
+
assert.throws(() => parseCli(['firmware', 'update', '--mode', 'install', '--tcp', 'host', '--board', 'BOARD', '--version', 'new']), /local --port/)
|
|
126
|
+
})
|
|
@@ -51,8 +51,16 @@ test('missing published integrity is not accepted', async () => {
|
|
|
51
51
|
await assert.rejects(verifyPublishedIntegrity(url, integrity, f.options), /integrity mismatch/)
|
|
52
52
|
assert.deepEqual(f.waits, [])
|
|
53
53
|
})
|
|
54
|
-
test('persistent propagation failures stop after
|
|
55
|
-
const f = fixture(Array.from({ length:
|
|
56
|
-
await assert.rejects(verifyPublishedIntegrity(url, integrity, f.options), /after
|
|
57
|
-
assert.equal(f.calls.length,
|
|
54
|
+
test('persistent propagation failures stop after ten reads with bounded backoff', async () => {
|
|
55
|
+
const f = fixture(Array.from({ length: 10 }, () => new Response('', { status: 404 })))
|
|
56
|
+
await assert.rejects(verifyPublishedIntegrity(url, integrity, f.options), /after 10 reads/)
|
|
57
|
+
assert.equal(f.calls.length, 10); assert.deepEqual(f.waits, [1000, 2000, 4000, 8000, 16000, 30000, 30000, 30000, 30000])
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('registry visibility delayed beyond the original 31-second window is verified without another publish', async () => {
|
|
61
|
+
const f = fixture([...Array.from({ length: 7 }, () => new Response('', { status: 404 })), published(integrity)])
|
|
62
|
+
await verifyPublishedIntegrity(url, integrity, f.options)
|
|
63
|
+
assert.equal(f.calls.length, 8)
|
|
64
|
+
assert.ok(f.waits.reduce((total, delay) => total + delay, 0) > 31000)
|
|
65
|
+
assert.ok(f.waits.every(delay => delay <= 30000))
|
|
58
66
|
})
|