🆕 Put reims-vgpu-video's kexts in the OpenCore image

This commit is contained in:
Anees Iqbal committed 2026-10-26 14:06:18 +02:00
1 parent c717e69f0a
commit 381f913237
15 files changed
+510 -55

No files matched your search

+24 -13
View File
@@ -85,8 +85,9 @@ What's in the image, and why:
has it ask for the one arm64 guests use (245), and patches what the driver and its Metal plugin
hardcode, so Metal offers the GPU families GPU-accelerated Chrome needs, and D32S8
depth/stencil textures. `--no-kexts` leaves them out, and the boot argument `-reimsvgpuoff`
turns the kext off. The apv-arm64-port kexts load after these, on macOS 26.4 and later
([below](#apv-arm64-port)). There are no others: QEMU's `isa-applesmc` is the SMC.
turns the kext off. The apv-arm64-port kexts load after these, on macOS 26.4 and later, and
reims-vgpu-video's after those, on macOS 26.7 ([below](#the-kexts)). There are no others:
QEMU's `isa-applesmc` is the SMC.
- **The drivers a VM boots with**: OpenRuntime, OpenHfsPlus (recovery images and installers are
HFS+), OpenPartitionDxe (for older recovery images) and ResetNvramEntry.
- **No boot picker**: OpenCore boots the default entry, the disk macOS last chose as its startup
@@ -176,12 +177,28 @@ made) or, for `list`, the versions, or `{"event":"error","message":"…"}`.
reims-util --json online-installer tahoe -o ~/vms/mac
```
## The ReimsVgpu kext
## The kexts
`kext/` holds ReimsVgpu.kext's source. A kext builds on a Mac alone, while reims-util builds
anywhere, so the built kext is in the repository too, at `kext/ReimsVgpu.kext`, and that's the one
reims-util puts in its images. After changing the source, rebuild it on a Mac with Xcode, and
commit it with the change:
`kext/` holds the kexts reims-util puts in its images, built: a kext builds on a Mac alone, while
reims-util builds anywhere. Every image carries them by default, each set after the one before it:
- **ReimsVgpu.kext**, with Lilu, on macOS 26 ([above](#opencore-and-ovmf)), built from its
source in `kext/`.
- **The apv-arm64-port kexts**, on macOS 26.4 and later, which drive reims-vgpu's GPU with kexts
of their own; older macOS 26 builds keep macOS's own driver with ReimsVgpu.kext.
`--no-apv-arm64-port` makes an image without them.
- **reims-vgpu-video's kexts**, on macOS 26.7, which drive the paravirtualized VideoToolbox
(106b:1a03) and M2 scaler (106b:1a0b) devices, when the VM's QEMU serves them:
AppleVideoToolboxParavirtualization.kext and AppleM2ScalerParavirtDriver.kext, Apple's arm64
guest drivers ported to x86-64, and VtWaitPatch.kext, a Lilu plugin that keeps the x86-64
VideoToolbox's waits for the host's replies from expiring at once on macOS 26.7.1 (25G241). The
two drivers link against apv-arm64-port's IOSurface mapper, so an image carries them only with
the apv-arm64-port kexts, from Darwin 25.6.0 on; a driver whose device the VM lacks loads and
matches nothing. `--no-video` makes an image without them. The two drivers are Apple's code,
ported, and are not for redistribution.
After changing ReimsVgpu.kext's source, rebuild it on a Mac with Xcode, and commit the built kext
with the change:
```sh
cd kext
@@ -194,12 +211,6 @@ make LILU=path/to/Lilu.kext KERNEL_SDK=path/to/MacKernelSDK
source builds the same bytes. `make` also writes `kext/sources.sha256`, what the kext was built
from, and `cargo test` fails when the source no longer matches it.
## apv-arm64-port
apv-arm64-port drives reims-vgpu's GPU on macOS 26.4 and later with kexts of its own, which every
image carries by default; older macOS 26 builds keep macOS's own driver with ReimsVgpu.kext.
`--no-apv-arm64-port` makes an image without them.
## License
reims-util is licensed under GPL-2.0-or-later OR LGPL-3.0-or-later; see [LICENSE](LICENSE). The
+36 -15
View File
@@ -1,8 +1,10 @@
//! Embeds the apv-arm64-port kexts, the seven bundles in kext/ that `SET` names, so the image
//! carries them as it carries ReimsVgpu.kext (src/opencore/apv_arm64_port.rs). Writes
//! `$OUT_DIR/apv_arm64_port.rs`: each file of each of them, by its path under kext/, with its
//! bytes, dotfiles left out. Nothing else in kext/ is read. With none of the seven there, nothing
//! is embedded; with only some, the build fails, as the seven load as one.
//! carries them as it carries ReimsVgpu.kext (src/opencore/apv_arm64_port.rs), and
//! reims-vgpu-video's kexts, the three that `VIDEO_SET` names, the same way
//! (src/opencore/video.rs). Writes `$OUT_DIR/apv_arm64_port.rs` and `$OUT_DIR/video.rs`: each
//! file of each bundle of the set, by its path under kext/, with its bytes, dotfiles left out.
//! Nothing else in kext/ is read. With none of a set there, nothing of it is embedded; with only
//! some, the build fails, as each set loads as one.
//!
//! The bundles are built without a path of the machine they were built on: the build fails when
//! an embedded file holds `/Users/`, as an unstripped kext's debug map does.
@@ -11,6 +13,7 @@ use std::fmt::Write as _;
use std::path::{Path, PathBuf};
include!("src/opencore/apv_arm64_port_set.rs");
include!("src/opencore/video_set.rs");
fn main() {
if let Err(e) = run() {
@@ -24,33 +27,53 @@ fn run() -> Result<(), String> {
let dir = root.join("kext");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/opencore/apv_arm64_port_set.rs");
println!("cargo:rerun-if-changed=src/opencore/video_set.rs");
println!("cargo:rerun-if-changed=kext");
let out = PathBuf::from(std::env::var("OUT_DIR").map_err(|e| e.to_string())?);
embed(
&dir,
&SET,
"apv-arm64-port",
"all seven",
&out.join("apv_arm64_port.rs"),
)?;
embed(
&dir,
&VIDEO_SET,
"video",
"all three",
&out.join("video.rs"),
)
}
let present: Vec<&str> = SET
/// Writes `to`, the files of the bundles `set` names in `dir`: all of them or none, `what` naming
/// them in errors, and `whole` how many make the set.
fn embed(dir: &Path, set: &[&str], what: &str, whole: &str, to: &Path) -> Result<(), String> {
let present: Vec<&str> = set
.iter()
.copied()
.filter(|b| dir.join(b).exists())
.collect();
if !present.is_empty() && present.len() != SET.len() {
let missing: Vec<&str> = SET
if !present.is_empty() && present.len() != set.len() {
let missing: Vec<&str> = set
.iter()
.copied()
.filter(|b| !present.contains(b))
.collect();
return Err(format!(
"partial apv-arm64-port set in kext/, without {}: deploy all seven",
"partial {what} set in kext/, without {}: deploy {whole}",
missing.join(", ")
));
}
let mut files = Vec::new();
for b in &present {
walk(&dir, Path::new(b), &mut files)?;
walk(dir, Path::new(b), &mut files)?;
}
files.sort();
let mut code = String::from(
"/// Each file of the apv-arm64-port kexts, by its path under kext/ (build.rs).\n\
pub static FILES: &[(&str, &[u8])] = &[\n",
let mut code = format!(
"/// Each file of the {what} kexts, by its path under kext/ (build.rs).\n\
pub static FILES: &[(&str, &[u8])] = &[\n"
);
for f in &files {
let path = dir.join(f);
@@ -68,9 +91,7 @@ fn run() -> Result<(), String> {
let _ = writeln!(code, " ({f:?}, include_bytes!({abs:?})),");
}
code.push_str("];\n");
let out = PathBuf::from(std::env::var("OUT_DIR").map_err(|e| e.to_string())?);
std::fs::write(out.join("apv_arm64_port.rs"), code)
.map_err(|e| format!("write apv_arm64_port.rs: {e}"))
std::fs::write(to, code).map_err(|e| format!("write {}: {e}", to.display()))
}
fn read_dir(dir: &Path) -> Result<Vec<std::fs::DirEntry>, String> {
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>23A344017</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>AppleM2ScalerParavirtDriver</string>
<key>CFBundleGetInfoString</key>
<string>9.0.5, Copyright Apple Inc. 2023</string>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleM2ScalerParavirtDriver</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Apple M2 Scaler Paravirtualized Driver</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>aapl</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string></string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>26.7</string>
<key>DTSDKBuild</key>
<string>25G221</string>
<key>DTSDKName</key>
<string>macosx26.7.internal</string>
<key>DTXcode</key>
<string>2630</string>
<key>DTXcodeBuild</key>
<string>17E6107</string>
<key>IOKitPersonalities</key>
<dict>
<key>AppleM2ScalerParavirtDriver</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleM2ScalerParavirtDriver</string>
<key>IOClass</key>
<string>AppleM2ScalerCSCDriver</string>
<key>IOProviderClass</key>
<string>AppleVirtIOTransport</string>
<key>IOVirtIOPrimaryMatch</key>
<string>0x1a0b106b</string>
</dict>
<key>AppleM2ScalerParavirtDriver Transport</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleVirtIO</string>
<key>IOClass</key>
<string>AppleVirtIOPCITransport</string>
<key>IOPCIPrimaryMatch</key>
<string>0x1a0b106b</string>
<key>IOProviderClass</key>
<string>IOPCIDevice</string>
</dict>
</dict>
<key>LSMinimumSystemVersion</key>
<string>26.7</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2023 Apple Inc. All rights reserved.</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.driver.AppleVirtIO</key>
<string>146.40.2</string>
<key>com.apple.iokit.AppleParavirtIOSurface</key>
<string>1.0</string>
<key>com.apple.iokit.IOPCIFamily</key>
<string>1.0.0b1</string>
<key>com.apple.iokit.IOSurface</key>
<string>52.7.0</string>
<key>com.apple.kpi.bsd</key>
<string>8.4.1</string>
<key>com.apple.kpi.iokit</key>
<string>8.4.1</string>
<key>com.apple.kpi.libkern</key>
<string>8.4.1</string>
<key>com.apple.kpi.mach</key>
<string>8.4.1</string>
<key>com.apple.kpi.private</key>
<string>8.0.0b1</string>
<key>com.apple.kpi.unsupported</key>
<string>8.0</string>
</dict>
</dict>
</plist>
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>23A344017</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>AppleVideoToolboxParavirtualization</string>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleVideoToolboxParavirtualization</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>com.apple.driver.AppleVideoToolboxParavirtualization</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>15.0.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>15.0.0</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string></string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>26.7</string>
<key>DTSDKBuild</key>
<string>25G221</string>
<key>DTSDKName</key>
<string>macosx26.7.internal</string>
<key>DTXcode</key>
<string>2630</string>
<key>DTXcodeBuild</key>
<string>17E6107</string>
<key>IOKitPersonalities</key>
<dict>
<key>AppleVideoToolboxParavirtualization</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleVideoToolboxParavirtualization</string>
<key>IOClass</key>
<string>AppleVideoToolboxParavirtualizationDriver</string>
<key>IOProviderClass</key>
<string>AppleVirtIOTransport</string>
<key>IOUserClientClass</key>
<string>AppleVideoToolboxParavirtualizationUserClient</string>
<key>IOVirtIOPrimaryMatch</key>
<string>0x1a03106b</string>
</dict>
<key>AppleVideoToolboxParavirtualization Transport</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleVirtIO</string>
<key>IOClass</key>
<string>AppleVirtIOPCITransport</string>
<key>IOPCIPrimaryMatch</key>
<string>0x1a03106b</string>
<key>IOProviderClass</key>
<string>IOPCIDevice</string>
</dict>
</dict>
<key>LSMinimumSystemVersion</key>
<string>26.7</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2022-2025 Apple Inc. All rights reserved.</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.driver.AppleVirtIO</key>
<string>146.40.2</string>
<key>com.apple.iokit.AppleParavirtIOSurface</key>
<string>1.0</string>
<key>com.apple.iokit.IOSurface</key>
<string>302.9</string>
<key>com.apple.kpi.iokit</key>
<string>15.5</string>
<key>com.apple.kpi.libkern</key>
<string>15.5</string>
</dict>
</dict>
</plist>
+53
View File
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>VtWaitPatch</string>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.VtWaitPatch</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>VtWaitPatch</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<key>CFBundleVersion</key>
<string>0.1.0</string>
<key>IOKitPersonalities</key>
<dict>
<key>VtWaitPatch</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.VtWaitPatch</string>
<key>IOClass</key>
<string>VtWaitPatch</string>
<key>IOMatchCategory</key>
<string>VtWaitPatch</string>
<key>IOProviderClass</key>
<string>IOResources</string>
<key>IOResourceMatch</key>
<string>IOKit</string>
</dict>
</dict>
<key>OSBundleLibraries</key>
<dict>
<key>as.vit9696.Lilu</key>
<string>1.7.2</string>
<key>com.apple.kpi.bsd</key>
<string>12.0.0</string>
<key>com.apple.kpi.iokit</key>
<string>12.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>12.0.0</string>
<key>com.apple.kpi.mach</key>
<string>12.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Root</string>
</dict>
</plist>
Binary file not shown.
+8 -3
View File
@@ -108,13 +108,17 @@ pub struct OpencoreArgs {
/// Show OpenCore's boot picker at every boot (by default OpenCore boots the default entry)
#[arg(long)]
pub show_picker: bool,
/// Leave out Lilu, ReimsVgpu.kext and the apv-arm64-port kexts, so macOS 26 drives
/// reims-vgpu's GPU with its driver as it is
/// Leave out Lilu, ReimsVgpu.kext, the apv-arm64-port kexts and reims-vgpu-video's, so
/// macOS 26 drives reims-vgpu's GPU with its driver as it is
#[arg(long)]
pub no_kexts: bool,
/// Leave out the apv-arm64-port kexts
/// Leave out the apv-arm64-port kexts, and with them reims-vgpu-video's, which link against
/// their mapper
#[arg(long)]
pub no_apv_arm64_port: bool,
/// Leave out reims-vgpu-video's kexts, the VideoToolbox and scaler devices' guest drivers
#[arg(long)]
pub no_video: bool,
/// Write no OVMF files
#[arg(long)]
pub no_ovmf: bool,
@@ -353,6 +357,7 @@ pub fn opencore_options(a: &OpencoreArgs) -> Result<opencore::Options> {
kexts: !a.no_kexts,
},
apv_arm64_port: !a.no_apv_arm64_port,
video: !a.no_video,
ovmf_dir,
})
}
+20 -9
View File
@@ -26,6 +26,17 @@ pub struct Kext<'a> {
/// after those of the set its `OSBundleLibraries` names. Empty when `files` holds no kext; files
/// beside the bundles are left out, and anything short of the exact set refused.
pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result<Vec<Kext<'a>>> {
set_of(files, &SET, "apv-arm64-port", "all seven")
}
/// The kexts `names` in `files`, taken as `set` takes apv-arm64-port's: `what` names them in its
/// errors, and `whole` says how many make the set. video.rs takes reims-vgpu-video's kexts so.
pub(super) fn set_of<'a>(
files: &[(&'a str, &'a [u8])],
names: &[&str],
what: &str,
whole: &str,
) -> Result<Vec<Kext<'a>>> {
let mut bundles: BTreeMap<&str, Vec<(&str, &[u8])>> = BTreeMap::new();
for &(path, data) in files {
let Some((bundle, rel)) = path.split_once('/') else {
@@ -34,10 +45,10 @@ pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result<Vec<Kext<'a>>> {
if !bundle.ends_with(".kext") || path.split('/').any(|c| c.starts_with('.')) {
continue;
}
if !SET.contains(&bundle) {
if !names.contains(&bundle) {
bail!(
"kext/{bundle} is not one of the apv-arm64-port kexts ({})",
SET.join(", ")
"kext/{bundle} is not one of the {what} kexts ({})",
names.join(", ")
);
}
bundles.entry(bundle).or_default().push((rel, data));
@@ -45,14 +56,14 @@ pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result<Vec<Kext<'a>>> {
if bundles.is_empty() {
return Ok(Vec::new());
}
let missing: Vec<&str> = SET
let missing: Vec<&str> = names
.iter()
.copied()
.filter(|b| !bundles.contains_key(b))
.collect();
if !missing.is_empty() {
bail!(
"partial apv-arm64-port set in kext/, without {}: deploy all seven",
"partial {what} set in kext/, without {}: deploy {whole}",
missing.join(", ")
);
}
@@ -60,7 +71,7 @@ pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result<Vec<Kext<'a>>> {
for (bundle, files) in bundles {
kexts.push(kext(bundle, files)?);
}
order(kexts)
order(kexts, what)
}
fn kext<'a>(bundle: &'a str, files: Vec<(&'a str, &'a [u8])>) -> Result<Kext<'a>> {
@@ -96,7 +107,7 @@ fn kext<'a>(bundle: &'a str, files: Vec<(&'a str, &'a [u8])>) -> Result<Kext<'a>
}
/// Orders the kexts so each comes after the ones it links against, and otherwise by name.
fn order(mut left: Vec<Kext<'_>>) -> Result<Vec<Kext<'_>>> {
fn order<'a>(mut left: Vec<Kext<'a>>, what: &str) -> Result<Vec<Kext<'a>>> {
let ids: BTreeSet<String> = left.iter().map(|k| k.identifier.clone()).collect();
let mut placed = BTreeSet::new();
let mut out = Vec::new();
@@ -109,7 +120,7 @@ fn order(mut left: Vec<Kext<'_>>) -> Result<Vec<Kext<'_>>> {
let Some(i) = ready else {
let names: Vec<&str> = left.iter().map(|k| k.bundle).collect();
bail!(
"the apv-arm64-port kexts {} link against each other in a cycle",
"the {what} kexts {} link against each other in a cycle",
names.join(", ")
);
};
@@ -125,7 +136,7 @@ pub(crate) mod tests {
use super::*;
/// A bundle's Info.plist: its identifier, executable and libraries.
fn info(id: &str, executable: Option<&str>, libraries: &[&str]) -> Vec<u8> {
pub(crate) fn info(id: &str, executable: Option<&str>, libraries: &[&str]) -> Vec<u8> {
let mut d = plist::Dictionary::new();
d.insert("CFBundleIdentifier".into(), id.into());
if let Some(e) = executable {
+44 -9
View File
@@ -14,8 +14,8 @@
//! - on macOS 26, two kexts: Lilu, and its plugin ReimsVgpu (kext/), which has macOS's own driver
//! for reims-vgpu's GPU negotiate the interface version arm64 guests use, and patches what the
//! x86-64 driver and its Metal plugin hardcode; after them, the seven apv-arm64-port kexts
//! (apv_arm64_port.rs), on macOS 26.4 and later alone; no others, as QEMU's `isa-applesmc` is
//! the SMC;
//! (apv_arm64_port.rs), on macOS 26.4 and later alone; after those, reims-vgpu-video's three
//! (video.rs), on macOS 26.7 alone; no others, as QEMU's `isa-applesmc` is the SMC;
//! - one ACPI table, the `EC` and `USBX` devices macOS looks for (acpi.rs);
//! - CPUID leaf 1 reported as a Skylake-SP (family 6, model 85, stepping 4), a CPU every x86-64
//! macOS from 10.13 to 26 knows, whatever `-cpu` model the VM has;
@@ -72,6 +72,10 @@ const KEXT_MAX_KERNEL: &str = "25.99.99";
/// The apv-arm64-port kexts load from macOS 26.4 on: on older builds, ReimsVgpu has macOS's own
/// driver take the GPU. Where the set refuses at boot, it leaves the GPU to that driver too.
const PORT_MIN_KERNEL: &str = "25.4.0";
/// reims-vgpu-video's kexts load on macOS 26.7 (Darwin 25.6) alone, the release whose kernel
/// collections their links were checked against (its docs/kext-port.md), within the
/// apv-arm64-port kexts' bounds, as two of them link against its mapper.
const VIDEO_MIN_KERNEL: &str = "25.6.0";
/// Arguments for every boot: kernel symbols in panic logs, and no panics on a TLB shootdown or a
/// timeout a vCPU took because the host descheduled it.
@@ -100,8 +104,13 @@ pub struct Options {
}
/// The config.plist for `o`, from the release's `sample`. With `o.kexts`, `port`
/// (apv_arm64_port.rs) loads after Lilu and ReimsVgpu.
pub fn make(sample: &[u8], o: &Options, port: &[PortKext<'_>]) -> Result<Vec<u8>> {
/// (apv_arm64_port.rs) loads after Lilu and ReimsVgpu, and `video` (video.rs) after `port`.
pub fn make(
sample: &[u8],
o: &Options,
port: &[PortKext<'_>],
video: &[PortKext<'_>],
) -> Result<Vec<u8>> {
let mut root: Value = plist::from_bytes(sample).context("read Sample.plist")?;
let c = root
.as_dictionary_mut()
@@ -146,7 +155,7 @@ pub fn make(sample: &[u8], o: &Options, port: &[PortKext<'_>]) -> Result<Vec<u8>
)?;
let kexts = if o.kexts {
kernel_add(&template(c, &["Kernel", "Add"])?, port)
kernel_add(&template(c, &["Kernel", "Add"])?, port, video)
} else {
Vec::new()
};
@@ -312,8 +321,8 @@ pub fn make(sample: &[u8], o: &Options, port: &[PortKext<'_>]) -> Result<Vec<u8>
}
/// Kernel > Add's entries, made from the sample's first: Lilu and ReimsVgpu for macOS 26, then
/// `port` for macOS 26.4 and later.
fn kernel_add(template: &Dictionary, port: &[PortKext<'_>]) -> Vec<Value> {
/// `port` for macOS 26.4 and later, then `video` for macOS 26.7.
fn kernel_add(template: &Dictionary, port: &[PortKext<'_>], video: &[PortKext<'_>]) -> Vec<Value> {
let mut add = vec![
(
LILU.bundle,
@@ -336,6 +345,14 @@ fn kernel_add(template: &Dictionary, port: &[PortKext<'_>]) -> Vec<Value> {
format!("apv-arm64-port's {}", k.bundle.trim_end_matches(".kext")),
));
}
for k in video {
add.push((
k.bundle,
k.executable.as_deref(),
VIDEO_MIN_KERNEL,
format!("reims-vgpu-video's {}", k.bundle.trim_end_matches(".kext")),
));
}
add.into_iter()
.map(|(bundle, executable, min_kernel, comment)| {
let mut e = template.clone();
@@ -402,6 +419,7 @@ fn unhex(s: &str) -> Result<Vec<u8>> {
mod tests {
use super::*;
use crate::opencore::apv_arm64_port as port;
use crate::opencore::video;
fn fields(v: &Value, keys: &[&str]) -> Vec<String> {
let d = v.as_dictionary().unwrap();
@@ -424,7 +442,7 @@ mod tests {
];
// With none of the set in kext/, Lilu and ReimsVgpu alone.
let today = kernel_add(&template, &port::set(&[]).unwrap());
let today = kernel_add(&template, &port::set(&[]).unwrap(), &[]);
let want = |b: &str, x: &str| {
[b, x, KEXT_MIN_KERNEL, KEXT_MAX_KERNEL, "x86_64"].map(str::to_string)
};
@@ -440,7 +458,7 @@ mod tests {
// no path.
let files = port::tests::fixture();
let set = port::set(&port::tests::refs(&files)).unwrap();
let all = kernel_add(&template, &set);
let all = kernel_add(&template, &set, &[]);
assert_eq!(all.len(), 9);
assert_eq!(all[..2], today[..]);
for (e, k) in all[2..].iter().zip(&set) {
@@ -452,5 +470,22 @@ mod tests {
assert!(fields(e, &["Comment"])[0].starts_with("apv-arm64-port's "));
}
assert!(all.iter().any(|e| fields(e, &keys)[1].is_empty()));
// With reims-vgpu-video's kexts too, they follow the set in their order, from macOS 26.7.
let video_files = video::tests::fixture();
let video_set = video::set(&port::tests::refs(&video_files)).unwrap();
let with_video = kernel_add(&template, &set, &video_set);
assert_eq!(with_video.len(), 12);
assert_eq!(with_video[..9], all[..]);
for (e, k) in with_video[9..].iter().zip(&video_set) {
let f = fields(e, &keys);
assert_eq!(f[0], k.bundle);
assert_eq!(
f[1],
format!("Contents/MacOS/{}", k.bundle.trim_end_matches(".kext"))
);
assert_eq!(f[2..], [VIDEO_MIN_KERNEL, KEXT_MAX_KERNEL, "x86_64"]);
assert!(fields(e, &["Comment"])[0].starts_with("reims-vgpu-video's "));
}
}
}
+19 -6
View File
@@ -1,14 +1,15 @@
//! The OpenCore boot image: a 128 MiB GPT disk whose EFI system partition holds a pinned
//! OpenCore release, the drivers and ACPI table a VM needs, the picker's icons and the boot chime
//! from a pinned commit of OcBinaryData, a pinned Lilu release and its plugin ReimsVgpu.kext
//! (kext/), the apv-arm64-port kexts (apv_arm64_port.rs), and a `config.plist` made for a q35 VM
//! (config.rs) with an SMBIOS identity of its own (smbios.rs). OVMF goes beside it (ovmf.rs),
//! where reims-ctl looks for it.
//! (kext/), the apv-arm64-port kexts (apv_arm64_port.rs), reims-vgpu-video's kexts (video.rs),
//! and a `config.plist` made for a q35 VM (config.rs) with an SMBIOS identity of its own
//! (smbios.rs). OVMF goes beside it (ovmf.rs), where reims-ctl looks for it.
pub mod acpi;
pub mod apv_arm64_port;
pub mod config;
pub mod smbios;
pub mod video;
use crate::cache::{self, Pinned};
use crate::image::{self, Data, Format};
@@ -62,6 +63,9 @@ pub struct Options {
pub config: config::Options,
/// The apv-arm64-port kexts too, when kext/ holds them; with `config.kexts` alone.
pub apv_arm64_port: bool,
/// reims-vgpu-video's kexts too, when kext/ holds them; with the apv-arm64-port kexts alone,
/// whose IOSurface mapper they link against.
pub video: bool,
/// Where OVMF's files go, or None to write none.
pub ovmf_dir: Option<PathBuf>,
}
@@ -74,6 +78,8 @@ pub struct Outputs {
pub smbios: smbios::Smbios,
/// Whether the image carries the apv-arm64-port kexts.
pub apv_arm64_port: bool,
/// Whether the image carries reims-vgpu-video's kexts.
pub video: bool,
pub ovmf: Option<crate::ovmf::Outputs>,
}
@@ -87,6 +93,11 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
} else {
Vec::new()
};
let video = if !port.is_empty() && o.video {
video::set(video::FILES)?
} else {
Vec::new()
};
let lilu_path = if o.config.kexts {
let p = cache::fetch(&LILU_RELEASE, r)?;
progress::check(r)?;
@@ -95,12 +106,12 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
None
};
r.step(&format!("Building the OpenCore {VERSION} image"));
let mut files = files(&zip_path, &o.config, &port)?;
let mut files = files(&zip_path, &o.config, &port, &video)?;
files.extend(resources(&resources_path, o.config.graphical_picker)?);
if let Some(p) = &lilu_path {
files.extend(kexts(p)?);
}
for k in &port {
for k in port.iter().chain(&video) {
for (p, d) in &k.files {
files.push((format!("EFI/OC/Kexts/{}/{p}", k.bundle), d.to_vec()));
}
@@ -132,6 +143,7 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
opencore: VERSION,
smbios: o.config.smbios.clone(),
apv_arm64_port: !port.is_empty(),
video: !video.is_empty(),
ovmf,
})
}
@@ -141,6 +153,7 @@ fn files(
zip_path: &Path,
c: &config::Options,
port: &[apv_arm64_port::Kext<'_>],
video: &[apv_arm64_port::Kext<'_>],
) -> Result<Vec<(String, Vec<u8>)>> {
let f =
std::fs::File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?;
@@ -173,7 +186,7 @@ fn files(
let sample = read("Docs/Sample.plist")?;
files.push((
"EFI/OC/config.plist".into(),
config::make(&sample, c, port)?,
config::make(&sample, c, port, video)?,
));
files.push((
format!("EFI/OC/ACPI/{}", acpi::FILE_NAME),
+107
View File
@@ -0,0 +1,107 @@
//! reims-vgpu-video's kexts: three bundles, which load as one, after the apv-arm64-port kexts, on
//! macOS 26.7 (Darwin 25.6) alone. kext/ holds them as built, under their own names: the
//! reims-vgpu-video project builds them (its docs/kext-port.md), and build.rs embeds them.
//! - AppleVideoToolboxParavirtualization.kext, the guest driver of the paravirtualized
//! VideoToolbox device (106b:1a03), Apple's arm64 kext ported to x86-64;
//! - AppleM2ScalerParavirtDriver.kext, the M2 scaler device's (106b:1a0b), ported the same way;
//! - VtWaitPatch.kext, a Lilu plugin of reims-vgpu-video's own, which patches the x86-64 guest's
//! VideoToolbox so that its 10 s waits for the host's replies do not expire at once. It patches
//! macOS 26.7.1 (25G241) alone, and leaves any other build as it is.
//!
//! The two drivers link against apv-arm64-port's IOSurface mapper, so an image carries them only
//! with the apv-arm64-port kexts, and only where kext/ holds them; `--no-video` makes one without
//! them. A driver whose device the VM lacks loads and matches nothing.
use super::apv_arm64_port::{Kext, set_of};
use anyhow::Result;
include!(concat!(env!("OUT_DIR"), "/video.rs"));
include!("video_set.rs");
/// The video kexts in `files` (each by its path under kext/), in the order OpenCore loads them.
/// Empty when `files` holds none of them; anything short of the three refused.
pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result<Vec<Kext<'a>>> {
set_of(files, &VIDEO_SET, "video", "all three")
}
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::opencore::apv_arm64_port::tests::{info, refs};
/// The three, linked as they are: the drivers against the mapper and Apple's families, the
/// plugin against Lilu, none against each other.
pub(crate) fn fixture() -> Vec<(String, Vec<u8>)> {
let mapper = "com.apple.iokit.AppleParavirtIOSurface";
let kexts: [(&str, &str, &[&str]); 3] = [
(
"AppleVideoToolboxParavirtualization",
"com.apple.driver.AppleVideoToolboxParavirtualization",
&[mapper, "com.apple.driver.AppleVirtIO"],
),
(
"AppleM2ScalerParavirtDriver",
"com.apple.driver.AppleM2ScalerParavirtDriver",
&[mapper, "com.apple.iokit.IOPCIFamily"],
),
("VtWaitPatch", "t.vtwait", &["as.vit9696.Lilu"]),
];
let mut files = Vec::new();
for (name, id, libraries) in kexts {
files.push((
format!("{name}.kext/Contents/Info.plist"),
info(id, Some(name), libraries),
));
files.push((format!("{name}.kext/Contents/MacOS/{name}"), vec![0xcf]));
}
files
}
#[test]
fn ordered_by_name() {
let files = fixture();
let kexts = set(&refs(&files)).unwrap();
let bundles: Vec<&str> = kexts.iter().map(|k| k.bundle).collect();
assert_eq!(
bundles,
[
"AppleM2ScalerParavirtDriver.kext",
"AppleVideoToolboxParavirtualization.kext",
"VtWaitPatch.kext",
]
);
for k in &kexts {
assert_eq!(
k.executable.as_deref(),
Some(k.bundle.trim_end_matches(".kext"))
);
}
}
#[test]
fn part_of_the_set_refused() {
let mut files = fixture();
files.retain(|(p, _)| !p.starts_with("VtWaitPatch.kext/"));
let e = set(&refs(&files)).unwrap_err().to_string();
assert!(e.contains("without VtWaitPatch.kext"), "{e}");
}
#[test]
fn other_kexts_refused() {
let mut files = fixture();
files.push((
"AppleParavirtIOSurface.kext/Contents/Info.plist".into(),
info("x", None, &[]),
));
let e = set(&refs(&files)).unwrap_err().to_string();
assert!(e.contains("not one of the video kexts"), "{e}");
}
/// What kext/ holds of the three is the whole of it, or nothing.
#[test]
fn embedded_set_whole() {
let kexts = set(FILES).unwrap();
assert!(kexts.is_empty() || kexts.len() == VIDEO_SET.len());
}
}
+8
View File
@@ -0,0 +1,8 @@
/// reims-vgpu-video's three bundles, in kext/ under their own names, which load as one: the
/// VideoToolbox and scaler devices' guest drivers, and the Lilu plugin their x86-64 guests need.
/// build.rs and video.rs both include this list.
pub const VIDEO_SET: [&str; 3] = [
"AppleVideoToolboxParavirtualization.kext",
"AppleM2ScalerParavirtDriver.kext",
"VtWaitPatch.kext",
];
+1
View File
@@ -274,6 +274,7 @@ impl App {
show_picker: form.toggle(8),
no_kexts: false,
no_apv_arm64_port: false,
no_video: false,
no_ovmf: !form.toggle(3),
ovmf_dir: None,
};