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