[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>
diff --git a/src/platform/nxp/common/NXPConfig.cpp b/src/platform/nxp/common/NXPConfig.cpp
index cc6f8d5..b047d8a 100644
--- a/src/platform/nxp/common/NXPConfig.cpp
+++ b/src/platform/nxp/common/NXPConfig.cpp
@@ -84,14 +84,14 @@
{
uint16_t chipConfigRamBufferLen;
uint16_t padding;
- uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_INT];
+ uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_INT] __attribute__((aligned(4)));
} ChipConfigRamStructKeyInt;
typedef struct
{
uint16_t chipConfigRamBufferLen;
uint16_t padding;
- uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_STRING];
+ uint8_t chipConfigRamBuffer[CONFIG_CHIP_NVM_RAMBUFFER_SIZE_KEY_STRING] __attribute__((aligned(4)));
} ChipConfigRamStructKeyString;
/* File system containing only integer keys */
@@ -193,6 +193,14 @@
{
if (!isInitialized)
{
+ /*
+ * Make sure to check that read buffers are always 4 bytes aligned,
+ * as NXP flash drivers may mandate the alignment of dst read buffer to 4 bytes
+ */
+ static_assert(alignof(chipConfigRamStructKeyInt.chipConfigRamBuffer) == 4,
+ "Wrong buffer alignment, it must be 4 bytes aligned");
+ static_assert(alignof(chipConfigRamStructKeyString.chipConfigRamBuffer) == 4,
+ "Wrong buffer alignment, it must be 4 bytes aligned");
ramStorageInit();
#if (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_NVM_FWK)