Storage: Dont send mount event if SD mounted at boot #4290
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the switch to
/inton/exthappened, a system was added to load config files when SD card is inserted. I use a similar approach for a few extra things in my fork downstream, and noticed some issues today updating from dev branch. This is not a a new bug here, but rather a side effect of a "bug"/misbehavior that has existed here for a long time.Most services using this system to load on boot and also on SD card mount do this when starting:
If SD card is present at boot, these services will load config right away, but when storage service finishes starting it will send a SD card mount event, meaning the configs are loaded twice.
In most cases this makes little difference, but for example it means BT keys are loaded twice and BT stack is started twice for no reason. And in my case, I had ble extra beacon setting up at boot with this same system, and just today it started bootlooping because it starts twice and there is probably some race condition somewhere between restarting ble stack and 2 threads wanting to setup ble extra beacon, which made me investigate and notice the double loading.
Some traces of this can be found 3+ years back:
flipperzero-firmware/applications/system/updater/scenes/updater_scene_main.c
Lines 35 to 45 in 85b6b2b
This had a different symptom but seems like same underlying issue of sending SD card mount after storage started. Also wording is a little wrong here, SD card is usually mounted even before storage finishes starting, in
storage_app_alloc()insidestorage_ext_init()withstorage_ext_tick_internal()Sd card is mounted immediately if present, the bug was not about mounting late but about storage tick detecting late that it was mounted.What's new
sd_guias already enabled if SD is present meansstorage_tick()will not detect the mount after starting as if it just happened, it already knows it was mounted from initThe alternative would work poorly: if all services did not check for SD card at boot on their own and rely on storage to send the mount event at boot, it could be that one service starts after storage and so it misses the mount event, which would be a tiny subtlety that causes config not to load on boot at all and be unreliable overall.
Verification
Checklist (For Reviewer)