Rewrite & Redesign uefi firmware in Rust - shijunjing/edk2 GitHub Wiki
Why?
- Modern firmware need modern programming language.
- Modern firmware != simply adopt Linuxboot/Coreboot/Uboot etc. Linux-based solutions also have inherent drawbacks
First Goal
- Enable the Rust build tool-chain and necessary libraries (memory safe + unsafe) in edk2 for single Rust module interoperability.
Long time Goal
- Complete Uefi Rust core/library for uncompromising memory safety
- Introduce fearless concurrency in Uefi Rust firmware
- Binary package management, distribution and Rust firmware update
Rust background and useful links:
- Oreboot Is Taking Shape As Rust'ed, Purely Open-Source Focused Coreboot: https://www.phoronix.com/scan.php?page=news_item&px=Oreboot-Rust-Fully-Open
- Intel and Rust: the Future of Systems Programming: Josh Triplett: https://www.youtube.com/watch?v=l9hM0h6IQDo
- “Rust is the future of systems programming, C is the new Assembly”: Intel principal engineer, Josh Triplett: https://hub.packtpub.com/rust-is-the-future-of-systems-programming-c-is-the-new-assembly-intel-principal-engineer-josh-triplett/
- According to posts on LWN.net, they are willing to investigate a framework for the Linux kernel to load drivers that are written in Rust.: https://lwn.net/Articles/797828/
- Mozilla Rust Considered for Linux Drivers: https://pcper.com/2019/09/mozilla-rust-considered-for-linux-drivers/
- Coreboot developers exploring Rust rewrite (oreboot -“fork of coreboot, with C removed”):https://github.com/oreboot/oreboot
- Facebook Libra (block chain project) is written in Rust: https://github.com/libra/libra
- https://www.rust-lang.org/
- https://www.rust-lang.org/what/embedded
- Stanford Seminar The Rust Programming Language: https://www.youtube.com/watch?v=SZvs15hC81U
- Rust channel: https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA
- [Chinese] RustCon Asia 2019 - Jing Yiming: Cargo meets Autotools: https://www.youtube.com/watch?v=C3GESQ_uxog
- [Chinese] RustCon Asia 2019 - Sun Mingshen: Linux From Scratch in Rust: https://www.youtube.com/watch?v=jVxBKW4frKE
- HotOS'17 - System Programming in Rust: Beyond Safety: http://soarlab.org/2017/06/hotos2017-bbbprr/
- HotOS'19 - RedLeaf : Towards An Operating System for Safe and Verified Firmware: https://dl.acm.org/citation.cfm?id=3321449
- POPL'18 RustBelt: securing the foundations of the rust programming language - https://dl.acm.org/citation.cfm?doid=3177123.3158154
Working notes
20190601
jshi19@ub2-uefi-b01:~$ curl https://sh.rustup.rs -sSf | sh
Need exit and login again to update PATH env
jshi19@ub2-uefi-b01:~$ cargo install cargo-binutils
Try to build a Rust embedded project: https://github.com/ah-/anne-key, but fail as below:
jshi19@ub2-uefi-b01:~/wksp_efi/Rust$ git clone https://github.com/ah-/anne-key.git
jshi19@ub2-uefi-b01:~/wksp_efi/Rust/anne-key$ make dfu
rustup component add llvm-tools-preview
info: component 'llvm-tools-preview' for target 'x86_64-unknown-linux-gnu' is up to date
rustup target add thumbv7m-none-eabi
info: component 'rust-std' for target 'thumbv7m-none-eabi' is up to date
cargo build --release
Updating git repository `https://github.com/hdhoang/cortex-m`
warning: spurious network error (2 tries remaining): failed to receive HTTP 200 response: got 401; class=Net (12)
warning: spurious network error (1 tries remaining): failed to receive HTTP 200 response: got 401; class=Net (12)
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to load source for a dependency on `cortex-m`
Caused by:
Unable to update https://github.com/hdhoang/cortex-m?branch=static-system_reset2#3605ad2e
Caused by:
failed to fetch into /home/jshi19/.cargo/git/db/cortex-m-9b34e66755859cca
Caused by:
failed to receive HTTP 200 response: got 401; class=Net (12)
Makefile:7: recipe for target 'build' failed
make: *** [build] Error 101
Try to add the Rust proxy as below, but build still fail with same error. Need further investigation.
jshi19@ub2-uefi-b01:~/wksp_efi/Rust/anne-key$ vim ~/.cargo/config
jshi19@ub2-uefi-b01:~/wksp_efi/Rust/anne-key$ cat ~/.cargo/config
[https]
proxy = "jshi19:Q5432*[email protected]:913"
[http]
proxy = "jshi19:Q5432*[email protected]:913"
20190603
Successfully build the doc and code samples of the book Tao of Rust
C:\Users\jshi19\RustWorkspace>set http_proxy=...
C:\Users\jshi19\RustWorkspace>set https_proxy=...
C:\Users\jshi19\RustWorkspace>git clone https://github.com/ZhangHanDong/tao-of-rust-codes.git
C:\Users\jshi19\RustWorkspace>cd tao-of-rust-codes
Add [http] and check-revoke = false as below in Cargo.toml
C:\Users\jshi19\RustWorkspace\tao-of-rust-codes>git diff
diff --git a/Cargo.toml b/Cargo.toml
@@ -14,3 +14,6 @@ readme = "README.md"
[dependencies]
failures_crate = { version = "0.1", path = "./src/ch09/failures_crate" }
csv_challenge = { version = "0.1", path = "./src/ch10/csv_challenge" }
+
+[http]
+check-revoke = false # Indicates whether SSL certs are checked for revocation
\ No newline at end of file
C:\Users\jshi19\RustWorkspace\tao-of-rust-codes>cargo doc
Finished dev [unoptimized + debuginfo] target(s) in 7m 15s
Change the default rustc to nightly then build all samples
C:\Users\jshi19\RustWorkspace\tao-of-rust-codes>rustup default nightly
nightly-x86_64-pc-windows-msvc installed - rustc 1.37.0-nightly (627486af1 2019-06-02)
C:\Users\jshi19\RustWorkspace\tao-of-rust-codes>cargo build
Finished dev [unoptimized + debuginfo] target(s) in 1m 17s