Skip to content

Conversation

@nvlsianpu
Copy link
Contributor

@nvlsianpu nvlsianpu commented Mar 19, 2019

Patch adds option for progressive erase of firmware image.
Using this flash is erased as necessary when receiving
new firmware, instead of erasing the whole image slot at once.
This is necessary on some hardware that has long erase times,
to prevent long wait times at the beginning of the DFU process.

usb/class/usb_dfu: support progressive image erase

Disable bulk slot image erase when progressive erase is on.
Erase of image bank is performed by image collection procedure
progressively.

For some SoC like nRF52840 bulk erase take too much time, which
cause timeout on tool on existing system out-of-the-box (dfu-util
or just by downloading package from sourceforge for Windows).

resolves #8734

@zephyrbot
Copy link

zephyrbot commented Mar 19, 2019

All checks are passing now.

Review history of this comment for details about previous failed status.
Note that some checks might have not completed yet.

@codecov-io
Copy link

codecov-io commented Mar 19, 2019

Codecov Report

Merging #14662 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14662      +/-   ##
==========================================
- Coverage   52.51%   52.49%   -0.02%     
==========================================
  Files         309      309              
  Lines       45048    45060      +12     
  Branches    10419    10431      +12     
==========================================
  Hits        23656    23656              
- Misses      16584    16592       +8     
- Partials     4808     4812       +4
Impacted Files Coverage Δ
...s/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c 54.57% <0%> (-0.96%) ⬇️
subsys/bluetooth/controller/ll_sw/ctrl.c 54.35% <0%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 373a42b...d906898. Read the comment docs.

@nvlsianpu nvlsianpu force-pushed the feature/progresive_image_erase branch from 233a472 to f70f4eb Compare March 21, 2019 15:17
Copy link
Member

Choose a reason for hiding this comment

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

it could be a single multi-line comment

@nvlsianpu
Copy link
Contributor Author

@Qbicz I spotted that the last erase (while flushing the buffer) has the bug you showed me. Will fix this.

@nvlsianpu
Copy link
Contributor Author

nvlsianpu commented Mar 22, 2019

@Qbicz it is fixed. Will squash once you tested it.

@Qbicz
Copy link
Member

Qbicz commented Mar 29, 2019

Hi @nvlsianpu, I tested the progressive image erase and it works. I was able to perform USB DFU on nRF52840 even with the dfu-util with 5 second timeout.

@Qbicz
Copy link
Member

Qbicz commented Mar 29, 2019

Please change commit message (last paragraph) to the following:
For some SoC like nRF52840 bulk erase take more than 5 seconds, which cause timeout on existing versions of dfu-util.

@Qbicz
Copy link
Member

Qbicz commented Mar 29, 2019

For me this PR can be merged, only the minor changes need to be done + rebase on master.

@nvlsianpu nvlsianpu force-pushed the feature/progresive_image_erase branch from d906898 to f283725 Compare March 29, 2019 15:13
@nvlsianpu nvlsianpu added the Enhancement Changes/Updates/Additions to existing features label Mar 29, 2019
@nvlsianpu nvlsianpu force-pushed the feature/progresive_image_erase branch from f283725 to f471f61 Compare March 29, 2019 15:19
@nvlsianpu nvlsianpu changed the title [DNM] DFU: progresive image erase DFU: progresive image erase Mar 29, 2019
@nvlsianpu
Copy link
Contributor Author

@Qbicz revisit

@nvlsianpu nvlsianpu force-pushed the feature/progresive_image_erase branch from f471f61 to 1b32d46 Compare March 29, 2019 15:43
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* If progressive erase is enabled, then erase take place while
* If progressive erase is enabled, erase takes place during

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* image collection, so not erase whole bank at DFU beginning
* image collection, in order not to erase whole bank at DFU beginning

@Qbicz
Copy link
Member

Qbicz commented Apr 9, 2019

@finikorg @jfischer-phytec-iot can you review?

@tormodvolden
Copy link

If this is meant to solve issues with dfu-util, it seems like the wrong fix or at the best a complicated workaround. When performing long operations like a bulk erase, the device should signal to the host (dfu-util) the time before it should resume polling the device, through the bwPollTimeout field. Long operations are only to be initiated after the host has requested the status through the DFU_GETSTATUS request (following the DFU_DNLOAD request that typically encodes an erase operation), whose reply includes the poll timeout value. Please see the DFU 1.1 specification at https://www.usb.org/sites/default/files/DFU_1.1.pdf

