From 16d54c665a4c966154283b1cb1de61ef407202b1 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 28 May 2024 13:57:05 +0200 Subject: [PATCH] Update dependencies --- Cargo.lock | 60 ++++++++++--------- Cargo.toml | 31 ++++++---- components/apps/src/dispatch.rs | 2 +- components/apps/src/lib.rs | 30 +++++----- components/boards/src/flash.rs | 10 ++-- .../migrations/ftl_journal/ifs_flash_old.rs | 3 +- components/boards/src/nk3xn/prince.rs | 4 +- components/boards/src/soc/nrf52/flash.rs | 3 +- components/boards/src/store.rs | 2 +- components/lfs-backup/src/lfs_backup.rs | 5 +- components/provisioner-app/src/lib.rs | 49 +++++++-------- components/utils/src/storage.rs | 2 +- runners/embedded/Cargo.toml | 3 +- runners/embedded/src/nk3xn/init.rs | 5 +- runners/usbip/src/store.rs | 4 +- 15 files changed, 109 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fb16aa4..ab2f2eb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ version = 3 [[package]] name = "admin-app" version = "0.1.0" -source = "git+https://github.com/Nitrokey/admin-app.git?tag=v0.1.0-nitrokey.13#c24149193fb9bdcaa9ed4dd99fd2a503159a66ee" +source = "git+https://github.com/Nitrokey/admin-app.git?branch=littlefs2#b0eac6363ee40280a35529d1c3c23f7b5864ed31" dependencies = [ "apdu-dispatch", "cbor-smol", @@ -13,7 +13,7 @@ dependencies = [ "delog", "hex-literal 0.4.1", "iso7816", - "littlefs2", + "littlefs2-core", "serde", "strum_macros", "trussed", @@ -839,16 +839,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "cstr_core" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd98742e4fdca832d40cab219dc2e3048de17d873248f83f17df47c1bea70956" -dependencies = [ - "cty", - "memchr", -] - [[package]] name = "csv" version = "1.3.0" @@ -1083,6 +1073,7 @@ dependencies = [ "delog", "embedded-hal", "interchange", + "littlefs2-core", "littlefs2-sys", "lpc55-hal", "lpc55-pac", @@ -1122,7 +1113,7 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encrypted_container" version = "0.1.0" -source = "git+https://github.com/Nitrokey/trussed-secrets-app?tag=v0.13.0#d819e0121f8231f4f9b3f915c32c083bc5f0ad1f" +source = "git+https://github.com/Nitrokey/trussed-secrets-app?branch=littlefs2#2e10b40409c5005df884c2848b64aae01fe21eb3" dependencies = [ "cbor-smol", "delog", @@ -1174,7 +1165,7 @@ dependencies = [ [[package]] name = "fido-authenticator" version = "0.1.1" -source = "git+https://github.com/Nitrokey/fido-authenticator.git?tag=v0.1.1-nitrokey.16#79b05b576863236fe54750b18e862ce0801f2040" +source = "git+https://github.com/Nitrokey/fido-authenticator.git?branch=littlefs2#e8fadf60a2a26b3329c9082e1ea056b486d40c12" dependencies = [ "apdu-dispatch", "cosey", @@ -1183,6 +1174,7 @@ dependencies = [ "delog", "heapless", "iso7816", + "littlefs2-core", "serde", "serde-indexed", "serde_bytes", @@ -1741,26 +1733,32 @@ checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" [[package]] name = "littlefs2" version = "0.4.0" -source = "git+https://github.com/trussed-dev/littlefs2.git?rev=960e57d9fc0d209308c8e15dc26252bbe1ff6ba8#960e57d9fc0d209308c8e15dc26252bbe1ff6ba8" +source = "git+https://github.com/trussed-dev/littlefs2.git?branch=core#95fd60a59c346f3bb6320d0cf5078d84a3193316" dependencies = [ - "bitflags 1.3.2", - "cstr_core", - "cty", "delog", "generic-array", "heapless", + "littlefs2-core", "littlefs2-sys", +] + +[[package]] +name = "littlefs2-core" +version = "0.1.0" +source = "git+https://github.com/trussed-dev/littlefs2.git?branch=core#95fd60a59c346f3bb6320d0cf5078d84a3193316" +dependencies = [ + "bitflags 2.6.0", + "heapless", "serde", ] [[package]] name = "littlefs2-sys" -version = "0.1.7" -source = "git+https://github.com/trussed-dev/littlefs2-sys.git?rev=39626c0dbc2f6c38b74889a5bf9d5a200614f121#39626c0dbc2f6c38b74889a5bf9d5a200614f121" +version = "0.2.0" +source = "git+https://github.com/trussed-dev/littlefs2-sys.git?tag=0.2.0#c12b0dc8b5123c67dc753875dbb02f8b5f85421f" dependencies = [ "bindgen", "cc", - "cty", ] [[package]] @@ -2092,7 +2090,7 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "opcard" version = "1.4.1" -source = "git+https://github.com/Nitrokey/opcard-rs?tag=v1.5.0#0c0f18b0d17155874e06b18726647097d06cb0da" +source = "git+https://github.com/Nitrokey/opcard-rs?branch=littlefs2#10a632de7987cca937b8dcdf719f7e734c6552b8" dependencies = [ "admin-app", "apdu-dispatch", @@ -2103,6 +2101,7 @@ dependencies = [ "heapless-bytes", "hex-literal 0.4.1", "iso7816", + "littlefs2-core", "log", "serde", "serde_repr", @@ -2201,7 +2200,7 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "piv-authenticator" version = "0.3.7" -source = "git+https://github.com/Nitrokey/piv-authenticator.git?tag=v0.3.7#9c88e0bb586ef1c750cc043dff867e3306105d15" +source = "git+https://github.com/trussed-dev/piv-authenticator.git?branch=littlefs2#b34579046ab49c1223cfdba28cdfa3d311fe817b" dependencies = [ "apdu-dispatch", "delog", @@ -2210,6 +2209,7 @@ dependencies = [ "heapless-bytes", "hex-literal 0.3.4", "iso7816", + "littlefs2", "log", "serde", "subtle", @@ -2632,7 +2632,7 @@ dependencies = [ [[package]] name = "secrets-app" version = "0.13.0" -source = "git+https://github.com/Nitrokey/trussed-secrets-app?tag=v0.13.0#d819e0121f8231f4f9b3f915c32c083bc5f0ad1f" +source = "git+https://github.com/Nitrokey/trussed-secrets-app?branch=littlefs2#2e10b40409c5005df884c2848b64aae01fe21eb3" dependencies = [ "apdu-dispatch", "bitflags 2.6.0", @@ -2646,6 +2646,7 @@ dependencies = [ "heapless-bytes", "hex-literal 0.3.4", "iso7816", + "littlefs2-core", "serde", "trussed", "trussed-auth", @@ -3151,7 +3152,7 @@ dependencies = [ [[package]] name = "trussed" version = "0.1.0" -source = "git+https://github.com/nitrokey/trussed.git?tag=v0.1.0-nitrokey.21#66e8fa72939b769587df28550034ba66425dcefd" +source = "git+https://github.com/trussed-dev/trussed.git?branch=littlefs2#12f827a61eccd9805574989e82bae9b02a449b74" dependencies = [ "aes", "bitflags 2.6.0", @@ -3188,7 +3189,7 @@ dependencies = [ [[package]] name = "trussed-auth" version = "0.3.0" -source = "git+https://github.com/trussed-dev/trussed-auth?rev=947ffe6cff426ccbbbb2d0f689437f427665919e#947ffe6cff426ccbbbb2d0f689437f427665919e" +source = "git+https://github.com/trussed-dev/trussed-auth?branch=littlefs2#0d24dca44240b20b9e66e8176e9a2457fe136020" dependencies = [ "chacha20poly1305", "hkdf", @@ -3247,7 +3248,7 @@ dependencies = [ [[package]] name = "trussed-se050-backend" version = "0.3.0" -source = "git+https://github.com/Nitrokey/trussed-se050-backend.git?tag=v0.3.4#351a879379d2e50f6324d1501a4f5788a4a8ad8b" +source = "git+https://github.com/Nitrokey/trussed-se050-backend.git?branch=littlefs2#7181fb9543a97982630ddae0e5709011cdb184a7" dependencies = [ "admin-app", "bitflags 2.6.0", @@ -3290,7 +3291,7 @@ dependencies = [ [[package]] name = "trussed-staging" version = "0.3.0" -source = "git+https://github.com/trussed-dev/trussed-staging.git?tag=v0.3.0#e016b25fbc49f3ba13272d58a9e9d47a16d8ea14" +source = "git+https://github.com/trussed-dev/trussed-staging.git?branch=littlefs2#01fbb0f100b029b47fb314467cdc9959e864b513" dependencies = [ "chacha20poly1305", "delog", @@ -3614,7 +3615,7 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "webcrypt" version = "0.8.0" -source = "git+https://github.com/nitrokey/nitrokey-websmartcard-rust?tag=v0.8.0-rc8#d6705ab95cbc3dd2e4120a5dfa1b8b5a2707b1c7" +source = "git+https://github.com/nitrokey/nitrokey-websmartcard-rust?branch=littlefs2#161f49ab6ba25f1ea9cb55b441a929cb603d4453" dependencies = [ "apdu-dispatch", "cbor-smol", @@ -3625,6 +3626,7 @@ dependencies = [ "heapless", "heapless-bytes", "hmac", + "littlefs2", "serde", "serde-indexed", "serde_bytes", diff --git a/Cargo.toml b/Cargo.toml index 8fb93be9..60967f62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,36 +17,43 @@ version = "1.7.2" memory-regions = { path = "components/memory-regions" } # forked -admin-app = { git = "https://github.com/Nitrokey/admin-app.git", tag = "v0.1.0-nitrokey.13" } +admin-app = { git = "https://github.com/Nitrokey/admin-app.git", branch = "littlefs2" } cbor-smol = { git = "https://github.com/Nitrokey/cbor-smol.git", tag = "v0.4.0-nitrokey.3"} -fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", tag = "v0.1.1-nitrokey.16" } +fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", branch = "littlefs2" } lpc55-hal = { git = "https://github.com/Nitrokey/lpc55-hal", tag = "v0.3.0-nitrokey.2" } -trussed = { git = "https://github.com/nitrokey/trussed.git", tag = "v0.1.0-nitrokey.21" } +# trussed = { git = "https://github.com/Nitrokey/trussed.git", tag = "v0.1.0-nitrokey.21" } +trussed = { git = "https://github.com/trussed-dev/trussed.git", branch = "littlefs2" } # unreleased upstream changes apdu-dispatch = { git = "https://github.com/Nitrokey/apdu-dispatch.git", tag = "v0.1.2-nitrokey.3" } ctaphid-dispatch = { git = "https://github.com/Nitrokey/ctaphid-dispatch.git", tag = "v0.1.1-nitrokey.3" } -littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "960e57d9fc0d209308c8e15dc26252bbe1ff6ba8" } -littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys.git", rev = "39626c0dbc2f6c38b74889a5bf9d5a200614f121" } +littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", branch = "core" } +littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", branch = "core" } +littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys.git", tag = "0.2.0" } usbd-ctaphid = { git = "https://github.com/trussed-dev/usbd-ctaphid.git", rev = "dcff9009c3cd1ef9e5b09f8f307aca998fc9a8c8" } usbd-ccid = { git = "https://github.com/Nitrokey/usbd-ccid", tag = "v0.2.0-nitrokey.1" } p256-cortex-m4 = { git = "https://github.com/ycrypto/p256-cortex-m4.git", rev = "cdb31e12594b4dc1f045b860a885fdc94d96aee2" } # unreleased crates -secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", tag = "v0.13.0" } -webcrypt = { git = "https://github.com/nitrokey/nitrokey-websmartcard-rust", tag = "v0.8.0-rc8" } -opcard = { git = "https://github.com/Nitrokey/opcard-rs", tag = "v1.5.0" } -piv-authenticator = { git = "https://github.com/Nitrokey/piv-authenticator.git", tag = "v0.3.7" } +secrets-app = { git = "https://github.com/Nitrokey/trussed-secrets-app", branch = "littlefs2" } +webcrypt = { git = "https://github.com/nitrokey/nitrokey-websmartcard-rust", branch = "littlefs2" } +# opcard = { git = "https://github.com/Nitrokey/opcard-rs", tag = "v1.5.0" } +opcard = { git = "https://github.com/Nitrokey/opcard-rs", branch = "littlefs2" } +# piv-authenticator = { git = "https://github.com/Nitrokey/piv-authenticator.git", tag = "v0.3.7" } +piv-authenticator = { git = "https://github.com/trussed-dev/piv-authenticator.git", branch = "littlefs2" } trussed-chunked = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "chunked-v0.1.0" } trussed-manage = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "manage-v0.1.0" } trussed-wrap-key-to-file = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "wrap-key-to-file-v0.1.0" } -trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "v0.3.0" } -trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", rev = "947ffe6cff426ccbbbb2d0f689437f427665919e" } +# trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "v0.3.0" } +trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", branch = "littlefs2" } +# trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", rev = "947ffe6cff426ccbbbb2d0f689437f427665919e" } +trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", branch = "littlefs2" } trussed-hkdf = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "hkdf-v0.2.0" } trussed-rsa-alloc = { git = "https://github.com/trussed-dev/trussed-rsa-backend.git", tag = "v0.2.1" } trussed-usbip = { git = "https://github.com/Nitrokey/pc-usbip-runner.git", tag = "v0.0.1-nitrokey.4" } trussed-se050-manage = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", tag = "se050-manage-v0.1.0" } -trussed-se050-backend = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", tag = "v0.3.4" } +# trussed-se050-backend = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", tag = "v0.3.4" } +trussed-se050-backend = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", branch = "littlefs2" } [profile.release] codegen-units = 1 diff --git a/components/apps/src/dispatch.rs b/components/apps/src/dispatch.rs index bc50e226..7ad88cac 100644 --- a/components/apps/src/dispatch.rs +++ b/components/apps/src/dispatch.rs @@ -84,7 +84,7 @@ fn should_preserve_file(file: &Path) -> bool { let mut components = file.iter(); if_chain! { - if components.next() == Some("/".into()); + if components.next().as_deref() == Some(path!("/")); if components.next().is_some(); if let Some(intermediary) = components.next(); if DIRS.contains(&&*intermediary); diff --git a/components/apps/src/lib.rs b/components/apps/src/lib.rs index 2e32cf59..87f82054 100644 --- a/components/apps/src/lib.rs +++ b/components/apps/src/lib.rs @@ -341,7 +341,7 @@ impl Apps { trussed_service: &mut Service>, mut make_client: impl FnMut( &mut Service>, - &'static str, + &'static Path, &'static [BackendId], Option<&'static InterruptFlag>, ) -> Client, @@ -417,7 +417,7 @@ impl Apps { trussed_service: &mut Service>, make_client: impl FnOnce( &mut Service>, - &'static str, + &'static Path, &'static [BackendId], Option<&'static InterruptFlag>, ) -> Client, @@ -549,7 +549,7 @@ impl Apps { runner, trussed_service, |trussed_service, id, backends, interrupt| { - ClientBuilder::new(id) + ClientBuilder::new(id.into()) .backends(backends) .interrupt(interrupt) .prepare(trussed_service) @@ -652,7 +652,7 @@ where &runner, trussed_service, move |trussed_service, id, backends, _| { - ClientBuilder::new(id) + ClientBuilder::new(id.into()) .backends(backends) .prepare(trussed_service) .unwrap() @@ -684,12 +684,12 @@ trait App: Sized { type Config; /// the desired client ID - const CLIENT_ID: &'static str; + const CLIENT_ID: &'static Path; fn new( runner: &R, make_client: impl FnOnce( - &'static str, + &'static Path, &'static [BackendId], Option<&'static InterruptFlag>, ) -> Client, @@ -703,7 +703,7 @@ trait App: Sized { fn client( runner: &R, make_client: impl FnOnce( - &'static str, + &'static Path, &'static [BackendId], Option<&'static InterruptFlag>, ) -> Client, @@ -828,10 +828,10 @@ impl AdminData { } } -const ADMIN_APP_CLIENT_ID: &str = "admin"; +const ADMIN_APP_CLIENT_ID: &Path = path!("admin"); impl App for AdminApp { - const CLIENT_ID: &'static str = ADMIN_APP_CLIENT_ID; + const CLIENT_ID: &'static Path = ADMIN_APP_CLIENT_ID; type Data = AdminData; type Config = (); @@ -866,7 +866,7 @@ pub struct FidoData { #[cfg(feature = "fido-authenticator")] impl App for FidoApp { - const CLIENT_ID: &'static str = "fido"; + const CLIENT_ID: &'static Path = path!("fido"); type Data = FidoData; type Config = FidoConfig; @@ -909,7 +909,7 @@ impl App for FidoApp { #[cfg(feature = "webcrypt")] impl App for WebcryptApp { - const CLIENT_ID: &'static str = "webcrypt"; + const CLIENT_ID: &'static Path = path!("webcrypt"); type Data = (); type Config = (); @@ -939,7 +939,7 @@ impl App for WebcryptApp { #[cfg(feature = "secrets-app")] impl App for SecretsApp { - const CLIENT_ID: &'static str = "secrets"; + const CLIENT_ID: &'static Path = path!("secrets"); type Data = (); type Config = (); @@ -972,7 +972,7 @@ static OPCARD_RESET_SIGNAL: ResetSignalAllocation = ResetSignalAllocation::new() #[cfg(feature = "opcard")] impl App for OpcardApp { - const CLIENT_ID: &'static str = "opcard"; + const CLIENT_ID: &'static Path = path!("opcard"); type Data = (); type Config = OpcardConfig; @@ -1038,7 +1038,7 @@ impl App for OpcardApp { #[cfg(feature = "piv-authenticator")] impl App for PivApp { - const CLIENT_ID: &'static str = "piv"; + const CLIENT_ID: &'static Path = path!("piv"); type Data = (); type Config = (); @@ -1075,7 +1075,7 @@ pub struct ProvisionerData { #[cfg(feature = "provisioner-app")] impl App for ProvisionerApp { - const CLIENT_ID: &'static str = "attn"; + const CLIENT_ID: &'static Path = path!("attn"); type Data = ProvisionerData; type Config = (); diff --git a/components/boards/src/flash.rs b/components/boards/src/flash.rs index 2bc6650d..bd26f9fd 100644 --- a/components/boards/src/flash.rs +++ b/components/boards/src/flash.rs @@ -46,7 +46,7 @@ where return Ok(0); }*/ if buf.len() > FLASH_PROPERTIES.size || off > FLASH_PROPERTIES.size - buf.len() { - return Err(Error::Unknown(0x6578_7046)); + return Err(Error::IO); } let mut flash = self.s25flash.borrow_mut(); let r = flash.read(off as u32, buf); @@ -62,9 +62,7 @@ where for chunk in data.chunks(CHUNK_SIZE) { let buf = &mut buf[..chunk.len()]; buf.copy_from_slice(chunk); - flash - .write_bytes(off, buf) - .map_err(|_| Error::Unknown(0x6565_6565))?; + flash.write_bytes(off, buf).map_err(|_| Error::IO)?; off += CHUNK_SIZE as u32; } Ok(data.len()) @@ -73,7 +71,7 @@ where fn erase(&mut self, off: usize, len: usize) -> Result { trace!("EFe {:x} {:x}", off, len); if len > FLASH_PROPERTIES.size || off > FLASH_PROPERTIES.size - len { - return Err(Error::Unknown(0x6578_7046)); + return Err(Error::IO); } let result = self .s25flash @@ -93,7 +91,7 @@ where { match r { Ok(()) => Ok(len), - Err(_) => Err(Error::Unknown(0x6565_6565)), + Err(_) => Err(Error::IO), } } diff --git a/components/boards/src/nk3am/migrations/ftl_journal/ifs_flash_old.rs b/components/boards/src/nk3am/migrations/ftl_journal/ifs_flash_old.rs index 7e073e27..b57b3ec3 100644 --- a/components/boards/src/nk3am/migrations/ftl_journal/ifs_flash_old.rs +++ b/components/boards/src/nk3am/migrations/ftl_journal/ifs_flash_old.rs @@ -78,8 +78,7 @@ fn nvmc_to_lfs_return( r: Result<(), nrf52840_hal::nvmc::NvmcError>, len: usize, ) -> Result { - r.map(|_| len) - .map_err(|_| littlefs2::io::Error::Unknown(0x4e56_4d43)) // 'NVMC' + r.map(|_| len).map_err(|_| littlefs2::io::Error::IO) // 'NVMC' } impl FlashStorage { diff --git a/components/boards/src/nk3xn/prince.rs b/components/boards/src/nk3xn/prince.rs index e5eab61a..e14efe99 100644 --- a/components/boards/src/nk3xn/prince.rs +++ b/components/boards/src/nk3xn/prince.rs @@ -108,7 +108,7 @@ impl Storage for InternalFilesystem { let ret = self.prince.write_encrypted(|prince| { with_enabled(prince, || self.flash_gordon.write(FS_START + off, data)) }); - ret.map(|_| data.len()).map_err(|_| Error::Io) + ret.map(|_| data.len()).map_err(|_| Error::IO) } fn erase(&mut self, off: usize, len: usize) -> Result { @@ -118,7 +118,7 @@ impl Storage for InternalFilesystem { for i in 0..pages { self.flash_gordon .erase_page(first_page + i) - .map_err(|_| Error::Io)?; + .map_err(|_| Error::IO)?; } Ok(BLOCK_SIZE * pages) } diff --git a/components/boards/src/soc/nrf52/flash.rs b/components/boards/src/soc/nrf52/flash.rs index a1ad9bee..18b3b2bf 100644 --- a/components/boards/src/soc/nrf52/flash.rs +++ b/components/boards/src/soc/nrf52/flash.rs @@ -269,8 +269,7 @@ fn nvmc_to_lfs_return( r: Result<(), nrf52840_hal::nvmc::NvmcError>, len: usize, ) -> Result { - r.map(|_| len) - .map_err(|_| littlefs2::io::Error::Unknown(0x4e56_4d43)) // 'NVMC' + r.map(|_| len).map_err(|_| littlefs2::io::Error::IO) // 'NVMC' } impl FlashStorage { diff --git a/components/boards/src/store.rs b/components/boards/src/store.rs index 7c2f20e0..e8c01b21 100644 --- a/components/boards/src/store.rs +++ b/components/boards/src/store.rs @@ -267,7 +267,7 @@ fn init_efs( ) -> LfsResult> { if !Filesystem::is_mountable(efs_storage) { let fmt_ext = Filesystem::format(efs_storage); - if simulated_efs && fmt_ext == Err(littlefs2::io::Error::NoSpace) { + 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); diff --git a/components/lfs-backup/src/lfs_backup.rs b/components/lfs-backup/src/lfs_backup.rs index 6b68ffdc..62e2079d 100644 --- a/components/lfs-backup/src/lfs_backup.rs +++ b/components/lfs-backup/src/lfs_backup.rs @@ -1,6 +1,7 @@ use littlefs2::consts::PATH_MAX; use littlefs2::fs::{Attribute, DirEntry, Filesystem}; +use littlefs2::path; use littlefs2::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; @@ -167,12 +168,12 @@ pub trait BackupBackend { &mut self, fs: &Filesystem, ) -> Result<(usize, usize)> { - let root_dir = PathBuf::from("/"); + let root_dir = path!("/"); let mut path_stack: Vec = Vec::new(); path_stack .push(PathCursor { - path: root_dir, + path: root_dir.into(), idx: 0, attr: None, }) diff --git a/components/provisioner-app/src/lib.rs b/components/provisioner-app/src/lib.rs index 124ce763..6d784793 100644 --- a/components/provisioner-app/src/lib.rs +++ b/components/provisioner-app/src/lib.rs @@ -19,7 +19,10 @@ generate_macros!(); use core::convert::TryFrom; use heapless::Vec; -use littlefs2::path::PathBuf; +use littlefs2::{ + path, + path::{Path, PathBuf}, +}; use trussed::{ client, key::{Flags, Key, Kind as KeyKind}, @@ -92,15 +95,15 @@ pub enum Error { type Uuid = [u8; 16]; -const FILENAME_T1_PUBLIC: &[u8] = b"/attn/pub/00"; +const FILENAME_T1_PUBLIC: &Path = path!("/attn/pub/00"); -const FILENAME_P256_SECRET: &[u8] = b"/attn/sec/01"; -const FILENAME_ED255_SECRET: &[u8] = b"/attn/sec/02"; -const FILENAME_X255_SECRET: &[u8] = b"/attn/sec/03"; +const FILENAME_P256_SECRET: &Path = path!("/attn/sec/01"); +const FILENAME_ED255_SECRET: &Path = path!("/attn/sec/02"); +const FILENAME_X255_SECRET: &Path = path!("/attn/sec/03"); -const FILENAME_P256_CERT: &[u8] = b"/attn/x5c/01"; -const FILENAME_ED255_CERT: &[u8] = b"/attn/x5c/02"; -const FILENAME_X255_CERT: &[u8] = b"/attn/x5c/03"; +const FILENAME_P256_CERT: &Path = path!("/attn/x5c/01"); +const FILENAME_ED255_CERT: &Path = path!("/attn/x5c/02"); +const FILENAME_X255_CERT: &Path = path!("/attn/x5c/03"); enum SelectedBuffer { Filename, @@ -194,7 +197,7 @@ where let res = store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(self.buffer_filename.as_slice()), + &PathBuf::try_from(self.buffer_filename.as_slice()).unwrap(), &self.buffer_file_contents, ); self.buffer_file_contents.clear(); @@ -239,14 +242,11 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_P256_SECRET), + FILENAME_P256_SECRET, &serialized_bytes, ) .map_err(|_| Error::NotEnoughMemory)?; - info!( - "stored to {}", - core::str::from_utf8(FILENAME_P256_SECRET).unwrap() - ); + info!("stored to {}", FILENAME_P256_SECRET); reply .extend_from_slice(&keypair.public.to_untagged_bytes()) @@ -272,7 +272,7 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_ED255_SECRET), + FILENAME_ED255_SECRET, &serialized_bytes, ) .map_err(|_| Error::NotEnoughMemory)?; @@ -301,7 +301,7 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_X255_SECRET), + FILENAME_X255_SECRET, &serialized_bytes, ) .map_err(|_| Error::NotEnoughMemory)?; @@ -313,8 +313,7 @@ where Ok(()) } Instruction::SaveP256AttestationCertificate => { - let secret_path = PathBuf::from(FILENAME_P256_SECRET); - if !secret_path.exists(self.store.ifs()) || data.len() < 100 { + if !self.store.ifs().exists(FILENAME_P256_SECRET) || data.len() < 100 { // Assuming certs will always be >100 bytes Err(Error::IncorrectDataParameter) } else { @@ -322,7 +321,7 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_P256_CERT), + FILENAME_P256_CERT, data, ) .map_err(|_| Error::NotEnoughMemory)?; @@ -330,8 +329,7 @@ where } } Instruction::SaveEd255AttestationCertificate => { - let secret_path = PathBuf::from(FILENAME_ED255_SECRET); - if !secret_path.exists(self.store.ifs()) || data.len() < 100 { + if !self.store.ifs().exists(FILENAME_ED255_SECRET) || data.len() < 100 { // Assuming certs will always be >100 bytes Err(Error::IncorrectDataParameter) } else { @@ -339,7 +337,7 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_ED255_CERT), + FILENAME_ED255_CERT, data, ) .map_err(|_| Error::NotEnoughMemory)?; @@ -347,8 +345,7 @@ where } } Instruction::SaveX255AttestationCertificate => { - let secret_path = PathBuf::from(FILENAME_X255_SECRET); - if !secret_path.exists(self.store.ifs()) || data.len() < 100 { + if !self.store.ifs().exists(FILENAME_X255_SECRET) || data.len() < 100 { // Assuming certs will always be >100 bytes Err(Error::IncorrectDataParameter) } else { @@ -356,7 +353,7 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_X255_CERT), + FILENAME_X255_CERT, data, ) .map_err(|_| Error::NotEnoughMemory)?; @@ -379,7 +376,7 @@ where store::store( self.store, trussed::types::Location::Internal, - &PathBuf::from(FILENAME_T1_PUBLIC), + FILENAME_T1_PUBLIC, &serialized_key, ) .map_err(|_| Error::NotEnoughMemory) diff --git a/components/utils/src/storage.rs b/components/utils/src/storage.rs index 2063a00b..21b2ceab 100644 --- a/components/utils/src/storage.rs +++ b/components/utils/src/storage.rs @@ -38,7 +38,7 @@ impl Storage for RamStorage { fn write(&mut self, off: usize, data: &[u8]) -> Result { if off + data.len() > SIZE { - return Err(Error::NoSpace); + return Err(Error::NO_SPACE); } let write_size: usize = Self::WRITE_SIZE; debug_assert!(off % write_size == 0); diff --git a/runners/embedded/Cargo.toml b/runners/embedded/Cargo.toml index 18ef12ba..12b6f9ab 100644 --- a/runners/embedded/Cargo.toml +++ b/runners/embedded/Cargo.toml @@ -17,6 +17,7 @@ cortex-m = { version = "0.7", features = ["critical-section-single-core"]} cortex-m-rt = "0.6.15" cortex-m-rtic = "1.0" embedded-hal = "0.2.3" +littlefs2-core = "0.1" nfc-device = { path = "../../components/nfc-device" } utils = { path = "../../components/utils", features = ["storage"] } @@ -45,7 +46,7 @@ systick-monotonic = { version = "1.0.0", optional = true } alloc-cortex-m = { version = "0.4.3", optional = true } # littlefs2-sys for intrinsics feature -littlefs2-sys = { version = "0.1.7", optional = true } +littlefs2-sys = { version = "0.2", optional = true } [build-dependencies] cargo-lock = "7" diff --git a/runners/embedded/src/nk3xn/init.rs b/runners/embedded/src/nk3xn/init.rs index 9a4b71ee..442218b2 100644 --- a/runners/embedded/src/nk3xn/init.rs +++ b/runners/embedded/src/nk3xn/init.rs @@ -57,11 +57,12 @@ use hal::{ Pin, }; use interchange::Channel; +use littlefs2_core::path; use lpc55_hal as hal; #[cfg(any(feature = "log-info", feature = "log-all"))] use lpc55_hal::drivers::timer::Elapsed as _; use nfc_device::Iso14443; -use trussed::types::{Location, PathBuf}; +use trussed::types::Location; use utils::OptionalStorage; use crate::{VERSION, VERSION_STRING}; @@ -757,7 +758,7 @@ impl Stage6 { let res = trussed::store::store( self.store, Location::Internal, - &PathBuf::from("fido/x5c/00"), + path!("fido/x5c/00"), include_bytes!("../../data/fido-cert.der"), ); if res.is_err() { diff --git a/runners/usbip/src/store.rs b/runners/usbip/src/store.rs index b3c7fd77..744087e2 100644 --- a/runners/usbip/src/store.rs +++ b/runners/usbip/src/store.rs @@ -101,7 +101,7 @@ impl LfsStorage for FilesystemStorage { fn write(&mut self, offset: usize, data: &[u8]) -> LfsResult { if offset + data.len() > Self::BLOCK_COUNT * Self::BLOCK_SIZE { - return Err(littlefs2::io::Error::NoSpace); + return Err(littlefs2::io::Error::NO_SPACE); } let mut file = OpenOptions::new().write(true).open(&self.path).unwrap(); file.seek(SeekFrom::Start(offset as _)).unwrap(); @@ -113,7 +113,7 @@ impl LfsStorage for FilesystemStorage { fn erase(&mut self, offset: usize, len: usize) -> LfsResult { if offset + len > Self::BLOCK_COUNT * Self::BLOCK_SIZE { - return Err(littlefs2::io::Error::NoSpace); + return Err(littlefs2::io::Error::NO_SPACE); } let mut file = OpenOptions::new().write(true).open(&self.path).unwrap(); file.seek(SeekFrom::Start(offset as _)).unwrap();