| # 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/images/args.gni") |
| |
| # Generates a partitions config to be consued by the Image Assembler. |
| # |
| # Arguments: |
| # output_path (required) |
| # [path] Board config output location. |
| # |
| # hw_revision (required) |
| # [string] The name of the hardware revision. |
| # This is placed in the flash manifest to ensure partitions are not |
| # flashed to the wrong hardware. |
| # |
| # esp_image_path (optional) |
| # [string] The path on host to the ESP bootloader. |
| # |
| # bootstrap_partitions (optional) |
| # [list] List of OEM images to flash when using: |
| # ffx target flash --product fuchsia |
| # |
| # Each entry will have the following format. A file is only flashed to the |
| # partition if the conditional fastboot arg equals the specified value. |
| # { |
| # path = "path/to/image" |
| # partition = "partition_name" |
| # condition = { |
| # variable = "variable_name" |
| # value = "value |
| # } |
| # } |
| # |
| # unlock_credentials (optional) |
| # [list] List of zip files containing the credentials used to unlock |
| # a device in fastboot mode. |
| # |
| template("generated_partitions_config") { |
| assert(defined(invoker.output_path), "Need to define output_path") |
| assert(defined(invoker.hw_revision), "Need to define hw_revision") |
| |
| bootstrap = [] |
| if (defined(invoker.bootstrap_partitions)) { |
| foreach(part, invoker.bootstrap_partitions) { |
| bootstrap += [ |
| { |
| image = rebase_path(part.path, root_build_dir) |
| name = part.partition |
| condition = part.condition |
| }, |
| ] |
| } |
| } |
| |
| credentials = [] |
| if (defined(invoker.unlock_credentials)) { |
| foreach(cred, invoker.unlock_credentials) { |
| credentials += [ rebase_path(cred, root_build_dir) ] |
| } |
| } |
| |
| generated_file(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| "visibility", |
| ]) |
| |
| outputs = [ invoker.output_path ] |
| output_conversion = "json" |
| |
| # Aggregate all the bootloader partitions. |
| _bootloader_partitions = [] |
| foreach(firmware, firmware_prebuilts) { |
| assert(defined(firmware.type), "Firmware type must be specified") |
| assert(defined(firmware.path), "Firmware path must be specified") |
| |
| firmware_path = |
| rebase_path("${firmware.path}${firmware_prebuilts_path_suffix}", |
| root_build_dir) |
| partition = { |
| } |
| partition.type = firmware.type |
| partition.image = firmware_path |
| |
| # If a partition is specified, then the flash manifest will include the bootloader. |
| if (defined(firmware.partition)) { |
| partition.name = firmware.partition |
| } |
| _bootloader_partitions += [ partition ] |
| } |
| |
| # Add the ESP partition if necessary. |
| if (defined(invoker.esp_image_path)) { |
| _bootloader_partitions += [ |
| { |
| name = "fuchsia-esp" |
| type = "esp" |
| image = rebase_path("${invoker.esp_image_path}", root_build_dir) |
| }, |
| ] |
| } |
| |
| # Aggregate all the non-bootloader partitions. |
| _partitions = [] |
| if (zircon_a_partition != "") { |
| _partitions += [ |
| { |
| name = zircon_a_partition |
| type = "ZBI" |
| slot = "A" |
| }, |
| ] |
| } |
| if (zircon_b_partition != "") { |
| _partitions += [ |
| { |
| name = zircon_b_partition |
| type = "ZBI" |
| slot = "B" |
| }, |
| ] |
| } |
| if (zircon_r_partition != "") { |
| _partitions += [ |
| { |
| name = zircon_r_partition |
| type = "ZBI" |
| slot = "R" |
| }, |
| ] |
| } |
| if (vbmeta_a_partition != "") { |
| _partitions += [ |
| { |
| name = vbmeta_a_partition |
| type = "VBMeta" |
| slot = "A" |
| }, |
| ] |
| } |
| if (vbmeta_b_partition != "") { |
| _partitions += [ |
| { |
| name = vbmeta_b_partition |
| type = "VBMeta" |
| slot = "B" |
| }, |
| ] |
| } |
| if (vbmeta_r_partition != "") { |
| _partitions += [ |
| { |
| name = vbmeta_r_partition |
| type = "VBMeta" |
| slot = "R" |
| }, |
| ] |
| } |
| if (fvm_partition != "") { |
| _partitions += [ |
| { |
| name = fvm_partition |
| type = "FVM" |
| }, |
| ] |
| } |
| |
| contents = { |
| hardware_revision = invoker.hw_revision |
| bootloader_partitions = _bootloader_partitions |
| partitions = _partitions |
| bootstrap_partitions = bootstrap |
| unlock_credentials = credentials |
| } |
| } |
| } |