There is a 5 second timeout value in dfu-util for the DFU request USB transaction, but any long operation should not hold up this transaction.

BTW, there is also a 5 second poll timeout default value in dfu-util, but it is only applied as a last resort for known, broken devices that doesn't fill in the bwPollTimeout field correctly.

@tormodvolden
Copy link

Looking at your code, here is what you will need to fix:
https://github.com/zephyrproject-rtos/zephyr/blob/master/subsys/usb/class/usb_dfu.c#L396

You have mistakenly hardcoded the bwPollTimeout to 256 ms. This value should be set dynamically, according to the time the device will need for the previously requested operation, e.g. how long it will be unresponsive after a bulk erase. It will typically be set differently for read/write operations and RAM/flash.

@jfischer-no
Copy link
Contributor

jfischer-no commented Apr 10, 2019

@tormodvolden thanks for the hint

You have mistakenly hardcoded the bwPollTimeout to 256 ms. This value should be set dynamically, according to the time the device will need for the previously requested operation, e.g. how long it will be unresponsive after a bulk erase. It will typically be set differently for read/write operations and RAM/flash.

I will change it.

@nvlsianpu
Copy link
Contributor Author

@tormodvolden Thanks for investigation and explanation.
I will keep this PR main content (progresive erase) as it was requested for other adoption as well.
Question is: should I remove it dfu class commit?

@tormodvolden
Copy link

At least the commit messages should be changed IMO, there is no problem with long erase times in the beginning of a DFU process, now that the device implements the bwPollTimeout correctly. So that part of the motivation for this pull request goes out. And no other reason is mentioned :)

@Qbicz
Copy link
Member

Qbicz commented Apr 12, 2019

While the real fix for #8734 is #15330, I would still like to merge this PR, of course with changed commit message.
Progressive image erase has some benefits:

  • it prevents user from waiting long time before update process is started.
  • according to @nvlsianpu in bulk erase whole image slot is erased. For progressive erase only the pages that need to be erased

Moreover, this is an optional feature. I would be happy to have it available to improve user experience.

Copy link
Member

@Qbicz Qbicz left a comment

Choose a reason for hiding this comment

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

Can we change first commit message to

Patch adds option for progressive erase of firmware image.
When using this, flash is erased as necessary when receiving
new firmware, instead of erasing the whole image slot at once.
This is useful on some hardware (like nRF52840) that has
long erase times, to prevent long wait times at the beginning
of the DFU process.

And the second commit message to

Disable bulk slot image erase when progressive erase is on.
Erase of image bank is performed by image collection procedure
progressively.

i.e. remove information about this fixing an issue with dfu-util.

@nvlsianpu
Copy link
Contributor Author

@Qbicz Thanks a lot for your comment. Of course I will rehearsed messages.

@tormodvolden
Copy link

IMO, whether dfu-util or not, "useful [...] to prevent long wait times" isn't a much of a technical motivation though. Or is it just for the user experience that the DFU process seems to be hold up with no visible progress during some seconds?

OTOH, what I see as a huge advantage here (if I understand correctly) is that you can download to parts of the flash without erasing other parts.

@nvlsianpu
Copy link
Contributor Author

@tormodvolden
Progressive erase feature is required by some applications we have to build (is not necessary USB DFU, just better User experience) class. It is optional and disabled by default.

@nvlsianpu nvlsianpu added this to the v2.0.0 milestone Apr 12, 2019
Patch adds option for progressive erase of firmware image.
When using this, flash is erased as necessary when receiving
new firmware, instead of erasing the whole image slot at once.
This is useful on some hardware (like nRF52840) that has
long erase times, to prevent long wait times at the beginning
of the DFU process.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
Disable bulk slot image erase when progressive erase is on.
Erase of image bank is performed by image collection procedure
progressively.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
@nvlsianpu nvlsianpu force-pushed the feature/progresive_image_erase branch from 1b32d46 to 7380e61 Compare April 18, 2019 14:58
@nvlsianpu
Copy link
Contributor Author

@tormodvolden @jfischer-phytec-iot commit message updated.

@jfischer-no
Copy link
Contributor

@carlescufi @nvlsianpu @Qbicz I will revert ea177e7, as it was not thought to end and does not work properly. So this should be merged asap and backported to 1.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes/Updates/Additions to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USB: DFU timeout on nRF52840 due to long flash erase

7 participants