#firmware #motorola #srecord

srec

Parsing and generating Motorola S-record (SRECORD/SREC) files

4 releases

0.2.0 Jun 26, 2020
0.1.2 Feb 8, 2020
0.1.1 Dec 3, 2019
0.1.0 Dec 3, 2019

#1281 in Parser implementations

Download history 245/week @ 2024-06-18 271/week @ 2024-06-25 245/week @ 2024-07-02 258/week @ 2024-07-09 264/week @ 2024-07-16 372/week @ 2024-07-23 243/week @ 2024-07-30 370/week @ 2024-08-06 291/week @ 2024-08-13 252/week @ 2024-08-20 249/week @ 2024-08-27 318/week @ 2024-09-03 323/week @ 2024-09-10 275/week @ 2024-09-17 317/week @ 2024-09-24 299/week @ 2024-10-01

1,263 downloads per month
Used in rxprog

MIT license

35KB
844 lines

srec

crates.io badge

A Rust crate for parsing/reading and generating/writing Motorola S-record (also known as SRECORD or SREC) files.

View documentation on docs.rs

Examples

Reading

See examples/read_srec_file.rs

let s = fs::read_to_string(path)?;

let records = srec::read_records(&s);

for record in records {
    match record {
        Ok(record) => match record {
            srec::Record::S0(s) => println!("S0 header: \"{}\"", s),
            srec::Record::S1(data) => println!(
                "S1 data w/ 16-bit address: addr = {:#06X}, data = {:02X?}",
                u32::from(data.address),
                data.data
            ),
            srec::Record::S2(data) => println!(
                "S2 data w/ 24-bit address: addr = {:#08X}, data = {:02X?}",
                u32::from(data.address),
                data.data
            ),
            srec::Record::S3(data) => println!(
                "S3 data w/ 32-bit address: addr = {:#010X}, data = {:02X?}",
                u32::from(data.address),
                data.data
            ),
            srec::Record::S5(count) => {
                println!("S5 16-bit record count: count = {:#06X}", u32::from(count))
            }
            srec::Record::S6(count) => {
                println!("S6 24-bit record count: count = {:#08X}", u32::from(count))
            }
            srec::Record::S7(addr) => {
                println!("S7 32-bit start address: addr = {:#010X}", u32::from(addr))
            }
            srec::Record::S8(addr) => {
                println!("S8 24-bit start address: addr = {:#08X}", u32::from(addr))
            }
            srec::Record::S9(addr) => {
                println!("S9 16-bit start address: addr = {:#06X}", u32::from(addr))
            }
        },
        Err(err) => println!("error reading record: {}", err),
    }
}

Writing

See examples/write_srec_file.rs

let records = [
    srec::Record::S0("HDR".into()),
    srec::Record::S1(srec::Data {
        address: srec::Address16(0x1234),
        data: vec![0x00, 0x01, 0x02, 0x03],
    }),
    srec::Record::S1(srec::Data {
        address: srec::Address16(0x1238),
        data: vec![0x04, 0x05, 0x06, 0x07],
    }),
    srec::Record::S9(srec::Address16(0x1234)),
];

let s = srec::writer::generate_srec_file(&records);

let mut file = fs::File::create(path)?;
file.write_all(&s.into_bytes())?;

No runtime deps