blob: 9ed62a1c21e49a68c51bd33a7592deba7ae3a795 [file] [log] [blame]
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/host.gni")
import("//build/rust/rustc_binary.gni")
import("//build/rust/rustc_library.gni")
assert(is_host, "Assembly libraries are host-only")
rustc_library("vbmeta") {
edition = "2021"
version = "0.1.0"
with_unit_tests = true
deps = [
"//src/lib/mundane",
"//third_party/modinv",
"//third_party/rust_crates:hex",
"//third_party/rust_crates:num",
"//third_party/rust_crates:pem",
"//third_party/rust_crates:ring",
"//third_party/rust_crates:serde",
"//third_party/rust_crates:thiserror",
"//third_party/rust_crates:zerocopy",
]
test_deps = [
"//src/lib/assembly/test_keys",
"//third_party/rust_crates:assert_matches",
]
sources = [
"src/descriptor.rs",
"src/descriptor/builder.rs",
"src/header.rs",
"src/key.rs",
"src/lib.rs",
"src/test.rs",
"src/vbmeta.rs",
]
}
test_avb_key =
"//third_party/android/platform/external/avb/test/data/testkey_atx_psk.pem"
test_avb_atx_metadata =
"//third_party/android/platform/external/avb/test/data/atx_metadata.bin"
salt = "56ebac2038b220d37b9b27e91c9e7afb3d7b7910c03775812c7a16cc01a8b380"
vbmeta_descriptor = "${target_out_dir}/expected_descriptor.vbmeta"
test_image = "${target_out_dir}/test_image"
action("expected_descriptor") {
testonly = true
script = "gen_expected_descriptor.py"
inputs = [ "//third_party/android/platform/external/avb/avbtool.py" ]
outputs = [
vbmeta_descriptor,
test_image,
]
args = [
"--python_path",
rebase_path(python_exe_src, root_build_dir),
"--avbtool",
rebase_path("//third_party/android/platform/external/avb/avbtool.py",
root_build_dir),
"--image",
rebase_path(test_image, root_build_dir),
"--salt",
salt,
"--output_vbmeta_image",
rebase_path(vbmeta_descriptor, root_build_dir),
]
}
action("expected_vbmeta") {
testonly = true
script = "//third_party/android/platform/external/avb/avbtool.py"
deps = [ ":expected_descriptor" ]
output_file = target_name + ".vbmeta"
output_file = "$target_out_dir/$output_file"
outputs = [ output_file ]
inputs = [
test_avb_key,
test_avb_atx_metadata,
vbmeta_descriptor,
]
args = [
"make_vbmeta_image",
"--output", # output of VBMETA image
rebase_path(outputs[0], root_build_dir),
"--key", # a key for signing
rebase_path(test_avb_key, root_build_dir),
"--algorithm", # an algorithm for signing
"SHA512_RSA4096",
"--public_key_metadata", # avb metadata
rebase_path(test_avb_atx_metadata, root_build_dir),
"--include_descriptors_from_image",
rebase_path(vbmeta_descriptor, root_build_dir),
]
}
avb_key_path = rebase_path(test_avb_key, root_build_dir)
avb_metadata_path = rebase_path(test_avb_atx_metadata, root_build_dir)
test_image_path = rebase_path(test_image, root_build_dir)
avb_outputs = get_target_outputs(":expected_vbmeta")
expected_vbmeta = avb_outputs[0]
expected_vbmeta_path = rebase_path(expected_vbmeta, root_build_dir)
rustc_test("integration_test") {
edition = "2021"
source_root = "tests/integration_test.rs"
sources = [ "tests/integration_test.rs" ]
deps = [
":vbmeta",
"//src/lib/include_bytes_from_working_dir",
"//src/lib/include_str_from_working_dir",
"//third_party/rust_crates:hex",
]
# These are not host_test_data(), but are compiled-in files.
non_rust_deps = [
":expected_descriptor",
":expected_vbmeta",
]
rustenv = [
"AVB_KEY=$avb_key_path",
"AVB_METADATA=$avb_metadata_path",
"EXPECTED_VBMETA=$expected_vbmeta_path",
"SALT=" + salt,
"IMAGE=$test_image_path",
]
inputs = [
test_avb_key,
test_avb_atx_metadata,
test_image,
expected_vbmeta,
]
}
rustc_binary("bin") {
name = "vbmeta"
edition = "2021"
sources = [ "src/main.rs" ]
deps = [
":vbmeta",
"//third_party/rust_crates:anyhow",
"//third_party/rust_crates:argh",
]
}