sftool¶
A command-line utility for SiFli SoC serial tool。
简介¶
Sftool is an open-source tool specifically designed for the SiFli series of SoCs (System on Chip), used to interact with the chip via a serial interface。It supports various operations, including writing data to flash memory, resetting the chip, and other functions。
特性¶
Supports SF32 series chips
Supports multiple storage types: NOR flash, NAND flash, and SD cards
Configurable serial port parameters
Reliable flash writing function, supporting verification and compression
Flexible reset options
Customizable connection attempts
安装¶
下载预构建¶
The latest pre-built sftool can be downloaded from GitHub release,Our naming standard is sftool-v{version}-{target}.zip/tar.xz, please select the compressed package suitable for your system architecture to download
URL: https://github.com/OpenSiFli/sftool/releases
Install using Cargo¶
cargo install --git https://github.com/OpenSiFli/sftool
Compile from source code¶
# Clone the repository
git clone https://github.com/OpenSiFli/sftool.git
cd sftool
# Compile using Cargo
cargo build --release
# The compiled binary file is located at
# ./target/release/sftool
使用方法¶
Basic command format¶
sftool [选项] 命令 [命令选项]
全局选项¶
-c, --chip <CHIP>
: Target chip type (currently supports SF32LB52)-m, --memory <MEMORY>
: Storage type [nor, nand, sd] (default: nor)-p, --port <PORT>
: Serial port device path-b, --baud <BAUD>
: Serial port baud rate used for flash/read (default: 1000000)--before <OPERATION>
: Operations before connecting the chip [no_reset, soft_reset] (default: no_reset)--after <OPERATION>
: Operations after the tool completes [no_reset, soft_reset] (default: soft_reset)--connect-attempts <ATTEMPTS>
: Number of connection attempts, negative or 0 means infinite times (default: 7)--compat
: Compatibility mode, this option should be enabled if timeout errors or verification failures frequently occur after downloading。
Write flash command¶
# Linux/Mac
sftool -c SF32LB52 -p /dev/ttyUSB0 write_flash [选项] <文件@地址>...
# Windows
sftool -c SF32LB52 -p COM9 write_flash [选项] <文件@地址>...
写入闪存选项¶
--verify
: Verify the just-written flash data-u, --no-compress
: Disable data compression during transmission-e, --erase-all
: Erase all flash areas before programming (not just the written area)<文件@地址>
: Binary file and its target address, if the file format contains address information, the @address part is optional
示例¶
Linux/Mac:
# Write a single file to flash
sftool -c SF32LB52 -p /dev/ttyUSB0 write_flash app.bin@0x12020000
# Write multiple files to different addresses
sftool -c SF32LB52 -p /dev/ttyUSB0 write_flash bootloader.bin@0x12010000 app.bin@0x12020000 ftab.bin@0x12000000
# Write and verify
sftool -c SF32LB52 -p /dev/ttyUSB0 write_flash --verify app.bin@0x12020000
# Erase all flash before writing
sftool -c SF32LB52 -p /dev/ttyUSB0 write_flash -e app.bin@0x12020000
Windows:
# Write multiple files to different addresses
sftool -c SF32LB52 -p /dev/ttyUSB0 write_flash bootloader.bin@0x1000 app.bin@0x12010000 ftab.bin@0x12000000
# 其它同上
库使用¶
Sftool also provides a reusable Rust library sftool-lib
, which can be integrated into other Rust projects:
use sftool_lib::{SifliTool, SifliToolBase, WriteFlashParams};
fn main() {
let mut tool = SifliTool::new(
SifliToolBase {
port_name: "/dev/ttyUSB0".to_string(),
chip: "sf32lb52".to_string(),
memory_type: "nor".to_string(),
quiet: false,
},
Some(WriteFlashParams {
file_path: vec!["app.bin@0x10000".to_string()],
verify: true,
no_compress: false,
erase_all: false,
}),
);
if let Err(e) = tool.write_flash() {
eprintln!("Error: {:?}", e);
}
}
贡献¶
Welcome to submit issues and Pull Requests!