spl_tool/
lib.rs

1// SPDX-License-Identifier: GPL-2.0+
2
3//! SPL header tool for the StarFive VisionFive2 board.
4//!
5//! Based on the C implementation: <https://github.com/starfive-tech/Tools/tree/master/spl_tool>
6//!
7//! ```rust
8//! use spl_tool::{crc32, crc32_final, Result, HeaderConf, UbootSplHeader};
9//! use spl_tool::{DEF_CRC32_IV, DEF_CRC32_SV, SPL_HEADER_LEN};
10//!
11//! // Dummy example of the U-Boot SPL image size
12//! // Real value should be read from SPL image file
13//! const UBOOT_IMG_SIZE: usize = 0xf00d;
14//!
15//! // Dummy data for the SPL image data
16//! let spl = [0xff; UBOOT_IMG_SIZE];
17//!
18//! // Calculate the main CRC-32 rounds
19//! let v = crc32(DEF_CRC32_IV, DEF_CRC32_SV, spl.as_ref());
20//! // Calculate the final CRC-32 round
21//! let crc = crc32_final(v);
22//!
23//! let conf = HeaderConf::new().with_name("u-boot-spl.bin");
24//!
25//! let hdr = UbootSplHeader::new()
26//!     .with_bofs(conf.bofs())
27//!     .with_vers(conf.vers())
28//!     .with_fsiz(UBOOT_IMG_SIZE as u32)
29//!     // Set calculated CRC-32 in the header
30//!     .with_crcs(crc);
31//!
32//! // Convert header to bytes
33//! let _hdr_bytes: [u8; SPL_HEADER_LEN] = hdr.into();
34//!
35//! // ... do cool stuff with your SPL header
36//! // ... usually, prepend it to the SPL image data in a new SPL image file
37//! ```
38
39#![no_std]
40
41mod crc32;
42mod error;
43mod spl_header;
44
45pub use crc32::*;
46pub use error::*;
47pub use spl_header::*;