zephyr: Flash map does not fare well with MCU who do bank swaps

Describe the bug On devices with two flash banks, a partition allocated in the first bank before a bank swap would become located in the second bank after a bank swap. Currently there is no way to fetch the proper address of a partition depending on the bank swap state.

I’ve encountered this issue when using settings_fcb on nucleo_h743zi, when I load my application firmware in each bank, do some settings write <id> <val> then perform a bank swap, the firmware running on the new bank do not see the settings written before the bank swap.

I have submitted a workaround for settings_fcb https://github.com/zephyrproject-rtos/zephyr/pull/47692, but as @de-nordic suggested it is just a workaround and the underlying issue could affect any subsystem using flash map and bank swap operations.

To Reproduce Steps to reproduce the behavior: On nucleo_h743zi, we need a patch in settings_fcb available on this PR: https://github.com/zephyrproject-rtos/zephyr/pull/47632 to be able to be able to support flash with larger than 16 write-size. Here is a sample application with settings and settings_shell settings_fcb.tar.gz (edit: settings_fcb.tar.gz for zephyr tree at revision https://github.com/zephyrproject-rtos/zephyr/commit/e61aec3e4c012e015008918a8a368701e35d2baa)

  1. west build -b nucleo_h743zi samples/settings_fcb
  2. STM32_Programmer_CLI --connect port=SWD reset=HWrst -ob SWAP_BANK=1 -e all
  3. west flash
  4. STM32_Programmer_CLI --connect port=SWD reset=HWrst -ob SWAP_BANK=0 -rst
  5. west flash # at this point same firmware is flashed to each bank
  6. from zephyr shell: settings write foo 123
  7. STM32_Programmer_CLI --connect port=SWD reset=HWrst -ob SWAP_BANK=1 -rst
  8. from zephyr shell: settings list yields nothing.

Expected behavior The value returned by FLASH_AREA_ID should take into account the bank from which the firmware is running on and point to the same physical area.

Impact The flash area returned does not contain the expected values due to a bank swap operation.

Logs and console output

/* running from bank 0 */
uart:~$ settings list
uart:~$ settings write foo 123
uart:~$ settings list
foo

/* Swap to bank 1 */

uart:~$ *** Booting Zephyr OS build zephyr-v3.1.0-2094-gc0d56b070770  ***
Hello World! nucleo_h743zi
<inf> h7_fcb: pwet
uart:~$ settings list
uart:~$ 

Environment (please complete the following information):

  • OS: Linux
  • 0.13.2, 0.14.2
  • 9ed194a00b18af81a037df9d74d63a26cb34c775 + patch mentionned above

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 38 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@nvincent-vossloh, could you test with flash map shell enabled CONFIG_FLASH_MAP_SHELL=y and run the command List flash areas running from bank 0 and then bank 1 ?