include: sd: revise the minimum alignment of card_buffer to 4-bytes

Since a85ffa8, `struct sd_card.card_buffer` has naturally fallen at an
offset that is unaligned. This meant that on systems without support for
unaligned access (e.g: Cortex-M0), a hard fault would present when
executing code that casts the buffer to `uint32_t` (such as
`sdmmc_spi_read_cxd()`, `card_query_written()`, etc...)

Historically, it appears that the alignment of the `card_buffer` member
was good and operational only by chance.

Altering the default value of `CONFIG_SDHC_BUFFER_ALIGNMENT` was
rejected, as this has wider implications.

Fixes #62619

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
This commit is contained in:
Attie Grande 2023-10-02 11:58:27 +01:00 committed by Alberto Escolar
parent 3b99fb1b4a
commit a97b61e7ed
1 changed files with 7 additions and 1 deletions

View File

@ -80,8 +80,14 @@ struct sd_card {
uint8_t bus_width; /*!< Desired bus width */
uint32_t cccr_flags; /*!< SDIO CCCR data */
struct sdio_func func0; /*!< Function 0 common card data */
/* NOTE: The buffer is accessed as a uint32_t* by the SD subsystem, so must be
* aligned to 4 bytes for platforms that don't support unaligned access...
* Systems where the buffer is accessed by DMA may require wider alignment, in
* which case, use CONFIG_SDHC_BUFFER_ALIGNMENT.
*/
uint8_t card_buffer[CONFIG_SD_BUFFER_SIZE]
__aligned(CONFIG_SDHC_BUFFER_ALIGNMENT); /* Card internal buffer */
__aligned(MAX(4, CONFIG_SDHC_BUFFER_ALIGNMENT)); /* Card internal buffer */
};
/**