blob: 5dc7df64d02ebb7ec572373106097ee13a86630c [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
Shikha Panwar01403bb2022-12-22 12:22:57 +000072 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090073 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090074
Shikha Panwar01403bb2022-12-22 12:22:57 +000075 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
76 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +000077 Avb_hash_algorithm *string
78
Jiyong Parkac4076d2021-03-15 23:21:30 +090079 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
80 Partition_name *string
81
Jiyong Park837cdb22021-02-05 00:17:14 +090082 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
83 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090084 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090085
86 // file_contexts file to make image. Currently, only ext4 is supported.
87 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090088
89 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
90 // (root).
91 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090092
93 // Directories to be created under root. e.g. /dev, /proc, etc.
94 Dirs []string
95
96 // Symbolic links to be created under root with "ln -sf <target> <name>".
97 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +090098
99 // Seconds since unix epoch to override timestamps of file entries
100 Fake_timestamp *string
101
102 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
103 // Otherwise, they'll be set as random which might cause indeterministic build output.
104 Uuid *string
Jiyong Park71baa762021-01-18 21:11:03 +0900105}
106
Jiyong Park65c49f52020-11-24 14:23:26 +0900107// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
108// image. The filesystem images are expected to be mounted in the target device, which means the
109// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
110// The modules are placed in the filesystem image just like they are installed to the ordinary
111// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900112func filesystemFactory() android.Module {
113 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900114 initFilesystemModule(module)
115 return module
116}
117
118func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900119 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900120 android.InitPackageModule(module)
121 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900122}
123
Jiyong Park12a719c2021-01-07 15:31:24 +0900124var dependencyTag = struct {
125 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900126 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900127}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900128
Jiyong Park6f0f6882020-11-12 13:14:30 +0900129func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900130 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900131}
132
Jiyong Park11a65972021-02-01 21:09:38 +0900133type fsType int
134
135const (
136 ext4Type fsType = iota
137 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900138 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900139 unknown
140)
141
142func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
143 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
144 switch typeStr {
145 case "ext4":
146 return ext4Type
147 case "compressed_cpio":
148 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900149 case "cpio":
150 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900151 default:
152 ctx.PropertyErrorf("type", "%q not supported", typeStr)
153 return unknown
154 }
155}
156
Jiyong Park65c49f52020-11-24 14:23:26 +0900157func (f *filesystem) installFileName() string {
158 return f.BaseModuleName() + ".img"
159}
160
Jiyong Park6f0f6882020-11-12 13:14:30 +0900161var pctx = android.NewPackageContext("android/soong/filesystem")
162
163func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900164 switch f.fsType(ctx) {
165 case ext4Type:
166 f.output = f.buildImageUsingBuildImage(ctx)
167 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900168 f.output = f.buildCpioImage(ctx, true)
169 case cpioType:
170 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900171 default:
172 return
173 }
174
175 f.installDir = android.PathForModuleInstall(ctx, "etc")
176 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
177}
178
Jiyong Parkfa616132021-04-20 11:36:40 +0900179// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900180func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
181 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
182 builder := android.NewRuleBuilder(pctx, ctx)
183 builder.Command().Text("rm -rf").Text(rootDir.String())
184 builder.Command().Text("mkdir -p").Text(rootDir.String())
185
Inseob Kim14199b02021-02-09 21:18:31 +0900186 // create dirs and symlinks
187 for _, dir := range f.properties.Dirs {
188 // OutputPath.Join verifies dir
189 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
190 }
191
192 for _, symlink := range f.properties.Symlinks {
193 name := strings.TrimSpace(proptools.String(symlink.Name))
194 target := strings.TrimSpace(proptools.String(symlink.Target))
195
196 if name == "" {
197 ctx.PropertyErrorf("symlinks", "Name can't be empty")
198 continue
199 }
200
201 if target == "" {
202 ctx.PropertyErrorf("symlinks", "Target can't be empty")
203 continue
204 }
205
206 // OutputPath.Join verifies name. don't need to verify target.
207 dst := rootDir.Join(ctx, name)
208
209 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
210 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
211 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900212
Jiyong Parkfa616132021-04-20 11:36:40 +0900213 // create extra files if there's any
214 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
215 var extraFiles android.OutputPaths
216 if f.buildExtraFiles != nil {
217 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
218 for _, f := range extraFiles {
219 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
220 if strings.HasPrefix(rel, "..") {
221 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
222 }
223 }
224 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900225
Jiyong Parkfa616132021-04-20 11:36:40 +0900226 // Zip them all
227 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
228 zipCommand := builder.Command().BuiltTool("soong_zip")
229 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900230 FlagWithArg("-C ", rootDir.String()).
231 Flag("-L 0"). // no compression because this will be unzipped soon
232 FlagWithArg("-D ", rootDir.String()).
233 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900234 if len(extraFiles) > 0 {
235 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
236 for _, f := range extraFiles {
237 zipCommand.FlagWithInput("-f ", f)
238 }
239 }
240
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900241 builder.Command().Text("rm -rf").Text(rootDir.String())
242
243 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
244 return zipOut
245}
246
Jiyong Park11a65972021-02-01 21:09:38 +0900247func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900248 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900249 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900250
251 builder := android.NewRuleBuilder(pctx, ctx)
252 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
253 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
254 builder.Command().
255 BuiltTool("zip2zip").
256 FlagWithInput("-i ", depsZipFile).
257 FlagWithOutput("-o ", rebasedDepsZip).
258 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900259
260 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900261 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900262 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800263 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900264 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900265 Input(rootZip).
266 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900267
Jiyong Park72678312021-01-18 17:29:49 +0900268 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900269 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800270 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900271 Text(rootDir.String()). // input directory
272 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900273 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900274 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900275 Text(rootDir.String()) // directory where to find fs_config_files|dirs
276
277 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800278 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900279
Jiyong Park11a65972021-02-01 21:09:38 +0900280 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900281}
282
Inseob Kimcc8e5362021-02-03 14:05:24 +0900283func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
284 builder := android.NewRuleBuilder(pctx, ctx)
285 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
286 builder.Command().BuiltTool("sefcontext_compile").
287 FlagWithOutput("-o ", fcBin).
288 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
289 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
290 return fcBin.OutputPath
291}
292
Jooyung Han65f402b2022-04-21 14:24:04 +0900293// Calculates avb_salt from entry list (sorted) for deterministic output.
294func (f *filesystem) salt() string {
295 return sha1sum(f.entries)
296}
297
Jiyong Park72678312021-01-18 17:29:49 +0900298func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
299 type prop struct {
300 name string
301 value string
302 }
303
304 var props []prop
305 var deps android.Paths
306 addStr := func(name string, value string) {
307 props = append(props, prop{name, value})
308 }
309 addPath := func(name string, path android.Path) {
310 props = append(props, prop{name, path.String()})
311 deps = append(deps, path)
312 }
313
Jiyong Park11a65972021-02-01 21:09:38 +0900314 // Type string that build_image.py accepts.
315 fsTypeStr := func(t fsType) string {
316 switch t {
317 // TODO(jiyong): add more types like f2fs, erofs, etc.
318 case ext4Type:
319 return "ext4"
320 }
321 panic(fmt.Errorf("unsupported fs type %v", t))
322 }
323
324 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900325 addStr("mount_point", "/")
Jiyong Park72678312021-01-18 17:29:49 +0900326 addStr("use_dynamic_partition_size", "true")
327 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
328 // b/177813163 deps of the host tools have to be added. Remove this.
329 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
330 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
331 }
332
Jiyong Park71baa762021-01-18 21:11:03 +0900333 if proptools.Bool(f.properties.Use_avb) {
334 addStr("avb_hashtree_enable", "true")
335 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
336 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
337 addStr("avb_algorithm", algorithm)
338 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
339 addPath("avb_key_path", key)
Shikha Panware6f30632022-12-21 12:54:45 +0000340 avb_add_hashtree_footer_args := "--do_not_generate_fec"
341 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
342 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
343 }
344 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jiyong Parkac4076d2021-03-15 23:21:30 +0900345 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
346 addStr("partition_name", partitionName)
Jooyung Han65f402b2022-04-21 14:24:04 +0900347 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900348 }
349
Inseob Kimcc8e5362021-02-03 14:05:24 +0900350 if proptools.String(f.properties.File_contexts) != "" {
351 addPath("selinux_fc", f.buildFileContexts(ctx))
352 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900353 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
354 addStr("timestamp", timestamp)
355 }
356 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
357 addStr("uuid", uuid)
358 addStr("hash_seed", uuid)
359 }
Jiyong Park72678312021-01-18 17:29:49 +0900360 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
361 builder := android.NewRuleBuilder(pctx, ctx)
362 builder.Command().Text("rm").Flag("-rf").Output(propFile)
363 for _, p := range props {
364 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900365 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900366 Flag(`"` + p.name + "=" + p.value + `"`).
367 Text(">>").Output(propFile)
368 }
369 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
370 return propFile, deps
371}
372
Jiyong Park837cdb22021-02-05 00:17:14 +0900373func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900374 if proptools.Bool(f.properties.Use_avb) {
375 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
376 "Consider adding this to bootimg module and signing the entire boot image.")
377 }
378
Inseob Kimcc8e5362021-02-03 14:05:24 +0900379 if proptools.String(f.properties.File_contexts) != "" {
380 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
381 }
382
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900383 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900384 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900385
386 builder := android.NewRuleBuilder(pctx, ctx)
387 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
388 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
389 builder.Command().
390 BuiltTool("zip2zip").
391 FlagWithInput("-i ", depsZipFile).
392 FlagWithOutput("-o ", rebasedDepsZip).
393 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900394
395 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900396 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900397 builder.Command().
398 BuiltTool("zipsync").
399 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900400 Input(rootZip).
401 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900402
403 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900404 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900405 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900406 Text(rootDir.String()) // input directory
407 if compressed {
408 cmd.Text("|").
409 BuiltTool("lz4").
410 Flag("--favor-decSpeed"). // for faster boot
411 Flag("-12"). // maximum compression level
412 Flag("-l"). // legacy format for kernel
413 Text(">").Output(output)
414 } else {
415 cmd.Text(">").Output(output)
416 }
Jiyong Park11a65972021-02-01 21:09:38 +0900417
418 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900419 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900420
421 return output
422}
423
Jiyong Park65c49f52020-11-24 14:23:26 +0900424var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
425
426// Implements android.AndroidMkEntriesProvider
427func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
428 return []android.AndroidMkEntries{android.AndroidMkEntries{
429 Class: "ETC",
430 OutputFile: android.OptionalPathForPath(f.output),
431 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700432 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800433 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900434 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
435 },
436 },
437 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900438}
Jiyong Park12a719c2021-01-07 15:31:24 +0900439
Jiyong Park940dfd42021-02-04 15:37:34 +0900440var _ android.OutputFileProducer = (*filesystem)(nil)
441
442// Implements android.OutputFileProducer
443func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
444 if tag == "" {
445 return []android.Path{f.output}, nil
446 }
447 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
448}
449
Jiyong Park12a719c2021-01-07 15:31:24 +0900450// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
451// package to have access to the output file.
452type Filesystem interface {
453 android.Module
454 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900455
456 // Returns the output file that is signed by avbtool. If this module is not signed, returns
457 // nil.
458 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900459}
460
461var _ Filesystem = (*filesystem)(nil)
462
463func (f *filesystem) OutputPath() android.Path {
464 return f.output
465}
Jiyong Park972e06c2021-03-15 23:32:49 +0900466
467func (f *filesystem) SignedOutputPath() android.Path {
468 if proptools.Bool(f.properties.Use_avb) {
469 return f.OutputPath()
470 }
471 return nil
472}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900473
474// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
475// Note that "apex" module installs its contents to "apex"(fake partition) as well
476// for symbol lookup by imitating "activated" paths.
477func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
478 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
479 if f.filterPackagingSpecs != nil {
480 f.filterPackagingSpecs(specs)
481 }
482 return specs
483}
Jooyung Han65f402b2022-04-21 14:24:04 +0900484
485func sha1sum(values []string) string {
486 h := sha256.New()
487 for _, value := range values {
488 io.WriteString(h, value)
489 }
490 return fmt.Sprintf("%x", h.Sum(nil))
491}