// Copyright (C) 2021 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copyof the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed toin writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OFANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
type VbmetaProperties struct {
// Name of the partition stored in vbmeta desc. Defaults to the name of this module.
Partition_name *string
// Typeof the `android_filesystem` for which the vbmeta.img is created.
// Examples are system, vendor, product.
Filesystem_partition_type *string
// Set the name of the output. Defaults to <module_name>.img.
Stem *string
// Path to the private key that avbtool will use tosign this vbmeta image.
Private_key *string `android:"path"`
// Algorithm that avbtool will use tosign this vbmeta image. Default is SHA256_RSA4096.
Algorithm *string
// The rollbackindex. If unspecified, the rollbackindexisfrom PLATFORM_SECURITY_PATCH
Rollback_index *int64
// Rollbackindex location of this vbmeta image. Must be 0, 1, 2, etc. Default is0.
Rollback_index_location *int64
// List of filesystem modules that this vbmeta has descriptors for. The filesystem modules
// have to be signed (use_avb: true).
Partitions proptools.Configurable[[]string]
// Metadata about the chained partitions that this vbmeta delegates the verification.
// This is an alternative to chained_partitions, using chained_partitions instead is simpler
// in most cases. However, this property allows building this vbmeta partition without
// its chained partitions existing in this build.
Chained_partition_metadata []ChainedPartitionProperties
// List of chained partitions that this vbmeta delegates the verification. They are the
// names of other vbmeta modules.
Chained_partitions []string
// List of key-value pair of avb properties
Avb_properties []avbProperty
// Determines if the moduleis auto-generated from Soong or not. If the moduleis
// auto-generated, it does not use generic config.
Is_auto_generated *bool
}
type avbProperty struct {
// Key of given avb property
Key *string
// Value of given avb property
Value *string
}
type ChainedPartitionProperties struct {
// Name of the chained partition
Name *string
// Rollbackindex location of the chained partition. Must be 1, 2, 3, etc. Default is the
// indexof this partition in the list + 1.
Rollback_index_location *int64
// Path to the public key that the chained partition is signed with. If this isspecified,
// private_key is ignored.
Public_key *string `android:"path"`
// Path to the private key that the chained partition is signed with. If this isspecified,
// and public_key is not specified, a public key is extracted from this private key and
// the extracted public key is embedded in the vbmeta image.
Private_key *string `android:"path"`
}
// @auto-generate: gob type vbmetaPartitionInfo struct {
// Name of the partition
Name string
// Partition typeof the correspdonding android_filesystem.
FilesystemPartitionType string
// Rollbackindex location, non-negative int
RollbackIndexLocation int
// The path to the public key of the private key used tosign this partition. Derived from
// the private key.
PublicKey android.Path
// The output of the vbmeta module
Output android.Path
// Information about the vbmeta partition that will be added to misc_info.txt
// created by android_device
PropFileForMiscInfo android.Path
// Whether this is a partition of bootloader.img
AbOtaBootloaderPartition bool
}
// @auto-generate: gob type vbmetaPartitionInfos []vbmetaPartitionInfo
var vbmetaPartitionProvider = blueprint.NewProvider[vbmetaPartitionInfo]()
var vbmetaPartitionsProvider = blueprint.NewProvider[vbmetaPartitionInfos]()
// vbmeta is the partition image that has the verification information for other partitions.
func VbmetaFactory() android.Module { module := &vbmeta{} module.AddProperties(&module.properties)
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
return module
}
type vbmetaDep struct {
blueprint.BaseDependencyTag
}
type chainedPartitionDep struct {
blueprint.BaseDependencyTag
}
var vbmetaPartitionDep = vbmetaDep{}
var vbmetaChainedPartitionDep = chainedPartitionDep{}
for _, avb_prop := range v.properties.Avb_properties {
key := proptools.String(avb_prop.Key) if key == "" {
ctx.PropertyErrorf("avb_properties", "key must be specified") continue
}
value := proptools.String(avb_prop.Value) if value == "" {
ctx.PropertyErrorf("avb_properties", "value must be specified") continue
}
cmd.FlagWithArg("--prop ", key+":"+value)
}
type partitionWithName struct {
Name string
Output android.Path
}
var includeDescriptorsFromImages []partitionWithName for _, p := range ctx.GetDirectDepsProxyWithTag(vbmetaPartitionDep) {
bootImgInfo, ok := android.OtherModuleProvider(ctx, p, BootimgInfoProvider) if ok {
includeDescriptorsFromImages = append(includeDescriptorsFromImages, partitionWithName{
Name: bootImgInfo.Type.String(),
Output: bootImgInfo.SignedOutput,
}) continue
}
vbmetaPartitionInfo, ok := android.OtherModuleProvider(ctx, p, vbmetaPartitionProvider) if ok {
includeDescriptorsFromImages = append(includeDescriptorsFromImages, partitionWithName{
Name: vbmetaPartitionInfo.Name,
Output: vbmetaPartitionInfo.Output,
}) continue
}
vbmetaPartitionInfos, ok := android.OtherModuleProvider(ctx, p, vbmetaPartitionsProvider) if ok { for _, vbmetaPartitionInfo := range vbmetaPartitionInfos {
includeDescriptorsFromImages = append(includeDescriptorsFromImages, partitionWithName{
Name: vbmetaPartitionInfo.Name,
Output: vbmetaPartitionInfo.Output,
})
} continue
}
fsInfo, ok := android.OtherModuleProvider(ctx, p, FilesystemProvider) if !ok {
ctx.PropertyErrorf("partitions", "%q(type: %s) is not supported, must be a filesystem",
p.Name(), ctx.OtherModuleType(p)) continue
}
includeDescriptorsFromImages = append(includeDescriptorsFromImages, partitionWithName{
Name: fsInfo.PartitionName,
Output: fsInfo.SignedOutputPath,
})
}