diff --git a/OSDK.toml b/OSDK.toml index 43186f932..0f482345a 100644 --- a/OSDK.toml +++ b/OSDK.toml @@ -1,18 +1,6 @@ -vars = [ - ["SMP", "1"], - ["MEM", "2G"], - ["EXT2_IMG", "$OSDK_CWD/regression/build/ext2.img"], - ["EXFAT_IMG", "$OSDK_CWD/regression/build/exfat.img"], -] - [boot] method = "grub-rescue-iso" -[run] -vars = [ - ["OVMF_PATH", "/usr/share/OVMF"], -] - [run.boot] kcmd_args = [ "SHELL=/bin/sh", @@ -32,48 +20,36 @@ boot.method = "qemu-direct" protocol = "multiboot2" [qemu] -args = "$(./tools/qemu_args.sh)" +args = "$(./tools/qemu_args.sh normal -ovmf)" + +[test.qemu] +args = "$(./tools/qemu_args.sh test)" [scheme."microvm"] boot.method = "qemu-direct" -vars = [ - ["MICROVM", "true"], -] -qemu.args = "$(./tools/qemu_args.sh)" +qemu.args = "$(./tools/qemu_args.sh microvm)" [scheme."iommu"] supported_archs = ["x86_64"] -vars = [ - ["IOMMU_DEV_EXTRA", ",iommu_platform=on,ats=on"], - ["IOMMU_EXTRA_ARGS", """\ - -device intel-iommu,intremap=on,device-iotlb=on \ - -device ioh3420,id=pcie.0,chassis=1\ - """], -] -qemu.args = "$(./tools/qemu_args.sh)" +qemu.args = "$(./tools/qemu_args.sh iommu)" [scheme."tdx"] supported_archs = ["x86_64"] build.features = ["intel_tdx"] -vars = [ - ["MEM", "8G"], - ["OVMF_PATH", "~/tdx-tools/ovmf"], -] boot.method = "grub-qcow2" grub.mkrescue_path = "~/tdx-tools/grub" grub.protocol = "linux" qemu.args = """\ -accel kvm \ -name process=tdxvm,debug-threads=on \ - -m $MEM \ - -smp $SMP \ + -m ${MEM:-8G} \ + -smp ${SMP:-1} \ -vga none \ -nographic \ -monitor pty \ -no-hpet \ -nodefaults \ -monitor telnet:127.0.0.1:9003,server,nowait \ - -bios $OVMF_PATH/OVMF_VARS.fd \ -object tdx-guest,sept-ve-disable,id=tdx,quote-generation-service=vsock:2:4050 \ -cpu host,-kvm-steal-time,pmu=off,tsc-freq=1000000000 \ -machine q35,kernel_irqchip=split,confidential-guest-support=tdx \ @@ -82,7 +58,7 @@ qemu.args = """\ -device virtio-blk-pci,bus=pcie.0,addr=0x6,drive=x0,disable-legacy=on,disable-modern=off \ -drive file=fs.img,if=none,format=raw,id=x0 \ -netdev user,id=mynet0,hostfwd=tcp::10027-:22,hostfwd=tcp::54136-:8090 \ - -chardev stdio,id=mux,mux=on,logfile=$OSDK_CWD/$(date '+%Y-%m-%dT%H%M%S').log \ + -chardev stdio,id=mux,mux=on,logfile=./$(date '+%Y-%m-%dT%H%M%S').log \ -device virtio-serial,romfile= \ -device virtconsole,chardev=mux \ -monitor chardev:mux \ diff --git a/docs/src/osdk/reference/manifest.md b/docs/src/osdk/reference/manifest.md index 7a9c9abc3..b246fcfce 100644 --- a/docs/src/osdk/reference/manifest.md +++ b/docs/src/osdk/reference/manifest.md @@ -23,7 +23,7 @@ will inherit values from the workspace manifest. ## Configurations Below, you will find a comprehensive version of -the available configuration tree in the manifest. +the available configurations in the manifest. Here are notes for some fields with special value treatings: - `*` marks the field as "will be evaluated", that the final @@ -36,47 +36,41 @@ If values are given in the tree that's the default value inferred if that the field is not explicitly stated. ``` -project_type # The type of the current crate. Can be lib/kernel[/module] +project_type = "kernel" # The type of the current crate. Can be lib/kernel[/module] -# --------------------------- the default schema settings --------------------- -vars = [] # List of lists. These are the env vars that will be set before - # any evaluation happens. The variables will be evaluated - # **SEQUENTIALLY**. - # The reserved variables: - # - `OSDK_CWD`: The directory of the OSDK manifest. -build -|- features = [] # List of strings, the same as Cargo -|- profile = "dev" # String, the same as Cargo -boot -|- method # "grub-rescue-iso"/"qemu-direct"/"grub-qcow2" -|- kcmd_args # <1> -|- init_args # <2> -|- initramfs + # The path to the initramfs -grub # Grub options are only needed if boot method is related to GRUB -|- mkrescue_path + # The path to the `grub-mkrescue` executable -|- protocol # The protocol GRUB used. "linux"/"multiboot"/"multiboot2" -|- display_grub_menu # To display the GRUB menu when booting with GRUB -qemu -|- path + # The path to the QEMU executable -|- args * # String. <3> -run # Special settings for running, which will override default ones -|- vars # The run specific variables evaluate after .vars -|- build # Overriding .build -|- boot # Overriding .boot -|- grub # Overriding .grub -|- qemu # Overriding .qemu -test # Special settings for testing, which will override default ones -|- vars # The test specific variables evaluate after .vars -|- build # Overriding .build -|- boot # Overriding .boot -|- grub # Overriding .grub -|- qemu # Overriding .qemu -# ----------------------- end of the default schema settings ------------------ +# --------------------------- the default schema settings ------------------------------- +supported_archs = ["x86_64"]# List of strings, that the arch the schema can apply to +[build] +features = [] # List of strings, the same as Cargo +profile = "dev" # String, the same as Cargo +[boot] +method = "qemu-direct" # "grub-rescue-iso"/"qemu-direct"/"grub-qcow2" +kcmd_args = [] # <1> +init_args = [] # <2> +initramfs = "path/to/it" # + The path to the initramfs +[grub] # Grub options are only needed if boot method is related to GRUB +mkrescue_path = "path/to/it"# + The path to the `grub-mkrescue` executable +protocol = "multiboot2" # The protocol GRUB used. "linux"/"multiboot"/"multiboot2" +display_grub_menu = false # To display the GRUB menu when booting with GRUB +[qemu] +path + # The path to the QEMU executable +args * # String. <3> +[run] # Special settings for running, which will override default ones +build # Overriding [build] +boot # Overriding [boot] +grub # Overriding [grub] +qemu # Overriding [qemu] +[test] # Special settings for testing, which will override default ones +build # Overriding [build] +boot # Overriding [boot] +grub # Overriding [grub] +qemu # Overriding [qemu] +# ----------------------- end of the default schema settings ---------------------------- -schema."user_custom_schema" -|- ... # All the other fields in the default schema. Missing but - # needed values will be firstly filled with the default - # value then the corresponding field in the default schema +[schema."user_custom_schema"] +#... # All the other fields in the default schema. Missing but + # needed values will be firstly filled with the default + # value then the corresponding field in the default schema ``` Here are some additional notes for the fields: @@ -124,18 +118,10 @@ used to determine the actual set of qemu arguments. ```toml project_type = "kernel" -vars = [ - ["SMP", "1"], - ["MEM", "2G"], -] - [boot] method = "grub-rescue-iso" [run] -vars = [ - ["OVMF_PATH", "/usr/share/OVMF"], -] boot.kcmd_args = [ "SHELL=/bin/sh", "LOGNAME=root", @@ -159,36 +145,22 @@ args = "$(./tools/qemu_args.sh)" [scheme."microvm"] boot.method = "qemu-direct" -vars = [ - ["MICROVM", "true"], -] -qemu.args = "$(./tools/qemu_args.sh)" +qemu.args = "$(./tools/qemu_args.sh microvm)" [scheme."iommu"] supported_archs = ["x86_64"] -vars = [ - ["IOMMU_DEV_EXTRA", ",iommu_platform=on,ats=on"], - ["IOMMU_EXTRA_ARGS", """\ - -device intel-iommu,intremap=on,device-iotlb=on \ - -device ioh3420,id=pcie.0,chassis=1\ - """], -] -qemu.args = "$(./tools/qemu_args.sh)" +qemu.args = "$(./tools/qemu_args.sh iommu)" [scheme."intel_tdx"] supported_archs = ["x86_64"] build.features = ["intel_tdx"] -vars = [ - ["MEM", "8G"], - ["OVMF_PATH", "~/tdx-tools/ovmf"], -] boot.method = "grub-qcow2" grub.mkrescue_path = "~/tdx-tools/grub" grub.protocol = "linux" qemu.args = """\ -accel kvm \ -name process=tdxvm,debug-threads=on \ - -m $MEM \ + -m ${MEM:-8G} \ -smp $SMP \ -vga none \ """ diff --git a/osdk/src/bundle/mod.rs b/osdk/src/bundle/mod.rs index b4d60e13e..2513aa8a5 100644 --- a/osdk/src/bundle/mod.rs +++ b/osdk/src/bundle/mod.rs @@ -200,6 +200,7 @@ impl Bundle { ActionChoice::Test => &config.test, }; let mut qemu_cmd = Command::new(&action.qemu.path); + qemu_cmd.current_dir(&config.work_dir); match shlex::split(&action.qemu.args) { Some(v) => { for arg in v { diff --git a/osdk/src/commands/new/kernel.OSDK.toml.template b/osdk/src/commands/new/kernel.OSDK.toml.template index d6fceb223..7a6505184 100644 --- a/osdk/src/commands/new/kernel.OSDK.toml.template +++ b/osdk/src/commands/new/kernel.OSDK.toml.template @@ -1,9 +1,5 @@ project_type = "kernel" -vars = [ - ["OVMF_PATH", "/usr/share/OVMF"], -] - [boot] method = "grub-rescue-iso" @@ -20,6 +16,6 @@ args = """\ -chardev stdio,id=mux,mux=on,signal=off \ -display none \ -device isa-debug-exit,iobase=0xf4,iosize=0x04 \ - -drive if=pflash,format=raw,unit=0,readonly=on,file=$OVMF_PATH/OVMF_CODE.fd \ - -drive if=pflash,format=raw,unit=1,file=$OVMF_PATH/OVMF_VARS.fd \ + -drive if=pflash,format=raw,unit=0,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd \ + -drive if=pflash,format=raw,unit=1,file=/usr/share/OVMF/OVMF_VARS.fd \ """ \ No newline at end of file diff --git a/osdk/src/config/eval.rs b/osdk/src/config/eval.rs index 6ee86c4fe..7faee2980 100644 --- a/osdk/src/config/eval.rs +++ b/osdk/src/config/eval.rs @@ -2,39 +2,15 @@ //! The module implementing the evaluation feature. -use std::{io, process}; - -pub type Vars = Vec<(String, String)>; +use std::{io, path::Path, process}; /// This function is used to evaluate the string using the host's shell recursively /// in order. -pub fn eval(vars: &Vars, s: &String) -> io::Result { - let mut vars = vars.clone(); - for i in 0..vars.len() { - vars[i].1 = eval_with_finalized_vars(&vars[..i], &vars[i].1)?; - } - eval_with_finalized_vars(&vars[..], s) -} - -fn eval_with_finalized_vars(vars: &[(String, String)], s: &String) -> io::Result { - let env_keys: Vec = std::env::vars().map(|(key, _)| key).collect(); - +pub fn eval(cwd: impl AsRef, s: &String) -> io::Result { let mut eval = process::Command::new("bash"); - let mut cwd = std::env::current_dir()?; - for (key, value) in vars { - // If the key is in the environment, we should ignore it. - // This allows users to override with the environment variables in CLI. - if env_keys.contains(key) { - continue; - } - eval.env(key, value); - if key == "OSDK_CWD" { - cwd = std::path::PathBuf::from(value); - } - } eval.arg("-c"); eval.arg(format!("echo \"{}\"", s)); - eval.current_dir(cwd); + eval.current_dir(cwd.as_ref()); let output = eval.output()?; if !output.stderr.is_empty() { println!( diff --git a/osdk/src/config/manifest.rs b/osdk/src/config/manifest.rs index 6488473c5..dabb186b4 100644 --- a/osdk/src/config/manifest.rs +++ b/osdk/src/config/manifest.rs @@ -12,7 +12,7 @@ use serde::{de, Deserialize, Deserializer, Serialize}; use super::scheme::Scheme; -use crate::{error::Errno, error_msg, util::get_cargo_metadata}; +use crate::{config::scheme::QemuScheme, error::Errno, error_msg, util::get_cargo_metadata}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OsdkMeta { @@ -150,6 +150,10 @@ fn deserialize_toml_manifest(path: impl AsRef) -> Option { // Preprocess the parsed manifest let cwd = path.as_ref().parent().unwrap(); + manifest.default_scheme.work_dir = Some(cwd.to_path_buf()); + for scheme in manifest.map.values_mut() { + scheme.work_dir = Some(cwd.to_path_buf()); + } // Canonicalize all the path fields let canonicalize = |target: &mut PathBuf| { let last_cwd = std::env::current_dir().unwrap(); @@ -194,22 +198,37 @@ fn deserialize_toml_manifest(path: impl AsRef) -> Option { } }; canonicalize_scheme(&mut manifest.default_scheme); - for (_, scheme) in manifest.map.iter_mut() { + for scheme in manifest.map.values_mut() { canonicalize_scheme(scheme); } - // Set the magic variable `OSDK_CWD` before any variable evaluation - let var = ("OSDK_CWD".to_owned(), cwd.to_string_lossy().to_string()); - manifest.default_scheme.vars = { - let mut vars = vec![var.clone()]; - vars.extend(manifest.default_scheme.vars.clone()); - vars - }; - for (_, scheme) in manifest.map.iter_mut() { - scheme.vars = { - let mut vars = vec![var.clone()]; - vars.extend(scheme.vars.clone()); - vars + // Do evaluations on the need to be evaluated string field, namely, + // QEMU arguments. + use super::eval::eval; + let eval_scheme = |scheme: &mut Scheme| { + let eval_qemu = |qemu: &mut Option| { + if let Some(ref mut qemu) = qemu { + if let Some(ref mut args) = qemu.args { + *args = match eval(cwd, args) { + Ok(v) => v, + Err(e) => { + error_msg!("Failed to evaluate qemu args: {:#?}", e); + process::exit(Errno::ParseMetadata as _); + } + } + } + } }; + eval_qemu(&mut scheme.qemu); + if let Some(ref mut run) = scheme.run { + eval_qemu(&mut run.qemu); + } + if let Some(ref mut test) = scheme.test { + eval_qemu(&mut test.qemu); + } + }; + eval_scheme(&mut manifest.default_scheme); + for scheme in manifest.map.values_mut() { + eval_scheme(scheme); } Some(manifest) } @@ -222,7 +241,6 @@ impl<'de> Deserialize<'de> for TomlManifest { enum Field { ProjectType, SupportedArchs, - Vars, Boot, Grub, Qemu, @@ -235,7 +253,6 @@ impl<'de> Deserialize<'de> for TomlManifest { const EXPECTED: &[&str] = &[ "project_type", "supported_archs", - "vars", "boot", "grub", "qemu", @@ -266,7 +283,6 @@ impl<'de> Deserialize<'de> for TomlManifest { match v { "project_type" => Ok(Field::ProjectType), "supported_archs" => Ok(Field::SupportedArchs), - "vars" => Ok(Field::Vars), "boot" => Ok(Field::Boot), "grub" => Ok(Field::Grub), "qemu" => Ok(Field::Qemu), @@ -328,7 +344,6 @@ impl<'de> Deserialize<'de> for TomlManifest { project_type = Some(value); } Field::SupportedArchs => match_and_add_vec!(supported_archs), - Field::Vars => match_and_add_vec!(vars), Field::Boot => match_and_add_option!(boot), Field::Grub => match_and_add_option!(grub), Field::Qemu => match_and_add_option!(qemu), diff --git a/osdk/src/config/mod.rs b/osdk/src/config/mod.rs index e37c9c2f3..40dbe2068 100644 --- a/osdk/src/config/mod.rs +++ b/osdk/src/config/mod.rs @@ -14,6 +14,8 @@ pub mod unix_args; #[cfg(test)] mod test; +use std::{env, path::PathBuf}; + use scheme::{Action, ActionScheme, BootScheme, Build, GrubScheme, QemuScheme, Scheme}; use crate::{ @@ -25,6 +27,7 @@ use crate::{ /// The global configuration for the OSDK actions. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Config { + pub work_dir: PathBuf, pub target_arch: Arch, pub build: Build, pub run: Action, @@ -84,7 +87,6 @@ impl Config { pub fn new(scheme: &Scheme, common_args: &CommonArgs) -> Self { let target_arch = common_args.target_arch.unwrap_or(get_default_arch()); let default_scheme = ActionScheme { - vars: scheme.vars.clone(), boot: scheme.boot.clone(), grub: scheme.grub.clone(), qemu: scheme.qemu.clone(), @@ -107,6 +109,10 @@ impl Config { test }; Self { + work_dir: scheme + .work_dir + .clone() + .unwrap_or_else(|| env::current_dir().unwrap()), target_arch, build: scheme.build.clone().unwrap_or_default().finalize(), run, diff --git a/osdk/src/config/scheme/action.rs b/osdk/src/config/scheme/action.rs index 63a5ff70b..f53b458ba 100644 --- a/osdk/src/config/scheme/action.rs +++ b/osdk/src/config/scheme/action.rs @@ -2,10 +2,7 @@ use super::{inherit_optional, Boot, BootScheme, Grub, GrubScheme, Qemu, QemuScheme}; -use crate::{ - cli::CommonArgs, - config::{scheme::Vars, Arch}, -}; +use crate::{cli::CommonArgs, config::Arch}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ActionChoice { @@ -69,7 +66,7 @@ impl Build { impl BuildScheme { pub fn inherit(&mut self, parent: &Self) { - if parent.profile.is_some() { + if self.profile.is_none() { self.profile = parent.profile.clone(); } self.features = { @@ -96,8 +93,6 @@ impl BuildScheme { #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ActionScheme { - #[serde(default)] - pub vars: Vars, pub boot: Option, pub grub: Option, pub qemu: Option, @@ -114,11 +109,6 @@ pub struct Action { impl ActionScheme { pub fn inherit(&mut self, from: &Self) { - self.vars = { - let mut vars = from.vars.clone(); - vars.extend(self.vars.clone()); - vars - }; inherit_optional!(from, self, .boot); inherit_optional!(from, self, .grub); inherit_optional!(from, self, .qemu); @@ -129,7 +119,7 @@ impl ActionScheme { Action { boot: self.boot.unwrap_or_default().finalize(), grub: self.grub.unwrap_or_default().finalize(), - qemu: self.qemu.unwrap_or_default().finalize(&self.vars, arch), + qemu: self.qemu.unwrap_or_default().finalize(arch), build: self.build.unwrap_or_default().finalize(), } } diff --git a/osdk/src/config/scheme/mod.rs b/osdk/src/config/scheme/mod.rs index 038e8a852..48655d0dd 100644 --- a/osdk/src/config/scheme/mod.rs +++ b/osdk/src/config/scheme/mod.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use super::eval::Vars; +use std::path::PathBuf; use crate::arch::Arch; @@ -16,10 +16,12 @@ pub use qemu::*; /// All the configurable fields within a scheme. #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Scheme { + // The user is not allowed to set this field. However, + // the manifest loader set this and all actions such + // as runnning, testing, and building will use this field. + pub work_dir: Option, #[serde(default)] pub supported_archs: Vec, - #[serde(default)] - pub vars: Vars, pub boot: Option, pub grub: Option, pub qemu: Option, @@ -29,12 +31,12 @@ pub struct Scheme { } macro_rules! inherit_optional { - ($from: ident, $to:ident, .$field:ident) => { - if $from.$field.is_some() { - if let Some($field) = &mut $to.$field { - $field.inherit($from.$field.as_ref().unwrap()); - } else { - $to.$field = $from.$field.clone(); + ($from:ident, $to:ident, .$field:ident) => { + if $to.$field.is_none() { + $to.$field = $from.$field.clone(); + } else { + if let Some($field) = &$from.$field { + $to.$field.as_mut().unwrap().inherit($field); } } }; @@ -44,8 +46,8 @@ use inherit_optional; impl Scheme { pub fn empty() -> Self { Scheme { + work_dir: None, supported_archs: vec![], - vars: vec![], boot: None, grub: None, qemu: None, @@ -57,17 +59,27 @@ impl Scheme { pub fn inherit(&mut self, from: &Self) { // Supported archs are not inherited - - self.vars = { - let mut vars = from.vars.clone(); - vars.extend(self.vars.clone()); - vars - }; inherit_optional!(from, self, .boot); inherit_optional!(from, self, .grub); - inherit_optional!(from, self, .qemu); inherit_optional!(from, self, .build); inherit_optional!(from, self, .run); inherit_optional!(from, self, .test); + // The inheritance of `work_dir` depends on `qemu`, so + // here is a special treatment. + if let Some(qemu) = &mut self.qemu { + if let Some(from_qemu) = &from.qemu { + if qemu.args.is_none() { + qemu.args = from_qemu.args.clone(); + self.work_dir = from.work_dir.clone(); + } + if qemu.path.is_none() { + qemu.path = from_qemu.path.clone(); + self.work_dir = from.work_dir.clone(); + } + } + } else { + self.qemu = from.qemu.clone(); + self.work_dir = from.work_dir.clone(); + } } } diff --git a/osdk/src/config/scheme/qemu.rs b/osdk/src/config/scheme/qemu.rs index 3ae20e156..7a510268f 100644 --- a/osdk/src/config/scheme/qemu.rs +++ b/osdk/src/config/scheme/qemu.rs @@ -6,10 +6,7 @@ use std::{path::PathBuf, process}; use crate::{ arch::{get_default_arch, Arch}, - config::{ - eval::{eval, Vars}, - unix_args::{apply_kv_array, get_key, split_to_kv_array}, - }, + config::unix_args::{apply_kv_array, get_key, split_to_kv_array}, error::Errno, error_msg, }; @@ -55,26 +52,17 @@ impl Qemu { impl QemuScheme { pub fn inherit(&mut self, from: &Self) { - if from.args.is_some() { + if self.args.is_none() { self.args = from.args.clone(); } - if from.path.is_some() { + if self.path.is_none() { self.path = from.path.clone(); } } - pub fn finalize(self, vars: &Vars, arch: Arch) -> Qemu { + pub fn finalize(self, arch: Arch) -> Qemu { Qemu { - args: self - .args - .map(|args| match eval(vars, &args) { - Ok(v) => v, - Err(e) => { - error_msg!("Failed to evaluate qemu args: {:#?}", e); - process::exit(Errno::ParseMetadata as _); - } - }) - .unwrap_or_default(), + args: self.args.unwrap_or_default(), path: self.path.unwrap_or(PathBuf::from(arch.system_qemu())), } } diff --git a/osdk/src/config/test/OSDK.toml.full b/osdk/src/config/test/OSDK.toml.full index 57337c389..ffafe94f6 100644 --- a/osdk/src/config/test/OSDK.toml.full +++ b/osdk/src/config/test/OSDK.toml.full @@ -1,20 +1,11 @@ project_type = "kernel" supported_archs = ["x86_64"] -vars = [ - ["SMP", "1"], - ["MEM", "2G"], - ["EXT2_IMG", "$OSDK_CWD/regression/build/ext2.img"], - ["EXFAT_IMG", "$OSDK_CWD/regression/build/exfat.img"], -] [boot] method = "grub-rescue-iso" [run] -vars = [ - ["OVMF_PATH", "/usr/share/OVMF"], -] boot.kcmd_args = [ "SHELL=/bin/sh", "LOGNAME=root", @@ -42,9 +33,6 @@ args = """\ [scheme."iommu"] supported_archs = ["x86_64"] -vars = [ - ["IOMMU_DEV_EXTRA", ",iommu_platform=on,ats=on"], -] qemu.args = """\ -device intel-iommu,intremap=on,device-iotlb=on \ -device ioh3420,id=pcie.0,chassis=1\ @@ -53,10 +41,6 @@ qemu.args = """\ [scheme."tdx"] supported_archs = ["x86_64"] build.features = ["intel_tdx"] -vars = [ - ["MEM", "8G"], - ["OVMF_PATH", "~/tdx-tools/ovmf"], -] boot.method = "grub-qcow2" grub.mkrescue_path = "/tmp/osdk_test_file" grub.protocol = "linux" diff --git a/osdk/src/config/test/mod.rs b/osdk/src/config/test/mod.rs index 06750f2be..dc5c48c6b 100644 --- a/osdk/src/config/test/mod.rs +++ b/osdk/src/config/test/mod.rs @@ -13,8 +13,6 @@ fn deserialize_toml_manifest() { let toml_manifest: manifest::TomlManifest = toml::from_str(content).unwrap(); let type_ = toml_manifest.project_type.unwrap(); assert!(type_ == manifest::ProjectType::Kernel); - let vars = toml_manifest.default_scheme.vars; - assert!(vars.contains(&("SMP".to_owned(), "1".to_owned()))); } #[test] diff --git a/tools/qemu_args.sh b/tools/qemu_args.sh index 7063157f9..c519e6ec6 100755 --- a/tools/qemu_args.sh +++ b/tools/qemu_args.sh @@ -2,15 +2,19 @@ # SPDX-License-Identifier: MPL-2.0 +# This script is used to generate QEMU arguments for OSDK. +# The positional argument $1 is the scheme. +# A switch "-ovmf" can be passed as an argument to enable OVMF. + RAND_PORT_NUM1=$(shuf -i 1024-65535 -n 1) RAND_PORT_NUM2=$(shuf -i 1024-65535 -n 1) -echo "Forwarded QEMU guest port: $RAND_PORT_NUM1->22; $RAND_PORT_NUM2->8080" 1>&2 +echo "[$1] Forwarded QEMU guest port: $RAND_PORT_NUM1->22; $RAND_PORT_NUM2->8080" 1>&2 COMMON_QEMU_ARGS="\ -cpu Icelake-Server,+x2apic \ - -smp $SMP \ - -m $MEM \ + -smp ${SMP:-1} \ + -m ${MEM:-2G} \ --no-reboot \ -nographic \ -display none \ @@ -20,10 +24,18 @@ COMMON_QEMU_ARGS="\ -netdev user,id=net01,hostfwd=tcp::$RAND_PORT_NUM1-:22,hostfwd=tcp::$RAND_PORT_NUM2-:8080 \ -object filter-dump,id=filter0,netdev=net01,file=virtio-net.pcap \ -device isa-debug-exit,iobase=0xf4,iosize=0x04 \ - -drive if=none,format=raw,id=x0,file=$EXT2_IMG \ - -drive if=none,format=raw,id=x1,file=$EXFAT_IMG \ + -drive if=none,format=raw,id=x0,file=./regression/build/ext2.img \ + -drive if=none,format=raw,id=x1,file=./regression/build/exfat.img \ " +if [ "$1" = "iommu" ]; then + IOMMU_DEV_EXTRA=",iommu_platform=on,ats=on" + IOMMU_EXTRA_ARGS="\ + -device intel-iommu,intremap=on,device-iotlb=on \ + -device ioh3420,id=pcie.0,chassis=1\ + " +fi + QEMU_ARGS="\ $COMMON_QEMU_ARGS \ -machine q35,kernel-irqchip=split \ @@ -49,13 +61,14 @@ MICROVM_QEMU_ARGS="\ -device virtconsole,chardev=mux \ " -if [ "$MICROVM" ]; then +if [ "$1" = "microvm" ]; then QEMU_ARGS=$MICROVM_QEMU_ARGS echo $QEMU_ARGS exit 0 fi -if [ "$OVMF_PATH" ]; then +if [ "$1" = "-ovmf" ] || [ "$2" = "-ovmf" ]; then + OVMF_PATH="/usr/share/OVMF" QEMU_ARGS="${QEMU_ARGS}\ -drive if=pflash,format=raw,unit=0,readonly=on,file=$OVMF_PATH/OVMF_CODE.fd \ -drive if=pflash,format=raw,unit=1,file=$OVMF_PATH/OVMF_VARS.fd \