1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Fix flash filesystem mass storage support for > 128MB flash

The required padding would be calculated incorrectly if more than 128MB of flash was used for log files.
This commit is contained in:
Bruce Luckcuck 2019-10-07 10:20:25 -04:00
parent c6452a55cc
commit 7ef0daf854

View file

@ -421,13 +421,14 @@ void emfat_init_files(void)
const int logCount = emfat_find_log(&entries[PREDEFINED_ENTRY_COUNT], EMFAT_MAX_LOG_ENTRY); const int logCount = emfat_find_log(&entries[PREDEFINED_ENTRY_COUNT], EMFAT_MAX_LOG_ENTRY);
int entryIndex = PREDEFINED_ENTRY_COUNT + logCount; int entryIndex = PREDEFINED_ENTRY_COUNT + logCount;
const int usedSpace = flashfsIdentifyStartOfFreeSpace();
if (logCount > 0) { if (logCount > 0) {
// Create the all logs entry that represents all used flash space to // Create the all logs entry that represents all used flash space to
// allow downloading the entire log in one file // allow downloading the entire log in one file
entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT]; entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT];
entry = &entries[entryIndex]; entry = &entries[entryIndex];
entry->curr_size = flashfsIdentifyStartOfFreeSpace(); entry->curr_size = usedSpace;
entry->max_size = entry->curr_size; entry->max_size = entry->curr_size;
// This entry has timestamps corresponding to when the filesystem is mounted // This entry has timestamps corresponding to when the filesystem is mounted
emfat_set_entry_cma(entry); emfat_set_entry_cma(entry);
@ -435,13 +436,15 @@ void emfat_init_files(void)
} }
// Padding file to fill out the filesystem size to FILESYSTEM_SIZE_MB // Padding file to fill out the filesystem size to FILESYSTEM_SIZE_MB
entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT + 1]; if (usedSpace * 2 < FILESYSTEM_SIZE_MB * 1024 * 1024) {
entry = &entries[entryIndex]; entries[entryIndex] = entriesPredefined[PREDEFINED_ENTRY_COUNT + 1];
// used space is doubled because of the individual files plus the single complete file entry = &entries[entryIndex];
entry->curr_size = (FILESYSTEM_SIZE_MB * 1024 * 1024) - (flashfsIdentifyStartOfFreeSpace() * 2); // used space is doubled because of the individual files plus the single complete file
entry->max_size = entry->curr_size; entry->curr_size = (FILESYSTEM_SIZE_MB * 1024 * 1024) - (usedSpace * 2);
// This entry has timestamps corresponding to when the filesystem is mounted entry->max_size = entry->curr_size;
emfat_set_entry_cma(entry); // This entry has timestamps corresponding to when the filesystem is mounted
emfat_set_entry_cma(entry);
}
emfat_init(&emfat, "BETAFLT", entries); emfat_init(&emfat, "BETAFLT", entries);
} }