Skip to content

Commit

Permalink
Introduce 'release' crate for SVSM Versioning
Browse files Browse the repository at this point in the history
Introduce the crate 'release' which will provide the version of the
COCONUT-SVSM being built. The crate is used in SVSM and Stage2 to
print a version identification in the initial console greeting.

Signed-off-by: Joerg Roedel <[email protected]>
  • Loading branch information
joergroedel committed Jan 21, 2025
1 parent dda83f0 commit 4b459da
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ members = [
"user/lib",
# Init user-space module
"user/init",
# Release version identifier
"release",
]


Expand All @@ -39,6 +41,7 @@ syscall = { path = "syscall" }
packit = { path = "packit" }
userlib = { path = "user/lib" }
userinit = { path = "user/init" }
release = { path = "release" }

# crates.io
aes-gcm = { version = "0.10.3", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ log = { workspace = true, features = ["max_level_info", "release_max_level_info"
packit.workspace = true
libtcgtpm = { workspace = true, optional = true }
zerocopy = { workspace = true, features = ["alloc", "derive"] }
release.workspace = true

builtin = { workspace = true, optional = true }
builtin_macros = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion kernel/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::locking::SpinLock;
use crate::serial::{SerialPort, Terminal, DEFAULT_SERIAL_PORT};
use crate::utils::immut_after_init::{ImmutAfterInitCell, ImmutAfterInitResult};
use core::fmt;
use release::COCONUT_VERSION;

#[derive(Clone, Copy, Debug)]
struct Console {
Expand Down Expand Up @@ -40,7 +41,10 @@ static CONSOLE_SERIAL: ImmutAfterInitCell<SerialPort<'_>> = ImmutAfterInitCell::
fn init_console(writer: &'static dyn Terminal) -> ImmutAfterInitResult<()> {
WRITER.lock().writer = writer;
CONSOLE_INITIALIZED.reinit(&true)?;
log::info!("COCONUT Secure Virtual Machine Service Module");
log::info!(
"COCONUT Secure Virtual Machine Service Module Version {}",
COCONUT_VERSION
);
Ok(())
}

Expand Down
9 changes: 9 additions & 0 deletions release/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "release"
version = "0.1.0"
edition = "2021"

[dependencies]

[lints]
workspace = true
54 changes: 54 additions & 0 deletions release/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2025 SUSE LLC
//
// Author: Joerg Roedel <[email protected]>

#![no_std]

use core::fmt;

#[allow(dead_code)]
#[derive(Debug)]
enum ReleaseType {
/// Development Release
Development,
/// Stable Release Candidate
Candidate(u32),
/// Stable Release
Stable(u32),
}

#[derive(Debug)]
pub struct SvsmVersion {
year: u32,
month: u32,
release_type: ReleaseType,
}

impl fmt::Display for SvsmVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.release_type {
ReleaseType::Development => {
write!(f, "{}.{:#02}-devel", self.year, self.month)
}
ReleaseType::Candidate(counter) => {
write!(f, "{}.{:#02}-rc{}", self.year, self.month, counter)
}
ReleaseType::Stable(counter) => {
write!(f, "{}.{:#02}.{}", self.year, self.month, counter)
}
}
}
}

const VERSION_YEAR: u32 = 2025;
const VERSION_MONTH: u32 = 1;
#[allow(dead_code)]
const VERSION_COUNTER: u32 = 0;

pub static COCONUT_VERSION: SvsmVersion = SvsmVersion {
year: VERSION_YEAR,
month: VERSION_MONTH,
release_type: ReleaseType::Development,
};

0 comments on commit 4b459da

Please sign in to comment.