Skip to content

sys/riotboot/flashwrite: when invalidating erase checksum as well #15912

Merged
benpicco merged 2 commits intoRIOT-OS:masterfrom
fjmolinas:pr_riotboot_flashwrite_invalidate_checksum
Feb 9, 2021
Merged

sys/riotboot/flashwrite: when invalidating erase checksum as well #15912
benpicco merged 2 commits intoRIOT-OS:masterfrom
fjmolinas:pr_riotboot_flashwrite_invalidate_checksum

Conversation

@fjmolinas
Copy link
Contributor

Contribution description

This PR addresses two issues with riotboot_flashwrite_invalidate:

  • writing 0XAA to invalidate will no always work, e.g. for stm32f1:

In this mode the CPU programs the main Flash memory by performing standard half-word
write operations. The PG bit in the FLASH_CR register must be set. FPEC preliminarily
reads the value at the addressed main Flash memory location and checks that it has been
erased. If not, the program operation is skipped and a warning is issued by the PGERR bit in
FLASH_SR register (the only exception to this is when 0x0000 is programmed. In this case,
the location is correctly programmed to 0x0000 and the PGERR bit is not set). If the
addressed main Flash memory location is write-protected by the FLASH_WRPR register,
the program operation is skipped and a warning is issued by the WRPRTERR bit in the
FLASH_SR register. The end of the program operation is indicated by the EOP bit in the
FLASH_SR register.

Also FLASHPAGE_WRITE_BLOCK_SIZE was not taken into account, so writing to RIOTBOOT_MAGIC might not work.

Discussing offline with @bergzand it was mentioned that the checksum should also be erased.

To be able to do this I added a FLASHPAGE_ERASE_STATE definition for all CPUs supporting flashpage.

Testing procedure

Use #15559 to test, with this PR these test passes, without it fails the invalidation check.

  • BOARD=iotlab-m3 make -C tests/riotboot_flashwrite/ flash test-with-config -j3

@fjmolinas fjmolinas added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: OTA Area: Over-the-air updates labels Feb 2, 2021
@fjmolinas fjmolinas force-pushed the pr_riotboot_flashwrite_invalidate_checksum branch from bfac4aa to 0c632dc Compare February 2, 2021 10:35
@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 2, 2021
@fjmolinas
Copy link
Contributor Author

Should I squash @benpicco?

@benpicco
Copy link
Contributor

benpicco commented Feb 9, 2021

Please squash!

@fjmolinas fjmolinas force-pushed the pr_riotboot_flashwrite_invalidate_checksum branch from bc2ece0 to 7aa8217 Compare February 9, 2021 10:06
@fjmolinas fjmolinas added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 9, 2021
@benpicco
Copy link
Contributor

benpicco commented Feb 9, 2021

looks like some old commits have sneaked in

@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 Feb 9, 2021
@fjmolinas
Copy link
Contributor Author

I checked that the test is passing rebased on #15559 on nucleo-f103rb

FEATURES_PROVIDED=riotboot BOARD=nucleo-f103rb make -C tests/riotboot_flashwrite/ flash test-with-config

Image Version: 0x60226910
Image start address: 0x08010c00
Header chksum: 0x42247ad5

Starting the shell
>

current-slot

>
> current-slot
Running from slot 1
TEST PASSED

@fjmolinas fjmolinas force-pushed the pr_riotboot_flashwrite_invalidate_checksum branch from 7aa8217 to 6baadad Compare February 9, 2021 10:53
@fjmolinas fjmolinas added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 9, 2021
@fjmolinas
Copy link
Contributor Author

All green @benpicco

@benpicco benpicco merged commit 27c5978 into RIOT-OS:master Feb 9, 2021
@fjmolinas fjmolinas deleted the pr_riotboot_flashwrite_invalidate_checksum branch February 9, 2021 12:37
@fjmolinas
Copy link
Contributor Author

thanks for the review @benpicco!

@kaspar030 kaspar030 added this to the Release 2021.04 milestone Apr 23, 2021
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 Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants