blob: bc090c792bf787bef4c4888ca97d94a1e3025ee8 [file] [log] [blame] [view]
Andrew Scull23042042018-08-22 17:44:56 +01001# Getting started
2
Andrew Walbranb7849972019-11-15 15:23:43 +00003[TOC]
4
Andrew Scull23042042018-08-22 17:44:56 +01005## Getting the source code
6
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +01007```shell
Andrew Scullcd3e77e2018-12-19 15:35:40 +00008git 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)
Andrew Scull23042042018-08-22 17:44:56 +01009```
10
11To upload a commit for review:
12
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010013```shell
Andrew Scull23042042018-08-22 17:44:56 +010014git push origin HEAD:refs/for/master
15```
Andrew Walbran0ba13bb2019-05-13 10:57:25 +010016
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010017Browse source at https://hafnium.googlesource.com/hafnium. Review CLs at
18https://hafnium-review.googlesource.com/.
Andrew Walbran0ba13bb2019-05-13 10:57:25 +010019
Andrew Scullb81de702019-07-09 13:46:50 +010020See details of [how to contribute](../CONTRIBUTING.md).
Andrew Scull23042042018-08-22 17:44:56 +010021
22## Compiling the hypervisor
23
Andrew Walbran10276722018-09-10 14:33:18 +010024Install prerequisites:
25
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010026```shell
Andrew Walbran45ac1d22019-10-21 16:54:24 +010027sudo apt install make libssl-dev flex bison
Andrew Walbran10276722018-09-10 14:33:18 +010028```
29
Andrew Scull23e93a82018-10-26 14:56:04 +010030By default, the hypervisor is built with clang for a few target platforms along
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000031with tests. Each project in the `project` directory specifies a root
32configurations of the build. Adding a project is the preferred way to extend
33support to new platforms. The target project that is built is selected by the
34`PROJECT` make variable, the default project is 'reference'.
Andrew Scull23042042018-08-22 17:44:56 +010035
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010036```shell
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000037make PROJECT=<project_name>
Andrew Scull23042042018-08-22 17:44:56 +010038```
39
David Brazdil5ecf75f2019-07-21 10:39:47 +020040The compiled image can be found under `out/<project>`, for example the QEMU
41image is at `out/reference/qemu_aarch64_clang/hafnium.bin`.
Andrew Scull23042042018-08-22 17:44:56 +010042
Andrew Scull23042042018-08-22 17:44:56 +010043## Running on QEMU
44
45You will need at least version 2.9 for QEMU. The following command line can be
46used to run Hafnium on it:
47
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010048```shell
Andrew Scull25d897e2019-06-27 12:57:02 +010049qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a57 -nographic -machine virtualization=true -kernel out/reference/qemu_aarch64_clang/hafnium.bin
Andrew Scull23042042018-08-22 17:44:56 +010050```
51
52Though it is admittedly not very useful because it doesn't have any virtual
53machines to run. Follow the [Hafnium RAM disk](HafniumRamDisk.md) instructions
54to create an initial RAM disk for Hafnium with Linux as the primary VM.
55
David Brazdil0dbb41f2019-09-09 18:03:35 +010056Next, you need to create a manifest which will describe the VM to Hafnium.
57Follow the [Manifest](Manifest.md) instructions and build a DTBO with:
58```
59/dts-v1/;
60/plugin/;
61
62&{/} {
63 hypervisor {
Serban Constantinescubeb0ec72019-11-07 13:42:56 +000064 compatible = "hafnium,hafnium";
David Brazdil0dbb41f2019-09-09 18:03:35 +010065 vm1 {
66 debug_name = "Linux VM";
Andrew Scull72b43c02019-09-18 13:53:45 +010067 kernel_filename = "vmlinuz";
Serban Constantinescubeb0ec72019-11-07 13:42:56 +000068 ramdisk_filename = "initrd.img";
David Brazdil0dbb41f2019-09-09 18:03:35 +010069 };
70 };
71};
72```
73
74Dump the DTB used by QEMU:
75```shell
76qemu-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
77```
78and follow instructions in [Manifest](Manifest.md) to overlay it with the manifest.
79
Andrew Scull23042042018-08-22 17:44:56 +010080The following command line will run Hafnium, with the RAM disk just created,
81which will then boot into the primary Linux VM:
82
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010083```shell
Shaked Flurd1cfe612019-11-27 15:14:10 +000084qemu-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
Andrew Scull23042042018-08-22 17:44:56 +010085```
86
87## Running tests
88
89After building, presubmit tests can be run with the following command line:
90
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010091```shell
Andrew Walbran219ceaf2020-01-10 15:44:29 +000092./kokoro/test.sh
Andrew Scull23042042018-08-22 17:44:56 +010093```
94
95Read about [testing](Testing.md) for more details about the tests.