blob: 2f6476c82421481a81931a44197efcde30b62bd8 [file] [log] [blame]
Jiyong Park6f0f6882020-11-12 13:14:30 +09001// Copyright (C) 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package filesystem
16
17import (
Jooyung Han65f402b2022-04-21 14:24:04 +090018 "crypto/sha256"
Jiyong Park6f0f6882020-11-12 13:14:30 +090019 "fmt"
Jooyung Han65f402b2022-04-21 14:24:04 +090020 "io"
Inseob Kim14199b02021-02-09 21:18:31 +090021 "path/filepath"
22 "strings"
Jiyong Park6f0f6882020-11-12 13:14:30 +090023
24 "android/soong/android"
Jooyung Hane6067592023-03-16 13:11:17 +090025 "android/soong/cc"
Jiyong Park65b62242020-11-25 12:44:59 +090026
27 "github.com/google/blueprint"
Jiyong Park71baa762021-01-18 21:11:03 +090028 "github.com/google/blueprint/proptools"
Jiyong Park6f0f6882020-11-12 13:14:30 +090029)
30
31func init() {
Jooyung Han9706cbc2021-04-15 22:43:48 +090032 registerBuildComponents(android.InitRegistrationContext)
33}
34
35func registerBuildComponents(ctx android.RegistrationContext) {
36 ctx.RegisterModuleType("android_filesystem", filesystemFactory)
Jiyong Parkfa616132021-04-20 11:36:40 +090037 ctx.RegisterModuleType("android_system_image", systemImageFactory)
Jiyong Parkbc485482022-11-15 22:31:49 +090038 ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090039 ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
Alice Wang000e3a32023-01-03 16:11:20 +000040 ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
Inseob Kim87230e62023-11-22 18:55:07 +090041 ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090042}
43
44type filesystem struct {
45 android.ModuleBase
46 android.PackagingBase
Jiyong Park65c49f52020-11-24 14:23:26 +090047
Jiyong Park71baa762021-01-18 21:11:03 +090048 properties filesystemProperties
49
Jiyong Parkfa616132021-04-20 11:36:40 +090050 // Function that builds extra files under the root directory and returns the files
51 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
52
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090053 // Function that filters PackagingSpecs returned by PackagingBase.GatherPackagingSpecs()
54 filterPackagingSpecs func(specs map[string]android.PackagingSpec)
55
Jiyong Park65c49f52020-11-24 14:23:26 +090056 output android.OutputPath
57 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090058
59 // For testing. Keeps the result of CopyDepsToZip()
60 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090061}
62
Inseob Kim14199b02021-02-09 21:18:31 +090063type symlinkDefinition struct {
64 Target *string
65 Name *string
66}
67
Jiyong Park71baa762021-01-18 21:11:03 +090068type filesystemProperties struct {
69 // When set to true, sign the image with avbtool. Default is false.
70 Use_avb *bool
71
72 // Path to the private key that avbtool will use to sign this filesystem image.
73 // TODO(jiyong): allow apex_key to be specified here
74 Avb_private_key *string `android:"path"`
75
Shikha Panwar01403bb2022-12-22 12:22:57 +000076 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090077 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090078
Shikha Panwar01403bb2022-12-22 12:22:57 +000079 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
80 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +000081 Avb_hash_algorithm *string
82
Jiyong Parkac4076d2021-03-15 23:21:30 +090083 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
84 Partition_name *string
85
Jiyong Park837cdb22021-02-05 00:17:14 +090086 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
87 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090088 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090089
90 // file_contexts file to make image. Currently, only ext4 is supported.
91 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090092
93 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
94 // (root).
95 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090096
97 // Directories to be created under root. e.g. /dev, /proc, etc.
98 Dirs []string
99
100 // Symbolic links to be created under root with "ln -sf <target> <name>".
101 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +0900102
103 // Seconds since unix epoch to override timestamps of file entries
104 Fake_timestamp *string
105
106 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
107 // Otherwise, they'll be set as random which might cause indeterministic build output.
108 Uuid *string
Inseob Kim376d72f2023-11-01 15:40:25 +0900109
110 // Mount point for this image. Default is "/"
111 Mount_point *string
Jiyong Park71baa762021-01-18 21:11:03 +0900112}
113
Jiyong Park65c49f52020-11-24 14:23:26 +0900114// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
115// image. The filesystem images are expected to be mounted in the target device, which means the
116// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
117// The modules are placed in the filesystem image just like they are installed to the ordinary
118// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900119func filesystemFactory() android.Module {
120 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900121 initFilesystemModule(module)
122 return module
123}
124
125func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900126 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900127 android.InitPackageModule(module)
128 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900129}
130
Jiyong Park12a719c2021-01-07 15:31:24 +0900131var dependencyTag = struct {
132 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900133 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900134}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900135
Jiyong Park6f0f6882020-11-12 13:14:30 +0900136func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900137 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900138}
139
Jiyong Park11a65972021-02-01 21:09:38 +0900140type fsType int
141
142const (
143 ext4Type fsType = iota
144 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900145 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900146 unknown
147)
148
149func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
150 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
151 switch typeStr {
152 case "ext4":
153 return ext4Type
154 case "compressed_cpio":
155 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900156 case "cpio":
157 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900158 default:
159 ctx.PropertyErrorf("type", "%q not supported", typeStr)
160 return unknown
161 }
162}
163
Jiyong Park65c49f52020-11-24 14:23:26 +0900164func (f *filesystem) installFileName() string {
165 return f.BaseModuleName() + ".img"
166}
167
Jiyong Park6f0f6882020-11-12 13:14:30 +0900168var pctx = android.NewPackageContext("android/soong/filesystem")
169
170func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900171 switch f.fsType(ctx) {
172 case ext4Type:
173 f.output = f.buildImageUsingBuildImage(ctx)
174 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900175 f.output = f.buildCpioImage(ctx, true)
176 case cpioType:
177 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900178 default:
179 return
180 }
181
182 f.installDir = android.PathForModuleInstall(ctx, "etc")
183 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
184}
185
Jiyong Parkfa616132021-04-20 11:36:40 +0900186// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900187func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
188 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
189 builder := android.NewRuleBuilder(pctx, ctx)
190 builder.Command().Text("rm -rf").Text(rootDir.String())
191 builder.Command().Text("mkdir -p").Text(rootDir.String())
192
Inseob Kim14199b02021-02-09 21:18:31 +0900193 // create dirs and symlinks
194 for _, dir := range f.properties.Dirs {
195 // OutputPath.Join verifies dir
196 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
197 }
198
199 for _, symlink := range f.properties.Symlinks {
200 name := strings.TrimSpace(proptools.String(symlink.Name))
201 target := strings.TrimSpace(proptools.String(symlink.Target))
202
203 if name == "" {
204 ctx.PropertyErrorf("symlinks", "Name can't be empty")
205 continue
206 }
207
208 if target == "" {
209 ctx.PropertyErrorf("symlinks", "Target can't be empty")
210 continue
211 }
212
213 // OutputPath.Join verifies name. don't need to verify target.
214 dst := rootDir.Join(ctx, name)
215
216 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
217 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
218 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900219
Jiyong Parkfa616132021-04-20 11:36:40 +0900220 // create extra files if there's any
221 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
222 var extraFiles android.OutputPaths
223 if f.buildExtraFiles != nil {
224 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
225 for _, f := range extraFiles {
226 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
227 if strings.HasPrefix(rel, "..") {
228 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
229 }
230 }
231 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900232
Jiyong Parkfa616132021-04-20 11:36:40 +0900233 // Zip them all
234 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
235 zipCommand := builder.Command().BuiltTool("soong_zip")
236 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900237 FlagWithArg("-C ", rootDir.String()).
238 Flag("-L 0"). // no compression because this will be unzipped soon
239 FlagWithArg("-D ", rootDir.String()).
240 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900241 if len(extraFiles) > 0 {
242 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
243 for _, f := range extraFiles {
244 zipCommand.FlagWithInput("-f ", f)
245 }
246 }
247
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900248 builder.Command().Text("rm -rf").Text(rootDir.String())
249
250 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
251 return zipOut
252}
253
Jiyong Park11a65972021-02-01 21:09:38 +0900254func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900255 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900256 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900257
258 builder := android.NewRuleBuilder(pctx, ctx)
259 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
260 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
261 builder.Command().
262 BuiltTool("zip2zip").
263 FlagWithInput("-i ", depsZipFile).
264 FlagWithOutput("-o ", rebasedDepsZip).
265 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900266
267 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900268 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900269 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800270 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900271 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900272 Input(rootZip).
273 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900274
Nikita Ioffe519015f2022-12-23 15:36:29 +0000275 // run host_init_verifier
276 // Ideally we should have a concept of pluggable linters that verify the generated image.
277 // While such concept is not implement this will do.
278 // TODO(b/263574231): substitute with pluggable linter.
279 builder.Command().
280 BuiltTool("host_init_verifier").
281 FlagWithArg("--out_system=", rootDir.String()+"/system")
282
Jiyong Park72678312021-01-18 17:29:49 +0900283 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900284 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800285 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900286 Text(rootDir.String()). // input directory
287 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900288 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900289 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900290 Text(rootDir.String()) // directory where to find fs_config_files|dirs
291
292 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800293 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900294
Jiyong Park11a65972021-02-01 21:09:38 +0900295 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900296}
297
Inseob Kimcc8e5362021-02-03 14:05:24 +0900298func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
299 builder := android.NewRuleBuilder(pctx, ctx)
300 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
301 builder.Command().BuiltTool("sefcontext_compile").
302 FlagWithOutput("-o ", fcBin).
303 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
304 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
305 return fcBin.OutputPath
306}
307
Jooyung Han65f402b2022-04-21 14:24:04 +0900308// Calculates avb_salt from entry list (sorted) for deterministic output.
309func (f *filesystem) salt() string {
310 return sha1sum(f.entries)
311}
312
Jiyong Park72678312021-01-18 17:29:49 +0900313func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
314 type prop struct {
315 name string
316 value string
317 }
318
319 var props []prop
320 var deps android.Paths
321 addStr := func(name string, value string) {
322 props = append(props, prop{name, value})
323 }
324 addPath := func(name string, path android.Path) {
325 props = append(props, prop{name, path.String()})
326 deps = append(deps, path)
327 }
328
Jiyong Park11a65972021-02-01 21:09:38 +0900329 // Type string that build_image.py accepts.
330 fsTypeStr := func(t fsType) string {
331 switch t {
332 // TODO(jiyong): add more types like f2fs, erofs, etc.
333 case ext4Type:
334 return "ext4"
335 }
336 panic(fmt.Errorf("unsupported fs type %v", t))
337 }
338
339 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim376d72f2023-11-01 15:40:25 +0900340 addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
Jiyong Park72678312021-01-18 17:29:49 +0900341 addStr("use_dynamic_partition_size", "true")
342 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
343 // b/177813163 deps of the host tools have to be added. Remove this.
344 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
345 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
346 }
347
Jiyong Park71baa762021-01-18 21:11:03 +0900348 if proptools.Bool(f.properties.Use_avb) {
349 addStr("avb_hashtree_enable", "true")
350 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
351 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
352 addStr("avb_algorithm", algorithm)
353 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
354 addPath("avb_key_path", key)
Seungjae Yooa30e4502023-11-09 14:55:44 +0900355 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
356 addStr("partition_name", partitionName)
Shikha Panware6f30632022-12-21 12:54:45 +0000357 avb_add_hashtree_footer_args := "--do_not_generate_fec"
358 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
359 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
360 }
Seungjae Yooa30e4502023-11-09 14:55:44 +0900361 securityPatchKey := "com.android.build." + partitionName + ".security_patch"
362 securityPatchValue := ctx.Config().PlatformSecurityPatch()
363 avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
Shikha Panware6f30632022-12-21 12:54:45 +0000364 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jooyung Han65f402b2022-04-21 14:24:04 +0900365 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900366 }
367
Inseob Kimcc8e5362021-02-03 14:05:24 +0900368 if proptools.String(f.properties.File_contexts) != "" {
369 addPath("selinux_fc", f.buildFileContexts(ctx))
370 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900371 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
372 addStr("timestamp", timestamp)
373 }
374 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
375 addStr("uuid", uuid)
376 addStr("hash_seed", uuid)
377 }
Jiyong Park72678312021-01-18 17:29:49 +0900378 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
379 builder := android.NewRuleBuilder(pctx, ctx)
380 builder.Command().Text("rm").Flag("-rf").Output(propFile)
381 for _, p := range props {
382 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900383 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900384 Flag(`"` + p.name + "=" + p.value + `"`).
385 Text(">>").Output(propFile)
386 }
387 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
388 return propFile, deps
389}
390
Jiyong Park837cdb22021-02-05 00:17:14 +0900391func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900392 if proptools.Bool(f.properties.Use_avb) {
393 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
394 "Consider adding this to bootimg module and signing the entire boot image.")
395 }
396
Inseob Kimcc8e5362021-02-03 14:05:24 +0900397 if proptools.String(f.properties.File_contexts) != "" {
398 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
399 }
400
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900401 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900402 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900403
404 builder := android.NewRuleBuilder(pctx, ctx)
405 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
406 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
407 builder.Command().
408 BuiltTool("zip2zip").
409 FlagWithInput("-i ", depsZipFile).
410 FlagWithOutput("-o ", rebasedDepsZip).
411 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900412
413 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900414 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900415 builder.Command().
416 BuiltTool("zipsync").
417 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900418 Input(rootZip).
419 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900420
421 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900422 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900423 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900424 Text(rootDir.String()) // input directory
425 if compressed {
426 cmd.Text("|").
427 BuiltTool("lz4").
428 Flag("--favor-decSpeed"). // for faster boot
429 Flag("-12"). // maximum compression level
430 Flag("-l"). // legacy format for kernel
431 Text(">").Output(output)
432 } else {
433 cmd.Text(">").Output(output)
434 }
Jiyong Park11a65972021-02-01 21:09:38 +0900435
436 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900437 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900438
439 return output
440}
441
Jiyong Park65c49f52020-11-24 14:23:26 +0900442var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
443
444// Implements android.AndroidMkEntriesProvider
445func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
446 return []android.AndroidMkEntries{android.AndroidMkEntries{
447 Class: "ETC",
448 OutputFile: android.OptionalPathForPath(f.output),
449 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700450 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800451 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900452 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
453 },
454 },
455 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900456}
Jiyong Park12a719c2021-01-07 15:31:24 +0900457
Jiyong Park940dfd42021-02-04 15:37:34 +0900458var _ android.OutputFileProducer = (*filesystem)(nil)
459
460// Implements android.OutputFileProducer
461func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
462 if tag == "" {
463 return []android.Path{f.output}, nil
464 }
465 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
466}
467
Jiyong Park12a719c2021-01-07 15:31:24 +0900468// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
469// package to have access to the output file.
470type Filesystem interface {
471 android.Module
472 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900473
474 // Returns the output file that is signed by avbtool. If this module is not signed, returns
475 // nil.
476 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900477}
478
479var _ Filesystem = (*filesystem)(nil)
480
481func (f *filesystem) OutputPath() android.Path {
482 return f.output
483}
Jiyong Park972e06c2021-03-15 23:32:49 +0900484
485func (f *filesystem) SignedOutputPath() android.Path {
486 if proptools.Bool(f.properties.Use_avb) {
487 return f.OutputPath()
488 }
489 return nil
490}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900491
492// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
493// Note that "apex" module installs its contents to "apex"(fake partition) as well
494// for symbol lookup by imitating "activated" paths.
495func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
496 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
497 if f.filterPackagingSpecs != nil {
498 f.filterPackagingSpecs(specs)
499 }
500 return specs
501}
Jooyung Han65f402b2022-04-21 14:24:04 +0900502
503func sha1sum(values []string) string {
504 h := sha256.New()
505 for _, value := range values {
506 io.WriteString(h, value)
507 }
508 return fmt.Sprintf("%x", h.Sum(nil))
509}
Jooyung Hane6067592023-03-16 13:11:17 +0900510
511// Base cc.UseCoverage
512
513var _ cc.UseCoverage = (*filesystem)(nil)
514
Colin Crossf5f4ad32024-01-19 15:41:48 -0800515func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool {
Jooyung Hane6067592023-03-16 13:11:17 +0900516 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
517}