Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 1 | # Getting started |
| 2 | |
Andrew Walbran | b784997 | 2019-11-15 15:23:43 +0000 | [diff] [blame] | 3 | [TOC] |
| 4 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 5 | ## Getting the source code |
| 6 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 7 | ```shell |
Andrew Scull | cd3e77e | 2018-12-19 15:35:40 +0000 | [diff] [blame] | 8 | 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) |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 9 | ``` |
| 10 | |
| 11 | To upload a commit for review: |
| 12 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 13 | ```shell |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 14 | git push origin HEAD:refs/for/master |
| 15 | ``` |
Andrew Walbran | 0ba13bb | 2019-05-13 10:57:25 +0100 | [diff] [blame] | 16 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 17 | Browse source at https://hafnium.googlesource.com/hafnium. Review CLs at |
| 18 | https://hafnium-review.googlesource.com/. |
Andrew Walbran | 0ba13bb | 2019-05-13 10:57:25 +0100 | [diff] [blame] | 19 | |
Andrew Scull | b81de70 | 2019-07-09 13:46:50 +0100 | [diff] [blame] | 20 | See details of [how to contribute](../CONTRIBUTING.md). |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 21 | |
| 22 | ## Compiling the hypervisor |
| 23 | |
Andrew Walbran | 1027672 | 2018-09-10 14:33:18 +0100 | [diff] [blame] | 24 | Install prerequisites: |
| 25 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 26 | ```shell |
Andrew Walbran | 45ac1d2 | 2019-10-21 16:54:24 +0100 | [diff] [blame] | 27 | sudo apt install make libssl-dev flex bison |
Andrew Walbran | 1027672 | 2018-09-10 14:33:18 +0100 | [diff] [blame] | 28 | ``` |
| 29 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 30 | By default, the hypervisor is built with clang for a few target platforms along |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 31 | with tests. Each project in the `project` directory specifies a root |
| 32 | configurations of the build. Adding a project is the preferred way to extend |
| 33 | support to new platforms. The target project that is built is selected by the |
| 34 | `PROJECT` make variable, the default project is 'reference'. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 35 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 36 | ```shell |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 37 | make PROJECT=<project_name> |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 38 | ``` |
| 39 | |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 40 | The compiled image can be found under `out/<project>`, for example the QEMU |
| 41 | image is at `out/reference/qemu_aarch64_clang/hafnium.bin`. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 42 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 43 | ## Running on QEMU |
| 44 | |
| 45 | You will need at least version 2.9 for QEMU. The following command line can be |
| 46 | used to run Hafnium on it: |
| 47 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 48 | ```shell |
Andrew Scull | 25d897e | 2019-06-27 12:57:02 +0100 | [diff] [blame] | 49 | qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a57 -nographic -machine virtualization=true -kernel out/reference/qemu_aarch64_clang/hafnium.bin |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 50 | ``` |
| 51 | |
| 52 | Though it is admittedly not very useful because it doesn't have any virtual |
| 53 | machines to run. Follow the [Hafnium RAM disk](HafniumRamDisk.md) instructions |
| 54 | to create an initial RAM disk for Hafnium with Linux as the primary VM. |
| 55 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 56 | Next, you need to create a manifest which will describe the VM to Hafnium. |
| 57 | Follow the [Manifest](Manifest.md) instructions and build a DTBO with: |
| 58 | ``` |
| 59 | /dts-v1/; |
| 60 | /plugin/; |
| 61 | |
| 62 | &{/} { |
| 63 | hypervisor { |
Serban Constantinescu | beb0ec7 | 2019-11-07 13:42:56 +0000 | [diff] [blame] | 64 | compatible = "hafnium,hafnium"; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 65 | vm1 { |
| 66 | debug_name = "Linux VM"; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 67 | kernel_filename = "vmlinuz"; |
Serban Constantinescu | beb0ec7 | 2019-11-07 13:42:56 +0000 | [diff] [blame] | 68 | ramdisk_filename = "initrd.img"; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 69 | }; |
| 70 | }; |
| 71 | }; |
| 72 | ``` |
| 73 | |
| 74 | Dump the DTB used by QEMU: |
| 75 | ```shell |
| 76 | 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 |
| 77 | ``` |
| 78 | and follow instructions in [Manifest](Manifest.md) to overlay it with the manifest. |
| 79 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 80 | The following command line will run Hafnium, with the RAM disk just created, |
| 81 | which will then boot into the primary Linux VM: |
| 82 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 83 | ```shell |
Shaked Flur | d1cfe61 | 2019-11-27 15:14:10 +0000 | [diff] [blame] | 84 | 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 |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 85 | ``` |
| 86 | |
| 87 | ## Running tests |
| 88 | |
| 89 | After building, presubmit tests can be run with the following command line: |
| 90 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 91 | ```shell |
Andrew Walbran | 219ceaf | 2020-01-10 15:44:29 +0000 | [diff] [blame^] | 92 | ./kokoro/test.sh |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 93 | ``` |
| 94 | |
| 95 | Read about [testing](Testing.md) for more details about the tests. |