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 Walbran | 05e5edc | 2020-06-17 16:50:45 +0100 | [diff] [blame] | 8 | git clone --recurse-submodules https://git.trustedfirmware.org/hafnium/hafnium.git && (cd hafnium && f=`git rev-parse --git-dir`/hooks/commit-msg ; curl -Lo $f https://review.trustedfirmware.org/tools/hooks/commit-msg ; chmod +x $f ; for m in `git rev-parse --git-dir`/modules/*; do cp $f $m/hooks/commit-msg; done) |
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 | |
Andrew Scull | 23e93a8 | 2018-10-26 14:56:04 +0100 | [diff] [blame] | 31 | 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] | 32 | with tests. Each project in the `project` directory specifies a root |
| 33 | configurations of the build. Adding a project is the preferred way to extend |
| 34 | support to new platforms. The target project that is built is selected by the |
| 35 | `PROJECT` make variable, the default project is 'reference'. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 36 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 37 | ```shell |
Alfredo Mazzinghi | b2bb1d3 | 2019-02-08 11:12:51 +0000 | [diff] [blame] | 38 | make PROJECT=<project_name> |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 39 | ``` |
| 40 | |
David Brazdil | 5ecf75f | 2019-07-21 10:39:47 +0200 | [diff] [blame] | 41 | The compiled image can be found under `out/<project>`, for example the QEMU |
| 42 | image is at `out/reference/qemu_aarch64_clang/hafnium.bin`. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 43 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 44 | ## Running on QEMU |
| 45 | |
| 46 | You will need at least version 2.9 for QEMU. The following command line can be |
| 47 | used to run Hafnium on it: |
| 48 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 49 | ```shell |
Andrew Scull | 25d897e | 2019-06-27 12:57:02 +0100 | [diff] [blame] | 50 | 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] | 51 | ``` |
| 52 | |
| 53 | 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] | 54 | machines to run. |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 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. |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 57 | Follow the [Manifest](Manifest.md) instructions and build a DTB with: |
Andrew Walbran | 05e5edc | 2020-06-17 16:50:45 +0100 | [diff] [blame] | 58 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 59 | ``` |
| 60 | /dts-v1/; |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 61 | |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 62 | / { |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 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 | |
Andrew Walbran | 05e5edc | 2020-06-17 16:50:45 +0100 | [diff] [blame] | 74 | Follow the [Hafnium RAM disk](HafniumRamDisk.md) instructions to create an |
| 75 | initial RAM disk for Hafnium with Linux as the primary VM. |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 76 | |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 77 | The following command line will run Hafnium, with the RAM disk just created, |
| 78 | which will then boot into the primary Linux VM: |
| 79 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 80 | ```shell |
David Brazdil | a2358d4 | 2020-01-27 18:51:38 +0000 | [diff] [blame] | 81 | 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] | 82 | ``` |
| 83 | |
| 84 | ## Running tests |
| 85 | |
| 86 | After building, presubmit tests can be run with the following command line: |
| 87 | |
Andrew Walbran | 6f8fd4c | 2019-08-05 13:28:17 +0100 | [diff] [blame] | 88 | ```shell |
Andrew Walbran | 219ceaf | 2020-01-10 15:44:29 +0000 | [diff] [blame] | 89 | ./kokoro/test.sh |
Andrew Scull | 2304204 | 2018-08-22 17:44:56 +0100 | [diff] [blame] | 90 | ``` |
| 91 | |
| 92 | Read about [testing](Testing.md) for more details about the tests. |