blob: 1a1cab82942950361bf90bb86d94e5746498f3a6 [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.
# Generates a partitions config to be consumed by the Image Assembler.
#
# Arguments:
# output_path (optional)
# [path] Board config output location.
# Defaults to $target_out_dir/$target_name.json
#
# 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)
# [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.json"
if (defined(invoker.output_path)) {
output_path = invoker.output_path
}
bootloaders = []
if (defined(invoker.bootloader_partitions)) {
foreach(part, invoker.bootloader_partitions) {
assert(defined(part.image), "All bootloaders must define a path")
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) ]
}
}
generated_file(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
outputs = [ output_path ]
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.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.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
}
}
}