@geastack/cli 0.1.93 → 0.1.95

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.93",
3
+ "version": "0.1.95",
4
4
  "description": "Command-line front door for GeaStack apps, targets, and local toolchains.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,8 +37,8 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@clack/prompts": "^1.8.0",
40
- "@geastack/simulator": "^0.1.13",
41
- "@geastack/targets": "^0.1.88",
40
+ "@geastack/simulator": "^0.1.14",
41
+ "@geastack/targets": "^0.1.93",
42
42
  "picocolors": "^1.1.1",
43
43
  "serialport": "^13.0.0"
44
44
  },
@@ -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',
@@ -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,
@@ -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'
@@ -163,7 +163,7 @@ async function flashEsp32(ctx, parsed, rest, options, selection, { monitor }) {
163
163
  const env = createChildEnv(ctx, base.env)
164
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)
@@ -415,6 +415,34 @@ export const geadev = {
415
415
  return `${line} (${data.length} bytes in ${seconds.toFixed(1)}s, ${Math.round(data.length / Math.max(seconds, 0.001) / 1024)} KiB/s)`
416
416
  },
417
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
+
418
446
  async pullFile(d, source, destination, { timeoutMs = 300000 } = {}) {
419
447
  const { chunks, end, lines } = await d.collect(`GEADEV PULL ${source}`, {
420
448
  begin: null,
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
- return [appRootFor(ctx, app), app.entry, app.runtime, ...app.nativeSources].join(';')
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