A simple, zero-configuration script to quickly boot FreeBSD ISO images using QEMU

Add firmware file handling for aarch64 architecture in QEMU startup

+37
+2
src/subcommands/start.ts
··· 1 1 import _ from "lodash"; 2 2 import { getInstanceState, updateInstanceState } from "../state.ts"; 3 + import { setupFirmwareFilesIfNeeded } from "../utils.ts"; 3 4 4 5 export default async function (name: string) { 5 6 const vm = await getInstanceState(name); ··· 53 54 `file=${vm.drivePath},format=${vm.diskFormat},if=virtio`, 54 55 ], 55 56 ), 57 + ...await setupFirmwareFilesIfNeeded(), 56 58 ], 57 59 stdin: "inherit", 58 60 stdout: "inherit",
+35
src/utils.ts
··· 97 97 }/FreeBSD-${version}-${arch}-disc1.iso`; 98 98 } 99 99 100 + export async function setupFirmwareFilesIfNeeded(): Promise<string[]> { 101 + if (Deno.build.arch !== "aarch64") { 102 + return []; 103 + } 104 + 105 + const brewCmd = new Deno.Command("brew", { 106 + args: ["--prefix", "qemu"], 107 + stdout: "piped", 108 + stderr: "inherit", 109 + }); 110 + const { stdout, success } = await brewCmd.spawn().output(); 111 + 112 + if (!success) { 113 + console.error( 114 + chalk.redBright( 115 + "Failed to get QEMU prefix from Homebrew. Ensure QEMU is installed via Homebrew.", 116 + ), 117 + ); 118 + Deno.exit(1); 119 + } 120 + 121 + const brewPrefix = new TextDecoder().decode(stdout).trim(); 122 + const edk2Aarch64 = `${brewPrefix}/share/qemu/edk2-aarch64-code.fd`; 123 + const edk2VarsAarch64 = "./edk2-arm-vars.fd"; 124 + 125 + await Deno.copyFile( 126 + `${brewPrefix}/share/qemu/edk2-aarch64-vars.fd`, 127 + edk2VarsAarch64, 128 + ); 129 + 130 + return [edk2Aarch64, edk2VarsAarch64]; 131 + } 132 + 100 133 export async function runQemu( 101 134 isoPath: string | null, 102 135 options: Options, 103 136 ): Promise<void> { 104 137 const macAddress = generateRandomMacAddress(); 138 + 105 139 const qemu = Deno.build.arch === "aarch64" 106 140 ? "qemu-system-aarch64" 107 141 : "qemu-system-x86_64"; ··· 140 174 `file=${options.drive},format=${options.diskFormat},if=virtio`, 141 175 ], 142 176 ), 177 + ...await setupFirmwareFilesIfNeeded(), 143 178 ], 144 179 stdin: "inherit", 145 180 stdout: "inherit",