diff options
Diffstat (limited to 'filesystem/filesystem.go')
-rw-r--r-- | filesystem/filesystem.go | 175 |
1 files changed, 127 insertions, 48 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index d5188d7c2..846e2e5e4 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -375,6 +375,20 @@ func (fs fsType) IsUnknown() bool { return fs == unknown } +// Type string that build_image.py accepts. +func (t fsType) String() string { + switch t { + // TODO(372522486): add more types like f2fs, erofs, etc. + case ext4Type: + return "ext4" + case erofsType: + return "erofs" + case f2fsType: + return "f2fs" + } + panic(fmt.Errorf("unsupported fs type %d", t)) +} + type InstalledFilesStruct struct { Txt android.Path Json android.Path @@ -438,9 +452,9 @@ type FilesystemInfo struct { Owners []InstalledModuleInfo - UseAvb bool - HasFsverity bool + + PropFileForMiscInfo android.Path } // FullInstallPathInfo contains information about the "full install" paths of all the files @@ -624,9 +638,11 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { var buildImagePropFile android.Path var buildImagePropFileDeps android.Paths var extraRootDirs android.Paths + var propFileForMiscInfo android.Path switch f.fsType(ctx) { case ext4Type, erofsType, f2fsType: buildImagePropFile, buildImagePropFileDeps = f.buildPropFile(ctx) + propFileForMiscInfo = f.buildPropFileForMiscInfo(ctx) output := android.PathForModuleOut(ctx, f.installFileName()) f.buildImageUsingBuildImage(ctx, builder, buildImageParams{rootDir, buildImagePropFile, buildImagePropFileDeps, output}) f.output = output @@ -689,12 +705,12 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { []InstalledFilesStruct{buildInstalledFiles(ctx, partitionNameForInstalledFiles, rootDir, f.output)}, includeFilesInstalledFiles(ctx), ), - ErofsCompressHints: erofsCompressHints, - SelinuxFc: f.selinuxFc, - FilesystemConfig: f.generateFilesystemConfig(ctx, rootDir, rebasedDir), - Owners: f.gatherOwners(specs), - UseAvb: proptools.Bool(f.properties.Use_avb), - HasFsverity: f.properties.Fsverity.Inputs.GetOrDefault(ctx, nil) != nil, + ErofsCompressHints: erofsCompressHints, + SelinuxFc: f.selinuxFc, + FilesystemConfig: f.generateFilesystemConfig(ctx, rootDir, rebasedDir), + Owners: f.gatherOwners(specs), + HasFsverity: f.properties.Fsverity.Inputs.GetOrDefault(ctx, nil) != nil, + PropFileForMiscInfo: propFileForMiscInfo, } android.SetProvider(ctx, FilesystemProvider, fsInfo) @@ -1031,21 +1047,7 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, and deps = append(deps, path) } - // Type string that build_image.py accepts. - fsTypeStr := func(t fsType) string { - switch t { - // TODO(372522486): add more types like f2fs, erofs, etc. - case ext4Type: - return "ext4" - case erofsType: - return "erofs" - case f2fsType: - return "f2fs" - } - panic(fmt.Errorf("unsupported fs type %v", t)) - } - - addStr("fs_type", fsTypeStr(f.fsType(ctx))) + addStr("fs_type", f.fsType(ctx).String()) addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) addStr("use_dynamic_partition_size", "true") addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) @@ -1064,28 +1066,7 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, and addPath("avb_key_path", key) } addStr("partition_name", f.partitionName()) - avb_add_hashtree_footer_args := "" - if !proptools.BoolDefault(f.properties.Use_fec, true) { - avb_add_hashtree_footer_args += " --do_not_generate_fec" - } - hashAlgorithm := proptools.StringDefault(f.properties.Avb_hash_algorithm, "sha256") - avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm - if f.properties.Rollback_index != nil { - rollbackIndex := proptools.Int(f.properties.Rollback_index) - if rollbackIndex < 0 { - ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") - } - avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) - } - avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.os_version:%s", f.partitionName(), ctx.Config().PlatformVersionLastStable()) - // We're not going to add BuildFingerPrintFile as a dep. If it changed, it's likely because - // the build number changed, and we don't want to trigger rebuilds solely based on the build - // number. - avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.fingerprint:{CONTENTS_OF:%s}", f.partitionName(), ctx.Config().BuildFingerprintFile(ctx)) - if f.properties.Security_patch != nil && proptools.String(f.properties.Security_patch) != "" { - avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.security_patch:%s", f.partitionName(), proptools.String(f.properties.Security_patch)) - } - addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) + addStr("avb_add_hashtree_footer_args", f.getAvbAddHashtreeFooterArgs(ctx)) } if f.properties.File_contexts != nil && f.properties.Precompiled_file_contexts != nil { @@ -1134,7 +1115,7 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, and addStr("f2fs_sparse_flag", "-S") } } - f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst)) + f.checkFsTypePropertyError(ctx, fst, fst.String()) if f.properties.Partition_size != nil { addStr("partition_size", strconv.FormatInt(*f.properties.Partition_size, 10)) @@ -1165,6 +1146,104 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, and return propFile, deps } +func (f *filesystem) 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("use_dynamic_partition_size", "true") + addStr("ext_mkuserimg", "mkuserimg_mke2fs") + + addStr("building_"+f.partitionName()+"_image", "true") + addStr(f.partitionName()+"_fs_type", f.fsType(ctx).String()) + + if proptools.Bool(f.properties.Use_avb) { + addStr("avb_"+f.partitionName()+"_hashtree_enable", "true") + if f.properties.Avb_private_key != nil { + key := android.PathForModuleSrc(ctx, *f.properties.Avb_private_key) + addStr("avb_"+f.partitionName()+"_key_path", key.String()) + } + addStr("avb_"+f.partitionName()+"_add_hashtree_footer_args", strings.TrimSpace(f.getAvbAddHashtreeFooterArgs(ctx))) + } + + if f.selinuxFc != nil { + addStr(f.partitionName()+"_selinux_fc", f.selinuxFc.String()) + } + + // Disable sparse only when partition size is not defined. disable_sparse has the same + // effect as <partition name>_disable_sparse. + if f.properties.Partition_size == nil { + addStr(f.partitionName()+"_disable_sparse", "true") + } + + fst := f.fsType(ctx) + switch fst { + case erofsType: + // Add erofs properties + addStr("erofs_default_compressor", proptools.StringDefault(f.properties.Erofs.Compressor, "lz4hc,9")) + if proptools.BoolDefault(f.properties.Erofs.Sparse, true) { + // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b + addStr("erofs_sparse_flag", "-s") + } + case f2fsType: + if proptools.BoolDefault(f.properties.F2fs.Sparse, true) { + // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2294;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b;bpv=1;bpt=0 + addStr("f2fs_sparse_flag", "-S") + } + } + + if proptools.BoolDefault(f.properties.Support_casefolding, false) { + addStr("needs_casefold", "1") + } + + if proptools.BoolDefault(f.properties.Support_project_quota, false) { + addStr("needs_projid", "1") + } + + if proptools.BoolDefault(f.properties.Enable_compression, false) { + addStr("needs_compress", "1") + } + + sort.Strings(lines) + + propFilePreProcessing := android.PathForModuleOut(ctx, "prop_misc_info_pre_processing") + android.WriteFileRule(ctx, propFilePreProcessing, strings.Join(lines, "\n")) + propFile := android.PathForModuleOut(ctx, "prop_file_for_misc_info") + ctx.Build(pctx, android.BuildParams{ + Rule: textFileProcessorRule, + Input: propFilePreProcessing, + Output: propFile, + }) + + return propFile +} + +func (f *filesystem) getAvbAddHashtreeFooterArgs(ctx android.ModuleContext) string { + avb_add_hashtree_footer_args := "" + if !proptools.BoolDefault(f.properties.Use_fec, true) { + avb_add_hashtree_footer_args += " --do_not_generate_fec" + } + hashAlgorithm := proptools.StringDefault(f.properties.Avb_hash_algorithm, "sha256") + avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm + if f.properties.Rollback_index != nil { + rollbackIndex := proptools.Int(f.properties.Rollback_index) + if rollbackIndex < 0 { + ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") + } + avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) + } + avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.os_version:%s", f.partitionName(), ctx.Config().PlatformVersionLastStable()) + // We're not going to add BuildFingerPrintFile as a dep. If it changed, it's likely because + // the build number changed, and we don't want to trigger rebuilds solely based on the build + // number. + avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.fingerprint:{CONTENTS_OF:%s}", f.partitionName(), ctx.Config().BuildFingerprintFile(ctx)) + if f.properties.Security_patch != nil && proptools.String(f.properties.Security_patch) != "" { + avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.security_patch:%s", f.partitionName(), proptools.String(f.properties.Security_patch)) + } + return avb_add_hashtree_footer_args +} + // This method checks if there is any property set for the fstype(s) other than // the current fstype. func (f *filesystem) checkFsTypePropertyError(ctx android.ModuleContext, t fsType, fs string) { @@ -1469,7 +1548,7 @@ func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]androi deps := f.gatherFilteredPackagingSpecs(ctx) ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { - if !android.OtherModuleProviderOrDefault(ctx, child, android.CommonModuleInfoProvider).Enabled { + if !android.OtherModulePointerProviderOrDefault(ctx, child, android.CommonModuleInfoProvider).Enabled { return false } for _, ps := range android.OtherModuleProviderOrDefault( @@ -1490,7 +1569,7 @@ func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]androi var requireModules []android.ModuleProxy ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { - if !android.OtherModuleProviderOrDefault(ctx, child, android.CommonModuleInfoProvider).Enabled { + if !android.OtherModulePointerProviderOrDefault(ctx, child, android.CommonModuleInfoProvider).Enabled { return false } _, parentInPackage := modulesInPackageByModule[parent] |