Crate spl_tool

Source
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§

HeaderConf
Represents configuration arguments for SPL header generation.
UbootSplHeader
Represents the U-Boot header for the SPL binary.

Enums§

Error

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 to SPL_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.

Type Aliases§

Result
Convenience alias for a Result type for the library.