diff --git a/Cargo.lock b/Cargo.lock index 55edbe6f..104923ec 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", @@ -840,16 +840,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" @@ -1084,6 +1074,7 @@ dependencies = [ "delog", "embedded-hal", "interchange", + "littlefs2-core", "littlefs2-sys", "lpc55-hal", "lpc55-pac", @@ -1123,7 +1114,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", @@ -1175,7 +1166,7 @@ dependencies = [ [[package]] name = "fido-authenticator" version = "0.1.1" -source = "git+https://github.com/Nitrokey/fido-authenticator.git?tag=v0.1.1-nitrokey.19#0fdecc93df800543aed0f1de0ea0f7178cf93b80" +source = "git+https://github.com/Nitrokey/fido-authenticator.git?branch=littlefs2#91584908c86d8912334bed920158009b89b52f91" dependencies = [ "apdu-dispatch", "cbor-smol", @@ -1185,6 +1176,7 @@ dependencies = [ "delog", "heapless", "iso7816", + "littlefs2-core", "serde", "serde-indexed", "serde_bytes", @@ -1726,7 +1718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1744,26 +1736,33 @@ 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?rev=a1f8d9e87bc70765b488625e5844dbce4c1568cc#a1f8d9e87bc70765b488625e5844dbce4c1568cc" 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?rev=a1f8d9e87bc70765b488625e5844dbce4c1568cc#a1f8d9e87bc70765b488625e5844dbce4c1568cc" +dependencies = [ + "bitflags 2.6.0", + "heapless", + "heapless-bytes", "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]] @@ -2095,7 +2094,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", @@ -2106,6 +2105,7 @@ dependencies = [ "heapless-bytes", "hex-literal 0.4.1", "iso7816", + "littlefs2-core", "log", "serde", "serde_repr", @@ -2204,7 +2204,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", @@ -2213,6 +2213,7 @@ dependencies = [ "heapless-bytes", "hex-literal 0.3.4", "iso7816", + "littlefs2", "log", "serde", "subtle", @@ -2635,7 +2636,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", @@ -2649,6 +2650,7 @@ dependencies = [ "heapless-bytes", "hex-literal 0.3.4", "iso7816", + "littlefs2-core", "serde", "trussed", "trussed-auth", @@ -3154,7 +3156,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/Nitrokey/trussed.git?branch=littlefs2-nk#a386be09679f4d3c5c26f4e7637338a0defda7ab" dependencies = [ "aes", "bitflags 2.6.0", @@ -3175,6 +3177,7 @@ dependencies = [ "hmac", "interchange", "littlefs2", + "littlefs2-core", "nb 1.1.0", "p256-cortex-m4", "postcard 0.7.3", @@ -3191,7 +3194,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", @@ -3260,7 +3263,7 @@ dependencies = [ [[package]] name = "trussed-se050-backend" version = "0.3.0" -source = "git+https://github.com/Nitrokey/trussed-se050-backend.git?tag=v0.3.5#f04beb6e1d5cc0ec84af4fcdc05338450c24cb0e" +source = "git+https://github.com/Nitrokey/trussed-se050-backend.git?branch=littlefs2#8877088c3fbf4c67f68701d0d38462f8b221038f" dependencies = [ "admin-app", "bitflags 2.6.0", @@ -3304,7 +3307,7 @@ dependencies = [ [[package]] name = "trussed-staging" version = "0.3.0" -source = "git+https://github.com/trussed-dev/trussed-staging.git?tag=v0.3.1#72b082002e0869facfc11bf8d76a1272c7ddf4ee" +source = "git+https://github.com/trussed-dev/trussed-staging.git?branch=littlefs2#4148fdab7e47844e890e81512955490b2bb773b7" dependencies = [ "chacha20poly1305", "delog", @@ -3629,7 +3632,7 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "webcrypt" version = "0.8.0" -source = "git+https://github.com/nitrokey/nitrokey-websmartcard-rust?tag=v0.8.0-rc9#5179795e6b1015efcfbbe22ad555fc5ae63d09bd" +source = "git+https://github.com/nitrokey/nitrokey-websmartcard-rust?branch=littlefs2#7a16620d2ca377f8ac244119dd864df596390c95" dependencies = [ "apdu-dispatch", "cbor-smol", @@ -3640,6 +3643,7 @@ dependencies = [ "heapless", "heapless-bytes", "hmac", + "littlefs2", "serde", "serde-indexed", "serde_bytes", @@ -3855,8 +3859,3 @@ dependencies = [ "quote", "syn 2.0.69", ] - -[[patch.unused]] -name = "ctap-types" -version = "0.2.0" -source = "git+https://github.com/trussed-dev/ctap-types.git?rev=72eb68b61e3f14957c5ab89bd22f776ac860eb62#72eb68b61e3f14957c5ab89bd22f776ac860eb62" diff --git a/Cargo.toml b/Cargo.toml index d2a6b10d..0c5bd6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,38 +17,45 @@ 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.4"} -fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", tag = "v0.1.1-nitrokey.19" } +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" } +trussed = { git = "https://github.com/Nitrokey/trussed.git", branch = "littlefs2-nk" } # 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", rev = "a1f8d9e87bc70765b488625e5844dbce4c1568cc" } +littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "a1f8d9e87bc70765b488625e5844dbce4c1568cc" } +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" } -ctap-types = { git = "https://github.com/trussed-dev/ctap-types.git", rev = "72eb68b61e3f14957c5ab89bd22f776ac860eb62" } # 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-rc9" } -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" } -trussed-fs-info = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "fs-info-v0.1.0" } +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-fs-info = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "fs-info-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.1" } -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.5" } +# 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 fdae5660..ecf6a9d2 100644 --- a/components/apps/src/dispatch.rs +++ b/components/apps/src/dispatch.rs @@ -85,7 +85,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 9495156c..ff97f26c 100644 --- a/components/apps/src/lib.rs +++ b/components/apps/src/lib.rs @@ -14,7 +14,6 @@ use ctaphid_dispatch::app::App as CtaphidApp; #[cfg(feature = "se050")] use embedded_hal::blocking::delay::DelayUs; use heapless::Vec; -#[cfg(any(feature = "factory-reset", feature = "se050"))] use littlefs2::path; #[cfg(feature = "factory-reset")] @@ -341,7 +340,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 +416,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 +548,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 +651,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 +683,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 +702,7 @@ trait App: Sized { fn client( runner: &R, make_client: impl FnOnce( - &'static str, + &'static Path, &'static [BackendId], Option<&'static InterruptFlag>, ) -> Client, @@ -828,10 +827,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 +865,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 +908,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 +938,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 +971,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; @@ -1042,7 +1041,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 = (); @@ -1079,7 +1078,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..74c07ddb 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, }) @@ -197,8 +198,9 @@ pub trait BackupBackend { // move index "pointer" to next item current.idx += 1; + let mut buffer = [0; Attribute::MAX_SIZE as _]; let attr = fs - .attribute(entry.path(), USER_ATTRIBUTE_NUMBER)? + .attribute(entry.path(), USER_ATTRIBUTE_NUMBER, &mut buffer)? .map(|v| UserAttribute::from_slice(v.data())) .transpose() .map_err(|_| FSBackupError::UserAttributeErr)?; @@ -267,9 +269,7 @@ pub trait BackupBackend { fs.create_dir(path)?; if let Some(user_attr) = v.attr { - let mut attr = Attribute::new(USER_ATTRIBUTE_NUMBER); - attr.set_data(user_attr.as_slice()); - fs.set_attribute(path, &attr)? + fs.set_attribute(path, USER_ATTRIBUTE_NUMBER, user_attr.as_slice())? }; } else { f_cnt += 1; @@ -277,9 +277,7 @@ pub trait BackupBackend { fs.write(path, content.as_slice())?; if let Some(user_attr) = v.attr { - let mut attr = Attribute::new(USER_ATTRIBUTE_NUMBER); - attr.set_data(user_attr.as_slice()); - fs.set_attribute(path, &attr)?; + fs.set_attribute(path, USER_ATTRIBUTE_NUMBER, user_attr.as_slice())?; }; } } 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();