| Crates.io | fitimage |
| lib.rs | fitimage |
| version | 0.1.0 |
| created_at | 2025-11-13 01:55:48.57151+00 |
| updated_at | 2025-11-13 01:55:48.57151+00 |
| description | A Rust library for creating U-Boot compatible FIT images |
| homepage | |
| repository | https://github.com/ZR233/ostool |
| max_upload_size | |
| id | 1930283 |
| size | 109,676 |
一个用于创建U-Boot兼容FIT (Flattened Image Tree) 镜像的Rust库。
[dependencies]
mkimage = "0.1.0"
use mkimage::{FitImageBuilder, FitImageConfig, ComponentConfig};
// 创建FIT镜像配置
let config = FitImageConfig::new("My FIT Image")
.with_kernel(
ComponentConfig::new("kernel", kernel_data)
.with_load_address(0x80080000)
.with_entry_point(0x80080000)
)
.with_fdt(
ComponentConfig::new("fdt", fdt_data)
.with_load_address(0x82000000)
)
.with_kernel_compression(true);
// 构建FIT镜像
let mut builder = FitImageBuilder::new();
let fit_data = builder.build(config)?;
// 保存到文件
std::fs::write("image.fit", fit_data)?;
FIT镜像的主配置结构:
pub struct FitImageConfig {
pub description: String,
pub kernel: Option<ComponentConfig>,
pub fdt: Option<ComponentConfig>,
pub ramdisk: Option<ComponentConfig>,
pub compress_kernel: bool,
}
单个组件的配置:
pub struct ComponentConfig {
pub name: String,
pub data: Vec<u8>,
pub load_address: Option<u64>,
pub entry_point: Option<u64>,
}
主要的构建器接口:
impl FitImageBuilder {
pub fn new() -> Self;
pub fn build(&mut self, config: FitImageConfig) -> Result<Vec<u8>>;
pub fn build_with_compressor(
&mut self,
config: FitImageConfig,
compressor: Box<dyn CompressionInterface>
) -> Result<Vec<u8>>;
}
use mkimage::{FitImageBuilder, FitImageConfig, ComponentConfig};
fn create_complete_fit() -> Result<(), Box<dyn std::error::Error>> {
let config = FitImageConfig::new("Complete FIT Image")
.with_kernel(
ComponentConfig::new("linux", kernel_data)
.with_load_address(0x80080000)
.with_entry_point(0x80080000)
)
.with_fdt(
ComponentConfig::new("devicetree", fdt_data)
.with_load_address(0x82000000)
)
.with_ramdisk(
ComponentConfig::new("initramfs", ramdisk_data)
.with_load_address(0x84000000)
)
.with_kernel_compression(true);
let mut builder = FitImageBuilder::new();
let fit_data = builder.build(config)?;
std::fs::write("complete.fit", fit_data)?;
println!("FIT image created successfully!");
Ok(())
}
库支持gzip压缩内核数据:
let config = FitImageConfig::new("Compressed FIT")
.with_kernel(kernel_component)
.with_kernel_compression(true); // 启用gzip压缩
# 构建库
cargo build --lib
# 运行测试
cargo test --lib
# 运行示例
cargo run --example basic_usage
cargo run --example compression_test
cargo run --example full_fit_test
运行以下命令生成API文档:
cargo doc --open
MIT OR Apache-2.0
欢迎提交Issue和Pull Request!