| # Copyright 2018 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/assembly/package_list.gni") |
| import("//build/board.gni") |
| import("//build/compiled_action.gni") |
| import("//build/component/component_id_index.gni") |
| import("//build/config.gni") |
| import("//build/config/clang/clang.gni") |
| import("//build/dist/fini_manifest.gni") |
| import("//build/drivers/driver_manifest.gni") |
| import("//build/images/args.gni") |
| import("//build/images/custom_signing.gni") |
| import("//build/images/paths.gni") |
| import("//build/images/size_checker/size_checker_input.gni") |
| import("//build/images/vbmeta.gni") |
| import("//build/images/vboot/vboot.gni") |
| import("//build/info/info.gni") |
| import("//build/product.gni") |
| import("//build/sdk/config.gni") |
| import("//build/security.gni") |
| import("//build/zbi/zbi_input.gni") |
| import("//build/zircon/tools.gni") |
| import("//src/storage/fshost/generated_fshost_config.gni") |
| |
| assert(current_toolchain == default_toolchain, |
| "//build/images/* are only valid in the Fuchsia toolchain") |
| |
| assert( |
| bootfs_only == use_bringup_assembly, |
| "use_bringup_assembly is replacing bootfs_only, and MUST always be the same value") |
| |
| # This is a group that contains the one-and-only assembly implementation. It |
| # can be used in contexts that need either bringup or the full-fuchsia assembly |
| # implementation's outputs. |
| # |
| # If a target requires the outputs of the full-fuchsia assembly implementation, |
| # it should directly use it (//build/images/fuchsia). |
| group("main_assembly") { |
| testonly = use_bringup_assembly || fuchsia_zbi_testonly |
| public_deps = [ labels.images ] |
| } |
| |
| # Dependencies for all image targets referenced by paver_targets, i.e., the |
| # images needed by the generated pave scripts. |
| default_image_deps = [ labels.images ] |
| |
| board_name_file = "$root_build_dir/board_name" |
| write_file(board_name_file, "${board_name}") |
| |
| ### |
| ### Zircon Boot Images |
| ### |
| |
| default_image_deps += [ labels.qemu_kernel ] |
| |
| # This action runs a script that checks all vtables in fuchsia binaries are |
| # in readonly data. |
| action("check_vtables_in_rodata") { |
| testonly = true |
| hermetic_deps = false |
| script = "//scripts/clang/check_vtable_rodata.py" |
| outputs = [ "$root_build_dir/$target_name" ] |
| depfile = "$root_build_dir/$target_name.d" |
| |
| # Ensure that all fuchsia binaries listed in `binaries.json` are created |
| # first. |
| deps = [ labels.images ] |
| |
| args = [ |
| # Ignore these specific libunwind symbols for now because these are from |
| # the libwundind prebuilts used by rust which we do not currently build |
| # with relative vtables. |
| "--exclude", |
| "vtable for libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_x86_64>", |
| "--exclude", |
| "vtable for libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm64>", |
| |
| "--readelf", |
| "$rebased_clang_prefix/llvm-readelf", |
| |
| # Write to a file. |
| "-o", |
| rebase_path(outputs[0], root_build_dir), |
| |
| # Run in `fuchsia` mode, which looks for `binaries.json` in the provided |
| # output directory. |
| "fuchsia", |
| |
| # Point to the output directory. |
| rebase_path("$root_build_dir", root_build_dir), |
| |
| "--depfile", |
| rebase_path(depfile, root_build_dir), |
| ] |
| } |
| |
| group("fvm.sparse.blk") { |
| testonly = fuchsia_zbi_testonly |
| public_deps = [ labels.images ] |
| } |
| |
| group("fvm.blob.sparse.blk") { |
| testonly = fuchsia_zbi_testonly |
| public_deps = [ labels.images ] |
| } |
| |
| group("fvm.fastboot.blk") { |
| testonly = fuchsia_zbi_testonly |
| public_deps = [ labels.images ] |
| } |
| |
| group("fuchsia") { |
| testonly = fuchsia_zbi_testonly |
| public_deps = [ labels.images ] |
| } |
| |
| group("fuchsia.vbmeta") { |
| testonly = fuchsia_zbi_testonly |
| public_deps = [ labels.images ] |
| } |
| |
| # Pseudo-target to record information about the sizes of filesystems assembled |
| # during the build for later analysis. |
| # TODO(fxbug.dev/81871): Only include this for builds that generate blobfs |
| # once this targets is no longer hardcoded in infra. |
| group("record_filesystem_sizes") { |
| testonly = true |
| if (!use_bringup_assembly) { |
| deps = [ "//build/images/sizes:elf_sizes.json" ] |
| } |
| } |
| |
| default_image_deps += [ "//build/images/flash" ] |
| |
| # If a GPT image was specified, make it available as a build artifact. |
| if (gpt_image != "") { |
| copy("gpt") { |
| testonly = true |
| sources = [ rebase_path(gpt_image, root_build_dir) ] |
| outputs = [ "$root_out_dir/gpt.bin" ] |
| |
| metadata = { |
| images = [ |
| { |
| label = get_label_info(":gpt", "label_with_toolchain") |
| archive = true |
| name = "gpt" |
| path = "gpt.bin" |
| type = "bin" |
| }, |
| ] |
| } |
| } |
| |
| default_image_deps += [ ":gpt" ] |
| } |
| |
| default_image_deps += [ "//build/images/tools:board_tools" ] |
| |
| default_image_deps += [ recovery_label ] |
| |
| # Build the UEFI disk image. |
| # GCE, a consumer of this image, requires it to be named disk.raw |
| uefi_disk_path = "$target_out_dir/disk.raw" |
| mkfs_label = "//zircon/third_party/uapp/mkfs-msdosfs($host_toolchain)" |
| mkfs_out_dir = get_label_info(mkfs_label, "root_out_dir") |
| mkfs_bin = "$mkfs_out_dir/mkfs-msdosfs" |
| |
| if (!use_bringup_assembly && !fxfs_blob) { |
| fvm_tool_target = "//src/storage/bin/fvm($host_toolchain)" |
| fvm_tool_path = get_label_info(fvm_tool_target, "root_out_dir") + "/fvm" |
| } |
| |
| compiled_action("uefi-disk") { |
| no_output_dir_leaks = false |
| |
| deps = [ |
| "zedboot", |
| "//src/firmware/gigaboot/cpp:fuchsia", |
| labels.images, |
| mkfs_label, |
| ] |
| testonly = true |
| tool = "//tools/make-fuchsia-vol" |
| inputs = [ mkfs_bin ] |
| |
| bootloader_path = |
| rebase_path("${root_build_dir}/kernel.efi_${target_cpu}/fuchsia-efi.efi") |
| |
| args = [ |
| "--fuchsia-build-dir", |
| rebase_path("$root_build_dir"), |
| "--arch", |
| target_cpu, |
| "--bootloader", |
| bootloader_path, |
| "--resize", |
| "10000000000", # 10GB |
| "--depfile", |
| "--host-arch", |
| host_cpu, |
| ] |
| if (fxfs_blob) { |
| args += [ "--use-fxfs" ] |
| } |
| |
| depfile = "$uefi_disk_path.d" |
| |
| if (use_bringup_assembly) { |
| args += [ "--ramdisk-only" ] |
| } else if (!fxfs_blob) { |
| inputs += [ fvm_tool_path ] |
| deps += [ "//src/storage/bin/fvm:fvm($host_toolchain)" ] |
| } |
| |
| args += [ rebase_path(uefi_disk_path) ] |
| outputs = [ uefi_disk_path ] |
| |
| metadata = { |
| images = [ |
| { |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| archive = false |
| name = "uefi-disk" |
| path = rebase_path(uefi_disk_path, root_build_dir) |
| type = "blk" |
| }, |
| ] |
| } |
| } |
| |
| group("images") { |
| testonly = true |
| deps = [ |
| ":default-images", |
| "//build/images/archive:build_args_metadata", |
| ] |
| |
| if (defined(labels.images_netboot)) { |
| deps += [ labels.images_netboot ] |
| } |
| } |
| |
| # The default-images target is a dependency of the top level default |
| # target when appropriate, and contains the minimum set of images that |
| # are typical given the requested build configuration. |
| group("default-images") { |
| testonly = true |
| |
| deps = default_image_deps |
| |
| # Downstream tools (e.g. bundle_fetcher in infra) relies on metadata generated |
| # by product_metadata, so keeping this dep for Bazel assembly. |
| deps += [ "//build/images/flash:product_metadata" ] |
| |
| # Prune unsupported targets when Bazel assembly is enabled. This makes sure |
| # the build: |
| # |
| # * does NOT take dependency on GN assembly when only Bazel assembly should |
| # be used; |
| # * does NOT generate unused outputs with incorrect content, which |
| # accidentally become load-bearing. |
| # |
| if (!use_bazel_images_only) { |
| # Paving is not supported in Bazel assembly. |
| if (recovery_is_zedboot) { |
| deps += [ |
| "//build/images/archive:paver-script", |
| "//build/images/archive:zedboot-script", |
| "//build/images/tools:bootserver", |
| ] |
| } |
| |
| # TODO(https://fxbug.dev/125008): Support size checking in Bazel assembly. |
| if (size_checker_input != { |
| }) { |
| deps += [ "size_checker:run_product_size_checker" ] |
| } |
| if (!bootfs_only) { |
| if (!use_bringup_assembly) { |
| deps += [ ":record_filesystem_sizes" ] |
| } |
| } |
| |
| # TODO(https://fxbug.dev/125009): Support uefi-disk in Bazel assembly. |
| if (build_uefi_disk) { |
| deps += [ ":uefi-disk" ] |
| } |
| } |
| |
| # Even if Bazel assembly uses product bundle to flash, downstream tools can |
| # still expect flash.json and flash.sh to exist for flashing. |
| deps += [ |
| "//build/images/flash:fastboot_manifest", |
| "//build/images/flash:flash_script", |
| "//build/images/tools:fastboot($host_toolchain)", |
| ] |
| |
| if (size_checker_input != { |
| }) { |
| # Size checks only make sense when use_bringup_assembly is false, since |
| # they require system images in addition to the ZBI. |
| deps += [ "size_checker:size_report.json" ] |
| } |
| |
| if (enable_netboot) { |
| deps += [ "archive:netboot-script" ] |
| } |
| |
| # TODO(fxbug.dev/46415): The build graph for "bringup" (use_bringup_assembly) |
| # MUST only contain one zircon-a metadata target, which means that anything |
| # reaching fuchsia.zbi must be excluded from the build graph. |
| if (!use_bringup_assembly) { |
| deps += [ "//build/images/updates" ] |
| } else { |
| deps += [ "//build/images/archive:fastboot-boot-script" ] |
| } |
| |
| if (check_vtables_in_rodata) { |
| deps += [ ":check_vtables_in_rodata" ] |
| } |
| |
| if (build_usb_installer) { |
| deps += [ "//build/images/installer" ] |
| } |
| |
| if (bazel_assembly_targets != []) { |
| # Make `bazel_assembly_targets` take precedence to aid soft transition. |
| # |
| # TODO(jayzhuang): Remove this if block when `bazel_assembly_targets` is |
| # removed. |
| deps += bazel_assembly_targets |
| } else if (bazel_product_bundle_target != "") { |
| deps += [ bazel_product_bundle_target ] |
| deps += extra_bazel_assembly_targets |
| } |
| } |
| |
| # Write delivery_blob_config.json file to be uploaded as a build artifact. |
| if (delivery_blob_type != false) { |
| generated_file("delivery_blob_config") { |
| outputs = [ "$root_build_dir/delivery_blob_config.json" ] |
| output_conversion = "json" |
| |
| contents = { |
| type = delivery_blob_type |
| } |
| } |
| } |