This repository demonstrates a modern Bazel-based build system for Rust firmware development with SystemC simulation and QEMU emulation support.
- Bazel Build System: Modern, scalable build configuration
- Multi-target Support: ARM Cortex-M4 and RISC-V32 targets
- Rich Rust Ecosystem: Demonstrates use of embedded Rust crates
- SystemC Integration: Hardware modeling with SystemC/TLM
- QEMU Simulation: Full system emulation support
- Co-simulation: SystemC and QEMU integration
rust-firmware-bazel/
├── firmware/ # Rust firmware source
│ ├── src/
│ │ ├── main.rs # Main firmware logic
│ │ ├── peripheral.rs # Hardware abstraction
│ │ └── protocol.rs # Communication protocol
│ ├── Cargo.toml # Rust dependencies
│ └── BUILD.bazel # Bazel build rules
├── systemc/ # SystemC models
│ ├── peripheral_model.h/cpp
│ ├── testbench.cpp
│ └── BUILD.bazel
├── qemu/ # QEMU configuration
│ ├── machine_config.c
│ ├── run_qemu.sh
│ └── BUILD.bazel
├── platforms/ # Target platform definitions
├── rust/ # Rust toolchain config
├── tools/ # Build and simulation scripts
├── WORKSPACE.bazel # Bazel workspace
└── .bazelrc # Bazel configuration
## Dependencies
- Bazel 6.0+
- Rust 1.75+
- SystemC 2.3.3+
- QEMU 7.0+
- ARM GCC toolchain (for debugging)
- RISC-V GCC toolchain (optional)
## Building
```bash
# Build all targets
./tools/build.sh
# Build specific target
bazel build //firmware:firmware --config=thumb
bazel build //firmware:firmware_riscv --config=riscv
bazel build //systemc:testbench
# QEMU simulation (ARM)
./tools/simulate.sh qemu arm
# QEMU simulation (RISC-V)
./tools/simulate.sh qemu riscv
# SystemC simulation
./tools/simulate.sh systemc
# Co-simulation
./tools/simulate.sh co-sim# Debug ARM target
./tools/debug.sh arm
# Debug RISC-V target
./tools/debug.sh riscvcortex-m&cortex-m-rt: ARM Cortex-M supportriscv&riscv-rt: RISC-V supportheapless: Static memory data structuresnb: Non-blocking I/O traitsembedded-hal: Hardware abstraction traitsdefmt: Efficient logging frameworkfugit: Time handlingstm32f4xx-hal: STM32F4 HAL (optional)
- Multi-platform builds with
--platforms - Crate universe for Rust dependencies
- Custom toolchain configuration
- Build configurations and feature flags
- Cross-compilation support
- TLM 2.0 socket communication
- Interrupt modeling
- Register-based peripheral model
- Transaction-level modeling
- Add new peripherals: Create models in
systemc/and corresponding drivers infirmware/src/peripheral.rs - Add new targets: Define platforms in
platforms/and updateWORKSPACE.bazel - Add dependencies: Update
firmware/Cargo.tomland regenerate lock file - Custom QEMU machines: Extend
qemu/machine_config.c