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