Nitrokey / nitrokey-3-firmware

Nitrokey 3 firmware
Apache License 2.0
224 stars 22 forks source link

Avoid is_mountable calls #440

Open robin-nitrokey opened 5 months ago

robin-nitrokey commented 5 months ago

Filesystem::is_mountable calls Filesystem::mount, checks the result and drops the mounted filesystem. This means that code that first calls is_mountable and then mount on the same storage mounts the storage twice.

https://github.com/Nitrokey/nitrokey-3-firmware/blob/6f032b5733b9c40621069cb29ef00bed028863fd/components/boards/src/store.rs#L275-L283

Instead we should first call Filesystem::mount and handle the error case directly.

robin-nitrokey commented 2 months ago

This should significantly reduce bootup time. With logging enabled (log-semihosting,log-info), removing the is_mountable call reduces the mount time from 1 000 ms to 500 ms and the total bootup time from 2 300 ms to 1 800 ms. Unfortunately, the borrow checker does not allow us to re-try the mount in the error case because of the static lifetime of the returned filesystem. Maybe we can find a workaround.

sosthene-nitrokey commented 2 months ago

We could have a mount_or_format method in littlefs2 ?

I'm not sure I see the borrow checker error. Is this NLL case N°3 again?

robin-nitrokey commented 2 months ago

Yes, we can do it in littlefs2 but not directly in the firmware.