// Copyright (C) 2024 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.
//go:generate go run ../../blueprint/gobtools/codegen
type PartitionNameProperties struct {
// Name of the super partition filesystem module
Super_partition_name *string
// Name of the boot partition filesystem module
Boot_partition_name *string
// Name of the boot 16k partition filesystem module
Boot_16k_partition_name *string
// Name of the vendor boot partition filesystem module
Vendor_boot_partition_name *string
// Name of the vendor boot debug partition filesystem module
Vendor_boot_debug_partition_name *string
// Name of the vendor boot test harness partition filesystem module
Vendor_boot_test_harness_partition_name *string
// Name of the vendor kernel boot partition filesystem module
Vendor_kernel_boot_partition_name *string
// Name of the init boot partition filesystem module
Init_boot_partition_name *string
// Name of the system partition filesystem module
System_partition_name *string
// Name of the system_ext partition filesystem module
System_ext_partition_name *string
// Name of the product partition filesystem module
Product_partition_name *string
// Name of the vendor partition filesystem module
Vendor_partition_name *string
// Name of the odm partition filesystem module
Odm_partition_name *string
// Name of the recovery partition filesystem module
Recovery_partition_name *string
// The vbmeta partition and its "chained" partitions
Vbmeta_partitions []string
// Name of the userdata partition filesystem module
Userdata_partition_name *string
// Name of the system_dlkm partition filesystem module
System_dlkm_partition_name *string
// Name of the vendor_dlkm partition filesystem module
Vendor_dlkm_partition_name *string
// Name of the odm_dlkm partition filesystem module
Odm_dlkm_partition_name *string
// Name of the ramdisk partition module
Ramdisk_partition_name *string
// Name of the vendor kernel ramdisk partition filesystem module
Vendor_kernel_ramdisk_partition_name *string
// Names of the custom partition filesystem modules
Custom_partitions []string
}
type StageDeviceFilePairProp struct {
// Path to the source fileto be installed. Note that this is the relative path from the
// root of the Android tree, not the relative path from the moduledefinition
Src *string `android:"path"`
// Name of the fileto be installed as
Dst *string
}
type DeviceProperties struct {
// Prebuilt bootloader module that would be copied to PRODUCT_OUT
Bootloader *string
// Name of the android_info module that provides the board specific info.
Android_info *string
// If this is the "main" android_device target for the build, i.e. the one that gets built
// when running a plain `m` command. Currently, this is the autogenerated android_device module
// in soong-only builds, but in the future when we checkin android_device modules, the main
// one will be determined based on the lunch product. TODO: Figure out how to make this
// blueprint:"mutated"and still set it from filesystem_creator
Main_device *bool
// The kernel version in the build. Will be verified against the actual kernel.
// If not provided, will attempt toextract it from the loose kernel or the kernel inside
// the boot image. The version is later used to decide whether or not to enable uffd_gc
// when dexpreopting apps. So setting this doesn't really do anything except enforce that the
// actual kernel version isasspecified here.
Kernel_version *string
// Precompiled sepolicy only with system + system_ext + product. Used for SELinux tests.
Precompiled_sepolicy_without_vendor *string `android:"path"`
// Name of the DTBO partitions
Dtbo_image *string
Dtbo_image_16k *string
// Name of the radio partition
Radio_partition_name *string
Pvmfw PvmfwProperties
Vendor_blobs_license *string `android:"path"`
// For saving those partition filesystems being created which are for gathering filesystem
// infos but not going tocreate images for the device.
InfoPartitionProps PartitionNameProperties
// This is used for fontchain_lint, it will not check emoji if Minimal_font_footprint is true.
Minimal_font_footprint *bool
// Name of the prebuilt tzsw partition.
Tzsw *string
// List of src:dst mapping of files to be installed in the root directory of $PRODUCT_OUT,
// instead of being installed inany partition subdirectories.
Stage_device_files []StageDeviceFilePairProp
// This is used for vendor_module_check, it will checkif VendorOwnerRestrict is true.
Vendor_product_restrict_vendor_files *string
Product_restrict_vendor_files *string
Vendor_exception_paths []string
Vendor_exception_modules []string
// Name of the system partition filesystem module that is generated by soong.
// This is used tocheck the parity between the handwritten system partition and the
// auto-generated system partition. So it must not be included in the PartitionNameProperties.
System_filelist_diff_ref *string
}
type PvmfwProperties struct {
Image *string `android:"path"`
// Name of the pvmfw raw_binary module
Binary_name *string
Avbkey *string `android:"path"`
Partition_size *int64
}
type androidDevice struct {
android.ModuleBase
blueprint.ModuleUsesIncrementalWalkDeps
var numMainAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices")
type partitionDepTagType struct {
blueprint.BaseDependencyTag
}
type superPartitionDepTagType struct {
blueprint.BaseDependencyTag
} type targetFilesMetadataDepTagType struct {
blueprint.BaseDependencyTag
} type fileContextsDepTagType struct {
blueprint.BaseDependencyTag
} type bootloaderDepTagType struct {
blueprint.BaseDependencyTag
} type tzswDepTagType struct {
blueprint.BaseDependencyTag
} type dtboDepTagType struct {
blueprint.BaseDependencyTag
} type radioDepTagType struct {
blueprint.BaseDependencyTag
} type ramdisk16kDepTagType struct {
blueprint.BaseDependencyTag
} type androidInfoDepTagType struct {
blueprint.BaseDependencyTag
}
type pvmfwRawBinaryDepTagType struct {
blueprint.BaseDependencyTag
}
type customPartitionDepTagType struct {
blueprint.BaseDependencyTag
}
type fileListCheckDepTagType struct {
blueprint.BaseDependencyTag
}
var superPartitionDepTag superPartitionDepTagType
var filesystemDepTag partitionDepTagType
var targetFilesMetadataDepTag targetFilesMetadataDepTagType
var fileContextsDepTag fileContextsDepTagType
var bootloaderDepTag bootloaderDepTagType
var tzswDepTag tzswDepTagType
var dtboDepTag dtboDepTagType
var radioDepTag radioDepTagType
var ramdisk16kDepTag ramdisk16kDepTagType
var androidInfoDepTag androidInfoDepTagType
var pvmfwRawBinaryDepTag pvmfwRawBinaryDepTagType
var customPartitionDepTag customPartitionDepTagType
var fileListCheckDepTag fileListCheckDepTagType
func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
addDependencyIfDefined := func(dep *string) { if dep != nil {
ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep))
}
}
if a.partitionProps.Super_partition_name != nil {
ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name)
} if a.deviceProps.InfoPartitionProps.Super_partition_name != nil {
ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.deviceProps.InfoPartitionProps.Super_partition_name)
}
addDependencyIfDefined(a.partitionProps.Boot_partition_name)
addDependencyIfDefined(a.partitionProps.Boot_16k_partition_name)
addDependencyIfDefined(a.partitionProps.Init_boot_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_boot_debug_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_boot_test_harness_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_kernel_boot_partition_name)
addDependencyIfDefined(a.partitionProps.System_partition_name)
addDependencyIfDefined(a.partitionProps.System_ext_partition_name)
addDependencyIfDefined(a.partitionProps.Product_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_partition_name)
addDependencyIfDefined(a.partitionProps.Odm_partition_name)
addDependencyIfDefined(a.partitionProps.Userdata_partition_name)
addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name)
addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name)
addDependencyIfDefined(a.partitionProps.Recovery_partition_name)
addDependencyIfDefined(a.partitionProps.Ramdisk_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_kernel_ramdisk_partition_name) for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions {
ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition)
}
a.addDepsForTargetFilesMetadata(ctx) if a.deviceProps.Bootloader != nil {
ctx.AddDependency(ctx.Module(), bootloaderDepTag, *a.deviceProps.Bootloader)
} if a.deviceProps.Tzsw != nil {
ctx.AddDependency(ctx.Module(), tzswDepTag, *a.deviceProps.Tzsw)
} if a.deviceProps.Dtbo_image != nil {
ctx.AddDependency(ctx.Module(), dtboDepTag, *a.deviceProps.Dtbo_image)
} if a.deviceProps.Dtbo_image_16k != nil {
ctx.AddDependency(ctx.Module(), dtboDepTag, *a.deviceProps.Dtbo_image_16k)
} if a.deviceProps.Radio_partition_name != nil {
ctx.AddDependency(ctx.Module(), radioDepTag, *a.deviceProps.Radio_partition_name)
} if a.deviceProps.Android_info != nil {
ctx.AddDependency(ctx.Module(), androidInfoDepTag, *a.deviceProps.Android_info)
} if a.deviceProps.Pvmfw.Binary_name != nil {
ctx.AddDependency(ctx.Module(), pvmfwRawBinaryDepTag, *a.deviceProps.Pvmfw.Binary_name)
}
// Add system-build.prop even system partition is not building.
ctx.AddDependency(ctx.Module(), filesystemDepTag, "system-build.prop")
// For collecting install module information for products not building system.img or system_ext.img.
addDependencyIfDefined(a.deviceProps.InfoPartitionProps.System_partition_name)
addDependencyIfDefined(a.deviceProps.InfoPartitionProps.System_ext_partition_name)
addDependencyIfDefined(a.deviceProps.InfoPartitionProps.Product_partition_name)
for _, customPartition := range a.partitionProps.Custom_partitions {
ctx.AddDependency(ctx.Module(), customPartitionDepTag, customPartition)
}
if a.deviceProps.System_filelist_diff_ref != nil {
ctx.AddDependency(ctx.Module(), fileListCheckDepTag, *a.deviceProps.System_filelist_diff_ref)
}
func (a *androidDevice) UseGenericConfig() bool {
return false
}
func (a *androidDevice) getAndroidInfoProvider(ctx android.ModuleContext) { if proptools.String(a.deviceProps.Android_info) != "" { mod := ctx.GetDirectDepProxyWithTag(*a.deviceProps.Android_info, androidInfoDepTag) if androidInfo, ok := android.OtherModuleProvider(ctx, mod, android.AndroidInfoProvider); ok {
a.androidInfoTxt = androidInfo.AndroidInfoTxt
a.boardInfoTxt = androidInfo.BoardInfoTxt
} else {
ctx.PropertyErrorf("Android_info", "Must be the android_info module type")
}
}
}
func (a *androidDevice) getCustomPartitionFilesystemInfos(ctx android.ModuleContext) []FilesystemInfo {
var fsInfos []FilesystemInfo for _, customPartition := range a.partitionProps.Custom_partitions {
customPartitionModule := ctx.GetDirectDepProxyWithTag(customPartition, customPartitionDepTag) if info, ok := android.OtherModuleProvider(ctx, customPartitionModule, FilesystemProvider); ok {
fsInfos = append(fsInfos, info)
} else {
ctx.PropertyErrorf("custom_partitions", "custom partition %s does not set FilesystemProvider", customPartition)
}
}
return fsInfos
}
type stageDeviceFilePair struct {
src android.Path
dst string
}
func (a *androidDevice) processStageDeviceFiles(ctx android.ModuleContext) []stageDeviceFilePair {
var ret []stageDeviceFilePair for _, pair := range a.deviceProps.Stage_device_files { if pair.Src == nil || pair.Dst == nil {
ctx.PropertyErrorf("stage_device_files", "src and dst are required for each entry")
} else { if srcPath := android.ExistentPathForSource(ctx, *pair.Src); !srcPath.Valid() {
ctx.PropertyErrorf("stage_device_files", "src %q is not a valid path", *pair.Src)
} elseif filepath.Base(*pair.Dst) != *pair.Dst { // If the destination path contains a directory, it's an error.
ctx.PropertyErrorf("stage_device_files", "dst %q must be a filename, not a path with directories", *pair.Dst)
} else {
ret = append(ret, stageDeviceFilePair{srcPath.Path(), *pair.Dst})
}
}
}
return ret
}
func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { if proptools.Bool(a.deviceProps.Main_device) {
numMainAndroidDevices := ctx.Config().Once(numMainAndroidDevicesOnceKey, func() interface{} {
return &atomic.Int32{}
}).(*atomic.Int32)
total := numMainAndroidDevices.Add(1) if total > 1 {
// There should only be 1 main android_device module. That one will be
// made the default thing to build in soong-only builds.
ctx.ModuleErrorf("There cannot be more than 1 main android_device module")
}
} if a.partitionProps.Init_boot_partition_name != nil && a.partitionProps.Ramdisk_partition_name != nil {
ctx.ModuleErrorf("Init_boot and Ramdisk cannot both be non-empty.")
}
// Normal allInstalledModules which only include modules in those partitions which will be create images for this product.
allInstalledModules := a.allInstalledModules(ctx, false)
a.customPartitionFilesystemInfos = a.getCustomPartitionFilesystemInfos(ctx)
a.getAndroidInfoProvider(ctx)
a.apkCertsInfo = a.buildApkCertsInfo(ctx)
a.kernelVersion, a.kernelConfig = a.extractKernelVersionAndConfigs(ctx)
a.miscInfo = a.addMiscInfo(ctx)
a.stageDeviceFiles = a.processStageDeviceFiles(ctx)
// Use the allInstalledModules which included modules which is installed under system or sysem_ext.
// Because target file's apexkeys.txt collect those apex under system or system_ext even they don't build these 2 images.
a.buildTargetFilesZip(ctx, a.allInstalledModules(ctx, true))
a.proguardZips = java.BuildProguardZips(ctx, allInstalledModules)
a.buildSymbolsZip(ctx, allInstalledModules)
a.buildUpdatePackage(ctx)
a.buildWithLicenseZip(ctx)
if a.partitionProps.Boot_partition_name != nil {
bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag)
bootImgInfo, ok := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) if !ok {
ctx.PropertyErrorf("boot_partition_name", "Expected a BootimgInfoProvider")
}
builder.Command().Textf("mkdir -p %s/BOOT && echo %s > %s/BOOT/cmdline", targetFilesDir, proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) if bootImgInfo.Dtb != nil {
builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/BOOT/dtb", targetFilesDir)
} if bootImgInfo.Kernel != nil && !bootImgInfo.IsPrebuilt {
builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir)
// Even though kernel is not used to build vendor_boot, copy the kernel to VENDOR_BOOT to match the behavior of make packaging.
builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/VENDOR_BOOT/kernel", targetFilesDir)
} if bootImgInfo.Bootconfig != nil {
builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir)
}
}
builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String()) if a.deviceProps.Bootloader != nil {
bootloader := ctx.GetDirectDepProxyWithTag(*a.deviceProps.Bootloader, bootloaderDepTag) if vbmetaPartitionInfo := android.OtherModuleProviderOrDefault(ctx, bootloader, vbmetaPartitionsProvider); len(vbmetaPartitionInfo) > 0 {
// Bootloader with AB ota partitions are copied to RADIO/ subdirectory.
// This matches the make implementation.
files := android.OutputFilesForModule(ctx, bootloader, "")
files = append(files, android.OutputFilesForModule(ctx, bootloader, "bootloader_partitions")...)
builder.Command().
Textf("mkdir -p %s/RADIO && cp -t %s/RADIO ", targetFilesDir, targetFilesDir).
Inputs(files)
} else {
bootloaderFile := android.OutputFilesForModule(ctx, bootloader, "") if len(bootloaderFile) != 1 {
ctx.ModuleErrorf("Expected bootloader to be a single file")
}
builder.Command().Textf("cp ").Input(bootloaderFile[0]).Textf(" %s/IMAGES/bootloader", targetFilesDir.String())
}
} if a.deviceProps.Tzsw != nil {
tzswImg := ctx.GetDirectDepProxyWithTag(*a.deviceProps.Tzsw, tzswDepTag)
files := android.OutputFilesForModule(ctx, tzswImg, "bootloader_partitions")
builder.Command().
Textf("mkdir -p %s/RADIO && cp -t %s/RADIO ", targetFilesDir, targetFilesDir).
Inputs(files)
}
if a.partitionProps.Boot_16k_partition_name != nil {
bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_16k_partition_name), filesystemDepTag) if bootImgInfo := android.OtherModuleProviderOrDefault(ctx, bootImg, BootimgInfoProvider); bootImgInfo.Output != nil {
// The primary boot.img is generated by add_img_to_target_files from misc_info.txt,
// but boot_16k.img is copied from the installation/intermediates directory.
builder.Command().Text("cp").Input(bootImgInfo.Output).Textf(" %s/IMAGES/", targetFilesDir)
// Make packaging copies the 16k kernel to PREBUILT_IMAGES. Port this behavior here.
builder.Command().
Textf("mkdir -p %s/PREBUILT_IMAGES && cp", targetFilesDir). Input(bootImgInfo.Kernel).Textf(" %s/PREBUILT_IMAGES/kernel_16k", targetFilesDir)
}
} if a.deviceProps.Radio_partition_name != nil {
radio := ctx.GetDirectDepProxyWithTag(*a.deviceProps.Radio_partition_name, radioDepTag)
files := android.OutputFilesForModule(ctx, radio, "")
builder.Command().
Textf("mkdir -p %s/RADIO && cp -t %s/RADIO ", targetFilesDir, targetFilesDir).
Inputs(files)
} if a.deviceProps.Pvmfw.Image != nil {
pvmfwImg := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Pvmfw.Image))
builder.Command().Textf("mkdir -p %s/PREBUILT_IMAGES/ && cp", targetFilesDir.String()).Input(pvmfwImg).Textf(" %s/PREBUILT_IMAGES/pvmfw.img", targetFilesDir.String())
} if a.deviceProps.Pvmfw.Binary_name != nil {
pvmfwBin := ctx.GetDirectDepProxyWithTag(proptools.String(a.deviceProps.Pvmfw.Binary_name), pvmfwRawBinaryDepTag) file := android.OutputFileForModule(ctx, pvmfwBin, "")
builder.Command().Textf("mkdir -p %s/PVMFW/ && cp", targetFilesDir.String()).Input(file).Textf(" %s/PVMFW/pvmfw_bin", targetFilesDir.String())
} if a.deviceProps.Pvmfw.Avbkey != nil {
pvbmfwAvbkey := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Pvmfw.Avbkey))
builder.Command().Textf("mkdir -p %s/PREBUILT_IMAGES/ && cp", targetFilesDir.String()).Input(pvbmfwAvbkey).Textf(" %s/PREBUILT_IMAGES/pvmfw_embedded.avbpubkey", targetFilesDir.String())
}
// Force copy build.prop for system partition even there's no system partition for this product to reflect the logic in make. if _, exist := a.getFsInfos(ctx)["system"]; !exist {
systemBuildProp := ctx.GetDirectDepProxyWithTag("system-build.prop", filesystemDepTag) if !systemBuildProp.IsNil() { file := android.OutputFileForModule(ctx, systemBuildProp, "")
builder.Command().Textf("mkdir -p %s/SYSTEM/ && cp", targetFilesDir.String()).Input(file).Textf(" %s/SYSTEM/build.prop", targetFilesDir.String())
}
}
func writeFileWithNewLines(ctx android.ModuleContext, path android.WritablePath, contents []string) {
builder := &strings.Builder{} for i, content := range contents {
builder.WriteString(content)
// Do not write a new lineat the end if i < len(contents)-1 {
builder.WriteString("\n")
}
}
android.WriteFileRule(ctx, path, builder.String())
}
// Create a META/ subdirectory
builder.Command().Textf("mkdir -p %s/META", targetFilesDir.String()) if proptools.Bool(a.deviceProps.Ab_ota_updater) {
ctx.VisitDirectDepsProxyWithTag(targetFilesMetadataDepTag, func(child android.ModuleProxy) {
var defFiles android.Paths if info := android.GetOutputFiles(ctx, child); info != nil {
defFiles = info.DefaultOutputFiles
}
builder.Command().Textf("cp").Inputs(defFiles).Textf(" %s/META/", targetFilesDir.String())
})
builder.Command().Textf("cp").Input(android.PathForSource(ctx, "external/zucchini/version_info.h")).Textf(" %s/META/zucchini_config.txt", targetFilesDir.String())
builder.Command().Textf("cp").Input(android.PathForSource(ctx, "system/update_engine/update_engine.conf")).Textf(" %s/META/update_engine_config.txt", targetFilesDir.String())
// erofs_default_compress_hints.txt
fsInfos := a.getFsInfos(ctx) if fsInfos["system"].ErofsCompressHints != nil {
builder.Command().Textf("cp").Input(fsInfos["system"].ErofsCompressHints).Textf(" %s/META/erofs_default_compress_hints.txt", targetFilesDir.String())
} else {
// Use other partitions' ErofsCompressHints if system partition's not exist. for _, partition := range android.SortedKeys(fsInfos) { if fsInfos[partition].ErofsCompressHints != nil {
builder.Command().Textf("cp").Input(fsInfos[partition].ErofsCompressHints).Textf(" %s/META/erofs_default_compress_hints.txt", targetFilesDir.String())
break
}
}
}
// ab_partitions.txt
abPartitionsSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_partitions) if len(abPartitionsSorted) > 0 {
abPartitionsFilePath := android.PathForModuleOut(ctx, "target_files_tmp", "ab_partitions.txt")
writeFileWithNewLines(ctx, abPartitionsFilePath, abPartitionsSorted)
builder.Command().Textf("cp").Input(abPartitionsFilePath).Textf(" %s/META/", targetFilesDir)
}
// otakeys.txt
abOtaKeysSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_keys)
abOtaKeysFilePath := android.PathForModuleOut(ctx, "target_files_tmp", "otakeys.txt")
writeFileWithNewLines(ctx, abOtaKeysFilePath, abOtaKeysSorted)
builder.Command().Textf("cp").Input(abOtaKeysFilePath).Textf(" %s/META/", targetFilesDir)
// postinstall_config.txt
abOtaPostInstallConfigFilePath := android.PathForModuleOut(ctx, "target_files_tmp", "postinstall_config.txt")
writeFileWithNewLines(ctx, abOtaPostInstallConfigFilePath, a.deviceProps.Ab_ota_postinstall_config)
builder.Command().Textf("cp").Input(abOtaPostInstallConfigFilePath).Textf(" %s/META/", targetFilesDir)
// selinuxfc
fileContextsModule := ctx.GetDirectDepProxyWithTag("file_contexts_bin_gen", fileContextsDepTag)
outputFiles := android.GetOutputFiles(ctx, fileContextsModule) if outputFiles == nil || len(outputFiles.DefaultOutputFiles) != 1 {
ctx.ModuleErrorf("Expected exactly 1 output file from file_contexts_bin_gen")
} else {
selinuxFc := outputFiles.DefaultOutputFiles[0] if selinuxFc != nil {
builder.Command().Textf("cp").Input(selinuxFc).Textf(" %s/META/file_contexts.bin", targetFilesDir.String())
}
}
}
// Copy $partition_filesystem_config.txt
fsInfos := a.getFsInfos(ctx) for _, partition := range android.SortedKeys(fsInfos) { if fsInfos[partition].FilesystemConfig == nil { continue
} if android.InList(partition, []string{"userdata", "vendor_kernel_ramdisk"}) { continue
} if android.InList(partition, a.partitionProps.Custom_partitions) { continue
} if partition != "vendor_ramdisk" {
// vendor_ramdisk will be handled separately.
builder.Command().Textf("cp").Input(fsInfos[partition].FilesystemConfig).Textf(" %s/META/%s", targetFilesDir.String(), a.filesystemConfigNameForTargetFiles(partition))
} if partition == "ramdisk" {
// Create an additional copyat boot_filesystem_config.txt
builder.Command().Textf("cp").Input(fsInfos[partition].FilesystemConfig).Textf(" %s/META/boot_filesystem_config.txt", targetFilesDir.String())
} if partition == "system" {
// Create root_filesystem_config from the assembled ROOT/ intermediates directory
a.generateFilesystemConfigForTargetFiles(ctx, builder, a.rootDirForFsConfigTimestamp, targetFilesDir.String(), a.rootDirForFsConfig, "root_filesystem_config.txt")
} if partition == "vendor_ramdisk" {
// Create vendor_boot_filesystem_config from the assembled VENDOR_BOOT/RAMDISK intermediates directory
vendorRamdiskStagingDir := targetFilesDir.String() + "/VENDOR_BOOT/RAMDISK"
vendorRamdiskFsConfigOut := targetFilesDir.String() + "/META/vendor_boot_filesystem_config.txt"
fsConfigBin := ctx.Config().HostToolPath(ctx, "fs_config")
builder.Command().Textf(
`(cd %s; find . -type d | sed 's,$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,,' | %s -C -D %s -R \"\" > %s`,
vendorRamdiskStagingDir, fsConfigBin, vendorRamdiskStagingDir, vendorRamdiskFsConfigOut).
Implicit(fsConfigBin)
}
} if a.partitionProps.Ramdisk_partition_name != nil {
partition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Ramdisk_partition_name, filesystemDepTag) if info, ok := android.OtherModuleProvider(ctx, partition, FilesystemProvider); ok {
builder.Command().Textf("cp").Input(info.FilesystemConfig).Textf(" %s/META/boot_filesystem_config.txt", targetFilesDir.String())
} else {
ctx.ModuleErrorf("Ramdisk partition %s does not set FilesystemProvider\n", partition.Name())
}
}
// Copy ramdisk_node_list if proptools.String(a.deviceProps.Ramdisk_node_list) != "" {
ramdiskNodeList := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Ramdisk_node_list))
builder.Command().Textf("cp").Input(ramdiskNodeList).Textf(" %s/META/", targetFilesDir.String())
}
// Copy releasetools.py if proptools.String(a.deviceProps.Releasetools_extension) != "" {
releaseTools := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Releasetools_extension))
builder.Command().Textf("cp").Input(releaseTools).Textf(" %s/META/", targetFilesDir.String())
}
// apexkeys.txt
var installedApexKeys []android.Path for _, installedModule := range allInstalledModules { if info, ok := android.OtherModuleProvider(ctx, installedModule, ApexKeyPathInfoProvider); ok {
installedApexKeys = append(installedApexKeys, info.ApexKeyPath)
}
}
ctx.VisitDirectDepsProxy(func(m android.ModuleProxy) { if info, ok := android.OtherModuleProvider(ctx, m, ApexKeyPathInfoProvider); ok {
installedApexKeys = append(installedApexKeys, info.ApexKeyPath)
}
})
installedApexKeys = android.SortedUniquePaths(installedApexKeys) // Sortby keypath to match make
builder.Command().Text("cat").Inputs(installedApexKeys).Textf(" >> %s/META/apexkeys.txt", targetFilesDir.String())
// apkcerts.txt
builder.Command().Textf("cp").Input(a.apkCertsInfo).Textf(" %s/META/", targetFilesDir.String())
// Copy fastboot-info.txt if proptools.String(a.deviceProps.FastbootInfo) != "" {
a.fastbootInfoFile = android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.FastbootInfo))
} else {
// Autogenerate fastboot-info.txt if there is no source fastboot-info.txt
a.fastbootInfoFile = a.createFastbootInfo(ctx)
}
builder.Command().Textf("cp").Input(a.fastbootInfoFile).Textf(" %s/META/fastboot-info.txt", targetFilesDir.String())
// kernel_configs.txt and kernel_version.txt if a.kernelConfig != nil {
builder.Command().Textf("cp").Input(a.kernelConfig).Textf(" %s/META/", targetFilesDir.String())
} if a.kernelVersion != nil {
builder.Command().Textf("cp").Input(a.kernelVersion).Textf(" %s/META/", targetFilesDir.String())
}
// misc_info.txt if a.miscInfo != nil {
builder.Command().Textf("cp").Input(a.miscInfo).Textf(" %s/META/", targetFilesDir.String())
}
// Pack dynamic_partitions_info.txt to target-file.
superPartitionName := a.partitionProps.Super_partition_name if superPartitionName == nil {
// Even if a super partition isn't actually built, its information needs to be included in misc_info.txt if dynamic partitioning is enabled. This is for its later use with merge_target_files alongside other targets.
superPartitionName = a.deviceProps.InfoPartitionProps.Super_partition_name
} if superPartitionName != nil {
superPartition := ctx.GetDirectDepProxyWithTag(*superPartitionName, superPartitionDepTag) if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
// dynamic_partitions_info.txt
// TODO (b/390192334): Add `building_super_empty_partition=true`
builder.Command().Text("cp").Input(info.DynamicPartitionsInfo).Textf(" %s/META/", targetFilesDir.String())
} else {
ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
}
}
// apex_info.pb, care_map.pb, vbmeta_digest.txt, this should be the last part for generating target files due to the process of creating target file will run the release tool tocreate images base on the file system and configurations under META folder.
a.addImgToTargetFiles(ctx, builder, targetFilesDir.String())
}
var allChainedVbmetaPartitionTypes []string for _, vbmetaPartitionName := range a.partitionProps.Vbmeta_partitions {
img := ctx.GetDirectDepProxyWithTag(vbmetaPartitionName, filesystemDepTag) if provider, ok := android.OtherModuleProvider(ctx, img, vbmetaPartitionProvider); ok {
builder.Command().Text("cat").Input(provider.PropFileForMiscInfo).Textf(" >> %s", miscInfo) if provider.FilesystemPartitionType != "" { // the top-level vbmeta.img
allChainedVbmetaPartitionTypes = append(allChainedVbmetaPartitionTypes, provider.FilesystemPartitionType)
}
} else {
ctx.ModuleErrorf("vbmeta dep %s does not set vbmetaPartitionProvider\n", vbmetaPartitionName)
}
}
// Determine the custom vbmeta partitions by removing system and vendor
customVbmetaPartitionTypes := android.RemoveListFromList(allChainedVbmetaPartitionTypes, []string{"system", "vendor"})
builder.Command().Textf("echo avb_custom_vbmeta_images_partition_list=%s >> %s",
strings.Join(android.SortedUniqueStrings(customVbmetaPartitionTypes), " "),
miscInfo,
)
func (a *androidDevice) buildUpdatePackage(ctx android.ModuleContext) {
var exclusions []string
fsInfos := a.getFsInfos(ctx)
// Exclude the partitions that are not supported by flashall for _, partition := range android.SortedKeys(fsInfos) { if fsInfos[partition].NoFlashall {
exclusions = append(exclusions, fmt.Sprintf("IMAGES/%s.img", partition))
exclusions = append(exclusions, fmt.Sprintf("IMAGES/%s.map", partition))
}
}
func (a *androidDevice) buildWithLicenseZip(ctx android.ModuleContext) {
name := "" if ctx.Config().HasDeviceProduct() { if ctx.Config().BuildType() == "debug" {
name = ctx.Config().DeviceProduct() + "_debug-"
} else {
name = ctx.Config().DeviceProduct() + "-"
}
}
a.withLicenseDistName = name + "flashable-FILE_NAME_TAG_PLACEHOLDER-with-license.sh"
name += "flashable-with-license"
withLicense := android.PathForModuleOut(ctx, "with-license", name+".sh")
a.withLicenseFile = withLicense if proptools.String(a.deviceProps.Vendor_blobs_license) == "" {
android.ErrorRule(ctx, withLicense, "with-license requires VENDOR_BLOBS_LICENSE to be set.")
return
}
// Filenames for the partition specific fs_config files.
// Hardcode the ramdisk files to their boot image prefix
func (a *androidDevice) filesystemConfigNameForTargetFiles(partition string) string {
name := partition + "_filesystem_config.txt" if partition == "system" {
name = "filesystem_config.txt"
} elseif partition == "ramdisk" {
name = "init_boot_filesystem_config.txt"
}
return name
}
func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo {
fsMod := ctx.GetDirectDepProxyWithTag(depName, filesystemDepTag)
fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider) if !ok {
ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName)
}
return fsInfo
}
func (a *androidDevice) setVbmetaPhonyTargets(ctx android.ModuleContext) { if !proptools.Bool(a.deviceProps.Main_device) {
return
}
if !ctx.Config().KatiEnabled() { for _, vbmetaPartitionName := range a.partitionProps.Vbmeta_partitions {
img := ctx.GetDirectDepProxyWithTag(vbmetaPartitionName, filesystemDepTag) if provider, ok := android.OtherModuleProvider(ctx, img, vbmetaPartitionProvider); ok {
// make generates `vbmetasystemimage` phony target instead of `vbmeta_systemimage` phony target.
partitionName := strings.ReplaceAll(provider.Name, "_", "")
ctx.Phony(fmt.Sprintf("%simage", partitionName), provider.Output)
}
}
}
}