blob: cce0e737c7f4408cf88dc5de91da82d9b3a99407 [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",
Alan Stokesd1ee63e2023-04-24 16:17:39 +010017 "libciborium_nostd",
18 "libciborium_io_nostd",
Pierre-Clément Tosi1bf532b2023-11-13 11:06:20 +000019 "libcstr",
Alice Wangcb9d2f92023-02-06 10:29:00 +000020 "libdiced_open_dice_nostd",
Andrew Walbran730375d2022-12-21 14:04:34 +000021 "libfdtpci",
Alice Wang0bdc3f62023-03-15 10:46:12 +000022 "libhyp",
Pierre-Clément Tosia0934c12022-11-25 20:54:11 +000023 "liblibfdt",
Pierre-Clément Tosi37105a62022-10-18 12:21:48 +010024 "liblog_rust_nostd",
Andrew Walbranb398fc82023-01-24 14:45:46 +000025 "libonce_cell_nostd",
Pierre-Clément Tosi2d652982023-01-09 19:30:17 +000026 "libpvmfw_avb_nostd",
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +010027 "libpvmfw_embedded_key",
Jiyong Park216793e2023-02-25 02:15:44 +090028 "libpvmfw_fdt_template",
Alice Wang12e4c862023-12-11 13:52:27 +000029 "libservice_vm_version",
Andrew Walbranf44f1602023-05-30 14:59:19 +000030 "libsmccc",
Pierre-Clément Tosi1cc5eb72023-02-02 11:09:18 +000031 "libstatic_assertions",
Pierre-Clément Tosi328dfb62022-11-25 18:20:42 +000032 "libtinyvec_nostd",
Pierre-Clément Tosi1cc5eb72023-02-02 11:09:18 +000033 "libuuid_nostd",
Andrew Walbrand1d03182022-12-09 18:20:01 +000034 "libvirtio_drivers",
Andrew Walbrandd74b902022-04-14 16:12:50 +000035 "libvmbase",
Alan Stokesa0e42962023-04-14 17:59:50 +010036 "libzerocopy_nostd",
Pierre-Clément Tosi8383c542022-11-01 14:07:29 +000037 "libzeroize_nostd",
Andrew Walbranf2594882022-03-15 17:32:53 +000038 ],
Andrew Walbran68a8c162022-03-07 15:38:42 +000039}
Andrew Walbran15068b02022-03-22 15:57:34 +000040
Alice Wang1c7e0eb2023-04-11 17:03:42 +000041// Generates an empty file.
42genrule {
43 name: "empty_file",
44 out: ["empty_file"],
45 cmd: "touch $(out)",
46}
47
Alan Stokesddb988c2023-11-27 11:13:06 +000048rust_defaults {
49 name: "libpvmfw.test.defaults",
Nikita Ioffeda1b2732023-09-04 13:46:56 +010050 defaults: ["avf_build_flags_rust"],
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090051 test_suites: ["general-tests"],
52 test_options: {
53 unit_test: true,
54 },
Alan Stokesddb988c2023-11-27 11:13:06 +000055 prefer_rlib: true,
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090056 rustlibs: [
Pierre-Clément Tosi1bf532b2023-11-13 11:06:20 +000057 "libcstr",
Alan Stokesddb988c2023-11-27 11:13:06 +000058 ],
59}
60
61rust_test {
62 name: "libpvmfw.bootargs.test",
63 host_supported: true,
64 // For now, only bootargs.rs is written to be conditionally compiled with std.
65 srcs: ["src/bootargs.rs"],
66 defaults: ["libpvmfw.test.defaults"],
67 rustlibs: [
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090068 "libzeroize",
69 ],
70}
71
Alan Stokesddb988c2023-11-27 11:13:06 +000072rust_test {
73 name: "libpvmfw.device_assignment.test",
74 srcs: ["src/device_assignment.rs"],
75 defaults: ["libpvmfw.test.defaults"],
76 rustlibs: [
Jaewan Kim52477ae2023-11-21 21:20:52 +090077 "libhyp",
Alan Stokesddb988c2023-11-27 11:13:06 +000078 "liblibfdt",
79 "liblog_rust",
80 "libpvmfw_fdt_template",
81 ],
82 data: [
83 ":test_pvmfw_devices_vm_dtbo",
84 ":test_pvmfw_devices_vm_dtbo_without_symbols",
Jaewan Kim19b984f2023-12-04 15:16:50 +090085 ":test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
Pierre-Clément Tosi49e26ce2024-03-12 16:31:50 +000086 ":test_pvmfw_devices_overlapping_pvmfw",
Alan Stokesddb988c2023-11-27 11:13:06 +000087 ":test_pvmfw_devices_with_rng",
Alan Stokesddb988c2023-11-27 11:13:06 +000088 ":test_pvmfw_devices_with_multiple_devices_iommus",
89 ":test_pvmfw_devices_with_iommu_sharing",
90 ":test_pvmfw_devices_with_iommu_id_conflict",
Jaewan Kim52477ae2023-11-21 21:20:52 +090091 ":test_pvmfw_devices_without_device",
Jaewan Kima67e36a2023-11-29 16:50:23 +090092 ":test_pvmfw_devices_without_iommus",
Jaewan Kim19b984f2023-12-04 15:16:50 +090093 ":test_pvmfw_devices_with_duplicated_pviommus",
94 ":test_pvmfw_devices_with_multiple_reg_iommus",
Alan Stokesddb988c2023-11-27 11:13:06 +000095 ],
96 // To use libpvmfw_fdt_template for testing
97 enabled: false,
98 target: {
99 android_arm64: {
100 enabled: true,
101 },
102 },
103}
104
105rust_test {
106 name: "libpvmfw.dice.test",
107 srcs: ["src/dice.rs"],
108 defaults: ["libpvmfw.test.defaults"],
109 rustlibs: [
110 "libcbor_util",
111 "libciborium",
112 "libdiced_open_dice_nostd",
113 "libpvmfw_avb_nostd",
Alan Stokesa17cfba2024-02-14 17:34:51 +0000114 "libzerocopy_nostd",
Alan Stokesddb988c2023-11-27 11:13:06 +0000115 ],
116}
117
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900118genrule {
119 name: "test_pvmfw_devices_vm_dtbo",
120 defaults: ["dts_to_dtb"],
121 srcs: ["testdata/test_pvmfw_devices_vm_dtbo.dts"],
122 out: ["test_pvmfw_devices_vm_dtbo.dtbo"],
123}
124
125genrule {
126 name: "test_pvmfw_devices_vm_dtbo_without_symbols",
127 defaults: ["dts_to_dtb"],
128 srcs: ["testdata/test_pvmfw_devices_vm_dtbo_without_symbols.dts"],
129 out: ["test_pvmfw_devices_vm_dtbo_without_symbols.dtbo"],
130}
131
Jaewan Kim19b984f2023-12-04 15:16:50 +0900132genrule {
133 name: "test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
134 defaults: ["dts_to_dtb"],
135 srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dts"],
136 out: ["test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dtbo"],
137}
138
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900139genrule_defaults {
140 name: "test_device_assignment_dts_to_dtb",
141 defaults: ["dts_to_dtb"],
142 srcs: ["testdata/test_crosvm_dt_base.dtsi"],
143}
144
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900145genrule {
Pierre-Clément Tosi49e26ce2024-03-12 16:31:50 +0000146 name: "test_pvmfw_devices_overlapping_pvmfw",
147 defaults: ["test_device_assignment_dts_to_dtb"],
148 srcs: ["testdata/test_pvmfw_devices_overlapping_pvmfw.dts"],
149 out: ["test_pvmfw_devices_overlapping_pvmfw.dtb"],
150}
151
152genrule {
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900153 name: "test_pvmfw_devices_with_rng",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900154 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900155 srcs: ["testdata/test_pvmfw_devices_with_rng.dts"],
156 out: ["test_pvmfw_devices_with_rng.dtb"],
157}
158
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900159genrule {
Jaewan Kima67e36a2023-11-29 16:50:23 +0900160 name: "test_pvmfw_devices_without_iommus",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900161 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kima67e36a2023-11-29 16:50:23 +0900162 srcs: ["testdata/test_pvmfw_devices_without_iommus.dts"],
163 out: ["test_pvmfw_devices_without_iommus.dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900164}
165
166genrule {
Jaewan Kim52477ae2023-11-21 21:20:52 +0900167 name: "test_pvmfw_devices_without_device",
168 defaults: ["test_device_assignment_dts_to_dtb"],
169 srcs: ["testdata/test_pvmfw_devices_without_device.dts"],
170 out: ["test_pvmfw_devices_without_device.dtb"],
171}
172
173genrule {
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900174 name: "test_pvmfw_devices_with_multiple_devices_iommus",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900175 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900176 srcs: ["testdata/test_pvmfw_devices_with_multiple_devices_iommus.dts"],
177 out: ["test_pvmfw_devices_with_multiple_devices_iommus.dtb"],
178}
179
180genrule {
181 name: "test_pvmfw_devices_with_iommu_sharing",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900182 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900183 srcs: ["testdata/test_pvmfw_devices_with_iommu_sharing.dts"],
184 out: ["test_pvmfw_devices_with_iommu_sharing.dtb"],
185}
186
187genrule {
188 name: "test_pvmfw_devices_with_iommu_id_conflict",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900189 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900190 srcs: ["testdata/test_pvmfw_devices_with_iommu_id_conflict.dts"],
191 out: ["test_pvmfw_devices_with_iommu_id_conflict.dtb"],
192}
193
Jaewan Kim19b984f2023-12-04 15:16:50 +0900194genrule {
195 name: "test_pvmfw_devices_with_duplicated_pviommus",
196 defaults: ["test_device_assignment_dts_to_dtb"],
197 srcs: ["testdata/test_pvmfw_devices_with_duplicated_pviommus.dts"],
198 out: ["test_pvmfw_devices_with_duplicated_pviommus.dtb"],
199}
200
201genrule {
202 name: "test_pvmfw_devices_with_multiple_reg_iommus",
203 defaults: ["test_device_assignment_dts_to_dtb"],
204 srcs: ["testdata/test_pvmfw_devices_with_multiple_reg_iommus.dts"],
205 out: ["test_pvmfw_devices_with_multiple_reg_iommus.dtb"],
206}
207
Andrew Walbran15068b02022-03-22 15:57:34 +0000208cc_binary {
Pierre-Clément Tosib1300352022-09-09 11:01:06 +0100209 name: "pvmfw",
David Brazdil30a7f082022-07-07 15:30:14 +0100210 defaults: ["vmbase_elf_defaults"],
Andrew Walbran15068b02022-03-22 15:57:34 +0000211 srcs: [
Andrew Walbran267f6c12022-03-24 11:26:36 +0000212 "idmap.S",
Andrew Walbran15068b02022-03-22 15:57:34 +0000213 ],
214 static_libs: [
215 "libpvmfw",
216 ],
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000217 linker_scripts: [
218 "image.ld",
219 ":vmbase_sections",
220 ],
Jiyong Park17b8d752022-12-16 14:36:24 +0900221 // `installable: false` is inherited from vmbase_elf_defaults, and that
222 // hides this module from Make, which makes it impossible for the Make world
223 // to place the unstripped binary to the symbols directory. Marking back as
224 // installable exposes this module to the Make world again. Note that this
225 // module (pvmfw) still is NOT installed to any of the filesystem images. It
226 // is fed into pvmfw_bin and then into pvmfw_img to become a standalone
227 // partition image. This is just to package the unstripped file into the
228 // symbols zip file for debugging purpose.
229 installable: true,
Andrew Walbran15068b02022-03-22 15:57:34 +0000230}
David Brazdil05d4e072022-04-25 14:47:06 +0100231
232raw_binary {
Pierre-Clément Tosib1300352022-09-09 11:01:06 +0100233 name: "pvmfw_bin",
234 stem: "pvmfw.bin",
235 src: ":pvmfw",
David Brazdil05d4e072022-04-25 14:47:06 +0100236 enabled: false,
237 target: {
238 android_arm64: {
239 enabled: true,
240 },
241 },
242}
David Brazdilac216b52022-04-25 15:07:22 +0100243
Jaewan Kim2cf6f392023-02-10 01:35:47 +0900244// Provide pvmfw.bin binary regardless of the architecture for building test.
245// Note that skipping tests on unsupported device is easy
246// while configuring server configuration to make such tests to run on working
247// devices.
248prebuilt_etc {
249 name: "pvmfw_test",
250 filename: "pvmfw_test.bin",
251 target: {
252 android_arm64: {
253 src: ":pvmfw_bin",
254 },
255 },
Alice Wang1c7e0eb2023-04-11 17:03:42 +0000256 src: ":empty_file",
Jaewan Kim2cf6f392023-02-10 01:35:47 +0900257 installable: false,
258}
259
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100260prebuilt_etc {
Pierre-Clément Tosi6ec2ae22022-10-26 15:14:45 +0100261 name: "pvmfw_embedded_key",
262 src: ":avb_testkey_rsa4096_pub_bin",
263 installable: false,
264}
265
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100266genrule {
267 name: "pvmfw_embedded_key_rs",
268 srcs: [":pvmfw_embedded_key"],
269 out: ["lib.rs"],
270 cmd: "(" +
271 " echo '#![no_std]';" +
272 " echo '#![allow(missing_docs)]';" +
273 " echo 'pub const PUBLIC_KEY: &[u8] = &[';" +
274 " xxd -i < $(in);" +
275 " echo '];';" +
276 ") > $(out)",
277}
278
279rust_library_rlib {
280 name: "libpvmfw_embedded_key",
Pierre-Clément Tosi4894b432023-06-27 14:02:26 +0000281 defaults: ["vmbase_rlib_defaults"],
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100282 srcs: [":pvmfw_embedded_key_rs"],
283 crate_name: "pvmfw_embedded_key",
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100284}
285
Pierre-Clément Tosi6ec2ae22022-10-26 15:14:45 +0100286prebuilt_etc {
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100287 name: "pvmfw_sign_key",
288 src: ":avb_testkey_rsa4096",
289 installable: false,
290}
291
Jiyong Park9c1c8182023-05-25 15:40:11 +0900292// We need to rename *.dts into *.cpp as cc_object doesn't accept *.dts as an
293// input
Jiyong Park216793e2023-02-25 02:15:44 +0900294genrule {
Jiyong Park9c1c8182023-05-25 15:40:11 +0900295 name: "pvmfw_platform.dts.renamed",
296 srcs: ["platform.dts"],
297 out: ["out.cpp"],
298 cmd: "cp $(in) $(out)",
299 visibility: ["//visibility:private"],
300}
301
302// Then run the macro processor to replace symbols like GIC_SPI into actual
303// numbers defined in the ARM DT binding headers
304cc_object {
305 name: "pvmfw_platform.dts.preprocessed",
Nikita Ioffe38b9e712024-02-08 15:55:07 +0000306 defaults: ["avf_build_flags_cc"],
Jiyong Park9c1c8182023-05-25 15:40:11 +0900307 header_libs: ["arm_dt_bindings_headers"],
308 host_supported: true,
309 srcs: [":pvmfw_platform.dts.renamed"],
310 cflags: [
311 "-E",
312 "-P",
313 "-xassembler-with-cpp", // allow C preprocessor directives
Jiyong Park216793e2023-02-25 02:15:44 +0900314 ],
Jiyong Park9c1c8182023-05-25 15:40:11 +0900315 visibility: ["//visibility:private"],
316}
317
318// Compile the preprocessed dts into binary and create a rust library source
319// having the binary.
320cc_genrule {
321 name: "pvmfw_fdt_template_rs",
322 srcs: [":pvmfw_platform.dts.preprocessed"],
Jiyong Park216793e2023-02-25 02:15:44 +0900323 out: ["lib.rs"],
324 tools: ["dtc"],
Jaewan Kim96411e92023-11-13 15:54:02 +0900325 cmd: "$(location dtc) -@ -I dts -O dtb -o $(genDir)/compiled.dtbo $(in) && " +
Jiyong Park216793e2023-02-25 02:15:44 +0900326 "(" +
327 " echo '#![no_std]';" +
328 " echo '#![allow(missing_docs)]';" +
329 " echo 'pub const RAW: &[u8] = &[';" +
330 " xxd -i < $(genDir)/compiled.dtbo;" +
331 " echo '];';" +
332 ") > $(out)",
Jiyong Park9c1c8182023-05-25 15:40:11 +0900333 visibility: ["//visibility:private"],
Jiyong Park216793e2023-02-25 02:15:44 +0900334}
335
336rust_library_rlib {
337 name: "libpvmfw_fdt_template",
Pierre-Clément Tosi4894b432023-06-27 14:02:26 +0000338 defaults: ["vmbase_rlib_defaults"],
Jiyong Park216793e2023-02-25 02:15:44 +0900339 srcs: [":pvmfw_fdt_template_rs"],
340 crate_name: "pvmfw_fdt_template",
341}
342
David Brazdilac216b52022-04-25 15:07:22 +0100343bootimg {
344 name: "pvmfw_img",
345 stem: "pvmfw.img",
346 kernel_prebuilt: ":pvmfw_bin",
347 header_version: "3",
348 partition_name: "pvmfw",
349 enabled: false,
350 target: {
351 android_arm64: {
352 enabled: true,
353 },
354 },
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100355 use_avb: true,
356 avb_private_key: ":pvmfw_sign_key",
David Brazdilac216b52022-04-25 15:07:22 +0100357}