From 99e7dc152aa61b2013d7a9088c60deecff4da295 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Wed, 19 Mar 2025 20:52:27 +0000 Subject: Handle android_app_set in Soong built apkcerts.txt android_app_set modules contain presigned apks, and uses `extract_apks` to create an entry for each split apk in `LOCAL_APK_CERTS`, which then gets concatenated to apkcerts.txt when built using Make. This logic was previously not handled correctly in the new Soong implementation, causing build errors in partner workspaces. Bug: 396131789 Test: In partner-workspace, built the soong generated apkcerts.txt file Change-Id: I7dd0dcd6c992660d5a7e7d484b5d83dc06e051f3 --- filesystem/android_device.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'filesystem/android_device.go') diff --git a/filesystem/android_device.go b/filesystem/android_device.go index 443e80e67..690b9e1be 100644 --- a/filesystem/android_device.go +++ b/filesystem/android_device.go @@ -1046,6 +1046,7 @@ func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalle } apkCerts := []string{} + var apkCertsFiles android.Paths for _, installedModule := range allInstalledModules { partition := "" if commonInfo, ok := android.OtherModuleProvider(ctx, installedModule, android.CommonModuleInfoProvider); ok { @@ -1054,7 +1055,11 @@ func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalle ctx.ModuleErrorf("%s does not set CommonModuleInfoKey", installedModule.Name()) } if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfoProvider); ok { - apkCerts = append(apkCerts, formatLine(info.Certificate, info.InstallApkName+".apk", partition)) + if info.AppSet { + apkCertsFiles = append(apkCertsFiles, info.ApkCertsFile) + } else { + apkCerts = append(apkCerts, formatLine(info.Certificate, info.InstallApkName+".apk", partition)) + } } else if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfosProvider); ok { for _, certInfo := range info { // Partition information of apk-in-apex is not exported to the legacy Make packaging system. @@ -1075,7 +1080,14 @@ func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalle } } + apkCertsInfoWithoutAppSets := android.PathForModuleOut(ctx, "apkcerts_without_app_sets.txt") + android.WriteFileRuleVerbatim(ctx, apkCertsInfoWithoutAppSets, strings.Join(apkCerts, "\n")+"\n") apkCertsInfo := android.PathForModuleOut(ctx, "apkcerts.txt") - android.WriteFileRuleVerbatim(ctx, apkCertsInfo, strings.Join(apkCerts, "\n")+"\n") + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cat, + Description: "combine apkcerts.txt", + Output: apkCertsInfo, + Inputs: append(apkCertsFiles, apkCertsInfoWithoutAppSets), + }) return apkCertsInfo } -- cgit v1.2.3-59-g8ed1b From 2e1338e23f64c8560110a802bef4e1887419aa4f Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Wed, 19 Mar 2025 23:57:36 +0000 Subject: Add vbmeta partition info to misc_info.txt This CL introduces a PropFileForMiscInfo to vbmeta. This will contain "partition qualified" key-value pairs, and will be written to misc_info.txt Bug: 398036609 Test: Built and diff'd locally Change-Id: I607480d7bd743bd8217c83c72fec13e14a8bc210 --- filesystem/android_device.go | 9 ++++++++ filesystem/vbmeta.go | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) (limited to 'filesystem/android_device.go') diff --git a/filesystem/android_device.go b/filesystem/android_device.go index 443e80e67..02bad0a3c 100644 --- a/filesystem/android_device.go +++ b/filesystem/android_device.go @@ -840,6 +840,15 @@ func (a *androidDevice) addMiscInfo(ctx android.ModuleContext) android.Path { Textf("echo avb_enable=true >> %s", miscInfo). Textf("&& echo avb_building_vbmeta_image=true >> %s", miscInfo). Textf("&& echo avb_avbtool=avbtool >> %s", miscInfo) + 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) + } else { + ctx.ModuleErrorf("vbmeta dep %s does not set vbmetaPartitionProvider\n", vbmetaPartitionName) + } + } + } if a.partitionProps.Boot_partition_name != nil { builder.Command().Textf("echo boot_images=boot.img >> %s", miscInfo) diff --git a/filesystem/vbmeta.go b/filesystem/vbmeta.go index 01b453e25..d59a2aec5 100644 --- a/filesystem/vbmeta.go +++ b/filesystem/vbmeta.go @@ -16,7 +16,10 @@ package filesystem import ( "fmt" + "sort" "strconv" + "strings" + "time" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -124,6 +127,10 @@ type vbmetaPartitionInfo struct { // 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 } var vbmetaPartitionProvider = blueprint.NewProvider[vbmetaPartitionInfo]() @@ -302,6 +309,7 @@ func (v *vbmeta) GenerateAndroidBuildActions(ctx android.ModuleContext) { RollbackIndexLocation: ril, PublicKey: extractedPublicKey, Output: output, + PropFileForMiscInfo: v.buildPropFileForMiscInfo(ctx), }) ctx.SetOutputFiles([]android.Path{output}, "") @@ -310,6 +318,41 @@ func (v *vbmeta) GenerateAndroidBuildActions(ctx android.ModuleContext) { setCommonFilesystemInfo(ctx, v) } +func (v *vbmeta) buildPropFileForMiscInfo(ctx android.ModuleContext) android.Path { + var lines []string + addStr := func(name string, value string) { + lines = append(lines, fmt.Sprintf("%s=%s", name, value)) + } + + addStr(fmt.Sprintf("avb_%s_algorithm", v.partitionName()), proptools.StringDefault(v.properties.Algorithm, "SHA256_RSA4096")) + if v.properties.Private_key != nil { + addStr(fmt.Sprintf("avb_%s_key_path", v.partitionName()), android.PathForModuleSrc(ctx, proptools.String(v.properties.Private_key)).String()) + } + if v.properties.Rollback_index_location != nil { + addStr(fmt.Sprintf("avb_%s_rollback_index_location", v.partitionName()), strconv.FormatInt(*v.properties.Rollback_index_location, 10)) + } + + var partitionDepNames []string + ctx.VisitDirectDepsProxyWithTag(vbmetaPartitionDep, func(child android.ModuleProxy) { + if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok { + partitionDepNames = append(partitionDepNames, info.Name) + } else { + ctx.ModuleErrorf("vbmeta dep %s does not set vbmetaPartitionProvider\n", child) + } + }) + if v.partitionName() != "vbmeta" { // skip for vbmeta to match Make's misc_info.txt + addStr(fmt.Sprintf("avb_%s", v.partitionName()), strings.Join(android.SortedUniqueStrings(partitionDepNames), " ")) + } + + addStr(fmt.Sprintf("avb_%s_args", v.partitionName()), fmt.Sprintf("--padding_size 4096 --rollback_index %s", v.rollbackIndexString(ctx))) + + sort.Strings(lines) + + propFile := android.PathForModuleOut(ctx, "prop_file_for_misc_info") + android.WriteFileRule(ctx, propFile, strings.Join(lines, "\n")) + return propFile +} + // Returns the embedded shell command that prints the rollback index func (v *vbmeta) rollbackIndexCommand(ctx android.ModuleContext) string { if v.properties.Rollback_index != nil { @@ -320,6 +363,17 @@ func (v *vbmeta) rollbackIndexCommand(ctx android.ModuleContext) string { } } +// Similar to rollbackIndexCommand, but guarantees that the rollback index is +// always computed during Soong analysis, even if v.properties.Rollback_index is nil +func (v *vbmeta) rollbackIndexString(ctx android.ModuleContext) string { + if v.properties.Rollback_index != nil { + return fmt.Sprintf("%d", *v.properties.Rollback_index) + } else { + t, _ := time.Parse(time.DateOnly, ctx.Config().PlatformSecurityPatch()) + return fmt.Sprintf("%d", t.Unix()) + } +} + var _ android.AndroidMkProviderInfoProducer = (*vbmeta)(nil) func (v *vbmeta) PrepareAndroidMKProviderInfo(config android.Config) *android.AndroidMkProviderInfo { -- cgit v1.2.3-59-g8ed1b