1*d289c2baSAndroid Build Coastguard Worker// Copyright 2023, The Android Open Source Project 2*d289c2baSAndroid Build Coastguard Worker// 3*d289c2baSAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*d289c2baSAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*d289c2baSAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*d289c2baSAndroid Build Coastguard Worker// 7*d289c2baSAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*d289c2baSAndroid Build Coastguard Worker// 9*d289c2baSAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*d289c2baSAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*d289c2baSAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*d289c2baSAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*d289c2baSAndroid Build Coastguard Worker// limitations under the License. 14*d289c2baSAndroid Build Coastguard Worker 15*d289c2baSAndroid Build Coastguard Worker// Rust bindgen wrappers to allow calling into libavb from Rust. 16*d289c2baSAndroid Build Coastguard Worker// 17*d289c2baSAndroid Build Coastguard Worker// The auto-generated wrappers are Rust unsafe and somewhat difficult to work 18*d289c2baSAndroid Build Coastguard Worker// with so are not exposed outside of this directory; instead we will provide 19*d289c2baSAndroid Build Coastguard Worker// a safe higher-level Rust API. 20*d289c2baSAndroid Build Coastguard Workerrust_defaults { 21*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen.common.defaults", 22*d289c2baSAndroid Build Coastguard Worker wrapper_src: "bindgen/avb.h", 23*d289c2baSAndroid Build Coastguard Worker crate_name: "avb_bindgen", 24*d289c2baSAndroid Build Coastguard Worker edition: "2021", 25*d289c2baSAndroid Build Coastguard Worker visibility: [ 26*d289c2baSAndroid Build Coastguard Worker ":__subpackages__", 27*d289c2baSAndroid Build Coastguard Worker // TODO(b/290110273): add the Rust public API layer here and adjust 28*d289c2baSAndroid Build Coastguard Worker // Virtualization packages to depend on it instead of the raw bindgen. 29*d289c2baSAndroid Build Coastguard Worker "//packages/modules/Virtualization:__subpackages__", 30*d289c2baSAndroid Build Coastguard Worker ], 31*d289c2baSAndroid Build Coastguard Worker source_stem: "bindings", 32*d289c2baSAndroid Build Coastguard Worker bindgen_flags: [ 33*d289c2baSAndroid Build Coastguard Worker "--constified-enum-module=AvbDescriptorTag", 34*d289c2baSAndroid Build Coastguard Worker "--bitfield-enum=Avb.*Flags", 35*d289c2baSAndroid Build Coastguard Worker "--default-enum-style rust", 36*d289c2baSAndroid Build Coastguard Worker "--with-derive-default", 37*d289c2baSAndroid Build Coastguard Worker "--with-derive-custom=Avb.*Descriptor=FromZeroes,FromBytes", 38*d289c2baSAndroid Build Coastguard Worker "--with-derive-custom=AvbCertPermanentAttributes=FromZeroes,FromBytes,AsBytes", 39*d289c2baSAndroid Build Coastguard Worker "--with-derive-custom=AvbCertCertificate.*=FromZeroes,FromBytes,AsBytes", 40*d289c2baSAndroid Build Coastguard Worker "--with-derive-custom=AvbCertUnlock.*=FromZeroes,FromBytes,AsBytes", 41*d289c2baSAndroid Build Coastguard Worker "--allowlist-type=AvbDescriptorTag", 42*d289c2baSAndroid Build Coastguard Worker "--allowlist-type=Avb.*Flags", 43*d289c2baSAndroid Build Coastguard Worker "--allowlist-function=.*", 44*d289c2baSAndroid Build Coastguard Worker "--allowlist-var=AVB.*", 45*d289c2baSAndroid Build Coastguard Worker "--use-core", 46*d289c2baSAndroid Build Coastguard Worker "--raw-line=#![no_std]", 47*d289c2baSAndroid Build Coastguard Worker "--raw-line=use zerocopy::{AsBytes, FromBytes, FromZeroes};", 48*d289c2baSAndroid Build Coastguard Worker "--ctypes-prefix=core::ffi", 49*d289c2baSAndroid Build Coastguard Worker ], 50*d289c2baSAndroid Build Coastguard Worker cflags: ["-DBORINGSSL_NO_CXX"], 51*d289c2baSAndroid Build Coastguard Worker} 52*d289c2baSAndroid Build Coastguard Worker 53*d289c2baSAndroid Build Coastguard Worker// Full bindgen defaults for std targets. 54*d289c2baSAndroid Build Coastguard Workerrust_defaults { 55*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen.std.defaults", 56*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_bindgen.common.defaults"], 57*d289c2baSAndroid Build Coastguard Worker host_supported: true, 58*d289c2baSAndroid Build Coastguard Worker static_libs: ["libavb_cert"], 59*d289c2baSAndroid Build Coastguard Worker shared_libs: ["libcrypto"], 60*d289c2baSAndroid Build Coastguard Worker rustlibs: ["libzerocopy"], 61*d289c2baSAndroid Build Coastguard Worker apex_available: ["com.android.virt"], 62*d289c2baSAndroid Build Coastguard Worker} 63*d289c2baSAndroid Build Coastguard Worker 64*d289c2baSAndroid Build Coastguard Worker// Full bindgen default for nostd targets. 65*d289c2baSAndroid Build Coastguard Workerrust_defaults { 66*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen.nostd.defaults", 67*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_bindgen.common.defaults"], 68*d289c2baSAndroid Build Coastguard Worker static_libs: [ 69*d289c2baSAndroid Build Coastguard Worker "libavb_cert_baremetal", 70*d289c2baSAndroid Build Coastguard Worker "libcrypto_baremetal", 71*d289c2baSAndroid Build Coastguard Worker ], 72*d289c2baSAndroid Build Coastguard Worker rustlibs: ["libzerocopy_nostd_noalloc"], 73*d289c2baSAndroid Build Coastguard Worker dylib: { 74*d289c2baSAndroid Build Coastguard Worker enabled: false, 75*d289c2baSAndroid Build Coastguard Worker }, 76*d289c2baSAndroid Build Coastguard Worker} 77*d289c2baSAndroid Build Coastguard Worker 78*d289c2baSAndroid Build Coastguard Worker// Internal source-only bindgen with std. 79*d289c2baSAndroid Build Coastguard Worker// 80*d289c2baSAndroid Build Coastguard Worker// This target should only be used as `srcs`, not `rustlibs` or `rlibs`. This 81*d289c2baSAndroid Build Coastguard Worker// is because the `rust_bindgen` rule intentionally only generates rlibs 82*d289c2baSAndroid Build Coastguard Worker// (b/166332519), and also forces its dependencies to use rlibs. However, this 83*d289c2baSAndroid Build Coastguard Worker// can create mismatched library types if the depenency is also used elsewhere 84*d289c2baSAndroid Build Coastguard Worker// in a build rule as a dylib. In particular for us, libzerocopy and its own 85*d289c2baSAndroid Build Coastguard Worker// dependency libbyteorder trigger this problem like so: 86*d289c2baSAndroid Build Coastguard Worker// 87*d289c2baSAndroid Build Coastguard Worker// build target (prefer dylib) 88*d289c2baSAndroid Build Coastguard Worker// / \ 89*d289c2baSAndroid Build Coastguard Worker// libavb_rs (dylib) \ 90*d289c2baSAndroid Build Coastguard Worker// / \ 91*d289c2baSAndroid Build Coastguard Worker// libavb_bindgen (rlib) ... arbitrary dependency chain (dylib) ... 92*d289c2baSAndroid Build Coastguard Worker// / \ 93*d289c2baSAndroid Build Coastguard Worker// libzerocopy (rlib) \ 94*d289c2baSAndroid Build Coastguard Worker// / \ 95*d289c2baSAndroid Build Coastguard Worker// libbyteorder (rlib) libbyteorder (dylib) 96*d289c2baSAndroid Build Coastguard Worker// 97*d289c2baSAndroid Build Coastguard Worker// By using it as a `srcs` instead, we can wrap it in a `rust_library` which 98*d289c2baSAndroid Build Coastguard Worker// allows selecting either library type and fixes the conflict: 99*d289c2baSAndroid Build Coastguard Worker// 100*d289c2baSAndroid Build Coastguard Worker// build target (prefer dylib) 101*d289c2baSAndroid Build Coastguard Worker// / \ 102*d289c2baSAndroid Build Coastguard Worker// libavb_rs (dylib) \ 103*d289c2baSAndroid Build Coastguard Worker// / \ 104*d289c2baSAndroid Build Coastguard Worker// libavb_bindgen (dylib) ... arbitrary dependency chain (dylib) ... 105*d289c2baSAndroid Build Coastguard Worker// / / 106*d289c2baSAndroid Build Coastguard Worker// libzerocopy (dylib) / 107*d289c2baSAndroid Build Coastguard Worker// \ / 108*d289c2baSAndroid Build Coastguard Worker// libbyteorder (dylib) 109*d289c2baSAndroid Build Coastguard Worker// 110*d289c2baSAndroid Build Coastguard Workerrust_bindgen { 111*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen_for_srcs_only", 112*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_bindgen.std.defaults"], 113*d289c2baSAndroid Build Coastguard Worker} 114*d289c2baSAndroid Build Coastguard Worker 115*d289c2baSAndroid Build Coastguard Worker// Bindgen with std. 116*d289c2baSAndroid Build Coastguard Worker// 117*d289c2baSAndroid Build Coastguard Worker// See above for why we need a `rust_library` wrapper here. 118*d289c2baSAndroid Build Coastguard Workerrust_library { 119*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen", 120*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_bindgen.std.defaults"], 121*d289c2baSAndroid Build Coastguard Worker srcs: [":libavb_bindgen_for_srcs_only"], 122*d289c2baSAndroid Build Coastguard Worker} 123*d289c2baSAndroid Build Coastguard Worker 124*d289c2baSAndroid Build Coastguard Worker// Bindgen nostd. 125*d289c2baSAndroid Build Coastguard Worker// 126*d289c2baSAndroid Build Coastguard Worker// Nostd targets always use rlibs, so we don't need a `rust_library` wrapper in 127*d289c2baSAndroid Build Coastguard Worker// this case; the rlib-only bindgen target is sufficient. 128*d289c2baSAndroid Build Coastguard Workerrust_bindgen { 129*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen_nostd", 130*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_bindgen.nostd.defaults"], 131*d289c2baSAndroid Build Coastguard Worker} 132*d289c2baSAndroid Build Coastguard Worker 133*d289c2baSAndroid Build Coastguard Worker// Bindgen auto-generated tests. 134*d289c2baSAndroid Build Coastguard Workerrust_test { 135*d289c2baSAndroid Build Coastguard Worker name: "libavb_bindgen_test", 136*d289c2baSAndroid Build Coastguard Worker srcs: [":libavb_bindgen_for_srcs_only"], 137*d289c2baSAndroid Build Coastguard Worker crate_name: "avb_bindgen_test", 138*d289c2baSAndroid Build Coastguard Worker edition: "2021", 139*d289c2baSAndroid Build Coastguard Worker test_suites: ["general-tests"], 140*d289c2baSAndroid Build Coastguard Worker auto_gen_config: true, 141*d289c2baSAndroid Build Coastguard Worker clippy_lints: "none", 142*d289c2baSAndroid Build Coastguard Worker lints: "none", 143*d289c2baSAndroid Build Coastguard Worker rustlibs: ["libzerocopy"], 144*d289c2baSAndroid Build Coastguard Worker} 145*d289c2baSAndroid Build Coastguard Worker 146*d289c2baSAndroid Build Coastguard Worker// Rust library wrapping libavb C implementation. 147*d289c2baSAndroid Build Coastguard Worker 148*d289c2baSAndroid Build Coastguard Worker// Common defaults for all variations. 149*d289c2baSAndroid Build Coastguard Workerrust_defaults { 150*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_common.defaults", 151*d289c2baSAndroid Build Coastguard Worker crate_name: "avb", 152*d289c2baSAndroid Build Coastguard Worker srcs: ["src/lib.rs"], 153*d289c2baSAndroid Build Coastguard Worker clippy_lints: "android", 154*d289c2baSAndroid Build Coastguard Worker lints: "android", 155*d289c2baSAndroid Build Coastguard Worker} 156*d289c2baSAndroid Build Coastguard Worker 157*d289c2baSAndroid Build Coastguard Worker// No std, no features. 158*d289c2baSAndroid Build Coastguard Workerrust_defaults { 159*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_nostd.defaults", 160*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs_common.defaults"], 161*d289c2baSAndroid Build Coastguard Worker // Only rlib can build without the required nostd hooks (eh_personality, 162*d289c2baSAndroid Build Coastguard Worker // panic_handler, etc) to defer them for the final binary to implement. 163*d289c2baSAndroid Build Coastguard Worker prefer_rlib: true, 164*d289c2baSAndroid Build Coastguard Worker no_stdlibs: true, 165*d289c2baSAndroid Build Coastguard Worker rustlibs: [ 166*d289c2baSAndroid Build Coastguard Worker "libavb_bindgen_nostd", 167*d289c2baSAndroid Build Coastguard Worker "libzerocopy_nostd_noalloc", 168*d289c2baSAndroid Build Coastguard Worker ], 169*d289c2baSAndroid Build Coastguard Worker whole_static_libs: [ 170*d289c2baSAndroid Build Coastguard Worker "libavb_cert_baremetal", 171*d289c2baSAndroid Build Coastguard Worker ], 172*d289c2baSAndroid Build Coastguard Worker stdlibs: [ 173*d289c2baSAndroid Build Coastguard Worker "libcore.rust_sysroot", 174*d289c2baSAndroid Build Coastguard Worker ], 175*d289c2baSAndroid Build Coastguard Worker} 176*d289c2baSAndroid Build Coastguard Worker 177*d289c2baSAndroid Build Coastguard Worker// Std, no features. 178*d289c2baSAndroid Build Coastguard Workerrust_defaults { 179*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs.defaults", 180*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs_common.defaults"], 181*d289c2baSAndroid Build Coastguard Worker host_supported: true, 182*d289c2baSAndroid Build Coastguard Worker rustlibs: [ 183*d289c2baSAndroid Build Coastguard Worker "libavb_bindgen", 184*d289c2baSAndroid Build Coastguard Worker "libzerocopy", 185*d289c2baSAndroid Build Coastguard Worker ], 186*d289c2baSAndroid Build Coastguard Worker whole_static_libs: [ 187*d289c2baSAndroid Build Coastguard Worker "libavb_cert", 188*d289c2baSAndroid Build Coastguard Worker ], 189*d289c2baSAndroid Build Coastguard Worker} 190*d289c2baSAndroid Build Coastguard Worker 191*d289c2baSAndroid Build Coastguard Worker// Adds UUID feature for nostd. 192*d289c2baSAndroid Build Coastguard Workerrust_defaults { 193*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_nostd.uuid.defaults", 194*d289c2baSAndroid Build Coastguard Worker features: [ 195*d289c2baSAndroid Build Coastguard Worker "uuid", 196*d289c2baSAndroid Build Coastguard Worker ], 197*d289c2baSAndroid Build Coastguard Worker rustlibs: [ 198*d289c2baSAndroid Build Coastguard Worker "libuuid_nostd", 199*d289c2baSAndroid Build Coastguard Worker ], 200*d289c2baSAndroid Build Coastguard Worker} 201*d289c2baSAndroid Build Coastguard Worker 202*d289c2baSAndroid Build Coastguard Worker// Adds UUID feature for std. 203*d289c2baSAndroid Build Coastguard Workerrust_defaults { 204*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs.uuid.defaults", 205*d289c2baSAndroid Build Coastguard Worker features: [ 206*d289c2baSAndroid Build Coastguard Worker "uuid", 207*d289c2baSAndroid Build Coastguard Worker ], 208*d289c2baSAndroid Build Coastguard Worker rustlibs: [ 209*d289c2baSAndroid Build Coastguard Worker "libuuid", 210*d289c2baSAndroid Build Coastguard Worker ], 211*d289c2baSAndroid Build Coastguard Worker} 212*d289c2baSAndroid Build Coastguard Worker 213*d289c2baSAndroid Build Coastguard Worker// lib: no std, no features. 214*d289c2baSAndroid Build Coastguard Workerrust_library_rlib { 215*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_nostd", 216*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs_nostd.defaults"], 217*d289c2baSAndroid Build Coastguard Worker} 218*d289c2baSAndroid Build Coastguard Worker 219*d289c2baSAndroid Build Coastguard Worker// lib: no std, UUID feature. 220*d289c2baSAndroid Build Coastguard Workerrust_library_rlib { 221*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_nostd_uuid", 222*d289c2baSAndroid Build Coastguard Worker defaults: [ 223*d289c2baSAndroid Build Coastguard Worker "libavb_rs_nostd.defaults", 224*d289c2baSAndroid Build Coastguard Worker "libavb_rs_nostd.uuid.defaults", 225*d289c2baSAndroid Build Coastguard Worker ], 226*d289c2baSAndroid Build Coastguard Worker} 227*d289c2baSAndroid Build Coastguard Worker 228*d289c2baSAndroid Build Coastguard Worker// lib: std, no features. 229*d289c2baSAndroid Build Coastguard Workerrust_library { 230*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs", 231*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs.defaults"], 232*d289c2baSAndroid Build Coastguard Worker} 233*d289c2baSAndroid Build Coastguard Worker 234*d289c2baSAndroid Build Coastguard Worker// lib: std, UUID feature. 235*d289c2baSAndroid Build Coastguard Workerrust_library { 236*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_uuid", 237*d289c2baSAndroid Build Coastguard Worker defaults: [ 238*d289c2baSAndroid Build Coastguard Worker "libavb_rs.defaults", 239*d289c2baSAndroid Build Coastguard Worker "libavb_rs.uuid.defaults", 240*d289c2baSAndroid Build Coastguard Worker ], 241*d289c2baSAndroid Build Coastguard Worker} 242*d289c2baSAndroid Build Coastguard Worker 243*d289c2baSAndroid Build Coastguard Worker// TestOps lib: std 244*d289c2baSAndroid Build Coastguard Workerrust_library { 245*d289c2baSAndroid Build Coastguard Worker crate_name: "avb_test", 246*d289c2baSAndroid Build Coastguard Worker name: "libavb_test_rs_testops", 247*d289c2baSAndroid Build Coastguard Worker srcs: ["tests/test_ops.rs"], 248*d289c2baSAndroid Build Coastguard Worker clippy_lints: "android", 249*d289c2baSAndroid Build Coastguard Worker lints: "android", 250*d289c2baSAndroid Build Coastguard Worker host_supported: true, 251*d289c2baSAndroid Build Coastguard Worker rustlibs: [ 252*d289c2baSAndroid Build Coastguard Worker "libavb_rs", 253*d289c2baSAndroid Build Coastguard Worker ], 254*d289c2baSAndroid Build Coastguard Worker whole_static_libs: [ 255*d289c2baSAndroid Build Coastguard Worker "libavb_cert", 256*d289c2baSAndroid Build Coastguard Worker ], 257*d289c2baSAndroid Build Coastguard Worker} 258*d289c2baSAndroid Build Coastguard Worker 259*d289c2baSAndroid Build Coastguard Worker// "libavb_rs.defaults" plus additional unit test defaults. 260*d289c2baSAndroid Build Coastguard Workerrust_defaults { 261*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_unittest.defaults", 262*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs.defaults"], 263*d289c2baSAndroid Build Coastguard Worker data: [":libavb_rs_example_descriptors"], 264*d289c2baSAndroid Build Coastguard Worker test_suites: ["general-tests"], 265*d289c2baSAndroid Build Coastguard Worker} 266*d289c2baSAndroid Build Coastguard Worker 267*d289c2baSAndroid Build Coastguard Worker// Unit tests: std, no features. 268*d289c2baSAndroid Build Coastguard Workerrust_test { 269*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_unittest", 270*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs_unittest.defaults"], 271*d289c2baSAndroid Build Coastguard Worker} 272*d289c2baSAndroid Build Coastguard Worker 273*d289c2baSAndroid Build Coastguard Worker// Unit tests: std, UUID feature. 274*d289c2baSAndroid Build Coastguard Workerrust_test { 275*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_uuid_unittest", 276*d289c2baSAndroid Build Coastguard Worker defaults: [ 277*d289c2baSAndroid Build Coastguard Worker "libavb_rs_unittest.defaults", 278*d289c2baSAndroid Build Coastguard Worker "libavb_rs.uuid.defaults", 279*d289c2baSAndroid Build Coastguard Worker ], 280*d289c2baSAndroid Build Coastguard Worker} 281*d289c2baSAndroid Build Coastguard Worker 282*d289c2baSAndroid Build Coastguard Worker// Example descriptors in binary format. 283*d289c2baSAndroid Build Coastguard Workerfilegroup { 284*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_example_descriptors", 285*d289c2baSAndroid Build Coastguard Worker srcs: [ 286*d289c2baSAndroid Build Coastguard Worker "testdata/chain_partition_descriptor.bin", 287*d289c2baSAndroid Build Coastguard Worker "testdata/hash_descriptor.bin", 288*d289c2baSAndroid Build Coastguard Worker "testdata/hashtree_descriptor.bin", 289*d289c2baSAndroid Build Coastguard Worker "testdata/kernel_commandline_descriptor.bin", 290*d289c2baSAndroid Build Coastguard Worker "testdata/property_descriptor.bin", 291*d289c2baSAndroid Build Coastguard Worker ], 292*d289c2baSAndroid Build Coastguard Worker} 293*d289c2baSAndroid Build Coastguard Worker 294*d289c2baSAndroid Build Coastguard Worker// Integration test defaults. 295*d289c2baSAndroid Build Coastguard Workerrust_defaults { 296*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_test.defaults", 297*d289c2baSAndroid Build Coastguard Worker srcs: ["tests/tests.rs"], 298*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 299*d289c2baSAndroid Build Coastguard Worker data: [ 300*d289c2baSAndroid Build Coastguard Worker ":avb_cert_test_permanent_attributes", 301*d289c2baSAndroid Build Coastguard Worker ":avb_cert_test_unlock_challenge", 302*d289c2baSAndroid Build Coastguard Worker ":avb_cert_test_unlock_credential", 303*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096_pub_bin", 304*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa8192_pub_bin", 305*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image", 306*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_with_vbmeta_footer", 307*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_with_vbmeta_footer_for_boot", 308*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_with_vbmeta_footer_for_test_part_2", 309*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta", 310*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_2_parts", 311*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_cert", 312*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_persistent_digest", 313*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_with_chained_partition", 314*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_with_commandline", 315*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_with_hashtree", 316*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_vbmeta_with_property", 317*d289c2baSAndroid Build Coastguard Worker ], 318*d289c2baSAndroid Build Coastguard Worker rustlibs: [ 319*d289c2baSAndroid Build Coastguard Worker "libhex", 320*d289c2baSAndroid Build Coastguard Worker "libzerocopy", 321*d289c2baSAndroid Build Coastguard Worker ], 322*d289c2baSAndroid Build Coastguard Worker test_suites: ["general-tests"], 323*d289c2baSAndroid Build Coastguard Worker clippy_lints: "android", 324*d289c2baSAndroid Build Coastguard Worker lints: "android", 325*d289c2baSAndroid Build Coastguard Worker} 326*d289c2baSAndroid Build Coastguard Worker 327*d289c2baSAndroid Build Coastguard Worker// Integration test: no features. 328*d289c2baSAndroid Build Coastguard Workerrust_test { 329*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_test", 330*d289c2baSAndroid Build Coastguard Worker defaults: ["libavb_rs_test.defaults"], 331*d289c2baSAndroid Build Coastguard Worker rustlibs: ["libavb_rs"], 332*d289c2baSAndroid Build Coastguard Worker} 333*d289c2baSAndroid Build Coastguard Worker 334*d289c2baSAndroid Build Coastguard Worker// Integration test: UUID feature. 335*d289c2baSAndroid Build Coastguard Workerrust_test { 336*d289c2baSAndroid Build Coastguard Worker name: "libavb_rs_uuid_test", 337*d289c2baSAndroid Build Coastguard Worker defaults: [ 338*d289c2baSAndroid Build Coastguard Worker "libavb_rs.uuid.defaults", 339*d289c2baSAndroid Build Coastguard Worker "libavb_rs_test.defaults", 340*d289c2baSAndroid Build Coastguard Worker ], 341*d289c2baSAndroid Build Coastguard Worker rustlibs: ["libavb_rs_uuid"], 342*d289c2baSAndroid Build Coastguard Worker} 343*d289c2baSAndroid Build Coastguard Worker 344*d289c2baSAndroid Build Coastguard Worker// Test images for verification. 345*d289c2baSAndroid Build Coastguard Worker 346*d289c2baSAndroid Build Coastguard Worker// Unsigned 16KiB test image. 347*d289c2baSAndroid Build Coastguard Workergenrule { 348*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image", 349*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 350*d289c2baSAndroid Build Coastguard Worker out: ["test_image.img"], 351*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) generate_test_image --image_size 16384 --output $(out)", 352*d289c2baSAndroid Build Coastguard Worker} 353*d289c2baSAndroid Build Coastguard Worker 354*d289c2baSAndroid Build Coastguard Worker// Unsigned vbmeta blob containing the test image descriptor for partition name "test_part". 355*d289c2baSAndroid Build Coastguard Workeravb_gen_vbmeta_image { 356*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_descriptor", 357*d289c2baSAndroid Build Coastguard Worker src: ":avbrs_test_image", 358*d289c2baSAndroid Build Coastguard Worker partition_name: "test_part", 359*d289c2baSAndroid Build Coastguard Worker salt: "1000", 360*d289c2baSAndroid Build Coastguard Worker} 361*d289c2baSAndroid Build Coastguard Worker 362*d289c2baSAndroid Build Coastguard Worker// Unsigned vbmeta blob containing the test image descriptor for partition name "test_part_2". 363*d289c2baSAndroid Build Coastguard Workeravb_gen_vbmeta_image { 364*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_descriptor_2", 365*d289c2baSAndroid Build Coastguard Worker src: ":avbrs_test_image", 366*d289c2baSAndroid Build Coastguard Worker partition_name: "test_part_2", 367*d289c2baSAndroid Build Coastguard Worker salt: "1001", 368*d289c2baSAndroid Build Coastguard Worker} 369*d289c2baSAndroid Build Coastguard Worker 370*d289c2baSAndroid Build Coastguard Worker// Unsigned vbmeta blob containing a persistent digest descriptor for partition name 371*d289c2baSAndroid Build Coastguard Worker// "test_part_persistent_digest". 372*d289c2baSAndroid Build Coastguard Worker// 373*d289c2baSAndroid Build Coastguard Worker// Currently this is the only in-tree usage of persistent digests, but if anyone else needs it 374*d289c2baSAndroid Build Coastguard Worker// later on it may be worth folding support for this into the `avb_gen_vbmeta_image` rule. 375*d289c2baSAndroid Build Coastguard Workergenrule { 376*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_descriptor_persistent_digest", 377*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 378*d289c2baSAndroid Build Coastguard Worker srcs: [":avbrs_test_image"], 379*d289c2baSAndroid Build Coastguard Worker out: ["avbrs_test_image_descriptor_persistent_digest.img"], 380*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) add_hash_footer --image $(location :avbrs_test_image) --partition_name test_part_persistent_digest --dynamic_partition_size --do_not_append_vbmeta_image --use_persistent_digest --output_vbmeta_image $(out)", 381*d289c2baSAndroid Build Coastguard Worker} 382*d289c2baSAndroid Build Coastguard Worker 383*d289c2baSAndroid Build Coastguard Worker// Unsigned vbmeta blob containing a hastree descriptor for partition name 384*d289c2baSAndroid Build Coastguard Worker// "test_part_hashtree". 385*d289c2baSAndroid Build Coastguard Workergenrule { 386*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_descriptor_hashtree", 387*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 388*d289c2baSAndroid Build Coastguard Worker srcs: [":avbrs_test_image"], 389*d289c2baSAndroid Build Coastguard Worker out: ["avbrs_test_image_descriptor_hashtree.img"], 390*d289c2baSAndroid Build Coastguard Worker // Generating FEC values requires the `fec` tool to be on $PATH, which does 391*d289c2baSAndroid Build Coastguard Worker // not seems to be possible here. For now pass `--do_not_generate_fec`. 392*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) add_hashtree_footer --image $(location :avbrs_test_image) --partition_name test_part_hashtree --partition_size 0 --salt B000 --do_not_append_vbmeta_image --output_vbmeta_image $(out) --do_not_generate_fec", 393*d289c2baSAndroid Build Coastguard Worker} 394*d289c2baSAndroid Build Coastguard Worker 395*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image signing the test image descriptor. 396*d289c2baSAndroid Build Coastguard Workercc_genrule { 397*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta", 398*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 399*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 400*d289c2baSAndroid Build Coastguard Worker srcs: [ 401*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor", 402*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 403*d289c2baSAndroid Build Coastguard Worker ], 404*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta.img"], 405*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor) --output $(out)", 406*d289c2baSAndroid Build Coastguard Worker} 407*d289c2baSAndroid Build Coastguard Worker 408*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image signing the test image descriptor with 409*d289c2baSAndroid Build Coastguard Worker// `avb_cert_testkey_psk` and `avb_cert_test_metadata`. 410*d289c2baSAndroid Build Coastguard Workercc_genrule { 411*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_cert", 412*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 413*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 414*d289c2baSAndroid Build Coastguard Worker srcs: [ 415*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor", 416*d289c2baSAndroid Build Coastguard Worker ":avb_cert_test_metadata", 417*d289c2baSAndroid Build Coastguard Worker ":avb_cert_testkey_psk", 418*d289c2baSAndroid Build Coastguard Worker ], 419*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_cert.img"], 420*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --key $(location :avb_cert_testkey_psk) --public_key_metadata $(location :avb_cert_test_metadata) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor) --output $(out)", 421*d289c2baSAndroid Build Coastguard Worker} 422*d289c2baSAndroid Build Coastguard Worker 423*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image signing the test image descriptors for "test_part" and "test_part_2". 424*d289c2baSAndroid Build Coastguard Workercc_genrule { 425*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_2_parts", 426*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 427*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 428*d289c2baSAndroid Build Coastguard Worker srcs: [ 429*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor", 430*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor_2", 431*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 432*d289c2baSAndroid Build Coastguard Worker ], 433*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_2_parts.img"], 434*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor) --include_descriptors_from_image $(location :avbrs_test_image_descriptor_2) --output $(out)", 435*d289c2baSAndroid Build Coastguard Worker} 436*d289c2baSAndroid Build Coastguard Worker 437*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image signing the test image persistent digest descriptor. 438*d289c2baSAndroid Build Coastguard Workercc_genrule { 439*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_persistent_digest", 440*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 441*d289c2baSAndroid Build Coastguard Worker srcs: [ 442*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor_persistent_digest", 443*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 444*d289c2baSAndroid Build Coastguard Worker ], 445*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_persistent_digest.img"], 446*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor_persistent_digest) --output $(out)", 447*d289c2baSAndroid Build Coastguard Worker} 448*d289c2baSAndroid Build Coastguard Worker 449*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image with property descriptor "test_prop_key" = "test_prop_value". 450*d289c2baSAndroid Build Coastguard Workercc_genrule { 451*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_with_property", 452*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 453*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 454*d289c2baSAndroid Build Coastguard Worker srcs: [ 455*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor", 456*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 457*d289c2baSAndroid Build Coastguard Worker ], 458*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_with_property.img"], 459*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --prop test_prop_key:test_prop_value --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor) --output $(out)", 460*d289c2baSAndroid Build Coastguard Worker} 461*d289c2baSAndroid Build Coastguard Worker 462*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image with the test image hashtree descriptor. 463*d289c2baSAndroid Build Coastguard Workercc_genrule { 464*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_with_hashtree", 465*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 466*d289c2baSAndroid Build Coastguard Worker srcs: [ 467*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor_hashtree", 468*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 469*d289c2baSAndroid Build Coastguard Worker ], 470*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_with_hashtree.img"], 471*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor_hashtree) --output $(out)", 472*d289c2baSAndroid Build Coastguard Worker} 473*d289c2baSAndroid Build Coastguard Worker 474*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image with kernel commandline "test_cmdline_key=test_cmdline_value". 475*d289c2baSAndroid Build Coastguard Workercc_genrule { 476*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_with_commandline", 477*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 478*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 479*d289c2baSAndroid Build Coastguard Worker srcs: [ 480*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor", 481*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 482*d289c2baSAndroid Build Coastguard Worker ], 483*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_with_commandline.img"], 484*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --kernel_cmdline test_cmdline_key=test_cmdline_value --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor) --output $(out)", 485*d289c2baSAndroid Build Coastguard Worker} 486*d289c2baSAndroid Build Coastguard Worker 487*d289c2baSAndroid Build Coastguard Worker// Standalone vbmeta image with chain descriptor to "test_part_2" with rollback 488*d289c2baSAndroid Build Coastguard Worker// index 4, signed by avb_testkey_rsa8192. 489*d289c2baSAndroid Build Coastguard Workercc_genrule { 490*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_vbmeta_with_chained_partition", 491*d289c2baSAndroid Build Coastguard Worker compile_multilib: "first", 492*d289c2baSAndroid Build Coastguard Worker tools: ["avbtool"], 493*d289c2baSAndroid Build Coastguard Worker srcs: [ 494*d289c2baSAndroid Build Coastguard Worker ":avbrs_test_image_descriptor", 495*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa4096", 496*d289c2baSAndroid Build Coastguard Worker ":avb_testkey_rsa8192_pub_bin", 497*d289c2baSAndroid Build Coastguard Worker ], 498*d289c2baSAndroid Build Coastguard Worker out: ["test_vbmeta_with_chained_partition.img"], 499*d289c2baSAndroid Build Coastguard Worker cmd: "$(location avbtool) make_vbmeta_image --chain_partition test_part_2:4:$(location :avb_testkey_rsa8192_pub_bin) --key $(location :avb_testkey_rsa4096) --algorithm SHA512_RSA4096 --include_descriptors_from_image $(location :avbrs_test_image_descriptor) --output $(out)", 500*d289c2baSAndroid Build Coastguard Worker} 501*d289c2baSAndroid Build Coastguard Worker 502*d289c2baSAndroid Build Coastguard Worker// Combined test image + signed vbmeta footer for "test_part". 503*d289c2baSAndroid Build Coastguard Workeravb_add_hash_footer { 504*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_with_vbmeta_footer", 505*d289c2baSAndroid Build Coastguard Worker src: ":avbrs_test_image", 506*d289c2baSAndroid Build Coastguard Worker partition_name: "test_part", 507*d289c2baSAndroid Build Coastguard Worker private_key: ":avb_testkey_rsa4096", 508*d289c2baSAndroid Build Coastguard Worker salt: "A000", 509*d289c2baSAndroid Build Coastguard Worker} 510*d289c2baSAndroid Build Coastguard Worker 511*d289c2baSAndroid Build Coastguard Worker// Combined test image + signed vbmeta footer for "boot". 512*d289c2baSAndroid Build Coastguard Workeravb_add_hash_footer { 513*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_with_vbmeta_footer_for_boot", 514*d289c2baSAndroid Build Coastguard Worker src: ":avbrs_test_image", 515*d289c2baSAndroid Build Coastguard Worker partition_name: "boot", 516*d289c2baSAndroid Build Coastguard Worker private_key: ":avb_testkey_rsa4096", 517*d289c2baSAndroid Build Coastguard Worker salt: "A001", 518*d289c2baSAndroid Build Coastguard Worker} 519*d289c2baSAndroid Build Coastguard Worker 520*d289c2baSAndroid Build Coastguard Worker// Combined test image + signed vbmeta footer for "test_part_2" signed by 521*d289c2baSAndroid Build Coastguard Worker// avb_testkey_rsa8192 with rollback index = 7. 522*d289c2baSAndroid Build Coastguard Workeravb_add_hash_footer { 523*d289c2baSAndroid Build Coastguard Worker name: "avbrs_test_image_with_vbmeta_footer_for_test_part_2", 524*d289c2baSAndroid Build Coastguard Worker src: ":avbrs_test_image", 525*d289c2baSAndroid Build Coastguard Worker partition_name: "test_part_2", 526*d289c2baSAndroid Build Coastguard Worker private_key: ":avb_testkey_rsa8192", 527*d289c2baSAndroid Build Coastguard Worker algorithm: "SHA256_RSA8192", 528*d289c2baSAndroid Build Coastguard Worker salt: "A002", 529*d289c2baSAndroid Build Coastguard Worker rollback_index: 7, 530*d289c2baSAndroid Build Coastguard Worker} 531