1# Copyright 2018 The Hafnium Authors.
2#
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file or at
5# https://opensource.org/licenses/BSD-3-Clause.
6
7import("//build/image/image.gni")
8import("//build/toolchain/platform.gni")
9
10declare_args() {
11  # Target which implements the standard output interface.
12  stdout = ":stdout"
13}
14
15# The hypervisor image.
16hypervisor("hafnium") {
17  deps = [
18    ":layout",
19    ":src_not_testable_yet",
20  ]
21}
22
23# Hypervisor specific code that isn't. One day it will be testable and both the
24# src targets will merge!
25source_set("src_not_testable_yet") {
26  public_configs = [ "//src/arch/${plat_arch}:arch_config" ]
27  sources = [
28    "cpio.c",
29    "init.c",
30    "load.c",
31    "main.c",
32  ]
33  deps = [
34    ":src_testable",
35    "//project/${project}/${plat_name}",
36    "//src/arch/${plat_arch}/hypervisor:other_world",
37    plat_boot_flow,
38    plat_console,
39    plat_iommu,
40  ]
41}
42
43# One day, this will contain all the hypervisor's source but only once it can
44# all be built against the fake arch for unit tests. Utilities that are shared
45# e.g. with VM used in the VM tests have their own targets to facilitate
46# sharing.
47source_set("src_testable") {
48  public_configs = [ "//src/arch/${plat_arch}:arch_config" ]
49  sources = [
50    "api.c",
51    "boot_info.c",
52    "cpu.c",
53    "ffa_memory.c",
54    "manifest.c",
55    "sp_pkg.c",
56    "vcpu.c",
57  ]
58
59  deps = [
60    ":abort",
61    ":dlog",
62    ":fdt",
63    ":fdt_handler",
64    ":memiter",
65    ":mm",
66    ":panic",
67    ":std",
68    ":vm",
69    "//src/arch/${plat_arch}:arch",
70    "//src/arch/${plat_arch}/hypervisor",
71    "//src/arch/${plat_arch}/hypervisor:other_world",
72    "//vmlib",
73    plat_boot_flow,
74    plat_console,
75    plat_iommu,
76  ]
77}
78
79source_set("layout") {
80  sources = [
81    "layout.c",
82  ]
83}
84
85source_set("mm") {
86  sources = [
87    "mm.c",
88    "mpool.c",
89  ]
90}
91
92source_set("vm") {
93  public_configs = [ "//src/arch/${plat_arch}:arch_config" ]
94  sources = [
95    "vm.c",
96  ]
97}
98
99# Standard library functions.
100source_set("std") {
101  sources = [
102    "std.c",
103  ]
104
105  deps = [
106    "//src/arch/${plat_arch}:std",
107  ]
108}
109
110# Default implementation of stdout which sends the character to the
111# 'plat_console' driver.
112source_set("stdout") {
113  sources = [
114    "stdout.c",
115  ]
116  deps = [
117    plat_console,
118  ]
119}
120
121# Debug code that is not specific to a certain image so can be shared.
122source_set("dlog") {
123  sources = [
124    "dlog.c",
125  ]
126
127  deps = [
128    ":std",
129    stdout,
130  ]
131}
132
133source_set("string") {
134  sources = [
135    "string.c",
136  ]
137  deps = [
138    ":memiter",
139    ":std",
140  ]
141}
142
143source_set("fdt_handler") {
144  sources = [
145    "fdt_handler.c",
146  ]
147  deps = [
148    ":dlog",
149    ":fdt",
150    ":fdt_patch",
151  ]
152}
153
154# Flattened Device Tree (FDT) utilities.
155source_set("fdt") {
156  sources = [
157    "fdt.c",
158  ]
159
160  deps = [
161    ":memiter",
162    ":string",
163    "//third_party/dtc:libfdt",
164  ]
165}
166
167source_set("fdt_patch") {
168  sources = [
169    "fdt_patch.c",
170  ]
171  deps = [
172    ":dlog",
173    ":fdt",
174    "//third_party/dtc:libfdt",
175  ]
176}
177
178source_set("memiter") {
179  sources = [
180    "memiter.c",
181  ]
182}
183
184source_set("panic") {
185  sources = [
186    "panic.c",
187  ]
188}
189
190source_set("abort") {
191  sources = [
192    "abort.c",
193  ]
194}
195
196executable("unit_tests") {
197  testonly = true
198  sources = [
199    "fdt_handler_test.cc",
200    "fdt_test.cc",
201    "manifest_test.cc",
202    "mm_test.cc",
203    "mpool_test.cc",
204    "string_test.cc",
205    "vm_test.cc",
206  ]
207  sources += [ "layout_fake.c" ]
208  cflags_cc = [
209    "-Wno-c99-extensions",
210    "-Wno-nested-anon-types",
211  ]
212  deps = [
213    ":src_testable",
214    "//third_party/googletest:gtest_main",
215  ]
216}
217