Crates.io | rblhost |
lib.rs | rblhost |
version | 0.1.0 |
created_at | 2025-08-22 08:23:16.161143+00 |
updated_at | 2025-08-22 08:23:16.161143+00 |
description | The rblhost application is a fast command-line utility providing McuBoot library used on the host computer to initiate communication and issue commands to the MCU bootloader. |
homepage | https://github.com/nxp-mcuxpresso/rblhost |
repository | https://github.com/nxp-mcuxpresso/rblhost |
max_upload_size | |
id | 1806067 |
size | 425,167 |
This is a concept implementation of the blhost tool in Rust programming language. It includes McuBoot
implementation, similar to the one in spsdk
, together with spsdk
-like Python bindings using pyo3
crate.
The Rust implementation offers performance improvements compared to both the Python SPSDK implementation and the original C/C++ blhost tool.
Benchmark performed on MacBook Air M2 comparing rblhost with SPSDK blhost and C/C++ blhost 2.6.7. Benchmark measures get-property 1 command execution time with MCXN236 board and 57600 baud rate. Resulting time is in miliseconds.
Key performance highlights:
Faster startup time compared to both Python and C++ implementations
Improved command execution speed
Native performance with the convenience of Python bindings
Clone the repository and cd into it:
git clone https://github.com/nxp-mcuxpresso/rblhost
cd rblhost
Refer to sections below to build bindings or the CLI tool.
Build the CLI tool:
cargo build --release
The binary will be available at target/release/rblhost
. For example usage of the library, look in examples folder.
cargo build --release --features python
pymboot
into the virtual environment
pip install .
pip install -e .
For examples on how to use Python bindings, look into examples folder.
Note: Compiling together python
and c_api
features/bindings may result in malfunctioning libraries.
Prerequisites:
cargo build --release --features c_api
target/release/libmboot.so
target/release/libmboot.dylib
target/release/mboot.dll
include/mboot.h
For more information about the bindings, refer to C Bindings section. For examples on how to use C bindings and an example CMakeLists.txt
file, look into examples folder.
sudo modprobe i2c-dev
For UART: No additional requirements
I2C communication is not supported on macOS
rblhost [OPTIONS] -- COMMAND [ARGS]...
rblhost -p <port>[,<baudrate>] [OPTIONS] -- COMMAND [ARGS]...
<port>
: Serial port name (e.g., COM3, /dev/ttyUSB0)<baudrate>
: Optional baudrate (default: 57600)Example:
rblhost -p COM3,115200 -- reset
Basic information:
/dev/i2c-X
)rblhost --i2c <device>:<slave_address> [OPTIONS] -- COMMAND [ARGS]...
<device>
: I2C device path in /dev/i2c-X
format, where X
is the I2C bus number<slave_address>
: Optional slave address in hex format (e.g., 0x3A
), default is 0x10
Example:
rblhost --i2c /dev/i2c-1:0x3A -- reset
-t, --timeout <MILLISECONDS>
: Serial read timeout in milliseconds (default: 5000)-s, --silent
: Suppress status response and response words-v, --verbose
: Increase verbosity level (can be used multiple times)Example with timeout:
rblhost -p COM3 -t 10000 -- flash-erase-all
get-property
: Queries various bootloader properties and settingsreset
: Reset the deviceexecute
: Jumps to code at the provided addresscall
: Invokes code at an address, passing an argument to itflash-erase-all
: Perform an erase of the entire flash memoryfill-memory
: Fills the memory with a patternread-memory
: Reads the memory and writes it to a file or stdoutset-property
: Changes properties and options in the bootloaderconfigure-memory
: Sets a config at internal memory to memory with IDflash-erase-all-unsecure
: Erase Complete Flash and Unlockflash-erase-region
: Erases one or more sectors of the flash memorywrite-memory
: Write memory from a file or CLIfuse-program
: Program fusefuse-read
: Reads the fuse and writes it to the file or stdoutreceive-sb-file
: Receives a file in a Secure Binary (SB) formatflash-read-once
: Read from MCU flash program once region (eFuse/OTP)flash-program-once
: Write into MCU program once region (eFuse/OTP)trust-provisioning
: Group of subcommands related to trust provisioningkey-provisioning
: Group of subcommands related to key provisioningload-image
: Sends a boot image file to the deviceThe MCU Boot library provides a C API that allows C/C++ applications to communicate with MCU bootloaders. The API provides functions for:
Include the header file in your C code:
#include "mboot.h"
Compile your C program with the library:
# Linux/macOS
gcc -o my_program my_program.c -L./target/release -lmboot -Wl,-rpath,./target/release
# Windows
gcc -o my_program.exe my_program.c -L./target/release -lmboot
You can also use cmake example in examples.
Look into the generated header to see all currently available functions.
The API functions return integer status codes:
0
: Success-1
: Invalid parameters (null pointers)-2
: Invalid property tag-3
: Communication errorAll of these errors are specified as macros in the generated header. It's also possible to use mbot_get_status_text
function to get a text description of the error during runtime.
All functions containing Allocations section in their documentation allocate data on heap, which must be later freed.
The MCU Boot C API is not thread-safe. Do not use the same MBOOT_CMcuBoot
instance from multiple threads simultaneously.
If you get a "library not found" error when running your program:
Linux: Set the LD_LIBRARY_PATH
environment variable:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./target/release
macOS: Set the DYLD_LIBRARY_PATH
environment variable:
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:./target/release
Windows: Add the library directory to your PATH or copy the DLL to the same directory as your executable.
If you get undefined symbol errors when linking:
Make sure you're using the correct library name (-lmboot
)
Check that the library path is correct (-L./target/release
)
Verify that the library was built successfully
"Undefined reference to Py*" -- Build the library with only the c_api
feature, like shown here:
cargo build -rF c_api
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
blhost
and McuBoot
commandsThis table compares the commands available in rblhost (Rust implementation) with the original blhost (C implementation), and indicates which commands are supported in the Python bindings.
Command | rblhost | blhost | Python Bindings | C Bindings |
---|---|---|---|---|
reset | ✅ | ✅ | ✅ | ❌ |
get-property | ✅ | ✅ | ✅ | ✅ |
set-property | ✅ | ✅ | ✅ | ❌ |
flash-erase-region | ✅ | ✅ | ✅ | ❌ |
flash-erase-all | ✅ | ✅ | ✅ | ✅ |
flash-erase-all-unsecure | ✅ | ✅ | ✅ | ❌ |
read-memory | ✅ | ✅ | ✅ | ✅ |
write-memory | ✅ | ✅ | ✅ | ✅ |
fill-memory | ✅ | ✅ | ✅ | ❌ |
receive-sb-file | ✅ | ✅ | ✅ | ✅ |
execute | ✅ | ✅ | ✅ | ❌ |
call | ✅ | ✅ | ✅ | ❌ |
flash-security-disable | ❌ | ✅ | ❌ | ❌ |
flash-program-once | ✅ | ✅ | ✅ | ✅ |
flash-read-once | ✅ | ✅ | ✅ | ✅ |
efuse-program-once | ❌ | ✅ | ❌ | ❌ |
efuse-read-once | ❌ | ✅ | ❌ | ❌ |
flash-read-resource | ❌ | ✅ | ❌ | ❌ |
configure-memory | ✅ | ✅ | ✅ | ❌ |
flash-image | ❌ | ✅ | ❌ | ❌ |
reliable-update | ❌ | ✅ | ❌ | ❌ |
generate-key-blob | ❌ | ✅ | ❌ | ❌ |
key-provisioning | ✅ | ✅ | ✅ | ❌ |
load-image | ✅ | ✅ | ✅ | ❌ |
program-aeskey | ❌ | ✅ | ❌ | ❌ |
fuse-program | ✅ | ❌ | ✅ | ❌ |
fuse-read | ✅ | ❌ | ✅ | ❌ |
trust-provisioning | ✅ | ❌ | ✅ | ❌ |