# Copyright 2020 The Hafnium Authors.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/BSD-3-Clause.

import("//build/image/image.gni")
import("//build/toolchain/platform.gni")

# The bootloader image.
image_binary("qemuloader") {
  image_name = "qemuloader"
  deps = [ ":loader" ]
}

source_set("loader") {
  public_configs = [
    "//src/arch/aarch64:config",
    "//third_party/dtc:libfdt_config",
  ]
  sources = [
    "entry.S",
    "fwcfg.c",
    "loader.c",
  ]

  deps = [
    "//src:abort",
    "//src:dlog",
    "//src:layout",
    "//src:panic",
    "//src/arch/${plat_arch}:entry",
    "//third_party/dtc:libfdt",
  ]
}

copy("tfa_copy") {
  sources = [
    "//prebuilts/linux-aarch64/trusted-firmware-a/qemu/bl2.bin",
    "//prebuilts/linux-aarch64/trusted-firmware-a/qemu/bl31.bin",
    "//prebuilts/linux-aarch64/trusted-firmware-a/qemu/bl32.bin",
  ]
  outputs = [ "$root_out_dir/{{source_file_part}}" ]
}

copy("qemuloader_copy") {
  sources = [ "$root_out_dir/qemuloader.bin" ]
  deps = [ ":qemuloader" ]
  outputs = [ "$root_out_dir/bl33.bin" ]
}

group("bl") {
  deps = [
    ":qemuloader_copy",
    ":tfa_copy",
  ]
}
