blob: 614ca0887268b4ff03bea2e83add6661bc4d1f13 [file] [log] [blame]
Bob Badoure8af2842022-04-07 10:44:22 -07001package {
2 default_applicable_licenses: ["Android-Apache-2.0"],
3}
4
Andrew Walbran68a8c162022-03-07 15:38:42 +00005rust_ffi_static {
6 name: "libpvmfw",
7 crate_name: "pvmfw",
David Brazdil30a7f082022-07-07 15:30:14 +01008 defaults: ["vmbase_ffi_defaults"],
Andrew Walbran68a8c162022-03-07 15:38:42 +00009 srcs: ["src/main.rs"],
Pierre-Clément Tosie8726e42022-10-17 13:35:27 +010010 features: [
11 "legacy",
12 ],
Andrew Walbranf2594882022-03-15 17:32:53 +000013 rustlibs: [
Pierre-Clément Tosia8a4a202022-11-03 14:16:46 +000014 "libaarch64_paging",
Alice Wang947f3f72023-09-29 09:04:07 +000015 "libbssl_avf_nostd",
Maurice Lam0322b8c2023-12-18 22:13:48 +000016 "libbssl_sys_nostd",
Shikha Panwar8f7fc1a2024-04-10 10:41:34 +000017 "libcbor_util_nostd",
Alan Stokesd1ee63e2023-04-24 16:17:39 +010018 "libciborium_nostd",
19 "libciborium_io_nostd",
Pierre-Clément Tosi1bf532b2023-11-13 11:06:20 +000020 "libcstr",
Alice Wangcb9d2f92023-02-06 10:29:00 +000021 "libdiced_open_dice_nostd",
Andrew Walbran730375d2022-12-21 14:04:34 +000022 "libfdtpci",
Alice Wang0bdc3f62023-03-15 10:46:12 +000023 "libhyp",
Pierre-Clément Tosia0934c12022-11-25 20:54:11 +000024 "liblibfdt",
Pierre-Clément Tosi37105a62022-10-18 12:21:48 +010025 "liblog_rust_nostd",
Andrew Walbranb398fc82023-01-24 14:45:46 +000026 "libonce_cell_nostd",
Pierre-Clément Tosi2d652982023-01-09 19:30:17 +000027 "libpvmfw_avb_nostd",
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +010028 "libpvmfw_embedded_key",
Jiyong Park216793e2023-02-25 02:15:44 +090029 "libpvmfw_fdt_template",
Alice Wang12e4c862023-12-11 13:52:27 +000030 "libservice_vm_version",
Andrew Walbranf44f1602023-05-30 14:59:19 +000031 "libsmccc",
Pierre-Clément Tosi1cc5eb72023-02-02 11:09:18 +000032 "libstatic_assertions",
Pierre-Clément Tosi328dfb62022-11-25 18:20:42 +000033 "libtinyvec_nostd",
Pierre-Clément Tosi1cc5eb72023-02-02 11:09:18 +000034 "libuuid_nostd",
Andrew Walbrand1d03182022-12-09 18:20:01 +000035 "libvirtio_drivers",
Andrew Walbrandd74b902022-04-14 16:12:50 +000036 "libvmbase",
Alan Stokesa0e42962023-04-14 17:59:50 +010037 "libzerocopy_nostd",
Pierre-Clément Tosi8383c542022-11-01 14:07:29 +000038 "libzeroize_nostd",
Andrew Walbranf2594882022-03-15 17:32:53 +000039 ],
Andrew Walbran68a8c162022-03-07 15:38:42 +000040}
Andrew Walbran15068b02022-03-22 15:57:34 +000041
Alice Wang1c7e0eb2023-04-11 17:03:42 +000042// Generates an empty file.
43genrule {
44 name: "empty_file",
45 out: ["empty_file"],
46 cmd: "touch $(out)",
47}
48
Alan Stokesddb988c2023-11-27 11:13:06 +000049rust_defaults {
50 name: "libpvmfw.test.defaults",
Nikita Ioffeda1b2732023-09-04 13:46:56 +010051 defaults: ["avf_build_flags_rust"],
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090052 test_suites: ["general-tests"],
53 test_options: {
54 unit_test: true,
55 },
Alan Stokesddb988c2023-11-27 11:13:06 +000056 prefer_rlib: true,
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090057 rustlibs: [
Pierre-Clément Tosi1bf532b2023-11-13 11:06:20 +000058 "libcstr",
Alan Stokesddb988c2023-11-27 11:13:06 +000059 ],
60}
61
62rust_test {
63 name: "libpvmfw.bootargs.test",
64 host_supported: true,
65 // For now, only bootargs.rs is written to be conditionally compiled with std.
66 srcs: ["src/bootargs.rs"],
67 defaults: ["libpvmfw.test.defaults"],
68 rustlibs: [
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090069 "libzeroize",
70 ],
71}
72
Alan Stokesddb988c2023-11-27 11:13:06 +000073rust_test {
74 name: "libpvmfw.device_assignment.test",
75 srcs: ["src/device_assignment.rs"],
76 defaults: ["libpvmfw.test.defaults"],
77 rustlibs: [
Jaewan Kim8f6f4662023-12-12 17:38:47 +090078 "libdts",
Jaewan Kim52477ae2023-11-21 21:20:52 +090079 "libhyp",
Alan Stokesddb988c2023-11-27 11:13:06 +000080 "liblibfdt",
81 "liblog_rust",
82 "libpvmfw_fdt_template",
Jaewan Kim8f6f4662023-12-12 17:38:47 +090083 "libzerocopy",
Alan Stokesddb988c2023-11-27 11:13:06 +000084 ],
85 data: [
86 ":test_pvmfw_devices_vm_dtbo",
87 ":test_pvmfw_devices_vm_dtbo_without_symbols",
Jaewan Kim19b984f2023-12-04 15:16:50 +090088 ":test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
Pierre-Clément Tosi49e26ce2024-03-12 16:31:50 +000089 ":test_pvmfw_devices_overlapping_pvmfw",
Jaewan Kim8f6f4662023-12-12 17:38:47 +090090 ":test_pvmfw_devices_vm_dtbo_with_dependencies",
Alan Stokesddb988c2023-11-27 11:13:06 +000091 ":test_pvmfw_devices_with_rng",
Alan Stokesddb988c2023-11-27 11:13:06 +000092 ":test_pvmfw_devices_with_multiple_devices_iommus",
93 ":test_pvmfw_devices_with_iommu_sharing",
94 ":test_pvmfw_devices_with_iommu_id_conflict",
Jaewan Kim52477ae2023-11-21 21:20:52 +090095 ":test_pvmfw_devices_without_device",
Jaewan Kima67e36a2023-11-29 16:50:23 +090096 ":test_pvmfw_devices_without_iommus",
Jaewan Kim19b984f2023-12-04 15:16:50 +090097 ":test_pvmfw_devices_with_duplicated_pviommus",
98 ":test_pvmfw_devices_with_multiple_reg_iommus",
Jaewan Kim8f6f4662023-12-12 17:38:47 +090099 ":test_pvmfw_devices_with_dependency",
100 ":test_pvmfw_devices_with_dependency_loop",
101 ":test_pvmfw_devices_with_multiple_dependencies",
102 ":test_pvmfw_devices_expected_dt",
Alan Stokesddb988c2023-11-27 11:13:06 +0000103 ],
Jaewan Kim8f6f4662023-12-12 17:38:47 +0900104 data_bins: ["dtc_static"],
105 compile_multilib: "first",
Alan Stokesddb988c2023-11-27 11:13:06 +0000106 // To use libpvmfw_fdt_template for testing
107 enabled: false,
108 target: {
109 android_arm64: {
110 enabled: true,
111 },
112 },
113}
114
115rust_test {
116 name: "libpvmfw.dice.test",
117 srcs: ["src/dice.rs"],
118 defaults: ["libpvmfw.test.defaults"],
119 rustlibs: [
120 "libcbor_util",
121 "libciborium",
122 "libdiced_open_dice_nostd",
123 "libpvmfw_avb_nostd",
Alan Stokesa17cfba2024-02-14 17:34:51 +0000124 "libzerocopy_nostd",
Alan Stokesddb988c2023-11-27 11:13:06 +0000125 ],
126}
127
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900128genrule {
129 name: "test_pvmfw_devices_vm_dtbo",
130 defaults: ["dts_to_dtb"],
131 srcs: ["testdata/test_pvmfw_devices_vm_dtbo.dts"],
132 out: ["test_pvmfw_devices_vm_dtbo.dtbo"],
133}
134
135genrule {
136 name: "test_pvmfw_devices_vm_dtbo_without_symbols",
137 defaults: ["dts_to_dtb"],
138 srcs: ["testdata/test_pvmfw_devices_vm_dtbo_without_symbols.dts"],
139 out: ["test_pvmfw_devices_vm_dtbo_without_symbols.dtbo"],
140}
141
Jaewan Kim19b984f2023-12-04 15:16:50 +0900142genrule {
143 name: "test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
144 defaults: ["dts_to_dtb"],
145 srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dts"],
146 out: ["test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dtbo"],
147}
148
Jaewan Kim8f6f4662023-12-12 17:38:47 +0900149genrule {
150 name: "test_pvmfw_devices_vm_dtbo_with_dependencies",
151 tools: ["dtc"],
152 cmd: "$(location dtc) -@ -I dts -O dtb $(in) -o $(out)",
153 srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_dependencies.dts"],
154 out: ["test_pvmfw_devices_vm_dtbo_with_dependencies.dtbo"],
155}
156
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900157genrule_defaults {
158 name: "test_device_assignment_dts_to_dtb",
159 defaults: ["dts_to_dtb"],
160 srcs: ["testdata/test_crosvm_dt_base.dtsi"],
161}
162
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900163genrule {
Pierre-Clément Tosi49e26ce2024-03-12 16:31:50 +0000164 name: "test_pvmfw_devices_overlapping_pvmfw",
165 defaults: ["test_device_assignment_dts_to_dtb"],
166 srcs: ["testdata/test_pvmfw_devices_overlapping_pvmfw.dts"],
167 out: ["test_pvmfw_devices_overlapping_pvmfw.dtb"],
168}
169
170genrule {
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900171 name: "test_pvmfw_devices_with_rng",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900172 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900173 srcs: ["testdata/test_pvmfw_devices_with_rng.dts"],
174 out: ["test_pvmfw_devices_with_rng.dtb"],
175}
176
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900177genrule {
Jaewan Kima67e36a2023-11-29 16:50:23 +0900178 name: "test_pvmfw_devices_without_iommus",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900179 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kima67e36a2023-11-29 16:50:23 +0900180 srcs: ["testdata/test_pvmfw_devices_without_iommus.dts"],
181 out: ["test_pvmfw_devices_without_iommus.dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900182}
183
184genrule {
Jaewan Kim52477ae2023-11-21 21:20:52 +0900185 name: "test_pvmfw_devices_without_device",
186 defaults: ["test_device_assignment_dts_to_dtb"],
187 srcs: ["testdata/test_pvmfw_devices_without_device.dts"],
188 out: ["test_pvmfw_devices_without_device.dtb"],
189}
190
191genrule {
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900192 name: "test_pvmfw_devices_with_multiple_devices_iommus",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900193 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900194 srcs: ["testdata/test_pvmfw_devices_with_multiple_devices_iommus.dts"],
195 out: ["test_pvmfw_devices_with_multiple_devices_iommus.dtb"],
196}
197
198genrule {
199 name: "test_pvmfw_devices_with_iommu_sharing",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900200 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900201 srcs: ["testdata/test_pvmfw_devices_with_iommu_sharing.dts"],
202 out: ["test_pvmfw_devices_with_iommu_sharing.dtb"],
203}
204
205genrule {
206 name: "test_pvmfw_devices_with_iommu_id_conflict",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900207 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900208 srcs: ["testdata/test_pvmfw_devices_with_iommu_id_conflict.dts"],
209 out: ["test_pvmfw_devices_with_iommu_id_conflict.dtb"],
210}
211
Jaewan Kim19b984f2023-12-04 15:16:50 +0900212genrule {
213 name: "test_pvmfw_devices_with_duplicated_pviommus",
214 defaults: ["test_device_assignment_dts_to_dtb"],
215 srcs: ["testdata/test_pvmfw_devices_with_duplicated_pviommus.dts"],
216 out: ["test_pvmfw_devices_with_duplicated_pviommus.dtb"],
217}
218
219genrule {
220 name: "test_pvmfw_devices_with_multiple_reg_iommus",
221 defaults: ["test_device_assignment_dts_to_dtb"],
222 srcs: ["testdata/test_pvmfw_devices_with_multiple_reg_iommus.dts"],
223 out: ["test_pvmfw_devices_with_multiple_reg_iommus.dtb"],
224}
225
Jaewan Kim8f6f4662023-12-12 17:38:47 +0900226genrule {
227 name: "test_pvmfw_devices_with_dependency",
228 defaults: ["test_device_assignment_dts_to_dtb"],
229 srcs: ["testdata/test_pvmfw_devices_with_dependency.dts"],
230 out: ["test_pvmfw_devices_with_dependency.dtb"],
231}
232
233genrule {
234 name: "test_pvmfw_devices_with_multiple_dependencies",
235 defaults: ["test_device_assignment_dts_to_dtb"],
236 srcs: ["testdata/test_pvmfw_devices_with_multiple_dependencies.dts"],
237 out: ["test_pvmfw_devices_with_multiple_dependencies.dtb"],
238}
239
240genrule {
241 name: "test_pvmfw_devices_with_dependency_loop",
242 defaults: ["test_device_assignment_dts_to_dtb"],
243 srcs: ["testdata/test_pvmfw_devices_with_dependency_loop.dts"],
244 out: ["test_pvmfw_devices_with_dependency_loop.dtb"],
245}
246
247// We can't use genrule because preprocessed platform DT is built with cc_object.
248// cc_genrule doesn't support default, so we'll build all expected DTs in
249// a single build rule.
250cc_genrule {
251 name: "test_pvmfw_devices_expected_dt",
252 srcs: [
253 ":pvmfw_platform.dts.preprocessed",
254 "testdata/expected_dt_with_dependency.dts",
255 "testdata/expected_dt_with_multiple_dependencies.dts",
256 "testdata/expected_dt_with_dependency_loop.dts",
257 ],
258 out: [
259 "expected_dt_with_dependency.dtb",
260 "expected_dt_with_multiple_dependencies.dtb",
261 "expected_dt_with_dependency_loop.dtb",
262 ],
263 tools: ["dtc"],
264 cmd: "FILES=($(in));" +
265 "cp $${FILES[0]} $(genDir)/platform_preprocessed.dts;" +
266 "for DTS in $${FILES[@]:1}; do" +
267 " DTB=$$(basename -s .dts $${DTS}).dtb;" +
268 " $(location dtc) -@ -i $(genDir) -I dts -O dtb $${DTS} -o $(genDir)/$${DTB};" +
269 "done",
270 visibility: ["//visibility:private"],
271}
272
Andrew Walbran15068b02022-03-22 15:57:34 +0000273cc_binary {
Pierre-Clément Tosib1300352022-09-09 11:01:06 +0100274 name: "pvmfw",
David Brazdil30a7f082022-07-07 15:30:14 +0100275 defaults: ["vmbase_elf_defaults"],
Andrew Walbran15068b02022-03-22 15:57:34 +0000276 srcs: [
Andrew Walbran267f6c12022-03-24 11:26:36 +0000277 "idmap.S",
Andrew Walbran15068b02022-03-22 15:57:34 +0000278 ],
279 static_libs: [
280 "libpvmfw",
281 ],
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000282 linker_scripts: [
283 "image.ld",
284 ":vmbase_sections",
285 ],
Jiyong Park17b8d752022-12-16 14:36:24 +0900286 // `installable: false` is inherited from vmbase_elf_defaults, and that
287 // hides this module from Make, which makes it impossible for the Make world
288 // to place the unstripped binary to the symbols directory. Marking back as
289 // installable exposes this module to the Make world again. Note that this
290 // module (pvmfw) still is NOT installed to any of the filesystem images. It
291 // is fed into pvmfw_bin and then into pvmfw_img to become a standalone
292 // partition image. This is just to package the unstripped file into the
293 // symbols zip file for debugging purpose.
294 installable: true,
Andrew Walbran15068b02022-03-22 15:57:34 +0000295}
David Brazdil05d4e072022-04-25 14:47:06 +0100296
297raw_binary {
Pierre-Clément Tosib1300352022-09-09 11:01:06 +0100298 name: "pvmfw_bin",
299 stem: "pvmfw.bin",
300 src: ":pvmfw",
David Brazdil05d4e072022-04-25 14:47:06 +0100301 enabled: false,
302 target: {
303 android_arm64: {
304 enabled: true,
305 },
306 },
307}
David Brazdilac216b52022-04-25 15:07:22 +0100308
Jaewan Kim2cf6f392023-02-10 01:35:47 +0900309// Provide pvmfw.bin binary regardless of the architecture for building test.
310// Note that skipping tests on unsupported device is easy
311// while configuring server configuration to make such tests to run on working
312// devices.
313prebuilt_etc {
314 name: "pvmfw_test",
315 filename: "pvmfw_test.bin",
316 target: {
317 android_arm64: {
318 src: ":pvmfw_bin",
319 },
320 },
Alice Wang1c7e0eb2023-04-11 17:03:42 +0000321 src: ":empty_file",
Jaewan Kim2cf6f392023-02-10 01:35:47 +0900322 installable: false,
323}
324
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100325prebuilt_etc {
Pierre-Clément Tosi6ec2ae22022-10-26 15:14:45 +0100326 name: "pvmfw_embedded_key",
327 src: ":avb_testkey_rsa4096_pub_bin",
328 installable: false,
329}
330
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100331genrule {
332 name: "pvmfw_embedded_key_rs",
333 srcs: [":pvmfw_embedded_key"],
334 out: ["lib.rs"],
335 cmd: "(" +
336 " echo '#![no_std]';" +
337 " echo '#![allow(missing_docs)]';" +
338 " echo 'pub const PUBLIC_KEY: &[u8] = &[';" +
339 " xxd -i < $(in);" +
340 " echo '];';" +
341 ") > $(out)",
342}
343
344rust_library_rlib {
345 name: "libpvmfw_embedded_key",
Pierre-Clément Tosi4894b432023-06-27 14:02:26 +0000346 defaults: ["vmbase_rlib_defaults"],
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100347 srcs: [":pvmfw_embedded_key_rs"],
348 crate_name: "pvmfw_embedded_key",
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100349}
350
Pierre-Clément Tosi6ec2ae22022-10-26 15:14:45 +0100351prebuilt_etc {
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100352 name: "pvmfw_sign_key",
353 src: ":avb_testkey_rsa4096",
354 installable: false,
355}
356
Jiyong Park9c1c8182023-05-25 15:40:11 +0900357// We need to rename *.dts into *.cpp as cc_object doesn't accept *.dts as an
358// input
Jiyong Park216793e2023-02-25 02:15:44 +0900359genrule {
Jiyong Park9c1c8182023-05-25 15:40:11 +0900360 name: "pvmfw_platform.dts.renamed",
361 srcs: ["platform.dts"],
362 out: ["out.cpp"],
363 cmd: "cp $(in) $(out)",
364 visibility: ["//visibility:private"],
365}
366
367// Then run the macro processor to replace symbols like GIC_SPI into actual
368// numbers defined in the ARM DT binding headers
369cc_object {
370 name: "pvmfw_platform.dts.preprocessed",
Nikita Ioffe38b9e712024-02-08 15:55:07 +0000371 defaults: ["avf_build_flags_cc"],
Jiyong Park9c1c8182023-05-25 15:40:11 +0900372 header_libs: ["arm_dt_bindings_headers"],
373 host_supported: true,
374 srcs: [":pvmfw_platform.dts.renamed"],
375 cflags: [
376 "-E",
377 "-P",
378 "-xassembler-with-cpp", // allow C preprocessor directives
Jiyong Park216793e2023-02-25 02:15:44 +0900379 ],
Jiyong Park9c1c8182023-05-25 15:40:11 +0900380 visibility: ["//visibility:private"],
381}
382
383// Compile the preprocessed dts into binary and create a rust library source
384// having the binary.
385cc_genrule {
386 name: "pvmfw_fdt_template_rs",
387 srcs: [":pvmfw_platform.dts.preprocessed"],
Jiyong Park216793e2023-02-25 02:15:44 +0900388 out: ["lib.rs"],
389 tools: ["dtc"],
Jaewan Kim96411e92023-11-13 15:54:02 +0900390 cmd: "$(location dtc) -@ -I dts -O dtb -o $(genDir)/compiled.dtbo $(in) && " +
Jiyong Park216793e2023-02-25 02:15:44 +0900391 "(" +
392 " echo '#![no_std]';" +
393 " echo '#![allow(missing_docs)]';" +
394 " echo 'pub const RAW: &[u8] = &[';" +
395 " xxd -i < $(genDir)/compiled.dtbo;" +
396 " echo '];';" +
397 ") > $(out)",
Jiyong Park9c1c8182023-05-25 15:40:11 +0900398 visibility: ["//visibility:private"],
Jiyong Park216793e2023-02-25 02:15:44 +0900399}
400
401rust_library_rlib {
402 name: "libpvmfw_fdt_template",
Pierre-Clément Tosi4894b432023-06-27 14:02:26 +0000403 defaults: ["vmbase_rlib_defaults"],
Jiyong Park216793e2023-02-25 02:15:44 +0900404 srcs: [":pvmfw_fdt_template_rs"],
405 crate_name: "pvmfw_fdt_template",
406}
407
David Brazdilac216b52022-04-25 15:07:22 +0100408bootimg {
409 name: "pvmfw_img",
410 stem: "pvmfw.img",
411 kernel_prebuilt: ":pvmfw_bin",
412 header_version: "3",
413 partition_name: "pvmfw",
414 enabled: false,
415 target: {
416 android_arm64: {
417 enabled: true,
418 },
419 },
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100420 use_avb: true,
421 avb_private_key: ":pvmfw_sign_key",
David Brazdilac216b52022-04-25 15:07:22 +0100422}