aboutsummaryrefslogtreecommitdiff
path: root/pvmfw/Android.bp
blob: 37a321d2ff7438223466e135108283684f6ce02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

rust_ffi_static {
    name: "libpvmfw",
    crate_name: "pvmfw",
    defaults: ["vmbase_ffi_defaults"],
    srcs: ["src/main.rs"],
    features: [
        "legacy",
    ],
    rustlibs: [
        "libaarch64_paging",
        "libbssl_avf_nostd",
        "libbssl_sys_nostd",
        "libciborium_nostd",
        "libciborium_io_nostd",
        "libcstr",
        "libdiced_open_dice_nostd",
        "libfdtpci",
        "liblibfdt",
        "liblog_rust_nostd",
        "libonce_cell_nostd",
        "libpvmfw_avb_nostd",
        "libpvmfw_embedded_key",
        "libpvmfw_fdt_template",
        "libservice_vm_version",
        "libsmccc",
        "libstatic_assertions",
        "libtinyvec_nostd",
        "libuuid_nostd",
        "libvirtio_drivers",
        "libvmbase",
        "libzerocopy_nostd",
        "libzeroize_nostd",
    ],
}

// Generates an empty file.
genrule {
    name: "empty_file",
    out: ["empty_file"],
    cmd: "touch $(out)",
}

rust_defaults {
    name: "libpvmfw.test.defaults",
    defaults: ["avf_build_flags_rust"],
    test_suites: ["general-tests"],
    test_options: {
        unit_test: true,
    },
    prefer_rlib: true,
    rustlibs: [
        "libcstr",
    ],
}

rust_test {
    name: "libpvmfw.bootargs.test",
    host_supported: true,
    // For now, only bootargs.rs is written to be conditionally compiled with std.
    srcs: ["src/bootargs.rs"],
    defaults: ["libpvmfw.test.defaults"],
    rustlibs: [
        "libzeroize",
    ],
}

rust_test {
    name: "libpvmfw.device_assignment.test",
    srcs: ["src/device_assignment.rs"],
    defaults: ["libpvmfw.test.defaults"],
    rustlibs: [
        "libdts",
        "liblibfdt",
        "liblog_rust",
        "libpvmfw_fdt_template",
        "libzerocopy",
    ],
    data: [
        ":test_pvmfw_devices_vm_dtbo",
        ":test_pvmfw_devices_vm_dtbo_without_symbols",
        ":test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
        ":test_pvmfw_devices_overlapping_pvmfw",
        ":test_pvmfw_devices_vm_dtbo_with_dependencies",
        ":test_pvmfw_devices_with_rng",
        ":test_pvmfw_devices_with_multiple_devices_iommus",
        ":test_pvmfw_devices_with_iommu_sharing",
        ":test_pvmfw_devices_with_iommu_id_conflict",
        ":test_pvmfw_devices_without_device",
        ":test_pvmfw_devices_without_iommus",
        ":test_pvmfw_devices_with_duplicated_pviommus",
        ":test_pvmfw_devices_with_multiple_reg_iommus",
        ":test_pvmfw_devices_with_dependency",
        ":test_pvmfw_devices_with_dependency_loop",
        ":test_pvmfw_devices_with_multiple_dependencies",
        ":test_pvmfw_devices_expected_dt",
    ],
    data_bins: ["dtc_static"],
    compile_multilib: "first",
    // To use libpvmfw_fdt_template for testing
    enabled: false,
    target: {
        android_arm64: {
            enabled: true,
        },
    },
}

rust_test {
    name: "libpvmfw.dice.test",
    srcs: ["src/dice.rs"],
    defaults: ["libpvmfw.test.defaults"],
    rustlibs: [
        "libcbor_util",
        "libciborium",
        "libdiced_open_dice_nostd",
        "libpvmfw_avb_nostd",
        "libzerocopy_nostd",
    ],
}

genrule {
    name: "test_pvmfw_devices_vm_dtbo",
    defaults: ["dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_vm_dtbo.dts"],
    out: ["test_pvmfw_devices_vm_dtbo.dtbo"],
}

genrule {
    name: "test_pvmfw_devices_vm_dtbo_without_symbols",
    defaults: ["dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_vm_dtbo_without_symbols.dts"],
    out: ["test_pvmfw_devices_vm_dtbo_without_symbols.dtbo"],
}

