Skip to content

Commit b96dc18

Browse files
committed
Update files (that don't need translation) from recent Pull Requests from @adeebshihadeh
1 parent 09765a9 commit b96dc18

File tree

12 files changed

+111
-19
lines changed

12 files changed

+111
-19
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ bun dev
1616
Open [http://localhost:5173](http://localhost:5173) with your browser to see the result.
1717

1818
You can start editing the page by modifying `src/app/index.jsx`. The page auto-updates as you edit the file.
19+
20+
21+
**Helpful for debugging**
22+
* [chrome://usb-internals/](chrome://usb-internals/)
23+
* [chrome://device-log/](chrome://device-log/)
24+
* Add `?fast=1` to the URL to skip flashing the system partition (the slowest). Useful for testing the full flow quickly.
25+
* Add `?windows=1` to the URL to force Windows mode (shows Zadig driver instructions). Useful for testing the Windows flow on other platforms.

deploy-preview.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
BRANCH="${1:-$(git branch --show-current)}"
5+
6+
bun run build
7+
bunx wrangler pages deploy dist --project-name=connect --branch="$BRANCH"
8+
9+
echo ""
10+
echo "Preview URL: https://${BRANCH}.connect-d5y.pages.dev"

src/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta
88
name="description"
9-
content="Update your comma device to the latest software"
9+
content="Restore your comma device to a fresh factory state"
1010
/>
1111
<title>flash.comma.ai</title>
1212
%sveltekit.head%

src/lib/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const config = {
33
release_mici: 'https://raw.githubusercontent.com/commaai/openpilot/ccf7361798a2b7ff36f5065dffb602eb40c22302/system/hardware/tici/all-partitions.json',
44
release_tizi: 'https://raw.githubusercontent.com/commaai/openpilot/927548621be1be0c2c9063868b93d1f5020904de/system/hardware/tici/all-partitions.json',
55
release_tici: 'https://raw.githubusercontent.com/commaai/openpilot/927548621be1be0c2c9063868b93d1f5020904de/system/hardware/tici/all-partitions.json',
6-
master: 'https://raw.githubusercontent.com/commaai/openpilot/master/system/hardware/tici/all-partitions.json',
76
},
87
loader: {
98
url: 'https://raw.githubusercontent.com/commaai/flash/master/src/QDL/programmer.bin',

src/lib/images/comma3X.webp

52.4 KB
Loading

src/lib/images/four_screen_on.webp

90.9 KB
Loading

src/lib/images/qdl-ports-four.svg

Lines changed: 1 addition & 1 deletion
Loading

src/lib/images/qdl-ports-three.svg

Lines changed: 1 addition & 1 deletion
Loading

src/lib/utils/image.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { fetchStream } from "./stream";
99
* @returns {void}
1010
*/
1111

12-
const MIN_QUOTA_MB = 5250;
12+
const MIN_QUOTA_GB = 5.25;
1313

1414
export class ImageManager {
1515
/** @type {FileSystemDirectoryHandle} */
@@ -18,14 +18,22 @@ export class ImageManager {
1818
async init() {
1919
if (!this.root) {
2020
this.root = await globalThis.navigator.storage.getDirectory()
21-
await this.root.remove({ recursive: true })
21+
// Clean up any leftover files from previous sessions
22+
try {
23+
await this.root.remove({ recursive: true })
24+
} catch (e) {
25+
// Ignore errors - directory might not exist or be empty
26+
console.debug('[ImageManager] Could not remove old directory:', e)
27+
}
28+
// Re-get the directory after removal
29+
this.root = await navigator.storage.getDirectory()
2230
console.info('[ImageManager] Initialized')
2331
}
2432

2533
const estimate = await globalThis.navigator.storage.estimate()
26-
const quotaMB = (estimate.quota || 0) / (1024 ** 2)
27-
if (quotaMB < MIN_QUOTA_MB) {
28-
throw new Error(`Not enough storage: ${quotaMB.toFixed(0)}MB free, need ${MIN_QUOTA_MB.toFixed(0)}MB`)
34+
const quotaGB = (estimate.quota || 0) / (1024 ** 3)
35+
if (quotaGB < MIN_QUOTA_GB) {
36+
throw new Error(`Not enough storage: ${quotaGB.toFixed(1)}GB free, need ${MIN_QUOTA_GB.toFixed(1)}GB`)
2937
}
3038
}
3139

src/lib/utils/manager.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ import { getManifest } from './manifest'
55
import config from '../config'
66
import { createSteps, withProgress } from './progress'
77

8+
// Fast mode for development - skips flashing system partition (the slowest)
9+
// Enable with ?fast=1 in URL
10+
const FAST_MODE = new URLSearchParams(window.location.search).has('fast')
11+
if (FAST_MODE) {
12+
console.warn('[Flash] FAST MODE ENABLED - skipping system partition')
13+
}
14+
815
export const StepCode = {
916
INITIALIZING: 0,
1017
READY: 1,
11-
CONNECTING: 2,
12-
REPAIR_PARTITION_TABLES: 3,
13-
ERASE_DEVICE: 4,
14-
FLASH_SYSTEM: 5,
15-
FINALIZING: 6,
16-
DONE: 7,
18+
DEVICE_PICKER: 2,
19+
CONNECTING: 3,
20+
REPAIR_PARTITION_TABLES: 4,
21+
ERASE_DEVICE: 5,
22+
FLASH_SYSTEM: 6,
23+
FINALIZING: 7,
24+
DONE: 8,
25+
}
26+
27+
// Device types for the picker
28+
export const DeviceType = {
29+
COMMA_3: 'comma3', // comma 3 or 3X
30+
COMMA_4: 'comma4', // comma four
1731
}
1832

1933
export const ErrorCode = {
@@ -181,9 +195,10 @@ export class FlashManager {
181195
} catch (err) {
182196
console.error('[Flash] Failed to initialize image worker')
183197
console.error(err)
184-
if (err instanceof String && err.startsWith('Not enough storage')) {
198+
const message = err?.message || String(err)
199+
if (message.startsWith('Not enough storage')) {
185200
this.#setError(ErrorCode.STORAGE_SPACE)
186-
this.#setMessage(err)
201+
this.#setMessage(message)
187202
} else {
188203
this.#setError(ErrorCode.UNKNOWN)
189204
}
@@ -210,6 +225,12 @@ export class FlashManager {
210225
try {
211226
await this.device.connect(usb)
212227
} catch (err) {
228+
// User cancelled the WebUSB dialog or no device was selected - not an error
229+
if (err.name === 'NotFoundError') {
230+
console.info('[Flash] No device selected')
231+
this.#setStep(StepCode.READY)
232+
return
233+
}
213234
console.error('[Flash] Connection error', err)
214235
this.#setError(ErrorCode.LOST_CONNECTION)
215236
this.#setConnected(false)
@@ -353,10 +374,16 @@ export class FlashManager {
353374
this.#setProgress(0)
354375

355376
// Exclude GPT images and persist image, and pick correct userdata image to flash
356-
const systemImages = this.manifest
377+
let systemImages = this.manifest
357378
.filter((image) => !image.gpt && image.name !== 'persist')
358379
.filter((image) => !image.name.startsWith('userdata_') || image.name === this.#userdataImage)
359380

381+
// In fast mode, skip the system partition (slowest to flash)
382+
if (FAST_MODE) {
383+
systemImages = systemImages.filter((image) => image.name !== 'system')
384+
console.info('[Flash] Fast mode: skipping system partition')
385+
}
386+
360387
if (!systemImages.find((image) => image.name === this.#userdataImage)) {
361388
console.error(`[Flash] Did not find userdata image "${this.#userdataImage}"`)
362389
this.#setError(ErrorCode.UNKNOWN)
@@ -414,7 +441,8 @@ export class FlashManager {
414441
async start() {
415442
if (this.step !== StepCode.READY) return
416443
await this.#connect()
417-
if (this.error !== ErrorCode.NONE) return
444+
// Check if connection was cancelled (step went back to READY) or failed
445+
if (this.step === StepCode.READY || this.error !== ErrorCode.NONE) return
418446
let start = performance.now()
419447
await this.#repairPartitionTables()
420448
console.info(`Repaired partition tables in ${((performance.now() - start) / 1000).toFixed(2)}s`)

0 commit comments

Comments
 (0)