blob: 3d491145b31f12173a21e8e566b76f80ff9fcbb5 [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)
Alice Wang000e3a32023-01-03 16:11:20 +000039 ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
Jiyong Park6f0f6882020-11-12 13:14:30 +090040}
41
42type filesystem struct {
43 android.ModuleBase
44 android.PackagingBase
Jiyong Park65c49f52020-11-24 14:23:26 +090045
Jiyong Park71baa762021-01-18 21:11:03 +090046 properties filesystemProperties
47
Jiyong Parkfa616132021-04-20 11:36:40 +090048 // Function that builds extra files under the root directory and returns the files
49 buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
50
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090051 // Function that filters PackagingSpecs returned by PackagingBase.GatherPackagingSpecs()
52 filterPackagingSpecs func(specs map[string]android.PackagingSpec)
53
Jiyong Park65c49f52020-11-24 14:23:26 +090054 output android.OutputPath
55 installDir android.InstallPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +090056
57 // For testing. Keeps the result of CopyDepsToZip()
58 entries []string
Jiyong Park6f0f6882020-11-12 13:14:30 +090059}
60
Inseob Kim14199b02021-02-09 21:18:31 +090061type symlinkDefinition struct {
62 Target *string
63 Name *string
64}
65
Jiyong Park71baa762021-01-18 21:11:03 +090066type filesystemProperties struct {
67 // When set to true, sign the image with avbtool. Default is false.
68 Use_avb *bool
69
70 // Path to the private key that avbtool will use to sign this filesystem image.
71 // TODO(jiyong): allow apex_key to be specified here
72 Avb_private_key *string `android:"path"`
73
Shikha Panwar01403bb2022-12-22 12:22:57 +000074 // Signing algorithm for avbtool. Default is SHA256_RSA4096.
Jiyong Park71baa762021-01-18 21:11:03 +090075 Avb_algorithm *string
Jiyong Park11a65972021-02-01 21:09:38 +090076
Shikha Panwar01403bb2022-12-22 12:22:57 +000077 // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
78 // avbtool. Default used by avbtool is sha1.
Shikha Panware6f30632022-12-21 12:54:45 +000079 Avb_hash_algorithm *string
80
Jiyong Parkac4076d2021-03-15 23:21:30 +090081 // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
82 Partition_name *string
83
Jiyong Park837cdb22021-02-05 00:17:14 +090084 // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
85 // is ext4.
Jiyong Park11a65972021-02-01 21:09:38 +090086 Type *string
Inseob Kimcc8e5362021-02-03 14:05:24 +090087
88 // file_contexts file to make image. Currently, only ext4 is supported.
89 File_contexts *string `android:"path"`
Inseob Kim2ce1b5d2021-02-15 17:01:04 +090090
91 // Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
92 // (root).
93 Base_dir *string
Inseob Kim14199b02021-02-09 21:18:31 +090094
95 // Directories to be created under root. e.g. /dev, /proc, etc.
96 Dirs []string
97
98 // Symbolic links to be created under root with "ln -sf <target> <name>".
99 Symlinks []symlinkDefinition
Jooyung Han65f402b2022-04-21 14:24:04 +0900100
101 // Seconds since unix epoch to override timestamps of file entries
102 Fake_timestamp *string
103
104 // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
105 // Otherwise, they'll be set as random which might cause indeterministic build output.
106 Uuid *string
Inseob Kim376d72f2023-11-01 15:40:25 +0900107
108 // Mount point for this image. Default is "/"
109 Mount_point *string
Jiyong Park71baa762021-01-18 21:11:03 +0900110}
111
Jiyong Park65c49f52020-11-24 14:23:26 +0900112// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
113// image. The filesystem images are expected to be mounted in the target device, which means the
114// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
115// The modules are placed in the filesystem image just like they are installed to the ordinary
116// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
Jiyong Park6f0f6882020-11-12 13:14:30 +0900117func filesystemFactory() android.Module {
118 module := &filesystem{}
Jiyong Parkfa616132021-04-20 11:36:40 +0900119 initFilesystemModule(module)
120 return module
121}
122
123func initFilesystemModule(module *filesystem) {
Jiyong Park71baa762021-01-18 21:11:03 +0900124 module.AddProperties(&module.properties)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900125 android.InitPackageModule(module)
126 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900127}
128
Jiyong Park12a719c2021-01-07 15:31:24 +0900129var dependencyTag = struct {
130 blueprint.BaseDependencyTag
Jooyung Han092ef812021-03-10 15:40:34 +0900131 android.PackagingItemAlwaysDepTag
Jiyong Park12a719c2021-01-07 15:31:24 +0900132}{}
Jiyong Park65b62242020-11-25 12:44:59 +0900133
Jiyong Park6f0f6882020-11-12 13:14:30 +0900134func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Park65b62242020-11-25 12:44:59 +0900135 f.AddDeps(ctx, dependencyTag)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900136}
137
Jiyong Park11a65972021-02-01 21:09:38 +0900138type fsType int
139
140const (
141 ext4Type fsType = iota
142 compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900143 cpioType // uncompressed
Jiyong Park11a65972021-02-01 21:09:38 +0900144 unknown
145)
146
147func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
148 typeStr := proptools.StringDefault(f.properties.Type, "ext4")
149 switch typeStr {
150 case "ext4":
151 return ext4Type
152 case "compressed_cpio":
153 return compressedCpioType
Jiyong Park837cdb22021-02-05 00:17:14 +0900154 case "cpio":
155 return cpioType
Jiyong Park11a65972021-02-01 21:09:38 +0900156 default:
157 ctx.PropertyErrorf("type", "%q not supported", typeStr)
158 return unknown
159 }
160}
161
Jiyong Park65c49f52020-11-24 14:23:26 +0900162func (f *filesystem) installFileName() string {
163 return f.BaseModuleName() + ".img"
164}
165
Jiyong Park6f0f6882020-11-12 13:14:30 +0900166var pctx = android.NewPackageContext("android/soong/filesystem")
167
168func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park11a65972021-02-01 21:09:38 +0900169 switch f.fsType(ctx) {
170 case ext4Type:
171 f.output = f.buildImageUsingBuildImage(ctx)
172 case compressedCpioType:
Jiyong Park837cdb22021-02-05 00:17:14 +0900173 f.output = f.buildCpioImage(ctx, true)
174 case cpioType:
175 f.output = f.buildCpioImage(ctx, false)
Jiyong Park11a65972021-02-01 21:09:38 +0900176 default:
177 return
178 }
179
180 f.installDir = android.PathForModuleInstall(ctx, "etc")
181 ctx.InstallFile(f.installDir, f.installFileName(), f.output)
182}
183
Jiyong Parkfa616132021-04-20 11:36:40 +0900184// root zip will contain extra files/dirs that are not from the `deps` property.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900185func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath {
186 rootDir := android.PathForModuleGen(ctx, "root").OutputPath
187 builder := android.NewRuleBuilder(pctx, ctx)
188 builder.Command().Text("rm -rf").Text(rootDir.String())
189 builder.Command().Text("mkdir -p").Text(rootDir.String())
190
Inseob Kim14199b02021-02-09 21:18:31 +0900191 // create dirs and symlinks
192 for _, dir := range f.properties.Dirs {
193 // OutputPath.Join verifies dir
194 builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
195 }
196
197 for _, symlink := range f.properties.Symlinks {
198 name := strings.TrimSpace(proptools.String(symlink.Name))
199 target := strings.TrimSpace(proptools.String(symlink.Target))
200
201 if name == "" {
202 ctx.PropertyErrorf("symlinks", "Name can't be empty")
203 continue
204 }
205
206 if target == "" {
207 ctx.PropertyErrorf("symlinks", "Target can't be empty")
208 continue
209 }
210
211 // OutputPath.Join verifies name. don't need to verify target.
212 dst := rootDir.Join(ctx, name)
213
214 builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
215 builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
216 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900217
Jiyong Parkfa616132021-04-20 11:36:40 +0900218 // create extra files if there's any
219 rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
220 var extraFiles android.OutputPaths
221 if f.buildExtraFiles != nil {
222 extraFiles = f.buildExtraFiles(ctx, rootForExtraFiles)
223 for _, f := range extraFiles {
224 rel, _ := filepath.Rel(rootForExtraFiles.String(), f.String())
225 if strings.HasPrefix(rel, "..") {
226 panic(fmt.Errorf("%q is not under %q\n", f, rootForExtraFiles))
227 }
228 }
229 }
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900230
Jiyong Parkfa616132021-04-20 11:36:40 +0900231 // Zip them all
232 zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath
233 zipCommand := builder.Command().BuiltTool("soong_zip")
234 zipCommand.FlagWithOutput("-o ", zipOut).
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900235 FlagWithArg("-C ", rootDir.String()).
236 Flag("-L 0"). // no compression because this will be unzipped soon
237 FlagWithArg("-D ", rootDir.String()).
238 Flag("-d") // include empty directories
Jiyong Parkfa616132021-04-20 11:36:40 +0900239 if len(extraFiles) > 0 {
240 zipCommand.FlagWithArg("-C ", rootForExtraFiles.String())
241 for _, f := range extraFiles {
242 zipCommand.FlagWithInput("-f ", f)
243 }
244 }
245
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900246 builder.Command().Text("rm -rf").Text(rootDir.String())
247
248 builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName()))
249 return zipOut
250}
251
Jiyong Park11a65972021-02-01 21:09:38 +0900252func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900253 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900254 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900255
256 builder := android.NewRuleBuilder(pctx, ctx)
257 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
258 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
259 builder.Command().
260 BuiltTool("zip2zip").
261 FlagWithInput("-i ", depsZipFile).
262 FlagWithOutput("-o ", rebasedDepsZip).
263 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park6f0f6882020-11-12 13:14:30 +0900264
265 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900266 rootZip := f.buildRootZip(ctx)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900267 builder.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800268 BuiltTool("zipsync").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900269 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900270 Input(rootZip).
271 Input(rebasedDepsZip)
Jiyong Park6f0f6882020-11-12 13:14:30 +0900272
Nikita Ioffe519015f2022-12-23 15:36:29 +0000273 // run host_init_verifier
274 // Ideally we should have a concept of pluggable linters that verify the generated image.
275 // While such concept is not implement this will do.
276 // TODO(b/263574231): substitute with pluggable linter.
277 builder.Command().
278 BuiltTool("host_init_verifier").
279 FlagWithArg("--out_system=", rootDir.String()+"/system")
280
Jiyong Park72678312021-01-18 17:29:49 +0900281 propFile, toolDeps := f.buildPropFile(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900282 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Colin Crossf1a035e2020-11-16 17:32:30 -0800283 builder.Command().BuiltTool("build_image").
Jiyong Park6f0f6882020-11-12 13:14:30 +0900284 Text(rootDir.String()). // input directory
285 Input(propFile).
Jiyong Park72678312021-01-18 17:29:49 +0900286 Implicits(toolDeps).
Jiyong Park11a65972021-02-01 21:09:38 +0900287 Output(output).
Jiyong Park6f0f6882020-11-12 13:14:30 +0900288 Text(rootDir.String()) // directory where to find fs_config_files|dirs
289
290 // rootDir is not deleted. Might be useful for quick inspection.
Colin Crossf1a035e2020-11-16 17:32:30 -0800291 builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park65c49f52020-11-24 14:23:26 +0900292
Jiyong Park11a65972021-02-01 21:09:38 +0900293 return output
Jiyong Park65c49f52020-11-24 14:23:26 +0900294}
295
Inseob Kimcc8e5362021-02-03 14:05:24 +0900296func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
297 builder := android.NewRuleBuilder(pctx, ctx)
298 fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
299 builder.Command().BuiltTool("sefcontext_compile").
300 FlagWithOutput("-o ", fcBin).
301 Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
302 builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
303 return fcBin.OutputPath
304}
305
Jooyung Han65f402b2022-04-21 14:24:04 +0900306// Calculates avb_salt from entry list (sorted) for deterministic output.
307func (f *filesystem) salt() string {
308 return sha1sum(f.entries)
309}
310
Jiyong Park72678312021-01-18 17:29:49 +0900311func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
312 type prop struct {
313 name string
314 value string
315 }
316
317 var props []prop
318 var deps android.Paths
319 addStr := func(name string, value string) {
320 props = append(props, prop{name, value})
321 }
322 addPath := func(name string, path android.Path) {
323 props = append(props, prop{name, path.String()})
324 deps = append(deps, path)
325 }
326
Jiyong Park11a65972021-02-01 21:09:38 +0900327 // Type string that build_image.py accepts.
328 fsTypeStr := func(t fsType) string {
329 switch t {
330 // TODO(jiyong): add more types like f2fs, erofs, etc.
331 case ext4Type:
332 return "ext4"
333 }
334 panic(fmt.Errorf("unsupported fs type %v", t))
335 }
336
337 addStr("fs_type", fsTypeStr(f.fsType(ctx)))
Inseob Kim376d72f2023-11-01 15:40:25 +0900338 addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
Jiyong Park72678312021-01-18 17:29:49 +0900339 addStr("use_dynamic_partition_size", "true")
340 addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
341 // b/177813163 deps of the host tools have to be added. Remove this.
342 for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
343 deps = append(deps, ctx.Config().HostToolPath(ctx, t))
344 }
345
Jiyong Park71baa762021-01-18 21:11:03 +0900346 if proptools.Bool(f.properties.Use_avb) {
347 addStr("avb_hashtree_enable", "true")
348 addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
349 algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
350 addStr("avb_algorithm", algorithm)
351 key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
352 addPath("avb_key_path", key)
Seungjae Yooa30e4502023-11-09 14:55:44 +0900353 partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
354 addStr("partition_name", partitionName)
Shikha Panware6f30632022-12-21 12:54:45 +0000355 avb_add_hashtree_footer_args := "--do_not_generate_fec"
356 if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
357 avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
358 }
Seungjae Yooa30e4502023-11-09 14:55:44 +0900359 securityPatchKey := "com.android.build." + partitionName + ".security_patch"
360 securityPatchValue := ctx.Config().PlatformSecurityPatch()
361 avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
Shikha Panware6f30632022-12-21 12:54:45 +0000362 addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
Jooyung Han65f402b2022-04-21 14:24:04 +0900363 addStr("avb_salt", f.salt())
Jiyong Park71baa762021-01-18 21:11:03 +0900364 }
365
Inseob Kimcc8e5362021-02-03 14:05:24 +0900366 if proptools.String(f.properties.File_contexts) != "" {
367 addPath("selinux_fc", f.buildFileContexts(ctx))
368 }
Jooyung Han65f402b2022-04-21 14:24:04 +0900369 if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
370 addStr("timestamp", timestamp)
371 }
372 if uuid := proptools.String(f.properties.Uuid); uuid != "" {
373 addStr("uuid", uuid)
374 addStr("hash_seed", uuid)
375 }
Jiyong Park72678312021-01-18 17:29:49 +0900376 propFile = android.PathForModuleOut(ctx, "prop").OutputPath
377 builder := android.NewRuleBuilder(pctx, ctx)
378 builder.Command().Text("rm").Flag("-rf").Output(propFile)
379 for _, p := range props {
380 builder.Command().
Jiyong Park3db465d2021-01-26 14:08:16 +0900381 Text("echo").
Jiyong Park72678312021-01-18 17:29:49 +0900382 Flag(`"` + p.name + "=" + p.value + `"`).
383 Text(">>").Output(propFile)
384 }
385 builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName()))
386 return propFile, deps
387}
388
Jiyong Park837cdb22021-02-05 00:17:14 +0900389func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
Jiyong Park11a65972021-02-01 21:09:38 +0900390 if proptools.Bool(f.properties.Use_avb) {
391 ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
392 "Consider adding this to bootimg module and signing the entire boot image.")
393 }
394
Inseob Kimcc8e5362021-02-03 14:05:24 +0900395 if proptools.String(f.properties.File_contexts) != "" {
396 ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
397 }
398
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900399 depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900400 f.entries = f.CopyDepsToZip(ctx, f.gatherFilteredPackagingSpecs(ctx), depsZipFile)
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900401
402 builder := android.NewRuleBuilder(pctx, ctx)
403 depsBase := proptools.StringDefault(f.properties.Base_dir, ".")
404 rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath
405 builder.Command().
406 BuiltTool("zip2zip").
407 FlagWithInput("-i ", depsZipFile).
408 FlagWithOutput("-o ", rebasedDepsZip).
409 Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase
Jiyong Park11a65972021-02-01 21:09:38 +0900410
411 rootDir := android.PathForModuleOut(ctx, "root").OutputPath
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900412 rootZip := f.buildRootZip(ctx)
Jiyong Park11a65972021-02-01 21:09:38 +0900413 builder.Command().
414 BuiltTool("zipsync").
415 FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
Inseob Kim2ce1b5d2021-02-15 17:01:04 +0900416 Input(rootZip).
417 Input(rebasedDepsZip)
Jiyong Park11a65972021-02-01 21:09:38 +0900418
419 output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
Jiyong Park837cdb22021-02-05 00:17:14 +0900420 cmd := builder.Command().
Jiyong Park11a65972021-02-01 21:09:38 +0900421 BuiltTool("mkbootfs").
Jiyong Park837cdb22021-02-05 00:17:14 +0900422 Text(rootDir.String()) // input directory
423 if compressed {
424 cmd.Text("|").
425 BuiltTool("lz4").
426 Flag("--favor-decSpeed"). // for faster boot
427 Flag("-12"). // maximum compression level
428 Flag("-l"). // legacy format for kernel
429 Text(">").Output(output)
430 } else {
431 cmd.Text(">").Output(output)
432 }
Jiyong Park11a65972021-02-01 21:09:38 +0900433
434 // rootDir is not deleted. Might be useful for quick inspection.
Jiyong Park837cdb22021-02-05 00:17:14 +0900435 builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
Jiyong Park11a65972021-02-01 21:09:38 +0900436
437 return output
438}
439
Jiyong Park65c49f52020-11-24 14:23:26 +0900440var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
441
442// Implements android.AndroidMkEntriesProvider
443func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
444 return []android.AndroidMkEntries{android.AndroidMkEntries{
445 Class: "ETC",
446 OutputFile: android.OptionalPathForPath(f.output),
447 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700448 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Colin Crossc68db4b2021-11-11 18:59:15 -0800449 entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
Jiyong Park65c49f52020-11-24 14:23:26 +0900450 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
451 },
452 },
453 }}
Jiyong Park6f0f6882020-11-12 13:14:30 +0900454}
Jiyong Park12a719c2021-01-07 15:31:24 +0900455
Jiyong Park940dfd42021-02-04 15:37:34 +0900456var _ android.OutputFileProducer = (*filesystem)(nil)
457
458// Implements android.OutputFileProducer
459func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
460 if tag == "" {
461 return []android.Path{f.output}, nil
462 }
463 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
464}
465
Jiyong Park12a719c2021-01-07 15:31:24 +0900466// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
467// package to have access to the output file.
468type Filesystem interface {
469 android.Module
470 OutputPath() android.Path
Jiyong Park972e06c2021-03-15 23:32:49 +0900471
472 // Returns the output file that is signed by avbtool. If this module is not signed, returns
473 // nil.
474 SignedOutputPath() android.Path
Jiyong Park12a719c2021-01-07 15:31:24 +0900475}
476
477var _ Filesystem = (*filesystem)(nil)
478
479func (f *filesystem) OutputPath() android.Path {
480 return f.output
481}
Jiyong Park972e06c2021-03-15 23:32:49 +0900482
483func (f *filesystem) SignedOutputPath() android.Path {
484 if proptools.Bool(f.properties.Use_avb) {
485 return f.OutputPath()
486 }
487 return nil
488}
Jooyung Han0fbbc2b2022-03-25 12:35:46 +0900489
490// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
491// Note that "apex" module installs its contents to "apex"(fake partition) as well
492// for symbol lookup by imitating "activated" paths.
493func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
494 specs := f.PackagingBase.GatherPackagingSpecs(ctx)
495 if f.filterPackagingSpecs != nil {
496 f.filterPackagingSpecs(specs)
497 }
498 return specs
499}
Jooyung Han65f402b2022-04-21 14:24:04 +0900500
501func sha1sum(values []string) string {
502 h := sha256.New()
503 for _, value := range values {
504 io.WriteString(h, value)
505 }
506 return fmt.Sprintf("%x", h.Sum(nil))
507}
Jooyung Hane6067592023-03-16 13:11:17 +0900508
509// Base cc.UseCoverage
510
511var _ cc.UseCoverage = (*filesystem)(nil)
512
513func (*filesystem) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
514 return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
515}