Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safely flash bootloader firmware to both slots #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,24 @@ async function tryFlashImages(
let pattern = new RegExp(`${imageName}(?:-.+)?\\.img$`);
let entry = entries.find((entry) => entry.filename.match(pattern));
if (entry !== undefined) {
await flashEntryBlob(device, entry, onProgress, imageName);
if (imageName == "bootloader") {
let current_slot = await device.getVariable("current-slot");
if (current_slot == "a") {
await flashEntryBlob(device, entry, onProgress, (imageName + "_b"));
await device.runCommand("set_active:b");
} else if (current_slot == "b") {
await flashEntryBlob(device, entry, onProgress, (imageName + "_a"));
await device.runCommand("set_active:a");
} else {
throw new FastbootError(
"FAIL",
`Invalid slot given by bootloader.`
);
}
}
else {
await flashEntryBlob(device, entry, onProgress, imageName);
}
}
}
}
Expand Down Expand Up @@ -217,7 +234,16 @@ export async function flashZip(
await device.reboot("bootloader", true, onReconnect);
}

// 1. Bootloader pack
// 1. Bootloader pack (repeated for slot A and B)
await tryFlashImages(device, entries, onProgress, ["bootloader"]);
await common.runWithTimedProgress(
onProgress,
"reboot",
"device",
BOOTLOADER_REBOOT_TIME,
tryReboot(device, "bootloader", onReconnect)
);

await tryFlashImages(device, entries, onProgress, ["bootloader"]);
await common.runWithTimedProgress(
onProgress,
Expand Down