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

sys/riotboot/flashwrite: display progress bar during copy/download #12551

Merged
merged 4 commits into from
Jan 9, 2020

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Oct 23, 2019

Contribution description

This PR makes use of the progress bar introduced in #12550 to nicely follow the copy/download of a firmware on flash.
The logic for updating the progress bar is added in riotboot/flashwrite submodule. The API had to be updated to add a firmware_size argument. There might be a better way, so suggestions are welcome.

The suit module is adapted to retrieve the firmware size from the manifest and pass it to the flashwrite module.

In the riotboot_flashwrite, the max uint32_t value is used for the firmware_size. It is used as a fallback when the firmware_size is not known in advance.

Testing procedure

Run the examples/suit_update testing procedure. The progress bar is displayed during the update, the automatic test works.

Issues/PRs references

Depends on #12550

@aabadie aabadie added Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first Area: OTA Area: Over-the-air updates labels Oct 23, 2019
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

I'm not happy with integrating the progress bar into the flashwrite module.

The suit module is adapted to retrieve the firmware size from the manifest and pass it to the flashwrite module.

A much less intrusive option for getting the progress bar into suit would be:

  1. as soon as the image size is known, store it in sth like static size_t _imgsize;, as global in suit/coap.c
  2. replace the DEBUG in suit_flashwrite_helper() with the appropriate progress_bar_print(prefix, suffix, (offset + len) * 100 / _imgsize) call.

@kaspar030
Copy link
Contributor

I'm not happy with integrating the progress bar into the flashwrite module.

riotboot_flashwrite is a quite low-level module. At the moment, it is quite verbose through LOG_INFO, but in general, its caller has all the information on how, if and when to display a progress bar. flashwrite can only globally enable it.

@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch from 4df2958 to 2c07e11 Compare November 15, 2019 10:57
@aabadie
Copy link
Contributor Author

aabadie commented Nov 15, 2019

I've reworked this PR following your suggestion @kaspar030. The problematic part now is how to share the image size between the handler code and the coap code in suit (it's using an ugly extern now). Maybe a better solution is to define the manifest static in coap.c ?
What do you think ?

@aabadie
Copy link
Contributor Author

aabadie commented Nov 15, 2019

I added the change to move the manifest as a static variable in 20ccbc6. I think it's a little better.

@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch from 20ccbc6 to b9457b9 Compare November 15, 2019 12:33
@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch from b9457b9 to 0013036 Compare December 2, 2019 15:33
@kaspar030
Copy link
Contributor

pls rebase!

@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch 2 times, most recently from ebcad87 to 1311aae Compare December 5, 2019 14:44
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Dec 5, 2019
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

I have a suggestion that also allows the code to be the same as before if MODULE_PROGRESS_BAR is not included.

@fjmolinas
Copy link
Contributor

I don't know why part of my comment got lost:

With the proposed change we only allocate a mainfest_t* on .bss and not the whole manifest which is not needed. You only really need the pointer to access the data you need.

The ptr can be set to NULL of the end of the function and the progress_bar code can check against it being defined.

  • current
   text	   data	    bss	    dec	    hex	filename
  71784	    372	  24404	  96560	  17930	/home/francisco/workspace/RIOT-test/examples/suit_update/bin/iotlab-m3/suit_update.elf
  • proposed
   text	   data	    bss	    dec	    hex	filename
  71784	    372	  23776	  95932	  176bc	/home/francisco/workspace/RIOT-test/examples/suit_update/bin/iotlab-m3/suit_update.elf

@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch from 1311aae to 239e517 Compare December 6, 2019 12:56
@aabadie
Copy link
Contributor Author

aabadie commented Dec 6, 2019

The ptr can be set to NULL of the end of the function and the progress_bar code can check against it being defined.

I don't understand which function you are talking about here.

Otherwise, I think I mostly addressed your other comments.

@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch from 0445778 to f1e3da8 Compare December 6, 2019 13:38
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

The ptr can be set to NULL of the end of the function and the progress_bar code can check against it being defined.

I don't understand which function you are talking about here.

At the end of _suit_handle_url(), the memmory address where manfiest_ptr points to might be occupied by something else after the function exits. I think it should probably be set to NULL and in:
_print_download_progress verify the pointer is not NULL, maybe I'm worried for nothing?

@aabadie
Copy link
Contributor Author

aabadie commented Dec 6, 2019

At the end of _suit_handle_url(), the memmory address where manfiest_ptr points to might be occupied by something else after the function exits. I think it should probably be set to NULL and in:
_print_download_progress verify the pointer is not NULL, maybe I'm worried for nothing?

I think your whole suggestion is dangerous because as you says the pointer to the manifest could be invalid when the function exits. _print_download_progress is called many times during the download, so it's important to ensure the manifest variable is not lost. Maybe it should be static ?

@fjmolinas
Copy link
Contributor

As discussed offline with @aabadie I think the new state is the best approach. But it does change suit_flashwrite_helper() since it know receives a pointer to the manifest. The function seems specific enough to suit code for this not to mater. Is the helper was somehow needed but something else it could be redefined to flashwrite_helper and suit_flashwrite_helper wrapped around it to pass a pointer to the writer and not the manifest.

@kaspar030 do you agree with the latest approach?

@fjmolinas fjmolinas removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 6, 2019
@fjmolinas
Copy link
Contributor

I removed the ready for build for now, to not waste CO2.

@aabadie
Copy link
Contributor Author

aabadie commented Dec 19, 2019

@kaspar030 ?

@aabadie
Copy link
Contributor Author

aabadie commented Jan 8, 2020

@kaspar030 @fjmolinas, are you ok with the current state of this PR ? May I squash/rebase ?

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK, @kaspar030 does your change request still stand?

EDIT: @aabadie please squash

@kaspar030 kaspar030 dismissed their stale review January 8, 2020 20:58

comments addressed

@aabadie aabadie force-pushed the pr/sys/flashwrite_progress_bar branch from 7c317cf to 0597fc9 Compare January 9, 2020 10:31
@aabadie
Copy link
Contributor Author

aabadie commented Jan 9, 2020

Thanks @kaspar030, @fjmolinas. This PR is now squashed and rebased.

@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 9, 2020
@aabadie aabadie merged commit 0b602f1 into RIOT-OS:master Jan 9, 2020
@aabadie aabadie deleted the pr/sys/flashwrite_progress_bar branch January 9, 2020 11:46
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: OTA Area: Over-the-air updates CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants