blob: 38dd0b23607b99a05064a847cfc29bd46e4d33e6 [file] [log] [blame]
Jiyong Park6f0f6882020-11-12 13:14:30 +09001// Copyright (C) 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package filesystem
16
17import (
Jooyung Han65f402b2022-04-21 14:24:04 +090018 "crypto/sha256"
Jiyong Park6f0f6882020-11-12 13:14:30 +090019 "fmt"
Jooyung Han65f402b2022-04-21 14:24:04 +090020 "io"
Inseob Kim14199b02021-02-09 21:18:31 +090021 "path/filepath"
Cole Faust4a2a7c92024-03-12 12:44:40 -070022 "slices"
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +000023 "strconv"
Inseob Kim14199b02021-02-09 21:18:31 +090024 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090025
26 "android/soong/android"
Jooyung Hane6067592023-03-16 13:11:17 +090027 "android/soong/cc"
Spandan Das92631882024-10-28 22:49:38 +000028 "android/soong/linkerconfig"
Jiyong Park65b62242020-11-25 12:44:59 +090029
30 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090031 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090032)
33
34func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090035 registerBuildComponents(android.InitRegistrationContext)
36}
37
38func registerBuildComponents(ctx android.RegistrationContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -070039 ctx.RegisterModuleType("android_filesystem", FilesystemFactory)
Jiyong Parkf46b1af2024-04-05 18:13:33 +090040 ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory)
Jihoon Kang98047cf2024-10-02 17:13:54 +000041 ctx.RegisterModuleType("android_system_image", SystemImageFactory)
Jiyong Parkbc485482022-11-15 22:31:49 +090042 ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090043 ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
Alice Wang000e3a32023-01-03 16:11:20 +000044 ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090045 ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090046}
47
48type filesystem struct {
49 android.ModuleBase
50 android.PackagingBase
Jiyong Parkf46b1af2024-04-05 18:13:33 +090051 android.DefaultableModuleBase
Jiyong Park65c49f52020-11-24 14:23:26 +090052
Jihoon Kang98047cf2024-10-02 17:13:54 +000053 properties FilesystemProperties
Jiyong Park71baa762021-01-18 21:11:03 +090054
Jiyong Park65c49f52020-11-24 14:23:26 +090055 output android.OutputPath
56 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090057
Kiyoung Kim99a954d2024-06-21 14:22:20 +090058 fileListFile android.OutputPath
59
60 // Keeps the entries installed from this filesystem
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090061 entries []string
Kiyoung Kim67118212024-11-07 13:23:44 +090062
63 filesystemBuilder filesystemBuilder
Jiyong Park6f0f6882020-11-12 13:14:30 +090064}
65
Kiyoung Kim67118212024-11-07 13:23:44 +090066type filesystemBuilder interface {
67 BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath)
68 // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
69 FilterPackagingSpec(spec android.PackagingSpec) bool
70}
71
72var _ filesystemBuilder = (*filesystem)(nil)
73
Spandan Das69464c32024-10-25 20:08:06 +000074type SymlinkDefinition struct {
Inseob Kim14199b02021-02-09 21:18:31 +090075 Target *string
76 Name *string
77}
78
Jihoon Kang98047cf2024-10-02 17:13:54 +000079type FilesystemProperties struct {
Jiyong Park71baa762021-01-18 21:11:03 +090080 // When set to true, sign the image with avbtool. Default is false.
81 Use_avb *bool
82
83 // Path to the private key that avbtool will use to sign this filesystem image.
84 // TODO(jiyong): allow apex_key to be specified here
85 Avb_private_key *string `android:"path"`
86
Shikha Panwar01403bb2022-12-22 12:22:57 +000087 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090088 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090089
Shikha Panwar01403bb2022-12-22 12:22:57 +000090 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
91 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +000092 Avb_hash_algorithm *string
93
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +000094 // The index used to prevent rollback of the image. Only used if use_avb is true.
95 Rollback_index *int64
96
Jiyong Parkac4076d2021-03-15 23:21:30 +090097 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
98 Partition_name *string
99
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000100 // Type of the filesystem. Currently, ext4, erofs, cpio, and compressed_cpio are supported. Default
Jiyong Park837cdb22021-02-05 00:17:14 +0900101 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +0900102 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +0900103
Cole Faust9a24d902024-03-18 15:38:12 -0700104 // Identifies which partition this is for //visibility:any_system_image (and others) visibility
105 // checks, and will be used in the future for API surface checks.
106 Partition_type *string
107
Inseob Kimcc8e5362021-02-03 14:05:24 +0900108 // file_contexts file to make image. Currently, only ext4 is supported.
109 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900110
111 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
112 // (root).
113 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +0900114
115 // Directories to be created under root. e.g. /dev, /proc, etc.
Cole Faustd9c6a5b2024-05-21 14:54:00 -0700116 Dirs proptools.Configurable[[]string]
Inseob Kim14199b02021-02-09 21:18:31 +0900117
118 // Symbolic links to be created under root with "ln -sf <target> <name>".
Spandan Das69464c32024-10-25 20:08:06 +0000119 Symlinks []SymlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +0900120
121 // Seconds since unix epoch to override timestamps of file entries
122 Fake_timestamp *string
123
124 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
125 // Otherwise, they'll be set as random which might cause indeterministic build output.
126 Uuid *string
Inseob Kim376d72f2023-11-01 15:40:25 +0900127
128 // Mount point for this image. Default is "/"
129 Mount_point *string
Cole Faust4a2a7c92024-03-12 12:44:40 -0700130
131 // If set to the name of a partition ("system", "vendor", etc), this filesystem module
132 // will also include the contents of the make-built staging directories. If any soong
133 // modules would be installed to the same location as a make module, they will overwrite
134 // the make version.
135 Include_make_built_files string
Inseob Kim53391842024-03-29 17:44:07 +0900136
Inseob Kimb7b84572024-04-30 10:51:47 +0900137 // When set, builds etc/event-log-tags file by merging logtags from all dependencies.
138 // Default is false
139 Build_logtags *bool
140
Justin Yun74f3f302024-05-07 14:32:14 +0900141 // Install aconfig_flags.pb file for the modules installed in this partition.
142 Gen_aconfig_flags_pb *bool
143
Inseob Kim53391842024-03-29 17:44:07 +0900144 Fsverity fsverityProperties
Cole Faust92ccbe22024-10-03 14:38:37 -0700145
146 // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing
147 // it to not be built on checkbuilds. Used for the automatic migration from make to soong
148 // build modules, where we want to emit some not-yet-working filesystems and we don't want them
149 // to be built.
150 Unchecked_module *bool `blueprint:"mutated"`
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000151
152 Erofs ErofsProperties
Jihoon Kang0d545b82024-10-11 00:21:57 +0000153
Spandan Das173256b2024-10-31 19:59:30 +0000154 Linkerconfig LinkerConfigProperties
Spandan Das92631882024-10-28 22:49:38 +0000155
Jihoon Kang0d545b82024-10-11 00:21:57 +0000156 // Determines if the module is auto-generated from Soong or not. If the module is
157 // auto-generated, its deps are exempted from visibility enforcement.
158 Is_auto_generated *bool
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000159}
160
161// Additional properties required to generate erofs FS partitions.
162type ErofsProperties struct {
163 // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9)
164 // Please see external/erofs-utils/README for complete documentation.
165 Compressor *string
166
167 // Used as --compress-hints for mkfs.erofs
168 Compress_hints *string `android:"path"`
169
170 Sparse *bool
Jiyong Park71baa762021-01-18 21:11:03 +0900171}
172
Spandan Das173256b2024-10-31 19:59:30 +0000173type LinkerConfigProperties struct {
174
175 // Build a linker.config.pb file
176 Gen_linker_config *bool
177
178 // List of files (in .json format) that will be converted to a linker config file (in .pb format).
179 // The linker config file be installed in the filesystem at /etc/linker.config.pb
180 Linker_config_srcs []string `android:"path"`
181}
182
Jiyong Park65c49f52020-11-24 14:23:26 +0900183// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
184// image. The filesystem images are expected to be mounted in the target device, which means the
185// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
186// The modules are placed in the filesystem image just like they are installed to the ordinary
187// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Cole Faust92ccbe22024-10-03 14:38:37 -0700188func FilesystemFactory() android.Module {
Jiyong Park6f0f6882020-11-12 13:14:30 +0900189 module := &filesystem{}
Kiyoung Kim67118212024-11-07 13:23:44 +0900190 module.filesystemBuilder = module
Cole Faust2cfe6962024-09-17 11:31:14 -0700191 initFilesystemModule(module, module)
Jiyong Parkfa616132021-04-20 11:36:40 +0900192 return module
193}
194
Cole Faust2cfe6962024-09-17 11:31:14 -0700195func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) {
196 module.AddProperties(&filesystemModule.properties)
197 android.InitPackageModule(filesystemModule)
198 filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true
Jihoon Kang79196c52024-10-30 18:49:47 +0000199 filesystemModule.PackagingBase.AllowHighPriorityDeps = true
Jiyong Park6f0f6882020-11-12 13:14:30 +0900200 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900201 android.InitDefaultableModule(module)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900202}
203
Jihoon Kang0d545b82024-10-11 00:21:57 +0000204type depTag struct {
Jiyong Park12a719c2021-01-07 15:31:24 +0900205 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900206 android.PackagingItemAlwaysDepTag
Jihoon Kang0d545b82024-10-11 00:21:57 +0000207}
208
209var dependencyTag = depTag{}
210
211type depTagWithVisibilityEnforcementBypass struct {
212 depTag
213}
214
215var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil)
216
217func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {}
218
219var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{}
Jiyong Park65b62242020-11-25 12:44:59 +0900220
Jiyong Park6f0f6882020-11-12 13:14:30 +0900221func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000222 if proptools.Bool(f.properties.Is_auto_generated) {
223 f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass)
224 } else {
225 f.AddDeps(ctx, dependencyTag)
226 }
Jiyong Park6f0f6882020-11-12 13:14:30 +0900227}
228
Jiyong Park11a65972021-02-01 21:09:38 +0900229type fsType int
230
231const (
232 ext4Type fsType = iota
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000233 erofsType
Jiyong Park11a65972021-02-01 21:09:38 +0900234 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900235 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900236 unknown
237)
238
Spandan Das7a46f6c2024-10-14 18:41:18 +0000239func (fs fsType) IsUnknown() bool {
240 return fs == unknown
241}
242
Cole Faust92ccbe22024-10-03 14:38:37 -0700243type FilesystemInfo struct {
244 // A text file containing the list of paths installed on the partition.
245 FileListFile android.Path
246}
247
248var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]()
249
Spandan Das7a46f6c2024-10-14 18:41:18 +0000250func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType {
Jiyong Park11a65972021-02-01 21:09:38 +0900251 switch typeStr {
252 case "ext4":
253 return ext4Type
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000254 case "erofs":
255 return erofsType
Jiyong Park11a65972021-02-01 21:09:38 +0900256 case "compressed_cpio":
257 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900258 case "cpio":
259 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900260 default:
Jiyong Park11a65972021-02-01 21:09:38 +0900261 return unknown
262 }
263}
264
Spandan Das7a46f6c2024-10-14 18:41:18 +0000265func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
266 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
267 fsType := GetFsTypeFromString(ctx, typeStr)
268 if fsType == unknown {
269 ctx.PropertyErrorf("type", "%q not supported", typeStr)
270 }
271 return fsType
272}
273
Jiyong Park65c49f52020-11-24 14:23:26 +0900274func (f *filesystem) installFileName() string {
275 return f.BaseModuleName() + ".img"
276}
277
Inseob Kim53391842024-03-29 17:44:07 +0900278func (f *filesystem) partitionName() string {
279 return proptools.StringDefault(f.properties.Partition_name, f.Name())
280}
281
Kiyoung Kim67118212024-11-07 13:23:44 +0900282func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool {
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000283 // Filesystem module respects the installation semantic. A PackagingSpec from a module with
284 // IsSkipInstall() is skipped.
Spandan Das6d056502024-10-21 15:40:32 +0000285 if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this.
286 return !ps.SkipInstall() && (ps.Partition() == f.PartitionType())
287 }
288 return !ps.SkipInstall()
Jiyong Park7e7d4af2024-05-01 12:36:10 +0000289}
290
Jiyong Park6f0f6882020-11-12 13:14:30 +0900291var pctx = android.NewPackageContext("android/soong/filesystem")
292
293func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900294 validatePartitionType(ctx, f)
Jiyong Park11a65972021-02-01 21:09:38 +0900295 switch f.fsType(ctx) {
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000296 case ext4Type, erofsType:
Jiyong Park11a65972021-02-01 21:09:38 +0900297 f.output = f.buildImageUsingBuildImage(ctx)
298 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900299 f.output = f.buildCpioImage(ctx, true)
300 case cpioType:
301 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900302 default:
303 return
304 }
305
306 f.installDir = android.PathForModuleInstall(ctx, "etc")
307 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
mrziwang555d1332024-06-07 11:15:33 -0700308 ctx.SetOutputFiles([]android.Path{f.output}, "")
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900309
310 f.fileListFile = android.PathForModuleOut(ctx, "fileList").OutputPath
311 android.WriteFileRule(ctx, f.fileListFile, f.installedFilesList())
Cole Faust92ccbe22024-10-03 14:38:37 -0700312
313 android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{
314 FileListFile: f.fileListFile,
315 })
316
317 if proptools.Bool(f.properties.Unchecked_module) {
318 ctx.UncheckedModule()
319 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900320}
321
322func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) {
323 partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/"
324
325 relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir)
326 if inTargetPartition {
327 f.entries = append(f.entries, relPath)
328 }
329}
330
331func (f *filesystem) installedFilesList() string {
332 installedFilePaths := android.FirstUniqueStrings(f.entries)
333 slices.Sort(installedFilePaths)
334
335 return strings.Join(installedFilePaths, "\n")
Jiyong Park11a65972021-02-01 21:09:38 +0900336}
337
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900338func validatePartitionType(ctx android.ModuleContext, p partition) {
339 if !android.InList(p.PartitionType(), validPartitions) {
340 ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType())
341 }
342
343 ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) {
344 if fdm, ok := m.(*filesystemDefaults); ok {
345 if p.PartitionType() != fdm.PartitionType() {
346 ctx.PropertyErrorf("partition_type",
347 "%s doesn't match with the partition type %s of the filesystem default module %s",
348 p.PartitionType(), fdm.PartitionType(), m.Name())
349 }
350 }
351 })
352}
353
Cole Faust3b806d32024-03-11 15:15:03 -0700354// Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files
355// already in `rootDir`.
356func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) {
Inseob Kim14199b02021-02-09 21:18:31 +0900357 // create dirs and symlinks
Cole Faustd9c6a5b2024-05-21 14:54:00 -0700358 for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) {
Inseob Kim14199b02021-02-09 21:18:31 +0900359 // OutputPath.Join verifies dir
360 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
361 }
362
363 for _, symlink := range f.properties.Symlinks {
364 name := strings.TrimSpace(proptools.String(symlink.Name))
365 target := strings.TrimSpace(proptools.String(symlink.Target))
366
367 if name == "" {
368 ctx.PropertyErrorf("symlinks", "Name can't be empty")
369 continue
370 }
371
372 if target == "" {
373 ctx.PropertyErrorf("symlinks", "Target can't be empty")
374 continue
375 }
376
377 // OutputPath.Join verifies name. don't need to verify target.
378 dst := rootDir.Join(ctx, name)
Cole Faust3b806d32024-03-11 15:15:03 -0700379 builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
Inseob Kim14199b02021-02-09 21:18:31 +0900380 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
381 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900382 f.appendToEntry(ctx, dst)
Inseob Kim14199b02021-02-09 21:18:31 +0900383 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900384}
385
Inseob Kim33f95a92024-07-11 15:44:49 +0900386func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string {
387 rootDirSpecs := make(map[string]android.PackagingSpec)
388 rebasedDirSpecs := make(map[string]android.PackagingSpec)
389
390 for rel, spec := range specs {
391 if spec.Partition() == "root" {
392 rootDirSpecs[rel] = spec
393 } else {
394 rebasedDirSpecs[rel] = spec
395 }
396 }
397
398 dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec)
399 dirsToSpecs[rootDir] = rootDirSpecs
400 dirsToSpecs[rebasedDir] = rebasedDirSpecs
401
402 return f.CopySpecsToDirs(ctx, builder, dirsToSpecs)
403}
404
Justin Yun34baa2e2024-08-30 21:11:33 +0900405func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
Justin Yun2cc42502024-09-11 14:10:20 +0900406 if f.Name() != ctx.Config().SoongDefinedSystemImage() {
Justin Yun34baa2e2024-08-30 21:11:33 +0900407 return
408 }
409 installPath := android.PathForModuleInPartitionInstall(ctx, f.partitionName())
410 builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath)
411}
412
Jiyong Park11a65972021-02-01 21:09:38 +0900413func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Jiyong Park6f0f6882020-11-12 13:14:30 +0900414 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700415 rebasedDir := rootDir
416 if f.properties.Base_dir != nil {
417 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
418 }
419 builder := android.NewRuleBuilder(pctx, ctx)
420 // Wipe the root dir to get rid of leftover files from prior builds
421 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900422 specs := f.gatherFilteredPackagingSpecs(ctx)
Inseob Kim33f95a92024-07-11 15:44:49 +0900423 f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir)
Cole Faust3b806d32024-03-11 15:15:03 -0700424
425 f.buildNonDepsFiles(ctx, builder, rootDir)
Cole Faust4a2a7c92024-03-12 12:44:40 -0700426 f.addMakeBuiltFiles(ctx, builder, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900427 f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
Inseob Kimb7b84572024-04-30 10:51:47 +0900428 f.buildEventLogtagsFile(ctx, builder, rebasedDir)
Justin Yun74f3f302024-05-07 14:32:14 +0900429 f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
Kiyoung Kim67118212024-11-07 13:23:44 +0900430 f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir)
Justin Yun34baa2e2024-08-30 21:11:33 +0900431 f.copyFilesToProductOut(ctx, builder, rebasedDir)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900432
Nikita Ioffe519015f2022-12-23 15:36:29 +0000433 // run host_init_verifier
434 // Ideally we should have a concept of pluggable linters that verify the generated image.
435 // While such concept is not implement this will do.
436 // TODO(b/263574231): substitute with pluggable linter.
437 builder.Command().
438 BuiltTool("host_init_verifier").
439 FlagWithArg("--out_system=", rootDir.String()+"/system")
440
Jiyong Park72678312021-01-18 17:29:49 +0900441 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900442 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800443 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900444 Text(rootDir.String()). // input directory
445 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900446 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900447 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900448 Text(rootDir.String()) // directory where to find fs_config_files|dirs
449
450 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800451 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900452
Jiyong Park11a65972021-02-01 21:09:38 +0900453 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900454}
455
Inseob Kimcc8e5362021-02-03 14:05:24 +0900456func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
457 builder := android.NewRuleBuilder(pctx, ctx)
458 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
459 builder.Command().BuiltTool("sefcontext_compile").
460 FlagWithOutput("-o ", fcBin).
461 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
462 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
463 return fcBin.OutputPath
464}
465
Jooyung Han65f402b2022-04-21 14:24:04 +0900466// Calculates avb_salt from entry list (sorted) for deterministic output.
467func (f *filesystem) salt() string {
468 return sha1sum(f.entries)
469}
470
Jiyong Park72678312021-01-18 17:29:49 +0900471func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
Jiyong Park72678312021-01-18 17:29:49 +0900472 var deps android.Paths
Cole Faustcec230a2024-03-07 15:51:12 -0800473 var propFileString strings.Builder
Jiyong Park72678312021-01-18 17:29:49 +0900474 addStr := func(name string, value string) {
Cole Faustcec230a2024-03-07 15:51:12 -0800475 propFileString.WriteString(name)
476 propFileString.WriteRune('=')
477 propFileString.WriteString(value)
478 propFileString.WriteRune('\n')
Jiyong Park72678312021-01-18 17:29:49 +0900479 }
480 addPath := func(name string, path android.Path) {
Cole Faustcec230a2024-03-07 15:51:12 -0800481 addStr(name, path.String())
Jiyong Park72678312021-01-18 17:29:49 +0900482 deps = append(deps, path)
483 }
484
Jiyong Park11a65972021-02-01 21:09:38 +0900485 // Type string that build_image.py accepts.
486 fsTypeStr := func(t fsType) string {
487 switch t {
Spandan Das94668822024-10-09 20:51:33 +0000488 // TODO(372522486): add more types like f2fs, erofs, etc.
Jiyong Park11a65972021-02-01 21:09:38 +0900489 case ext4Type:
490 return "ext4"
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000491 case erofsType:
492 return "erofs"
Jiyong Park11a65972021-02-01 21:09:38 +0900493 }
494 panic(fmt.Errorf("unsupported fs type %v", t))
495 }
496
497 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim376d72f2023-11-01 15:40:25 +0900498 addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
Jiyong Park72678312021-01-18 17:29:49 +0900499 addStr("use_dynamic_partition_size", "true")
500 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
501 // b/177813163 deps of the host tools have to be added. Remove this.
502 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
503 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
504 }
505
Jiyong Park71baa762021-01-18 21:11:03 +0900506 if proptools.Bool(f.properties.Use_avb) {
507 addStr("avb_hashtree_enable", "true")
508 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
509 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
510 addStr("avb_algorithm", algorithm)
511 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
512 addPath("avb_key_path", key)
Inseob Kim53391842024-03-29 17:44:07 +0900513 addStr("partition_name", f.partitionName())
Shikha Panware6f30632022-12-21 12:54:45 +0000514 avb_add_hashtree_footer_args := "--do_not_generate_fec"
515 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
516 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
517 }
Nikita Ioffe2c8cdc62024-03-27 22:19:30 +0000518 if f.properties.Rollback_index != nil {
519 rollbackIndex := proptools.Int(f.properties.Rollback_index)
520 if rollbackIndex < 0 {
521 ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative")
522 }
523 avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex)
524 }
Inseob Kim53391842024-03-29 17:44:07 +0900525 securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch"
Seungjae Yooa30e4502023-11-09 14:55:44 +0900526 securityPatchValue := ctx.Config().PlatformSecurityPatch()
527 avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
Shikha Panware6f30632022-12-21 12:54:45 +0000528 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jooyung Han65f402b2022-04-21 14:24:04 +0900529 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900530 }
531
Inseob Kimcc8e5362021-02-03 14:05:24 +0900532 if proptools.String(f.properties.File_contexts) != "" {
533 addPath("selinux_fc", f.buildFileContexts(ctx))
534 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900535 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
536 addStr("timestamp", timestamp)
537 }
538 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
539 addStr("uuid", uuid)
540 addStr("hash_seed", uuid)
541 }
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000542 // Add erofs properties
543 if f.fsType(ctx) == erofsType {
544 if compressor := f.properties.Erofs.Compressor; compressor != nil {
545 addStr("erofs_default_compressor", proptools.String(compressor))
546 }
547 if compressHints := f.properties.Erofs.Compress_hints; compressHints != nil {
Cole Faust7cd4bad2024-10-11 10:31:12 -0700548 addPath("erofs_default_compress_hints", android.PathForModuleSrc(ctx, *compressHints))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000549 }
550 if proptools.BoolDefault(f.properties.Erofs.Sparse, true) {
551 // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b
552 addStr("erofs_sparse_flag", "-s")
553 }
Cole Faust7cd4bad2024-10-11 10:31:12 -0700554 } else if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil {
555 // Raise an exception if the propfile contains erofs properties, but the fstype is not erofs
556 fs := fsTypeStr(f.fsType(ctx))
Spandan Dasc35d6fb2024-10-10 17:51:14 +0000557 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)
558 }
559
Jiyong Park72678312021-01-18 17:29:49 +0900560 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
Cole Faustcec230a2024-03-07 15:51:12 -0800561 android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
Jiyong Park72678312021-01-18 17:29:49 +0900562 return propFile, deps
563}
564
Jiyong Park837cdb22021-02-05 00:17:14 +0900565func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900566 if proptools.Bool(f.properties.Use_avb) {
567 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
568 "Consider adding this to bootimg module and signing the entire boot image.")
569 }
570
Inseob Kimcc8e5362021-02-03 14:05:24 +0900571 if proptools.String(f.properties.File_contexts) != "" {
572 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
573 }
574
Cole Faust4a2a7c92024-03-12 12:44:40 -0700575 if f.properties.Include_make_built_files != "" {
576 ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.")
577 }
578
Jiyong Park11a65972021-02-01 21:09:38 +0900579 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700580 rebasedDir := rootDir
581 if f.properties.Base_dir != nil {
582 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
583 }
584 builder := android.NewRuleBuilder(pctx, ctx)
585 // Wipe the root dir to get rid of leftover files from prior builds
586 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900587 specs := f.gatherFilteredPackagingSpecs(ctx)
Inseob Kim33f95a92024-07-11 15:44:49 +0900588 f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir)
Cole Faust3b806d32024-03-11 15:15:03 -0700589
590 f.buildNonDepsFiles(ctx, builder, rootDir)
Inseob Kim53391842024-03-29 17:44:07 +0900591 f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
Inseob Kimb7b84572024-04-30 10:51:47 +0900592 f.buildEventLogtagsFile(ctx, builder, rebasedDir)
Justin Yun74f3f302024-05-07 14:32:14 +0900593 f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir)
Kiyoung Kim67118212024-11-07 13:23:44 +0900594 f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir)
Justin Yun34baa2e2024-08-30 21:11:33 +0900595 f.copyFilesToProductOut(ctx, builder, rebasedDir)
Jiyong Park11a65972021-02-01 21:09:38 +0900596
597 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900598 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900599 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900600 Text(rootDir.String()) // input directory
601 if compressed {
602 cmd.Text("|").
603 BuiltTool("lz4").
604 Flag("--favor-decSpeed"). // for faster boot
605 Flag("-12"). // maximum compression level
606 Flag("-l"). // legacy format for kernel
607 Text(">").Output(output)
608 } else {
609 cmd.Text(">").Output(output)
610 }
Jiyong Park11a65972021-02-01 21:09:38 +0900611
612 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900613 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900614
615 return output
616}
617
Cole Faust4a2a7c92024-03-12 12:44:40 -0700618var validPartitions = []string{
619 "system",
620 "userdata",
621 "cache",
622 "system_other",
623 "vendor",
624 "product",
625 "system_ext",
626 "odm",
627 "vendor_dlkm",
628 "odm_dlkm",
629 "system_dlkm",
630}
631
632func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) {
633 partition := f.properties.Include_make_built_files
634 if partition == "" {
635 return
636 }
637 if !slices.Contains(validPartitions, partition) {
638 ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition)
639 return
640 }
641 stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition)
642 fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition)
643 stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition)
644
645 builder.Command().BuiltTool("merge_directories").
646 Implicit(android.PathForArbitraryOutput(ctx, stampFile)).
647 Text("--ignore-duplicates").
648 FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)).
649 Text(rootDir.String()).
650 Text(android.PathForArbitraryOutput(ctx, stagingDir).String())
651}
652
Inseob Kimb7b84572024-04-30 10:51:47 +0900653func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
654 if !proptools.Bool(f.properties.Build_logtags) {
655 return
656 }
657
658 logtagsFilePaths := make(map[string]bool)
659 ctx.WalkDeps(func(child, parent android.Module) bool {
660 if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok {
661 for _, path := range logtagsInfo.Logtags {
662 logtagsFilePaths[path.String()] = true
663 }
664 }
665 return true
666 })
667
668 if len(logtagsFilePaths) == 0 {
669 return
670 }
671
672 etcPath := rebasedDir.Join(ctx, "etc")
673 eventLogtagsPath := etcPath.Join(ctx, "event-log-tags")
674 builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String())
675 cmd := builder.Command().BuiltTool("merge-event-log-tags").
676 FlagWithArg("-o ", eventLogtagsPath.String()).
677 FlagWithInput("-m ", android.MergedLogtagsPath(ctx))
678
679 for _, path := range android.SortedKeys(logtagsFilePaths) {
680 cmd.Text(path)
681 }
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900682
683 f.appendToEntry(ctx, eventLogtagsPath)
Inseob Kimb7b84572024-04-30 10:51:47 +0900684}
685
Kiyoung Kim67118212024-11-07 13:23:44 +0900686func (f *filesystem) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) {
Spandan Das173256b2024-10-31 19:59:30 +0000687 if !proptools.Bool(f.properties.Linkerconfig.Gen_linker_config) {
Spandan Das92631882024-10-28 22:49:38 +0000688 return
689 }
690
Spandan Das918191e2024-10-31 18:27:23 +0000691 provideModules, _ := f.getLibsForLinkerConfig(ctx)
Spandan Das92631882024-10-28 22:49:38 +0000692 output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
Spandan Das173256b2024-10-31 19:59:30 +0000693 linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linkerconfig.Linker_config_srcs), provideModules, nil, output)
Spandan Das92631882024-10-28 22:49:38 +0000694
695 f.appendToEntry(ctx, output)
696}
697
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900698type partition interface {
699 PartitionType() string
700}
701
Cole Faust9a24d902024-03-18 15:38:12 -0700702func (f *filesystem) PartitionType() string {
703 return proptools.StringDefault(f.properties.Partition_type, "system")
704}
705
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900706var _ partition = (*filesystem)(nil)
707
Jiyong Park65c49f52020-11-24 14:23:26 +0900708var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
709
710// Implements android.AndroidMkEntriesProvider
711func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
712 return []android.AndroidMkEntries{android.AndroidMkEntries{
713 Class: "ETC",
714 OutputFile: android.OptionalPathForPath(f.output),
715 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700716 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800717 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900718 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
Kiyoung Kim99a954d2024-06-21 14:22:20 +0900719 entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900720 },
721 },
722 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900723}
Jiyong Park12a719c2021-01-07 15:31:24 +0900724
725// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
726// package to have access to the output file.
727type Filesystem interface {
728 android.Module
729 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900730
731 // Returns the output file that is signed by avbtool. If this module is not signed, returns
732 // nil.
733 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900734}
735
736var _ Filesystem = (*filesystem)(nil)
737
738func (f *filesystem) OutputPath() android.Path {
739 return f.output
740}
Jiyong Park972e06c2021-03-15 23:32:49 +0900741
742func (f *filesystem) SignedOutputPath() android.Path {
743 if proptools.Bool(f.properties.Use_avb) {
744 return f.OutputPath()
745 }
746 return nil
747}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900748
749// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
750// Note that "apex" module installs its contents to "apex"(fake partition) as well
751// for symbol lookup by imitating "activated" paths.
752func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
Kiyoung Kim67118212024-11-07 13:23:44 +0900753 specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filesystemBuilder.FilterPackagingSpec)
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900754 return specs
755}
Jooyung Han65f402b2022-04-21 14:24:04 +0900756
757func sha1sum(values []string) string {
758 h := sha256.New()
759 for _, value := range values {
760 io.WriteString(h, value)
761 }
762 return fmt.Sprintf("%x", h.Sum(nil))
763}
Jooyung Hane6067592023-03-16 13:11:17 +0900764
765// Base cc.UseCoverage
766
767var _ cc.UseCoverage = (*filesystem)(nil)
768
Colin Crosse1a85552024-06-14 12:17:37 -0700769func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
Jooyung Hane6067592023-03-16 13:11:17 +0900770 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
771}
Jiyong Parkf46b1af2024-04-05 18:13:33 +0900772
773// android_filesystem_defaults
774
775type filesystemDefaults struct {
776 android.ModuleBase
777 android.DefaultsModuleBase
778
779 properties filesystemDefaultsProperties
780}
781
782type filesystemDefaultsProperties struct {
783 // Identifies which partition this is for //visibility:any_system_image (and others) visibility
784 // checks, and will be used in the future for API surface checks.
785 Partition_type *string
786}
787
788// android_filesystem_defaults is a default module for android_filesystem and android_system_image
789func filesystemDefaultsFactory() android.Module {
790 module := &filesystemDefaults{}
791 module.AddProperties(&module.properties)
792 module.AddProperties(&android.PackagingProperties{})
793 android.InitDefaultsModule(module)
794 return module
795}
796
797func (f *filesystemDefaults) PartitionType() string {
798 return proptools.StringDefault(f.properties.Partition_type, "system")
799}
800
801var _ partition = (*filesystemDefaults)(nil)
802
803func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
804 validatePartitionType(ctx, f)
805}
Spandan Das918191e2024-10-31 18:27:23 +0000806
807// getLibsForLinkerConfig returns
808// 1. A list of libraries installed in this filesystem
809// 2. A list of dep libraries _not_ installed in this filesystem
810//
811// `linkerconfig.BuildLinkerConfig` will convert these two to a linker.config.pb for the filesystem
812// (1) will be added to --provideLibs if they are C libraries with a stable interface (has stubs)
813// (2) will be added to --requireLibs if they are C libraries with a stable interface (has stubs)
814func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]android.Module, []android.Module) {
815 // we need "Module"s for packaging items
816 modulesInPackageByModule := make(map[android.Module]bool)
817 modulesInPackageByName := make(map[string]bool)
818
819 deps := f.gatherFilteredPackagingSpecs(ctx)
820 ctx.WalkDeps(func(child, parent android.Module) bool {
821 for _, ps := range android.OtherModuleProviderOrDefault(
822 ctx, child, android.InstallFilesProvider).PackagingSpecs {
823 if _, ok := deps[ps.RelPathInPackage()]; ok {
824 modulesInPackageByModule[child] = true
825 modulesInPackageByName[child.Name()] = true
826 return true
827 }
828 }
829 return true
830 })
831
832 provideModules := make([]android.Module, 0, len(modulesInPackageByModule))
833 for mod := range modulesInPackageByModule {
834 provideModules = append(provideModules, mod)
835 }
836
837 var requireModules []android.Module
838 ctx.WalkDeps(func(child, parent android.Module) bool {
839 _, parentInPackage := modulesInPackageByModule[parent]
840 _, childInPackageName := modulesInPackageByName[child.Name()]
841
842 // When parent is in the package, and child (or its variant) is not, this can be from an interface.
843 if parentInPackage && !childInPackageName {
844 requireModules = append(requireModules, child)
845 }
846 return true
847 })
848
849 return provideModules, requireModules
850}