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 |
Olivier Deprez | f90639e | 2021-04-21 09:51:23 +0200 | [diff] [blame] | 8 | git clone --recurse-submodules https://git.trustedfirmware.org/hafnium/hafnium.git && { cd hafnium && f="$(git rev-parse --git-dir)"; curl -Lo "$f/hooks/commit-msg" https://review.trustedfirmware.org/tools/hooks/commit-msg && { chmod +x "$f/hooks/commit-msg"; git submodule --quiet foreach "cp \"\$toplevel/$f/hooks/commit-msg\" \"\$toplevel/$f/modules/\$path/hooks/commit-msg\""; }; } |
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 | 05e5edc | 2020-06-17 16:50:45 +0100 | [diff] [blame] | 17 | Browse source at https://review.trustedfirmware.org/plugins/gitiles/. Review CLs |
| 18 | at https://review.trustedfirmware.org/. |
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 |
Raghu Krishnamurthy | 3fe1f4b | 2021-03-20 19:46:13 -0700 | [diff] [blame] | 27 | sudo apt install make libssl-dev flex bison python3 python3-serial python3-pip |
| 28 | pip3 install fdt |
Andrew Walbran | 1027672 | 2018-09-10 14:33:18 +0100 | [diff] [blame] | 29 | ``` |
| 30 | |
Olivier Deprez | 9fa3696 | 2021-09-20 14:32:14 +0100 | [diff] [blame^] | 31 | Before building, provide the LLVM/clang toolchain and dtc tool in the PATH |
| 32 | environment variable. To use the default prebuilt toolchain (used by the |
| 33 | Hafnium CI): |
| 34 | |
| 35 | ```shell |
| 36 | PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH |
| 37 | ``` |
| 38 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 39 | 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] | 40 | with tests. Each project in the `project` directory specifies a root |
| 41 | configurations of the build. Adding a project is the preferred way to extend |
| 42 | support to new platforms. The target project that is built is selected by the |
| 43 | `PROJECT` make variable, the default project is 'reference'. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 44 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 45 | ```shell |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 46 | make PROJECT=<project_name> |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 47 | ``` |
| 48 | |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 49 | The compiled image can be found under `out/<project>`, for example the QEMU |
| 50 | image is at `out/reference/qemu_aarch64_clang/hafnium.bin`. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 51 | |
Daniel Boulby | 6530adf | 2021-11-26 09:54:01 +0000 | [diff] [blame] | 52 | The presence of assertions in the final build can be set using the `ENABLE_ASSERTIONS` |
| 53 | make variable, by default this is set to `true`, meaning asserts are included in the build. |
| 54 | |
| 55 | ```shell |
| 56 | make ENABLE_ASSERTIONS=<true|false> |
| 57 | ``` |
| 58 | If you wish to change the value of the make variables you may need to first use: |
| 59 | |
| 60 | ```shell |
| 61 | make clobber |
| 62 | ``` |
| 63 | So the `args.gn` file will be regenerated with the new values. |
| 64 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 65 | ## Running on QEMU |
| 66 | |
| 67 | You will need at least version 2.9 for QEMU. The following command line can be |
| 68 | used to run Hafnium on it: |
| 69 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 70 | ```shell |
Andrew Scull | 25d897e | 2019-06-27 12:57:02 +0100 | [diff] [blame] | 71 | 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] | 72 | ``` |
| 73 | |
| 74 | Though it is admittedly not very useful because it doesn't have any virtual |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 75 | machines to run. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 76 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 77 | Next, you need to create a manifest which will describe the VM to Hafnium. |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 78 | Follow the [Manifest](Manifest.md) instructions and build a DTB with: |
Andrew Walbran | 05e5edc | 2020-06-17 16:50:45 +0100 | [diff] [blame] | 79 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 80 | ``` |
| 81 | /dts-v1/; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 82 | |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 83 | / { |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 84 | hypervisor { |
Serban Constantinescu | beb0ec7 | 2019-11-07 13:42:56 +0000 | [diff] [blame] | 85 | compatible = "hafnium,hafnium"; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 86 | vm1 { |
| 87 | debug_name = "Linux VM"; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 88 | kernel_filename = "vmlinuz"; |
Serban Constantinescu | beb0ec7 | 2019-11-07 13:42:56 +0000 | [diff] [blame] | 89 | ramdisk_filename = "initrd.img"; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 90 | }; |
| 91 | }; |
| 92 | }; |
| 93 | ``` |
| 94 | |
Andrew Walbran | 05e5edc | 2020-06-17 16:50:45 +0100 | [diff] [blame] | 95 | Follow the [Hafnium RAM disk](HafniumRamDisk.md) instructions to create an |
| 96 | initial RAM disk for Hafnium with Linux as the primary VM. |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 97 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 98 | The following command line will run Hafnium, with the RAM disk just created, |
| 99 | which will then boot into the primary Linux VM: |
| 100 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 101 | ```shell |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 102 | 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" |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 103 | ``` |
| 104 | |
| 105 | ## Running tests |
| 106 | |
| 107 | After building, presubmit tests can be run with the following command line: |
| 108 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 109 | ```shell |
Andrew Walbran | 219ceaf | 2020-01-10 15:44:29 +0000 | [diff] [blame] | 110 | ./kokoro/test.sh |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 111 | ``` |
| 112 | |
| 113 | Read about [testing](Testing.md) for more details about the tests. |