Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 28, 2024
1 parent 55ac253 commit 242aa65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,14 +965,10 @@ class Device extends DeviceBase {
async getProtectionState() {
if (this.isInDfuMode) {
let allSegmentsProtected = true;
const memMap = await this._dfu.getMemoryMap();
memMap.forEach(m => {
if (m.name === 'Internal Flash') {
m.segments.forEach(s => {
if (!(s.erasable === true && s.writable === false && s.readable === false)) {
allSegmentsProtected = false;
}
});
const memInfo = await this._dfu.getSegmentForInternalFlash();
memInfo.segments.forEach(s => {
if (!(s.erasable === true && s.writable === false && s.readable === false)) {
allSegmentsProtected = false;
}
});
// FIXME: Currently, device-os does not reliably distinguish the `overridden` value for different protection modes.
Expand Down
10 changes: 3 additions & 7 deletions src/dfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,9 @@ class Dfu {
await this._pollUntil((state) => state === DfuDeviceState.dfuMANIFEST);
}

async getMemoryMap() {
for (const i of this._allInterfaces) {
const ifaceName = await this._getStringDescriptor(i.iInterface);
const memInfo = this._parseMemoryDescriptor(ifaceName);
this._memoryMap.push(memInfo);
}
return this._memoryMap;
async getSegmentForInternalFlash() {
await this.setAltSetting(0);
return this._memoryInfo;
}

/**
Expand Down

0 comments on commit 242aa65

Please sign in to comment.