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 "libcbor_util_nostd", 17 "libciborium_nostd", 18 "libciborium_io_nostd", 19 "libcoset_nostd", 20 "libcstr", 21 "libdiced_open_dice_nostd", 22 "libhypervisor_backends", 23 "liblibfdt_nostd", 24 "liblog_rust_nostd", 25 "libpvmfw_avb_nostd", 26 "libpvmfw_embedded_key", 27 "libpvmfw_fdt_template", 28 "libservice_vm_version", 29 "libsmccc", 30 "libstatic_assertions", 31 "libtinyvec_nostd", 32 "libuuid_nostd", 33 "libvirtio_drivers", 34 "libvmbase", 35 "libzerocopy_nostd", 36 "libzeroize_nostd", 37 ], 38} 39 40// Generates an empty file. 41genrule { 42 name: "empty_file", 43 out: ["empty_file"], 44 cmd: "touch $(out)", 45} 46 47rust_defaults { 48 name: "libpvmfw.test.defaults", 49 defaults: ["avf_build_flags_rust"], 50 test_suites: ["general-tests"], 51 test_options: { 52 unit_test: true, 53 }, 54 prefer_rlib: true, 55 rustlibs: [ 56 "libcstr", 57 ], 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: [ 67 "libzeroize", 68 ], 69} 70 71rust_test { 72 name: "libpvmfw.device_assignment.test", 73 srcs: ["src/device_assignment.rs"], 74 defaults: ["libpvmfw.test.defaults"], 75 rustlibs: [ 76 "libdts", 77 "liblibfdt", 78 "liblog_rust", 79 "libpvmfw_fdt_template", 80 "libzerocopy", 81 ], 82 data: [ 83 ":test_pvmfw_devices_vm_dtbo", 84 ":test_pvmfw_devices_vm_dtbo_without_symbols", 85 ":test_pvmfw_devices_vm_dtbo_with_duplicated_iommus", 86 ":test_pvmfw_devices_overlapping_pvmfw", 87 ":test_pvmfw_devices_vm_dtbo_with_dependencies", 88 ":test_pvmfw_devices_with_rng", 89 ":test_pvmfw_devices_with_multiple_devices_iommus", 90 ":test_pvmfw_devices_with_iommu_sharing", 91 ":test_pvmfw_devices_with_iommu_id_conflict", 92 ":test_pvmfw_devices_without_device", 93 ":test_pvmfw_devices_without_iommus", 94 ":test_pvmfw_devices_with_duplicated_pviommus", 95 ":test_pvmfw_devices_with_multiple_reg_iommus", 96 ":test_pvmfw_devices_with_dependency", 97 ":test_pvmfw_devices_with_dependency_loop", 98 ":test_pvmfw_devices_with_multiple_dependencies", 99 ":test_pvmfw_devices_expected_dt", 100 ], 101 data_bins: ["dtc_static"], 102 compile_multilib: "first", 103 // To use libpvmfw_fdt_template for testing 104 enabled: false, 105 target: { 106 android_arm64: { 107 enabled: true, 108 }, 109 }, 110} 111 112rust_test { 113 name: "libpvmfw.dice.test", 114 srcs: ["src/dice.rs"], 115 defaults: ["libpvmfw.test.defaults"], 116 rustlibs: [ 117 "libcbor_util", 118 "libciborium", 119 "libdiced_open_dice_nostd", 120 "libpvmfw_avb_nostd", 121 "libdiced_sample_inputs_nostd", 122 "libzerocopy_nostd", 123 "libhex", 124 ], 125 static_libs: ["libopen_dice_clear_memory"], 126} 127 128genrule { 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 142genrule { 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 149genrule { 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 157genrule_defaults { 158 name: "test_device_assignment_dts_to_dtb", 159 defaults: ["dts_to_dtb"], 160 srcs: ["testdata/test_crosvm_dt_base.dtsi"], 161} 162 163genrule { 164 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 { 171 name: "test_pvmfw_devices_with_rng", 172 defaults: ["test_device_assignment_dts_to_dtb"], 173 srcs: ["testdata/test_pvmfw_devices_with_rng.dts"], 174 out: ["test_pvmfw_devices_with_rng.dtb"], 175} 176 177genrule { 178 name: "test_pvmfw_devices_without_iommus", 179 defaults: ["test_device_assignment_dts_to_dtb"], 180 srcs: ["testdata/test_pvmfw_devices_without_iommus.dts"], 181 out: ["test_pvmfw_devices_without_iommus.dtb"], 182} 183 184genrule { 185 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 { 192 name: "test_pvmfw_devices_with_multiple_devices_iommus", 193 defaults: ["test_device_assignment_dts_to_dtb"], 194 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", 200 defaults: ["test_device_assignment_dts_to_dtb"], 201 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", 207 defaults: ["test_device_assignment_dts_to_dtb"], 208 srcs: ["testdata/test_pvmfw_devices_with_iommu_id_conflict.dts"], 209 out: ["test_pvmfw_devices_with_iommu_id_conflict.dtb"], 210} 211 212genrule { 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 226genrule { 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 273cc_binary { 274 name: "pvmfw", 275 defaults: ["vmbase_elf_defaults"], 276 srcs: [ 277 "idmap.S", 278 ], 279 static_libs: [ 280 "libpvmfw", 281 "libvmbase_dice_clear_memory", 282 ], 283 linker_scripts: [ 284 "image.ld", 285 ":vmbase_sections", 286 ], 287 // `installable: false` is inherited from vmbase_elf_defaults, and that 288 // hides this module from Make, which makes it impossible for the Make world 289 // to place the unstripped binary to the symbols directory. Marking back as 290 // installable exposes this module to the Make world again. Note that this 291 // module (pvmfw) still is NOT installed to any of the filesystem images. It 292 // is fed into pvmfw_bin and then into pvmfw_img to become a standalone 293 // partition image. This is just to package the unstripped file into the 294 // symbols zip file for debugging purpose. 295 installable: true, 296} 297 298raw_binary { 299 name: "pvmfw_bin", 300 stem: "pvmfw.bin", 301 src: ":pvmfw", 302 enabled: false, 303 target: { 304 android_arm64: { 305 enabled: true, 306 }, 307 }, 308} 309 310// Provide pvmfw.bin binary regardless of the architecture for building test. 311// Note that skipping tests on unsupported device is easy 312// while configuring server configuration to make such tests to run on working 313// devices. 314prebuilt_etc { 315 name: "pvmfw_test", 316 filename: "pvmfw_test.bin", 317 target: { 318 android_arm64: { 319 src: ":pvmfw_bin", 320 }, 321 }, 322 src: ":empty_file", 323 installable: false, 324} 325 326filegroup { 327 name: "pvmfw_embedded_key", 328 srcs: [":avb_testkey_rsa4096"], 329} 330 331genrule { 332 name: "pvmfw_embedded_key_pub_bin", 333 tools: ["avbtool"], 334 srcs: [":pvmfw_embedded_key"], 335 out: ["pvmfw_embedded_key_pub.bin"], 336 cmd: "$(location avbtool) extract_public_key --key $(in) --output $(out)", 337} 338 339genrule { 340 name: "pvmfw_embedded_key_rs", 341 srcs: [":pvmfw_embedded_key_pub_bin"], 342 out: ["lib.rs"], 343 cmd: "(" + 344 " echo '#![no_std]';" + 345 " echo '#![allow(missing_docs)]';" + 346 " echo 'pub const PUBLIC_KEY: &[u8] = &[';" + 347 " xxd -i < $(in);" + 348 " echo '];';" + 349 ") > $(out)", 350} 351 352rust_library_rlib { 353 name: "libpvmfw_embedded_key", 354 defaults: ["vmbase_rlib_defaults"], 355 srcs: [":pvmfw_embedded_key_rs"], 356 crate_name: "pvmfw_embedded_key", 357} 358 359prebuilt_etc { 360 name: "pvmfw_sign_key", 361 src: ":avb_testkey_rsa4096", 362 installable: false, 363} 364 365// We need to rename *.dts into *.cpp as cc_object doesn't accept *.dts as an 366// input 367genrule { 368 name: "pvmfw_platform.dts.renamed", 369 srcs: ["platform.dts"], 370 out: ["out.cpp"], 371 cmd: "cp $(in) $(out)", 372 visibility: ["//visibility:private"], 373} 374 375// Then run the macro processor to replace symbols like GIC_SPI into actual 376// numbers defined in the ARM DT binding headers 377cc_object { 378 name: "pvmfw_platform.dts.preprocessed", 379 defaults: ["avf_build_flags_cc"], 380 header_libs: ["arm_dt_bindings_headers"], 381 host_supported: true, 382 srcs: [":pvmfw_platform.dts.renamed"], 383 cflags: [ 384 "-E", 385 "-P", 386 "-xassembler-with-cpp", // allow C preprocessor directives 387 ], 388 visibility: ["//visibility:private"], 389} 390 391// Compile the preprocessed dts into binary and create a rust library source 392// having the binary. 393cc_genrule { 394 name: "pvmfw_fdt_template_rs", 395 srcs: [":pvmfw_platform.dts.preprocessed"], 396 out: ["lib.rs"], 397 tools: ["dtc"], 398 cmd: "$(location dtc) -@ -I dts -O dtb -o $(genDir)/compiled.dtbo $(in) && " + 399 "(" + 400 " echo '#![no_std]';" + 401 " echo '#![allow(missing_docs)]';" + 402 " echo 'pub const RAW: &[u8] = &[';" + 403 " xxd -i < $(genDir)/compiled.dtbo;" + 404 " echo '];';" + 405 ") > $(out)", 406 visibility: ["//visibility:private"], 407} 408 409rust_library_rlib { 410 name: "libpvmfw_fdt_template", 411 defaults: ["vmbase_rlib_defaults"], 412 srcs: [":pvmfw_fdt_template_rs"], 413 crate_name: "pvmfw_fdt_template", 414} 415 416bootimg { 417 name: "pvmfw_img", 418 stem: "pvmfw.img", 419 kernel_prebuilt: ":pvmfw_bin", 420 header_version: "3", 421 partition_name: "pvmfw", 422 enabled: false, 423 target: { 424 android_arm64: { 425 enabled: true, 426 }, 427 }, 428 use_avb: true, 429 avb_private_key: ":pvmfw_sign_key", 430} 431