Skip to content

Commit

Permalink
flash critical images to both slots (#99)
Browse files Browse the repository at this point in the history
* flash critical images to both slots

* improve progress reporting

* revert
  • Loading branch information
incognitojam authored Feb 11, 2025
1 parent 3d9ac9e commit de28964
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/utils/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,26 @@ export function useQdl() {
// with corrupted primary gpt header, it would not update the backup
await qdl.current.erase(`xbl_${currentSlot}`)

for await (const [image, onProgress] of withProgress(manifest.current, setProgress)) {
/** @type {[Image, string][]} */
const steps = []
const findImage = (name) => manifest.current.find((it) => it.name === name)

// Flash aop, abl, xbl, xbl_config, devcfg to both slots
for (const name of ['aop', 'abl', 'xbl', 'xbl_config', 'devcfg']) {
const image = findImage(name)
steps.push([image, `${name}_a`], [image, `${name}_b`])
}

// Flash boot, system to other slot
for (const name of ['boot', 'system']) {
const image = findImage(name)
steps.push([image, `${name}_${otherSlot}`])
}

for (const [[image, partitionName], onProgress] of withProgress(steps, setProgress, ([image]) => Math.sqrt(image.size))) {
const fileHandle = await imageWorker.current.getImage(image)
const blob = await fileHandle.getFile()

setMessage(`Flashing ${image.name}`)
const partitionName = `${image.name}_${otherSlot}`
setMessage(`Flashing ${partitionName}`)
await qdl.current.flashBlob(partitionName, blob, onProgress)
}
console.debug('[QDL] Flashed all partitions')
Expand Down
14 changes: 12 additions & 2 deletions src/utils/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ export function createSteps(steps, onProgress) {
})
}

/**
* Step weight callback
*
* @template T
* @callback weightCallback
* @param {T} step
* @returns {number}
*/

/**
* Iterate over a list of steps while reporting progress.
* @template T
* @param {T[]} steps
* @param {progressCallback} onProgress
* @param {weightCallback} [getStepWeight]
* @returns {([T, progressCallback])[]}
*/
export function withProgress(steps, onProgress) {
export function withProgress(steps, onProgress, getStepWeight) {
const callbacks = createSteps(
steps.map(step => typeof step === 'number' ? step : step.size || step.length || 1),
steps.map(getStepWeight || (step => typeof step === 'number' ? step : step.size || step.length || 1)),
onProgress,
)
return steps.map((step, idx) => [step, callbacks[idx]])
Expand Down

0 comments on commit de28964

Please sign in to comment.