mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-07 01:28:53 +08:00
migrateFWFromRoot held the SD root directory open via opendir/readdir while performing heavy file I/O (getFileInfo, copyFw, unlink) inside the loop. Between readdir calls the FAT semaphore is released, allowing other tasks (e.g. logger) to dirty the shared FAT sector cache. When the next FAT operation needed a different sector, fat_fscacheflush would write the dirty data followed by an immediate read — triggering a write-busy to read transition in the SDMMC WRCOMPLETE path that kills the SD card on STM32H7. Split into two phases: first collect .bin filenames with the directory open, then close it before doing any file I/O. This also fixes a missing closedir on the mkdir error path and avoids modifying directory entries (via unlink) while iterating them with readdir.