blob: abc656f495f05da68bfdbd04c0c1eb37f17afb8a [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"
22 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090023
24 "android/soong/android"
Jooyung Hane6067592023-03-16 13:11:17 +090025 "android/soong/cc"
Jiyong Park65b62242020-11-25 12:44:59 +090026
27 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090028 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090029)
30
31func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090032 registerBuildComponents(android.InitRegistrationContext)
33}
34
35func registerBuildComponents(ctx android.RegistrationContext) {
36 ctx.RegisterModuleType("android_filesystem", filesystemFactory)
Jiyong Parkfa616132021-04-20 11:36:40 +090037 ctx.RegisterModuleType("android_system_image", systemImageFactory)
Jiyong Parkbc485482022-11-15 22:31:49 +090038 ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090039 ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
Alice Wang000e3a32023-01-03 16:11:20 +000040 ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090041 ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090042}
43
44type filesystem struct {
45 android.ModuleBase
46 android.PackagingBase
Jiyong Park65c49f52020-11-24 14:23:26 +090047
Jiyong Park71baa762021-01-18 21:11:03 +090048 properties filesystemProperties
49
Jiyong Parkfa616132021-04-20 11:36:40 +090050 // Function that builds extra files under the root directory and returns the files
51 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
52
Jeongik Cha54bf8752024-02-08 10:44:37 +090053 // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
54 filterPackagingSpec func(spec android.PackagingSpec) bool
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090055
Jiyong Park65c49f52020-11-24 14:23:26 +090056 output android.OutputPath
57 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090058
59 // For testing. Keeps the result of CopyDepsToZip()
60 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090061}
62
Inseob Kim14199b02021-02-09 21:18:31 +090063type symlinkDefinition struct {
64 Target *string
65 Name *string
66}
67
Jiyong Park71baa762021-01-18 21:11:03 +090068type filesystemProperties struct {
69 // When set to true, sign the image with avbtool. Default is false.
70 Use_avb *bool
71
72 // Path to the private key that avbtool will use to sign this filesystem image.
73 // TODO(jiyong): allow apex_key to be specified here
74 Avb_private_key *string `android:"path"`
75
Shikha Panwar01403bb2022-12-22 12:22:57 +000076 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090077 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090078
Shikha Panwar01403bb2022-12-22 12:22:57 +000079 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
80 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +000081 Avb_hash_algorithm *string
82
Jiyong Parkac4076d2021-03-15 23:21:30 +090083 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
84 Partition_name *string
85
Jiyong Park837cdb22021-02-05 00:17:14 +090086 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
87 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090088 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090089
90 // file_contexts file to make image. Currently, only ext4 is supported.
91 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090092
93 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
94 // (root).
95 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090096
97 // Directories to be created under root. e.g. /dev, /proc, etc.
98 Dirs []string
99
100 // Symbolic links to be created under root with "ln -sf <target> <name>".
101 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +0900102
103 // Seconds since unix epoch to override timestamps of file entries
104 Fake_timestamp *string
105
106 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
107 // Otherwise, they'll be set as random which might cause indeterministic build output.
108 Uuid *string
Inseob Kim376d72f2023-11-01 15:40:25 +0900109
110 // Mount point for this image. Default is "/"
111 Mount_point *string
Jiyong Park71baa762021-01-18 21:11:03 +0900112}
113
Jiyong Park65c49f52020-11-24 14:23:26 +0900114// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
115// image. The filesystem images are expected to be mounted in the target device, which means the
116// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
117// The modules are placed in the filesystem image just like they are installed to the ordinary
118// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900119func filesystemFactory() android.Module {
120 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900121 initFilesystemModule(module)
122 return module
123}
124
125func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900126 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900127 android.InitPackageModule(module)
128 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900129}
130
Jiyong Park12a719c2021-01-07 15:31:24 +0900131var dependencyTag = struct {
132 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900133 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900134}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900135
Jiyong Park6f0f6882020-11-12 13:14:30 +0900136func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900137 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900138}
139
Jiyong Park11a65972021-02-01 21:09:38 +0900140type fsType int
141
142const (
143 ext4Type fsType = iota
144 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900145 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900146 unknown
147)
148
149func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
150 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
151 switch typeStr {
152 case "ext4":
153 return ext4Type
154 case "compressed_cpio":
155 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900156 case "cpio":
157 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900158 default:
159 ctx.PropertyErrorf("type", "%q not supported", typeStr)
160 return unknown
161 }
162}
163
Jiyong Park65c49f52020-11-24 14:23:26 +0900164func (f *filesystem) installFileName() string {
165 return f.BaseModuleName() + ".img"
166}
167
Jiyong Park6f0f6882020-11-12 13:14:30 +0900168var pctx = android.NewPackageContext("android/soong/filesystem")
169
170func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900171 switch f.fsType(ctx) {
172 case ext4Type:
173 f.output = f.buildImageUsingBuildImage(ctx)
174 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900175 f.output = f.buildCpioImage(ctx, true)
176 case cpioType:
177 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900178 default:
179 return
180 }
181
182 f.installDir = android.PathForModuleInstall(ctx, "etc")
183 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
184}
185
Cole Faust3b806d32024-03-11 15:15:03 -0700186// Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files
187// already in `rootDir`.
188func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) {
Inseob Kim14199b02021-02-09 21:18:31 +0900189 // create dirs and symlinks
190 for _, dir := range f.properties.Dirs {
191 // OutputPath.Join verifies dir
192 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
193 }
194
195 for _, symlink := range f.properties.Symlinks {
196 name := strings.TrimSpace(proptools.String(symlink.Name))
197 target := strings.TrimSpace(proptools.String(symlink.Target))
198
199 if name == "" {
200 ctx.PropertyErrorf("symlinks", "Name can't be empty")
201 continue
202 }
203
204 if target == "" {
205 ctx.PropertyErrorf("symlinks", "Target can't be empty")
206 continue
207 }
208
209 // OutputPath.Join verifies name. don't need to verify target.
210 dst := rootDir.Join(ctx, name)
Cole Faust3b806d32024-03-11 15:15:03 -0700211 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 +0900212 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
213 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
214 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900215
Jiyong Parkfa616132021-04-20 11:36:40 +0900216 // create extra files if there's any
217 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
218 var extraFiles android.OutputPaths
219 if f.buildExtraFiles != nil {
220 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
Jiyong Parkfa616132021-04-20 11:36:40 +0900221 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900222
Cole Faust3b806d32024-03-11 15:15:03 -0700223 for _, f := range extraFiles {
224 rel, err := filepath.Rel(rootForExtraFiles.String(), f.String())
225 if err != nil || strings.HasPrefix(rel, "..") {
226 ctx.ModuleErrorf("can't make %q relative to %q", f, rootForExtraFiles)
227 continue
Jiyong Parkfa616132021-04-20 11:36:40 +0900228 }
Cole Faust3b806d32024-03-11 15:15:03 -0700229 dst := rootDir.Join(ctx, rel)
230 builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
231 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
232 builder.Command().Text("cp -P").Input(f).Output(dst)
Jiyong Parkfa616132021-04-20 11:36:40 +0900233 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900234}
235
Jiyong Park11a65972021-02-01 21:09:38 +0900236func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Jiyong Park6f0f6882020-11-12 13:14:30 +0900237 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700238 rebasedDir := rootDir
239 if f.properties.Base_dir != nil {
240 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
241 }
242 builder := android.NewRuleBuilder(pctx, ctx)
243 // Wipe the root dir to get rid of leftover files from prior builds
244 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
245 f.entries = f.CopySpecsToDir(ctx, builder, f.gatherFilteredPackagingSpecs(ctx), rebasedDir)
246
247 f.buildNonDepsFiles(ctx, builder, rootDir)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900248
Nikita Ioffe519015f2022-12-23 15:36:29 +0000249 // run host_init_verifier
250 // Ideally we should have a concept of pluggable linters that verify the generated image.
251 // While such concept is not implement this will do.
252 // TODO(b/263574231): substitute with pluggable linter.
253 builder.Command().
254 BuiltTool("host_init_verifier").
255 FlagWithArg("--out_system=", rootDir.String()+"/system")
256
Jiyong Park72678312021-01-18 17:29:49 +0900257 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900258 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800259 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900260 Text(rootDir.String()). // input directory
261 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900262 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900263 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900264 Text(rootDir.String()) // directory where to find fs_config_files|dirs
265
266 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800267 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900268
Jiyong Park11a65972021-02-01 21:09:38 +0900269 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900270}
271
Inseob Kimcc8e5362021-02-03 14:05:24 +0900272func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
273 builder := android.NewRuleBuilder(pctx, ctx)
274 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
275 builder.Command().BuiltTool("sefcontext_compile").
276 FlagWithOutput("-o ", fcBin).
277 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
278 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
279 return fcBin.OutputPath
280}
281
Jooyung Han65f402b2022-04-21 14:24:04 +0900282// Calculates avb_salt from entry list (sorted) for deterministic output.
283func (f *filesystem) salt() string {
284 return sha1sum(f.entries)
285}
286
Jiyong Park72678312021-01-18 17:29:49 +0900287func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
Jiyong Park72678312021-01-18 17:29:49 +0900288 var deps android.Paths
Cole Faustcec230a2024-03-07 15:51:12 -0800289 var propFileString strings.Builder
Jiyong Park72678312021-01-18 17:29:49 +0900290 addStr := func(name string, value string) {
Cole Faustcec230a2024-03-07 15:51:12 -0800291 propFileString.WriteString(name)
292 propFileString.WriteRune('=')
293 propFileString.WriteString(value)
294 propFileString.WriteRune('\n')
Jiyong Park72678312021-01-18 17:29:49 +0900295 }
296 addPath := func(name string, path android.Path) {
Cole Faustcec230a2024-03-07 15:51:12 -0800297 addStr(name, path.String())
Jiyong Park72678312021-01-18 17:29:49 +0900298 deps = append(deps, path)
299 }
300
Jiyong Park11a65972021-02-01 21:09:38 +0900301 // Type string that build_image.py accepts.
302 fsTypeStr := func(t fsType) string {
303 switch t {
304 // TODO(jiyong): add more types like f2fs, erofs, etc.
305 case ext4Type:
306 return "ext4"
307 }
308 panic(fmt.Errorf("unsupported fs type %v", t))
309 }
310
311 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim376d72f2023-11-01 15:40:25 +0900312 addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
Jiyong Park72678312021-01-18 17:29:49 +0900313 addStr("use_dynamic_partition_size", "true")
314 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
315 // b/177813163 deps of the host tools have to be added. Remove this.
316 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
317 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
318 }
319
Jiyong Park71baa762021-01-18 21:11:03 +0900320 if proptools.Bool(f.properties.Use_avb) {
321 addStr("avb_hashtree_enable", "true")
322 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
323 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
324 addStr("avb_algorithm", algorithm)
325 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
326 addPath("avb_key_path", key)
Seungjae Yooa30e4502023-11-09 14:55:44 +0900327 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
328 addStr("partition_name", partitionName)
Shikha Panware6f30632022-12-21 12:54:45 +0000329 avb_add_hashtree_footer_args := "--do_not_generate_fec"
330 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
331 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
332 }
Seungjae Yooa30e4502023-11-09 14:55:44 +0900333 securityPatchKey := "com.android.build." + partitionName + ".security_patch"
334 securityPatchValue := ctx.Config().PlatformSecurityPatch()
335 avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
Shikha Panware6f30632022-12-21 12:54:45 +0000336 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jooyung Han65f402b2022-04-21 14:24:04 +0900337 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900338 }
339
Inseob Kimcc8e5362021-02-03 14:05:24 +0900340 if proptools.String(f.properties.File_contexts) != "" {
341 addPath("selinux_fc", f.buildFileContexts(ctx))
342 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900343 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
344 addStr("timestamp", timestamp)
345 }
346 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
347 addStr("uuid", uuid)
348 addStr("hash_seed", uuid)
349 }
Jiyong Park72678312021-01-18 17:29:49 +0900350 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
Cole Faustcec230a2024-03-07 15:51:12 -0800351 android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
Jiyong Park72678312021-01-18 17:29:49 +0900352 return propFile, deps
353}
354
Jiyong Park837cdb22021-02-05 00:17:14 +0900355func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900356 if proptools.Bool(f.properties.Use_avb) {
357 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
358 "Consider adding this to bootimg module and signing the entire boot image.")
359 }
360
Inseob Kimcc8e5362021-02-03 14:05:24 +0900361 if proptools.String(f.properties.File_contexts) != "" {
362 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
363 }
364
Jiyong Park11a65972021-02-01 21:09:38 +0900365 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Cole Faust3b806d32024-03-11 15:15:03 -0700366 rebasedDir := rootDir
367 if f.properties.Base_dir != nil {
368 rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
369 }
370 builder := android.NewRuleBuilder(pctx, ctx)
371 // Wipe the root dir to get rid of leftover files from prior builds
372 builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
373 f.entries = f.CopySpecsToDir(ctx, builder, f.gatherFilteredPackagingSpecs(ctx), rebasedDir)
374
375 f.buildNonDepsFiles(ctx, builder, rootDir)
Jiyong Park11a65972021-02-01 21:09:38 +0900376
377 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900378 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900379 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900380 Text(rootDir.String()) // input directory
381 if compressed {
382 cmd.Text("|").
383 BuiltTool("lz4").
384 Flag("--favor-decSpeed"). // for faster boot
385 Flag("-12"). // maximum compression level
386 Flag("-l"). // legacy format for kernel
387 Text(">").Output(output)
388 } else {
389 cmd.Text(">").Output(output)
390 }
Jiyong Park11a65972021-02-01 21:09:38 +0900391
392 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900393 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900394
395 return output
396}
397
Jiyong Park65c49f52020-11-24 14:23:26 +0900398var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
399
400// Implements android.AndroidMkEntriesProvider
401func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
402 return []android.AndroidMkEntries{android.AndroidMkEntries{
403 Class: "ETC",
404 OutputFile: android.OptionalPathForPath(f.output),
405 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700406 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800407 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900408 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
409 },
410 },
411 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900412}
Jiyong Park12a719c2021-01-07 15:31:24 +0900413
Jiyong Park940dfd42021-02-04 15:37:34 +0900414var _ android.OutputFileProducer = (*filesystem)(nil)
415
416// Implements android.OutputFileProducer
417func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
418 if tag == "" {
419 return []android.Path{f.output}, nil
420 }
421 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
422}
423
Jiyong Park12a719c2021-01-07 15:31:24 +0900424// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
425// package to have access to the output file.
426type Filesystem interface {
427 android.Module
428 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900429
430 // Returns the output file that is signed by avbtool. If this module is not signed, returns
431 // nil.
432 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900433}
434
435var _ Filesystem = (*filesystem)(nil)
436
437func (f *filesystem) OutputPath() android.Path {
438 return f.output
439}
Jiyong Park972e06c2021-03-15 23:32:49 +0900440
441func (f *filesystem) SignedOutputPath() android.Path {
442 if proptools.Bool(f.properties.Use_avb) {
443 return f.OutputPath()
444 }
445 return nil
446}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900447
448// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
449// Note that "apex" module installs its contents to "apex"(fake partition) as well
450// for symbol lookup by imitating "activated" paths.
451func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
Jeongik Cha54bf8752024-02-08 10:44:37 +0900452 specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec)
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900453 return specs
454}
Jooyung Han65f402b2022-04-21 14:24:04 +0900455
456func sha1sum(values []string) string {
457 h := sha256.New()
458 for _, value := range values {
459 io.WriteString(h, value)
460 }
461 return fmt.Sprintf("%x", h.Sum(nil))
462}
Jooyung Hane6067592023-03-16 13:11:17 +0900463
464// Base cc.UseCoverage
465
466var _ cc.UseCoverage = (*filesystem)(nil)
467
Colin Crossf5f4ad32024-01-19 15:41:48 -0800468func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool {
Jooyung Hane6067592023-03-16 13:11:17 +0900469 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
470}