-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
- Loading branch information
1 parent
0ade197
commit 379230b
Showing
5 changed files
with
640 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::fs; | ||
use std::mem::size_of; | ||
use std::slice::from_raw_parts_mut; | ||
|
||
use crate::error::Contextual; | ||
use crate::{BuildUpdateCmdArgs, Ovmf, UserspaceVmm, Vmsa}; | ||
|
||
pub fn cmd(args: BuildUpdateCmdArgs) -> super::Result<()> { | ||
let mut vmsa = Vmsa::default(); | ||
vmsa.init_amd64(); | ||
vmsa.init_kvm(); | ||
match args.userspace { | ||
UserspaceVmm::Qemu => vmsa.init_qemu(args.cpu), | ||
UserspaceVmm::Krun => vmsa.init_krun(args.cpu), | ||
}; | ||
|
||
let family: u64 = args.family.unwrap_or(0); | ||
let model: u64 = args.model.unwrap_or(0); | ||
let stepping: u64 = args.stepping.unwrap_or(0); | ||
|
||
if family > 0 || model > 0 || stepping > 0 { | ||
vmsa.cpu_sku(family, model, stepping); | ||
} | ||
|
||
if let Some(fw) = args.firmware { | ||
let mut ovmf = Ovmf::default(); | ||
ovmf.load(fw) | ||
.context("error loading firmware blob entries in OVMF")?; | ||
|
||
if args.userspace == UserspaceVmm::Qemu && args.cpu != 0 { | ||
let ovmf_reset_addr = ovmf | ||
.reset_addr() | ||
.context("error getting OVMF reset address")?; | ||
|
||
vmsa.reset_addr(ovmf_reset_addr); | ||
} | ||
} | ||
|
||
let vmsa: &mut [u8] = | ||
unsafe { from_raw_parts_mut(&vmsa as *const Vmsa as *mut u8, size_of::<Vmsa>()) }; | ||
let buf: &mut [u8] = &mut [0; 4096]; | ||
buf[..size_of::<Vmsa>()].copy_from_slice(vmsa); | ||
|
||
fs::write(args.filename, buf).context("could not write VMSA buffer")?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.