🆕 Put the apv-arm64-port kexts in the OpenCore image

This commit is contained in:
Anees Iqbal committed 2026-10-17 11:53:39 +03:00
1 parent b302389a95
commit 302c97bdbb
22 files changed
+937 -32

No files matched your search

+8 -1
View File
@@ -85,7 +85,8 @@ 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. 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
([below](#apv-arm64-port)). 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.
- **The graphical picker**, OpenCanopy, with the GoldenGate icons. Pick with the arrow keys, Tab
@@ -191,6 +192,12 @@ 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
+105
View File
@@ -0,0 +1,105 @@
//! 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.
//!
//! 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.
use std::fmt::Write as _;
use std::path::{Path, PathBuf};
include!("src/opencore/apv_arm64_port_set.rs");
fn main() {
if let Err(e) = run() {
eprintln!("apv-arm64-port: {e}");
std::process::exit(1);
}
}
fn run() -> Result<(), String> {
let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").map_err(|e| e.to_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=kext");
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
.iter()
.copied()
.filter(|b| !present.contains(b))
.collect();
return Err(format!(
"partial apv-arm64-port set in kext/, without {}: deploy all seven",
missing.join(", ")
));
}
let mut files = Vec::new();
for b in &present {
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",
);
for f in &files {
let path = dir.join(f);
println!("cargo:rerun-if-changed={}", path.display());
let bytes = std::fs::read(&path).map_err(|e| format!("read {}: {e}", path.display()))?;
if bytes.windows(7).any(|w| w == b"/Users/") {
return Err(format!(
"kext/{f} holds a /Users/ path, from the machine it was built on: deploy a \
stripped build"
));
}
let abs = path
.to_str()
.ok_or(format!("{} is not UTF-8", path.display()))?;
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}"))
}
fn read_dir(dir: &Path) -> Result<Vec<std::fs::DirEntry>, String> {
let mut v = std::fs::read_dir(dir)
.and_then(|r| r.collect::<Result<Vec<_>, _>>())
.map_err(|e| format!("read {}: {e}", dir.display()))?;
v.sort_by_key(|e| e.file_name());
Ok(v)
}
/// Adds the files under `dir/rel`, by their path under `dir`, skipping dotfiles.
fn walk(dir: &Path, rel: &Path, files: &mut Vec<String>) -> Result<(), String> {
let path = dir.join(rel);
let t = std::fs::symlink_metadata(&path)
.map_err(|e| format!("read {}: {e}", path.display()))?
.file_type();
if t.is_dir() {
for e in read_dir(&path)? {
if !e.file_name().to_string_lossy().starts_with('.') {
walk(dir, &rel.join(e.file_name()), files)?;
}
}
} else if t.is_file() {
let s = rel
.to_str()
.ok_or(format!("{} is not UTF-8", rel.display()))?;
files.push(s.to_string());
} else {
return Err(format!("{} is neither a file nor a folder", rel.display()));
}
Ok(())
}
@@ -0,0 +1,69 @@
<?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>APVDisplayPort</string>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.APVDisplayPort</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>com.apple.driver.APVDisplayPort</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>LSMinimumSystemVersion</key>
<string>26.7</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018-2025 Apple Inc. All rights reserved.</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.driver.AppleParavirtGPUIOGPUFamily</key>
<string>15.0.0</string>
<key>com.apple.iokit.IOPCIFamily</key>
<string>1.0.0b1</string>
<key>com.apple.iokit.IOSurface</key>
<string>87.0</string>
<key>com.apple.kpi.iokit</key>
<string>16.7</string>
<key>com.apple.kpi.libkern</key>
<string>16.7</string>
<key>com.apple.kpi.mach</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.private</key>
<string>10.0.0d3</string>
<key>com.steelbrain.paravirt.AppleGraphicsDeviceControlBridge</key>
<string>1.0.0</string>
<key>com.steelbrain.paravirt.IOGraphicsFamilyBridge</key>
<string>1.0.0</string>
</dict>
</dict>
</plist>
@@ -0,0 +1,33 @@
<?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>AppleGraphicsDeviceControlBridge</string>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.paravirt.AppleGraphicsDeviceControlBridge</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>AppleGraphicsDeviceControlBridge</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0.0</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Root</string>
</dict>
</plist>
@@ -0,0 +1,69 @@
<?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>AppleParavirtGPUIOGPUFamily</string>
<key>CFBundleIdentifier</key>
<string>com.apple.driver.AppleParavirtGPUIOGPUFamily</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>com.apple.driver.AppleParavirtGPUIOGPUFamily</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>LSMinimumSystemVersion</key>
<string>26.7</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019-2025 Apple Inc. All rights reserved.</string>
<key>OSBundleCompatibleVersion</key>
<string>15.0.0</string>
<key>OSBundleLibraries</key>
<dict>
<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>87.0</string>
<key>com.apple.kpi.iokit</key>
<string>16.7</string>
<key>com.apple.kpi.libkern</key>
<string>16.7</string>
<key>com.apple.kpi.mach</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.private</key>
<string>10.0.0d3</string>
<key>com.steelbrain.paravirt.IOGPUFamilyBridge</key>
<string>1.0.0</string>
</dict>
</dict>
</plist>
@@ -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>AppleParavirtGPULoader</string>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.paravirt.AppleParavirtGPULoader</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>AppleParavirtGPULoader</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>IOKitPersonalities</key>
<dict>
<key>AppleParavirtGPULoader</key>
<dict>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.paravirt.AppleParavirtGPULoader</string>
<key>IOClass</key>
<string>AppleParavirtGPULoader</string>
<key>IOMatchCategory</key>
<string>AppleParavirtGPULoader</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>
@@ -0,0 +1,69 @@
<?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>AppleParavirtIOSurface</string>
<key>CFBundleIdentifier</key>
<string>com.apple.iokit.AppleParavirtIOSurface</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>com.apple.iokit.AppleParavirtIOSurface</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>LSMinimumSystemVersion</key>
<string>26.7</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019-2025 Apple Inc. All rights reserved.</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.iokit.IOPCIFamily</key>
<string>1.0.0b1</string>
<key>com.apple.iokit.IOSurface</key>
<string>87.0</string>
<key>com.apple.kpi.bsd</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.iokit</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.libkern</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.mach</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.private</key>
<string>9.0.0b1</string>
<key>com.apple.kpi.unsupported</key>
<string>9.0.0b1</string>
</dict>
</dict>
</plist>
@@ -0,0 +1,33 @@
<?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>IOGPUFamilyBridge</string>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.paravirt.IOGPUFamilyBridge</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>IOGPUFamilyBridge</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0.0</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Root</string>
</dict>
</plist>
Binary file not shown.
@@ -0,0 +1,33 @@
<?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>IOGraphicsFamilyBridge</string>
<key>CFBundleIdentifier</key>
<string>com.steelbrain.paravirt.IOGraphicsFamilyBridge</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>IOGraphicsFamilyBridge</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>OSBundleCompatibleVersion</key>
<string>1.0.0</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
<key>com.apple.kpi.mach</key>
<string>8.0.0</string>
</dict>
<key>OSBundleRequired</key>
<string>Root</string>
</dict>
</plist>
+6 -2
View File
@@ -104,10 +104,13 @@ pub struct OpencoreArgs {
/// Use OpenCore's text picker instead of the graphical one
#[arg(long)]
pub text_picker: bool,
/// Leave out Lilu and ReimsVgpu.kext, so macOS 26 drives reims-vgpu's GPU with its driver as
/// it is
/// 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
#[arg(long)]
pub no_kexts: bool,
/// Leave out the apv-arm64-port kexts
#[arg(long)]
pub no_apv_arm64_port: bool,
/// Write no OVMF files
#[arg(long)]
pub no_ovmf: bool,
@@ -344,6 +347,7 @@ pub fn opencore_options(a: &OpencoreArgs) -> Result<opencore::Options> {
graphical_picker: !a.text_picker,
kexts: !a.no_kexts,
},
apv_arm64_port: !a.no_apv_arm64_port,
ovmf_dir,
})
}
+301
View File
@@ -0,0 +1,301 @@
//! The apv-arm64-port kexts: seven bundles, which load as one, after Lilu and ReimsVgpu, on macOS
//! 26.4 and later. kext/ holds them as built, under their own names: the apv-arm64-port project's
//! deploy.sh writes them there, and build.rs embeds them. Every image carries them unless kext/
//! holds none of them; `--no-apv-arm64-port` makes one without them.
use anyhow::{Context, Result, bail};
use std::collections::{BTreeMap, BTreeSet};
include!(concat!(env!("OUT_DIR"), "/apv_arm64_port.rs"));
include!("apv_arm64_port_set.rs");
/// A kext of the set.
#[derive(Debug)]
pub struct Kext<'a> {
pub bundle: &'a str,
/// Its executable in `Contents/MacOS`, or None for a kext with no code.
pub executable: Option<String>,
identifier: String,
libraries: Vec<String>,
/// Its files, by their path in the bundle.
pub files: Vec<(&'a str, &'a [u8])>,
}
/// The set in `files` (each by its path under kext/), in the order OpenCore loads it: each kext
/// 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>>> {
let mut bundles: BTreeMap<&str, Vec<(&str, &[u8])>> = BTreeMap::new();
for &(path, data) in files {
let Some((bundle, rel)) = path.split_once('/') else {
continue;
};
if !bundle.ends_with(".kext") || path.split('/').any(|c| c.starts_with('.')) {
continue;
}
if !SET.contains(&bundle) {
bail!(
"kext/{bundle} is not one of the apv-arm64-port kexts ({})",
SET.join(", ")
);
}
bundles.entry(bundle).or_default().push((rel, data));
}
if bundles.is_empty() {
return Ok(Vec::new());
}
let missing: Vec<&str> = SET
.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",
missing.join(", ")
);
}
let mut kexts = Vec::new();
for (bundle, files) in bundles {
kexts.push(kext(bundle, files)?);
}
order(kexts)
}
fn kext<'a>(bundle: &'a str, files: Vec<(&'a str, &'a [u8])>) -> Result<Kext<'a>> {
let plist = files
.iter()
.find(|(p, _)| *p == "Contents/Info.plist")
.with_context(|| format!("kext/{bundle} has no Contents/Info.plist"))?;
let info: plist::Dictionary = plist::from_bytes(plist.1)
.with_context(|| format!("read kext/{bundle}/Contents/Info.plist"))?;
let string = |k: &str| info.get(k).and_then(plist::Value::as_string);
let identifier = string("CFBundleIdentifier")
.with_context(|| format!("kext/{bundle} has no CFBundleIdentifier"))?
.to_string();
let executable = string("CFBundleExecutable").map(str::to_string);
if let Some(e) = &executable {
let path = format!("Contents/MacOS/{e}");
if !files.iter().any(|(p, _)| *p == path) {
bail!("kext/{bundle} has no {path}, the executable its Info.plist names");
}
}
let libraries = info
.get("OSBundleLibraries")
.and_then(plist::Value::as_dictionary)
.map(|d| d.keys().cloned().collect())
.unwrap_or_default();
Ok(Kext {
bundle,
executable,
identifier,
libraries,
files,
})
}
/// 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<'_>>> {
let ids: BTreeSet<String> = left.iter().map(|k| k.identifier.clone()).collect();
let mut placed = BTreeSet::new();
let mut out = Vec::new();
while !left.is_empty() {
let ready = left.iter().position(|k| {
k.libraries
.iter()
.all(|l| !ids.contains(l) || placed.contains(l))
});
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",
names.join(", ")
);
};
let k = left.remove(i);
placed.insert(k.identifier.clone());
out.push(k);
}
Ok(out)
}
#[cfg(test)]
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> {
let mut d = plist::Dictionary::new();
d.insert("CFBundleIdentifier".into(), id.into());
if let Some(e) = executable {
d.insert("CFBundleExecutable".into(), e.into());
}
let mut l = plist::Dictionary::new();
for x in libraries {
l.insert(x.to_string(), "1.0.0".into());
}
d.insert("OSBundleLibraries".into(), l.into());
let mut v = Vec::new();
plist::Value::Dictionary(d).to_writer_xml(&mut v).unwrap();
v
}
/// The seven, linked as the set is: each kext on its bridges, the loader on Lilu. The
/// bridges here have no code, to cover a kext without an executable.
pub(crate) fn fixture() -> Vec<(String, Vec<u8>)> {
let lilu = "as.vit9696.Lilu";
let kexts: [(&str, &str, bool, &[&str]); 7] = [
("AppleParavirtGPULoader", "loader", true, &[lilu]),
("IOGPUFamilyBridge", "gpub", false, &["com.apple.kpi.iokit"]),
("IOGraphicsFamilyBridge", "gfxb", false, &[]),
("AppleGraphicsDeviceControlBridge", "agdcb", false, &[]),
("AppleParavirtIOSurface", "iosurface", true, &[]),
(
"AppleParavirtGPUIOGPUFamily",
"gpu",
true,
&["t.gpub", "t.iosurface"],
),
(
"APVDisplayPort",
"display",
true,
&["t.gfxb", "t.agdcb", "t.gpu"],
),
];
let mut files = Vec::new();
for (name, id, code, libraries) in kexts {
let exe = code.then_some(name);
files.push((
format!("{name}.kext/Contents/Info.plist"),
info(&format!("t.{id}"), exe, libraries),
));
if code {
files.push((format!("{name}.kext/Contents/MacOS/{name}"), vec![0xcf]));
}
}
files
}
pub(crate) fn refs(files: &[(String, Vec<u8>)]) -> Vec<(&str, &[u8])> {
files
.iter()
.map(|(p, d)| (p.as_str(), d.as_slice()))
.collect()
}
fn bundles(kexts: &[Kext<'_>]) -> Vec<String> {
kexts
.iter()
.map(|k| k.bundle.replace(".kext", ""))
.collect()
}
#[test]
fn ordered_by_libraries() {
let files = fixture();
let kexts = set(&refs(&files)).unwrap();
assert_eq!(
bundles(&kexts),
[
"AppleGraphicsDeviceControlBridge",
"AppleParavirtGPULoader",
"AppleParavirtIOSurface",
"IOGPUFamilyBridge",
"AppleParavirtGPUIOGPUFamily",
"IOGraphicsFamilyBridge",
"APVDisplayPort",
]
);
}
#[test]
fn executables() {
let files = fixture();
let kexts = set(&refs(&files)).unwrap();
for k in &kexts {
let code = !k.bundle.ends_with("Bridge.kext");
assert_eq!(
k.executable.as_deref(),
code.then(|| k.bundle.trim_end_matches(".kext")),
"{}",
k.bundle
);
assert_eq!(k.files.len(), if code { 2 } else { 1 }, "{}", k.bundle);
}
let mut files = fixture();
files.retain(|(p, _)| p != "APVDisplayPort.kext/Contents/MacOS/APVDisplayPort");
let e = set(&refs(&files)).unwrap_err().to_string();
assert!(e.contains("Contents/MacOS/APVDisplayPort"), "{e}");
}
#[test]
fn side_files_left_out() {
let mut files = fixture();
for p in [
"notes.txt",
"APVDisplayPort.plist",
"APVDisplayPort.kext/.DS_Store",
"APVDisplayPort.kext/Contents/._Info.plist",
] {
files.push((p.to_string(), b"junk".to_vec()));
}
let kexts = set(&refs(&files)).unwrap();
assert_eq!(kexts.len(), 7);
for k in &kexts {
for (p, _) in &k.files {
assert!(!p.contains("/.") && !p.starts_with('.'), "{}/{p}", k.bundle);
}
}
}
#[test]
fn other_kexts_refused() {
for extra in ["Lilu.kext", "IOGPUFamily.kext"] {
let mut files = fixture();
files.push((format!("{extra}/Contents/Info.plist"), info("x", None, &[])));
let e = set(&refs(&files)).unwrap_err().to_string();
assert!(e.contains(extra), "{e}");
}
}
#[test]
fn part_of_the_set_refused() {
let mut files = fixture();
files.retain(|(p, _)| !p.starts_with("IOGPUFamilyBridge.kext/"));
let e = set(&refs(&files)).unwrap_err().to_string();
assert!(e.contains("without IOGPUFamilyBridge.kext"), "{e}");
}
#[test]
fn cycle_refused() {
let mut files = fixture();
for (p, d) in &mut files {
if p == "AppleParavirtIOSurface.kext/Contents/Info.plist" {
*d = info(
"t.iosurface",
Some("AppleParavirtIOSurface"),
&["t.display"],
);
}
}
let e = set(&refs(&files)).unwrap_err().to_string();
assert!(e.contains("cycle"), "{e}");
}
#[test]
fn nothing_without_kexts() {
assert!(set(&[]).unwrap().is_empty());
let side: [(&str, &[u8]); 1] = [("notes.txt", b"")];
assert!(set(&side).unwrap().is_empty());
}
/// What kext/ holds of the set is the whole of it, or nothing.
#[test]
fn embedded_set_whole() {
let kexts = set(FILES).unwrap();
assert!(kexts.is_empty() || kexts.len() == SET.len());
}
}
+12
View File
@@ -0,0 +1,12 @@
/// The seven apv-arm64-port bundles, in kext/ under their own names, which load as one:
/// AppleParavirtGPULoader binds the others through the bridges, and refuses when one is missing
/// or differs. build.rs and apv_arm64_port.rs both include this list.
pub const SET: [&str; 7] = [
"AppleParavirtGPULoader.kext",
"IOGPUFamilyBridge.kext",
"IOGraphicsFamilyBridge.kext",
"AppleGraphicsDeviceControlBridge.kext",
"AppleParavirtIOSurface.kext",
"AppleParavirtGPUIOGPUFamily.kext",
"APVDisplayPort.kext",
];
+116 -24
View File
@@ -13,7 +13,9 @@
//! when the VM has one, unless macOS's "Play sound on startup" is off (`StartupMute`);
//! - 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; no others, as QEMU's `isa-applesmc` is the SMC;
//! 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;
//! - 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;
@@ -23,6 +25,7 @@
//! does not see it runs in a VM and lets iCloud and the App Store sign in;
//! - the SMBIOS identity (smbios.rs), and the picker's timeout and boot arguments.
use super::apv_arm64_port::Kext as PortKext;
use super::smbios::Smbios;
use anyhow::{Context, Result, bail};
use plist::{Dictionary, Value};
@@ -65,6 +68,9 @@ pub const REIMS_VGPU: Kext = Kext {
/// The kexts load on Darwin 25 alone, macOS 26, whose GPU driver ReimsVgpu patches.
const KEXT_MIN_KERNEL: &str = "25.0.0";
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";
/// 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.
@@ -86,11 +92,13 @@ pub struct Options {
pub hide_vm: bool,
/// OpenCanopy's graphical picker, or OpenCore's text one.
pub graphical_picker: bool,
/// Lilu and ReimsVgpu, for macOS 26.
/// Lilu and ReimsVgpu (and the set `make` is given), for macOS 26.
pub kexts: bool,
}
pub fn make(sample: &[u8], o: &Options) -> Result<Vec<u8>> {
/// 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>> {
let mut root: Value = plist::from_bytes(sample).context("read Sample.plist")?;
let c = root
.as_dictionary_mut()
@@ -134,27 +142,11 @@ pub fn make(sample: &[u8], o: &Options) -> Result<Vec<u8>> {
Value::Dictionary(Dictionary::new()),
)?;
let mut kexts = Vec::new();
if o.kexts {
for (k, comment) in [
(LILU, "Patch engine"),
(REIMS_VGPU, "reims-vgpu's GPU features on macOS 26"),
] {
let mut e = template(c, &["Kernel", "Add"])?;
e.insert("Arch".into(), "x86_64".into());
e.insert("BundlePath".into(), k.bundle.into());
e.insert("Comment".into(), comment.into());
e.insert("Enabled".into(), true.into());
e.insert(
"ExecutablePath".into(),
format!("Contents/MacOS/{}", k.executable).into(),
);
e.insert("MaxKernel".into(), KEXT_MAX_KERNEL.into());
e.insert("MinKernel".into(), KEXT_MIN_KERNEL.into());
e.insert("PlistPath".into(), "Contents/Info.plist".into());
kexts.push(Value::Dictionary(e));
}
}
let kexts = if o.kexts {
kernel_add(&template(c, &["Kernel", "Add"])?, port)
} else {
Vec::new()
};
set(c, &["Kernel"], "Add", Value::Array(kexts))?;
set(c, &["Kernel"], "Block", Value::Array(vec![]))?;
set(c, &["Kernel"], "Force", Value::Array(vec![]))?;
@@ -316,6 +308,49 @@ pub fn make(sample: &[u8], o: &Options) -> Result<Vec<u8>> {
Ok(out)
}
/// 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> {
let mut add = vec![
(
LILU.bundle,
Some(LILU.executable),
KEXT_MIN_KERNEL,
"Patch engine".to_string(),
),
(
REIMS_VGPU.bundle,
Some(REIMS_VGPU.executable),
KEXT_MIN_KERNEL,
"reims-vgpu's GPU features on macOS 26".to_string(),
),
];
for k in port {
add.push((
k.bundle,
k.executable.as_deref(),
PORT_MIN_KERNEL,
format!("apv-arm64-port's {}", k.bundle.trim_end_matches(".kext")),
));
}
add.into_iter()
.map(|(bundle, executable, min_kernel, comment)| {
let mut e = template.clone();
e.insert("Arch".into(), "x86_64".into());
e.insert("BundlePath".into(), bundle.into());
e.insert("Comment".into(), comment.into());
e.insert("Enabled".into(), true.into());
// A kext with no code has an empty path.
let path = executable.map(|x| format!("Contents/MacOS/{x}"));
e.insert("ExecutablePath".into(), path.unwrap_or_default().into());
e.insert("MaxKernel".into(), KEXT_MAX_KERNEL.into());
e.insert("MinKernel".into(), min_kernel.into());
e.insert("PlistPath".into(), "Contents/Info.plist".into());
Value::Dictionary(e)
})
.collect()
}
fn dict<'a>(root: &'a mut Dictionary, path: &[&str]) -> Result<&'a mut Dictionary> {
let mut d = root;
for (i, k) in path.iter().enumerate() {
@@ -359,3 +394,60 @@ fn unhex(s: &str) -> Result<Vec<u8>> {
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::opencore::apv_arm64_port as port;
fn fields(v: &Value, keys: &[&str]) -> Vec<String> {
let d = v.as_dictionary().unwrap();
keys.iter()
.map(|k| d.get(k).and_then(Value::as_string).unwrap().to_string())
.collect()
}
#[test]
fn kernel_add_entries() {
let mut template = Dictionary::new();
template.insert("BundlePath".into(), "Lilu.kext".into());
template.insert("Enabled".into(), false.into());
let keys = [
"BundlePath",
"ExecutablePath",
"MinKernel",
"MaxKernel",
"Arch",
];
// With none of the set in kext/, Lilu and ReimsVgpu alone.
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)
};
assert_eq!(
today.iter().map(|e| fields(e, &keys)).collect::<Vec<_>>(),
[
want("Lilu.kext", "Contents/MacOS/Lilu"),
want("ReimsVgpu.kext", "Contents/MacOS/ReimsVgpu"),
]
);
// With the set, it follows them in its order, from macOS 26.4; a kext with no code has
// no path.
let files = port::tests::fixture();
let set = port::set(&port::tests::refs(&files)).unwrap();
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) {
let f = fields(e, &keys);
assert_eq!(f[0], k.bundle);
let x = k.executable.as_ref().map(|x| format!("Contents/MacOS/{x}"));
assert_eq!(f[1], x.unwrap_or_default());
assert_eq!(f[2..], [PORT_MIN_KERNEL, KEXT_MAX_KERNEL, "x86_64"]);
assert!(fields(e, &["Comment"])[0].starts_with("apv-arm64-port's "));
}
assert!(all.iter().any(|e| fields(e, &keys)[1].is_empty()));
}
}
+29 -5
View File
@@ -1,10 +1,12 @@
//! 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/), 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), 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;
@@ -58,6 +60,8 @@ const DISK_SIZE: u64 = 128 << 20;
pub struct Options {
pub output: PathBuf,
pub config: config::Options,
/// The apv-arm64-port kexts too, when kext/ holds them; with `config.kexts` alone.
pub apv_arm64_port: bool,
/// Where OVMF's files go, or None to write none.
pub ovmf_dir: Option<PathBuf>,
}
@@ -68,6 +72,8 @@ pub struct Outputs {
pub format: Format,
pub opencore: &'static str,
pub smbios: smbios::Smbios,
/// Whether the image carries the apv-arm64-port kexts.
pub apv_arm64_port: bool,
pub ovmf: Option<crate::ovmf::Outputs>,
}
@@ -76,6 +82,11 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
progress::check(r)?;
let resources_path = cache::fetch(&RESOURCES, r)?;
progress::check(r)?;
let port = if o.config.kexts && o.apv_arm64_port {
apv_arm64_port::set(apv_arm64_port::FILES)?
} else {
Vec::new()
};
let lilu_path = if o.config.kexts {
let p = cache::fetch(&LILU_RELEASE, r)?;
progress::check(r)?;
@@ -84,11 +95,16 @@ 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)?;
let mut files = files(&zip_path, &o.config, &port)?;
files.extend(resources(&resources_path, o.config.graphical_picker)?);
if let Some(p) = &lilu_path {
files.extend(kexts(p)?);
}
for k in &port {
for (p, d) in &k.files {
files.push((format!("EFI/OC/Kexts/{}/{p}", k.bundle), d.to_vec()));
}
}
let files: Vec<(String, Data)> = files
.into_iter()
.map(|(p, d)| (p, Data::Bytes(d)))
@@ -115,12 +131,17 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
format,
opencore: VERSION,
smbios: o.config.smbios.clone(),
apv_arm64_port: !port.is_empty(),
ovmf,
})
}
/// The partition's files, from the release's X64 tree, and the made config.plist and ACPI table.
fn files(zip_path: &Path, c: &config::Options) -> Result<Vec<(String, Vec<u8>)>> {
fn files(
zip_path: &Path,
c: &config::Options,
port: &[apv_arm64_port::Kext<'_>],
) -> Result<Vec<(String, Vec<u8>)>> {
let f =
std::fs::File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?;
let mut zip = zip::ZipArchive::new(f).context("read the OpenCore release")?;
@@ -150,7 +171,10 @@ fn files(zip_path: &Path, c: &config::Options) -> Result<Vec<(String, Vec<u8>)>>
));
}
let sample = read("Docs/Sample.plist")?;
files.push(("EFI/OC/config.plist".into(), config::make(&sample, c)?));
files.push((
"EFI/OC/config.plist".into(),
config::make(&sample, c, port)?,
));
files.push((
format!("EFI/OC/ACPI/{}", acpi::FILE_NAME),
acpi::ssdt_ec_usbx(),
+1
View File
@@ -272,6 +272,7 @@ impl App {
show_vm: !form.toggle(5),
text_picker: !form.toggle(7),
no_kexts: false,
no_apv_arm64_port: false,
no_ovmf: !form.toggle(3),
ovmf_dir: None,
};