thenickdude / asyncfatfs

Asynchronous FAT16/32 filesystem for embedded devices
MIT License
29 stars 9 forks source link

afatfs.cache unaligned with latest GCC #6

Open sean-lawless opened 1 month ago

sean-lawless commented 1 month ago

I have added your fine library to my simple asynchronous OS (https://github.com/sean-lawless/computersystems/tree/master/Lab20%20Mass%20Storage/fat). All was working fine last time I tested. Recently I upgraded my PC and installed the latest versions of all my embedded development tools and now the sdcard integration was broken.

It turns out that with the latest GCC (arm-none-eabi-gcc.exe (GCC) 13.3.0) the afatfs.cache[] compiles to be unaligned (starts at 3 bytes from the structure start). This caused the lower-level code (USB SD card) to complain about an unaligned buffer (not 4 byte-aligned) when writing data to the afatfs.cache (reading from SD).

I fixed this locally by moving the cache and descriptors above the enumerated types, as below. If you like the change I can make a pull request.

typedef struct afatfs_t {
    uint8_t cache[AFATFS_SECTOR_SIZE * AFATFS_NUM_CACHE_SECTORS];
    afatfsCacheBlockDescriptor_t cacheDescriptor[AFATFS_NUM_CACHE_SECTORS];
    fatFilesystemType_e filesystemType;

    afatfsFilesystemState_e filesystemState;
    afatfsInitializationPhase_e initPhase;

Compile settings (see link): arm-none-eabi-gcc -c -Wall -ggdb -O0 -ffreestanding

thenickdude commented 1 month ago

I think that comment must be a malware bot, definitely do not touch that. I've reported them to GitHub

thenickdude commented 1 month ago

The change looks great, thanks, please submit that PR!

thenickdude commented 1 month ago

Wow it's a different user posting the malware this time, I've reported them too. Hopefully GitHub gets on top of it.

thenickdude commented 1 month ago

Locking this issue so that we don't get any more of them appearing.