Skip to content

Commit 4728f4f

Browse files
authored
[NXP][platform] Forcing 4 bytes alignment for the RAM storage read buffer (#33895)
Issue could happen on NXP platforms supporting Matter with the RAM storage module + littlefs due to read buffer alignment issue. As mflash_drv_read mandates the alignment of dst read buffer to 4 bytes, make sure to always align read buffers to 4 bytes. Signed-off-by: Gatien Chapon <gatien.chapon@nxp.com>
1 parent a030a47 commit 4728f4f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/platform/nxp/common/NXPConfig.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ typedef struct
8484
{
8585
uint16_t chipConfigRamBufferLen;
8686
uint16_t padding;
87-
uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_INT];
87+
uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_INT] __attribute__((aligned(4)));
8888
} ChipConfigRamStructKeyInt;
8989

9090
typedef struct
9191
{
9292
uint16_t chipConfigRamBufferLen;
9393
uint16_t padding;
94-
uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_STRING];
94+
uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_STRING] __attribute__((aligned(4)));
9595
} ChipConfigRamStructKeyString;
9696

9797
/* File system containing only integer keys */
@@ -193,6 +193,14 @@ CHIP_ERROR NXPConfig::Init()
193193
{
194194
if (!isInitialized)
195195
{
196+
/*
197+
* Make sure to check that read buffers are always 4 bytes aligned,
198+
* as NXP flash drivers may mandate the alignment of dst read buffer to 4 bytes
199+
*/
200+
static_assert(alignof(chipConfigRamStructKeyInt.chipConfigRamBuffer) == 4,
201+
"Wrong buffer alignment, it must be 4 bytes aligned");
202+
static_assert(alignof(chipConfigRamStructKeyString.chipConfigRamBuffer) == 4,
203+
"Wrong buffer alignment, it must be 4 bytes aligned");
196204
ramStorageInit();
197205

198206
#if (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_NVM_FWK)

0 commit comments

Comments
 (0)