🆕 Add kexts to the OpenCore image with --add-kext, drop the ported ones

reims-ctl gets a graphics option of its own, reims-vgpu: QEMU's
reims-graphics-pci device, driven by guest kexts that reims-ctl adds to the
image. Images now carry no ported kexts: only what the guest already has,
or what is added.

- kext/ loses the seven apv-arm64-port kexts and reims-vgpu-video's three,
  with their modules and build.rs, which embedded nothing else.
  --no-apv-arm64-port and --no-video are accepted and ignored.
- Lilu and ReimsVgpu.kext are as they were: the same bytes, first in
  Kernel > Add, on Darwin 25.0.0 to 25.99.99.
- --add-kext PATH[,MIN[,MAX]], repeatable, copies a bundle into
  EFI/OC/Kexts (dotfiles left out) and loads it after reims-util's own, in
  the order given: Arch x86_64, its BundlePath, the ExecutablePath its
  CFBundleExecutable names (empty without one), PlistPath
  Contents/Info.plist, MinKernel and MaxKernel as given (25.0.0 and
  25.99.99 when left out), and its identifier as Comment. A kext whose
  bundle name (case aside, as FAT32 ignores it) or identifier is already in
  the image is refused, as is one that links against a kext given after it,
  or against Lilu with --no-kexts. These fail before anything downloads.
- opencore's done result drops apv_arm64_port and video, and adds kexts:
  the bundle names in the order they load.

