This repository provides a Rust-based bootloader and an example IoT application for microcontrollers (STM32F4 series as a reference).
The bootloader is designed to enable:
- Secure firmware updates (UART, USB, or OTA-ready)
- Firmware integrity verification using CRC or SHA256
- Fallback mechanism for invalid firmware
- Minimal dependency on external runtime (
#![no_std]
)
This project serves as a starting template for embedded developers looking to build robust IoT bootloaders in Rust.
- Bare-metal Rust bootloader (
#![no_std]
) - Hardware initialization module (
init.rs
) - Flash read/write routines (
flash.rs
) - Firmware verification (
verify.rs
) - Update handling (
updater.rs
) - Example IoT application (
app/
) - Cross-platform scripts for flashing and verification
- Ready-to-use GitHub Actions CI for building bootloader and app
iot-bootloader-rust/
│
├─ Cargo.toml # Workspace manifest
├─ rust-toolchain.toml # Rust version pinning
├─ README.md
├─ .gitignore
├─ .github/workflows/build.yml # CI/CD workflow
│
├─ bootloader/ # Bootloader crate
│ ├─ Cargo.toml
│ └─ src/
│ ├─ main.rs
│ ├─ init.rs
│ ├─ flash.rs
│ ├─ updater.rs
│ └─ verify.rs
│
├─ app/ # IoT Application crate
│ ├─ Cargo.toml
│ └─ src/
│ ├─ main.rs
│ └─ peripherals.rs
│
├─ scripts/ # Flashing and verification scripts
│ ├─ flash.sh
│ └─ check_firmware.sh
│
├─ examples/ # Example applications for testing
│ └─ blinky.rs
│
└─ docs/
└─ memory_map.md # MCU flash layout and memory map
- Rust toolchain (stable recommended)
cargo
andrustup
- Embedded development tools:
probe-rs
CLI for flashing- STM32 USB/UART programmer
- Optional: VSCode + Rust Analyzer for development
cd bootloader
cargo build --release --target thumbv7em-none-eabihf
cd app
cargo build --release --target thumbv7em-none-eabihf
./scripts/flash.sh
./scripts/check_firmware.sh
+----------------+
| MCU Reset |
+----------------+
|
v
+----------------+
| Bootloader |
| init hardware |
+----------------+
|
v
+----------------+
| Verify firmware |
+----------------+
|
v
+-------------------------+
| Check for update |
| (UART/USB/OTA) |
+-------------------------+
|
v
+-------------------------+
| Apply update if present |
+-------------------------+
|
v
+-------------------------+
| Jump to application |
+-------------------------+
|
v
+-------------------------+
| Fallback if failure |
+-------------------------+
Bootloader: 0x08000000 - 0x08003FFF
Application: 0x08004000 - 0x080FFFFF
Backup: 0x08100000 - 0x08103FFF
#![no_std]
#![no_main]
use cortex_m_rt::entry;
mod init;
mod flash;
mod updater;
mod verify;
#[entry]
fn main() -> ! {
init::init_hardware();
if verify::firmware_valid() {
updater::check_for_update();
jump_to_app();
} else {
loop {}
}
}
fn jump_to_app() -> ! {
const APP_START_ADDRESS: u32 = 0x0800_4000;
let app: extern "C" fn() = unsafe { core::mem::transmute(APP_START_ADDRESS) };
app();
}
#![no_std]
#![no_main]
use cortex_m_rt::entry;
mod peripherals;
#[entry]
fn main() -> ! {
peripherals::init_led();
loop {
peripherals::toggle_led();
}
}
pub fn init_led() {}
pub fn toggle_led() {}
- Add OTA over Wi-Fi or BLE
- Secure boot with digital signature verification
- Dual-bank firmware for rollback support
- Support additional MCUs (ESP32, nRF52)
- Add unit tests and CI/CD for embedded targets
This project is dual-licensed:
- Open-Source / Personal Use: Apache 2.0
- Commercial / Closed-Source Use: Proprietary license required
For commercial licensing inquiries or enterprise use, please contact: mahbub.aaman.app@gmail.com
Md Mahbubur Rahman GitHub | Website
We welcome contributions!
- Fork the repo and submit pull requests
- Follow Rust coding guidelines and safety best practices
- Report issues or suggest features via GitHub Issues
- Developing a Cryptographically Secure Bootloader for RISC-V in Rust
- Low-Power Secure Booting for IoT Edge Devices
- Secure Boot and Root-of-Trust in Heterogeneous SoCs
- Design and Implementation of a Secure Bootloader Using Public Key Cryptography
- Rust for Embedded Systems: Current State and Open Problems
- Rust for Security and Correctness in the Embedded World
- Building Safe and Secure Software with Rust on Arm
- Building a Secure Operating System (Redox OS) with Rust
- Rust vs C: Language Choices in Embedded Systems and Cryptography
- Twine: An Embedded Trusted Runtime for WebAssembly
- Ferrocene: Rust Toolchain for Safety-Critical Applications
- Embedded Rust Book
- Rust Embedded Working Group
- Rust Embedded HAL
- probe-rs: Debug Probe Library for Rust