This commit is contained in:
Artur Gurgul 2025-08-26 17:50:38 +02:00
parent 54d4dfcb33
commit 605cfd38f9
8 changed files with 130 additions and 6 deletions

View file

@ -37,6 +37,13 @@ module System
puts os_name
end
def self.qemu_paths
{
code_fd: qemu_code_fd_path,
vars_fd: qemu_vars_fd_path
}
end
def self.arch_to_symbol(arch)
normalize_architecture_string(arch)
end

View file

@ -54,4 +54,12 @@ module DebianSystem
puts "Failed to uninstall some packages."
end
end
def qemu_code_fd_path()
raise "not supported yet"
end
def qemu_vars_fd_path()
raise "not supported yet"
end
end

View file

@ -54,4 +54,23 @@ module MacOSSystem
puts "Failed to uninstall some packages."
end
end
def qemu_code_fd_path()
case arch_to_symbol(arch)
when :arm64
"/opt/homebrew/share/qemu/edk2-aarch64-code.fd"
else
raise "not supported yet"
end
end
def qemu_vars_fd_path()
case arch_to_symbol(arch)
when :arm64
"/opt/homebrew/share/qemu/edk2-arm-vars.fd"
else
raise "not supported yet"
end
end
end

View file

@ -36,6 +36,6 @@ module User
def self.cache_path
"#{ENV["HOME"]}/.cache/dat/"
ENV["DAT_CACHE_PATH"] || "#{ENV["HOME"]}/.cache/dat/"
end
end

View file

@ -66,6 +66,14 @@ module VirtualMachine
if options[:tpm] == nil
options[:tpm] = false
end
unless options[:vars_fd]
options[:vars_fd] = File.join(vm_dir(options), "vars.fd")
end
unless options[:code_fd]
options[:code_fd] = File.join(vm_dir(options), "code.fd")
end
end
def self.archive(options)
@ -97,8 +105,11 @@ module VirtualMachine
Qemu.launch(
options[:arch],
disk_img_path,
code_fd: options[:code_fd],
vars_fd: options[:vars_fd],
cpus: [1, System.cpus - 2].max,
detach: options[:detached]
detach: options[:detached],
tpm: options[:tpm]
)
end
@ -117,6 +128,8 @@ module VirtualMachine
Qemu.launch(
options[:arch],
disk_img_path,
code_fd: options[:code_fd],
vars_fd: options[:vars_fd],
cpus: [1, System.cpus - 2].max,
cdrom: path,
detach: options[:detached],

View file

@ -91,20 +91,33 @@ module Qemu
defaults[:display] = DisplayMode.fullscreen
defaults[:display] = DisplayMode.window
defaults[:display] = DisplayMode.none
# defaults[:display] = DisplayMode.none
opts = defaults.merge(options)
puts options
puts opts
qemu = qemu_bin_for(arch)
args = []
if System::OS == :macos && arch == :arm64
# args += ["-bios", "/opt/homebrew/share/qemu/edk2-aarch64-code.fd"]
# cp /opt/homebrew/share/qemu/edk2-arm-vars.fd ~/edk2-arm-vars.fd
args += ["-drive", "if=pflash,format=raw,unit=0,readonly=on,file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd"]
args += ["-drive", "if=pflash,format=raw,unit=1,file=/Users/agurgul/edk2-arm-vars.fd"]
unless File.exist?(opts[:vars_fd])
#System.qemu_paths
FileUtils.cp(System.qemu_vars_fd_path, opts[:vars_fd])
end
unless File.exist?(opts[:code_fd])
FileUtils.cp(System.qemu_code_fd_path, opts[:code_fd])
end
args += ["-drive", "if=pflash,format=raw,unit=0,readonly=on,file=#{opts[:code_fd]}"]
args += ["-drive", "if=pflash,format=raw,unit=1,file=#{opts[:vars_fd]}"]
if opts[:display] == DisplayMode::none
port = 2222
@ -181,6 +194,9 @@ module Qemu
# brew install swtpm
# swtpm socket --tpm2 --ctrl type=unixio,path=./tpm/tpm.sock --tpmstate dir=./tpm --daemon
["swtpm", "socket", "--tpm2", "--ctrl", "type=unixio,path=./tpm/tpm.sock", "--tpmstate", "dir=./tpm"]
# args += ["-chardev", "socket,id=chrtpm,path=/Users/agurgul/Downloads/tpm/tpm.sock"]
# args += ["-tpmdev", "emulator,id=tpm0,chardev=chrtpm"]
# args += ["-device", "tpm-crb-device,tpmdev=tpm0"]
@ -190,6 +206,9 @@ module Qemu
#args += ["-device", "tpm-tis,tpmdev=tpm0"]
args += ["-device", "tpm-tis-device,tpmdev=tpm0"]
# nic user,ipv6=off,model=rtl8139,mac=84:1b:77:c9:03:a6
# TODO: Shared network on macOS
# -netdev vmnet-shared,id=net0
end
# args += ["-device", "virtio-net,netdev=n0", "-netdev", "user,id=n0"] # user-mode NAT