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

Feature/sc 123873/check hash #693

Merged
merged 13 commits into from
Nov 30, 2023
Merged

Feature/sc 123873/check hash #693

merged 13 commits into from
Nov 30, 2023

Conversation

keeramis
Copy link
Contributor

@keeramis keeramis commented Nov 29, 2023

Description

Currently, particle flash --local command flashes all the assets that are provided by the Particle project or the user app bundle. This PR skips flashing an asset which is already existing on the device. The reason for this change is to improve flashing times, which can be especially beneficial for large projects or when working with devices that have a significant amount of existing assets.

This PR only makes changes to the particle flash --local command and others are unchanged.

How to Test

Setup:

  1. Point particle-usb to this branch: Device::getAssetInfo() and new format in Device::getFirmwareModuleInfo() particle-usb#96
  2. Use device-os this branch on the device: Asset OTA fixes device-os#2711
    • Don't forget to pull submodules

Test:

  1. Create a Particle project with a single asset (say, assetA)
  2. Create a bundle using particle bundle myApp.bin --assets /path/to/assets
  3. Flash it using particle flash --local myApp.zip. Watch the progress
  4. Verify that myApp.bin and assetA are flashed
  5. Add an additional asset to this Particle project (say, assetB)
  6. Create a new bundle using particle bundle myApp.bin --assets /path/to/assets
  7. Flash it using particle flash --local myApp.zip. Watch the progress
  8. Verify that myApp.bin and assetB are flashed. assetA will be skipped with a log message saying Skipping asset assetA because it is already on the device
Flashing p2 0a10aced202194944a02c4d4
Skipping asset random.txt because it is already on the device
[█████████████████████████] 100% | Flashing random2.txt
Flash success!

Related Issues / Discussions

SC: https://app.shortcut.com/particle/story/123873/flash-asset-only-if-it-s-not-existing-on-the-device
Protobuf PR: particle-iot/device-os-protobuf#22
Particle USB PR: particle-iot/particle-usb#96
Device OS PR: particle-iot/device-os#2711

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA
  • Problem and solution clearly stated
  • Tests have been provided
  • Docs have been updated
  • CI is passing

}
} else {
console.log(chalk.red(' ' + assetInfo.name + ' failed' + ' (hash should be ' + assetInfo.hash + ' but is not in the bundle)'));
console.log(chalk.red(' ' + appAsset.name + ' failed' + ' (hash should be ' + appAsset.hash + ' but is not in the bundle)'));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No functional change here. Felt like the readability of this code could be improved.

@keeramis keeramis requested review from monkbroc, hugomontero and avtolstoy and removed request for monkbroc November 29, 2023 01:03
if (asset) {
const valid = isAssetValid(asset.data, assetInfo);
const valid = isAssetValid(asset.data, appAsset);
// isAssetValid();
Copy link
Member

Choose a reason for hiding this comment

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

Reminder to remove commented out code

src/cmd/flash.js Outdated
await flashFiles({ device, flashSteps, ui: this.ui });
}

async _filterAssetsOnDevice(device, modules) {
if (device.isInDfuMode) {
device = await usbUtils.reopenInNormalMode(device, { reset: true });
Copy link
Member

Choose a reason for hiding this comment

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

Let's use a different approach because this makes flashing less reliable. If the application firmware is crashing and someone manually puts the device in DFU mode to reflash it and the CLI reopens it in normal mode, the device will crash before it can get the asset info. This will also call getAssetInfo even in case the application doesn't have assets.

I think we could create the flash steps as if we're flashing all the assets, but in flashFiles when it comes time to flash an asset, call getAssetInfo (cache the result in case there are other assets) and skip calling device.updateFirmware if the asset already exists.

Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

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

Works great!

it ('returns the hash of the file', async () => {
const assetModules = await createAssetModules();

const hash = await _get256Hash(assetModules[0]);
Copy link
Member

Choose a reason for hiding this comment

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

No need for await since _get256Hash and _skipAsset are not async (check for the other uses below too)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. I clicked the Merge button too fast. Fixed in #694


it('skips asset is it is on the device', async () => {
const modules = await createAssetModules();
const asset = modules.filter(m => m.filename === 'asset1.bin')[0];
Copy link
Member

Choose a reason for hiding this comment

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

You can use find instead of filter with [0]

@keeramis keeramis merged commit 985bd24 into master Nov 30, 2023
6 checks passed
@keeramis keeramis mentioned this pull request Nov 30, 2023
6 tasks
@monkbroc monkbroc deleted the feature/sc-123873/check-hash branch January 19, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants