Skip to content

Instantly share code, notes, and snippets.

@rn
Last active September 19, 2017 17:45
Show Gist options
  • Save rn/6fdc5b35d9b90fdbae5cc93c814c2f95 to your computer and use it in GitHub Desktop.
Save rn/6fdc5b35d9b90fdbae5cc93c814c2f95 to your computer and use it in GitHub Desktop.

Build OVMF

mostly from: https://git.alpinelinux.org/cgit/aports/tree/community/edk2/APKBUILD

docker run --rm -ti -v $(pwd):/out alpine
apk add --no-cache bash python2 iasl nasm util-linux-dev gcc musl-dev make g++ git

# need to clone in container as on Mac the host FS is not case sensitive
git clone git@github.com:tianocore/edk2.git

bash
cd edk2

. edksetup.sh
make -j1 -C BaseTools

export WORKSPACE=$PWD
export PACKAGES_PATH=$PWD
export EDK_TOOLS_PATH=$PWD/BaseTools/
export PATH=$PWD/BaseTools/BinWrappers/PosixLike/:$PATH

TOOLCHAIN=GCC49
RELEASE=DEBUG
TARGET_ARCH=X64
OVMFPKG=OvmfPkgX64.dsc
command build -b ${RELEASE} -a ${TARGET_ARCH} -p OvmfPkg/${OVMFPKG} -t ${TOOLCHAIN} -n ${JOBS:-2}

cp Build/OvmfX64/DEBUG_GCC49/FV/OVMF*.fd /out

Test in qemu

qemu-system-x86_64 -machine q35 -nographic -drive if=pflash,format=raw,file=./OVMF.fd

Boot LinuxKit images via EFI

  • build a linuxkit image/initrd
  • move them into a separate directory, sat ./foo
  • rename the kernel to something ending in .efi, say bzImage.efi

Then start qemu:

qemu-system-x86_64 -machine q35 -nographic -drive if=pflash,format=raw,file=./OVMF.fd -drive file=fat:rw:./foo

This turns the directory ./foo into a fat formated hard disk on the fly.

On the EFI shell:

fs0:
bzImage.efi console=ttyS0 efi=debug initrd=/linuxkit-initrd.img

This cds into the the drive fs0 and then executes the kernel (via the EFI stub built into it) with the command line provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment