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

Fix bug causing long swap times in certain cases #1131

Closed
wants to merge 1 commit into from

Conversation

hjuul
Copy link

@hjuul hjuul commented Sep 7, 2021

When the secondary slot is stored in a flash with smaller sector size than
the primary slot, MCUboot would swap more sectors than necessary.
This is an attempt to fix that.

This PR is related to #983.

More details in this Slack thread: https://mcuboot.slack.com/archives/C6CB5BXGC/p1627994014013400

Copy link
Collaborator

@nvlsianpu nvlsianpu left a comment

Choose a reason for hiding this comment

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

fix looks sane.
Thanks!

@nvlsianpu nvlsianpu added area: core Affects core functionality bug labels Sep 7, 2021
@pennam
Copy link

pennam commented Sep 9, 2021

@hjuul tests are complainig about your commit email address... maybe you shoud replace [email protected] with [email protected]

When the secondary slot is stored in a flash with smaller sector size than
the primary slot, MCUboot would swap more sectors than necessary.
This is an attempt to fix that.

Signed-off-by: Helge Juul <[email protected]>
@hjuul hjuul force-pushed the fix_long_swap_times branch from d52e4c0 to 246048a Compare September 9, 2021 10:18
@d3zd3z
Copy link
Member

d3zd3z commented Sep 13, 2021

This is failing ci with ../../boot/bootutil/src/swap_scratch.c:575: boot_swap_sectors: Assertion rc == 0' failed.`

@hjuul
Copy link
Author

hjuul commented Sep 17, 2021

Ok, so I was encouraged to create this PR based on a naïve workaround I had for this issue.
Now that it fails, I don't know the code base enough to make it work.
Are there any maintainers that are willing to take this PR further?

@pennam
Copy link

pennam commented Sep 17, 2021

since i'm interested in using this i'll will be happy to help to found out why is failing. Any suggestion from the maintainers is really appreciated. Is there a way to reproduce and debug the issues on the simulator?

Copy link
Member

@utzig utzig left a comment

Choose a reason for hiding this comment

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

I believe this is just plain wrong, the purpose of that loop is to match the copy sizes based on both sectors from primary and secondary, so sizes in multiples will work. The update proposed in this PR would try to write a 4K sector in internal flash into a 2K flash on SPI, for example, which obviously does not work. How many sectors are we talking about (in your case)? I believe it should be only enough to match the internal flash, so say you have 4K internal and 2K external, that would be a single sector, is this really that bad?

@hjuul
Copy link
Author

hjuul commented Sep 17, 2021

@utzig , in my case I have 256KiB sector size on internal flash (primary slot) and only 4KiB sector size on external flash (secondary slot). So yeah, it's really bad.

@utzig
Copy link
Member

utzig commented Sep 17, 2021

@utzig , in my case I have 256KiB sector size on internal flash (primary slot) and only 4KiB sector size on external flash (secondary slot). So yeah, it's really bad.

I think you will basically have to add special handling for the last sector, since the swap code would like to erase 256KiB on the last sector fitting up to the image size, but you only want to erase up to the size enough for fitting the image, which could be much smaller than that, and also try to synchronize this between both slots, erasing one size in the primary and another size for the secondary. I don't think it will be remotely close to this simplistic approach, but feel free to prove me wrong! ;-)

@utzig
Copy link
Member

utzig commented Sep 17, 2021

@utzig , in my case I have 256KiB sector size on internal flash (primary slot) and only 4KiB sector size on external flash (secondary slot). So yeah, it's really bad.

How long does it take to erase 4KiB on that flash?

@utzig
Copy link
Member

utzig commented Sep 17, 2021

@utzig , in my case I have 256KiB sector size on internal flash (primary slot) and only 4KiB sector size on external flash (secondary slot). So yeah, it's really bad.

Just read your Zephyr thread here: zephyrproject-rtos/zephyr#38548. Your QSPI flash, MT25QU256, supports 4KB, 32KB, and 64KB sector erases, and the driver should choose automatically, for example, I implemented this for Mynewt, and I assume Zephyr's driver can also do it, otherwise it could be implemented in a few lines of code like this: https://github.com/apache/mynewt-core/blob/master/hw/mcu/nxp/kinetis/src/hal_qspi.c#L352.

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the stale label Jun 27, 2022
@github-actions github-actions bot closed this Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Affects core functionality bug stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants