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

riotboot/flashwrite: use flashpage_raw when available #11683

Closed
wants to merge 3 commits into from

Conversation

fjmolinas
Copy link
Contributor

Contribution description

The following PR allows using flashpage_write_raw() to finish an update process. The main objective of this is to support OTA on stm32f4/2/7. Since the flash is sector based if at the finish we are to perform an erase operation the whole sector would be erased (sectors that go from 16KB to 256KB). The idea is that since we only need to write 4 bytes if flashpage_write_raw() is available erasing the sector again can be avoided since it was already erased at the start of the flashwrite process. So as long as the first 4 bytes are kept in an erased state '0xFF' flashpage_write_raw() can be used.

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
 GNRC_NETIF_NUMOF := 2
 
 # 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
-#CFLAGS += -DETHOS_BAUDRATE=$(ETHOS_BAUDRATE) -DUSE_ETHOS_FOR_STDIO
+ETHOS_BAUDRATE ?= 115200
+CFLAGS += -DETHOS_BAUDRATE=$(ETHOS_BAUDRATE) -DUSE_ETHOS_FOR_STDIO
+
+TAP ?= tap0
+IPV6_PREFIX ?= 2001:db8::/64
+
+TERMPROG ?= sudo sh $(RIOTTOOLS)/ethos/start_network.sh
+TERMFLAGS ?= $(PORT) $(TAP) $(IPV6_PREFIX)
 
 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.

  1. rebase on top of cpu/stm32f4: add riotboot requirements #11682 and cpu/stm32f7/4/2: add flashpage and flashpage_raw #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

Issues/PRs references

Related to #11682 and #1168

@fjmolinas fjmolinas added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: OTA Area: Over-the-air updates labels Jun 12, 2019
@fjmolinas fjmolinas requested a review from kaspar030 June 12, 2019 17:02
- If supported when finishing flashwrite, i.e. writing RIOT
  magic number, if FLASHPAGE_RAW is supported it will be used
  insetad of FLASHPAGE to avoid copying and erasing the page.
- This also allows it work for sectors based flash, e.g. stm32f4
@fjmolinas fjmolinas force-pushed the pr_flashwrite_finish_raw branch from aabdf42 to b2a7e74 Compare June 12, 2019 17:10
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.

Code looks fine. Will try to test tomorrow.

(Some of the alignment changes were a little off, fixing from too little spaces to too many.)

@@ -0,0 +1,151 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmmm ;)

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.

Hm, shouldn't flashpage_raw allow to not allocate a whole flash page as buffer?
The idea would be to erase a page on first write, but then write in FLASHPAGE_RAW_BLOCKSIZE sized chunks.

@fjmolinas
Copy link
Contributor Author

Closed in favor of #11705

@fjmolinas fjmolinas closed this Jul 8, 2019
@fjmolinas fjmolinas deleted the pr_flashwrite_finish_raw branch August 7, 2019 15:42
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 Platform: ARM Platform: This PR/issue effects ARM-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants