@geastack/cli 0.1.92 → 0.1.94
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/package.json +1 -1
- package/src/board-catalog.mjs +16 -0
- package/src/boards/resolve.mjs +10 -0
- package/src/boards/usb.mjs +23 -6
- package/src/commands/board.mjs +65 -3
- package/src/device/device.mjs +1 -1
- package/src/device/serial.mjs +66 -4
- package/src/esp32/build.mjs +10 -5
- package/src/esp32/flash.mjs +1 -1
- package/src/esp32/idf-env.mjs +47 -14
- package/src/esp32/idf-version.mjs +5 -0
- package/src/manifest.mjs +9 -1
package/package.json
CHANGED
package/src/board-catalog.mjs
CHANGED
|
@@ -176,6 +176,22 @@ export const knownBoards = Object.freeze([
|
|
|
176
176
|
gps: false
|
|
177
177
|
}
|
|
178
178
|
},
|
|
179
|
+
{
|
|
180
|
+
id: 'espressif-mosaico',
|
|
181
|
+
label: 'Espressif ESP-Mosaico (V1.2)',
|
|
182
|
+
alias: 'mosaico',
|
|
183
|
+
target: 'esp32-s31-espressif-mosaico',
|
|
184
|
+
adapter: 'esp32-idf',
|
|
185
|
+
mcu: 'ESP32-S31',
|
|
186
|
+
capabilities: {
|
|
187
|
+
display: '480 × 480 square AMOLED (CO5300 QSPI)',
|
|
188
|
+
touch: 'CST9220 capacitive touch',
|
|
189
|
+
wireless: ['WiFi 6', 'BLE'],
|
|
190
|
+
storage: ['16 MB flash', '16 MB PSRAM', '128 MB SPI NAND'],
|
|
191
|
+
audio: ['ES8311 speaker + microphone'],
|
|
192
|
+
gps: false
|
|
193
|
+
}
|
|
194
|
+
},
|
|
179
195
|
{
|
|
180
196
|
id: 'waveshare-rp2350-amoled-241',
|
|
181
197
|
label: 'Waveshare RP2350 Touch AMOLED 2.41',
|
package/src/boards/resolve.mjs
CHANGED
|
@@ -159,6 +159,16 @@ export function resolveBoardSelection({
|
|
|
159
159
|
compatibleAppPlatforms: Array.isArray(targetInfo.compatibleAppPlatforms) ? targetInfo.compatibleAppPlatforms : [],
|
|
160
160
|
idfTarget: board?.idfTarget || targetInfo.idfTarget || '',
|
|
161
161
|
esptoolChip: board?.esptoolChip || targetInfo.esptoolChip || '',
|
|
162
|
+
// The oldest ESP-IDF major.minor the target compiles against. A chip that
|
|
163
|
+
// only exists in a pre-release IDF (ESP32-S31) names it here; every other
|
|
164
|
+
// target leaves it empty and keeps the newest stable install.
|
|
165
|
+
idfVersion: board?.idfVersion || targetInfo.idfVersion || '',
|
|
166
|
+
// A board whose USB port cannot be reset into the ROM loader from the host
|
|
167
|
+
// is flashed in manual boot mode by default: BOOT held through a power cycle.
|
|
168
|
+
manualBoot: Boolean(board?.manualBoot ?? targetInfo.manualBoot),
|
|
169
|
+
// 'geadev-ota': `gea flash` installs the app through the running firmware
|
|
170
|
+
// over its USB console (GEADEV OTA) and falls back to the ROM downloader.
|
|
171
|
+
usbAppUpdate: board?.usbAppUpdate || targetInfo.usbAppUpdate || '',
|
|
162
172
|
mainTaskStackSize: board?.mainTaskStackSize || targetInfo.mainTaskStackSize || '',
|
|
163
173
|
ipcTaskStackSize: board?.ipcTaskStackSize || targetInfo.ipcTaskStackSize || '',
|
|
164
174
|
port,
|
package/src/boards/usb.mjs
CHANGED
|
@@ -109,7 +109,10 @@ function macUsbCalloutPortsForSerial(serial, ioreg = runIoreg) {
|
|
|
109
109
|
for (const line of output.split(/\r?\n/)) {
|
|
110
110
|
const node = line.match(/^([\s|]*)[+\\-]*o\s+/)
|
|
111
111
|
if (node) {
|
|
112
|
-
|
|
112
|
+
// The column of `+-o` is the depth. Counting `|` is not: ioreg draws the
|
|
113
|
+
// last child's subtree with spaces, so a callout under a device's last
|
|
114
|
+
// interface would look shallower than the device holding its serial.
|
|
115
|
+
const depth = node[1].length
|
|
113
116
|
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) stack.pop()
|
|
114
117
|
stack.push({ depth, serial: '' })
|
|
115
118
|
continue
|
|
@@ -144,7 +147,10 @@ export function listMacUsbCalloutPorts(ioreg = runIoreg) {
|
|
|
144
147
|
for (const line of output.split(/\r?\n/)) {
|
|
145
148
|
const node = line.match(/^([\s|]*)[+\\-]*o\s+/)
|
|
146
149
|
if (node) {
|
|
147
|
-
|
|
150
|
+
// The column of `+-o` is the depth. Counting `|` is not: ioreg draws the
|
|
151
|
+
// last child's subtree with spaces, so a callout under a device's last
|
|
152
|
+
// interface would look shallower than the device holding its serial.
|
|
153
|
+
const depth = node[1].length
|
|
148
154
|
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) stack.pop()
|
|
149
155
|
stack.push({ depth, serial: '', product: '' })
|
|
150
156
|
continue
|
|
@@ -183,8 +189,18 @@ function resolveMacUsbSerialPort(serial, ioreg = runIoreg) {
|
|
|
183
189
|
throw new Error(`Could not map USB serial ${serial} to a /dev/cu.* port. Check that the board is attached.`)
|
|
184
190
|
}
|
|
185
191
|
|
|
186
|
-
export function resolveUsbSerialPort({ serial }, { platform = process.platform, ioreg = runIoreg } = {}) {
|
|
192
|
+
export function resolveUsbSerialPort({ serial }, { platform = process.platform, ioreg = runIoreg, env = process.env } = {}) {
|
|
187
193
|
if (!serial) throw new Error('A USB serial number is required to locate the board; /dev paths are not accepted.')
|
|
194
|
+
// GEA_SERIAL_DEVICES replaces OS enumeration everywhere (see detectSerialDevices);
|
|
195
|
+
// resolution honors it with the same exact-serial rule, so a declared device list
|
|
196
|
+
// can never map one board's serial onto another's port.
|
|
197
|
+
if (env.GEA_SERIAL_DEVICES) {
|
|
198
|
+
const needle = normalizedSerial(serial)
|
|
199
|
+
const matches = detectSerialDevices({ env }).filter((device) => device.serial && normalizedSerial(device.serial) === needle)
|
|
200
|
+
if (matches.length === 1) return matches[0].path
|
|
201
|
+
if (matches.length > 1) throw new Error([`USB serial ${serial} maps to multiple ports:`, ...matches.map((device) => ` ${device.path}`)].join('\n'))
|
|
202
|
+
throw new Error(`Could not map USB serial ${serial} to a port in GEA_SERIAL_DEVICES. Check that the board is attached.`)
|
|
203
|
+
}
|
|
188
204
|
if (platform === 'linux') {
|
|
189
205
|
const matches = linuxSerialByIdCandidates(serial)
|
|
190
206
|
if (matches.length === 1) return realpathSync(matches[0])
|
|
@@ -225,7 +241,8 @@ export async function waitForSerialPort({
|
|
|
225
241
|
pollSeconds = 1,
|
|
226
242
|
log = (line) => process.stderr.write(`${line}\n`),
|
|
227
243
|
resolver = resolveUsbSerialPort,
|
|
228
|
-
portPresent = serialPortPresent
|
|
244
|
+
portPresent = serialPortPresent,
|
|
245
|
+
env = process.env
|
|
229
246
|
} = {}) {
|
|
230
247
|
const startedAt = Date.now()
|
|
231
248
|
let nextLog = startedAt
|
|
@@ -234,14 +251,14 @@ export async function waitForSerialPort({
|
|
|
234
251
|
if (portPresent(port)) {
|
|
235
252
|
if (!serial) return port
|
|
236
253
|
try {
|
|
237
|
-
if (resolver({ serial }) === port) return port
|
|
254
|
+
if (resolver({ serial }, { env }) === port) return port
|
|
238
255
|
} catch {
|
|
239
256
|
// An explicit path does not override the registered board identity.
|
|
240
257
|
}
|
|
241
258
|
}
|
|
242
259
|
} else if (serial) {
|
|
243
260
|
try {
|
|
244
|
-
const resolved = resolver({ serial })
|
|
261
|
+
const resolved = resolver({ serial }, { env })
|
|
245
262
|
if (resolved && portPresent(resolved)) return resolved
|
|
246
263
|
} catch {
|
|
247
264
|
// not attached yet
|
package/src/commands/board.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path'
|
|
|
3
3
|
import { flag, option, optionList } from '../args.mjs'
|
|
4
4
|
import { loadBoardConfig, normalizeBoardConfig } from '../boards/config.mjs'
|
|
5
5
|
import { resolveBoardSelection } from '../boards/resolve.mjs'
|
|
6
|
-
import { resolveUsbSerialPort } from '../boards/usb.mjs'
|
|
6
|
+
import { resolveUsbSerialPort, serialPortPresent } from '../boards/usb.mjs'
|
|
7
7
|
import { createChildEnv } from '../context.mjs'
|
|
8
8
|
import { chooseTransport, openDevice, saveScreenshot } from '../device/device.mjs'
|
|
9
9
|
import { geadev } from '../device/serial.mjs'
|
|
@@ -161,9 +161,9 @@ export async function cleanCommand(ctx, parsed, rest, options) {
|
|
|
161
161
|
async function flashEsp32(ctx, parsed, rest, options, selection, { monitor }) {
|
|
162
162
|
const base = io(parsed, options)
|
|
163
163
|
const env = createChildEnv(ctx, base.env)
|
|
164
|
-
const idf = requireEspIdf(env, base.stdout)
|
|
164
|
+
const idf = requireEspIdf(env, base.stdout, selection)
|
|
165
165
|
const flashEnv = idf.env
|
|
166
|
-
const opts = flashOptions(flashEnv, { idf, selection, manualBoot: flag(parsed, 'manual-boot'), noReset: option(parsed, 'reset') === false, baud: option(parsed, 'flash-baud', '') })
|
|
166
|
+
const opts = flashOptions(flashEnv, { idf, selection, manualBoot: flag(parsed, 'manual-boot') || selection.manualBoot, noReset: option(parsed, 'reset') === false, baud: option(parsed, 'flash-baud', '') })
|
|
167
167
|
const common = { idf, selection, options: opts, port: selection.port, env: flashEnv, dryRun: base.dryRun, verbose: flag(parsed, 'verbose'), stdout: base.stdout, stderr: base.stderr }
|
|
168
168
|
const slotImages = optionList(parsed, 'slot-image')
|
|
169
169
|
const eraseSlotName = option(parsed, 'erase-slot', '')
|
|
@@ -197,6 +197,10 @@ async function flashEsp32(ctx, parsed, rest, options, selection, { monitor }) {
|
|
|
197
197
|
await stageImage({ ...common, image, slot, buildDir, appLabel })
|
|
198
198
|
return 0
|
|
199
199
|
}
|
|
200
|
+
if (selection.usbAppUpdate === 'geadev-ota' && !flag(parsed, 'manual-boot') && !base.dryRun && (await usbAppUpdate({ selection, image, appLabel, env: flashEnv, stdout: base.stdout, stderr: base.stderr }))) {
|
|
201
|
+
if (!monitor) return 0
|
|
202
|
+
return monitorCommand(ctx, parsed, rest, options, selection)
|
|
203
|
+
}
|
|
200
204
|
await flashFirmware({ ...common, images, appImage: image, appLabel })
|
|
201
205
|
if (!monitor) {
|
|
202
206
|
postFlashRestartNote(selection, base.stderr)
|
|
@@ -205,6 +209,64 @@ async function flashEsp32(ctx, parsed, rest, options, selection, { monitor }) {
|
|
|
205
209
|
return monitorCommand(ctx, parsed, rest, options, selection)
|
|
206
210
|
}
|
|
207
211
|
|
|
212
|
+
// A board whose USB port is not a ROM console (the ESP32-S31's OTG port) is
|
|
213
|
+
// updated through the app it is running: GEADEV OTA writes the image into the
|
|
214
|
+
// next OTA slot and restarts into it. Only when no gea app answers does the
|
|
215
|
+
// flash fall back to the ROM downloader, which on such a board needs BOOT.
|
|
216
|
+
async function usbAppUpdate({ selection, image, appLabel, env, stdout, stderr }) {
|
|
217
|
+
let device
|
|
218
|
+
try {
|
|
219
|
+
device = await openDevice({ selection, transport: 'usb', env, stderr: () => {}, waitSeconds: 5 })
|
|
220
|
+
} catch {
|
|
221
|
+
stderr('No running gea app answered on USB; falling back to the ROM downloader (hold BOOT while powering on).')
|
|
222
|
+
return false
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
stdout(`Installing '${appLabel}' through the running app over USB...`)
|
|
226
|
+
const result = await geadev.otaUpdate(device.serial, image, { stderr })
|
|
227
|
+
success(stdout, `Installed '${appLabel}' (${Math.round(result.bytes / 1024)} KB in ${result.seconds.toFixed(1)}s) into ${result.line.match(/slot=(\S+)/)?.[1] || 'the next OTA slot'}; the board is restarting.`)
|
|
228
|
+
return true
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (error.uploaded) {
|
|
231
|
+
await device.close().catch(() => {})
|
|
232
|
+
device = null
|
|
233
|
+
if (await usbAppAnswers({ selection, appLabel, env })) {
|
|
234
|
+
success(stdout, `Installed '${appLabel}'; the board restarted into it (its confirmation line was lost on the console).`)
|
|
235
|
+
return true
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
stderr(`USB app update failed: ${error.message}. Falling back to the ROM downloader (hold BOOT while powering on).`)
|
|
239
|
+
return false
|
|
240
|
+
} finally {
|
|
241
|
+
if (device) await device.close().catch(() => {})
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// After a fully sent image whose reply went missing: the board restarted only
|
|
246
|
+
// if the port went away, and the install took only if the app that comes back
|
|
247
|
+
// is the one sent.
|
|
248
|
+
async function usbAppAnswers({ selection, appLabel, env }) {
|
|
249
|
+
let port = ''
|
|
250
|
+
try {
|
|
251
|
+
port = resolveUsbSerialPort({ serial: selection.usbSerial }, { env })
|
|
252
|
+
} catch {}
|
|
253
|
+
if (port && serialPortPresent(port)) return false
|
|
254
|
+
const deadline = Date.now() + 30000
|
|
255
|
+
while (Date.now() < deadline) {
|
|
256
|
+
let device
|
|
257
|
+
try {
|
|
258
|
+
device = await openDevice({ selection, transport: 'usb', env, stderr: () => {}, waitSeconds: 5 })
|
|
259
|
+
const pong = await geadev.ping(device.serial)
|
|
260
|
+
return /\bapp=(\S+)/.exec(pong)?.[1] === appLabel
|
|
261
|
+
} catch {
|
|
262
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
263
|
+
} finally {
|
|
264
|
+
if (device) await device.close().catch(() => {})
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return false
|
|
268
|
+
}
|
|
269
|
+
|
|
208
270
|
export async function flashCommand(ctx, parsed, rest, options, { monitor = false } = {}) {
|
|
209
271
|
const selection = selectBoard(ctx, parsed, { usbPort: true })
|
|
210
272
|
const base = io(parsed, options)
|
package/src/device/device.mjs
CHANGED
|
@@ -36,7 +36,7 @@ export async function openDevice({ selection, transport, host = '', port = '', e
|
|
|
36
36
|
if (!selection.usbSerial && !port) {
|
|
37
37
|
fail(`Board '${selection.boardName || selection.target}' has no transports.usbSerial.serial; use --transport wifi or add the USB serial.`, ExitCode.usage)
|
|
38
38
|
}
|
|
39
|
-
const devicePath = await waitForSerialPort({ port, serial: selection.usbSerial, timeoutSeconds: waitSeconds, label: 'USB serial port', log: stderr })
|
|
39
|
+
const devicePath = await waitForSerialPort({ port, serial: selection.usbSerial, timeoutSeconds: waitSeconds, label: 'USB serial port', log: stderr, env })
|
|
40
40
|
const serial = await SerialDevice.open({ path: devicePath, baudRate: serialBaudRate(selection, env), trace, stderr })
|
|
41
41
|
return new UsbDevice(serial, { stderr })
|
|
42
42
|
}
|
package/src/device/serial.mjs
CHANGED
|
@@ -92,13 +92,47 @@ export class SerialDevice {
|
|
|
92
92
|
|
|
93
93
|
async writeLine(line) {
|
|
94
94
|
const data = `${line.replace(/[\r\n]+$/, '')}\n`
|
|
95
|
-
await
|
|
96
|
-
await new Promise((resolve) => this.port.drain(() => resolve()))
|
|
95
|
+
await this.writeRaw(data)
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
async writeRaw(data) {
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
if (this.error) throw this.error
|
|
100
|
+
if (this.closed) throw new Error(`serial device ${this.path} is closed`)
|
|
101
|
+
// A USB removal can leave write/drain callbacks permanently pending.
|
|
102
|
+
// Keep a referenced deadline and reject on lifecycle events so callers can
|
|
103
|
+
// still release remote resources when the physical transport disappears.
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
let settled = false
|
|
106
|
+
const finish = (error) => {
|
|
107
|
+
if (settled) return
|
|
108
|
+
settled = true
|
|
109
|
+
clearTimeout(timer)
|
|
110
|
+
this.port.removeListener('close', closed)
|
|
111
|
+
this.port.removeListener('error', failed)
|
|
112
|
+
if (error) reject(error)
|
|
113
|
+
else resolve()
|
|
114
|
+
}
|
|
115
|
+
const closed = () => finish(new Error(`serial device ${this.path} closed during write`))
|
|
116
|
+
const failed = (error) => finish(error)
|
|
117
|
+
const timer = setTimeout(() => finish(new Error(`serial write timed out for ${this.path}`)), 5000)
|
|
118
|
+
this.port.once('close', closed)
|
|
119
|
+
this.port.once('error', failed)
|
|
120
|
+
try {
|
|
121
|
+
this.port.write(data, (error) => {
|
|
122
|
+
if (settled) return
|
|
123
|
+
if (error) finish(error)
|
|
124
|
+
else {
|
|
125
|
+
try {
|
|
126
|
+
this.port.drain((error) => finish(error))
|
|
127
|
+
} catch (error) {
|
|
128
|
+
finish(error)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
} catch (error) {
|
|
133
|
+
finish(error)
|
|
134
|
+
}
|
|
135
|
+
})
|
|
102
136
|
}
|
|
103
137
|
|
|
104
138
|
async readLine(timeoutMs) {
|
|
@@ -381,6 +415,34 @@ export const geadev = {
|
|
|
381
415
|
return `${line} (${data.length} bytes in ${seconds.toFixed(1)}s, ${Math.round(data.length / Math.max(seconds, 0.001) / 1024)} KiB/s)`
|
|
382
416
|
},
|
|
383
417
|
|
|
418
|
+
// Installs an app image through the running app (GEADEV OTA): it lands in
|
|
419
|
+
// the next OTA slot and the board restarts into it. Same throttled raw
|
|
420
|
+
// stream as pushFile.
|
|
421
|
+
async otaUpdate(d, source, { timeoutMs = 120000, stderr = () => {} } = {}) {
|
|
422
|
+
const data = readFileSync(source)
|
|
423
|
+
await d.writeLine(`GEADEV OTA ${data.length} ${crc32(data)}`)
|
|
424
|
+
const ready = await waitFor(d, 'GEADEV:OTA READY', 'GEADEV:OTA ERR', 15000, 'OTA READY')
|
|
425
|
+
const startedAt = Date.now()
|
|
426
|
+
await new Promise((resolve) => setTimeout(resolve, 300))
|
|
427
|
+
const burst = 2048
|
|
428
|
+
for (let offset = 0; offset < data.length; offset += burst) {
|
|
429
|
+
await d.writeRaw(data.subarray(offset, Math.min(offset + burst, data.length)))
|
|
430
|
+
await new Promise((resolve) => setTimeout(resolve, 4))
|
|
431
|
+
if (((offset / burst) | 0) % 128 === 0) stderr(` upload ${Math.floor((offset * 100) / data.length)}%`)
|
|
432
|
+
}
|
|
433
|
+
let line
|
|
434
|
+
try {
|
|
435
|
+
line = await waitFor(d, 'GEADEV:OTA OK', 'GEADEV:OTA ERR', timeoutMs, 'OTA OK')
|
|
436
|
+
} catch (error) {
|
|
437
|
+
// The board restarts right after the reply, and firmware whose console
|
|
438
|
+
// drops output on a full TX FIFO can lose it; the caller decides from
|
|
439
|
+
// what boots.
|
|
440
|
+
if (!error.message.startsWith('GEADEV:OTA ERR')) error.uploaded = true
|
|
441
|
+
throw error
|
|
442
|
+
}
|
|
443
|
+
return { ready, line, bytes: data.length, seconds: (Date.now() - startedAt) / 1000 }
|
|
444
|
+
},
|
|
445
|
+
|
|
384
446
|
async pullFile(d, source, destination, { timeoutMs = 300000 } = {}) {
|
|
385
447
|
const { chunks, end, lines } = await d.collect(`GEADEV PULL ${source}`, {
|
|
386
448
|
begin: null,
|
package/src/esp32/build.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { appCmakeMeta, appCmakeLdFragments, appTargetConfig, appTargetPaths } fr
|
|
|
9
9
|
import { quietSteps, runQuiet } from '../run.mjs'
|
|
10
10
|
import { resolveAppCapabilities, withRendererFeatureDefines } from './capabilities.mjs'
|
|
11
11
|
import { activateEspIdf, idfPyCommand } from './idf-env.mjs'
|
|
12
|
+
import { espIdfVersionForTarget } from './idf-version.mjs'
|
|
12
13
|
import { Sdkconfig, prepareBuildLocalSdkconfig } from './sdkconfig.mjs'
|
|
13
14
|
import { writePartitionTable } from './partitions-from-manifest.mjs'
|
|
14
15
|
import { listAppSources } from './source-set.mjs'
|
|
@@ -48,15 +49,19 @@ export function buildImages(buildDir) {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
export function requireEspIdf(env, log) {
|
|
52
|
+
export function requireEspIdf(env, log, selection = null) {
|
|
53
|
+
const defaultVersion = espIdfVersionForTarget(selection?.target)
|
|
52
54
|
let idf
|
|
53
55
|
try {
|
|
54
|
-
idf = activateEspIdf({ env, log })
|
|
56
|
+
idf = activateEspIdf({ env, log, defaultVersion })
|
|
55
57
|
} catch (error) {
|
|
56
58
|
fail(error.message, ExitCode.missingDependency)
|
|
57
59
|
}
|
|
58
60
|
if (!idf) {
|
|
59
|
-
fail(
|
|
61
|
+
fail(
|
|
62
|
+
`ESP-IDF ${defaultVersion} was not found${selection?.target ? ` for target '${selection.target}'` : ''}. Install it under ~/esp32/esp-idf-v${defaultVersion} and run its install.sh (install.bat on Windows), or set IDF_PATH to another installation.`,
|
|
63
|
+
ExitCode.missingDependency
|
|
64
|
+
)
|
|
60
65
|
}
|
|
61
66
|
return idf
|
|
62
67
|
}
|
|
@@ -549,7 +554,7 @@ function runInTarget(command, args, { cwd, env, dryRun, verbose, label, logFile,
|
|
|
549
554
|
// system's responsibility. This retains Ninja's sub-second no-op.
|
|
550
555
|
export async function ensureConfigured({ idf, prepared, env, dryRun = false, verbose = false, stdout, stderr = console.error }) {
|
|
551
556
|
const signatureFile = path.join(prepared.buildDir, '.gea-configure-args')
|
|
552
|
-
const signature = [`-DSDKCONFIG=${prepared.sdkconfigFile}`, `-DSDKCONFIG_DEFAULTS=${prepared.defaultsArg || prepared.defaultsFile}`, ...prepared.idfArgs, ...(prepared.sourceSet || [])].join('\n') + '\n'
|
|
557
|
+
const signature = [`IDF_PATH=${idf.idfDir}`, `IDF_PYTHON_ENV_PATH=${idf.pythonEnv}`, `-DSDKCONFIG=${prepared.sdkconfigFile}`, `-DSDKCONFIG_DEFAULTS=${prepared.defaultsArg || prepared.defaultsFile}`, ...prepared.idfArgs, ...(prepared.sourceSet || [])].join('\n') + '\n'
|
|
553
558
|
if (existsSync(path.join(prepared.buildDir, 'CMakeCache.txt')) && existsSync(signatureFile) && readFileSync(signatureFile, 'utf8') === signature) {
|
|
554
559
|
return false
|
|
555
560
|
}
|
|
@@ -623,7 +628,7 @@ export async function buildEsp32Firmware({ ctx, selection, app = null, env = ctx
|
|
|
623
628
|
// dim line; the spinner labels name each phase.
|
|
624
629
|
const quiet = quietSteps(env, verbose)
|
|
625
630
|
const detail = quiet ? () => {} : stdout
|
|
626
|
-
const idf = requireEspIdf(env, detail)
|
|
631
|
+
const idf = requireEspIdf(env, detail, selection)
|
|
627
632
|
const prepared = prepareEsp32Build({ ctx, selection, app, env: idf.env, log: detail, bleOta, dryRun })
|
|
628
633
|
prepared.targetDir = selection.targetDir
|
|
629
634
|
if (quiet) hint(stdout, buildSummaryLine(idf, selection, prepared.capabilities))
|
package/src/esp32/flash.mjs
CHANGED
|
@@ -70,7 +70,7 @@ export async function runEsptoolOverUsb({ idf, selection, options, args, port =
|
|
|
70
70
|
}
|
|
71
71
|
const flashPort = dryRun
|
|
72
72
|
? port || `<usb serial ${selection.usbSerial}>`
|
|
73
|
-
: await waitForSerialPort({ port, serial: selection.usbSerial, timeoutSeconds: remaining, label: 'ESP32 USB flash port', log: stderr })
|
|
73
|
+
: await waitForSerialPort({ port, serial: selection.usbSerial, timeoutSeconds: remaining, label: 'ESP32 USB flash port', log: stderr, env })
|
|
74
74
|
if (options.before === 'no-reset') {
|
|
75
75
|
stdout('Manual boot mode: hold BOOT/IO0, reset or power-cycle the board, then keep BOOT held until esptool connects.')
|
|
76
76
|
stdout('Manual boot mode: esptool will not toggle reset before connecting.')
|
package/src/esp32/idf-env.mjs
CHANGED
|
@@ -43,13 +43,38 @@ function compareVersions(a, b) {
|
|
|
43
43
|
return 0
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
// A checkout of an unreleased IDF line (master, a release candidate) is named
|
|
47
|
+
// for it: `esp-idf-v6.2-dev`, `esp-idf-v6.1-rc1`. Its version.cmake already
|
|
48
|
+
// reads like the release, so the name is the only thing that tells it apart.
|
|
49
|
+
function isPrereleaseIdf(dir) {
|
|
50
|
+
return /-(dev|rc\d*|beta\d*|master)$/i.test(path.basename(dir))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function meetsMinimum(dir, minimum) {
|
|
54
|
+
if (!minimum) return true
|
|
55
|
+
const want = minimum.split('.').map((part) => Number(part) || 0)
|
|
56
|
+
return compareVersions(versionKey(dir), [want[0] || 0, want[1] || 0, 0]) >= 0
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function matchesDefaultVersion(dir, defaultVersion) {
|
|
60
|
+
if (!defaultVersion) return true
|
|
61
|
+
const version = espIdfVersion(dir)
|
|
62
|
+
if (defaultVersion.endsWith('-dev')) {
|
|
63
|
+
return version?.majorMinor === defaultVersion.slice(0, -4) && /-dev$/i.test(path.basename(dir))
|
|
64
|
+
}
|
|
65
|
+
return version?.full === defaultVersion && !isPrereleaseIdf(dir)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Generic discovery honours explicit settings and otherwise prefers the
|
|
69
|
+
// newest stable installation. Callers can request a minimum version instead.
|
|
70
|
+
// Builds provide an exact defaultVersion for automatic discovery. IDF_PATH
|
|
71
|
+
// overrides that default; export-script hints must still match the target.
|
|
72
|
+
export function findEspIdf(env = process.env, home = os.homedir(), { minVersion = '', defaultVersion = '' } = {}) {
|
|
73
|
+
const accepts = (dir) => meetsMinimum(dir, minVersion) && matchesDefaultVersion(dir, defaultVersion)
|
|
74
|
+
if (isIdfDir(env.IDF_PATH) && meetsMinimum(env.IDF_PATH, minVersion)) return path.resolve(env.IDF_PATH)
|
|
75
|
+
const explicit = [envExportDir(env.GEA_EMBEDDED_IDF_EXPORT), envExportDir(env.ESP_IDF_EXPORT)]
|
|
51
76
|
for (const candidate of explicit) {
|
|
52
|
-
if (isIdfDir(candidate)) return path.resolve(candidate)
|
|
77
|
+
if (isIdfDir(candidate) && accepts(candidate)) return path.resolve(candidate)
|
|
53
78
|
}
|
|
54
79
|
const roots = [path.join(home, 'esp'), path.join(home, 'esp32'), home]
|
|
55
80
|
const found = []
|
|
@@ -72,7 +97,9 @@ export function findEspIdf(env = process.env, home = os.homedir()) {
|
|
|
72
97
|
}
|
|
73
98
|
if (found.length === 0) return ''
|
|
74
99
|
found.sort((a, b) => compareVersions(versionKey(b), versionKey(a)))
|
|
75
|
-
return found
|
|
100
|
+
if (defaultVersion) return found.find(accepts) || ''
|
|
101
|
+
if (minVersion) return found.find((dir) => meetsMinimum(dir, minVersion)) || ''
|
|
102
|
+
return found.find((dir) => !isPrereleaseIdf(dir)) || found[0]
|
|
76
103
|
}
|
|
77
104
|
|
|
78
105
|
function envExportDir(exportScript) {
|
|
@@ -92,9 +119,10 @@ export function idfVenvPython(pythonEnv) {
|
|
|
92
119
|
}
|
|
93
120
|
|
|
94
121
|
export function findIdfPythonEnv(idfDir, env = process.env, home = os.homedir()) {
|
|
95
|
-
const explicit = env.IDF_PYTHON_ENV_PATH
|
|
96
|
-
if (explicit && existsSync(idfVenvPython(explicit))) return explicit
|
|
97
122
|
const version = espIdfVersion(idfDir)?.majorMinor
|
|
123
|
+
const explicit = env.IDF_PYTHON_ENV_PATH
|
|
124
|
+
const explicitVersion = explicit && path.basename(explicit).match(/^idf(\d+\.\d+)_py/)?.[1]
|
|
125
|
+
if (explicit && (!explicitVersion || explicitVersion === version) && existsSync(idfVenvPython(explicit))) return explicit
|
|
98
126
|
if (!version) return ''
|
|
99
127
|
const envRoot = path.join(env.IDF_TOOLS_PATH || path.join(home, '.espressif'), 'python_env')
|
|
100
128
|
let entries = []
|
|
@@ -130,10 +158,15 @@ const activationCache = new Map()
|
|
|
130
158
|
// The tool export is cached per installation; the caller's environment is
|
|
131
159
|
// layered on fresh every time so per-invocation settings (jobs, variants,
|
|
132
160
|
// flash baud) are never frozen into a cached activation.
|
|
133
|
-
export function activateEspIdf({ env = process.env, home = os.homedir(), log = () => {} } = {}) {
|
|
134
|
-
const idfDir = findEspIdf(env, home)
|
|
161
|
+
export function activateEspIdf({ env = process.env, home = env.HOME || env.USERPROFILE || os.homedir(), log = () => {}, minVersion = '', defaultVersion = '' } = {}) {
|
|
162
|
+
const idfDir = findEspIdf(env, home, { minVersion, defaultVersion })
|
|
135
163
|
if (!idfDir) return null
|
|
136
|
-
|
|
164
|
+
// A venv exported by a different active checkout belongs to that checkout.
|
|
165
|
+
const activeIdf = env.IDF_PATH || envExportDir(env.GEA_EMBEDDED_IDF_EXPORT) || envExportDir(env.ESP_IDF_EXPORT)
|
|
166
|
+
const pythonEnvSettings = defaultVersion && activeIdf && path.resolve(activeIdf) !== idfDir
|
|
167
|
+
? { ...env, IDF_PYTHON_ENV_PATH: '' }
|
|
168
|
+
: env
|
|
169
|
+
const pythonEnv = findIdfPythonEnv(idfDir, pythonEnvSettings, home)
|
|
137
170
|
if (!pythonEnv) {
|
|
138
171
|
const envRoot = path.join(env.IDF_TOOLS_PATH || path.join(home, '.espressif'), 'python_env')
|
|
139
172
|
throw new Error(
|
|
@@ -149,7 +182,7 @@ export function activateEspIdf({ env = process.env, home = os.homedir(), log = (
|
|
|
149
182
|
exported = parseKeyValueExport(
|
|
150
183
|
execFileSync(python, [idfToolsPy, 'export', '--format', 'key-value'], {
|
|
151
184
|
encoding: 'utf8',
|
|
152
|
-
env: { ...env, IDF_PATH: idfDir },
|
|
185
|
+
env: { ...env, IDF_PATH: idfDir, IDF_PYTHON_ENV_PATH: pythonEnv },
|
|
153
186
|
stdio: ['ignore', 'pipe', 'ignore']
|
|
154
187
|
})
|
|
155
188
|
)
|
|
@@ -157,8 +190,8 @@ export function activateEspIdf({ env = process.env, home = os.homedir(), log = (
|
|
|
157
190
|
throw new Error(`ESP-IDF tool export failed for ${idfDir}: ${error.message}`)
|
|
158
191
|
}
|
|
159
192
|
activationCache.set(cacheKey, exported)
|
|
160
|
-
log(`Using ESP-IDF ${espIdfVersion(idfDir)?.full || ''} at ${idfDir} (python env ${pythonEnv})`)
|
|
161
193
|
}
|
|
194
|
+
log(`Using ESP-IDF ${espIdfVersion(idfDir)?.full || ''} at ${idfDir} (python env ${pythonEnv})`)
|
|
162
195
|
const callerPath = envPath(env)
|
|
163
196
|
const exportedPath = (exported.PATH || '').replace(/\$PATH|%PATH%/g, callerPath)
|
|
164
197
|
return {
|
|
@@ -15,6 +15,11 @@ const VERSION_IN_TEXT = /v?(\d+)\.(\d+)\.(\d+)/i
|
|
|
15
15
|
// Bump this alongside board-script updates.
|
|
16
16
|
export const DEFAULT_ESP_IDF_VERSION = 'v6.0.2'
|
|
17
17
|
|
|
18
|
+
// Automatic build selection is target-specific; IDF_PATH can override it.
|
|
19
|
+
export function espIdfVersionForTarget(target) {
|
|
20
|
+
return target === 'esp32-s31-espressif-mosaico' ? '6.2-dev' : DEFAULT_ESP_IDF_VERSION.slice(1)
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
const GITHUB_LATEST_RELEASE_URL = 'https://api.github.com/repos/espressif/esp-idf/releases/latest'
|
|
19
24
|
|
|
20
25
|
// Parses a strict `vX.Y.Z` release tag. Returns null for anything else,
|
package/src/manifest.mjs
CHANGED
|
@@ -182,8 +182,16 @@ export function appRootFor(ctx, app) {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// `root;entry;runtime;nativeSource...` -- the one line CMake splits on ';'.
|
|
185
|
+
// Every target joins a native source onto the app root, so a source named by
|
|
186
|
+
// package (`@scope/pkg/native/x.cpp`) goes out as its resolved file relative to
|
|
187
|
+
// that root; an app-relative source is unchanged.
|
|
185
188
|
export function appCmakeMeta(ctx, app) {
|
|
186
|
-
|
|
189
|
+
const root = appRootFor(ctx, app)
|
|
190
|
+
const nativeSources = app.nativeSources.map((source) => {
|
|
191
|
+
const resolved = resolveAppSourcePath(app.root, source)
|
|
192
|
+
return resolved && resolved !== path.resolve(app.root, source) ? path.relative(root, resolved).split(path.sep).join('/') : source
|
|
193
|
+
})
|
|
194
|
+
return [root, app.entry, app.runtime, ...nativeSources].join(';')
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
// Defines and linker fragments travel in their own variables rather than being
|