From 4a045178dbb99e79b3ac65278b26ef96c07ff3e3 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 24 Apr 2024 19:42:08 +0200 Subject: [PATCH] Mount EFS only once With this patch, the EFS is only mounted once if it is mountable. This significantly reduces bootup time by approximately 0.5 s. Fixes: https://github.com/Nitrokey/nitrokey-3-firmware/issues/440 --- CHANGELOG.md | 2 ++ components/boards/src/store.rs | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d3398b..38a37854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,12 @@ - admin-app: Add command to list all supported config fields ([admin-app#28][]) - admin-app: Add `opcard.disabled` configuration option to disable OpenPGP ([#539][]) - piv: Use SE050 and encrypt data on external flash ([#534][]) +- Improve external flash mounting to decrease startup time ([#440][]) [admin-app#28]: https://github.com/Nitrokey/admin-app/issues/28 [fido-authenticator#38]: https://github.com/Nitrokey/fido-authenticator/issues/38 [piv-authenticator#38]: https://github.com/Nitrokey/piv-authenticator/issues/38 +[#440]: https://github.com/Nitrokey/nitrokey-3-firmware/issues/440 [#524]: https://github.com/Nitrokey/nitrokey-3-firmware/pull/524 [#534]: https://github.com/Nitrokey/nitrokey-3-firmware/pull/534 [#539]: https://github.com/Nitrokey/nitrokey-3-firmware/pull/539 diff --git a/components/boards/src/store.rs b/components/boards/src/store.rs index e8c01b21..bc989236 100644 --- a/components/boards/src/store.rs +++ b/components/boards/src/store.rs @@ -265,16 +265,17 @@ fn init_efs( simulated_efs: bool, status: &mut InitStatus, ) -> LfsResult> { - if !Filesystem::is_mountable(efs_storage) { - let fmt_ext = Filesystem::format(efs_storage); + Filesystem::mount_or_else(efs_alloc, efs_storage, |_err, storage| { + error_now!("EFS Mount Error {:?}", _err); + let fmt_ext = Filesystem::format(storage); if simulated_efs && fmt_ext == Err(littlefs2::io::Error::NO_SPACE) { info_now!("Formatting simulated EFS failed as expected"); } else { - error_now!("EFS Mount Error, Reformat {:?}", fmt_ext); + error_now!("EFS Reformat {:?}", fmt_ext); status.insert(InitStatus::EXTERNAL_FLASH_ERROR); } - }; - Filesystem::mount(efs_alloc, efs_storage) + Ok(()) + }) } #[inline(always)]