diff --git a/firmware/Cargo.lock b/firmware/Cargo.lock index 22215f1..f0f9da1 100644 --- a/firmware/Cargo.lock +++ b/firmware/Cargo.lock @@ -1,11 +1,12 @@ [root] name = "ionpak-firmware" -version = "0.1.0" +version = "1.0.0" dependencies = [ "cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp?rev=d03ea64)", "tm4c129x 0.5.0 (git+https://github.com/m-labs/dslite2svd?rev=d527f3f)", + "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -42,6 +43,15 @@ dependencies = [ "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "managed" version = "0.3.0" @@ -52,6 +62,15 @@ name = "r0" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "smoltcp" version = "0.4.0-pre" @@ -85,15 +104,40 @@ dependencies = [ "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "walkdir" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [metadata] "checksum aligned 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a92995cea48691c7c93e12597cca4d692bb3130d0a291c7141b9793c7829e7" "checksum bare-metal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "19de0ac42f6977d7428858b750131ea9c8166f4ccb7deeab38b6a8656c9798b0" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d553ca1f23403c81e6d3d28a64ef6e8eadd7f395195aacda65cbc0dc987738e" "checksum cortex-m-rt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ec28308ef272803380c9c4e6708bf1d794ddcc8c9d511b9976b31ac3322452e5" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "61eb783b4fa77e8fa4d27ec400f97ed9168546b8b30341a120b7ba9cc6571aaf" "checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" +"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" "checksum smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp?rev=d03ea64)" = "" "checksum tm4c129x 0.5.0 (git+https://github.com/m-labs/dslite2svd?rev=d527f3f)" = "" "checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d" "checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" +"checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml index 2ef1c05..c741700 100644 --- a/firmware/Cargo.toml +++ b/firmware/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "ionpak-firmware" -version = "0.1.0" +version = "1.0.0" authors = ["whitequark "] +[build-dependencies] +walkdir = "1.0" + [dependencies] cortex-m = "0.3.1" cortex-m-rt = { version = "0.3.5" } diff --git a/firmware/build.rs b/firmware/build.rs index 88f7fef..7e55d6c 100644 --- a/firmware/build.rs +++ b/firmware/build.rs @@ -1,9 +1,53 @@ -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; +extern crate walkdir; -fn main() { +use std::env; +use std::io::Write; +use std::fs::File; +use std::path::{Path, PathBuf}; +use std::process::Command; + +use walkdir::WalkDir; + +fn git_describe() { + let git_dir = Path::new("../.git"); + + println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display()); + for entry in WalkDir::new(git_dir.join("refs")) { + let entry = entry.unwrap(); + println!("cargo:rerun-if-changed={}", entry.path().display()); + } + + let version; + if git_dir.exists() { + let git_describe = + Command::new("git") + .arg("describe") + .arg("--tags") + .arg("--dirty") + .arg("--always") + .arg("--long") + .arg("--abbrev=8") + .output() + .ok() + .and_then(|o| String::from_utf8(o.stdout).ok()) + .map(|mut s| { + let len = s.trim_right().len(); + s.truncate(len); + s + }) + .unwrap(); + let parts = git_describe.split("-").collect::>(); + version = format!("{}+{}.{}", parts[0], parts[1], parts[2]); + } else { + version = "unknown".to_owned(); + } + + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let mut f = File::create(out_dir.join("git-describe")).unwrap(); + write!(f, "{}", version).unwrap(); +} + +fn linker_script() { // Put the linker script somewhere the linker can find it let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); File::create(out.join("memory.x")) @@ -15,3 +59,8 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=memory.x"); } + +fn main() { + linker_script(); + git_describe(); +} diff --git a/firmware/src/pages.rs b/firmware/src/pages.rs index 28ba298..5cd4ecf 100644 --- a/firmware/src/pages.rs +++ b/firmware/src/pages.rs @@ -61,6 +61,11 @@ pub fn serve(output: &mut TcpSocket, request: &http::Request, cathode_fbv=OpnFmt(cathode.fbv), ion_current=OpnFmt(electrometer.ic.and_then(|x| Some(x*1.0e9)))).unwrap(); }, + b"/firmware.html" => { + http::write_reply_header(output, 200, "text/html; charset=utf-8", false).unwrap(); + write!(output, include_str!("firmware.html"), + version=include_str!(concat!(env!("OUT_DIR"), "/git-describe"))).unwrap(); + } b"/style.css" => { let data = include_bytes!("style.css.gz"); http::write_reply_header(output, 200, "text/css", true).unwrap();