blob: 7c9111952ed4d1c2c9a83f830311f220dd0b12e7 [file] [log] [blame]
# Copyright 2021 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
import("//build/testing/boot_tests/zbi_test.gni")
import("//build/zbi/kernel_cmdline.gni")
import("//zircon/kernel/phys/boot-shim/devicetree.gni")
import("//zircon/kernel/phys/efi/efi_executable.gni")
import("//zircon/kernel/phys/phys_executable.gni")
import("//zircon/kernel/phys/qemu.gni")
import("//zircon/kernel/phys/test/turducken_zbi_test.gni")
import("//zircon/kernel/phys/zbi_executable.gni")
group("boot-shim") {
deps = [
":zbi-boot-shim",
"//zircon/kernel/arch/$zircon_cpu/phys/boot-shim",
]
if (current_cpu != "riscv64") { # TODO(mcgrathr): EFI not there yet
deps += [ ":efi-boot-shim" ]
}
}
template("devicetree_zbi_test") {
test_target = "devicetree-shim-$target_name"
zbi_test(test_target) {
qemu_kernel = "//zircon/kernel/arch/$current_cpu/phys/boot-shim:linux-$current_cpu-boot-shim(${phys_toolchain})"
device_types = [ "QEMU" ]
forward_variables_from(invoker, "*")
if (!defined(timeout)) {
timeout = qemu_short_timeout
}
}
}
if (have_devicetree) {
devicetree_zbi_test("phys-unittests") {
deps =
[ "//zircon/kernel/phys/test:zbi-phys-unittests.zbi($phys_toolchain)" ]
}
devicetree_zbi_test("memory-test") {
deps = [ "//zircon/kernel/phys/test:zbi-memory-test.zbi($phys_toolchain)" ]
# This value should match `//zircon/kernel/phys/test:qemu-memory-test timeout`.
timeout = 150
}
devicetree_zbi_test("core-tests") {
deps = [ "//zircon/system/utest/core:core-tests.zbi($default_toolchain)" ]
# We've observed the ASAN variant of core-tests take as long as 701 seconds
# when booted via firmware on certain types of hardware. Leave a little buffer
# for growth.
timeout = 840
}
}
zbi_executable("zbi-boot-shim") {
deps = [ ":noop-boot-shim" ]
}
if (toolchain_environment == "kernel.phys") {
source_set("noop-boot-shim") {
sources = [ "zbi-boot-shim.cc" ]
include_dirs = [ "//zircon/kernel/phys" ]
deps = [
"//src/lib/zbitl",
"//zircon/kernel/phys:address-space",
"//zircon/kernel/phys:allocation",
"//zircon/kernel/phys:boot-zbi",
"//zircon/kernel/phys:main",
"//zircon/kernel/phys:symbolize",
"//zircon/kernel/phys:zbi-memory",
]
}
config("includes") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
source_set("devicetree") {
public_configs = [ ":includes" ]
sources = [ "devicetree.cc" ]
public = [ "include/phys/boot-shim/devicetree.h" ]
public_deps = [
"//sdk/lib/fit",
"//sdk/lib/zbi-format",
"//src/lib/zbitl",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/kernel/phys:allocation",
"//zircon/kernel/phys:boot-options",
"//zircon/kernel/phys:stdio",
"//zircon/kernel/phys:zbitl-allocation",
"//zircon/kernel/phys:zbitl-allocation",
"//zircon/kernel/phys/lib/boot-shim",
"//zircon/system/ulib/fbl",
]
deps = [
"//zircon/kernel/arch/$current_cpu/phys:linuxboot",
"//zircon/kernel/lib/arch",
"//zircon/kernel/phys:address-space",
"//zircon/kernel/phys:allocation-init",
"//zircon/kernel/phys:main",
"//zircon/kernel/phys:uart",
"//zircon/system/ulib/uart",
]
}
}
efi_executable("efi-boot-shim") {
sources = [ "efi-boot-shim.cc" ]
defines = [ "DEFAULT_ZBI_FILENAME=\"boot${efi_cpu}.zbi\"" ]
deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/kernel/phys/efi:efi-boot-zbi",
"//zircon/kernel/phys/efi:file",
"//zircon/kernel/phys/efi:main",
"//zircon/kernel/phys/lib/boot-shim",
]
}
group("tests") {
testonly = true
deps = [
":boot-shim",
"//zircon/kernel/arch/$zircon_cpu/phys/boot-shim:tests",
]
}
group("boot_tests") {
testonly = true
deps = [
":zbi-boot-shim-core-tests",
":zbi-boot-shim-phys-unittests",
":zbi-debugdata-boot-shim-hello-world-test",
":zbi-debugdata-boot-shim-test",
"//zircon/kernel/arch/$zircon_cpu/phys/boot-shim:boot_tests",
]
if (have_devicetree) {
deps += [
":devicetree-shim-core-tests",
":devicetree-shim-memory-test",
":devicetree-shim-phys-unittests",
]
}
}
zbi_test("zbi-boot-shim-phys-unittests") {
deps = [
":zbi-boot-shim",
"//zircon/kernel/phys/test:zbi-phys-unittests.zbi($phys_toolchain)",
]
# Set a short timeout since the tests don't reliably reboot the machine.
timeout = qemu_short_timeout
}
zbi_test("zbi-boot-shim-core-tests") {
deps = [
":zbi-boot-shim",
"//zircon/system/utest/core:core-tests.zbi($default_toolchain)",
]
}
zbi_executable("debugdata-boot-shim-test") {
testonly = true
sources = [ "debugdata-boot-shim-test.cc" ]
deps = [
"//zircon/kernel/lib/arch",
"//zircon/kernel/phys/lib/boot-shim",
"//zircon/kernel/phys/test:turducken",
]
}
# This brings the test program and the command-line to tell it to be the turkey
# that publishes data for the duck to see.
kernel_cmdline("debugdata-boot-shim-test.publish") {
visibility = [ ":*" ]
testonly = true
args = [ "debugdata.publish" ]
deps = [ ":debugdata-boot-shim-test" ]
}
# This just repacks the ZBI executable as a ZBI again, which doesn't change its
# contents. But it gets the file into a place where get_target_outputs() can
# find it without being in the right phys toolchain.
zbi("debugdata-boot-shim-test.zbi") {
visibility = [ ":*" ]
testonly = true
deps = [ ":debugdata-boot-shim-test" ]
}
# This just packs the same test as the turkey and the duck, the second instance
# won't get the "publish" command line so it will check instead.
turducken_zbi_test("zbi-debugdata-boot-shim-test") {
kernel = ":debugdata-boot-shim-test.publish"
# This needs a dependency on the zbi() target so it can use its output as an
# input. data_deps vs deps keeps it from being folded as a zbi_input() into
# the outer ZBI being created. The second output from the zbi() target is
# the JSON file; we only want the ZBI file, which is the first output.
data_deps = [ ":debugdata-boot-shim-test.zbi" ]
zbi_files = get_target_outputs(data_deps[0])
sources = [ zbi_files[0] ]
}
# This just repacks the hello-world-test ZBI executable as a ZBI again, which
# doesn't change its contents. But it gets the file into a place where
# get_target_outputs() in this BUILD.gn file can find it.
zbi("zbi-hello-world-test") {
visibility = [ ":*" ]
testonly = true
deps = [ "//zircon/kernel/phys/test:zbi-hello-world-test.executable($phys_toolchain)" ]
}
# This is the duck inside the turkey below. It checks for the debugdata item
# and then hands off to its chicken: the hello-world test.
turducken_zbi_test("debugdata-boot-shim-test.hello-world-test") {
visibility = [ ":*" ]
kernel = ":debugdata-boot-shim-test"
data_deps = [ ":zbi-hello-world-test" ]
zbi_files = get_target_outputs(data_deps[0])
sources = [ zbi_files[0] ]
}
# This will add the debugdata, hand off the the duck above that checks it
# and then hands off to hello-world-test.
turducken_zbi_test("zbi-debugdata-boot-shim-hello-world-test") {
kernel = ":debugdata-boot-shim-test.publish"
data_deps = [ ":debugdata-boot-shim-test.hello-world-test.zbi" ]
zbi_files = get_target_outputs(data_deps[0])
sources = [ zbi_files[0] ]
}