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

Align uf2 blocks to flash erase pages #763

Closed
wants to merge 1 commit into from

Conversation

timokroeger
Copy link

@timokroeger timokroeger commented Mar 22, 2022

Fixes #762

The rp2040 bootrom uses the uf2 block number to determine when to erase a flash sector:
https://github.com/raspberrypi/pico-bootrom/blob/c09c7f08550e8a36fc38dc74f8873b9576de99eb/bootrom/virtual_disk.c#L205

When there is a gap in target addresses between two uf2 blocks this logic does not work out.
As a workaround align all uf2 blocks to page erase boundary, so that the bootrom always removes the correct sector.

@kilograham
Copy link
Contributor

Argh; good catch on the bootrom bug.

Two things:

  1. The changes should be limited to flash UF2 generation
  2. I'm not sure the fix is quite right, because the block_num needs to change whenever the flash sector number does, and this is relative to the start of flash not the previous UF2 block address. I think a simpler, and the easier one conceptually, would be just to include zeroed data for any unused pages in a sector (they are going to be erased anyway).

The rp2040 bootrom uses the uf2 block number to determine when to erase a flash sector:
https://github.com/raspberrypi/pico-bootrom/blob/c09c7f08550e8a36fc38dc74f8873b9576de99eb/bootrom/virtual_disk.c#L205

When there is a gap in target addresses between two uf2 blocks this logic does not work out.
As a workaround align all uf2 blocks to page erase boundary, so that the bootrom always removes the correct sector.
@timokroeger
Copy link
Author

Implemented your feedback, the code is much more readable now.

@timokroeger timokroeger changed the title Align uf2 blocks to flash erase pages, fixes #762 Align uf2 blocks to flash erase pages Mar 28, 2022
@kilograham kilograham added the documentation Improvements or additions to documentation label Apr 4, 2022
@kilograham kilograham added this to the 1.3.1 milestone Apr 4, 2022
@kilograham
Copy link
Contributor

Actually see #800

@kilograham kilograham closed this May 3, 2022
@kilograham kilograham modified the milestones: 1.3.1, none May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants