| # 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/images/args.gni") |
| import("//build/test.gni") |
| import("//build/testing/zbi_test.gni") |
| import("//build/unification/global_variables.gni") |
| import("//zircon/kernel/phys/phys_executable.gni") |
| import("//zircon/kernel/phys/qemu.gni") |
| import("//zircon/kernel/phys/zbi_executable.gni") |
| |
| group("boot-shim") { |
| deps = [ |
| ":linux-x86-boot-shim", |
| ":multiboot-shim", |
| ":pic-1mb-boot-shim", |
| ":x86-1mb-boot-shim", |
| ] |
| } |
| |
| # This is a shim between a legacy 1M ZBI boot loader and a modern |
| # position-independent ZBI. It's just the plain ZBI boot shim but |
| # linked at the fixed 1M load address instead of linked at zero. Like |
| # that shim, it's simply a ZBI kernel item prepended to a bootable ZBI |
| # to make the shimmed bootable ZBI--in this case, the 1M protocol ZBI. |
| zbi_executable("x86-1mb-boot-shim") { |
| # The add, remove trick ensures these are removed, whether or not they're |
| # present in the default configs list. |
| configs += [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| configs -= [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| configs += [ "//zircon/kernel/phys:load-pic" ] |
| configs -= [ "//zircon/kernel/phys:load-pic" ] |
| |
| # Now add the one we want. |
| configs += [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| |
| deps = [ "//zircon/kernel/phys/boot-shim:noop-boot-shim" ] |
| } |
| |
| # This is the inverse shim: between a modern ZBI boot loader that |
| # supports only the position-independent protocol, and a legacy ZBI |
| # that must be loaded at the 1M fixed address. It's also just a ZBI |
| # kernel item prepended to a bootable ZBI to make the shimmed bootable |
| # ZBI--in this case, the position-independent protocol ZBI. |
| zbi_executable("pic-1mb-boot-shim") { |
| # The add, remove trick ensures these are removed, whether or not they're |
| # present in the default configs list. |
| configs += [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| configs -= [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| configs += [ "//zircon/kernel/phys:load-pic" ] |
| configs -= [ "//zircon/kernel/phys:load-pic" ] |
| |
| # Now add the one we want. |
| configs += [ "//zircon/kernel/phys:load-pic" ] |
| |
| sources = [ "pic-1mb-shim.cc" ] |
| deps = [ |
| ":trampoline-boot", |
| "//zircon/kernel/phys:main", |
| "//zircon/kernel/phys:symbolize", |
| "//zircon/kernel/phys:zbi-memory", |
| "//zircon/kernel/phys/lib/memalloc", |
| "//zircon/system/ulib/zbitl", |
| ] |
| } |
| |
| if (toolchain.environment == "kernel.phys" || |
| toolchain.environment == "kernel.phys32") { |
| source_set("trampoline-boot") { |
| visibility = [ |
| ":*", |
| "//zircon/kernel/phys/*", |
| ] |
| sources = [ "trampoline-boot.cc" ] |
| public = [ "trampoline-boot.h" ] |
| public_deps = [ "//zircon/kernel/phys:boot-zbi" ] |
| deps = [ |
| "//zircon/kernel/lib/arch", |
| "//zircon/kernel/phys:symbolize", |
| "//zircon/kernel/phys/lib/memalloc", |
| ] |
| } |
| } |
| |
| zbi_executable("phys-1mb-hello-world") { |
| testonly = true |
| |
| # The add, remove trick ensures these are removed, whether or not they're |
| # present in the default configs list. |
| configs += [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| configs -= [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| configs += [ "//zircon/kernel/phys:load-pic" ] |
| configs -= [ "//zircon/kernel/phys:load-pic" ] |
| |
| # Now add the one we want. |
| configs += [ "//zircon/kernel/arch/x86/phys:load-1mb" ] |
| |
| deps = [ |
| "//zircon/kernel/phys/test:hello-world-test.source", |
| "//zircon/kernel/phys/test:zbi-test-main", |
| ] |
| } |
| |
| zbi_test("x86-boot-shim-tests") { |
| # The order matters here! |
| deps = [ |
| # First, the 1M shim: boot loaders in use today support the 1M protocol. |
| ":x86-1mb-boot-shim", |
| |
| # Second, the 1M->PIC shim hands off to the PIC->1M shim. |
| ":pic-1mb-boot-shim", |
| |
| # Finally, the PIC->1M shim hands off to the 1M test program. |
| ":phys-1mb-hello-world", |
| ] |
| } |
| |
| if (toolchain.environment == "kernel.phys32") { |
| source_set("legacy-boot-shim") { |
| sources = [ |
| "legacy-boot-shim.cc", |
| "legacy-boot-shim.h", |
| ] |
| deps = [ |
| ":stdout", |
| ":trampoline-boot", |
| "..:address-space", |
| "..:legacy-boot", |
| "//zircon/kernel/lib/arch", |
| "//zircon/kernel/lib/boot-options", |
| "//zircon/kernel/phys:arch-header", |
| "//zircon/kernel/phys:main", |
| "//zircon/kernel/phys:symbolize", |
| "//zircon/kernel/phys/lib/boot-shim", |
| "//zircon/system/ulib/hwreg", |
| ] |
| friend = [ ":legacy-boot-shim-tests" ] |
| } |
| |
| source_set("stdout") { |
| sources = [ "stdout.cc" ] |
| public = [ "stdout.h" ] |
| deps = [ |
| "//zircon/kernel/lib/boot-options", |
| "//zircon/system/ulib/lazy_init", |
| "//zircon/system/ulib/uart", |
| ] |
| } |
| |
| phys_executable("linux-x86-boot-shim") { |
| sources = [ "linux-x86-boot-shim.cc" ] |
| deps = [ |
| ":legacy-boot-shim", |
| "..:linuxboot", |
| "//zircon/kernel/phys:symbolize", |
| ] |
| } |
| |
| phys_executable("multiboot-shim") { |
| sources = [ "multiboot-shim.cc" ] |
| deps = [ |
| ":legacy-boot-shim", |
| "..:multiboot", |
| "//zircon/kernel/phys:symbolize", |
| ] |
| |
| # This marks it as the official default boot shim for using QEMU. |
| images_metadata = { |
| name = "qemu-kernel" |
| archive = add_qemu_to_build_archives |
| } |
| |
| # Everything should find this via the //:images build API. |
| # But some things might still look for "out/.../multiboot.bin" directly. |
| output_dir = root_build_dir |
| output_name = "multiboot" |
| } |
| } else { |
| group("linux-x86-boot-shim") { |
| public_deps = |
| [ ":linux-x86-boot-shim(//zircon/kernel/arch/x86/phys:kernel.phys32)" ] |
| } |
| |
| group("multiboot-shim") { |
| public_deps = |
| [ ":multiboot-shim(//zircon/kernel/arch/x86/phys:kernel.phys32)" ] |
| } |
| } |
| |
| test("legacy-boot-shim-tests") { |
| sources = [ "legacy-boot-shim-tests.cc" ] |
| deps = [ |
| "//zircon/kernel/phys/lib/boot-shim", |
| "//zircon/kernel/phys/lib/boot-shim:boot-shim-test", |
| "//zircon/system/ulib/zxtest", |
| ] |
| } |
| |
| qemu_shims = [ |
| { |
| name = "linux-x86-boot-shim" |
| format = "linuxboot" |
| }, |
| { |
| name = "multiboot-shim" |
| format = "multiboot" |
| }, |
| ] |
| |
| qemu_shim_tests = [ |
| "bootsvc-integration-tests", |
| "core-tests", |
| "phys-unittests", |
| ] |
| |
| template("qemu_shim_test") { |
| foreach(shim, qemu_shims) { |
| zbi_test("${shim.name}-$target_name") { |
| foreach(qemu, qemu_boot_formats) { |
| if (qemu.name == shim.format) { |
| qemu_kernel = ":${shim.name}(${qemu.environment})" |
| forward_variables_from(qemu, [ "timeout" ]) |
| } |
| } |
| assert(defined(qemu_kernel), "$shim not in $qemu_boot_formats") |
| |
| device_types = [ "QEMU" ] |
| |
| forward_variables_from(invoker, "*") |
| } |
| } |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":legacy-boot-shim-tests($host_toolchain)", |
| ":x86-boot-shim-tests", |
| ] |
| foreach(shim, qemu_shims) { |
| deps += [ ":${shim.name}" ] |
| foreach(test, qemu_shim_tests) { |
| deps += [ ":${shim.name}-$test" ] |
| } |
| } |
| } |
| |
| qemu_shim_test("phys-unittests") { |
| deps = [ "//zircon/kernel/phys/test:zbi-phys-unittests.zbi(//zircon/kernel/phys:kernel.phys_$current_cpu)" ] |
| } |
| |
| qemu_shim_test("core-tests") { |
| deps = [ "//zircon/system/utest/core:core-tests.zbi($default_toolchain)" ] |
| |
| # This runs the real kernel with full hardware reboot/shutdown support and it |
| # isn't necessarily really quick, so don't impose the short timeout used for |
| # raw phys tests. |
| timeout = false |
| } |
| |
| qemu_shim_test("bootsvc-integration-tests") { |
| deps = [ "//src/bringup/bin/bootsvc/integration_test:bootsvc-integration-tests.zbi($default_toolchain)" ] |
| } |