RustSBI Prototyper is a developing RISC-V Secure Bootloader solution. It can be integrated with the Rust or C language ecosystem to form a complete RISC-V bootloader ecosystem.
Before compiling, ensure the following packages are installed:
cargo install cargo-binutils
sudo apt install u-boot-toolsThese are necessary for building the firmware and handling RISC-V binary outputs.
The following command compiles the RustSBI Prototyper bootloader with optional settings:
cargo prototyper [OPTIONS]This builds the firmware based on the provided options (or defaults if none are specified). The resulting files—such as .elf executables and .bin binaries—are generated in the target/riscv64imac-unknown-none-elf/release/ directory under your project root. See the "Firmware Compilation" section for specific outputs and modes.
These are necessary for building the firmware and handling RISC-V binary outputs.
-f, --features <FEATURES>
Enable specific features during the build (supports multiple values, e.g.,--features "hypervisor,feat2").--fdt <PATH>
Specify the path to a Flattened Device Tree (FDT) file.
[Environment Variable:PROTOTYPER_FDT_PATH]--payload <PATH>
Specify the path to the payload ELF file.
[Environment Variable:PROTOTYPER_PAYLOAD_PATH]--jump
Enable jump mode.-c, --config-file <PATH>
Specify the path to a custom configuration file.-v, --verbose
Increase logging verbosity (more detailed output).-q, --quiet
Decrease logging verbosity (less output).-h, --help
Display help information.
Regardless of the mode (Dynamic Firmware, Payload Firmware, or Jump Firmware), specifying an FDT file with
--fdtensures it is used to initialize the hardware platform configuration. The FDT file provides essential hardware setup details and overrides the bootloader's default settings.
Compilation Command:
Use this command to compile firmware that dynamically loads payloads:
cargo prototyperOutput:
Once compiled, the firmware files will be located in the target/riscv64imac-unknown-none-elf/release/ directory under your project root:
rustsbi-prototyper-dynamic.elf(ELF executable)rustsbi-prototyper-dynamic.bin(Binary file)
Compilation Command:
Build firmware with an embedded payload:
cargo prototyper --payload <PAYLOAD_PATH>Output:
After compilation, the resulting firmware files are generated in the target/riscv64imac-unknown-none-elf/release/ directory:
rustsbi-prototyper-payload.elfrustsbi-prototyper-payload.bin
Compilation Command:
Build firmware for jump mode:
cargo prototyper --jumpOutput:
After compilation, the resulting firmware files are generated in the target/riscv64imac-unknown-none-elf/release/ directory:
rustsbi-prototyper-jump.elfrustsbi-prototyper-jump.bin
Customize bootloader parameters by editing default.toml located at prototyper/config/default.toml. Example:
num_hart_max = 8
stack_size_per_hart = 16384 # 16 KiB (16 * 1024)
heap_size = 32768 # 32 KiB (32 * 1024)
page_size = 4096 # 4 KiB
log_level = "INFO"
jump_address = 0x80200000
tlb_flush_limit = 16384 # 16 KiB (page_size * 4)num_hart_max: Maximum number of supported harts (hardware threads).stack_size_per_hart: Stack size per hart, in bytes.heap_size: Heap size, in bytes.page_size: Page size, in bytes.log_level: Logging level (TRACE,DEBUG,INFO,WARN,ERROR).jump_address: Target address for jump mode.tlb_flush_limit: TLB flush limit, in bytes.
To use a custom configuration file, specify it with:
cargo prototyper -c /path/to/custom_config.tomlRun the generated firmware in QEMU:
qemu-system-riscv64 \
-machine virt \
-bios target/riscv64imac-unknown-none-elf/release/rustsbi-prototyper-dynamic.elf \
-display none \
-serial stdioFor additional examples, see the docs directory.
See the Required Dependencies under Usage above for the packages needed to compile the RustSBI Prototyper.
These tools are optional but recommended to enhance your development workflow:
A tool to run code checks before committing:
pipx install pre-commit
pre-commit install # Set up pre-commit for the projectA Cargo plugin to audit dependency security:
cargo install --locked cargo-denyA spell-checking tool for code and documentation:
cargo install typos-cliA changelog generation tool:
cargo install git-cliffThis project is dual-licensed under MIT or Mulan-PSL v2. See LICENSE-MIT and LICENSE-MULAN for details.