blob: d01608f33aa083d27dfe042b306a238d0979a8f8 [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
Nikita Ioffe519015f2022-12-23 15:36:29 +0000267 // run host_init_verifier
268 // Ideally we should have a concept of pluggable linters that verify the generated image.
269 // While such concept is not implement this will do.
270 // TODO(b/263574231): substitute with pluggable linter.
271 builder.Command().
272 BuiltTool("host_init_verifier").
273 FlagWithArg("--out_system=", rootDir.String()+"/system")
274
Jiyong Park72678312021-01-18 17:29:49 +0900275 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900276 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800277 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900278 Text(rootDir.String()). // input directory
279 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900280 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900281 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900282 Text(rootDir.String()) // directory where to find fs_config_files|dirs
283
284 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800285 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900286
Jiyong Park11a65972021-02-01 21:09:38 +0900287 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900288}
289
Inseob Kimcc8e5362021-02-03 14:05:24 +0900290func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
291 builder := android.NewRuleBuilder(pctx, ctx)
292 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
293 builder.Command().BuiltTool("sefcontext_compile").
294 FlagWithOutput("-o ", fcBin).
295 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
296 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
297 return fcBin.OutputPath
298}
299
Jooyung Han65f402b2022-04-21 14:24:04 +0900300// Calculates avb_salt from entry list (sorted) for deterministic output.
301func (f *filesystem) salt() string {
302 return sha1sum(f.entries)
303}
304
Jiyong Park72678312021-01-18 17:29:49 +0900305func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
306 type prop struct {
307 name string
308 value string
309 }
310
311 var props []prop
312 var deps android.Paths
313 addStr := func(name string, value string) {
314 props = append(props, prop{name, value})
315 }
316 addPath := func(name string, path android.Path) {
317 props = append(props, prop{name, path.String()})
318 deps = append(deps, path)
319 }
320
Jiyong Park11a65972021-02-01 21:09:38 +0900321 // Type string that build_image.py accepts.
322 fsTypeStr := func(t fsType) string {
323 switch t {
324 // TODO(jiyong): add more types like f2fs, erofs, etc.
325 case ext4Type:
326 return "ext4"
327 }
328 panic(fmt.Errorf("unsupported fs type %v", t))
329 }
330
331 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900332 addStr("mount_point", "/")
Jiyong Park72678312021-01-18 17:29:49 +0900333 addStr("use_dynamic_partition_size", "true")
334 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
335 // b/177813163 deps of the host tools have to be added. Remove this.
336 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
337 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
338 }
339
Jiyong Park71baa762021-01-18 21:11:03 +0900340 if proptools.Bool(f.properties.Use_avb) {
341 addStr("avb_hashtree_enable", "true")
342 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
343 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
344 addStr("avb_algorithm", algorithm)
345 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
346 addPath("avb_key_path", key)
Shikha Panware6f30632022-12-21 12:54:45 +0000347 avb_add_hashtree_footer_args := "--do_not_generate_fec"
348 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
349 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
350 }
351 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jiyong Parkac4076d2021-03-15 23:21:30 +0900352 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
353 addStr("partition_name", partitionName)
Jooyung Han65f402b2022-04-21 14:24:04 +0900354 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900355 }
356
Inseob Kimcc8e5362021-02-03 14:05:24 +0900357 if proptools.String(f.properties.File_contexts) != "" {
358 addPath("selinux_fc", f.buildFileContexts(ctx))
359 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900360 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
361 addStr("timestamp", timestamp)
362 }
363 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
364 addStr("uuid", uuid)
365 addStr("hash_seed", uuid)
366 }
Jiyong Park72678312021-01-18 17:29:49 +0900367 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
368 builder := android.NewRuleBuilder(pctx, ctx)
369 builder.Command().Text("rm").Flag("-rf").Output(propFile)
370 for _, p := range props {
371 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900372 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900373 Flag(`"` + p.name + "=" + p.value + `"`).
374 Text(">>").Output(propFile)
375 }
376 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
377 return propFile, deps
378}
379
Jiyong Park837cdb22021-02-05 00:17:14 +0900380func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900381 if proptools.Bool(f.properties.Use_avb) {
382 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
383 "Consider adding this to bootimg module and signing the entire boot image.")
384 }
385
Inseob Kimcc8e5362021-02-03 14:05:24 +0900386 if proptools.String(f.properties.File_contexts) != "" {
387 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
388 }
389
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900390 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900391 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900392
393 builder := android.NewRuleBuilder(pctx, ctx)
394 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
395 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
396 builder.Command().
397 BuiltTool("zip2zip").
398 FlagWithInput("-i ", depsZipFile).
399 FlagWithOutput("-o ", rebasedDepsZip).
400 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900401
402 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900403 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900404 builder.Command().
405 BuiltTool("zipsync").
406 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900407 Input(rootZip).
408 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900409
410 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900411 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900412 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900413 Text(rootDir.String()) // input directory
414 if compressed {
415 cmd.Text("|").
416 BuiltTool("lz4").
417 Flag("--favor-decSpeed"). // for faster boot
418 Flag("-12"). // maximum compression level
419 Flag("-l"). // legacy format for kernel
420 Text(">").Output(output)
421 } else {
422 cmd.Text(">").Output(output)
423 }
Jiyong Park11a65972021-02-01 21:09:38 +0900424
425 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900426 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900427
428 return output
429}
430
Jiyong Park65c49f52020-11-24 14:23:26 +0900431var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
432
433// Implements android.AndroidMkEntriesProvider
434func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
435 return []android.AndroidMkEntries{android.AndroidMkEntries{
436 Class: "ETC",
437 OutputFile: android.OptionalPathForPath(f.output),
438 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700439 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800440 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900441 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
442 },
443 },
444 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900445}
Jiyong Park12a719c2021-01-07 15:31:24 +0900446
Jiyong Park940dfd42021-02-04 15:37:34 +0900447var _ android.OutputFileProducer = (*filesystem)(nil)
448
449// Implements android.OutputFileProducer
450func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
451 if tag == "" {
452 return []android.Path{f.output}, nil
453 }
454 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
455}
456
Jiyong Park12a719c2021-01-07 15:31:24 +0900457// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
458// package to have access to the output file.
459type Filesystem interface {
460 android.Module
461 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900462
463 // Returns the output file that is signed by avbtool. If this module is not signed, returns
464 // nil.
465 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900466}
467
468var _ Filesystem = (*filesystem)(nil)
469
470func (f *filesystem) OutputPath() android.Path {
471 return f.output
472}
Jiyong Park972e06c2021-03-15 23:32:49 +0900473
474func (f *filesystem) SignedOutputPath() android.Path {
475 if proptools.Bool(f.properties.Use_avb) {
476 return f.OutputPath()
477 }
478 return nil
479}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900480
481// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
482// Note that "apex" module installs its contents to "apex"(fake partition) as well
483// for symbol lookup by imitating "activated" paths.
484func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
485 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
486 if f.filterPackagingSpecs != nil {
487 f.filterPackagingSpecs(specs)
488 }
489 return specs
490}
Jooyung Han65f402b2022-04-21 14:24:04 +0900491
492func sha1sum(values []string) string {
493 h := sha256.New()
494 for _, value := range values {
495 io.WriteString(h, value)
496 }
497 return fmt.Sprintf("%x", h.Sum(nil))
498}