blob: e123f24f9e84195dbe3698442879db0ea2c96a55 [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
Shikha Panware6f30632022-12-21 12:54:45 +000075 // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
76 Avb_hash_algorithm *string
77
Jiyong Parkac4076d2021-03-15 23:21:30 +090078 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
79 Partition_name *string
80
Jiyong Park837cdb22021-02-05 00:17:14 +090081 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
82 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090083 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090084
85 // file_contexts file to make image. Currently, only ext4 is supported.
86 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090087
88 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
89 // (root).
90 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090091
92 // Directories to be created under root. e.g. /dev, /proc, etc.
93 Dirs []string
94
95 // Symbolic links to be created under root with "ln -sf <target> <name>".
96 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +090097
98 // Seconds since unix epoch to override timestamps of file entries
99 Fake_timestamp *string
100
101 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
102 // Otherwise, they'll be set as random which might cause indeterministic build output.
103 Uuid *string
Jiyong Park71baa762021-01-18 21:11:03 +0900104}
105
Jiyong Park65c49f52020-11-24 14:23:26 +0900106// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
107// image. The filesystem images are expected to be mounted in the target device, which means the
108// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
109// The modules are placed in the filesystem image just like they are installed to the ordinary
110// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900111func filesystemFactory() android.Module {
112 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900113 initFilesystemModule(module)
114 return module
115}
116
117func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900118 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900119 android.InitPackageModule(module)
120 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900121}
122
Jiyong Park12a719c2021-01-07 15:31:24 +0900123var dependencyTag = struct {
124 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900125 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900126}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900127
Jiyong Park6f0f6882020-11-12 13:14:30 +0900128func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900129 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900130}
131
Jiyong Park11a65972021-02-01 21:09:38 +0900132type fsType int
133
134const (
135 ext4Type fsType = iota
136 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900137 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900138 unknown
139)
140
141func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
142 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
143 switch typeStr {
144 case "ext4":
145 return ext4Type
146 case "compressed_cpio":
147 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900148 case "cpio":
149 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900150 default:
151 ctx.PropertyErrorf("type", "%q not supported", typeStr)
152 return unknown
153 }
154}
155
Jiyong Park65c49f52020-11-24 14:23:26 +0900156func (f *filesystem) installFileName() string {
157 return f.BaseModuleName() + ".img"
158}
159
Jiyong Park6f0f6882020-11-12 13:14:30 +0900160var pctx = android.NewPackageContext("android/soong/filesystem")
161
162func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900163 switch f.fsType(ctx) {
164 case ext4Type:
165 f.output = f.buildImageUsingBuildImage(ctx)
166 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900167 f.output = f.buildCpioImage(ctx, true)
168 case cpioType:
169 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900170 default:
171 return
172 }
173
174 f.installDir = android.PathForModuleInstall(ctx, "etc")
175 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
176}
177
Jiyong Parkfa616132021-04-20 11:36:40 +0900178// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900179func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
180 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
181 builder := android.NewRuleBuilder(pctx, ctx)
182 builder.Command().Text("rm -rf").Text(rootDir.String())
183 builder.Command().Text("mkdir -p").Text(rootDir.String())
184
Inseob Kim14199b02021-02-09 21:18:31 +0900185 // create dirs and symlinks
186 for _, dir := range f.properties.Dirs {
187 // OutputPath.Join verifies dir
188 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
189 }
190
191 for _, symlink := range f.properties.Symlinks {
192 name := strings.TrimSpace(proptools.String(symlink.Name))
193 target := strings.TrimSpace(proptools.String(symlink.Target))
194
195 if name == "" {
196 ctx.PropertyErrorf("symlinks", "Name can't be empty")
197 continue
198 }
199
200 if target == "" {
201 ctx.PropertyErrorf("symlinks", "Target can't be empty")
202 continue
203 }
204
205 // OutputPath.Join verifies name. don't need to verify target.
206 dst := rootDir.Join(ctx, name)
207
208 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
209 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
210 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900211
Jiyong Parkfa616132021-04-20 11:36:40 +0900212 // create extra files if there's any
213 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
214 var extraFiles android.OutputPaths
215 if f.buildExtraFiles != nil {
216 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
217 for _, f := range extraFiles {
218 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
219 if strings.HasPrefix(rel, "..") {
220 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
221 }
222 }
223 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900224
Jiyong Parkfa616132021-04-20 11:36:40 +0900225 // Zip them all
226 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
227 zipCommand := builder.Command().BuiltTool("soong_zip")
228 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900229 FlagWithArg("-C ", rootDir.String()).
230 Flag("-L 0"). // no compression because this will be unzipped soon
231 FlagWithArg("-D ", rootDir.String()).
232 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900233 if len(extraFiles) > 0 {
234 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
235 for _, f := range extraFiles {
236 zipCommand.FlagWithInput("-f ", f)
237 }
238 }
239
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900240 builder.Command().Text("rm -rf").Text(rootDir.String())
241
242 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
243 return zipOut
244}
245
Jiyong Park11a65972021-02-01 21:09:38 +0900246func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900247 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900248 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900249
250 builder := android.NewRuleBuilder(pctx, ctx)
251 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
252 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
253 builder.Command().
254 BuiltTool("zip2zip").
255 FlagWithInput("-i ", depsZipFile).
256 FlagWithOutput("-o ", rebasedDepsZip).
257 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900258
259 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900260 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900261 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800262 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900263 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900264 Input(rootZip).
265 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900266
Jiyong Park72678312021-01-18 17:29:49 +0900267 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900268 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800269 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900270 Text(rootDir.String()). // input directory
271 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900272 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900273 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900274 Text(rootDir.String()) // directory where to find fs_config_files|dirs
275
276 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800277 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900278
Jiyong Park11a65972021-02-01 21:09:38 +0900279 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900280}
281
Inseob Kimcc8e5362021-02-03 14:05:24 +0900282func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
283 builder := android.NewRuleBuilder(pctx, ctx)
284 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
285 builder.Command().BuiltTool("sefcontext_compile").
286 FlagWithOutput("-o ", fcBin).
287 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
288 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
289 return fcBin.OutputPath
290}
291
Jooyung Han65f402b2022-04-21 14:24:04 +0900292// Calculates avb_salt from entry list (sorted) for deterministic output.
293func (f *filesystem) salt() string {
294 return sha1sum(f.entries)
295}
296
Jiyong Park72678312021-01-18 17:29:49 +0900297func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
298 type prop struct {
299 name string
300 value string
301 }
302
303 var props []prop
304 var deps android.Paths
305 addStr := func(name string, value string) {
306 props = append(props, prop{name, value})
307 }
308 addPath := func(name string, path android.Path) {
309 props = append(props, prop{name, path.String()})
310 deps = append(deps, path)
311 }
312
Jiyong Park11a65972021-02-01 21:09:38 +0900313 // Type string that build_image.py accepts.
314 fsTypeStr := func(t fsType) string {
315 switch t {
316 // TODO(jiyong): add more types like f2fs, erofs, etc.
317 case ext4Type:
318 return "ext4"
319 }
320 panic(fmt.Errorf("unsupported fs type %v", t))
321 }
322
323 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900324 addStr("mount_point", "/")
Jiyong Park72678312021-01-18 17:29:49 +0900325 addStr("use_dynamic_partition_size", "true")
326 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
327 // b/177813163 deps of the host tools have to be added. Remove this.
328 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
329 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
330 }
331
Jiyong Park71baa762021-01-18 21:11:03 +0900332 if proptools.Bool(f.properties.Use_avb) {
333 addStr("avb_hashtree_enable", "true")
334 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
335 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
336 addStr("avb_algorithm", algorithm)
337 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
338 addPath("avb_key_path", key)
Shikha Panware6f30632022-12-21 12:54:45 +0000339 avb_add_hashtree_footer_args := "--do_not_generate_fec"
340 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
341 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
342 }
343 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jiyong Parkac4076d2021-03-15 23:21:30 +0900344 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
345 addStr("partition_name", partitionName)
Jooyung Han65f402b2022-04-21 14:24:04 +0900346 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900347 }
348
Inseob Kimcc8e5362021-02-03 14:05:24 +0900349 if proptools.String(f.properties.File_contexts) != "" {
350 addPath("selinux_fc", f.buildFileContexts(ctx))
351 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900352 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
353 addStr("timestamp", timestamp)
354 }
355 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
356 addStr("uuid", uuid)
357 addStr("hash_seed", uuid)
358 }
Jiyong Park72678312021-01-18 17:29:49 +0900359 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
360 builder := android.NewRuleBuilder(pctx, ctx)
361 builder.Command().Text("rm").Flag("-rf").Output(propFile)
362 for _, p := range props {
363 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900364 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900365 Flag(`"` + p.name + "=" + p.value + `"`).
366 Text(">>").Output(propFile)
367 }
368 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
369 return propFile, deps
370}
371
Jiyong Park837cdb22021-02-05 00:17:14 +0900372func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900373 if proptools.Bool(f.properties.Use_avb) {
374 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
375 "Consider adding this to bootimg module and signing the entire boot image.")
376 }
377
Inseob Kimcc8e5362021-02-03 14:05:24 +0900378 if proptools.String(f.properties.File_contexts) != "" {
379 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
380 }
381
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900382 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900383 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900384
385 builder := android.NewRuleBuilder(pctx, ctx)
386 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
387 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
388 builder.Command().
389 BuiltTool("zip2zip").
390 FlagWithInput("-i ", depsZipFile).
391 FlagWithOutput("-o ", rebasedDepsZip).
392 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900393
394 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900395 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900396 builder.Command().
397 BuiltTool("zipsync").
398 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900399 Input(rootZip).
400 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900401
402 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900403 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900404 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900405 Text(rootDir.String()) // input directory
406 if compressed {
407 cmd.Text("|").
408 BuiltTool("lz4").
409 Flag("--favor-decSpeed"). // for faster boot
410 Flag("-12"). // maximum compression level
411 Flag("-l"). // legacy format for kernel
412 Text(">").Output(output)
413 } else {
414 cmd.Text(">").Output(output)
415 }
Jiyong Park11a65972021-02-01 21:09:38 +0900416
417 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900418 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900419
420 return output
421}
422
Jiyong Park65c49f52020-11-24 14:23:26 +0900423var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
424
425// Implements android.AndroidMkEntriesProvider
426func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
427 return []android.AndroidMkEntries{android.AndroidMkEntries{
428 Class: "ETC",
429 OutputFile: android.OptionalPathForPath(f.output),
430 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700431 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800432 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900433 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
434 },
435 },
436 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900437}
Jiyong Park12a719c2021-01-07 15:31:24 +0900438
Jiyong Park940dfd42021-02-04 15:37:34 +0900439var _ android.OutputFileProducer = (*filesystem)(nil)
440
441// Implements android.OutputFileProducer
442func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
443 if tag == "" {
444 return []android.Path{f.output}, nil
445 }
446 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
447}
448
Jiyong Park12a719c2021-01-07 15:31:24 +0900449// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
450// package to have access to the output file.
451type Filesystem interface {
452 android.Module
453 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900454
455 // Returns the output file that is signed by avbtool. If this module is not signed, returns
456 // nil.
457 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900458}
459
460var _ Filesystem = (*filesystem)(nil)
461
462func (f *filesystem) OutputPath() android.Path {
463 return f.output
464}
Jiyong Park972e06c2021-03-15 23:32:49 +0900465
466func (f *filesystem) SignedOutputPath() android.Path {
467 if proptools.Bool(f.properties.Use_avb) {
468 return f.OutputPath()
469 }
470 return nil
471}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900472
473// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
474// Note that "apex" module installs its contents to "apex"(fake partition) as well
475// for symbol lookup by imitating "activated" paths.
476func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
477 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
478 if f.filterPackagingSpecs != nil {
479 f.filterPackagingSpecs(specs)
480 }
481 return specs
482}
Jooyung Han65f402b2022-04-21 14:24:04 +0900483
484func sha1sum(values []string) string {
485 h := sha256.New()
486 for _, value := range values {
487 io.WriteString(h, value)
488 }
489 return fmt.Sprintf("%x", h.Sum(nil))
490}