From b5ac2e730337f62607249c4075d6ce6763bdf4cb Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 6 Jun 2019 00:12:17 +0800 Subject: [PATCH] add simple Rust firmware (WIP) --- firmware/.cargo/config | 2 + firmware/Cargo.lock | 154 +++++++++++++++++++++++++++++++++++++++++ firmware/Cargo.toml | 14 ++++ firmware/build.rs | 20 ++++++ firmware/memory.x | 5 ++ firmware/src/main.rs | 12 ++++ 6 files changed, 207 insertions(+) create mode 100644 firmware/.cargo/config create mode 100644 firmware/Cargo.lock create mode 100644 firmware/Cargo.toml create mode 100644 firmware/build.rs create mode 100644 firmware/memory.x create mode 100644 firmware/src/main.rs diff --git a/firmware/.cargo/config b/firmware/.cargo/config new file mode 100644 index 0000000..5b46eb4 --- /dev/null +++ b/firmware/.cargo/config @@ -0,0 +1,2 @@ +[build] +target = "riscv32imc-unknown-none-elf" diff --git a/firmware/Cargo.lock b/firmware/Cargo.lock new file mode 100644 index 0000000..d92775d --- /dev/null +++ b/firmware/Cargo.lock @@ -0,0 +1,154 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bare-metal" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bit_field" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "helloworld" +version = "0.0.0" +dependencies = [ + "panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "riscv-rt 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "panic-halt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "r0" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "riscv" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riscv-rt" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "riscv-rt-macros 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riscv-rt-macros" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "0.15.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a" +"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" +"checksum panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" +"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" +"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00f3ec73803f144a6474819070dfcf0b0d1662e1bd8845956850ee8f8cfbc69b" +"checksum riscv-rt 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af8c51c09a5445950a53431d3f8ca9d90ba4062cd86b5407c3e16d8c2558c17d" +"checksum riscv-rt-macros 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e9ba967e1f2902cc37cc4722f7ef4dd5e08cec430c97586424d6f679eb51b695" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml new file mode 100644 index 0000000..f81b311 --- /dev/null +++ b/firmware/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "helloworld" +version = "0.0.0" + +[dependencies] +panic-halt = "0.2.0" +riscv-rt = "0.5.0" + +[profile.release] +codegen-units = 1 +incremental = false +debug = true +opt-level = "s" +lto = true diff --git a/firmware/build.rs b/firmware/build.rs new file mode 100644 index 0000000..da2a65a --- /dev/null +++ b/firmware/build.rs @@ -0,0 +1,20 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::Path; + +/// Put the linker script somewhere the linker can find it. +fn main() { + let out_dir = env::var("OUT_DIR").expect("No out dir"); + let dest_path = Path::new(&out_dir); + let mut f = File::create(&dest_path.join("memory.x")) + .expect("Could not create file"); + + f.write_all(include_bytes!("memory.x")) + .expect("Could not write file"); + + println!("cargo:rustc-link-search={}", dest_path.display()); + + println!("cargo:rerun-if-changed=memory.x"); + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/firmware/memory.x b/firmware/memory.x new file mode 100644 index 0000000..dc78f12 --- /dev/null +++ b/firmware/memory.x @@ -0,0 +1,5 @@ +MEMORY +{ + FLASH : ORIGIN = 0x20000000, LENGTH = 16M + RAM : ORIGIN = 0x80000000, LENGTH = 16K +} diff --git a/firmware/src/main.rs b/firmware/src/main.rs new file mode 100644 index 0000000..1db0b05 --- /dev/null +++ b/firmware/src/main.rs @@ -0,0 +1,12 @@ +#![no_std] +#![no_main] + +extern crate riscv_rt; +extern crate panic_halt; + +use riscv_rt::entry; + +#[entry] +fn main() -> ! { + loop {} +}