blob: 1365d4a587c395fb51264733c9736583304fb03f [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"
Jiyong Park65b62242020-11-25 12:44:59 +090025
26 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090027 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090028)
29
30func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090031 registerBuildComponents(android.InitRegistrationContext)
32}
33
34func registerBuildComponents(ctx android.RegistrationContext) {
35 ctx.RegisterModuleType("android_filesystem", filesystemFactory)
Jiyong Parkfa616132021-04-20 11:36:40 +090036 ctx.RegisterModuleType("android_system_image", systemImageFactory)
Jiyong Parkbc485482022-11-15 22:31:49 +090037 ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090038}
39
40type filesystem struct {
41 android.ModuleBase
42 android.PackagingBase
Jiyong Park65c49f52020-11-24 14:23:26 +090043
Jiyong Park71baa762021-01-18 21:11:03 +090044 properties filesystemProperties
45
Jiyong Parkfa616132021-04-20 11:36:40 +090046 // Function that builds extra files under the root directory and returns the files
47 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
48
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090049 // Function that filters PackagingSpecs returned by PackagingBase.GatherPackagingSpecs()
50 filterPackagingSpecs func(specs map[string]android.PackagingSpec)
51
Jiyong Park65c49f52020-11-24 14:23:26 +090052 output android.OutputPath
53 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090054
55 // For testing. Keeps the result of CopyDepsToZip()
56 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090057}
58
Inseob Kim14199b02021-02-09 21:18:31 +090059type symlinkDefinition struct {
60 Target *string
61 Name *string
62}
63
Jiyong Park71baa762021-01-18 21:11:03 +090064type filesystemProperties struct {
65 // When set to true, sign the image with avbtool. Default is false.
66 Use_avb *bool
67
68 // Path to the private key that avbtool will use to sign this filesystem image.
69 // TODO(jiyong): allow apex_key to be specified here
70 Avb_private_key *string `android:"path"`
71
72 // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
73 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090074
Jiyong Parkac4076d2021-03-15 23:21:30 +090075 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
76 Partition_name *string
77
Jiyong Park837cdb22021-02-05 00:17:14 +090078 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
79 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090080 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090081
82 // file_contexts file to make image. Currently, only ext4 is supported.
83 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090084
85 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
86 // (root).
87 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090088
89 // Directories to be created under root. e.g. /dev, /proc, etc.
90 Dirs []string
91
92 // Symbolic links to be created under root with "ln -sf <target> <name>".
93 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +090094
95 // Seconds since unix epoch to override timestamps of file entries
96 Fake_timestamp *string
97
98 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
99 // Otherwise, they'll be set as random which might cause indeterministic build output.
100 Uuid *string
Jiyong Park71baa762021-01-18 21:11:03 +0900101}
102
Jiyong Park65c49f52020-11-24 14:23:26 +0900103// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
104// image. The filesystem images are expected to be mounted in the target device, which means the
105// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
106// The modules are placed in the filesystem image just like they are installed to the ordinary
107// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900108func filesystemFactory() android.Module {
109 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900110 initFilesystemModule(module)
111 return module
112}
113
114func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900115 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900116 android.InitPackageModule(module)
117 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900118}
119
Jiyong Park12a719c2021-01-07 15:31:24 +0900120var dependencyTag = struct {
121 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900122 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900123}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900124
Jiyong Park6f0f6882020-11-12 13:14:30 +0900125func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900126 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900127}
128
Jiyong Park11a65972021-02-01 21:09:38 +0900129type fsType int
130
131const (
132 ext4Type fsType = iota
133 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900134 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900135 unknown
136)
137
138func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
139 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
140 switch typeStr {
141 case "ext4":
142 return ext4Type
143 case "compressed_cpio":
144 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900145 case "cpio":
146 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900147 default:
148 ctx.PropertyErrorf("type", "%q not supported", typeStr)
149 return unknown
150 }
151}
152
Jiyong Park65c49f52020-11-24 14:23:26 +0900153func (f *filesystem) installFileName() string {
154 return f.BaseModuleName() + ".img"
155}
156
Jiyong Park6f0f6882020-11-12 13:14:30 +0900157var pctx = android.NewPackageContext("android/soong/filesystem")
158
159func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900160 switch f.fsType(ctx) {
161 case ext4Type:
162 f.output = f.buildImageUsingBuildImage(ctx)
163 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900164 f.output = f.buildCpioImage(ctx, true)
165 case cpioType:
166 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900167 default:
168 return
169 }
170
171 f.installDir = android.PathForModuleInstall(ctx, "etc")
172 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
173}
174
Jiyong Parkfa616132021-04-20 11:36:40 +0900175// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900176func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
177 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
178 builder := android.NewRuleBuilder(pctx, ctx)
179 builder.Command().Text("rm -rf").Text(rootDir.String())
180 builder.Command().Text("mkdir -p").Text(rootDir.String())
181
Inseob Kim14199b02021-02-09 21:18:31 +0900182 // create dirs and symlinks
183 for _, dir := range f.properties.Dirs {
184 // OutputPath.Join verifies dir
185 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
186 }
187
188 for _, symlink := range f.properties.Symlinks {
189 name := strings.TrimSpace(proptools.String(symlink.Name))
190 target := strings.TrimSpace(proptools.String(symlink.Target))
191
192 if name == "" {
193 ctx.PropertyErrorf("symlinks", "Name can't be empty")
194 continue
195 }
196
197 if target == "" {
198 ctx.PropertyErrorf("symlinks", "Target can't be empty")
199 continue
200 }
201
202 // OutputPath.Join verifies name. don't need to verify target.
203 dst := rootDir.Join(ctx, name)
204
205 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
206 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
207 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900208
Jiyong Parkfa616132021-04-20 11:36:40 +0900209 // create extra files if there's any
210 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
211 var extraFiles android.OutputPaths
212 if f.buildExtraFiles != nil {
213 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
214 for _, f := range extraFiles {
215 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
216 if strings.HasPrefix(rel, "..") {
217 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
218 }
219 }
220 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900221
Jiyong Parkfa616132021-04-20 11:36:40 +0900222 // Zip them all
223 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
224 zipCommand := builder.Command().BuiltTool("soong_zip")
225 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900226 FlagWithArg("-C ", rootDir.String()).
227 Flag("-L 0"). // no compression because this will be unzipped soon
228 FlagWithArg("-D ", rootDir.String()).
229 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900230 if len(extraFiles) > 0 {
231 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
232 for _, f := range extraFiles {
233 zipCommand.FlagWithInput("-f ", f)
234 }
235 }
236
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900237 builder.Command().Text("rm -rf").Text(rootDir.String())
238
239 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
240 return zipOut
241}
242
Jiyong Park11a65972021-02-01 21:09:38 +0900243func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900244 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900245 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900246
247 builder := android.NewRuleBuilder(pctx, ctx)
248 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
249 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
250 builder.Command().
251 BuiltTool("zip2zip").
252 FlagWithInput("-i ", depsZipFile).
253 FlagWithOutput("-o ", rebasedDepsZip).
254 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900255
256 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900257 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900258 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800259 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900260 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900261 Input(rootZip).
262 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900263
Jiyong Park72678312021-01-18 17:29:49 +0900264 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900265 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800266 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900267 Text(rootDir.String()). // input directory
268 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900269 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900270 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900271 Text(rootDir.String()) // directory where to find fs_config_files|dirs
272
273 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800274 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900275
Jiyong Park11a65972021-02-01 21:09:38 +0900276 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900277}
278
Inseob Kimcc8e5362021-02-03 14:05:24 +0900279func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
280 builder := android.NewRuleBuilder(pctx, ctx)
281 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
282 builder.Command().BuiltTool("sefcontext_compile").
283 FlagWithOutput("-o ", fcBin).
284 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
285 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
286 return fcBin.OutputPath
287}
288
Jooyung Han65f402b2022-04-21 14:24:04 +0900289// Calculates avb_salt from entry list (sorted) for deterministic output.
290func (f *filesystem) salt() string {
291 return sha1sum(f.entries)
292}
293
Jiyong Park72678312021-01-18 17:29:49 +0900294func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
295 type prop struct {
296 name string
297 value string
298 }
299
300 var props []prop
301 var deps android.Paths
302 addStr := func(name string, value string) {
303 props = append(props, prop{name, value})
304 }
305 addPath := func(name string, path android.Path) {
306 props = append(props, prop{name, path.String()})
307 deps = append(deps, path)
308 }
309
Jiyong Park11a65972021-02-01 21:09:38 +0900310 // Type string that build_image.py accepts.
311 fsTypeStr := func(t fsType) string {
312 switch t {
313 // TODO(jiyong): add more types like f2fs, erofs, etc.
314 case ext4Type:
315 return "ext4"
316 }
317 panic(fmt.Errorf("unsupported fs type %v", t))
318 }
319
320 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900321 addStr("mount_point", "/")
Jiyong Park72678312021-01-18 17:29:49 +0900322 addStr("use_dynamic_partition_size", "true")
323 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
324 // b/177813163 deps of the host tools have to be added. Remove this.
325 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
326 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
327 }
328
Jiyong Park71baa762021-01-18 21:11:03 +0900329 if proptools.Bool(f.properties.Use_avb) {
330 addStr("avb_hashtree_enable", "true")
331 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
332 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
333 addStr("avb_algorithm", algorithm)
334 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
335 addPath("avb_key_path", key)
336 addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec")
Jiyong Parkac4076d2021-03-15 23:21:30 +0900337 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
338 addStr("partition_name", partitionName)
Jooyung Han65f402b2022-04-21 14:24:04 +0900339 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900340 }
341
Inseob Kimcc8e5362021-02-03 14:05:24 +0900342 if proptools.String(f.properties.File_contexts) != "" {
343 addPath("selinux_fc", f.buildFileContexts(ctx))
344 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900345 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
346 addStr("timestamp", timestamp)
347 }
348 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
349 addStr("uuid", uuid)
350 addStr("hash_seed", uuid)
351 }
Jiyong Park72678312021-01-18 17:29:49 +0900352 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
353 builder := android.NewRuleBuilder(pctx, ctx)
354 builder.Command().Text("rm").Flag("-rf").Output(propFile)
355 for _, p := range props {
356 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900357 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900358 Flag(`"` + p.name + "=" + p.value + `"`).
359 Text(">>").Output(propFile)
360 }
361 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
362 return propFile, deps
363}
364
Jiyong Park837cdb22021-02-05 00:17:14 +0900365func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900366 if proptools.Bool(f.properties.Use_avb) {
367 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
368 "Consider adding this to bootimg module and signing the entire boot image.")
369 }
370
Inseob Kimcc8e5362021-02-03 14:05:24 +0900371 if proptools.String(f.properties.File_contexts) != "" {
372 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
373 }
374
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900375 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900376 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900377
378 builder := android.NewRuleBuilder(pctx, ctx)
379 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
380 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
381 builder.Command().
382 BuiltTool("zip2zip").
383 FlagWithInput("-i ", depsZipFile).
384 FlagWithOutput("-o ", rebasedDepsZip).
385 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900386
387 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900388 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900389 builder.Command().
390 BuiltTool("zipsync").
391 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900392 Input(rootZip).
393 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900394
395 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900396 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900397 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900398 Text(rootDir.String()) // input directory
399 if compressed {
400 cmd.Text("|").
401 BuiltTool("lz4").
402 Flag("--favor-decSpeed"). // for faster boot
403 Flag("-12"). // maximum compression level
404 Flag("-l"). // legacy format for kernel
405 Text(">").Output(output)
406 } else {
407 cmd.Text(">").Output(output)
408 }
Jiyong Park11a65972021-02-01 21:09:38 +0900409
410 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900411 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900412
413 return output
414}
415
Jiyong Park65c49f52020-11-24 14:23:26 +0900416var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
417
418// Implements android.AndroidMkEntriesProvider
419func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
420 return []android.AndroidMkEntries{android.AndroidMkEntries{
421 Class: "ETC",
422 OutputFile: android.OptionalPathForPath(f.output),
423 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700424 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800425 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900426 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
427 },
428 },
429 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900430}
Jiyong Park12a719c2021-01-07 15:31:24 +0900431
Jiyong Park940dfd42021-02-04 15:37:34 +0900432var _ android.OutputFileProducer = (*filesystem)(nil)
433
434// Implements android.OutputFileProducer
435func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
436 if tag == "" {
437 return []android.Path{f.output}, nil
438 }
439 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
440}
441
Jiyong Park12a719c2021-01-07 15:31:24 +0900442// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
443// package to have access to the output file.
444type Filesystem interface {
445 android.Module
446 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900447
448 // Returns the output file that is signed by avbtool. If this module is not signed, returns
449 // nil.
450 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900451}
452
453var _ Filesystem = (*filesystem)(nil)
454
455func (f *filesystem) OutputPath() android.Path {
456 return f.output
457}
Jiyong Park972e06c2021-03-15 23:32:49 +0900458
459func (f *filesystem) SignedOutputPath() android.Path {
460 if proptools.Bool(f.properties.Use_avb) {
461 return f.OutputPath()
462 }
463 return nil
464}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900465
466// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
467// Note that "apex" module installs its contents to "apex"(fake partition) as well
468// for symbol lookup by imitating "activated" paths.
469func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
470 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
471 if f.filterPackagingSpecs != nil {
472 f.filterPackagingSpecs(specs)
473 }
474 return specs
475}
Jooyung Han65f402b2022-04-21 14:24:04 +0900476
477func sha1sum(values []string) string {
478 h := sha256.New()
479 for _, value := range values {
480 io.WriteString(h, value)
481 }
482 return fmt.Sprintf("%x", h.Sum(nil))
483}