From faa51908d7d326c23e368fb63ddb73486c5bdcf6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 31 Jan 2022 23:02:32 +0800 Subject: [PATCH] maybe, just maybe...we finally have version info baked into the kernel correctly. --- .gitignore | 2 + Cargo.lock | 15 ++---- services/com/src/main.rs | 1 + services/log-server/src/main.rs | 19 -------- services/shellchat/src/cmds/ver.rs | 12 +---- services/ticktimer-server/Cargo.toml | 2 + services/ticktimer-server/src/api.rs | 8 ++++ services/ticktimer-server/src/lib.rs | 10 ++++ services/ticktimer-server/src/main.rs | 11 ++++- services/ticktimer-server/src/version.rs | 8 ---- xtask/Cargo.toml | 5 +- xtask/build.rs | 15 ------ xtask/src/main.rs | 60 ++++++++++++++++++++++++ 13 files changed, 99 insertions(+), 69 deletions(-) delete mode 100644 services/ticktimer-server/src/version.rs delete mode 100644 xtask/build.rs diff --git a/.gitignore b/.gitignore index ceeae1287..cbd79451d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ **/*.rs.bk /emulation/peripherals.csproj /emulation/obj +# auto-generated +services/ticktimer-server/src/version.rs *.map diff --git a/Cargo.lock b/Cargo.lock index 3621ff43d..a961c4890 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2447,9 +2447,11 @@ dependencies = [ "log-server", "num-derive", "num-traits", + "rkyv", "susres", "utralib", "xous", + "xous-ipc", "xous-names", ] @@ -2563,17 +2565,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "vergen" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7141e445af09c8919f1d5f8a20dae0b20c3b57a45dee0d5823c6ed5d237f15a" -dependencies = [ - "bitflags", - "chrono", - "rustc_version 0.4.0", -] - [[package]] name = "version-compare" version = "0.0.10" @@ -2921,10 +2912,10 @@ name = "xtask" version = "0.1.0" dependencies = [ "atty", + "chrono", "curl", "filetime", "rustc_version 0.4.0", - "vergen", "zip", ] diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 9931f69ed..aa5936641 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -675,6 +675,7 @@ fn xmain() -> ! { loop { com.txrx(ComState::LOOP_TEST.verb); let ack = com.wait_txrx(ComState::LINK_READ.verb, Some(5000)); // should finish with 5 seconds + // TODO: offer a more robust sequence than 0x00 for detecting if sync is back... if (ack & 0xff) != 0x00 { //it will read 0xdd or 0xff if the EC is actually still in reset or held up log::warn!("Wf200 reset took too long, trying to re-establish link sync...{:x}", ack); com.txrx(ComState::LINK_SYNC.verb); diff --git a/services/log-server/src/main.rs b/services/log-server/src/main.rs index 918df479a..99930184c 100644 --- a/services/log-server/src/main.rs +++ b/services/log-server/src/main.rs @@ -394,25 +394,6 @@ fn handle_opcode( fn reader_thread(arg: usize) { let output = unsafe { &mut *(arg as *mut implementation::OutputWriter) }; writeln!(output, "LOG: Xous Logging Server starting up...").unwrap(); - - writeln!( - output, - "LOG: ****************************************************************" - ) - .unwrap(); - writeln!( - output, - "LOG: *** Welcome to Xous {:40} ***", - env!("VERGEN_SHA") - ) - .unwrap(); - writeln!(output, "LOG: *** Built: {:49} ***", env!("VERGEN_BUILD_TIMESTAMP")).unwrap(); - writeln!(output, "LOG: *** Semver: {:48} ***", env!("VERGEN_SEMVER")).unwrap(); - writeln!( - output, - "LOG: ****************************************************************" - ) - .unwrap(); let server_addr = xous::create_server_with_address(b"xous-log-server ").unwrap(); writeln!(output, "LOG: Server listening on address {:?}", server_addr).unwrap(); diff --git a/services/shellchat/src/cmds/ver.rs b/services/shellchat/src/cmds/ver.rs index 4c2ad15e5..2504550fe 100644 --- a/services/shellchat/src/cmds/ver.rs +++ b/services/shellchat/src/cmds/ver.rs @@ -36,16 +36,8 @@ impl<'a> ShellCmdApi<'a> for Ver { "dna" => { write!(ret, "SoC silicon DNA: 0x{:x}", env.llio.soc_dna().unwrap()).unwrap(); } - "shellchat" => { - // note that this only picks up new build info when shellchat is rebuilt - // we don't retrigger a shellchat rebuild every time we rebuild xous because it - // would make small builds take much longer. A fix to this would be to create - // a "version server" that is tiny, fast to re-link, and rebuilt on every build pass. - write!(ret, "Shellchat version info:\n{}\n{}\n{}\n{}", - env!("VERGEN_SEMVER"), - env!("VERGEN_BRANCH"), - env!("VERGEN_SHA_SHORT"), - env!("VERGEN_BUILD_TIMESTAMP")).unwrap(); + "xous" => { + write!(ret, "Xous version: {}", env.ticktimer.get_version()).unwrap(); } _ => { write!(ret, "{}", helpstring).unwrap(); diff --git a/services/ticktimer-server/Cargo.toml b/services/ticktimer-server/Cargo.toml index 9c6ea8522..eb85ca9c9 100644 --- a/services/ticktimer-server/Cargo.toml +++ b/services/ticktimer-server/Cargo.toml @@ -10,6 +10,8 @@ version = "0.1.0" log = "0.4.14" log-server = {path = "../log-server"} xous = {path = "../../xous-rs"} +xous-ipc = {path = "../../xous-ipc"} +rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} susres = {path = "../susres"} diff --git a/services/ticktimer-server/src/api.rs b/services/ticktimer-server/src/api.rs index dfddde563..fd4f40b97 100644 --- a/services/ticktimer-server/src/api.rs +++ b/services/ticktimer-server/src/api.rs @@ -14,4 +14,12 @@ pub(crate) enum Opcode { /// force a WDT update PingWdt = 4, + + /// return the version string of Xous. We bury it here because this is a small, lightweight server we can rebuild on every run. + GetVersion = 5, } + +#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +pub struct VersionString { + pub version: xous_ipc::String::<512>, +} \ No newline at end of file diff --git a/services/ticktimer-server/src/lib.rs b/services/ticktimer-server/src/lib.rs index 1a3873ef3..a303bb10a 100644 --- a/services/ticktimer-server/src/lib.rs +++ b/services/ticktimer-server/src/lib.rs @@ -60,6 +60,16 @@ impl Ticktimer { ) .expect("Couldn't send WDT ping"); } + + pub fn get_version(&self) -> String { + let alloc = api::VersionString { + version: xous_ipc::String::new(), + }; + let mut buf = xous_ipc::Buffer::into_buf(alloc).expect("couldn't convert version request"); + buf.lend_mut(self.conn, api::Opcode::GetVersion.to_u32().unwrap()).expect("couldn't get version"); + let v = buf.to_original::().expect("couldn't revert buffer"); + String::from(v.version.as_str().unwrap()) + } } use core::sync::atomic::{AtomicU32, Ordering}; static REFCOUNT: AtomicU32 = AtomicU32::new(0); diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index 175300d36..561b55f9c 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -473,6 +473,11 @@ fn xmain() -> ! { log::set_max_level(log::LevelFilter::Info); info!("my PID is {}", xous::process::id()); + log::info!("****************************************************************"); + log::info!("Welcome to Xous {}", version::SEMVER); + log::info!("Built at {}", version::TIMESTAMP); + log::info!("****************************************************************"); + let ticktimer_server = xous::create_server_with_address(b"ticktimer-server") .expect("Couldn't create Ticktimer server"); info!("Server started with SID {:?}", ticktimer_server); @@ -498,7 +503,7 @@ fn xmain() -> ! { //#[cfg(feature = "watchdog")] // for debugging the watchdog //ticktimer.check_wdt(); - let msg = xous::receive_message(ticktimer_server).unwrap(); + let mut msg = xous::receive_message(ticktimer_server).unwrap(); log::trace!("msg: {:?}", msg); match num_traits::FromPrimitive::from_usize(msg.body.id()) { Some(api::Opcode::ElapsedMs) => { @@ -533,6 +538,10 @@ fn xmain() -> ! { Some(api::Opcode::PingWdt) => { ticktimer.reset_wdt(); } + Some(api::Opcode::GetVersion) => { + let mut buf = unsafe{xous_ipc::Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())}; + buf.replace(version::get_version()).unwrap(); + } None => { error!("couldn't convert opcode"); break; diff --git a/services/ticktimer-server/src/version.rs b/services/ticktimer-server/src/version.rs deleted file mode 100644 index fd1604b87..000000000 --- a/services/ticktimer-server/src/version.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Versioning information is kept in a separate file, attached to a small, well-known server in the Xous System -// This is a trade-off between rebuild times and flexibility. - -//LOG: **************************************************************** -//LOG: *** Welcome to Xous 2a1ab53e6b271feb3ea791cdf3ae822612f59d30 *** -//LOG: *** Built: 2022-01-31T05:13:03.355604900+00:00 *** -//LOG: *** Semver: v0.9.5-352-g2a1ab53e *** -//LOG: **************************************************************** \ No newline at end of file diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 6a2cabc65..1b61edb03 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -12,7 +12,4 @@ atty = "0.2.14" filetime = "0.2.14" rustc_version = "0.4.0" zip = "0.5.13" - -[build-dependencies] -vergen = "3.2.0" -filetime = "0.2.14" +chrono = "0.4" diff --git a/xtask/build.rs b/xtask/build.rs deleted file mode 100644 index 2bf9e25ed..000000000 --- a/xtask/build.rs +++ /dev/null @@ -1,15 +0,0 @@ -use vergen::{ConstantsFlags, generate_cargo_keys}; - -fn main() { - // Setup the flags, toggling off the 'SEMVER_FROM_CARGO_PKG' flag - let flags = ConstantsFlags::all(); - - // Generate the 'cargo:' key output - generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); - - // touch the log server to force it to pick up the version - let ts = filetime::FileTime::from_system_time(std::time::SystemTime::now()); - filetime::set_file_mtime("../services/log-server/src/main.rs", ts).unwrap(); - - // note that shellchat won't pick up the vesion, but because it's a big crate to rebuild we aren't re-triggering it -} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index acbddce87..b2c5088a7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -5,6 +5,8 @@ use std::{ path::{Path, PathBuf, MAIN_SEPARATOR}, process::Command, }; +use std::fs::OpenOptions; +use chrono::Local; type DynError = Box; @@ -34,6 +36,8 @@ impl std::fmt::Display for BuildError { impl std::error::Error for BuildError {} fn main() -> Result<(), Box> { + generate_version(); // really brute force way to try and get a version into the build system. + let hw_pkgs = [ // core OS services "gam", @@ -1014,3 +1018,59 @@ fn whycheproof_import() -> Result<(), DynError> { // fn dist_dir() -> PathBuf { // project_root().join("target/dist") // } + +fn generate_version() { + let output = if cfg!(target_os = "windows") { + Command::new("cmd") + .args(["/C", "git describe --tags"]) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg("git describe --tags") + .output() + .expect("failed to execute process") + }; + let gitver = output.stdout; + let semver = String::from_utf8_lossy(&gitver); + + let mut vfile = OpenOptions::new() + .read(true) + .write(true) + .create(true) + .truncate(true) + .open("services/ticktimer-server/src/version.rs").expect("Can't open our version file for writing"); + print_header(&mut vfile); + let now = Local::now(); + write!(vfile, "pub const TIMESTAMP: &'static str = \"{}\";\n", now.to_rfc2822()).expect("couldn't add our timestamp"); + write!(vfile, "pub const SEMVER: &'static str = \"{}\";\n", + semver + .strip_suffix("\r\n") + .or(semver.strip_suffix("\n")) + .unwrap_or(&semver) + ).expect("couldn't add our semver"); +} + +fn print_header(out: &mut U) { + let s = r####"// Versioning information is kept in a separate file, attached to a small, well-known server in the Xous System +// This is a trade-off between rebuild times and flexibility. +// This was autogenerated by xtask/build.rs. + +pub(crate) fn get_version() -> crate::api::VersionString { + let mut v = crate::api::VersionString { + version: xous_ipc::String::new() + }; + // NOTE: the semver is only updated if you can somehow trigger build.rs on xtask to re-run. AFAIK, it basically never re-runs, + // because it will only rerun if something *inside xtask* changes (not the rest of the code). + // so if you want to pick up the "correct" SEMVER, you have to do a cargo clean. + v.version.append(SEMVER).ok(); + v.version.append("\n").ok(); + // This timestamp *will* be correct because we are actually forcing it to be rebuilt every build. + v.version.append(TIMESTAMP).ok(); + v.version.append("\n").ok(); + v +} +"####; + out.write_all(s.as_bytes()).expect("couldn't write our version template header"); +} \ No newline at end of file