blob: aa9942c74bcaecab8976ba34384152f3fb44940c [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",
Pierre-Clément Tosi90cd4f12023-02-17 11:19:56 +000016 "libbssl_ffi_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",
Andrew Walbranf44f1602023-05-30 14:59:19 +000029 "libsmccc",
Pierre-Clément Tosi1cc5eb72023-02-02 11:09:18 +000030 "libstatic_assertions",
Pierre-Clément Tosi328dfb62022-11-25 18:20:42 +000031 "libtinyvec_nostd",
Pierre-Clément Tosi1cc5eb72023-02-02 11:09:18 +000032 "libuuid_nostd",
Andrew Walbrand1d03182022-12-09 18:20:01 +000033 "libvirtio_drivers",
Andrew Walbrandd74b902022-04-14 16:12:50 +000034 "libvmbase",
Alan Stokesa0e42962023-04-14 17:59:50 +010035 "libzerocopy_nostd",
Pierre-Clément Tosi8383c542022-11-01 14:07:29 +000036 "libzeroize_nostd",
Andrew Walbranf2594882022-03-15 17:32:53 +000037 ],
Andrew Walbran68a8c162022-03-07 15:38:42 +000038}
Andrew Walbran15068b02022-03-22 15:57:34 +000039
Alice Wang1c7e0eb2023-04-11 17:03:42 +000040// Generates an empty file.
41genrule {
42 name: "empty_file",
43 out: ["empty_file"],
44 cmd: "touch $(out)",
45}
46
Alan Stokesddb988c2023-11-27 11:13:06 +000047rust_defaults {
48 name: "libpvmfw.test.defaults",
Nikita Ioffeda1b2732023-09-04 13:46:56 +010049 defaults: ["avf_build_flags_rust"],
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090050 test_suites: ["general-tests"],
51 test_options: {
52 unit_test: true,
53 },
Alan Stokesddb988c2023-11-27 11:13:06 +000054 prefer_rlib: true,
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090055 rustlibs: [
Pierre-Clément Tosi1bf532b2023-11-13 11:06:20 +000056 "libcstr",
Alan Stokesddb988c2023-11-27 11:13:06 +000057 ],
58}
59
60rust_test {
61 name: "libpvmfw.bootargs.test",
62 host_supported: true,
63 // For now, only bootargs.rs is written to be conditionally compiled with std.
64 srcs: ["src/bootargs.rs"],
65 defaults: ["libpvmfw.test.defaults"],
66 rustlibs: [
Jiyong Parkc5d2ef22023-04-11 01:23:46 +090067 "libzeroize",
68 ],
69}
70
Alan Stokesddb988c2023-11-27 11:13:06 +000071rust_test {
72 name: "libpvmfw.device_assignment.test",
73 srcs: ["src/device_assignment.rs"],
74 defaults: ["libpvmfw.test.defaults"],
75 rustlibs: [
Jaewan Kim52477ae2023-11-21 21:20:52 +090076 "libhyp",
Alan Stokesddb988c2023-11-27 11:13:06 +000077 "liblibfdt",
78 "liblog_rust",
79 "libpvmfw_fdt_template",
80 ],
81 data: [
82 ":test_pvmfw_devices_vm_dtbo",
83 ":test_pvmfw_devices_vm_dtbo_without_symbols",
84 ":test_pvmfw_devices_with_rng",
Alan Stokesddb988c2023-11-27 11:13:06 +000085 ":test_pvmfw_devices_with_multiple_devices_iommus",
86 ":test_pvmfw_devices_with_iommu_sharing",
87 ":test_pvmfw_devices_with_iommu_id_conflict",
Jaewan Kim52477ae2023-11-21 21:20:52 +090088 ":test_pvmfw_devices_without_device",
Jaewan Kima67e36a2023-11-29 16:50:23 +090089 ":test_pvmfw_devices_without_iommus",
Alan Stokesddb988c2023-11-27 11:13:06 +000090 ],
91 // To use libpvmfw_fdt_template for testing
92 enabled: false,
93 target: {
94 android_arm64: {
95 enabled: true,
96 },
97 },
98}
99
100rust_test {
101 name: "libpvmfw.dice.test",
102 srcs: ["src/dice.rs"],
103 defaults: ["libpvmfw.test.defaults"],
104 rustlibs: [
105 "libcbor_util",
106 "libciborium",
107 "libdiced_open_dice_nostd",
108 "libpvmfw_avb_nostd",
109 ],
110}
111
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900112genrule {
113 name: "test_pvmfw_devices_vm_dtbo",
114 defaults: ["dts_to_dtb"],
115 srcs: ["testdata/test_pvmfw_devices_vm_dtbo.dts"],
116 out: ["test_pvmfw_devices_vm_dtbo.dtbo"],
117}
118
119genrule {
120 name: "test_pvmfw_devices_vm_dtbo_without_symbols",
121 defaults: ["dts_to_dtb"],
122 srcs: ["testdata/test_pvmfw_devices_vm_dtbo_without_symbols.dts"],
123 out: ["test_pvmfw_devices_vm_dtbo_without_symbols.dtbo"],
124}
125
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900126genrule_defaults {
127 name: "test_device_assignment_dts_to_dtb",
128 defaults: ["dts_to_dtb"],
129 srcs: ["testdata/test_crosvm_dt_base.dtsi"],
130}
131
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900132genrule {
133 name: "test_pvmfw_devices_with_rng",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900134 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kimc6e023b2023-10-12 15:11:05 +0900135 srcs: ["testdata/test_pvmfw_devices_with_rng.dts"],
136 out: ["test_pvmfw_devices_with_rng.dtb"],
137}
138
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900139genrule {
Jaewan Kima67e36a2023-11-29 16:50:23 +0900140 name: "test_pvmfw_devices_without_iommus",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900141 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kima67e36a2023-11-29 16:50:23 +0900142 srcs: ["testdata/test_pvmfw_devices_without_iommus.dts"],
143 out: ["test_pvmfw_devices_without_iommus.dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900144}
145
146genrule {
Jaewan Kim52477ae2023-11-21 21:20:52 +0900147 name: "test_pvmfw_devices_without_device",
148 defaults: ["test_device_assignment_dts_to_dtb"],
149 srcs: ["testdata/test_pvmfw_devices_without_device.dts"],
150 out: ["test_pvmfw_devices_without_device.dtb"],
151}
152
153genrule {
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900154 name: "test_pvmfw_devices_with_multiple_devices_iommus",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900155 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900156 srcs: ["testdata/test_pvmfw_devices_with_multiple_devices_iommus.dts"],
157 out: ["test_pvmfw_devices_with_multiple_devices_iommus.dtb"],
158}
159
160genrule {
161 name: "test_pvmfw_devices_with_iommu_sharing",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900162 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900163 srcs: ["testdata/test_pvmfw_devices_with_iommu_sharing.dts"],
164 out: ["test_pvmfw_devices_with_iommu_sharing.dtb"],
165}
166
167genrule {
168 name: "test_pvmfw_devices_with_iommu_id_conflict",
Jaewan Kimcb0d45d2023-11-30 15:40:12 +0900169 defaults: ["test_device_assignment_dts_to_dtb"],
Jaewan Kim51ccfed2023-11-08 13:51:58 +0900170 srcs: ["testdata/test_pvmfw_devices_with_iommu_id_conflict.dts"],
171 out: ["test_pvmfw_devices_with_iommu_id_conflict.dtb"],
172}
173
Andrew Walbran15068b02022-03-22 15:57:34 +0000174cc_binary {
Pierre-Clément Tosib1300352022-09-09 11:01:06 +0100175 name: "pvmfw",
David Brazdil30a7f082022-07-07 15:30:14 +0100176 defaults: ["vmbase_elf_defaults"],
Andrew Walbran15068b02022-03-22 15:57:34 +0000177 srcs: [
Andrew Walbran267f6c12022-03-24 11:26:36 +0000178 "idmap.S",
Andrew Walbran15068b02022-03-22 15:57:34 +0000179 ],
180 static_libs: [
181 "libpvmfw",
182 ],
Andrew Walbrana5b7af52022-07-06 15:06:20 +0000183 linker_scripts: [
184 "image.ld",
185 ":vmbase_sections",
186 ],
Jiyong Park17b8d752022-12-16 14:36:24 +0900187 // `installable: false` is inherited from vmbase_elf_defaults, and that
188 // hides this module from Make, which makes it impossible for the Make world
189 // to place the unstripped binary to the symbols directory. Marking back as
190 // installable exposes this module to the Make world again. Note that this
191 // module (pvmfw) still is NOT installed to any of the filesystem images. It
192 // is fed into pvmfw_bin and then into pvmfw_img to become a standalone
193 // partition image. This is just to package the unstripped file into the
194 // symbols zip file for debugging purpose.
195 installable: true,
Andrew Walbran15068b02022-03-22 15:57:34 +0000196}
David Brazdil05d4e072022-04-25 14:47:06 +0100197
198raw_binary {
Pierre-Clément Tosib1300352022-09-09 11:01:06 +0100199 name: "pvmfw_bin",
200 stem: "pvmfw.bin",
201 src: ":pvmfw",
David Brazdil05d4e072022-04-25 14:47:06 +0100202 enabled: false,
203 target: {
204 android_arm64: {
205 enabled: true,
206 },
207 },
208}
David Brazdilac216b52022-04-25 15:07:22 +0100209
Jaewan Kim2cf6f392023-02-10 01:35:47 +0900210// Provide pvmfw.bin binary regardless of the architecture for building test.
211// Note that skipping tests on unsupported device is easy
212// while configuring server configuration to make such tests to run on working
213// devices.
214prebuilt_etc {
215 name: "pvmfw_test",
216 filename: "pvmfw_test.bin",
217 target: {
218 android_arm64: {
219 src: ":pvmfw_bin",
220 },
221 },
Alice Wang1c7e0eb2023-04-11 17:03:42 +0000222 src: ":empty_file",
Jaewan Kim2cf6f392023-02-10 01:35:47 +0900223 installable: false,
224}
225
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100226prebuilt_etc {
Pierre-Clément Tosi6ec2ae22022-10-26 15:14:45 +0100227 name: "pvmfw_embedded_key",
228 src: ":avb_testkey_rsa4096_pub_bin",
229 installable: false,
230}
231
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100232genrule {
233 name: "pvmfw_embedded_key_rs",
234 srcs: [":pvmfw_embedded_key"],
235 out: ["lib.rs"],
236 cmd: "(" +
237 " echo '#![no_std]';" +
238 " echo '#![allow(missing_docs)]';" +
239 " echo 'pub const PUBLIC_KEY: &[u8] = &[';" +
240 " xxd -i < $(in);" +
241 " echo '];';" +
242 ") > $(out)",
243}
244
245rust_library_rlib {
246 name: "libpvmfw_embedded_key",
Pierre-Clément Tosi4894b432023-06-27 14:02:26 +0000247 defaults: ["vmbase_rlib_defaults"],
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100248 srcs: [":pvmfw_embedded_key_rs"],
249 crate_name: "pvmfw_embedded_key",
Pierre-Clément Tosi4ef75222022-10-26 17:40:50 +0100250}
251
Pierre-Clément Tosi6ec2ae22022-10-26 15:14:45 +0100252prebuilt_etc {
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100253 name: "pvmfw_sign_key",
254 src: ":avb_testkey_rsa4096",
255 installable: false,
256}
257
Jiyong Park9c1c8182023-05-25 15:40:11 +0900258// We need to rename *.dts into *.cpp as cc_object doesn't accept *.dts as an
259// input
Jiyong Park216793e2023-02-25 02:15:44 +0900260genrule {
Jiyong Park9c1c8182023-05-25 15:40:11 +0900261 name: "pvmfw_platform.dts.renamed",
262 srcs: ["platform.dts"],
263 out: ["out.cpp"],
264 cmd: "cp $(in) $(out)",
265 visibility: ["//visibility:private"],
266}
267
268// Then run the macro processor to replace symbols like GIC_SPI into actual
269// numbers defined in the ARM DT binding headers
270cc_object {
271 name: "pvmfw_platform.dts.preprocessed",
272 header_libs: ["arm_dt_bindings_headers"],
273 host_supported: true,
274 srcs: [":pvmfw_platform.dts.renamed"],
275 cflags: [
276 "-E",
277 "-P",
278 "-xassembler-with-cpp", // allow C preprocessor directives
Jiyong Park216793e2023-02-25 02:15:44 +0900279 ],
Jiyong Park9c1c8182023-05-25 15:40:11 +0900280 visibility: ["//visibility:private"],
281}
282
283// Compile the preprocessed dts into binary and create a rust library source
284// having the binary.
285cc_genrule {
286 name: "pvmfw_fdt_template_rs",
287 srcs: [":pvmfw_platform.dts.preprocessed"],
Jiyong Park216793e2023-02-25 02:15:44 +0900288 out: ["lib.rs"],
289 tools: ["dtc"],
Jaewan Kim96411e92023-11-13 15:54:02 +0900290 cmd: "$(location dtc) -@ -I dts -O dtb -o $(genDir)/compiled.dtbo $(in) && " +
Jiyong Park216793e2023-02-25 02:15:44 +0900291 "(" +
292 " echo '#![no_std]';" +
293 " echo '#![allow(missing_docs)]';" +
294 " echo 'pub const RAW: &[u8] = &[';" +
295 " xxd -i < $(genDir)/compiled.dtbo;" +
296 " echo '];';" +
297 ") > $(out)",
Jiyong Park9c1c8182023-05-25 15:40:11 +0900298 visibility: ["//visibility:private"],
Jiyong Park216793e2023-02-25 02:15:44 +0900299}
300
301rust_library_rlib {
302 name: "libpvmfw_fdt_template",
Pierre-Clément Tosi4894b432023-06-27 14:02:26 +0000303 defaults: ["vmbase_rlib_defaults"],
Jiyong Park216793e2023-02-25 02:15:44 +0900304 srcs: [":pvmfw_fdt_template_rs"],
305 crate_name: "pvmfw_fdt_template",
306}
307
David Brazdilac216b52022-04-25 15:07:22 +0100308bootimg {
309 name: "pvmfw_img",
310 stem: "pvmfw.img",
311 kernel_prebuilt: ":pvmfw_bin",
312 header_version: "3",
313 partition_name: "pvmfw",
314 enabled: false,
315 target: {
316 android_arm64: {
317 enabled: true,
318 },
319 },
Pierre-Clément Tosib5771c02022-09-06 16:01:35 +0100320 use_avb: true,
321 avb_private_key: ":pvmfw_sign_key",
David Brazdilac216b52022-04-25 15:07:22 +0100322}