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

Add possibility to run CONFIRM step after DFU when device becomes present again (advertising after reboot) #127

Open
gte1 opened this issue Nov 21, 2023 · 8 comments

Comments

@gte1
Copy link

gte1 commented Nov 21, 2023

Normally the swap time setting defines when the CONFIRM step is performed. If the device starts advertising again before that timeout, then allow the CONFIRM step to be executed.

(if decided to implement, the IOS version should be updated too)

@philips77
Copy link
Member

Sorry, I don't get it.

In Test & Confirm mode the library will:

  1. upload,
  2. send TEST command,
  3. send RESET command,
  4. wait "swap time",
  5. try to connect,
  6. send CONFIRM command,
  7. Report success.

What would you like to change here? What is your desired path?

@gte1
Copy link
Author

gte1 commented Nov 21, 2023

  1. wait "swap time" or detect that device has rebooted (device starts advertising again), whichever comes first

@philips77
Copy link
Member

The device usually reboots immediately after RESET is sent. Then, if the bootloader is in Swap mode, it will move images from secondary to primary partition which will take time. For nRF52840 it's around 15+ seconds, depending on the image size. The swap time should be measured for given device and set before updating, so that "try to connect" does not timeout. After swap is complete the new image is booted. I understand that by "rebooted" you mean this whole process.

To measure when a device is ready to reconnect the library would have to scan for it. This would add a lot of complications on Android side. There are Location permissions that have to be granted on some Android versions, Location service enabled, Nearby permission, etc. And this is only for Test & Confirm mode.
Having customizable "swap time" seems OK, as the "try to connect" has ca. 30 sec timeout, so you may set swap time for less than really needed and reconnection should be immediate when ready.

Also, NCS 2.5 added "Direct XIP" bootloader mode. This requires changing the McuBoot to one which would support it, but this means no swap at all and reboot is immediate.

@gte1
Copy link
Author

gte1 commented Nov 21, 2023

I see your point on the complexity of implementing this.

We use ncs 2.5 now, but have devices in the field that started with ncs 2.2, and some with ncs 2.4.
Those older devices does not have mcuboot with Direct XIP, so we will have to keep using the swap method.

@ksidirop-laerdal
Copy link
Contributor

ksidirop-laerdal commented Nov 21, 2023

Sorry, I don't get it.

In Test & Confirm mode the library will:

1. upload,

2. send TEST command,

3. send RESET command,

4. wait "swap time",

5. try to connect,

6. send CONFIRM command,

7. Report success.

What would you like to change here? What is your desired path?

@philips77 Just thinking out loud off the top of my head - just bare with me:

What if we try to connect + send the "confirm" command preemptively every few seconds and see if it has any effect - if it doesn't then wait a few more seconds and retry connect+sending "confirm" until it actually succeeds.

This way we won't have to wait for the full-swap time duration just to try sending "confirm" once at the very end and the code-changes will essentially enrich a mechanism which is already in place - no need for fancy stuff with permissions etc.

Might be missing something - Let me know what you think.

@philips77
Copy link
Member

That could work, yes, but I have 2 questions.

  1. Why do you need this feature? Do you have different devices with different swap times? Does your device sometimes requires more, sometimes less time to swap? Is it not possible to estimate approximate swap time (connection timeouts in 30 seconds)?
  2. Your suggested approach would require adding some timeout property to finally give up those connections.

@gte1
Copy link
Author

gte1 commented Nov 23, 2023

I can answer this (since I am a collegue to @ksidirop-laerdal):

  1. Our device might get increased swap time as new features are added and the firmware image grows. But the main reason is that at startup of a newly uploaded firmware version, we sometimes have to do some housekeeping before starting the BLE services. (we use littlefs, which sometimes has high latencies, sometimes tens of seconds if it decides to do garbage collection etc.). So to make sure that we get the uploaded image confirmed, we would have to set an unecessarily high swap time.
  2. Could that timeout just be the swap timeout setting?

@philips77
Copy link
Member

OK, thanks for explanation. I'll discuss with my colleagues.

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

No branches or pull requests

3 participants