blob: 36453f844d9bb47b8ee011bb41b2c63f97bfb00d [file] [log] [blame]
# 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/compiled_action.gni")
# Generates a partitions config to be consumed by the Image Assembler.
#
# Arguments:
# 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.
#
# bootloader_partitions (optional)
# [list] List of bootloaders to use when flashing or updating.
# Each entry will have the following format.
# {
# image = "path/to/image"
# type = "bl2"
# name = "boot1"
# }
#
# If a name is not provided, then the bootloader will not be flashed, but
# will still be included in the update package.
#
# 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"
# condition = {
# variable = "variable"
# value = "value
# }
# }
#
# unlock_credentials (optional)
# [list] List of zip files containing the credentials used to unlock
# a device in fastboot mode.
#
# zbi_a (optional)
# zbi_b (optional)
# zbi_r (optional)
# recovery_zbi_a (optional)
# recovery_zbi_b (optional)
# recovery_zbi_r (optional)
# [string] The name of the zbi partitions for each slot.
#
# zbi_a_size (optional)
# zbi_b_size (optional)
# zbi_r_size (optional)
# [int] The number of bytes available in the partition.
#
# vbmeta_a (optional)
# vbmeta_b (optional)
# vbmeta_r (optional)
# [string] The name of the vbmeta partitions for each slot.
#
# vbmeta_a_size (optional)
# vbmeta_b_size (optional)
# vbmeta_r_size (optional)
# [int] The number of bytes available in the partition.
#
# fvm (optional)
# [string] The name of the fvm partition.
#
# fxfs (optional)
# [string] The name of the fxfs partition.
#
# fvm_size (optional)
# fxfs_size (optional)
# [int] The number of bytes available in the partition.
#
template("generated_partitions_config") {
assert(defined(invoker.hw_revision), "Need to define hw_revision")
output_path = "$target_out_dir/$target_name"
bootloaders = []
if (defined(invoker.bootloader_partitions)) {
foreach(part, invoker.bootloader_partitions) {
assert(defined(part.image), "All bootloaders must define an image")
assert(defined(part.type), "All bootloaders must define a type")
path = rebase_path(part.image, root_build_dir)
if (defined(part.name)) {
bootloaders += [
{
image = path
type = part.type
name = part.name
},
]
} else {
bootloaders += [
{
image = path
type = part.type
},
]
}
}
}
bootstraps = []
if (defined(invoker.bootstrap_partitions)) {
foreach(part, invoker.bootstrap_partitions) {
bootstraps += [
{
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) ]
}
}
cwd_relative_partitions_label = "$target_name.cwd_relative_partitions_config"
cwd_relative_partitions_config =
"$target_out_dir/${target_name}_intermediate.json"
generated_file(cwd_relative_partitions_label) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
outputs = [ cwd_relative_partitions_config ]
output_conversion = "json"
# Aggregate all the non-bootloader partitions.
_partitions = []
if (defined(invoker.zbi_a) && invoker.zbi_a != "") {
_zbi_a = {
name = invoker.zbi_a
type = "ZBI"
slot = "A"
if (defined(invoker.zbi_a_size)) {
size = invoker.zbi_a_size
}
}
_partitions += [ _zbi_a ]
}
if (defined(invoker.zbi_b) && invoker.zbi_b != "") {
_zbi_b = {
name = invoker.zbi_b
type = "ZBI"
slot = "B"
if (defined(invoker.zbi_b_size)) {
size = invoker.zbi_b_size
}
}
_partitions += [ _zbi_b ]
}
if (defined(invoker.zbi_r) && invoker.zbi_r != "") {
_zbi_r = {
name = invoker.zbi_r
type = "ZBI"
slot = "R"
if (defined(invoker.zbi_r_size)) {
size = invoker.zbi_r_size
}
}
_partitions += [ _zbi_r ]
}
if (defined(invoker.recovery_zbi_a) && invoker.recovery_zbi_a != "") {
_recovery_zbi_a = {
name = invoker.recovery_zbi_a
type = "RecoveryZBI"
slot = "A"
}
_partitions += [ _recovery_zbi_a ]
}
if (defined(invoker.recovery_zbi_b) && invoker.recovery_zbi_b != "") {
_recovery_zbi_b = {
name = invoker.recovery_zbi_b
type = "RecoveryZBI"
slot = "B"
}
_partitions += [ _recovery_zbi_b ]
}
if (defined(invoker.recovery_zbi_r) && invoker.recovery_zbi_r != "") {
_recovery_zbi_r = {
name = invoker.recovery_zbi_r
type = "RecoveryZBI"
slot = "R"
}
_partitions += [ _recovery_zbi_r ]
}
if (defined(invoker.vbmeta_a) && invoker.vbmeta_a != "") {
_vbmeta_a = {
name = invoker.vbmeta_a
type = "VBMeta"
slot = "A"
if (defined(invoker.vbmeta_a_size)) {
size = invoker.vbmeta_a_size
}
}
_partitions += [ _vbmeta_a ]
}
if (defined(invoker.vbmeta_b) && invoker.vbmeta_b != "") {
_vbmeta_b = {
name = invoker.vbmeta_b
type = "VBMeta"
slot = "B"
if (defined(invoker.vbmeta_b_size)) {
size = invoker.vbmeta_b_size
}
}
_partitions += [ _vbmeta_b ]
}
if (defined(invoker.vbmeta_r) && invoker.vbmeta_r != "") {
_vbmeta_r = {
name = invoker.vbmeta_r
type = "VBMeta"
slot = "R"
if (defined(invoker.vbmeta_r_size)) {
size = invoker.vbmeta_r_size
}
}
_partitions += [ _vbmeta_r ]
}
if (defined(invoker.dtbo_a) && invoker.dtbo_a != "") {
_dtbo_a = {
name = invoker.dtbo_a
type = "Dtbo"
slot = "A"
if (defined(invoker.dtbo_a_size)) {
size = invoker.dtbo_a_size
}
}
_partitions += [ _dtbo_a ]
}
if (defined(invoker.dtbo_b) && invoker.dtbo_b != "") {
_dtbo_b = {
name = invoker.dtbo_b
type = "Dtbo"
slot = "B"
if (defined(invoker.dtbo_b_size)) {
size = invoker.dtbo_b_size
}
}
_partitions += [ _dtbo_b ]
}
if (defined(invoker.fvm) && invoker.fvm != "") {
_fvm = {
name = invoker.fvm
type = "FVM"
if (defined(invoker.fvm_size)) {
size = invoker.fvm_size
}
}
_partitions += [ _fvm ]
}
if (defined(invoker.fxfs) && invoker.fxfs != "") {
_fxfs = {
name = invoker.fxfs
type = "Fxfs"
if (defined(invoker.fxfs_size)) {
size = invoker.fxfs_size
}
}
_partitions += [ _fxfs ]
}
contents = {
hardware_revision = invoker.hw_revision
bootloader_partitions = bootloaders
partitions = _partitions
bootstrap_partitions = bootstraps
unlock_credentials = credentials
}
}
compiled_action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
# The contents of these folders are dynamic, and managed entirely by this
# action. Further, this action will need to delete items from these
# directories that are not added back (on an incremental build, if an item
# is removed from one of these sets)
hermetic_action_ignored_prefixes = [ output_path ]
tool = "//build/assembly/tools/assembly_config"
tool_output_name = "assembly_config"
depfile_path = "$target_out_dir/$target_name.depfile"
depfile = depfile_path
outputs = [ "$output_path/partitions_config.json" ]
inputs = [ cwd_relative_partitions_config ]
metadata = {
partitions_configs = [
{
label = get_label_info(target_name, "label_with_toolchain")
name = invoker.hw_revision
outdir = rebase_path(output_path, root_build_dir)
},
]
}
args = [
"generate",
"partitions",
"--config",
rebase_path(inputs[0], root_build_dir),
"--output",
rebase_path(output_path, root_build_dir),
"--depfile",
rebase_path(depfile_path, root_build_dir),
]
deps = [ ":$cwd_relative_partitions_label" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}