diff --git a/README.md b/README.md index a3a7787..ca009c6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.rs b/build.rs deleted file mode 100644 index dcf6b3c..0000000 --- a/build.rs +++ /dev/null @@ -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, String> { - let mut v = std::fs::read_dir(dir) - .and_then(|r| r.collect::, _>>()) - .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) -> 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(()) -} diff --git a/kext/APVDisplayPort.kext/Contents/Info.plist b/kext/APVDisplayPort.kext/Contents/Info.plist deleted file mode 100644 index 053771b..0000000 --- a/kext/APVDisplayPort.kext/Contents/Info.plist +++ /dev/null @@ -1,69 +0,0 @@ - - - - - BuildMachineOSBuild - 23A344017 - CFBundleDevelopmentRegion - en - CFBundleExecutable - APVDisplayPort - CFBundleIdentifier - com.apple.driver.APVDisplayPort - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - com.apple.driver.APVDisplayPort - CFBundlePackageType - KEXT - CFBundleShortVersionString - 15.0.0 - CFBundleSupportedPlatforms - - MacOSX - - CFBundleVersion - 15.0.0 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - - DTPlatformName - macosx - DTPlatformVersion - 26.7 - DTSDKBuild - 25G221 - DTSDKName - macosx26.7.internal - DTXcode - 2630 - DTXcodeBuild - 17E6107 - LSMinimumSystemVersion - 26.7 - NSHumanReadableCopyright - Copyright © 2018-2025 Apple Inc. All rights reserved. - OSBundleLibraries - - com.apple.driver.AppleParavirtGPUIOGPUFamily - 15.0.0 - com.apple.iokit.IOPCIFamily - 1.0.0b1 - com.apple.iokit.IOSurface - 87.0 - com.apple.kpi.iokit - 16.7 - com.apple.kpi.libkern - 16.7 - com.apple.kpi.mach - 9.0.0b1 - com.apple.kpi.private - 10.0.0d3 - com.steelbrain.paravirt.AppleGraphicsDeviceControlBridge - 1.0.0 - com.steelbrain.paravirt.IOGraphicsFamilyBridge - 1.0.0 - - - diff --git a/kext/APVDisplayPort.kext/Contents/MacOS/APVDisplayPort b/kext/APVDisplayPort.kext/Contents/MacOS/APVDisplayPort deleted file mode 100644 index b3a66ec..0000000 Binary files a/kext/APVDisplayPort.kext/Contents/MacOS/APVDisplayPort and /dev/null differ diff --git a/kext/AppleGraphicsDeviceControlBridge.kext/Contents/Info.plist b/kext/AppleGraphicsDeviceControlBridge.kext/Contents/Info.plist deleted file mode 100644 index 11a0c67..0000000 --- a/kext/AppleGraphicsDeviceControlBridge.kext/Contents/Info.plist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - AppleGraphicsDeviceControlBridge - CFBundleIdentifier - com.steelbrain.paravirt.AppleGraphicsDeviceControlBridge - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - AppleGraphicsDeviceControlBridge - CFBundlePackageType - KEXT - CFBundleShortVersionString - 1.0.0 - CFBundleVersion - 1.0.0 - OSBundleCompatibleVersion - 1.0.0 - OSBundleLibraries - - com.apple.kpi.libkern - 8.0.0 - com.apple.kpi.mach - 8.0.0 - - OSBundleRequired - Root - - diff --git a/kext/AppleGraphicsDeviceControlBridge.kext/Contents/MacOS/AppleGraphicsDeviceControlBridge b/kext/AppleGraphicsDeviceControlBridge.kext/Contents/MacOS/AppleGraphicsDeviceControlBridge deleted file mode 100755 index 626e942..0000000 Binary files a/kext/AppleGraphicsDeviceControlBridge.kext/Contents/MacOS/AppleGraphicsDeviceControlBridge and /dev/null differ diff --git a/kext/AppleM2ScalerParavirtDriver.kext/Contents/Info.plist b/kext/AppleM2ScalerParavirtDriver.kext/Contents/Info.plist deleted file mode 100644 index df23915..0000000 --- a/kext/AppleM2ScalerParavirtDriver.kext/Contents/Info.plist +++ /dev/null @@ -1,102 +0,0 @@ - - - - - BuildMachineOSBuild - 23A344017 - CFBundleDevelopmentRegion - English - CFBundleExecutable - AppleM2ScalerParavirtDriver - CFBundleGetInfoString - 9.0.5, Copyright Apple Inc. 2023 - CFBundleIdentifier - com.apple.driver.AppleM2ScalerParavirtDriver - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - Apple M2 Scaler Paravirtualized Driver - CFBundlePackageType - KEXT - CFBundleShortVersionString - 1.0.0 - CFBundleSignature - aapl - CFBundleSupportedPlatforms - - MacOSX - - CFBundleVersion - 1.0.0 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - - DTPlatformName - macosx - DTPlatformVersion - 26.7 - DTSDKBuild - 25G221 - DTSDKName - macosx26.7.internal - DTXcode - 2630 - DTXcodeBuild - 17E6107 - IOKitPersonalities - - AppleM2ScalerParavirtDriver - - CFBundleIdentifier - com.apple.driver.AppleM2ScalerParavirtDriver - IOClass - AppleM2ScalerCSCDriver - IOProviderClass - AppleVirtIOTransport - IOVirtIOPrimaryMatch - 0x1a0b106b - - AppleM2ScalerParavirtDriver Transport - - CFBundleIdentifier - com.apple.driver.AppleVirtIO - IOClass - AppleVirtIOPCITransport - IOPCIPrimaryMatch - 0x1a0b106b - IOProviderClass - IOPCIDevice - - - LSMinimumSystemVersion - 26.7 - NSHumanReadableCopyright - Copyright © 2023 Apple Inc. All rights reserved. - OSBundleCompatibleVersion - 1.0 - OSBundleLibraries - - com.apple.driver.AppleVirtIO - 146.40.2 - com.apple.iokit.AppleParavirtIOSurface - 1.0 - com.apple.iokit.IOPCIFamily - 1.0.0b1 - com.apple.iokit.IOSurface - 52.7.0 - com.apple.kpi.bsd - 8.4.1 - com.apple.kpi.iokit - 8.4.1 - com.apple.kpi.libkern - 8.4.1 - com.apple.kpi.mach - 8.4.1 - com.apple.kpi.private - 8.0.0b1 - com.apple.kpi.unsupported - 8.0 - - - diff --git a/kext/AppleM2ScalerParavirtDriver.kext/Contents/MacOS/AppleM2ScalerParavirtDriver b/kext/AppleM2ScalerParavirtDriver.kext/Contents/MacOS/AppleM2ScalerParavirtDriver deleted file mode 100644 index f12950a..0000000 Binary files a/kext/AppleM2ScalerParavirtDriver.kext/Contents/MacOS/AppleM2ScalerParavirtDriver and /dev/null differ diff --git a/kext/AppleParavirtGPUIOGPUFamily.kext/Contents/Info.plist b/kext/AppleParavirtGPUIOGPUFamily.kext/Contents/Info.plist deleted file mode 100644 index fec6b96..0000000 --- a/kext/AppleParavirtGPUIOGPUFamily.kext/Contents/Info.plist +++ /dev/null @@ -1,69 +0,0 @@ - - - - - BuildMachineOSBuild - 23A344017 - CFBundleDevelopmentRegion - en - CFBundleExecutable - AppleParavirtGPUIOGPUFamily - CFBundleIdentifier - com.apple.driver.AppleParavirtGPUIOGPUFamily - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - com.apple.driver.AppleParavirtGPUIOGPUFamily - CFBundlePackageType - KEXT - CFBundleShortVersionString - 15.0.0 - CFBundleSupportedPlatforms - - MacOSX - - CFBundleVersion - 15.0.0 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - - DTPlatformName - macosx - DTPlatformVersion - 26.7 - DTSDKBuild - 25G221 - DTSDKName - macosx26.7.internal - DTXcode - 2630 - DTXcodeBuild - 17E6107 - LSMinimumSystemVersion - 26.7 - NSHumanReadableCopyright - Copyright © 2019-2025 Apple Inc. All rights reserved. - OSBundleCompatibleVersion - 15.0.0 - OSBundleLibraries - - com.apple.iokit.AppleParavirtIOSurface - 1.0 - com.apple.iokit.IOPCIFamily - 1.0.0b1 - com.apple.iokit.IOSurface - 87.0 - com.apple.kpi.iokit - 16.7 - com.apple.kpi.libkern - 16.7 - com.apple.kpi.mach - 9.0.0b1 - com.apple.kpi.private - 10.0.0d3 - com.steelbrain.paravirt.IOGPUFamilyBridge - 1.0.0 - - - diff --git a/kext/AppleParavirtGPUIOGPUFamily.kext/Contents/MacOS/AppleParavirtGPUIOGPUFamily b/kext/AppleParavirtGPUIOGPUFamily.kext/Contents/MacOS/AppleParavirtGPUIOGPUFamily deleted file mode 100644 index 5773b5e..0000000 Binary files a/kext/AppleParavirtGPUIOGPUFamily.kext/Contents/MacOS/AppleParavirtGPUIOGPUFamily and /dev/null differ diff --git a/kext/AppleParavirtGPULoader.kext/Contents/Info.plist b/kext/AppleParavirtGPULoader.kext/Contents/Info.plist deleted file mode 100644 index abe7583..0000000 --- a/kext/AppleParavirtGPULoader.kext/Contents/Info.plist +++ /dev/null @@ -1,53 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - AppleParavirtGPULoader - CFBundleIdentifier - com.steelbrain.paravirt.AppleParavirtGPULoader - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - AppleParavirtGPULoader - CFBundlePackageType - KEXT - CFBundleShortVersionString - 1.0.0 - CFBundleVersion - 1.0.0 - IOKitPersonalities - - AppleParavirtGPULoader - - CFBundleIdentifier - com.steelbrain.paravirt.AppleParavirtGPULoader - IOClass - AppleParavirtGPULoader - IOMatchCategory - AppleParavirtGPULoader - IOProviderClass - IOResources - IOResourceMatch - IOKit - - - OSBundleLibraries - - as.vit9696.Lilu - 1.7.2 - com.apple.kpi.bsd - 12.0.0 - com.apple.kpi.iokit - 12.0.0 - com.apple.kpi.libkern - 12.0.0 - com.apple.kpi.mach - 12.0.0 - - OSBundleRequired - Root - - diff --git a/kext/AppleParavirtGPULoader.kext/Contents/MacOS/AppleParavirtGPULoader b/kext/AppleParavirtGPULoader.kext/Contents/MacOS/AppleParavirtGPULoader deleted file mode 100755 index fab5756..0000000 Binary files a/kext/AppleParavirtGPULoader.kext/Contents/MacOS/AppleParavirtGPULoader and /dev/null differ diff --git a/kext/AppleParavirtIOSurface.kext/Contents/Info.plist b/kext/AppleParavirtIOSurface.kext/Contents/Info.plist deleted file mode 100644 index 65cfb83..0000000 --- a/kext/AppleParavirtIOSurface.kext/Contents/Info.plist +++ /dev/null @@ -1,69 +0,0 @@ - - - - - BuildMachineOSBuild - 23A344017 - CFBundleDevelopmentRegion - en - CFBundleExecutable - AppleParavirtIOSurface - CFBundleIdentifier - com.apple.iokit.AppleParavirtIOSurface - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - com.apple.iokit.AppleParavirtIOSurface - CFBundlePackageType - KEXT - CFBundleShortVersionString - 15.0.0 - CFBundleSupportedPlatforms - - MacOSX - - CFBundleVersion - 15.0.0 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - - DTPlatformName - macosx - DTPlatformVersion - 26.7 - DTSDKBuild - 25G221 - DTSDKName - macosx26.7.internal - DTXcode - 2630 - DTXcodeBuild - 17E6107 - LSMinimumSystemVersion - 26.7 - NSHumanReadableCopyright - Copyright © 2019-2025 Apple Inc. All rights reserved. - OSBundleCompatibleVersion - 1.0 - OSBundleLibraries - - com.apple.iokit.IOPCIFamily - 1.0.0b1 - com.apple.iokit.IOSurface - 87.0 - com.apple.kpi.bsd - 9.0.0b1 - com.apple.kpi.iokit - 9.0.0b1 - com.apple.kpi.libkern - 9.0.0b1 - com.apple.kpi.mach - 9.0.0b1 - com.apple.kpi.private - 9.0.0b1 - com.apple.kpi.unsupported - 9.0.0b1 - - - diff --git a/kext/AppleParavirtIOSurface.kext/Contents/MacOS/AppleParavirtIOSurface b/kext/AppleParavirtIOSurface.kext/Contents/MacOS/AppleParavirtIOSurface deleted file mode 100644 index ef9c1c4..0000000 Binary files a/kext/AppleParavirtIOSurface.kext/Contents/MacOS/AppleParavirtIOSurface and /dev/null differ diff --git a/kext/AppleVideoToolboxParavirtualization.kext/Contents/Info.plist b/kext/AppleVideoToolboxParavirtualization.kext/Contents/Info.plist deleted file mode 100644 index 62f879f..0000000 --- a/kext/AppleVideoToolboxParavirtualization.kext/Contents/Info.plist +++ /dev/null @@ -1,88 +0,0 @@ - - - - - BuildMachineOSBuild - 23A344017 - CFBundleDevelopmentRegion - en - CFBundleExecutable - AppleVideoToolboxParavirtualization - CFBundleIdentifier - com.apple.driver.AppleVideoToolboxParavirtualization - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - com.apple.driver.AppleVideoToolboxParavirtualization - CFBundlePackageType - KEXT - CFBundleShortVersionString - 15.0.0 - CFBundleSupportedPlatforms - - MacOSX - - CFBundleVersion - 15.0.0 - DTCompiler - com.apple.compilers.llvm.clang.1_0 - DTPlatformBuild - - DTPlatformName - macosx - DTPlatformVersion - 26.7 - DTSDKBuild - 25G221 - DTSDKName - macosx26.7.internal - DTXcode - 2630 - DTXcodeBuild - 17E6107 - IOKitPersonalities - - AppleVideoToolboxParavirtualization - - CFBundleIdentifier - com.apple.driver.AppleVideoToolboxParavirtualization - IOClass - AppleVideoToolboxParavirtualizationDriver - IOProviderClass - AppleVirtIOTransport - IOUserClientClass - AppleVideoToolboxParavirtualizationUserClient - IOVirtIOPrimaryMatch - 0x1a03106b - - AppleVideoToolboxParavirtualization Transport - - CFBundleIdentifier - com.apple.driver.AppleVirtIO - IOClass - AppleVirtIOPCITransport - IOPCIPrimaryMatch - 0x1a03106b - IOProviderClass - IOPCIDevice - - - LSMinimumSystemVersion - 26.7 - NSHumanReadableCopyright - Copyright © 2022-2025 Apple Inc. All rights reserved. - OSBundleLibraries - - com.apple.driver.AppleVirtIO - 146.40.2 - com.apple.iokit.AppleParavirtIOSurface - 1.0 - com.apple.iokit.IOSurface - 302.9 - com.apple.kpi.iokit - 15.5 - com.apple.kpi.libkern - 15.5 - - - diff --git a/kext/AppleVideoToolboxParavirtualization.kext/Contents/MacOS/AppleVideoToolboxParavirtualization b/kext/AppleVideoToolboxParavirtualization.kext/Contents/MacOS/AppleVideoToolboxParavirtualization deleted file mode 100644 index 7232d24..0000000 Binary files a/kext/AppleVideoToolboxParavirtualization.kext/Contents/MacOS/AppleVideoToolboxParavirtualization and /dev/null differ diff --git a/kext/IOGPUFamilyBridge.kext/Contents/Info.plist b/kext/IOGPUFamilyBridge.kext/Contents/Info.plist deleted file mode 100644 index dd4ee0d..0000000 --- a/kext/IOGPUFamilyBridge.kext/Contents/Info.plist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - IOGPUFamilyBridge - CFBundleIdentifier - com.steelbrain.paravirt.IOGPUFamilyBridge - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - IOGPUFamilyBridge - CFBundlePackageType - KEXT - CFBundleShortVersionString - 1.0.0 - CFBundleVersion - 1.0.0 - OSBundleCompatibleVersion - 1.0.0 - OSBundleLibraries - - com.apple.kpi.libkern - 8.0.0 - com.apple.kpi.mach - 8.0.0 - - OSBundleRequired - Root - - diff --git a/kext/IOGPUFamilyBridge.kext/Contents/MacOS/IOGPUFamilyBridge b/kext/IOGPUFamilyBridge.kext/Contents/MacOS/IOGPUFamilyBridge deleted file mode 100755 index e32fd80..0000000 Binary files a/kext/IOGPUFamilyBridge.kext/Contents/MacOS/IOGPUFamilyBridge and /dev/null differ diff --git a/kext/IOGraphicsFamilyBridge.kext/Contents/Info.plist b/kext/IOGraphicsFamilyBridge.kext/Contents/Info.plist deleted file mode 100644 index e7152c2..0000000 --- a/kext/IOGraphicsFamilyBridge.kext/Contents/Info.plist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - IOGraphicsFamilyBridge - CFBundleIdentifier - com.steelbrain.paravirt.IOGraphicsFamilyBridge - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - IOGraphicsFamilyBridge - CFBundlePackageType - KEXT - CFBundleShortVersionString - 1.0.0 - CFBundleVersion - 1.0.0 - OSBundleCompatibleVersion - 1.0.0 - OSBundleLibraries - - com.apple.kpi.libkern - 8.0.0 - com.apple.kpi.mach - 8.0.0 - - OSBundleRequired - Root - - diff --git a/kext/IOGraphicsFamilyBridge.kext/Contents/MacOS/IOGraphicsFamilyBridge b/kext/IOGraphicsFamilyBridge.kext/Contents/MacOS/IOGraphicsFamilyBridge deleted file mode 100755 index 0bf3057..0000000 Binary files a/kext/IOGraphicsFamilyBridge.kext/Contents/MacOS/IOGraphicsFamilyBridge and /dev/null differ diff --git a/kext/VtWaitPatch.kext/Contents/Info.plist b/kext/VtWaitPatch.kext/Contents/Info.plist deleted file mode 100644 index 853f4a5..0000000 --- a/kext/VtWaitPatch.kext/Contents/Info.plist +++ /dev/null @@ -1,53 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - VtWaitPatch - CFBundleIdentifier - com.steelbrain.VtWaitPatch - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - VtWaitPatch - CFBundlePackageType - KEXT - CFBundleShortVersionString - 0.1.0 - CFBundleVersion - 0.1.0 - IOKitPersonalities - - VtWaitPatch - - CFBundleIdentifier - com.steelbrain.VtWaitPatch - IOClass - VtWaitPatch - IOMatchCategory - VtWaitPatch - IOProviderClass - IOResources - IOResourceMatch - IOKit - - - OSBundleLibraries - - as.vit9696.Lilu - 1.7.2 - com.apple.kpi.bsd - 12.0.0 - com.apple.kpi.iokit - 12.0.0 - com.apple.kpi.libkern - 12.0.0 - com.apple.kpi.mach - 12.0.0 - - OSBundleRequired - Root - - diff --git a/kext/VtWaitPatch.kext/Contents/MacOS/VtWaitPatch b/kext/VtWaitPatch.kext/Contents/MacOS/VtWaitPatch deleted file mode 100755 index d761523..0000000 Binary files a/kext/VtWaitPatch.kext/Contents/MacOS/VtWaitPatch and /dev/null differ diff --git a/src/cli.rs b/src/cli.rs index efe2259..fa57b72 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, + /// 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 { 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, }) } diff --git a/src/opencore/added.rs b/src/opencore/added.rs new file mode 100644 index 0000000..fadc73a --- /dev/null +++ b/src/opencore/added.rs @@ -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 { + 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 { + 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, + /// The bundles its `OSBundleLibraries` name. + libraries: Vec, + pub min_kernel: String, + pub max_kernel: String, + /// Its files, by their path in the bundle. + pub files: Vec<(String, Vec)>, +} + +/// Reads the bundle `s` names. +pub fn read(s: &Spec) -> Result { + 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 = ["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)>) -> 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::, _>>()) + .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 { + 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"); + } +} diff --git a/src/opencore/apv_arm64_port.rs b/src/opencore/apv_arm64_port.rs deleted file mode 100644 index c43c218..0000000 --- a/src/opencore/apv_arm64_port.rs +++ /dev/null @@ -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, - identifier: String, - libraries: Vec, - /// 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>> { - 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>> { - 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> { - 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>, what: &str) -> Result>> { - let ids: BTreeSet = 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 { - 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)> { - 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)]) -> Vec<(&str, &[u8])> { - files - .iter() - .map(|(p, d)| (p.as_str(), d.as_slice())) - .collect() - } - - fn bundles(kexts: &[Kext<'_>]) -> Vec { - 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()); - } -} diff --git a/src/opencore/apv_arm64_port_set.rs b/src/opencore/apv_arm64_port_set.rs deleted file mode 100644 index daec187..0000000 --- a/src/opencore/apv_arm64_port_set.rs +++ /dev/null @@ -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", -]; diff --git a/src/opencore/config.rs b/src/opencore/config.rs index 1ae9353..c84f9c6 100644 --- a/src/opencore/config.rs +++ b/src/opencore/config.rs @@ -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> { +/// 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> { 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 { - 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 { + 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> { #[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 { 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::>(), - [ - 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) + ); } } diff --git a/src/opencore/mod.rs b/src/opencore/mod.rs index 2128eed..5d41841 100644 --- a/src/opencore/mod.rs +++ b/src/opencore/mod.rs @@ -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, /// Where OVMF's files go, or None to write none. pub ovmf_dir: Option, } @@ -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, pub ovmf: Option, } pub fn build(o: &Options, r: &dyn Reporter) -> Result { + // 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::>>()?; + 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 { 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 { 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 { fn files( zip_path: &Path, c: &config::Options, - port: &[apv_arm64_port::Kext<'_>], - video: &[apv_arm64_port::Kext<'_>], + added: &[added::Kext], ) -> Result)>> { 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), diff --git a/src/opencore/video.rs b/src/opencore/video.rs deleted file mode 100644 index 48436e5..0000000 --- a/src/opencore/video.rs +++ /dev/null @@ -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>> { - 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)> { - 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()); - } -} diff --git a/src/opencore/video_set.rs b/src/opencore/video_set.rs deleted file mode 100644 index 574b98a..0000000 --- a/src/opencore/video_set.rs +++ /dev/null @@ -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", -]; diff --git a/src/tui.rs b/src/tui.rs index 3e1861a..fadc7ad 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -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, };