Expand description
SPL header tool for the StarFive VisionFive2 board.
Based on the C implementation: https://github.com/starfive-tech/Tools/tree/master/spl_tool
use spl_tool::{crc32, crc32_final, Result, HeaderConf, UbootSplHeader};
use spl_tool::{DEF_CRC32_IV, DEF_CRC32_SV, SPL_HEADER_LEN};
// Dummy example of the U-Boot SPL image size
// Real value should be read from SPL image file
const UBOOT_IMG_SIZE: usize = 0xf00d;
// Dummy data for the SPL image data
let spl = [0xff; UBOOT_IMG_SIZE];
// Calculate the main CRC-32 rounds
let v = crc32(DEF_CRC32_IV, DEF_CRC32_SV, spl.as_ref());
// Calculate the final CRC-32 round
let crc = crc32_final(v);
let conf = HeaderConf::new().with_name("u-boot-spl.bin");
let hdr = UbootSplHeader::new()
.with_bofs(conf.bofs())
.with_vers(conf.vers())
.with_fsiz(UBOOT_IMG_SIZE as u32)
// Set calculated CRC-32 in the header
.with_crcs(crc);
// Convert header to bytes
let _hdr_bytes: [u8; SPL_HEADER_LEN] = hdr.into();
// ... do cool stuff with your SPL header
// ... usually, prepend it to the SPL image data in a new SPL image file
Structs§
- Header
Conf - Represents configuration arguments for SPL header generation.
- Uboot
SplHeader - Represents the U-Boot header for the SPL binary.
Enums§
Constants§
- CRC_
FAILED - Value indicating a failed CRC32 calculation/check.
- DEF_
BACKUP - Default value of
SBL_BAK_OFFSET
. - DEF_
CRC32_ IV - Default CRC-32 initialization vector used by StarFive.
- DEF_
CRC32_ SV - Default CRC-32 state vector used by StarFive.
- DEF_
RESL - Default value for the offset from
HDR
toSPL_IMAGE
. - DEF_
SOFS - Default value of the offset of SPL header:
64+256+256 = 0x240
- DEF_
SPL_ FILE - Default filename of the U-Boot SPL binary.
- DEF_
VERS - Default SPL version ID.
- MAX_
SPL_ LEN - Maximum supported length of an U-Boot SPL image.
- PATH_
MAX - Maximum path length: defined in
linux/limits.h
. - SPL_
HEADER_ LEN - Default size for an U-Boot SPL header.
Functions§
- crc32
- Calculate the CRC-32 value over the provided data buffer.
- crc32_
final - Performs the final round of the CRC-32 calculation.
- crc32_
reverse - Reverses the bits in the CRC-32 calculation.