2024-12-14 18:16:10 -05:00
|
|
|
use std::sync::Arc;
|
2024-01-10 10:08:39 -08:00
|
|
|
use std::{env, process};
|
2024-04-22 12:48:45 -07:00
|
|
|
use tokio::fs;
|
2024-06-21 10:38:19 -07:00
|
|
|
use uuid::Uuid;
|
2024-01-30 17:42:55 -08:00
|
|
|
use xenclient::error::Result;
|
2024-12-14 18:16:10 -05:00
|
|
|
use xenclient::tx::channel::ChannelDeviceConfig;
|
|
|
|
use xenclient::{config::DomainConfig, XenClient};
|
|
|
|
use xenplatform::domain::{
|
|
|
|
KernelFormat, PlatformDomainConfig, PlatformKernelConfig, PlatformOptions,
|
|
|
|
PlatformResourcesConfig,
|
|
|
|
};
|
|
|
|
use xenplatform::RuntimePlatformType;
|
2024-06-20 19:42:45 -07:00
|
|
|
|
2024-02-23 04:37:53 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2024-01-11 12:21:33 -08:00
|
|
|
env_logger::init();
|
|
|
|
|
2024-01-10 10:08:39 -08:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2024-01-16 17:57:19 -08:00
|
|
|
if args.len() != 3 {
|
|
|
|
println!("usage: boot <kernel-image> <initrd>");
|
2024-01-10 10:08:39 -08:00
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
let kernel_image_path = args.get(1).expect("argument not specified");
|
2024-01-16 17:57:19 -08:00
|
|
|
let initrd_path = args.get(2).expect("argument not specified");
|
2024-12-14 18:16:10 -05:00
|
|
|
let client = XenClient::new().await?;
|
|
|
|
|
2024-12-14 18:22:37 -05:00
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
let runtime_platform = RuntimePlatformType::Pv;
|
|
|
|
#[cfg(not(target_arch = "x86_64"))]
|
|
|
|
let runtime_platform = RuntimePlatformType::Unsupported;
|
|
|
|
|
2024-12-14 18:16:10 -05:00
|
|
|
let mut config = DomainConfig::new();
|
|
|
|
config.platform(PlatformDomainConfig {
|
|
|
|
uuid: Uuid::new_v4(),
|
2024-12-14 18:22:37 -05:00
|
|
|
platform: runtime_platform,
|
2024-12-14 18:16:10 -05:00
|
|
|
kernel: PlatformKernelConfig {
|
|
|
|
data: Arc::new(fs::read(&kernel_image_path).await?),
|
|
|
|
format: KernelFormat::ElfCompressed,
|
2024-06-21 10:38:19 -07:00
|
|
|
cmdline: "earlyprintk=xen earlycon=xen console=hvc0 init=/init".to_string(),
|
2024-12-14 18:16:10 -05:00
|
|
|
initrd: Some(Arc::new(fs::read(&initrd_path).await?)),
|
|
|
|
},
|
|
|
|
resources: PlatformResourcesConfig {
|
|
|
|
max_vcpus: 1,
|
|
|
|
assigned_vcpus: 1,
|
|
|
|
max_memory_mb: 512,
|
|
|
|
assigned_memory_mb: 512,
|
2024-06-21 10:38:19 -07:00
|
|
|
},
|
2024-12-14 18:16:10 -05:00
|
|
|
options: PlatformOptions { iommu: true },
|
|
|
|
});
|
|
|
|
config.name("xenclient-test");
|
|
|
|
let mut channel = ChannelDeviceConfig::new();
|
|
|
|
channel.default_console().backend_initialized();
|
|
|
|
config.add_channel(channel);
|
|
|
|
let created = client.create(config).await?;
|
|
|
|
println!("created domain {}", created.platform.domid);
|
2024-01-09 22:39:32 -08:00
|
|
|
Ok(())
|
|
|
|
}
|