Checked on this Mac: cargo test (48 pass), clippy -D warnings, fmt. A raw
image made with an identity, --no-ovmf and four synthetic kexts (with code,
codeless, linked to Lilu and to each other) carries them after Lilu and
ReimsVgpu (byte-identical to kext/'s) with the entries above, and OpenCore
1.0.8's ocvalidate finds no issues in its config.plist. Without --add-kext,
an image differs from ed73989's only by the ten kexts and their entries.
This commit is contained in:
Anees Iqbal committed 2026-11-05 22:38:29 -08:00
1 parent ed7398997f
commit fe9bfe1a62
31 files changed
+686 -1336

No files matched your search

+27 -24
View File
@@ -85,9 +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. 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.
turns the kext off. Kexts you add with `--add-kext` load after these
([below](#adding-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
@@ -108,6 +107,26 @@ What's in the image, and why:
arguments, and `--verbose-boot` shows the kernel's messages while it boots.
`reims-util opencore --help` lists the rest.
#### Adding kexts
`--add-kext` puts a kext bundle of your own in the image, after Lilu and ReimsVgpu.kext. Repeat
it for more: they load in the order you give them, so give a kext after the ones it links
against.
```sh
reims-util opencore -o OpenCore.qcow2 \
--add-kext ~/kexts/Loader.kext,25.4.0,25.99.99 --add-kext ~/kexts/Plugin.kext,25.4.0
```
Each value is `PATH[,MIN[,MAX]]`: the bundle, then the Darwin versions it loads on, as OpenCore's
MinKernel and MaxKernel take them (25.4.0 is macOS 26.4). Left out, they're 25.0.0 and 25.99.99,
macOS 26, as for the image's own kexts. The bundle is copied whole into `EFI/OC/Kexts`, without
its dotfiles, and OpenCore loads the executable its Info.plist names, or none for a kext with no
code. reims-util refuses a kext with the name or bundle identifier of one already in the image
(the image's FAT32 partition doesn't tell names apart by case), and one that links against a kext
given after it, or against Lilu when `--no-kexts` leaves Lilu out. `--no-kexts` leaves out
reims-util's own kexts alone: the ones you add still go in.
### Online installers
```sh
@@ -171,7 +190,8 @@ still boots, and a VM may be using it.
`--json` prints progress and the result as JSON lines on stdout. The last line is either
`{"event":"done","result":{…}}`, with what was written (and for `opencore`, the identity it
made) or, for `list`, the versions, or `{"event":"error","message":"…"}`.
made, and in `kexts` the bundles it carries, in the order they load) or, for `list`, the
versions, or `{"event":"error","message":"…"}`.
```sh
reims-util --json online-installer tahoe -o ~/vms/mac
@@ -179,26 +199,9 @@ reims-util --json online-installer tahoe -o ~/vms/mac
## The kexts
`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:
`kext/` holds ReimsVgpu.kext, the kext reims-util puts in its images, built: a kext builds on a
Mac alone, while reims-util builds anywhere. After changing its source, rebuild it on a Mac with
Xcode, and commit the built kext with the change:
```sh
cd kext
-126
View File
@@ -1,126 +0,0 @@
//! 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), 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.
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() {
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=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"),
)
}
/// 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
.iter()
.copied()
.filter(|b| !present.contains(b))
.collect();
return Err(format!(
"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)?;
}
files.sort();
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);
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");
std::fs::write(to, code).map_err(|e| format!("write {}: {e}", to.display()))
}
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(())
}
@@ -1,69 +0,0 @@
<?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>
@@ -1,33 +0,0 @@
<?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>
@@ -1,102 +0,0 @@
<?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>
@@ -1,69 +0,0 @@
<?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>
@@ -1,53 +0,0 @@
<?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>
@@ -1,69 +0,0 @@
<?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>
@@ -1,88 +0,0 @@
<?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>
@@ -1,33 +0,0 @@
<?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>
@@ -1,33 +0,0 @@
<?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>
-53
View File
@@ -1,53 +0,0 @@
<?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.
+17 -12
View File
@@ -2,7 +2,7 @@
//! progress and the result are JSON lines on stdout (progress.rs), and the last line is a `done`
//! event with what was written, or an `error` event.
use crate::opencore::{self, config, smbios};
use crate::opencore::{self, added, config, smbios};
use crate::progress::{self, JsonReporter, Reporter, TextReporter};
use crate::{installer, recovery};
use anyhow::{Context, Result, bail};
@@ -108,17 +108,23 @@ 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, the apv-arm64-port kexts and reims-vgpu-video's, so
/// macOS 26 drives reims-vgpu's GPU with its driver as it is
/// Leave out Lilu and ReimsVgpu.kext, so macOS 26 drives reims-vgpu's GPU with its driver as
/// it is (kexts given with --add-kext still go in)
#[arg(long)]
pub no_kexts: bool,
/// 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,
/// Add a kext bundle, loaded after Lilu and ReimsVgpu.kext on Darwin MIN to MAX (default
/// 25.0.0 to 25.99.99, macOS 26). Repeat it for more: they load in the order given
#[arg(long = "add-kext", value_name = "PATH[,MIN[,MAX]]", value_parser = added::parse)]
pub add_kext: Vec<added::Spec>,
/// Accepted and ignored: --no-apv-arm64-port and --no-video, whose kexts images no longer
/// carry
#[arg(
long = "no-apv-arm64-port",
alias = "no-video",
hide = true,
action = clap::ArgAction::Count
)]
pub _retired: u8,
/// Write no OVMF files
#[arg(long)]
pub no_ovmf: bool,
@@ -356,8 +362,7 @@ pub fn opencore_options(a: &OpencoreArgs) -> Result<opencore::Options> {
show_picker: a.show_picker,
kexts: !a.no_kexts,
},
apv_arm64_port: !a.no_apv_arm64_port,
video: !a.no_video,
add_kexts: a.add_kext.clone(),
ovmf_dir,
})
}
+498
View File
@@ -0,0 +1,498 @@
//! Kexts given with `--add-kext`, which the image carries after its own (Lilu and ReimsVgpu), in
//! the order given: reims-vgpu's guest kexts for its own GPU device, for one. Each is a bundle on
//! disk, copied whole into `EFI/OC/Kexts` (dotfiles left out), and loaded by a Kernel > Add entry
//! made from its Info.plist and the Darwin versions it was given (config.rs).
use super::config;
use anyhow::{Context, Result, bail};
use std::path::{Path, PathBuf};
/// A `--add-kext` value, `PATH[,MIN[,MAX]]`: a bundle, and the Darwin versions it loads on.
#[derive(Clone, Debug, PartialEq)]
pub struct Spec {
pub path: PathBuf,
pub min_kernel: String,
pub max_kernel: String,
}
/// Reads `PATH[,MIN[,MAX]]`. The path ends in `.kext`, so a comma in a folder's name stays in
/// the path; MIN and MAX are versions as OpenCore takes them (25.4.0), each 25.0.0 and 25.99.99,
/// the bounds of the image's own kexts, when left out or empty.
pub fn parse(s: &str) -> Result<Spec, String> {
let usage = "give PATH[,MIN[,MAX]], such as Foo.kext,25.4.0,25.99.99";
let mut path = s;
let mut bounds: Vec<&str> = Vec::new();
while !is_bundle(path) && bounds.len() < 2 {
let Some((p, b)) = path.rsplit_once(',') else {
break;
};
path = p;
bounds.insert(0, b);
}
if !is_bundle(path) {
return Err(format!("{s:?} is not a .kext bundle: {usage}"));
}
let bound = |i: usize, default: &str| -> Result<String, String> {
match bounds.get(i).map(|b| b.trim()).filter(|b| !b.is_empty()) {
None => Ok(default.to_string()),
Some(b) if version(b).is_some() => Ok(b.to_string()),
Some(b) => Err(format!(
"{b:?} is not a Darwin version such as 25.4.0: {usage}"
)),
}
};
let min_kernel = bound(0, config::KEXT_MIN_KERNEL)?;
let max_kernel = bound(1, config::KEXT_MAX_KERNEL)?;
if version(&min_kernel) > version(&max_kernel) {
return Err(format!(
"{s:?} loads on no Darwin version: {min_kernel} is past {max_kernel}"
));
}
Ok(Spec {
path: PathBuf::from(path),
min_kernel,
max_kernel,
})
}
fn is_bundle(path: &str) -> bool {
path.trim_end_matches('/').ends_with(".kext")
}
/// A version as OpenCore's MinKernel and MaxKernel take it, X.Y.Z.
fn version(s: &str) -> Option<[u32; 3]> {
let mut parts = s.split('.').map(|p| {
(!p.is_empty() && p.bytes().all(|b| b.is_ascii_digit()))
.then(|| p.parse().ok())
.flatten()
});
let v = [parts.next()??, parts.next()??, parts.next()??];
parts.next().is_none().then_some(v)
}
/// A kext to add, read from its bundle.
#[derive(Debug)]
pub struct Kext {
/// The bundle's name, which it has in `EFI/OC/Kexts`.
pub bundle: String,
pub identifier: String,
/// Its executable in `Contents/MacOS`, or None for a kext with no code.
pub executable: Option<String>,
/// The bundles its `OSBundleLibraries` name.
libraries: Vec<String>,
pub min_kernel: String,
pub max_kernel: String,
/// Its files, by their path in the bundle.
pub files: Vec<(String, Vec<u8>)>,
}
/// Reads the bundle `s` names.
pub fn read(s: &Spec) -> Result<Kext> {
let shown = s.path.display();
let bundle = s
.path
.file_name()
.and_then(|n| n.to_str())
.filter(|n| n.ends_with(".kext"))
.with_context(|| format!("{shown} is not a .kext bundle"))?
.to_string();
// A link to a bundle is followed, as macOS follows it; links within one are refused.
let root = std::fs::canonicalize(&s.path).with_context(|| format!("read {shown}"))?;
if !root.is_dir() {
bail!("{shown} is not a bundle: it is a file, not a folder");
}
let mut files = Vec::new();
walk(&root, Path::new(""), &mut files)?;
files.sort();
let plist = files
.iter()
.find(|(p, _)| p == "Contents/Info.plist")
.with_context(|| format!("{shown} has no Contents/Info.plist"))?;
let info: plist::Dictionary =
plist::from_bytes(&plist.1).with_context(|| format!("read {shown}/Contents/Info.plist"))?;
let string = |k: &str| info.get(k).and_then(plist::Value::as_string);
let identifier = string("CFBundleIdentifier")
.filter(|i| !i.is_empty())
.with_context(|| format!("{shown} has no CFBundleIdentifier"))?
.to_string();
let executable = string("CFBundleExecutable")
.filter(|e| !e.is_empty())
.map(str::to_string);
if let Some(e) = &executable {
let path = format!("Contents/MacOS/{e}");
if !files.iter().any(|(p, _)| *p == path) {
bail!("{shown} has no {path}, the executable its Info.plist names");
}
}
let mut libraries: Vec<String> = ["OSBundleLibraries", "OSBundleLibraries_x86_64"]
.iter()
.filter_map(|k| info.get(k).and_then(plist::Value::as_dictionary))
.flat_map(|d| d.keys().cloned())
.collect();
libraries.sort();
libraries.dedup();
Ok(Kext {
bundle,
identifier,
executable,
libraries,
min_kernel: s.min_kernel.clone(),
max_kernel: s.max_kernel.clone(),
files,
})
}
/// Adds the files under `root/rel`, by their path under `root`, skipping dotfiles.
fn walk(root: &Path, rel: &Path, files: &mut Vec<(String, Vec<u8>)>) -> Result<()> {
let path = root.join(rel);
let t = std::fs::symlink_metadata(&path)
.with_context(|| format!("read {}", path.display()))?
.file_type();
if t.is_dir() {
let mut entries = std::fs::read_dir(&path)
.and_then(|r| r.collect::<Result<Vec<_>, _>>())
.with_context(|| format!("read {}", path.display()))?;
entries.sort_by_key(|e| e.file_name());
for e in entries {
if !e.file_name().to_string_lossy().starts_with('.') {
walk(root, &rel.join(e.file_name()), files)?;
}
}
} else if t.is_file() {
let name = rel
.to_str()
.with_context(|| format!("{} is not UTF-8", path.display()))?
.replace('\\', "/");
let data = std::fs::read(&path).with_context(|| format!("read {}", path.display()))?;
files.push((name, data));
} else {
bail!(
"{} is neither a file nor a folder (a link?): give a bundle of files",
path.display()
);
}
Ok(())
}
/// Refuses `added` where it would clash with the image's own kexts, `own` (in the image when
/// `own_in`), or with each other: a bundle name FAT32 can't tell from another's (it ignores
/// case), an identifier already loaded, or a library of the image's that does not load before it.
pub fn check(own: &[config::Kext], own_in: bool, added: &[Kext]) -> Result<()> {
let present: &[config::Kext] = if own_in { own } else { &[] };
for (i, k) in added.iter().enumerate() {
let earlier = &added[..i];
let same = |b: &str| b.eq_ignore_ascii_case(&k.bundle);
if let Some(o) = present.iter().find(|o| same(o.bundle)) {
bail!(
"the image carries its own {}: leave {} out of --add-kext",
o.bundle,
k.bundle
);
}
if let Some(o) = present.iter().find(|o| o.identifier == k.identifier) {
bail!(
"{} is {}, as the image's own {} is",
k.bundle,
k.identifier,
o.bundle
);
}
if let Some(e) = earlier.iter().find(|e| same(&e.bundle)) {
if e.bundle == k.bundle {
bail!("{} is given twice", k.bundle);
}
bail!(
"{} and {} are one name on the image's FAT32 partition, which ignores case",
e.bundle,
k.bundle
);
}
if let Some(e) = earlier.iter().find(|e| e.identifier == k.identifier) {
bail!("{} and {} are both {}", e.bundle, k.bundle, k.identifier);
}
for l in &k.libraries {
let before = *l == k.identifier
|| present.iter().any(|o| o.identifier == *l)
|| earlier.iter().any(|e| e.identifier == *l);
if before {
continue;
}
if let Some(later) = added[i + 1..].iter().find(|a| a.identifier == *l) {
bail!(
"{} links against {} ({l}), which comes after it: give {} first",
k.bundle,
later.bundle,
later.bundle
);
}
if let Some(o) = own.iter().find(|o| o.identifier == *l) {
bail!(
"{} links against {} ({l}), which --no-kexts leaves out",
k.bundle,
o.bundle
);
}
}
}
Ok(())
}
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::opencore::config::{LILU, REIMS_VGPU};
fn spec(path: &str, min: &str, max: &str) -> Spec {
Spec {
path: PathBuf::from(path),
min_kernel: min.into(),
max_kernel: max.into(),
}
}
#[test]
fn parsed() {
let (lo, hi) = (config::KEXT_MIN_KERNEL, config::KEXT_MAX_KERNEL);
for (s, want) in [
("Foo.kext", spec("Foo.kext", lo, hi)),
("/k/Foo.kext/", spec("/k/Foo.kext/", lo, hi)),
("Foo.kext,25.4.0", spec("Foo.kext", "25.4.0", hi)),
(
"/k/Foo.kext,25.4.0,25.6.0",
spec("/k/Foo.kext", "25.4.0", "25.6.0"),
),
("Foo.kext,,25.6.0", spec("Foo.kext", lo, "25.6.0")),
("Foo.kext, 25.4.0 ,", spec("Foo.kext", "25.4.0", hi)),
("/a,b/Foo.kext", spec("/a,b/Foo.kext", lo, hi)),
(
"/a,b/Foo.kext,25.4.0,25.99.99",
spec("/a,b/Foo.kext", "25.4.0", "25.99.99"),
),
("Foo.kext,9.0.0", spec("Foo.kext", "9.0.0", hi)),
] {
assert_eq!(parse(s), Ok(want), "{s}");
}
}
#[test]
fn refused() {
for (s, says) in [
("Foo", "not a .kext bundle"),
("Foo.kext,25.4.0,25.99.99,1", "not a .kext bundle"),
("Foo.kext,25.4", "not a Darwin version"),
("Foo.kext,25.4.0.1", "not a Darwin version"),
("Foo.kext,25.x.0", "not a Darwin version"),
("Foo.kext,+25.4.0", "not a Darwin version"),
("Foo.kext,25.6.0,25.4.0", "past 25.4.0"),
("Foo.kext,26.0.0", "past 25.99.99"),
] {
let e = parse(s).unwrap_err();
assert!(e.contains(says), "{s}: {e}");
}
}
/// A bundle in a new folder under the system's temporary one, with `files` by their path
/// in it; removed when dropped.
pub(crate) struct Bundle {
pub path: PathBuf,
dir: PathBuf,
}
impl Bundle {
pub(crate) fn new(name: &str, files: &[(&str, &[u8])]) -> Bundle {
let mut tag = [0u8; 8];
getrandom::fill(&mut tag).unwrap();
let tag: String = tag.iter().map(|b| format!("{b:02x}")).collect();
let dir = std::env::temp_dir().join(format!("reims-util-test-{tag}"));
let path = dir.join(name);
for (p, d) in files {
let f = path.join(p);
std::fs::create_dir_all(f.parent().unwrap()).unwrap();
std::fs::write(f, d).unwrap();
}
std::fs::create_dir_all(&path).unwrap();
Bundle { path, dir }
}
pub(crate) fn spec(&self) -> Spec {
parse(self.path.to_str().unwrap()).unwrap()
}
}
impl Drop for Bundle {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.dir);
}
}
/// An Info.plist: its identifier, executable and libraries.
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 {
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
}
/// A kext as `read` gives it, for `check`.
fn kext(bundle: &str, id: &str, libraries: &[&str]) -> Kext {
Kext {
bundle: bundle.into(),
identifier: id.into(),
executable: None,
libraries: libraries.iter().map(|l| l.to_string()).collect(),
min_kernel: config::KEXT_MIN_KERNEL.into(),
max_kernel: config::KEXT_MAX_KERNEL.into(),
files: Vec::new(),
}
}
#[test]
fn read_with_code() {
let plist = info("t.loader", Some("Loader"), &["as.vit9696.Lilu"]);
let b = Bundle::new(
"Loader.kext",
&[
("Contents/Info.plist", &plist),
("Contents/MacOS/Loader", &[0xcf]),
("Contents/Resources/en.lproj/x.strings", b"x"),
(".DS_Store", b"junk"),
("Contents/._Info.plist", b"junk"),
],
);
let s = parse(&format!("{},25.4.0", b.path.display())).unwrap();
let k = read(&s).unwrap();
assert_eq!(k.bundle, "Loader.kext");
assert_eq!(k.identifier, "t.loader");
assert_eq!(k.executable.as_deref(), Some("Loader"));
assert_eq!(k.libraries, ["as.vit9696.Lilu"]);
assert_eq!(
(k.min_kernel.as_str(), k.max_kernel.as_str()),
("25.4.0", config::KEXT_MAX_KERNEL)
);
let paths: Vec<&str> = k.files.iter().map(|(p, _)| p.as_str()).collect();
assert_eq!(
paths,
[
"Contents/Info.plist",
"Contents/MacOS/Loader",
"Contents/Resources/en.lproj/x.strings"
]
);
}
#[test]
fn read_codeless() {
let plist = info("t.shim", None, &[]);
let b = Bundle::new("Shim.kext", &[("Contents/Info.plist", &plist)]);
let k = read(&b.spec()).unwrap();
assert_eq!(k.executable, None);
assert_eq!(k.files.len(), 1);
}
#[test]
fn read_refused() {
let plist = info("t.x", Some("X"), &[]);
let b = Bundle::new("X.kext", &[("Contents/Info.plist", &plist)]);
let e = format!("{:#}", read(&b.spec()).unwrap_err());
assert!(e.contains("no Contents/MacOS/X"), "{e}");
let b = Bundle::new("Y.kext", &[("Contents/MacOS/Y", &[0xcf])]);
let e = format!("{:#}", read(&b.spec()).unwrap_err());
assert!(e.contains("no Contents/Info.plist"), "{e}");
let b = Bundle::new(
"Z.kext",
&[("Contents/Info.plist", &info("", None, &[])[..])],
);
let e = format!("{:#}", read(&b.spec()).unwrap_err());
assert!(e.contains("no CFBundleIdentifier"), "{e}");
let mut d = plist::Dictionary::new();
d.insert("CFBundleExecutable".into(), "Z".into());
let mut v = Vec::new();
plist::Value::Dictionary(d).to_writer_xml(&mut v).unwrap();
let b = Bundle::new("Z.kext", &[("Contents/Info.plist", &v)]);
let e = format!("{:#}", read(&b.spec()).unwrap_err());
assert!(e.contains("no CFBundleIdentifier"), "{e}");
let e = format!(
"{:#}",
read(&spec("/nonexistent/N.kext", "1.0.0", "1.0.0")).unwrap_err()
);
assert!(e.contains("read /nonexistent/N.kext"), "{e}");
}
#[test]
fn checked_against_the_image() {
let own = [LILU, REIMS_VGPU];
let ok = [
kext("Loader.kext", "t.loader", &["as.vit9696.Lilu"]),
kext("Shim.kext", "t.shim", &["com.apple.kpi.iokit"]),
kext("Gfx.kext", "t.gfx", &["t.shim", "t.loader", "t.gfx"]),
];
check(&own, true, &ok).unwrap();
check(&own, true, &[]).unwrap();
check(&own, false, &[]).unwrap();
let refused = |own_in: bool, added: &[Kext], says: &str| {
let e = check(&own, own_in, added).unwrap_err().to_string();
assert!(e.contains(says), "{says}: {e}");
};
refused(
true,
&[kext("Lilu.kext", "t.other", &[])],
"carries its own Lilu.kext: leave Lilu.kext out",
);
refused(
true,
&[kext("lilu.KEXT", "t.other", &[])],
"carries its own Lilu.kext: leave lilu.KEXT out",
);
refused(
true,
&[kext("L.kext", "as.vit9696.Lilu", &[])],
"L.kext is as.vit9696.Lilu, as the image's own Lilu.kext is",
);
refused(
true,
&[kext("A.kext", "t.a", &[]), kext("A.kext", "t.b", &[])],
"A.kext is given twice",
);
refused(
true,
&[kext("A.kext", "t.a", &[]), kext("a.kext", "t.b", &[])],
"A.kext and a.kext are one name",
);
refused(
true,
&[kext("A.kext", "t.a", &[]), kext("B.kext", "t.a", &[])],
"A.kext and B.kext are both t.a",
);
refused(
true,
&[kext("A.kext", "t.a", &["t.b"]), kext("B.kext", "t.b", &[])],
"A.kext links against B.kext (t.b), which comes after it: give B.kext first",
);
refused(
false,
&[kext("Loader.kext", "t.loader", &["as.vit9696.Lilu"])],
"Loader.kext links against Lilu.kext (as.vit9696.Lilu), which --no-kexts leaves out",
);
// With --no-kexts, a Lilu of one's own goes in, ahead of its plugins.
let own_lilu = [
kext("Lilu.kext", "as.vit9696.Lilu", &[]),
kext("Loader.kext", "t.loader", &["as.vit9696.Lilu"]),
];
check(&own, false, &own_lilu).unwrap();
refused(true, &own_lilu, "carries its own Lilu.kext");
}
}
-312
View File
@@ -1,312 +0,0 @@
//! 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>>> {
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 {
continue;
};
if !bundle.ends_with(".kext") || path.split('/').any(|c| c.starts_with('.')) {
continue;
}
if !names.contains(&bundle) {
bail!(
"kext/{bundle} is not one of the {what} kexts ({})",
names.join(", ")
);
}
bundles.entry(bundle).or_default().push((rel, data));
}
if bundles.is_empty() {
return Ok(Vec::new());
}
let missing: Vec<&str> = names
.iter()
.copied()
.filter(|b| !bundles.contains_key(b))
.collect();
if !missing.is_empty() {
bail!(
"partial {what} set in kext/, without {}: deploy {whole}",
missing.join(", ")
);
}
let mut kexts = Vec::new();
for (bundle, files) in bundles {
kexts.push(kext(bundle, files)?);
}
order(kexts, what)
}
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<'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();
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 {what} 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.
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 {
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
@@ -1,12 +0,0 @@
/// 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",
];
+117 -98
View File
@@ -13,9 +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; after them, the seven apv-arm64-port kexts
//! (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;
//! x86-64 driver and its Metal plugin hardcode; after them, the kexts given with `--add-kext`
//! (added.rs), in their order and on the Darwin versions given; 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;
@@ -26,7 +26,7 @@
//! - the picker hidden, so OpenCore boots the default entry, unless asked to show it;
//! - the SMBIOS identity (smbios.rs), and the picker's timeout and boot arguments.
use super::apv_arm64_port::Kext as PortKext;
use super::added;
use super::smbios::Smbios;
use anyhow::{Context, Result, bail};
use plist::{Dictionary, Value};
@@ -48,34 +48,34 @@ pub fn drivers(o: &Options) -> Vec<&'static str> {
d
}
/// A kext the image carries in `EFI/OC/Kexts`: its bundle, and the executable in its
/// `Contents/MacOS`.
/// A kext of reims-util's own in `EFI/OC/Kexts`: its bundle, its `CFBundleIdentifier`, and the
/// executable in its `Contents/MacOS`.
pub struct Kext {
pub bundle: &'static str,
pub identifier: &'static str,
pub executable: &'static str,
}
pub const LILU: Kext = Kext {
bundle: "Lilu.kext",
identifier: "as.vit9696.Lilu",
executable: "Lilu",
};
/// Lilu's plugin, built from kext/.
pub const REIMS_VGPU: Kext = Kext {
bundle: "ReimsVgpu.kext",
identifier: "com.steelbrain.ReimsVgpu",
executable: "ReimsVgpu",
};
/// 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";
/// 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";
/// reims-util's kexts, in the order they load.
pub const OWN: [Kext; 2] = [LILU, REIMS_VGPU];
/// reims-util's kexts load on Darwin 25 alone, macOS 26, whose GPU driver ReimsVgpu patches; so
/// does a kext added with no bounds of its own.
pub const KEXT_MIN_KERNEL: &str = "25.0.0";
pub const KEXT_MAX_KERNEL: &str = "25.99.99";
/// 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.
@@ -99,18 +99,13 @@ pub struct Options {
pub graphical_picker: bool,
/// The picker at every boot, or none: OpenCore boots the default entry.
pub show_picker: bool,
/// Lilu and ReimsVgpu (and the set `make` is given), for macOS 26.
/// Lilu and ReimsVgpu, for macOS 26.
pub kexts: bool,
}
/// The config.plist for `o`, from the release's `sample`. With `o.kexts`, `port`
/// (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>> {
/// The config.plist for `o`, from the release's `sample`. `added` (added.rs) loads after Lilu and
/// ReimsVgpu, or alone when `o.kexts` leaves them out.
pub fn make(sample: &[u8], o: &Options, added: &[added::Kext]) -> Result<Vec<u8>> {
let mut root: Value = plist::from_bytes(sample).context("read Sample.plist")?;
let c = root
.as_dictionary_mut()
@@ -154,11 +149,7 @@ pub fn make(
Value::Dictionary(Dictionary::new()),
)?;
let kexts = if o.kexts {
kernel_add(&template(c, &["Kernel", "Add"])?, port, video)
} else {
Vec::new()
};
let kexts = kernel_add(&template(c, &["Kernel", "Add"])?, o.kexts, added);
set(c, &["Kernel"], "Add", Value::Array(kexts))?;
set(c, &["Kernel"], "Block", Value::Array(vec![]))?;
set(c, &["Kernel"], "Force", Value::Array(vec![]))?;
@@ -320,41 +311,37 @@ pub fn make(
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, then `video` for macOS 26.7.
fn kernel_add(template: &Dictionary, port: &[PortKext<'_>], video: &[PortKext<'_>]) -> Vec<Value> {
let mut add = vec![
(
/// Kernel > Add's entries, made from the sample's first: with `own`, Lilu and ReimsVgpu for
/// macOS 26, then `added`, in its order, on the Darwin versions each was given.
fn kernel_add(template: &Dictionary, own: bool, added: &[added::Kext]) -> Vec<Value> {
let mut add = Vec::new();
if own {
add.push((
LILU.bundle,
Some(LILU.executable),
KEXT_MIN_KERNEL,
"Patch engine".to_string(),
),
(
KEXT_MAX_KERNEL,
"Patch engine",
));
add.push((
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")),
KEXT_MAX_KERNEL,
"reims-vgpu's GPU features on macOS 26",
));
}
for k in video {
for k in added {
add.push((
k.bundle,
&k.bundle,
k.executable.as_deref(),
VIDEO_MIN_KERNEL,
format!("reims-vgpu-video's {}", k.bundle.trim_end_matches(".kext")),
&k.min_kernel,
&k.max_kernel,
&k.identifier,
));
}
add.into_iter()
.map(|(bundle, executable, min_kernel, comment)| {
.map(|(bundle, executable, min_kernel, max_kernel, comment)| {
let mut e = template.clone();
e.insert("Arch".into(), "x86_64".into());
e.insert("BundlePath".into(), bundle.into());
@@ -363,7 +350,7 @@ fn kernel_add(template: &Dictionary, port: &[PortKext<'_>], video: &[PortKext<'_
// 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("MaxKernel".into(), max_kernel.into());
e.insert("MinKernel".into(), min_kernel.into());
e.insert("PlistPath".into(), "Contents/Info.plist".into());
Value::Dictionary(e)
@@ -418,8 +405,6 @@ fn unhex(s: &str) -> Result<Vec<u8>> {
#[cfg(test)]
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();
@@ -428,6 +413,18 @@ mod tests {
.collect()
}
fn added(bundle: &str, executable: Option<&str>, min: &str, max: &str) -> added::Kext {
let plist = added::tests::info(&format!("t.{bundle}"), executable, &[]);
let mut files: Vec<(&str, &[u8])> = vec![("Contents/Info.plist", &plist)];
let path = executable.map(|x| format!("Contents/MacOS/{x}"));
if let Some(p) = &path {
files.push((p, &[0xcf]));
}
let b = added::tests::Bundle::new(&format!("{bundle}.kext"), &files);
let s = added::parse(&format!("{},{min},{max}", b.path.display())).unwrap();
added::read(&s).unwrap()
}
#[test]
fn kernel_add_entries() {
let mut template = Dictionary::new();
@@ -436,56 +433,78 @@ mod tests {
let keys = [
"BundlePath",
"ExecutablePath",
"PlistPath",
"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)
let want = |b: &str, x: &str, min: &str, max: &str| {
[b, x, "Contents/Info.plist", min, max, "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"),
]
let entries = |own: bool, added: &[added::Kext]| -> Vec<[String; 6]> {
kernel_add(&template, own, added)
.iter()
.map(|e| {
assert_eq!(e.as_dictionary().unwrap()["Enabled"], Value::Boolean(true));
fields(e, &keys).try_into().unwrap()
})
.collect()
};
let lilu = want(
"Lilu.kext",
"Contents/MacOS/Lilu",
KEXT_MIN_KERNEL,
KEXT_MAX_KERNEL,
);
let reims = want(
"ReimsVgpu.kext",
"Contents/MacOS/ReimsVgpu",
KEXT_MIN_KERNEL,
KEXT_MAX_KERNEL,
);
// 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()));
// Lilu and ReimsVgpu alone, or nothing.
assert_eq!(entries(true, &[]), [lilu.clone(), reims.clone()]);
assert!(entries(false, &[]).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 "));
}
// Added kexts follow, in their order, on their own bounds; one with no code has no path.
let set = [
added("Loader", Some("Loader"), "25.4.0", "25.99.99"),
added("Shim", None, "25.4.0", "25.6.0"),
added("Gfx", Some("ReimsGraphics"), "25.0.0", "25.99.99"),
];
let tail = [
want("Loader.kext", "Contents/MacOS/Loader", "25.4.0", "25.99.99"),
want("Shim.kext", "", "25.4.0", "25.6.0"),
want(
"Gfx.kext",
"Contents/MacOS/ReimsGraphics",
"25.0.0",
"25.99.99",
),
];
let mut all = vec![lilu, reims];
all.extend(tail.clone());
assert_eq!(entries(true, &set), all);
assert_eq!(entries(false, &set), tail);
let e = &kernel_add(&template, true, &set)[2];
assert_eq!(fields(e, &["Comment"]), ["t.Loader"]);
}
/// ReimsVgpu's identifier here is the one its Info.plist gives.
#[test]
fn own_identifiers() {
let info: Dictionary = plist::from_bytes(include_bytes!(
"../../kext/ReimsVgpu.kext/Contents/Info.plist"
))
.unwrap();
assert_eq!(
info["CFBundleIdentifier"].as_string(),
Some(REIMS_VGPU.identifier)
);
assert_eq!(
info["CFBundleExecutable"].as_string(),
Some(REIMS_VGPU.executable)
);
}
}
+25 -33
View File
@@ -1,15 +1,14 @@
//! 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), 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.
//! (kext/), the kexts given with `--add-kext` (added.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 added;
pub mod config;
pub mod smbios;
pub mod video;
use crate::cache::{self, Pinned};
use crate::image::{self, Data, Format};
@@ -61,11 +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,
/// 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,
/// Kexts to load after Lilu and ReimsVgpu, in this order.
pub add_kexts: Vec<added::Spec>,
/// Where OVMF's files go, or None to write none.
pub ovmf_dir: Option<PathBuf>,
}
@@ -76,28 +72,23 @@ 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,
/// Whether the image carries reims-vgpu-video's kexts.
pub video: bool,
/// The kexts the image carries, by their bundle names, in the order they load.
pub kexts: Vec<String>,
pub ovmf: Option<crate::ovmf::Outputs>,
}
pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
// Read first, so a kext that can't go in fails before anything is downloaded.
let added = o
.add_kexts
.iter()
.map(added::read)
.collect::<Result<Vec<_>>>()?;
added::check(&config::OWN, o.config.kexts, &added)?;
let zip_path = cache::fetch(&RELEASE, r)?;
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 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)?;
@@ -106,15 +97,18 @@ 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, &video)?;
let mut files = files(&zip_path, &o.config, &added)?;
files.extend(resources(&resources_path, o.config.graphical_picker)?);
let mut kext_names = Vec::new();
if let Some(p) = &lilu_path {
files.extend(kexts(p)?);
kext_names.extend(config::OWN.iter().map(|k| k.bundle.to_string()));
}
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()));
for k in added {
for (p, d) in k.files {
files.push((format!("EFI/OC/Kexts/{}/{p}", k.bundle), d));
}
kext_names.push(k.bundle);
}
let files: Vec<(String, Data)> = files
.into_iter()
@@ -142,8 +136,7 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
format,
opencore: VERSION,
smbios: o.config.smbios.clone(),
apv_arm64_port: !port.is_empty(),
video: !video.is_empty(),
kexts: kext_names,
ovmf,
})
}
@@ -152,8 +145,7 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result<Outputs> {
fn files(
zip_path: &Path,
c: &config::Options,
port: &[apv_arm64_port::Kext<'_>],
video: &[apv_arm64_port::Kext<'_>],
added: &[added::Kext],
) -> Result<Vec<(String, Vec<u8>)>> {
let f =
std::fs::File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?;
@@ -186,7 +178,7 @@ fn files(
let sample = read("Docs/Sample.plist")?;
files.push((
"EFI/OC/config.plist".into(),
config::make(&sample, c, port, video)?,
config::make(&sample, c, added)?,
));
files.push((
format!("EFI/OC/ACPI/{}", acpi::FILE_NAME),
-107
View File
@@ -1,107 +0,0 @@
//! 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
@@ -1,8 +0,0 @@
/// 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",
];
+2 -2
View File
@@ -273,8 +273,8 @@ impl App {
text_picker: !form.toggle(7),
show_picker: form.toggle(8),
no_kexts: false,
no_apv_arm64_port: false,
no_video: false,
add_kext: Vec::new(),
_retired: 0,
no_ovmf: !form.toggle(3),
ovmf_dir: None,
};