x86_64: add SMBIOS serial number option

Allows adding an optional serial number to the SMBIOS table.

BUG=b:249382713
TEST=crosvm run --smbios serial-number=abcdef ...

Change-Id: I00a00defb6904dbfa8ae38910b887e0a464787e3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4761847
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Mike Gerow <gerow@google.com>
This commit is contained in:
Daniel Verkamp 2023-08-08 13:04:59 -07:00 committed by crosvm LUCI
parent 2422c65f3d
commit 54f80c60f1
2 changed files with 11 additions and 0 deletions

View file

@ -1368,6 +1368,9 @@ pub struct SmbiosOptions {
/// System product name.
pub product_name: Option<String>,
/// System serial number (free-form string).
pub serial_number: Option<String>,
/// Additional OEM strings to add to SMBIOS table.
#[serde(default)]
pub oem_strings: Vec<String>,

View file

@ -237,6 +237,11 @@ pub fn setup_smbios(mem: &GuestMemory, options: &SmbiosOptions) -> Result<()> {
handle,
manufacturer: 1, // First string written in this section
product_name: 2, // Second string written in this section
serial_number: if options.serial_number.is_some() {
3 // Third string written in this section
} else {
0 // Serial number not specified
},
..Default::default()
};
curptr = write_and_incr(mem, smbios_sysinfo, curptr)?;
@ -256,6 +261,9 @@ pub fn setup_smbios(mem: &GuestMemory, options: &SmbiosOptions) -> Result<()> {
.unwrap_or(DEFAULT_SMBIOS_PRODUCT_NAME),
curptr,
)?;
if let Some(serial_number) = options.serial_number.as_deref() {
curptr = write_string(mem, serial_number, curptr)?;
}
curptr = write_and_incr(mem, 0u8, curptr)?;
}