Skip to content

Commit

Permalink
Enable default firmware flashing for the Atreus and Model 01
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Dec 1, 2023
1 parent 754890b commit 94b7535
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion product-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This is an *early test release* of the next version of Chrysalis, the graphical
## What doesn't work

- Firmware updates for the Model 100
- Loading stock firmware for the Atreus and Model 01
- Loading "pre-configured" layouts
- Device disconnect detection
- Backup and restore (outside of flashing)
Expand All @@ -17,6 +16,7 @@ This is an *early test release* of the next version of Chrysalis, the graphical
- Changing device settings
- Factory reset
- Custom firmware updates for the Atreus and Model 01
- Loading stock firmware for the Atreus and Model 01

## Device support

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/api/flash/AVR109Flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const encoder = new TextEncoder();

const flash = async (port, filecontents) => {
var enc = new TextDecoder("utf-8");
console.log("filecontents");
console.log(filecontents);

var hexAsText = enc.decode(filecontents);
return new Promise((resolve, reject) => {
(async () => {
Expand Down
37 changes: 31 additions & 6 deletions src/renderer/screens/FirmwareUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,34 @@ const FirmwareUpdate = (props) => {

const NOTIFICATION_THRESHOLD = 5;

const defaultFirmwareFilename = () => {
const loadDefaultFirmwareContent = async () => {
const { vendor, product } = focusDeviceDescriptor.info;
const firmwareType = focusDeviceDescriptor.info.firmwareType || "hex";
const cVendor = vendor.replace("/", ""),
cProduct = product.replace("/", "");
return cVendor + "/" + cProduct + "/default." + firmwareType;
const firmwareURL = `/assets/firmware/${cVendor}/${cProduct}/default.${firmwareType}`;

let defaultFirmwareContent;
try {
const response = await fetch(firmwareURL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const firmwareBlob = await response.blob();
defaultFirmwareContent = await firmwareBlob.arrayBuffer();
} catch (err) {
console.error(`Failed to fetch firmware file from ${firmwareURL}:`, err);
throw err;
}
console.log("Firmware content", defaultFirmwareContent);

setFirmwareContent(defaultFirmwareContent);
return defaultFirmwareContent;
};

const doFactoryReset = async () => {
const tasksInBootloaderMode = async () => {
await flashDeviceFirmwareFromBootloader(firmwareContent);
await flashDeviceFirmwareFromBootloader();

await onStepChange("reconnect");

Expand All @@ -121,13 +138,21 @@ const FirmwareUpdate = (props) => {
const flashDeviceFirmwareFromBootloader = async () => {
const flasher = activeDevice.getFlasher();
await onStepChange("flash");
let firmwareToSend = firmwareContent;
console.log(focus);
await flasher.flash(focus._port, firmwareContent);
if (selectedFirmwareType == "default") {
firmwareToSend = await loadDefaultFirmwareContent();
}
console.log("about to flash");
console.log(" firmware content is ", firmwareToSend);
await flasher.flash(focus._port, firmwareToSend);
};

const updateDeviceFirmware = async () => {
// If the user selected the factory firmware, we need to fetch it from the
// server. Otherwise, we'll use the file the user uploaded.
if (activeDevice.bootloaderDetected()) {
await flashDeviceFirmwareFromBootloader(firmwareContent);
await flashDeviceFirmwareFromBootloader();
return;
} else {
await onStepChange("saveEEPROM");
Expand All @@ -137,7 +162,7 @@ const FirmwareUpdate = (props) => {
const tasksInBootloaderMode = async () => {
console.trace();
console.log("Runing tasks in bootloader mode");
await flashDeviceFirmwareFromBootloader(firmwareContent);
await flashDeviceFirmwareFromBootloader();
console.log("flashed device firmware");
await onStepChange("reconnect");

Expand Down

0 comments on commit 94b7535

Please sign in to comment.