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