blob: 812fb09c880de41a11157e9a7d75848988c0ac0b [file] [log] [blame] [view]
Olivier Deprez70128812023-05-22 12:12:03 +02001# Get started
Andrew Walbranb7849972019-11-15 15:23:43 +00002
Andrew Scull23042042018-08-22 17:44:56 +01003## Getting the source code
4
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +01005```shell
Olivier Deprezf90639e2021-04-21 09:51:23 +02006git 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 +01007```
8
9To upload a commit for review:
10
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010011```shell
Andrew Scull23042042018-08-22 17:44:56 +010012git push origin HEAD:refs/for/master
13```
Andrew Walbran0ba13bb2019-05-13 10:57:25 +010014
Andrew Walbran05e5edc2020-06-17 16:50:45 +010015Browse source at https://review.trustedfirmware.org/plugins/gitiles/. Review CLs
16at https://review.trustedfirmware.org/.
Andrew Walbran0ba13bb2019-05-13 10:57:25 +010017
Andrew Scull23042042018-08-22 17:44:56 +010018## Compiling the hypervisor
19
Andrew Walbran10276722018-09-10 14:33:18 +010020Install prerequisites:
21
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010022```shell
Raghu Krishnamurthy3fe1f4b2021-03-20 19:46:13 -070023sudo apt install make libssl-dev flex bison python3 python3-serial python3-pip
24pip3 install fdt
Andrew Walbran10276722018-09-10 14:33:18 +010025```
26
Olivier Deprez9fa36962021-09-20 14:32:14 +010027Before building, provide the LLVM/clang toolchain and dtc tool in the PATH
28environment variable. To use the default prebuilt toolchain (used by the
29Hafnium CI):
30
31```shell
32PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
33```
34
Andrew Scull23e93a82018-10-26 14:56:04 +010035By default, the hypervisor is built with clang for a few target platforms along
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000036with tests. Each project in the `project` directory specifies a root
37configurations of the build. Adding a project is the preferred way to extend
38support to new platforms. The target project that is built is selected by the
39`PROJECT` make variable, the default project is 'reference'.
Andrew Scull23042042018-08-22 17:44:56 +010040
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010041```shell
Alfredo Mazzinghib2bb1d32019-02-08 11:12:51 +000042make PROJECT=<project_name>
Andrew Scull23042042018-08-22 17:44:56 +010043```
44
David Brazdil5ecf75f2019-07-21 10:39:47 +020045The compiled image can be found under `out/<project>`, for example the QEMU
46image is at `out/reference/qemu_aarch64_clang/hafnium.bin`.
Andrew Scull23042042018-08-22 17:44:56 +010047
Daniel Boulby6530adf2021-11-26 09:54:01 +000048The presence of assertions in the final build can be set using the `ENABLE_ASSERTIONS`
49make variable, by default this is set to `true`, meaning asserts are included in the build.
50
51```shell
52make ENABLE_ASSERTIONS=<true|false>
53```
54If you wish to change the value of the make variables you may need to first use:
55
56```shell
57make clobber
58```
59So the `args.gn` file will be regenerated with the new values.
60
Andrew Scull23042042018-08-22 17:44:56 +010061## Running on QEMU
62
63You will need at least version 2.9 for QEMU. The following command line can be
64used to run Hafnium on it:
65
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010066```shell
Andrew Scull25d897e2019-06-27 12:57:02 +010067qemu-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 +010068```
69
70Though it is admittedly not very useful because it doesn't have any virtual
David Brazdila2358d42020-01-27 18:51:38 +000071machines to run.
Andrew Scull23042042018-08-22 17:44:56 +010072
David Brazdil0dbb41f2019-09-09 18:03:35 +010073Next, you need to create a manifest which will describe the VM to Hafnium.
David Brazdila2358d42020-01-27 18:51:38 +000074Follow the [Manifest](Manifest.md) instructions and build a DTB with:
Andrew Walbran05e5edc2020-06-17 16:50:45 +010075
David Brazdil0dbb41f2019-09-09 18:03:35 +010076```
77/dts-v1/;
David Brazdil0dbb41f2019-09-09 18:03:35 +010078
David Brazdila2358d42020-01-27 18:51:38 +000079/ {
David Brazdil0dbb41f2019-09-09 18:03:35 +010080 hypervisor {
Serban Constantinescubeb0ec72019-11-07 13:42:56 +000081 compatible = "hafnium,hafnium";
David Brazdil0dbb41f2019-09-09 18:03:35 +010082 vm1 {
83 debug_name = "Linux VM";
Andrew Scull72b43c02019-09-18 13:53:45 +010084 kernel_filename = "vmlinuz";
Serban Constantinescubeb0ec72019-11-07 13:42:56 +000085 ramdisk_filename = "initrd.img";
David Brazdil0dbb41f2019-09-09 18:03:35 +010086 };
87 };
88};
89```
90
Andrew Walbran05e5edc2020-06-17 16:50:45 +010091Follow the [Hafnium RAM disk](HafniumRamDisk.md) instructions to create an
92initial RAM disk for Hafnium with Linux as the primary VM.
David Brazdil0dbb41f2019-09-09 18:03:35 +010093
Andrew Scull23042042018-08-22 17:44:56 +010094The following command line will run Hafnium, with the RAM disk just created,
95which will then boot into the primary Linux VM:
96
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +010097```shell
David Brazdila2358d42020-01-27 18:51:38 +000098qemu-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 +010099```
100
101## Running tests
102
103After building, presubmit tests can be run with the following command line:
104
Andrew Walbran6f8fd4c2019-08-05 13:28:17 +0100105```shell
Andrew Walbran219ceaf2020-01-10 15:44:29 +0000106./kokoro/test.sh
Andrew Scull23042042018-08-22 17:44:56 +0100107```
108
109Read about [testing](Testing.md) for more details about the tests.