Page MenuHomePhabricator

Issues with alignment and buffer locations
Open, Needs TriagePublic

Description

One partner reported QSPI flash driver reported errors when:

  • An input buffer is an internal XIP flash address;
  • The given memory buffer is not aligned (4 can be the option), both address and size.

Here is the raw log:

> Could help to provide the details so that we can see what the problem is? Looks like you mentioned two problems here, one for the un-aligned memory accessing and another is the FLASH read/write.

Sure. This is being based on the nRF5340 (Cortex-M33) chipset, it uses image swapping rather than overwriting, the primary image is located in the on-chip flash and the secondary slot is located in QSPI flash, the scratch slot is also located in QSPI flash, this is the trailing part of the log when the issue with trying to write to QSPI from a non-RAM buffer occurs (GCC build):
[ERR] Qerase 0xfe000
[ERR] Qerase 0xff000
[ERR] read area=3, off=0x9fff0, len=0x10
[ERR] Qread 0x9fff0 10 to 0x20005ad8
[ERR] read area=3, off=0x9ffd8, len=0x1
[ERR] Qread 0x9ffd8 1 to 0x20005ad7
[ERR] read area=3, off=0x9ffe0, len=0x1
[ERR] Qread 0x9ffe0 1 to 0x20005b22
[ERR] read area=3, off=0x9ffe8, len=0x1
[ERR] Qread 0x9ffe8 1 to 0x20005b23
[ERR] write area=5, off=0x1ffd8, len=0x4
[ERR] Qwrite 0xfffd8 4 from 0x20005ae0
[ERR] write area=5, off=0x1ffd0, len=0x4
[ERR] Qwrite 0xfffd0 4 from 0x20005ae0
[ERR] write area=5, off=0x1fff0, len=0x10
[ERR] Qwrite 0xffff0 10 from 0xcfdc
[ERR] QSPI write failed -400
assertion "rc == 0" failed: file "lib/ext/mcuboot-src/boot/bootutil/src/swap_misc.c", line 125, function: swap_status_init
The final write fails because it is attempting to write to QSPI from a non-RAM address, 0xcfdc is an address in the internal flash. Unless this is possibly an issue with the buffer address being overwritten somehow?

> For the memory alignment, to ensure the isolation setting all sections should be 32-bytes aligned; and the stack-alignment is 8 bytes. Other contents are set as default, the toolchain should have handled them correctly.

This is the error in the trailing part of the log I am getting with it reading 1 byte at a time to an invalid buffer:
[ERR] read area=1, off=0, len=0x20
[ERR] Fread 0x10000 0x20 to 0x20002530
[ERR] read area=3, off=0, len=0x20
[ERR] Qread 0x0 0x20 to 0x2000255c
[ERR] read area=1, off=0x9fff0, len=0x10
[ERR] Fread 0xafff0 10 to 0x20005b60
[ERR] read area=1, off=0x9ffd8, len=0x1
[ERR] Fread 0xaffd8 1 to 0x20005b5f
[ERR] read area=1, off=0x9ffe0, len=0x1
[ERR] Fread 0xaffe0 1 to 0x20005baa
[ERR] read area=1, off=0x9ffe8, len=0x1
[ERR] Fread 0xaffe8 1 to 0x20005bab
[ERR] read area=5, off=0x1fff0, len=0x10
[ERR] Qread 0xffff0 10 to 0x20005b60
[ERR] read area=5, off=0x1ffd8, len=0x1
[ERR] Qread 0xfffd8 1 to 0x20005b5f
[ERR] Qread QSPI failed
assertion "rc == 0" failed: file "lib/ext/mcuboot-src/boot/bootutil/src/swap_scratch.c", line 384, function: swap_status_source
The 2 issues are QSPI reads must be multiples of 4 bytes, it cannot read just 1 byte, and secondly the 0x20005b5f buffer is not 4-byte aligned so it cannot be used to store the data anyway. The same GCC linker .ld files are being used as are currently in the TF-M repository for the nRF5340-DK which is 4-byte aligned for data and bss and 8-byte aligned for heap.
Qread/Qwrite = QSPI, Fread/Write = internal flash, area 5 is the scratch partition. This is TF-M built with separate secure and non-secure image slots.

Please help to investigate it and provide explanations/solutions.

Event Timeline

KenLSoft created this task.Apr 2 2021, 12:39 AM
KenLSoft created this object with edit policy "Subscribers".

@oyvind.ronningstad@nordicsemi.no This issue is on the Nordic platform. Can you take a look at it?