From edc04893e99ae38eaf62419298b3c72955d05840 Mon Sep 17 00:00:00 2001 From: David Ge Date: Wed, 18 Sep 2024 13:01:44 -0500 Subject: [PATCH 1/2] expose map item iterator, to load all items in one pass --- CHANGELOG.md | 1 + src/item.rs | 6 +++-- src/lib.rs | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/queue.rs | 2 +- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43686a0..1516a5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - *Breaking:* Added `Value` impls for `bool`, `Option`, and `[T: Value; N]`. *This can break existing code because it changes type inference, be mindfull of that!* +- Expose map item iterator, to load all items in one pass ## 3.0.1 25-07-24 diff --git a/src/item.rs b/src/item.rs index 6361fb0..564501f 100644 --- a/src/item.rs +++ b/src/item.rs @@ -506,17 +506,19 @@ pub async fn is_page_empty( } } +/// An iterator-like interface to iterate over items in page pub struct ItemIter { header: ItemHeaderIter, } impl ItemIter { - pub fn new(start_address: u32, end_address: u32) -> Self { + pub(crate) fn new(start_address: u32, end_address: u32) -> Self { Self { header: ItemHeaderIter::new(start_address, end_address), } } + /// iterator next pub async fn next<'m, S: NorFlash>( &mut self, flash: &mut S, @@ -543,7 +545,7 @@ impl ItemIter { pub struct ItemHeaderIter { current_address: u32, - end_address: u32, + pub(crate) end_address: u32, } impl ItemHeaderIter { diff --git a/src/lib.rs b/src/lib.rs index 567c4ab..a541b8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,13 +7,15 @@ // - flash erase size is quite big, aka, this is a paged flash // - flash write size is quite small, so it writes words and not full pages -use cache::PrivateCacheImpl; +use cache::{CacheImpl, PrivateCacheImpl}; use core::{ fmt::Debug, ops::{Deref, DerefMut, Range}, }; use embedded_storage_async::nor_flash::NorFlash; +pub use item::ItemIter; use map::SerializationError; +use queue::find_oldest_page; #[cfg(feature = "arrayvec")] mod arrayvec_impl; @@ -32,6 +34,65 @@ pub mod mock_flash; /// Many flashes have 4-byte or 1-byte words. const MAX_WORD_SIZE: usize = 32; +/// Storage configuration +pub struct Storage<'s, S: NorFlash, CI: CacheImpl> { + /// flash + pub flash: &'s mut S, + /// range + pub flash_range: Range, + /// cache + pub cache: &'s mut CI, +} +impl<'s, S: NorFlash, CI: CacheImpl> Storage<'s, S, CI> { + /// constructor + pub fn new(flash: &'s mut S, flash_range: Range, cache: &'s mut CI) -> Self { + Self { + flash, + flash_range, + cache, + } + } + + /// return iterator for used page + pub async fn iter(&mut self) -> Result> { + let index = find_oldest_page(self.flash, self.flash_range.clone(), self.cache).await?; + + Ok(PageIter { index }) + } +} +/// An iterator-like interface to iterate over Closed and PartialOpen pages +/// This goes from oldest to newest. +pub struct PageIter { + index: usize, +} +impl PageIter { + /// return iterator for items in page + pub async fn next<'s, S: NorFlash, CI: CacheImpl>( + &mut self, + storage: &mut Storage<'s, S, CI>, + ) -> Result, Error> { + let r = match get_page_state( + storage.flash, + storage.flash_range.clone(), + storage.cache, + self.index, + ) + .await + { + Ok(PageState::Closed) | Ok(PageState::PartialOpen) => Some(ItemIter::new( + calculate_page_address::(storage.flash_range.clone(), self.index), + calculate_page_end_address::(storage.flash_range.clone(), self.index), + )), + _ => None, + }; + self.index += 1; + if self.index >= storage.flash_range.len() / S::ERASE_SIZE { + self.index = 0; + } + Ok(r) + } +} + /// Resets the flash in the entire given flash range. /// /// This is just a thin helper function as it just calls the flash's erase function. diff --git a/src/queue.rs b/src/queue.rs index a56d965..a85f536 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -710,7 +710,7 @@ async fn find_youngest_page( }) } -async fn find_oldest_page( +pub(crate) async fn find_oldest_page( flash: &mut S, flash_range: Range, cache: &mut impl PrivateCacheImpl, From 3d743f945664bd28169facb2beb5d8e96b42c137 Mon Sep 17 00:00:00 2001 From: David Ge Date: Wed, 18 Sep 2024 19:47:55 -0500 Subject: [PATCH 2/2] Add host tool, allow experiment, inspect dump file in the host environment. --- .gitignore | 2 +- .vscode/settings.json | 3 +- CHANGELOG.md | 1 + host-tool/Cargo.lock | 501 ++++++++++++++++++++++++++++++++++++++++++ host-tool/Cargo.toml | 9 + host-tool/rmk.raw | Bin 0 -> 65536 bytes host-tool/src/main.rs | 96 ++++++++ 7 files changed, 610 insertions(+), 2 deletions(-) create mode 100644 host-tool/Cargo.lock create mode 100644 host-tool/Cargo.toml create mode 100755 host-tool/rmk.raw create mode 100644 host-tool/src/main.rs diff --git a/.gitignore b/.gitignore index 4fffb2f..d2599e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target +target /Cargo.lock diff --git a/.vscode/settings.json b/.vscode/settings.json index 2b0ee9f..65677c4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "rust-analyzer.linkedProjects": [ "Cargo.toml", "fuzz/Cargo.toml", - "example/Cargo.toml" + "example/Cargo.toml", + "host-tool/Cargo.toml" ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1516a5b..e8cda29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - *Breaking:* Added `Value` impls for `bool`, `Option`, and `[T: Value; N]`. *This can break existing code because it changes type inference, be mindfull of that!* - Expose map item iterator, to load all items in one pass +- Add host tool, allow experiment, inspect dump file in the host environment. ## 3.0.1 25-07-24 diff --git a/host-tool/Cargo.lock b/host-tool/Cargo.lock new file mode 100644 index 0000000..54b3dad --- /dev/null +++ b/host-tool/Cargo.lock @@ -0,0 +1,501 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "embedded-storage" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032" + +[[package]] +name = "embedded-storage-async" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1763775e2323b7d5f0aa6090657f5e21cfa02ede71f5dc40eead06d64dcd15cc" +dependencies = [ + "embedded-storage", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sequential-storage" +version = "3.0.1" +dependencies = [ + "approx", + "arrayvec", + "embedded-storage-async", + "futures", +] + +[[package]] +name = "sequential-storage-tool" +version = "0.1.0" +dependencies = [ + "embedded-storage-async", + "sequential-storage", + "tokio", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/host-tool/Cargo.toml b/host-tool/Cargo.toml new file mode 100644 index 0000000..2c6a24c --- /dev/null +++ b/host-tool/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "sequential-storage-tool" +version = "0.1.0" +edition = "2021" + +[dependencies] +embedded-storage-async = "0.4.1" +sequential-storage = { version = "3.0.1", path = "..", features = ["_test"] } +tokio = { version = "1.40.0", features = ["full"]} diff --git a/host-tool/rmk.raw b/host-tool/rmk.raw new file mode 100755 index 0000000000000000000000000000000000000000..ebb218382eb337cce9d1ad5a40f6e562a579b6ec GIT binary patch literal 65536 zcmeI&XH-?!x(492H@yf7DvB5tl_COyqSy?JmAv0**){nnS`{c-=D`{Vxj93vy~8FQ_@_Pgeq@7#Mw(=^SuS%9~t*5<4F zPx=$`aZ-}CmRVq`{)T_>XU+aSFJM|xO*7MeB0Kf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mqf45|9KW0ZBj-kOU+FNk9^i1SA1TKoXDyBmqf45|9KW0ZBj-kOU+FNk9^i z1SA1TKoXDyBmqf45|9KW0ZBj-kOU+FNk9^i1SA1TKoXDyBmqf45|9KW0ZBj-kOU+F zNk9^i1SA1TKoXDyBmqf45|9KW0ZBj-kOU+FNk9^i1SA1TKoXDyBmqf45|9KW0ZBj- zkOU+FNk9^i1SA1TKoXDyBmqf45|9KW0ZBj-kOU+FNk9^i1SA1TKoXDyBmqf45|9KW z0ZBj-kOU+FNk9^i1SA1TKoXDyBmqf45|9KW0ZBj-kOU+FNk9^i1SA1TKoXDyBmqf4 Y5|9KW0ZBj-kOU+FNk9_#|C_+S0R~OJKL7v# literal 0 HcmV?d00001 diff --git a/host-tool/src/main.rs b/host-tool/src/main.rs new file mode 100644 index 0000000..93c6ae8 --- /dev/null +++ b/host-tool/src/main.rs @@ -0,0 +1,96 @@ +use std::{ + fs::File, + io::{Read, Seek, SeekFrom}, + ops::Range, +}; + +use embedded_storage_async::nor_flash::{ + ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, +}; +use sequential_storage::{cache::NoCache, Storage}; + +pub struct Partition(File); + +impl Partition { + pub const WORD_SIZE: usize = 4; + pub const SECTOR_SIZE: usize = 4096; + + pub fn new(path: &str) -> Self { + Self(File::open(path).unwrap()) + } +} + +#[derive(Debug)] +pub struct Error(std::io::Error); +impl From for Error { + fn from(value: std::io::Error) -> Self { + Self(value) + } +} + +impl NorFlashError for Error { + fn kind(&self) -> NorFlashErrorKind { + // match self.0.code() { + // => NorFlashErrorKind::NotAligned, + // ESP_ERR_INVALID_SIZE => NorFlashErrorKind::OutOfBounds, + // _ => + NorFlashErrorKind::Other + // } + } +} + +impl ErrorType for Partition { + type Error = Error; +} + +impl ReadNorFlash for Partition { + const READ_SIZE: usize = Self::WORD_SIZE as _; + + async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { + self.0.seek(SeekFrom::Start(offset as u64))?; + self.0.read_exact(bytes).map_err(Error::from) + } + + fn capacity(&self) -> usize { + self.0.metadata().unwrap().len() as usize + } +} + +impl NorFlash for Partition { + const WRITE_SIZE: usize = Self::WORD_SIZE as _; + const ERASE_SIZE: usize = Self::SECTOR_SIZE as _; + + async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { + println!( + "esp partition write at {:#x} size {:#x}", + offset, + bytes.len() + ); + Ok(()) + } + + async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { + println!("esp partition erase from {:#x} size {:#x}", from, to - from); + Ok(()) + } +} + +impl MultiwriteNorFlash for Partition {} + +#[tokio::main] +async fn main() -> Result<(), sequential_storage::Error> { + let mut flash = Partition::new("rmk.raw"); + let flash_range: Range = 0..flash.capacity() as u32; + let mut cache = NoCache::new(); + let mut storage = Storage::new(&mut flash, flash_range, &mut cache); + + let mut pageit = storage.iter().await?; + while let Some(mut itemit) = pageit.next(&mut storage).await? { + println!("Page {:?}", 1); + let mut buffer = [0u8; 1024]; + while let Ok(Some((item, _))) = itemit.next(&mut storage.flash, &mut buffer).await { + println!("\tItem {:02x?}", item.data()); + } + } + Ok(()) +}