Getting started

Getting the source code

git clone --recurse-submodules https://hafnium.googlesource.com/hafnium && (cd hafnium && f=`git rev-parse --git-dir`/hooks/commit-msg ; curl -Lo $f https://gerrit-review.googlesource.com/tools/hooks/commit-msg ; chmod +x $f)

To upload a commit for review:

git push origin HEAD:refs/for/master

Browse source at https://hafnium.googlesource.com/hafnium. Review CLs at https://hafnium-review.googlesource.com/.

See details of how to contribute.

Compiling the hypervisor

Install prerequisites:

sudo apt install make libssl-dev flex bison

By default, the hypervisor is built with clang for a few target platforms along with tests. Each project in the project directory specifies a root configurations of the build. Adding a project is the preferred way to extend support to new platforms. The target project that is built is selected by the PROJECT make variable, the default project is ‘reference’.

make PROJECT=<project_name>

The compiled image can be found under out/<project>, for example the QEMU image is at out/reference/qemu_aarch64_clang/hafnium.bin.

Running on QEMU

You will need at least version 2.9 for QEMU. The following command line can be used to run Hafnium on it:

qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a57 -nographic -machine virtualization=true -kernel out/reference/qemu_aarch64_clang/hafnium.bin

Though it is admittedly not very useful because it doesn't have any virtual machines to run. Follow the Hafnium RAM disk instructions to create an initial RAM disk for Hafnium with Linux as the primary VM.

Next, you need to create a manifest which will describe the VM to Hafnium. Follow the Manifest instructions and build a DTBO with:

/dts-v1/;
/plugin/;

&{/} {
	hypervisor {
		vm1 {
			debug_name = "Linux VM";
			kernel_filename = "vmlinuz";
		};
	};
};

Dump the DTB used by QEMU:

qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a57 -nographic -machine virtualization=true -kernel out/reference/qemu_aarch64_clang/hafnium.bin -initrd initrd.img -append "rdinit=/sbin/init" -machine dumpdtb=qemu.dtb

and follow instructions in Manifest to overlay it with the manifest.

The following command line will run Hafnium, with the RAM disk just created, which will then boot into the primary Linux VM:

qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a57 -nographic -machine virtualization=true -kernel out/reference/qemu_aarch64_clang/hafnium.bin -initrd initrd.img -append "rdinit=/sbin/init" -dtb=qemu_with_manifest.dtb

Running tests

After building, presubmit tests can be run with the following command line:

./kokoro/ubuntu/test.sh

Read about testing for more details about the tests.