[riot-notifications] [RIOT-OS/RIOT] riotboot/flashwrite: use chunks instead of pages, support flashpage_write_raw (#11705)

Francisco notifications at github.com
Mon Jun 17 10:11:57 CEST 2019

The RIOT community cares a lot about code quality.
Therefore, before describing what your contribution is about, we would like
you to make sure that your modifications are compliant with the RIOT
coding conventions, see https://github.com/RIOT-OS/RIOT/wiki/Coding-conventions.

### Contribution description

Put here the description of your contribution:
- describe which part(s) of RIOT is (are) involved
- if it's a bug fix, describe the bug that it solves and how it is solved
- you can also give more information to reviewers about how to test your changes

The following PR changes the approach used for flashwrite. Instead of always writing pages it writes chunks into flash. If `flashpage_raw` is supported these chunk can be smalled than FLASHPAGE_SIZE allowing for buffers as small as `FLASHPAGE_RAW_BLOCKSIZE`. This will also allow supporting stm32f4/2/7` or sectors based CPU since we can pick when to erase the flash.

The PR involves three changes (I can open separate PR's if the spirit of the PR is agreed upon):

* Introduces a `FLASH_ERASE_STATE` variable so the when skipping an offset or in this case `RIOTBOOT_MAGIC` we keep those bytes in an erase state so they don't need to be overwritten.
* Introduces `flashpage_write_and_verify_raw` and `flashpage_write_raw`. These are convenience functions.
* Changes the behaviour of `flashwrite` to be based on chunks

When implementing #11683 I was too focused on making it work for `stm32f2/4` and not on the global picture I think this approach works better by still having the same behavior for the base case an completely removing the use of page buffers when possible.

A buffer is still kept in `riotboot_flashwrite_t` for convenience, it makes it easier and more robust to handle unaligned `riotboot_flashwrite_putbytes`. The buffer could always be defined to `FLASHPAGE_RAW_BLOCKSIZE`. The choice of 64 bytes I made is based on having it the same size as a coap_block. But it could be changed

### Testing procedure

1. Verify that everything still works on supported board that support and don't support flashpage. Applying this diff can help in testing over ethos:

diff --git a/tests/riotboot_flashwrite/Makefile b/tests/riotboot_flashwrite/Makefile
index 32f127d70..d3c9f20b4 100644
--- a/tests/riotboot_flashwrite/Makefile
+++ b/tests/riotboot_flashwrite/Makefile
@@ -39,11 +39,17 @@ LOW_MEMORY_BOARDS := nucleo-f334r8
 # uncomment these to use ethos
-#USEMODULE += ethos gnrc_uhcpc
+USEMODULE += ethos gnrc_uhcpc  stdio_uart_rx
 ## ethos baudrate can be configured from make command
-#ETHOS_BAUDRATE ?= 115200
+TAP ?= tap0
+IPV6_PREFIX ?= 2001:db8::/64
+TERMPROG ?= sudo sh $(RIOTTOOLS)/ethos/start_network.sh
 ifneq (,$(filter $(BOARD),$(LOW_MEMORY_BOARDS)))
   $(info Using low-memory configuration for microcoap_server.)

for nucleo-l073rz:

- provided the node `make -C tests/riotboot_flashwrite/ BOARD= nucleo-l073rz riotboot/flash term`
- compile new firmware: `make -C tests/riotboot_flashwrite/ BOARD= nucleo-l073rzriotboot`
- launch an updated: `coap-client -m post coap://[fe80::2%tap0]/flashwrite -f tests/riotboot_flashwrite/bin/ nucleo-l073rz/tests_riotboot_flashwrite-slot1.riot.bin -b 64`

for samr21-xpro:

- provided the node `make -C tests/riotboot_flashwrite/ BOARD= samr21-xpro riotboot/flash term`
- compile new firmware: `make -C tests/riotboot_flashwrite/ BOARD= samr21-xpro rzriotboot`
- launch an updated: `coap-client -m post coap://[fe80::2%tap0]/flashwrite -f tests/riotboot_flashwrite/bin/  samr21-xpro/tests_riotboot_flashwrite-slot1.riot.bin -b 64`

When the update finished reboot the node manually it should have started from a different slot.

2. rebase on top of https://github.com/RIOT-OS/RIOT/pull/11682 and https://github.com/RIOT-OS/RIOT/pull/11681 and test over an stm32f4 board, e.g. `nucleo-f446re`

- provided the node `make -C tests/riotboot_flashwrite/ BOARD=nucleo-f446re riotboot/flash term`
- compile new firmware: `make -C tests/riotboot_flashwrite/ BOARD=nucleo-f446re riotboot`
- launch an updated: `coap-client -m post coap://[fe80::2%tap0]/flashwrite -f tests/riotboot_flashwrite/bin/ nucleo-f446retests_riotboot_flashwrite-slot1.riot.bin -b 64`

Details steps to test your contribution:
- which test/example to compile for which board and is there a 'test' command
- how to know that it was not working/available in master
- the expected success test output

### Issues/PRs references

Examples: Fixes #1234. See also #5678. Depends on PR #9876.

Please use keywords (e.g., fixes, resolve) with the links to the issues you
resolved, this way they will be automatically closed when your pull request
is merged. See https://help.github.com/articles/closing-issues-using-keywords/.

Replaces #11683

Related to https://github.com/RIOT-OS/RIOT/pull/11682 and https://github.com/RIOT-OS/RIOT/pull/1168
You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * periph/flashpage: add variable for value of erased byte
  * periph/flashpage: add flashpage_raw verify functions
  * riotboot/flashwrite: use chunks instead of pages
  * sys/riotboot: cleanup useless action

-- File Changes --

    M Makefile.dep (1)
    M cpu/efm32/include/cpu_conf.h (2)
    M cpu/msp430_common/include/cpu_conf.h (3)
    M cpu/nrf51/include/cpu_conf.h (3)
    M cpu/nrf52/include/cpu_conf.h (3)
    M cpu/sam0_common/include/cpu_conf.h (3)
    M cpu/stm32f0/include/cpu_conf.h (2)
    M cpu/stm32f1/include/cpu_conf.h (2)
    M cpu/stm32l0/include/cpu_conf.h (2)
    M cpu/stm32l1/include/cpu_conf.h (3)
    M cpu/stm32l4/include/cpu_conf.h (3)
    M drivers/include/periph/flashpage.h (49)
    M drivers/periph_common/flashpage.c (18)
    M sys/include/riotboot/flashwrite.h (32)
    M sys/riotboot/flashwrite.c (93)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190617/b5f6fd0e/attachment.html>

More information about the notifications mailing list