Expand description
§littlefs2-pack
A Rust crate for building a file system into a LittleFS binary file to be flashed to an embedded device.
This crate wraps the LittleFS C library
using the littlefs2-sys crate. The littlefs2 crate
might have been an easier starting point but it doesn’t
currently allow setting the image configuration dynamically
at runtime, such as the block size and count.
littlefs2-pack is tested for compatibility with the C++
mklittlefs project. This is ensured with the cross-compat.rs
test that packs with one tool then unpack with the other,
in both directions. These tests are ran against the version of
mklittlefs in the submodule and requires that tool to be built
prior to running the tests.
§Example
use littlefs2_pack::littlefs::LfsImage;
use littlefs2_pack::config::ImageConfig;
let config = ImageConfig {
name: String::from("filesystem"),
block_size: 4096,
block_count: 128,
read_size: 256,
write_size: 256,
block_cycles: -1,
cache_size: 256,
lookahead_size: 8,
};
let mut image = LfsImage::new(config).unwrap();
image.format().unwrap();
image.mount_and_then(|fs| {
fs.create_dir("/data")?;
fs.write_file("/data/hello.txt", b"Hello from LittleFS!")?;
Ok(())
}).unwrap();
let binary = image.into_data();
std::fs::write("filesystem.bin", &binary).unwrap();Modules§
- config
- littlefs2-config
- littlefs
- partition_
table - Partition Table
- walk
Functions§
- generate_
esp_ partitions_ config - Generate a Rust module with partition offset and size constants from an ESP-IDF partition table CSV.
- pack_
and_ generate_ config - Generate a LittleFS image and Rust configuration module from a
littlefs.tomlfile.