genrule {
    name: "test_pvmfw_devices_vm_dtbo_with_duplicated_iommus",
    defaults: ["dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dts"],
    out: ["test_pvmfw_devices_vm_dtbo_with_duplicated_iommus.dtbo"],
}

genrule {
    name: "test_pvmfw_devices_vm_dtbo_with_dependencies",
    tools: ["dtc"],
    cmd: "$(location dtc) -@ -I dts -O dtb $(in) -o $(out)",
    srcs: ["testdata/test_pvmfw_devices_vm_dtbo_with_dependencies.dts"],
    out: ["test_pvmfw_devices_vm_dtbo_with_dependencies.dtbo"],
}

genrule_defaults {
    name: "test_device_assignment_dts_to_dtb",
    defaults: ["dts_to_dtb"],
    srcs: ["testdata/test_crosvm_dt_base.dtsi"],
}

genrule {
    name: "test_pvmfw_devices_overlapping_pvmfw",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_overlapping_pvmfw.dts"],
    out: ["test_pvmfw_devices_overlapping_pvmfw.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_rng",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_rng.dts"],
    out: ["test_pvmfw_devices_with_rng.dtb"],
}

genrule {
    name: "test_pvmfw_devices_without_iommus",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_without_iommus.dts"],
    out: ["test_pvmfw_devices_without_iommus.dtb"],
}

genrule {
    name: "test_pvmfw_devices_without_device",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_without_device.dts"],
    out: ["test_pvmfw_devices_without_device.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_multiple_devices_iommus",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_multiple_devices_iommus.dts"],
    out: ["test_pvmfw_devices_with_multiple_devices_iommus.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_iommu_sharing",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_iommu_sharing.dts"],
    out: ["test_pvmfw_devices_with_iommu_sharing.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_iommu_id_conflict",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_iommu_id_conflict.dts"],
    out: ["test_pvmfw_devices_with_iommu_id_conflict.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_duplicated_pviommus",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_duplicated_pviommus.dts"],
    out: ["test_pvmfw_devices_with_duplicated_pviommus.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_multiple_reg_iommus",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_multiple_reg_iommus.dts"],
    out: ["test_pvmfw_devices_with_multiple_reg_iommus.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_dependency",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_dependency.dts"],
    out: ["test_pvmfw_devices_with_dependency.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_multiple_dependencies",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_multiple_dependencies.dts"],
    out: ["test_pvmfw_devices_with_multiple_dependencies.dtb"],
}

genrule {
    name: "test_pvmfw_devices_with_dependency_loop",
    defaults: ["test_device_assignment_dts_to_dtb"],
    srcs: ["testdata/test_pvmfw_devices_with_dependency_loop.dts"],
    out: ["test_pvmfw_devices_with_dependency_loop.dtb"],
}

// We can't use genrule because preprocessed platform DT is built with cc_object.
// cc_genrule doesn't support default, so we'll build all expected DTs in
// a single build rule.
cc_genrule {
    name: "test_pvmfw_devices_expected_dt",
    srcs: [
        ":pvmfw_platform.dts.preprocessed",
        "testdata/expected_dt_with_dependency.dts",
        "testdata/expected_dt_with_multiple_dependencies.dts",
        "testdata/expected_dt_with_dependency_loop.dts",
    ],
    out: [
        "expected_dt_with_dependency.dtb",
        "expected_dt_with_multiple_dependencies.dtb",
        "expected_dt_with_dependency_loop.dtb",
    ],
    tools: ["dtc"],
    cmd: "FILES=($(in));" +
        "cp $${FILES[0]} $(genDir)/platform_preprocessed.dts;" +
        "for DTS in $${FILES[@]:1}; do" +
        "  DTB=$$(basename -s .dts $${DTS}).dtb;" +
        "  $(location dtc) -@ -i $(genDir) -I dts -O dtb $${DTS} -o $(genDir)/$${DTB};" +
        "done",
    visibility: ["//visibility:private"],
}

cc_binary {
    name: "pvmfw",
    defaults: ["vmbase_elf_defaults"],
    srcs: [
        "idmap.S",
    ],
    static_libs: [
        "libpvmfw",
    ],
    linker_scripts: [
        "image.ld",
        ":vmbase_sections",
    ],
    // `installable: false` is inherited from vmbase_elf_defaults, and that
    // hides this module from Make, which makes it impossible for the Make world
    // to place the unstripped binary to the symbols directory. Marking back as
    // installable exposes this module to the Make world again. Note that this
    // module (pvmfw) still is NOT installed to any of the filesystem images. It
    // is fed into pvmfw_bin and then into pvmfw_img to become a standalone
    // partition image. This is just to package the unstripped file into the
    // symbols zip file for debugging purpose.
    installable: true,
}

raw_binary {
    name: "pvmfw_bin",
    stem: "pvmfw.bin",
    src: ":pvmfw",
    enabled: false,
    target: {
        android_arm64: {
            enabled: true,
        },
    },
}

// Provide pvmfw.bin binary regardless of the architecture for building test.
// Note that skipping tests on unsupported device is easy
// while configuring server configuration to make such tests to run on working
// devices.
prebuilt_etc {
    name: "pvmfw_test",
    filename: "pvmfw_test.bin",
    target: {
        android_arm64: {
            src: ":pvmfw_bin",
        },
    },
    src: ":empty_file",
    installable: false,
}

prebuilt_etc {
    name: "pvmfw_embedded_key",
    src: ":avb_testkey_rsa4096_pub_bin",
    installable: false,
}

genrule {
    name: "pvmfw_embedded_key_rs",
    srcs: [":pvmfw_embedded_key"],
    out: ["lib.rs"],
    cmd: "(" +
        "    echo '#![no_std]';" +
        "    echo '#![allow(missing_docs)]';" +
        "    echo 'pub const PUBLIC_KEY: &[u8] = &[';" +
        "    xxd -i < $(in);" +
        "    echo '];';" +
        ") > $(out)",
}

rust_library_rlib {
    name: "libpvmfw_embedded_key",
    defaults: ["vmbase_rlib_defaults"],
    srcs: [":pvmfw_embedded_key_rs"],
    crate_name: "pvmfw_embedded_key",
}

prebuilt_etc {
    name: "pvmfw_sign_key",
    src: ":avb_testkey_rsa4096",
    installable: false,
}

// We need to rename *.dts into *.cpp as cc_object doesn't accept *.dts as an
// input
genrule {
    name: "pvmfw_platform.dts.renamed",
    srcs: ["platform.dts"],
    out: ["out.cpp"],
    cmd: "cp $(in) $(out)",
    visibility: ["//visibility:private"],
}

// Then run the macro processor to replace symbols like GIC_SPI into actual
// numbers defined in the ARM DT binding headers
cc_object {
    name: "pvmfw_platform.dts.preprocessed",
    defaults: ["avf_build_flags_cc"],
    header_libs: ["arm_dt_bindings_headers"],
    host_supported: true,
    srcs: [":pvmfw_platform.dts.renamed"],
    cflags: [
        "-E",
        "-P",
        "-xassembler-with-cpp", // allow C preprocessor directives
    ],
    visibility: ["//visibility:private"],
}

// Compile the preprocessed dts into binary and create a rust library source
// having the binary.
cc_genrule {
    name: "pvmfw_fdt_template_rs",
    srcs: [":pvmfw_platform.dts.preprocessed"],
    out: ["lib.rs"],
    tools: ["dtc"],
    cmd: "$(location dtc) -@ -I dts -O dtb -o $(genDir)/compiled.dtbo $(in) && " +
        "(" +
        "    echo '#![no_std]';" +
        "    echo '#![allow(missing_docs)]';" +
        "    echo 'pub const RAW: &[u8] = &[';" +
        "    xxd -i < $(genDir)/compiled.dtbo;" +
        "    echo '];';" +
        ") > $(out)",
    visibility: ["//visibility:private"],
}

rust_library_rlib {
    name: "libpvmfw_fdt_template",
    defaults: ["vmbase_rlib_defaults"],
    srcs: [":pvmfw_fdt_template_rs"],
    crate_name: "pvmfw_fdt_template",
}

bootimg {
    name: "pvmfw_img",
    stem: "pvmfw.img",
    kernel_prebuilt: ":pvmfw_bin",
    header_version: "3",
    partition_name: "pvmfw",
    enabled: false,
    target: {
        android_arm64: {
            enabled: true,
        },
    },
    use_avb: true,
    avb_private_key: ":pvmfw_sign_key",
}