summaryrefslogtreecommitdiff
path: root/filesystem/filesystem.go
diff options
context:
space:
mode:
Diffstat (limited to 'filesystem/filesystem.go')
-rw-r--r--filesystem/filesystem.go461
1 files changed, 386 insertions, 75 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 97421c8a3..b9cb0769a 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -25,6 +25,8 @@ import (
"android/soong/android"
"android/soong/cc"
+ "android/soong/java"
+ "android/soong/linkerconfig"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -32,6 +34,7 @@ import (
func init() {
registerBuildComponents(android.InitRegistrationContext)
+ registerMutators(android.InitRegistrationContext)
}
func registerBuildComponents(ctx android.RegistrationContext) {
@@ -44,6 +47,18 @@ func registerBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
}
+func registerMutators(ctx android.RegistrationContext) {
+ ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("add_autogenerated_rro_deps", addAutogeneratedRroDeps)
+ })
+}
+
+// Remember to add referenced files to implicits!
+var textFileProcessorRule = pctx.AndroidStaticRule("text_file_processing", blueprint.RuleParams{
+ Command: "build/soong/scripts/text_file_processor.py $in $out",
+ CommandDeps: []string{"build/soong/scripts/text_file_processor.py"},
+})
+
type filesystem struct {
android.ModuleBase
android.PackagingBase
@@ -51,21 +66,33 @@ type filesystem struct {
properties FilesystemProperties
- // Function that builds extra files under the root directory and returns the files
- buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
-
- // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
- filterPackagingSpec func(spec android.PackagingSpec) bool
-
- output android.OutputPath
+ output android.Path
installDir android.InstallPath
- fileListFile android.OutputPath
+ fileListFile android.Path
// Keeps the entries installed from this filesystem
entries []string
+
+ filesystemBuilder filesystemBuilder
}
+type filesystemBuilder interface {
+ BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath)
+ // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
+ FilterPackagingSpec(spec android.PackagingSpec) bool
+ // Function that modifies PackagingSpec in PackagingBase.GatherPackagingSpecs() to customize.
+ // For example, GSI system.img contains system_ext and product artifacts and their
+ // relPathInPackage need to be rebased to system/system_ext and system/system_product.
+ ModifyPackagingSpec(spec *android.PackagingSpec)
+
+ // Function to check if the filesystem should not use `vintf_fragments` property,
+ // but use `vintf_fragment` module type instead
+ ShouldUseVintfFragmentModuleOnly() bool
+}
+
+var _ filesystemBuilder = (*filesystem)(nil)
+
type SymlinkDefinition struct {
Target *string
Name *string
@@ -86,6 +113,9 @@ type FilesystemProperties struct {
// avbtool. Default used by avbtool is sha1.
Avb_hash_algorithm *string
+ // Whether or not to use forward-error-correction codes when signing with AVB. Defaults to true.
+ Use_fec *bool
+
// The index used to prevent rollback of the image. Only used if use_avb is true.
Rollback_index *int64
@@ -100,9 +130,13 @@ type FilesystemProperties struct {
// checks, and will be used in the future for API surface checks.
Partition_type *string
- // file_contexts file to make image. Currently, only ext4 is supported.
+ // file_contexts file to make image. Currently, only ext4 is supported. These file contexts
+ // will be compiled with sefcontext_compile
File_contexts *string `android:"path"`
+ // The selinux file contexts, after having already run them through sefcontext_compile
+ Precompiled_file_contexts *string `android:"path"`
+
// Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
// (root).
Base_dir *string
@@ -146,9 +180,25 @@ type FilesystemProperties struct {
Erofs ErofsProperties
+ F2fs F2fsProperties
+
+ Linker_config LinkerConfigProperties
+
// Determines if the module is auto-generated from Soong or not. If the module is
// auto-generated, its deps are exempted from visibility enforcement.
Is_auto_generated *bool
+
+ // Path to the dev nodes description file. This is only needed for building the ramdisk
+ // partition and should not be explicitly specified.
+ Dev_nodes_description_file *string `android:"path" blueprint:"mutated"`
+
+ // Additional dependencies used for building android products
+ Android_filesystem_deps AndroidFilesystemDeps
+}
+
+type AndroidFilesystemDeps struct {
+ System *string
+ System_ext *string
}
// Additional properties required to generate erofs FS partitions.
@@ -163,6 +213,21 @@ type ErofsProperties struct {
Sparse *bool
}
+// Additional properties required to generate f2fs FS partitions.
+type F2fsProperties struct {
+ Sparse *bool
+}
+
+type LinkerConfigProperties struct {
+
+ // Build a linker.config.pb file
+ Gen_linker_config *bool
+
+ // List of files (in .json format) that will be converted to a linker config file (in .pb format).
+ // The linker config file be installed in the filesystem at /etc/linker.config.pb
+ Linker_config_srcs []string `android:"path"`
+}
+
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
// image. The filesystem images are expected to be mounted in the target device, which means the
// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
@@ -170,7 +235,7 @@ type ErofsProperties struct {
// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
func FilesystemFactory() android.Module {
module := &filesystem{}
- module.filterPackagingSpec = module.filterInstallablePackagingSpec
+ module.filesystemBuilder = module
initFilesystemModule(module, module)
return module
}
@@ -179,8 +244,13 @@ func initFilesystemModule(module android.DefaultableModule, filesystemModule *fi
module.AddProperties(&filesystemModule.properties)
android.InitPackageModule(filesystemModule)
filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true
+ filesystemModule.PackagingBase.AllowHighPriorityDeps = true
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
+
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) {
+ filesystemModule.setDevNodesDescriptionProp()
+ })
}
type depTag struct {
@@ -194,18 +264,40 @@ type depTagWithVisibilityEnforcementBypass struct {
depTag
}
+type interPartitionDepTag struct {
+ blueprint.BaseDependencyTag
+}
+
+var interPartitionDependencyTag = interPartitionDepTag{}
+
var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil)
func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {}
var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{}
+// ramdiskDevNodesDescription is the name of the filegroup module that provides the file that
+// contains the description of dev nodes added to the CPIO archive for the ramdisk partition.
+const ramdiskDevNodesDescription = "ramdisk_node_list"
+
+func (f *filesystem) setDevNodesDescriptionProp() {
+ if proptools.String(f.properties.Partition_name) == "ramdisk" {
+ f.properties.Dev_nodes_description_file = proptools.StringPtr(":" + ramdiskDevNodesDescription)
+ }
+}
+
func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
if proptools.Bool(f.properties.Is_auto_generated) {
f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass)
} else {
f.AddDeps(ctx, dependencyTag)
}
+ if f.properties.Android_filesystem_deps.System != nil {
+ ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System))
+ }
+ if f.properties.Android_filesystem_deps.System_ext != nil {
+ ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System_ext))
+ }
}
type fsType int
@@ -213,6 +305,7 @@ type fsType int
const (
ext4Type fsType = iota
erofsType
+ f2fsType
compressedCpioType
cpioType // uncompressed
unknown
@@ -235,6 +328,8 @@ func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType
return ext4Type
case "erofs":
return erofsType
+ case "f2fs":
+ return f2fsType
case "compressed_cpio":
return compressedCpioType
case "cpio":
@@ -261,21 +356,43 @@ func (f *filesystem) partitionName() string {
return proptools.StringDefault(f.properties.Partition_name, f.Name())
}
-func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool {
+func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool {
// Filesystem module respects the installation semantic. A PackagingSpec from a module with
// IsSkipInstall() is skipped.
+ if ps.SkipInstall() {
+ return false
+ }
if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this.
- return !ps.SkipInstall() && (ps.Partition() == f.PartitionType())
+ pt := f.PartitionType()
+ return ps.Partition() == pt || strings.HasPrefix(ps.Partition(), pt+"/")
+ }
+ return true
+}
+
+func (f *filesystem) ModifyPackagingSpec(ps *android.PackagingSpec) {
+ // Sometimes, android.modulePartition() returns a path with >1 path components.
+ // This makes the partition field of packagingSpecs have multiple components, like
+ // "system/product". Right now, the filesystem module doesn't look at the partition field
+ // when deciding what path to install the file under, only the RelPathInPackage field, so
+ // we move the later path components from partition to relPathInPackage. This should probably
+ // be revisited in the future.
+ prefix := f.PartitionType() + "/"
+ if strings.HasPrefix(ps.Partition(), prefix) {
+ subPartition := strings.TrimPrefix(ps.Partition(), prefix)
+ ps.SetPartition(f.PartitionType())
+ ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage()))
}
- return !ps.SkipInstall()
}
var pctx = android.NewPackageContext("android/soong/filesystem")
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
validatePartitionType(ctx, f)
+ if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() {
+ f.validateVintfFragments(ctx)
+ }
switch f.fsType(ctx) {
- case ext4Type, erofsType:
+ case ext4Type, erofsType, f2fsType:
f.output = f.buildImageUsingBuildImage(ctx)
case compressedCpioType:
f.output = f.buildCpioImage(ctx, true)
@@ -289,20 +406,58 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.InstallFile(f.installDir, f.installFileName(), f.output)
ctx.SetOutputFiles([]android.Path{f.output}, "")
- f.fileListFile = android.PathForModuleOut(ctx, "fileList").OutputPath
- android.WriteFileRule(ctx, f.fileListFile, f.installedFilesList())
+ fileListFile := android.PathForModuleOut(ctx, "fileList")
+ android.WriteFileRule(ctx, fileListFile, f.installedFilesList())
android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{
- FileListFile: f.fileListFile,
+ FileListFile: fileListFile,
})
+ f.fileListFile = fileListFile
if proptools.Bool(f.properties.Unchecked_module) {
ctx.UncheckedModule()
}
}
-func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) {
- partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/"
+func (f *filesystem) validateVintfFragments(ctx android.ModuleContext) {
+ visitedModule := map[string]bool{}
+ packagingSpecs := f.gatherFilteredPackagingSpecs(ctx)
+
+ moduleInFileSystem := func(mod android.Module) bool {
+ for _, ps := range android.OtherModuleProviderOrDefault(
+ ctx, mod, android.InstallFilesProvider).PackagingSpecs {
+ if _, ok := packagingSpecs[ps.RelPathInPackage()]; ok {
+ return true
+ }
+ }
+ return false
+ }
+
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ if visitedModule[child.Name()] {
+ return false
+ }
+ if !moduleInFileSystem(child) {
+ visitedModule[child.Name()] = true
+ return true
+ }
+ if vintfFragments := child.VintfFragments(ctx); vintfFragments != nil {
+ ctx.PropertyErrorf(
+ "vintf_fragments",
+ "Module %s is referenced by soong-defined filesystem %s with property vintf_fragments(%s) in use."+
+ " Use vintf_fragment_modules property instead.",
+ child.Name(),
+ f.BaseModuleName(),
+ strings.Join(vintfFragments, ", "),
+ )
+ }
+ visitedModule[child.Name()] = true
+ return true
+ })
+}
+
+func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) {
+ partitionBaseDir := android.PathForModuleOut(ctx, "root", proptools.String(f.properties.Base_dir)).String() + "/"
relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir)
if inTargetPartition {
@@ -363,25 +518,6 @@ func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *andro
builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
f.appendToEntry(ctx, dst)
}
-
- // create extra files if there's any
- if f.buildExtraFiles != nil {
- rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
- extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles)
- for _, extraFile := range extraFiles {
- rel, err := filepath.Rel(rootForExtraFiles.String(), extraFile.String())
- if err != nil || strings.HasPrefix(rel, "..") {
- ctx.ModuleErrorf("can't make %q relative to %q", extraFile, rootForExtraFiles)
- }
- f.appendToEntry(ctx, rootDir.Join(ctx, rel))
- }
- if len(extraFiles) > 0 {
- builder.Command().BuiltTool("merge_directories").
- Implicits(extraFiles.Paths()).
- Text(rootDir.String()).
- Text(rootForExtraFiles.String())
- }
- }
}
func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string {
@@ -411,7 +547,7 @@ func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *a
builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath)
}
-func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
+func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.Path {
rootDir := android.PathForModuleOut(ctx, "root").OutputPath
rebasedDir := rootDir
if f.properties.Base_dir != nil {
@@ -428,6 +564,7 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi
f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
f.buildEventLogtagsFile(ctx, builder, rebasedDir)
f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
+ f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir)
f.copyFilesToProductOut(ctx, builder, rebasedDir)
// run host_init_verifier
@@ -439,11 +576,21 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi
FlagWithArg("--out_system=", rootDir.String()+"/system")
propFile, toolDeps := f.buildPropFile(ctx)
- output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
- builder.Command().BuiltTool("build_image").
+
+ // Most of the time, if build_image were to call a host tool, it accepts the path to the
+ // host tool in a field in the prop file. However, it doesn't have that option for fec, which
+ // it expects to just be on the PATH. Add fec to the PATH.
+ fec := ctx.Config().HostToolPath(ctx, "fec")
+ pathToolDirs := []string{filepath.Dir(fec.String())}
+
+ output := android.PathForModuleOut(ctx, f.installFileName())
+ builder.Command().
+ Textf("PATH=%s:$PATH", strings.Join(pathToolDirs, ":")).
+ BuiltTool("build_image").
Text(rootDir.String()). // input directory
Input(propFile).
Implicits(toolDeps).
+ Implicit(fec).
Output(output).
Text(rootDir.String()) // directory where to find fs_config_files|dirs
@@ -453,14 +600,14 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi
return output
}
-func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
+func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path {
builder := android.NewRuleBuilder(pctx, ctx)
fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
builder.Command().BuiltTool("sefcontext_compile").
FlagWithOutput("-o ", fcBin).
Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
- return fcBin.OutputPath
+ return fcBin
}
// Calculates avb_salt from entry list (sorted) for deterministic output.
@@ -468,7 +615,7 @@ func (f *filesystem) salt() string {
return sha1sum(f.entries)
}
-func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
+func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, android.Paths) {
var deps android.Paths
var propFileString strings.Builder
addStr := func(name string, value string) {
@@ -490,6 +637,8 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
return "ext4"
case erofsType:
return "erofs"
+ case f2fsType:
+ return "f2fs"
}
panic(fmt.Errorf("unsupported fs type %v", t))
}
@@ -508,10 +657,15 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
addStr("avb_algorithm", algorithm)
- key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
- addPath("avb_key_path", key)
+ if f.properties.Avb_private_key != nil {
+ key := android.PathForModuleSrc(ctx, *f.properties.Avb_private_key)
+ addPath("avb_key_path", key)
+ }
addStr("partition_name", f.partitionName())
- avb_add_hashtree_footer_args := "--do_not_generate_fec"
+ avb_add_hashtree_footer_args := ""
+ if !proptools.BoolDefault(f.properties.Use_fec, true) {
+ avb_add_hashtree_footer_args += " --do_not_generate_fec"
+ }
if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
}
@@ -522,15 +676,22 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
}
avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex)
}
- securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch"
- securityPatchValue := ctx.Config().PlatformSecurityPatch()
- avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
+ avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.os_version:%s", f.partitionName(), ctx.Config().PlatformVersionLastStable())
+ avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.fingerprint:{CONTENTS_OF:%s}", f.partitionName(), ctx.Config().BuildFingerprintFile(ctx))
+ avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.security_patch:%s", f.partitionName(), ctx.Config().PlatformSecurityPatch())
addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
addStr("avb_salt", f.salt())
}
- if proptools.String(f.properties.File_contexts) != "" {
+ if f.properties.File_contexts != nil && f.properties.Precompiled_file_contexts != nil {
+ ctx.ModuleErrorf("file_contexts and precompiled_file_contexts cannot both be set")
+ } else if f.properties.File_contexts != nil {
addPath("selinux_fc", f.buildFileContexts(ctx))
+ } else if f.properties.Precompiled_file_contexts != nil {
+ src := android.PathForModuleSrc(ctx, *f.properties.Precompiled_file_contexts)
+ if src != nil {
+ addPath("selinux_fc", src)
+ }
}
if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
addStr("timestamp", timestamp)
@@ -539,30 +700,68 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
addStr("uuid", uuid)
addStr("hash_seed", uuid)
}
- // Add erofs properties
- if f.fsType(ctx) == erofsType {
- if compressor := f.properties.Erofs.Compressor; compressor != nil {
- addStr("erofs_default_compressor", proptools.String(compressor))
- }
- if compressHints := f.properties.Erofs.Compress_hints; compressHints != nil {
- addPath("erofs_default_compress_hints", android.PathForModuleSrc(ctx, *compressHints))
+
+ // TODO(b/381120092): This should only be added if none of the size-related properties are set,
+ // but currently soong built partitions don't have size properties. Make code:
+ // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2262;drc=39cd33701c9278db0e7e481a090605f428d5b12d
+ // Make uses system_disable_sparse but disable_sparse has the same effect, and we shouldn't need
+ // to qualify it because each partition gets its own property file built.
+ addStr("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 f.properties.Erofs.Compress_hints != nil {
+ src := android.PathForModuleSrc(ctx, *f.properties.Erofs.Compress_hints)
+ addPath("erofs_default_compress_hints", src)
}
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")
}
- } else if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil {
- // Raise an exception if the propfile contains erofs properties, but the fstype is not erofs
- fs := fsTypeStr(f.fsType(ctx))
- ctx.PropertyErrorf("erofs", "erofs is non-empty, but FS type is %s\n. Please delete erofs properties if this partition should use %s\n", fs, fs)
+ 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")
+ }
}
-
- propFile = android.PathForModuleOut(ctx, "prop").OutputPath
- android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
+ f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst))
+
+ propFilePreProcessing := android.PathForModuleOut(ctx, "prop_pre_processing")
+ android.WriteFileRuleVerbatim(ctx, propFilePreProcessing, propFileString.String())
+ propFile := android.PathForModuleOut(ctx, "prop")
+ ctx.Build(pctx, android.BuildParams{
+ Rule: textFileProcessorRule,
+ Input: propFilePreProcessing,
+ Output: propFile,
+ Implicit: ctx.Config().BuildFingerprintFile(ctx),
+ })
return propFile, deps
}
-func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
+// 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) {
+ raiseError := func(otherFsType, currentFsType string) {
+ errMsg := fmt.Sprintf("%s is non-empty, but FS type is %s\n. Please delete %s properties if this partition should use %s\n", otherFsType, currentFsType, otherFsType, currentFsType)
+ ctx.PropertyErrorf(otherFsType, errMsg)
+ }
+
+ if t != erofsType {
+ if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil {
+ raiseError("erofs", fs)
+ }
+ }
+ if t != f2fsType {
+ if f.properties.F2fs.Sparse != nil {
+ raiseError("f2fs", fs)
+ }
+ }
+}
+
+func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.Path {
if proptools.Bool(f.properties.Use_avb) {
ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
"Consider adding this to bootimg module and signing the entire boot image.")
@@ -591,12 +790,16 @@ func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool)
f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
f.buildEventLogtagsFile(ctx, builder, rebasedDir)
f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
+ f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir)
f.copyFilesToProductOut(ctx, builder, rebasedDir)
- output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
+ output := android.PathForModuleOut(ctx, f.installFileName())
cmd := builder.Command().
BuiltTool("mkbootfs").
Text(rootDir.String()) // input directory
+ if nodeList := f.properties.Dev_nodes_description_file; nodeList != nil {
+ cmd.FlagWithInput("-n ", android.PathForModuleSrc(ctx, proptools.String(nodeList)))
+ }
if compressed {
cmd.Text("|").
BuiltTool("lz4").
@@ -626,6 +829,9 @@ var validPartitions = []string{
"vendor_dlkm",
"odm_dlkm",
"system_dlkm",
+ "ramdisk",
+ "vendor_ramdisk",
+ "recovery",
}
func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) {
@@ -682,6 +888,22 @@ func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *a
f.appendToEntry(ctx, eventLogtagsPath)
}
+func (f *filesystem) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
+ if !proptools.Bool(f.properties.Linker_config.Gen_linker_config) {
+ return
+ }
+
+ provideModules, _ := f.getLibsForLinkerConfig(ctx)
+ output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
+ linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linker_config.Linker_config_srcs), provideModules, nil, output)
+
+ f.appendToEntry(ctx, output)
+}
+
+func (f *filesystem) ShouldUseVintfFragmentModuleOnly() bool {
+ return false
+}
+
type partition interface {
PartitionType() string
}
@@ -737,7 +959,7 @@ func (f *filesystem) SignedOutputPath() android.Path {
// Note that "apex" module installs its contents to "apex"(fake partition) as well
// for symbol lookup by imitating "activated" paths.
func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
- specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec)
+ specs := f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec)
return specs
}
@@ -763,13 +985,7 @@ type filesystemDefaults struct {
android.ModuleBase
android.DefaultsModuleBase
- properties filesystemDefaultsProperties
-}
-
-type filesystemDefaultsProperties struct {
- // Identifies which partition this is for //visibility:any_system_image (and others) visibility
- // checks, and will be used in the future for API surface checks.
- Partition_type *string
+ properties FilesystemProperties
}
// android_filesystem_defaults is a default module for android_filesystem and android_system_image
@@ -790,3 +1006,98 @@ var _ partition = (*filesystemDefaults)(nil)
func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
validatePartitionType(ctx, f)
}
+
+// getLibsForLinkerConfig returns
+// 1. A list of libraries installed in this filesystem
+// 2. A list of dep libraries _not_ installed in this filesystem
+//
+// `linkerconfig.BuildLinkerConfig` will convert these two to a linker.config.pb for the filesystem
+// (1) will be added to --provideLibs if they are C libraries with a stable interface (has stubs)
+// (2) will be added to --requireLibs if they are C libraries with a stable interface (has stubs)
+func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]android.Module, []android.Module) {
+ // we need "Module"s for packaging items
+ modulesInPackageByModule := make(map[android.Module]bool)
+ modulesInPackageByName := make(map[string]bool)
+
+ deps := f.gatherFilteredPackagingSpecs(ctx)
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ for _, ps := range android.OtherModuleProviderOrDefault(
+ ctx, child, android.InstallFilesProvider).PackagingSpecs {
+ if _, ok := deps[ps.RelPathInPackage()]; ok && ps.Partition() == f.PartitionType() {
+ modulesInPackageByModule[child] = true
+ modulesInPackageByName[child.Name()] = true
+ return true
+ }
+ }
+ return true
+ })
+
+ provideModules := make([]android.Module, 0, len(modulesInPackageByModule))
+ for mod := range modulesInPackageByModule {
+ provideModules = append(provideModules, mod)
+ }
+
+ var requireModules []android.Module
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ _, parentInPackage := modulesInPackageByModule[parent]
+ _, childInPackageName := modulesInPackageByName[child.Name()]
+
+ // When parent is in the package, and child (or its variant) is not, this can be from an interface.
+ if parentInPackage && !childInPackageName {
+ requireModules = append(requireModules, child)
+ }
+ return true
+ })
+
+ return provideModules, requireModules
+}
+
+// Checks that the given file doesn't exceed the given size, and will also print a warning
+// if it's nearing the maximum size. Equivalent to assert-max-image-size in make:
+// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10
+func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) {
+ if addAvbLater {
+ // The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool.
+ // Logic copied from make:
+ // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6
+ maxSize -= 69632
+ }
+ cmd := builder.Command()
+ cmd.Textf(`file="%s"; maxsize="%d";`+
+ `total=$(stat -c "%%s" "$file" | tr -d '\n');`+
+ `if [ "$total" -gt "$maxsize" ]; then `+
+ ` echo "error: $file too large ($total > $maxsize)";`+
+ ` false;`+
+ `elif [ "$total" -gt $((maxsize - 32768)) ]; then `+
+ ` echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+
+ `fi`,
+ image, maxSize)
+ cmd.Implicit(image)
+}
+
+// addAutogeneratedRroDeps walks the transitive closure of vendor and product partitions.
+// It visits apps installed in system and system_ext partitions, and adds the autogenerated
+// RRO modules to its own deps.
+func addAutogeneratedRroDeps(ctx android.BottomUpMutatorContext) {
+ f, ok := ctx.Module().(*filesystem)
+ if !ok {
+ return
+ }
+ thisPartition := f.PartitionType()
+ if thisPartition != "vendor" && thisPartition != "product" {
+ return
+ }
+ ctx.WalkDeps(func(child, parent android.Module) bool {
+ depTag := ctx.OtherModuleDependencyTag(child)
+ if parent.Name() == f.Name() && depTag != interPartitionDependencyTag {
+ return false // This is a module listed in deps of vendor/product filesystem
+ }
+ if vendorOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "vendor"); ctx.OtherModuleExists(vendorOverlay) && thisPartition == "vendor" {
+ ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, vendorOverlay)
+ }
+ if productOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "product"); ctx.OtherModuleExists(productOverlay) && thisPartition == "product" {
+ ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, productOverlay)
+ }
+ return true
+ })
+}