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 124322/protected error #711

Merged
merged 12 commits into from
Jan 19, 2024
Merged

Conversation

keeramis
Copy link
Contributor

@keeramis keeramis commented Jan 11, 2024

Description

CLI gives an error that device is protected if the device is protected.

How to Test

  1. Prepare your device with a device-os branch that returns a device protected error. I used this diff on device-os 5.6.0
diff --git a/services/inc/system_error.h b/services/inc/system_error.h
index 5f3b9252c..8bb781629 100644
--- a/services/inc/system_error.h
+++ b/services/inc/system_error.h
@@ -24,6 +24,7 @@
 // List of all defined system errors
 #define SYSTEM_ERRORS \
         (NONE, "", 0), /* -999 ... 0: Generic result codes */ \
+        (DEVICE_PROTECTED, "Device protected error", -999), \
         (UNKNOWN, "Unknown error", -100), \
         (BUSY, "Resource busy", -110), \
         (NOT_SUPPORTED, "Not supported", -120), \
diff --git a/system/src/control/storage.cpp b/system/src/control/storage.cpp
index d9438eaa9..d6630a681 100644
--- a/system/src/control/storage.cpp
+++ b/system/src/control/storage.cpp
@@ -84,6 +84,7 @@ void firmwareUpdateCompletionHandler(int result, void* data) {
 } // namespace
 
 int startFirmwareUpdateRequest(ctrl_request* req) {
+    return SYSTEM_ERROR_DEVICE_PROTECTED;
     PB(StartFirmwareUpdateRequest) pbReq = {};
     CHECK(decodeRequestMessage(req, PB(StartFirmwareUpdateRequest_fields), &pbReq));
     cancelFirmwareUpdate(); // Cancel current transfer

  1. Point this particle-cli branch to use this particle-usb PR - Add error code for protected devices particle-usb#97
  2. Attempt to flash a device by running npm start -- flash --local

After testing, make sure you flash the device with a "good" device-os branch so you can resume flashing.

$ npm start -- flash --local --target 5.6.0 /Users/keerthyamisagadda/code/workbench/uhura-tests/

> particle-cli@3.18.1 start
> node ./src/index.js flash --local --target 5.6.0 /Users/keerthyamisagadda/code/workbench/uhura-tests/

Flashing boron e00fce68623fcff480e85e47
Targeting version: 5.6.0

Including:
    ../workbench/uhura-tests/project.properties
    ../workbench/uhura-tests/src/uhura-tests.cpp
    /Users/keerthyamisagadda/code/workbench/uhura-tests/assets/cat.txt
    /Users/keerthyamisagadda/code/workbench/uhura-tests/assets/water.txt
    /Users/keerthyamisagadda/code/workbench/uhura-tests/assets/water2.txt

Compile succeeded and bundle created.

Memory use:
    Flash      RAM
    11144      542

[░░░░░░░░░░░░░░░░░░░░░░░░░] 0% | Flash success!
Operation could not be completed due to device protection.

keerthyamisagadda@loaners-macbook-pro particle-cli (feature/sc-124322/protected-error) $ 

Related Issues / Discussions

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

buf = await device.readOverDfu({ altSetting, startAddr, size });
} catch (err) {
throw new Error('Reading over DFU failed', err);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might as well throw an error here? So I added this

Copy link
Member

Choose a reason for hiding this comment

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

That doesn't look necessary. The previous code will throw an error if it fails already.

} finally {
progress({ event: 'finish' });
progress({ event: 'finish', success });
Copy link
Contributor Author

@keeramis keeramis Jan 17, 2024

Choose a reason for hiding this comment

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

The UI was looking a bit weird as it says Flash Success and then Operation failed due to device protection.

So I added Flash Failed

@keeramis keeramis marked this pull request as ready for review January 17, 2024 22:27
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.

Looks good now. Probably simplify the throw statements to just throw error. Update particle-usb dependency then this is good to merge 👍

if (err instanceof DeviceProtectionError) {
throw new Error('Operation could not be completed due to device protection.');
}
throw new VError(ensureError(err), 'Writing over DFU failed');
Copy link
Member

Choose a reason for hiding this comment

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

This is a change in behavior. Previously it would have just thrown the error directly (i.e. throw err). Does this change fix a specific thing you noticed during testing?

buf = await device.readOverDfu({ altSetting, startAddr, size });
} catch (err) {
throw new Error('Reading over DFU failed', err);
}
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't look necessary. The previous code will throw an error if it fails already.

if (error instanceof DeviceProtectionError) {
throw new Error('Operation could not be completed due to device protection.');
}
throw new VError(ensureError(error), 'Writing over DFU failed');
Copy link
Member

Choose a reason for hiding this comment

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

Same question here. Why use this vs throw error;

@@ -177,7 +194,7 @@ function _createFlashProgress({ flashSteps, ui }) {
}
break;
case 'finish':
description = 'Flash success!';
description = payload.success ? 'Flash success!' : 'Flash failed.';
Copy link
Member

Choose a reason for hiding this comment

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

That's a good improvement.

@keeramis keeramis force-pushed the feature/sc-124322/protected-error branch from ed541c0 to 9e73928 Compare January 19, 2024 22:56
@keeramis
Copy link
Contributor Author

From my local run:

Screenshot 2024-01-19 at 2 48 22 PM

@keeramis keeramis merged commit f935f3a into master Jan 19, 2024
6 checks passed
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