diff options
-rw-r--r-- | filesystem/filesystem.go | 17 | ||||
-rw-r--r-- | filesystem/system_other.go | 61 |
2 files changed, 74 insertions, 4 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index f8faa496f..e86ebf4fa 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -455,6 +455,14 @@ type FilesystemInfo struct { HasFsverity bool PropFileForMiscInfo android.Path + + // Additional avb and partition size information. + // `system_other` will use this information of `system` dep for misc_info.txt processing. + PartitionSize *int64 + UseAvb bool + AvbAlgorithm string + AvbHashAlgorithm string + AvbKey android.Path } // FullInstallPathInfo contains information about the "full install" paths of all the files @@ -711,6 +719,15 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { Owners: f.gatherOwners(specs), HasFsverity: f.properties.Fsverity.Inputs.GetOrDefault(ctx, nil) != nil, PropFileForMiscInfo: propFileForMiscInfo, + PartitionSize: f.properties.Partition_size, + } + if proptools.Bool(f.properties.Use_avb) { + fsInfo.UseAvb = true + fsInfo.AvbAlgorithm = proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") + fsInfo.AvbHashAlgorithm = proptools.StringDefault(f.properties.Avb_hash_algorithm, "sha256") + if f.properties.Avb_private_key != nil { + fsInfo.AvbKey = android.PathForModuleSrc(ctx, *f.properties.Avb_private_key) + } } android.SetProvider(ctx, FilesystemProvider, fsInfo) diff --git a/filesystem/system_other.go b/filesystem/system_other.go index cbfd78b5b..348c01035 100644 --- a/filesystem/system_other.go +++ b/filesystem/system_other.go @@ -16,8 +16,11 @@ package filesystem import ( "android/soong/android" + "fmt" "path/filepath" + "sort" "strings" + "time" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -172,10 +175,11 @@ func (m *systemOtherImage) GenerateAndroidBuildActions(ctx android.ModuleContext builder.Build("build_system_other_hermetic", "build system other") fsInfo := FilesystemInfo{ - Output: output, - OutputHermetic: outputHermetic, - RootDir: stagingDir, - FilesystemConfig: m.generateFilesystemConfig(ctx, stagingDir, stagingDirTimestamp), + Output: output, + OutputHermetic: outputHermetic, + RootDir: stagingDir, + FilesystemConfig: m.generateFilesystemConfig(ctx, stagingDir, stagingDirTimestamp), + PropFileForMiscInfo: m.buildPropFileForMiscInfo(ctx), } android.SetProvider(ctx, FilesystemProvider, fsInfo) @@ -204,3 +208,52 @@ func (f *systemOtherImage) propFileForHermeticImg(ctx android.ModuleContext, bui Textf(" && echo use_fixed_timestamp=true >> %s", propFilePinnedTimestamp) return propFilePinnedTimestamp } + +func (f *systemOtherImage) 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("building_system_other_image", "true") + + systemImage := ctx.GetDirectDepProxyWithTag(*f.properties.System_image, systemImageDependencyTag) + systemInfo, ok := android.OtherModuleProvider(ctx, systemImage, FilesystemProvider) + if !ok { + ctx.PropertyErrorf("system_image", "Expected system_image module to provide FilesystemProvider") + return nil + } + if systemInfo.PartitionSize == nil { + addStr("system_other_disable_sparse", "true") + } + if systemInfo.UseAvb { + addStr("avb_system_other_hashtree_enable", "true") + addStr("avb_system_other_algorithm", systemInfo.AvbAlgorithm) + footerArgs := fmt.Sprintf("--hash_algorithm %s", systemInfo.AvbHashAlgorithm) + if rollbackIndex, err := f.avbRollbackIndex(ctx); err == nil { + footerArgs += fmt.Sprintf(" --rollback_index %d", rollbackIndex) + } else { + ctx.ModuleErrorf("Could not determine rollback_index %s\n", err) + } + addStr("avb_system_other_add_hashtree_footer_args", footerArgs) + if systemInfo.AvbKey != nil { + addStr("avb_system_other_key_path", systemInfo.AvbKey.String()) + } + } + + sort.Strings(lines) + + propFile := android.PathForModuleOut(ctx, "prop_file") + android.WriteFileRule(ctx, propFile, strings.Join(lines, "\n")) + return propFile +} + +// Use the default: PlatformSecurityPatch +// TODO: Get this value from vbmeta_system +func (f *systemOtherImage) avbRollbackIndex(ctx android.ModuleContext) (int64, error) { + t, err := time.Parse(time.DateOnly, ctx.Config().PlatformSecurityPatch()) + if err != nil { + return -1, err + } + return t.Unix(), err +} |