Skip to content

Fix LittleFS formatting freeze bug #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2023
Merged

Fix LittleFS formatting freeze bug #98

merged 1 commit into from
Aug 16, 2023

Conversation

alrvid
Copy link
Contributor

@alrvid alrvid commented Aug 16, 2023

LittleFileSystem::reformat() on the SD Card block device internally runs LittleFileSystem::format() and then LittleFileSystem::mount() in a sequence. After LittleFileSystem::format()'s main job is performed using the LittleFS file system driver one level below it, it runs deinit() on the block device. That leads, after a series of calls, to a call to the Renesas FSP function R_SDHI_Close(), which sets the initialized field of the ctrl structure to false. LittleFileSystem::mount() runs next, and begins by running init() on the block device, but because it's still in a state where card_inserted and initialized are true, full initialization doesn't occur - only parts of it. This leaves the initialized field of the ctrl structure being false, which leads to the FSP-internal function r_sdhi_common_error_check() returning an error when it's called by the FSP function R_SDHI_Read() from SDCardBlockDevice::read(), which is, in turn, called from LittleFileSystem::mount(). This is caught by the LittleFS file system driver function lfs_bd_read() at the layer directly over the SDCardBlockDevice::read() function, which, in turn, sends the board into an infinite loop and the format freezes.

LittleFileSystem::reformat() on the SD Card block device internally runs LittleFileSystem::format() and then LittleFileSystem::mount() in a sequence. After LittleFileSystem::format()'s main job is performed using the LittleFS file system driver one level below it, it runs deinit() on the block device. That leads, after a series of calls, to a call to the Renesas FSP function R_SDHI_Close(), which sets the initialized field of the ctrl structure to false. LittleFileSystem::mount() runs next, and begins by running init() on the block device, but because it's still in a state where card_inserted and initialized are true, full initialization doesn't occur - only parts of it. This leaves the initialized field of the ctrl structure being false, which leads to the FSP-internal function r_sdhi_common_error_check() returning an error when it's called by the FSP function R_SDHI_Read() from SDCardBlockDevice::read(), which is, in turn, called from LittleFileSystem::mount(). This is caught by the LittleFS file system driver function lfs_bd_read() at the layer directly over the SDCardBlockDevice::read() function, which, in turn, sends the board into an infinite loop and the format freezes.
@alrvid alrvid merged commit f19b922 into arduino:main Aug 16, 2023
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Aug 16, 2023
@per1234 per1234 linked an issue Aug 16, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting with mbed reformat() fails
3 participants