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

Fix the asset check code #728

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/lib/flash-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ async function _flashDeviceInNormalMode(device, data, { name, progress, checkSki
}
return device;
}
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes more sense this approach since prepareToFlash always puts the device in listening for nonDFU modes.
I was thinking about a final reset after the whole process could be also a good way to have the device back to normal but would be too much since in all the times the device is being resetting when it flashes something hehe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flashing with control requests resets by itself so it should be in a good state without an extra reset.

await device.enterListeningMode();
await delay(1000); // Just in case
} catch (error) {
// ignore
}
await device.updateFirmware(data, { progress, timeout: FLASH_TIMEOUT });
return device;
} catch (error) {
Expand All @@ -90,12 +96,6 @@ async function prepareDeviceForFlash({ device, mode, progress }) {
}
device = await usbUtils.reopenInNormalMode(device, { reset: true });
}
try {
await device.enterListeningMode();
await delay(1000); // Just in case
} catch (error) {
// ignore
}
break;
case 'dfu':
if (!device.isInDfuMode) {
Expand Down Expand Up @@ -332,8 +332,9 @@ async function createFlashSteps({ modules, isInDfuMode, factory, platformId }) {
}

function _skipAsset(module, existingAssets) {
const name = path.basename(module.filename);
const hashAssetToBeFlashed = _get256Hash(module);
return existingAssets.some((asset) => hashAssetToBeFlashed === asset.hash && module.filename === asset.name);
return existingAssets.some((asset) => hashAssetToBeFlashed === asset.hash && name === asset.name);
}

function _get256Hash(module) {
Expand Down
16 changes: 4 additions & 12 deletions src/lib/flash-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,60 +416,52 @@ describe('flash-helper', () => {
const device = {
isOpen: true,
isInDfuMode: true,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};
reopenInNormalStub.resolves(device);
reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'normal' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInNormalStub).to.have.been.calledOnce;
expect(reopenInDfuModeStub).to.not.have.been.called;
expect(device.enterListeningMode).to.have.been.calledOnce;
});
it('prepares the device when is required for normal mode and currently is in normal mode', async () => {
const device = {
isOpen: true,
isInDfuMode: false,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};

reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'normal' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInNormalStub).to.not.have.been.called;
expect(reopenInDfuModeStub).to.not.have.been.called;
expect(device.enterListeningMode).to.have.been.calledOnce;
});
it('prepares the device when is required for dfu mode and currently is in normal mode', async () => {
const device = {
isOpen: true,
isInDfuMode: false,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};

reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'dfu' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInDfuModeStub).to.have.been.calledOnce;
expect(reopenInNormalStub).to.not.have.been.called;
expect(device.enterListeningMode).to.not.have.been.called;
});
it('prepares the device when is required for dfu mode and currently is in dfu mode', async () => {
const device = {
isOpen: true,
isInDfuMode: true,
close: sinon.stub(),
enterListeningMode: sinon.stub()
close: sinon.stub()
};
reopenStub.resolves(device);
await prepareDeviceForFlash({ device, mode: 'dfu' });
expect(reopenStub).to.have.been.calledOnce;
expect(reopenInDfuModeStub).to.not.have.been.called;
expect(reopenInNormalStub).to.not.have.been.called;
expect(device.enterListeningMode).to.not.have.been.called;
});
});

Expand Down