• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package {
2    default_applicable_licenses: ["Android-Apache-2.0"],
3}
4
5rust_ffi_static {
6    name: "libpvmfw",
7    crate_name: "pvmfw",
8    defaults: ["vmbase_ffi_defaults"],
9    srcs: ["src/main.rs"],
10    features: [
11        "legacy",
12    ],
13    rustlibs: [
14        "libbssl_avf_nostd",
15        "libcbor_util_nostd",
16        "libciborium_nostd",
17        "libciborium_io_nostd",
18        "libcoset_nostd",
19        "libdiced_open_dice_nostd",
20        "libhypervisor_backends",
21        "liblibfdt_nostd",
22        "liblog_rust_nostd",
23        "libpvmfw_avb_nostd",
24        "libpvmfw_embedded_key",
25        "libpvmfw_fdt_template",
26        "libstatic_assertions",
27        "libtinyvec_nostd",
28        "libuuid_nostd",
29        "libvirtio_drivers",
30        "libvmbase",
31        "libzerocopy_nostd",
32        "libzeroize_nostd",
33    ],
34    target: {
35        android_arm64: {
36            rustlibs: [
37                "libaarch64_paging",
38                "libsmccc",
39                "libservice_vm_version",
40            ],
41        },
42    },
43}
44
45// Generates an empty file.
46genrule {
47    name: "empty_file",
48    out: ["empty_file"],
49    cmd: "touch $(out)",
50}
51
52rust_defaults {
53    name: "libpvmfw.test.defaults",
54    defaults: ["avf_build_flags_rust"],
55    test_suites: ["general-tests"],
56    test_options: {
57        unit_test: true,
58    },
59    prefer_rlib: true,
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: [
69        "libzeroize",
70    ],
71}
72
73rust_test {
74    name: "libpvmfw.device_assignment.test",
75    srcs: ["src/device_assignment.rs"],
76    defaults: ["libpvmfw.test.defaults"],
77    rustlibs: [
78        "libdts",
79        "liblibfdt",
80        "liblog_rust",
81        "libpvmfw_fdt_template",
82        "libzerocopy",
83    ],
84    data: [
85        ":test_pvmfw_devices_vm_dtbo",
86        ":test_pvmfw_devices_vm_dtbo_without_symbols",
87        ":test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
88        ":test_pvmfw_devices_overlapping_pvmfw",
89        ":test_pvmfw_devices_vm_dtbo_with_dependencies",
90        ":test_pvmfw_devices_with_rng",
91        ":test_pvmfw_devices_with_multiple_devices_iommus",
92        ":test_pvmfw_devices_with_iommu_sharing",
93        ":test_pvmfw_devices_with_iommu_id_conflict",
94        ":test_pvmfw_devices_without_device",
95        ":test_pvmfw_devices_without_iommus",
96        ":test_pvmfw_devices_with_duplicated_pviommus",
97        ":test_pvmfw_devices_with_multiple_reg_iommus",
98        ":test_pvmfw_devices_with_dependency",
99        ":test_pvmfw_devices_with_dependency_loop",
100        ":test_pvmfw_devices_with_multiple_dependencies",
101        ":test_pvmfw_devices_expected_dt",
102    ],
103    data_bins: ["dtc_static"],
104    compile_multilib: "first",
105    // To use libpvmfw_fdt_template for testing
106    enabled: false,
107    target: {
108        android_arm64: {
109            enabled: true,
110        },
111    },
112}
113
114rust_test {
115    name: "libpvmfw.dice.test",
116    srcs: ["src/dice/mod.rs"],
117    defaults: ["libpvmfw.test.defaults"],
118    rustlibs: [
119        "libcbor_util",
120        "libciborium",
121        "libcoset_nostd",
122        "libdiced_open_dice_nostd",
123        "libhwtrust",
124        "liblog_rust",
125        "libpvmfw_avb_nostd",
126        "libdiced_sample_inputs_nostd",
127        "libzerocopy_nostd",
128        "libhex",
129    ],
130    static_libs: ["libopen_dice_clear_memory"],
131}
132
133genrule {
134    name: "test_pvmfw_devices_vm_dtbo",
135    defaults: ["dts_to_dtb"],
136    srcs: ["testdata/test_pvmfw_devices_vm_dtbo.dts"],
137    out: ["test_pvmfw_devices_vm_dtbo.dtbo"],
138}
139
140genrule {
141    name: "test_pvmfw_devices_vm_dtbo_without_symbols",
142    defaults: ["dts_to_dtb"],
143    srcs: ["testdata/test_pvmfw_devices_vm_dtbo_without_symbols.dts"],
144    out: ["test_pvmfw_devices_vm_dtbo_without_symbols.dtbo"],
145}
146
147genrule {
148    name: "test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
149    defaults: ["dts_to_dtb"],
150    srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dts"],
151    out: ["test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dtbo"],
152}
153
154genrule {
155    name: "test_pvmfw_devices_vm_dtbo_with_dependencies",
156    tools: ["dtc"],
157    cmd: "$(location dtc) -@ -I dts -O dtb $(in) -o $(out)",
158    srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_dependencies.dts"],
159    out: ["test_pvmfw_devices_vm_dtbo_with_dependencies.dtbo"],
160}
161
162genrule_defaults {
163    name: "test_device_assignment_dts_to_dtb",
164    defaults: ["dts_to_dtb"],
165    srcs: ["testdata/test_crosvm_dt_base.dtsi"],
166}
167
168genrule {
169    name: "test_pvmfw_devices_overlapping_pvmfw",
170    defaults: ["test_device_assignment_dts_to_dtb"],
171    srcs: ["testdata/test_pvmfw_devices_overlapping_pvmfw.dts"],
172    out: ["test_pvmfw_devices_overlapping_pvmfw.dtb"],
173}
174
175genrule {
176    name: "test_pvmfw_devices_with_rng",
177    defaults: ["test_device_assignment_dts_to_dtb"],
178    srcs: ["testdata/test_pvmfw_devices_with_rng.dts"],
179    out: ["test_pvmfw_devices_with_rng.dtb"],
180}
181
182genrule {
183    name: "test_pvmfw_devices_without_iommus",
184    defaults: ["test_device_assignment_dts_to_dtb"],
185    srcs: ["testdata/test_pvmfw_devices_without_iommus.dts"],
186    out: ["test_pvmfw_devices_without_iommus.dtb"],
187}
188
189genrule {
190    name: "test_pvmfw_devices_without_device",
191    defaults: ["test_device_assignment_dts_to_dtb"],
192    srcs: ["testdata/test_pvmfw_devices_without_device.dts"],
193    out: ["test_pvmfw_devices_without_device.dtb"],
194}
195
196genrule {
197    name: "test_pvmfw_devices_with_multiple_devices_iommus",
198    defaults: ["test_device_assignment_dts_to_dtb"],
199    srcs: ["testdata/test_pvmfw_devices_with_multiple_devices_iommus.dts"],
200    out: ["test_pvmfw_devices_with_multiple_devices_iommus.dtb"],
201}
202
203genrule {
204    name: "test_pvmfw_devices_with_iommu_sharing",
205    defaults: ["test_device_assignment_dts_to_dtb"],
206    srcs: ["testdata/test_pvmfw_devices_with_iommu_sharing.dts"],
207    out: ["test_pvmfw_devices_with_iommu_sharing.dtb"],
208}
209
210genrule {
211    name: "test_pvmfw_devices_with_iommu_id_conflict",
212    defaults: ["test_device_assignment_dts_to_dtb"],
213    srcs: ["testdata/test_pvmfw_devices_with_iommu_id_conflict.dts"],
214    out: ["test_pvmfw_devices_with_iommu_id_conflict.dtb"],
215}
216
217genrule {
218    name: "test_pvmfw_devices_with_duplicated_pviommus",
219    defaults: ["test_device_assignment_dts_to_dtb"],
220    srcs: ["testdata/test_pvmfw_devices_with_duplicated_pviommus.dts"],
221    out: ["test_pvmfw_devices_with_duplicated_pviommus.dtb"],
222}
223
224genrule {
225    name: "test_pvmfw_devices_with_multiple_reg_iommus",
226    defaults: ["test_device_assignment_dts_to_dtb"],
227    srcs: ["testdata/test_pvmfw_devices_with_multiple_reg_iommus.dts"],
228    out: ["test_pvmfw_devices_with_multiple_reg_iommus.dtb"],
229}
230
231genrule {
232    name: "test_pvmfw_devices_with_dependency",
233    defaults: ["test_device_assignment_dts_to_dtb"],
234    srcs: ["testdata/test_pvmfw_devices_with_dependency.dts"],
235    out: ["test_pvmfw_devices_with_dependency.dtb"],
236}
237
238genrule {
239    name: "test_pvmfw_devices_with_multiple_dependencies",
240    defaults: ["test_device_assignment_dts_to_dtb"],
241    srcs: ["testdata/test_pvmfw_devices_with_multiple_dependencies.dts"],
242    out: ["test_pvmfw_devices_with_multiple_dependencies.dtb"],
243}
244
245genrule {
246    name: "test_pvmfw_devices_with_dependency_loop",
247    defaults: ["test_device_assignment_dts_to_dtb"],
248    srcs: ["testdata/test_pvmfw_devices_with_dependency_loop.dts"],
249    out: ["test_pvmfw_devices_with_dependency_loop.dtb"],
250}
251
252// We can't use genrule because preprocessed platform DT is built with cc_object.
253// cc_genrule doesn't support default, so we'll build all expected DTs in
254// a single build rule.
255cc_genrule {
256    name: "test_pvmfw_devices_expected_dt",
257    srcs: [
258        ":pvmfw_platform.dts.preprocessed",
259        "testdata/expected_dt_with_dependency.dts",
260        "testdata/expected_dt_with_multiple_dependencies.dts",
261        "testdata/expected_dt_with_dependency_loop.dts",
262    ],
263    out: [
264        "expected_dt_with_dependency.dtb",
265        "expected_dt_with_multiple_dependencies.dtb",
266        "expected_dt_with_dependency_loop.dtb",
267    ],
268    tools: ["dtc"],
269    cmd: "FILES=($(in));" +
270        "cp $${FILES[0]} $(genDir)/platform_preprocessed.dts;" +
271        "for DTS in $${FILES[@]:1}; do" +
272        "  DTB=$$(basename -s .dts $${DTS}).dtb;" +
273        "  $(location dtc) -@ -i $(genDir) -I dts -O dtb $${DTS} -o $(genDir)/$${DTB};" +
274        "done",
275    visibility: ["//visibility:private"],
276}
277
278cc_binary {
279    name: "pvmfw",
280    defaults: ["vmbase_elf_defaults"],
281    static_libs: [
282        "libpvmfw",
283        "libvmbase_dice_clear_memory",
284    ],
285    target: {
286        android_arm64: {
287            srcs: [
288                "asm/aarch64/idmap.S",
289            ],
290            linker_scripts: [
291                "asm/aarch64/image.ld",
292                ":vmbase_sections",
293            ],
294        },
295    },
296    // `installable: false` is inherited from vmbase_elf_defaults, and that
297    // hides this module from Make, which makes it impossible for the Make world
298    // to place the unstripped binary to the symbols directory. Marking back as
299    // installable exposes this module to the Make world again. Note that this
300    // module (pvmfw) still is NOT installed to any of the filesystem images. It
301    // is fed into pvmfw_bin and then into pvmfw_img to become a standalone
302    // partition image. This is just to package the unstripped file into the
303    // symbols zip file for debugging purpose.
304    installable: true,
305}
306
307raw_binary {
308    name: "pvmfw_bin",
309    stem: "pvmfw.bin",
310    src: ":pvmfw",
311    enabled: false,
312    target: {
313        android_arm64: {
314            enabled: true,
315        },
316    },
317}
318
319// Provide pvmfw.bin binary regardless of the architecture for building test.
320// Note that skipping tests on unsupported device is easy
321// while configuring server configuration to make such tests to run on working
322// devices.
323prebuilt_etc {
324    name: "pvmfw_test",
325    filename: "pvmfw_test.bin",
326    target: {
327        android_arm64: {
328            src: ":pvmfw_bin",
329        },
330    },
331    src: ":empty_file",
332    installable: false,
333}
334
335filegroup {
336    name: "pvmfw_embedded_key",
337    srcs: [":avb_testkey_rsa4096"],
338}
339
340genrule {
341    name: "pvmfw_embedded_key_pub_bin",
342    tools: ["avbtool"],
343    srcs: [":pvmfw_embedded_key"],
344    out: ["pvmfw_embedded_key_pub.bin"],
345    cmd: "$(location avbtool) extract_public_key --key $(in) --output $(out)",
346}
347
348genrule {
349    name: "pvmfw_embedded_key_rs",
350    srcs: [":pvmfw_embedded_key_pub_bin"],
351    out: ["lib.rs"],
352    cmd: "(" +
353        "    echo '#![no_std]';" +
354        "    echo '#![allow(missing_docs)]';" +
355        "    echo 'pub const PUBLIC_KEY: &[u8] = &[';" +
356        "    xxd -i < $(in);" +
357        "    echo '];';" +
358        ") > $(out)",
359}
360
361rust_library_rlib {
362    name: "libpvmfw_embedded_key",
363    defaults: ["vmbase_rlib_defaults"],
364    srcs: [":pvmfw_embedded_key_rs"],
365    crate_name: "pvmfw_embedded_key",
366}
367
368prebuilt_etc {
369    name: "pvmfw_sign_key",
370    src: ":avb_testkey_rsa4096",
371    installable: false,
372}
373
374// We need to rename *.dts into *.cpp as cc_object doesn't accept *.dts as an
375// input
376genrule {
377    name: "pvmfw_platform.dts.renamed",
378    srcs: ["platform.dts"],
379    out: ["out.cpp"],
380    cmd: "cp $(in) $(out)",
381    visibility: ["//visibility:private"],
382}
383
384// Then run the macro processor to replace symbols like GIC_SPI into actual
385// numbers defined in the ARM DT binding headers
386cc_object {
387    name: "pvmfw_platform.dts.preprocessed",
388    defaults: ["avf_build_flags_cc"],
389    header_libs: ["arm_dt_bindings_headers"],
390    host_supported: true,
391    srcs: [":pvmfw_platform.dts.renamed"],
392    cflags: [
393        "-E",
394        "-P",
395        "-xassembler-with-cpp", // allow C preprocessor directives
396        // Suppress an error about the unused -c that precedes -S.
397        "-Wno-unused-command-line-argument",
398    ],
399    visibility: ["//visibility:private"],
400}
401
402// Compile the preprocessed dts into binary and create a rust library source
403// having the binary.
404cc_genrule {
405    name: "pvmfw_fdt_template_rs",
406    srcs: [":pvmfw_platform.dts.preprocessed"],
407    out: ["lib.rs"],
408    tools: ["dtc"],
409    cmd: "$(location dtc) -@ -I dts -O dtb -o $(genDir)/compiled.dtbo $(in) && " +
410        "(" +
411        "    echo '#![no_std]';" +
412        "    echo '#![allow(missing_docs)]';" +
413        "    echo 'pub const RAW: &[u8] = &[';" +
414        "    xxd -i < $(genDir)/compiled.dtbo;" +
415        "    echo '];';" +
416        ") > $(out)",
417    visibility: ["//visibility:private"],
418}
419
420rust_library_rlib {
421    name: "libpvmfw_fdt_template",
422    defaults: ["vmbase_rlib_defaults"],
423    srcs: [":pvmfw_fdt_template_rs"],
424    crate_name: "pvmfw_fdt_template",
425}
426
427bootimg {
428    name: "pvmfw_img",
429    stem: "pvmfw.img",
430    kernel_prebuilt: ":pvmfw_bin",
431    header_version: "3",
432    partition_name: "pvmfw",
433    enabled: false,
434    target: {
435        android_arm64: {
436            enabled: true,
437        },
438    },
439    use_avb: true,
440    avb_private_key: ":pvmfw_sign_key",
441}
442