blob: 09706b14c3b2c16c23677dbda48fa21cc3a06af7 [file] [log] [blame] [view]
Andrew Scull23042042018-08-22 17:44:56 +01001# Getting started
2
Andrew Walbranb7849972019-11-15 15:23:43 +00003[TOC]
4
Andrew Scull23042042018-08-22 17:44:56 +01005## Getting the source code
6
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +01007```shell
Olivier Deprezf90639e2021-04-21 09:51:23 +02008git 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 Scull23042042018-08-22 17:44:56 +01009```
10
11To upload a commit for review:
12
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010013```shell
Andrew Scull23042042018-08-22 17:44:56 +010014git push origin HEAD:refs/for/master
15```
Andrew Walbran0ba13bb2019-05-13 10:57:25 +010016
Andrew Walbran05e5edc2020-06-17 16:50:45 +010017Browse source at https://review.trustedfirmware.org/plugins/gitiles/. Review CLs
18at https://review.trustedfirmware.org/.
Andrew Walbran0ba13bb2019-05-13 10:57:25 +010019
Andrew Scullb81de702019-07-09 13:46:50 +010020See details of [how to contribute](../CONTRIBUTING.md).
Andrew Scull23042042018-08-22 17:44:56 +010021
22## Compiling the hypervisor
23
Andrew Walbran10276722018-09-10 14:33:18 +010024Install prerequisites:
25
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010026```shell
Raghu Krishnamurthy3fe1f4b2021-03-20 19:46:13 -070027sudo apt install make libssl-dev flex bison python3 python3-serial python3-pip
28pip3 install fdt
Andrew Walbran10276722018-09-10 14:33:18 +010029```
30
Olivier Deprez9fa36962021-09-20 14:32:14 +010031Before building, provide the LLVM/clang toolchain and dtc tool in the PATH
32environment variable. To use the default prebuilt toolchain (used by the
33Hafnium CI):
34
35```shell
36PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
37```
38
Andrew Scull23e93a82018-10-26 14:56:04 +010039By default, the hypervisor is built with clang for a few target platforms along
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000040with tests. Each project in the `project` directory specifies a root
41configurations of the build. Adding a project is the preferred way to extend
42support to new platforms. The target project that is built is selected by the
43`PROJECT` make variable, the default project is 'reference'.
Andrew Scull23042042018-08-22 17:44:56 +010044
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010045```shell
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000046make PROJECT=<project_name>
Andrew Scull23042042018-08-22 17:44:56 +010047```
48
David Brazdil5ecf75f2019-07-21 10:39:47 +020049The compiled image can be found under `out/<project>`, for example the QEMU
50image is at `out/reference/qemu_aarch64_clang/hafnium.bin`.
Andrew Scull23042042018-08-22 17:44:56 +010051
Daniel Boulby6530adf2021-11-26 09:54:01 +000052The presence of assertions in the final build can be set using the `ENABLE_ASSERTIONS`
53make variable, by default this is set to `true`, meaning asserts are included in the build.
54
55```shell
56make ENABLE_ASSERTIONS=<true|false>
57```
58If you wish to change the value of the make variables you may need to first use:
59
60```shell
61make clobber
62```
63So the `args.gn` file will be regenerated with the new values.
64
Andrew Scull23042042018-08-22 17:44:56 +010065## Running on QEMU
66
67You will need at least version 2.9 for QEMU. The following command line can be
68used to run Hafnium on it:
69
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010070```shell
Andrew Scull25d897e2019-06-27 12:57:02 +010071qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a57 -nographic -machine virtualization=true -kernel out/reference/qemu_aarch64_clang/hafnium.bin
Andrew Scull23042042018-08-22 17:44:56 +010072```
73
74Though it is admittedly not very useful because it doesn't have any virtual
David Brazdila2358d42020-01-27 18:51:38 +000075machines to run.
Andrew Scull23042042018-08-22 17:44:56 +010076
David Brazdil0dbb41f2019-09-09 18:03:35 +010077Next, you need to create a manifest which will describe the VM to Hafnium.
David Brazdila2358d42020-01-27 18:51:38 +000078Follow the [Manifest](Manifest.md) instructions and build a DTB with:
Andrew Walbran05e5edc2020-06-17 16:50:45 +010079
David Brazdil0dbb41f2019-09-09 18:03:35 +010080```
81/dts-v1/;
David Brazdil0dbb41f2019-09-09 18:03:35 +010082
David Brazdila2358d42020-01-27 18:51:38 +000083/ {
David Brazdil0dbb41f2019-09-09 18:03:35 +010084 hypervisor {
Serban Constantinescubeb0ec72019-11-07 13:42:56 +000085 compatible = "hafnium,hafnium";
David Brazdil0dbb41f2019-09-09 18:03:35 +010086 vm1 {
87 debug_name = "Linux VM";
Andrew Scull72b43c02019-09-18 13:53:45 +010088 kernel_filename = "vmlinuz";
Serban Constantinescubeb0ec72019-11-07 13:42:56 +000089 ramdisk_filename = "initrd.img";
David Brazdil0dbb41f2019-09-09 18:03:35 +010090 };
91 };
92};
93```
94
Andrew Walbran05e5edc2020-06-17 16:50:45 +010095Follow the [Hafnium RAM disk](HafniumRamDisk.md) instructions to create an
96initial RAM disk for Hafnium with Linux as the primary VM.
David Brazdil0dbb41f2019-09-09 18:03:35 +010097
Andrew Scull23042042018-08-22 17:44:56 +010098The following command line will run Hafnium, with the RAM disk just created,
99which will then boot into the primary Linux VM:
100
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +0100101```shell
David Brazdila2358d42020-01-27 18:51:38 +0000102qemu-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 Scull23042042018-08-22 17:44:56 +0100103```
104
105## Running tests
106
107After building, presubmit tests can be run with the following command line:
108
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +0100109```shell
Andrew Walbran219ceaf2020-01-10 15:44:29 +0000110./kokoro/test.sh
Andrew Scull23042042018-08-22 17:44:56 +0100111```
112
113Read about [testing](Testing.md) for more details about the tests.