Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package filesystem |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 19 | "path/filepath" |
| 20 | "strings" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 21 | |
| 22 | "android/soong/android" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint" |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 25 | "github.com/google/blueprint/proptools" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func init() { |
| 29 | android.RegisterModuleType("android_filesystem", filesystemFactory) |
| 30 | } |
| 31 | |
| 32 | type filesystem struct { |
| 33 | android.ModuleBase |
| 34 | android.PackagingBase |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 35 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 36 | properties filesystemProperties |
| 37 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 38 | output android.OutputPath |
| 39 | installDir android.InstallPath |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 40 | } |
| 41 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 42 | type symlinkDefinition struct { |
| 43 | Target *string |
| 44 | Name *string |
| 45 | } |
| 46 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 47 | type filesystemProperties struct { |
| 48 | // When set to true, sign the image with avbtool. Default is false. |
| 49 | Use_avb *bool |
| 50 | |
| 51 | // Path to the private key that avbtool will use to sign this filesystem image. |
| 52 | // TODO(jiyong): allow apex_key to be specified here |
| 53 | Avb_private_key *string `android:"path"` |
| 54 | |
| 55 | // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096. |
| 56 | Avb_algorithm *string |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 57 | |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 58 | // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default |
| 59 | // is ext4. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 60 | Type *string |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 61 | |
| 62 | // file_contexts file to make image. Currently, only ext4 is supported. |
| 63 | File_contexts *string `android:"path"` |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 64 | |
| 65 | // Base directory relative to root, to which deps are installed, e.g. "system". Default is "." |
| 66 | // (root). |
| 67 | Base_dir *string |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 68 | |
| 69 | // Directories to be created under root. e.g. /dev, /proc, etc. |
| 70 | Dirs []string |
| 71 | |
| 72 | // Symbolic links to be created under root with "ln -sf <target> <name>". |
| 73 | Symlinks []symlinkDefinition |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 74 | } |
| 75 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 76 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem |
| 77 | // image. The filesystem images are expected to be mounted in the target device, which means the |
| 78 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). |
| 79 | // The modules are placed in the filesystem image just like they are installed to the ordinary |
| 80 | // partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory. |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 81 | func filesystemFactory() android.Module { |
| 82 | module := &filesystem{} |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 83 | module.AddProperties(&module.properties) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 84 | android.InitPackageModule(module) |
| 85 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 86 | return module |
| 87 | } |
| 88 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 89 | var dependencyTag = struct { |
| 90 | blueprint.BaseDependencyTag |
| 91 | android.InstallAlwaysNeededDependencyTag |
| 92 | }{} |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 93 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 94 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 95 | f.AddDeps(ctx, dependencyTag) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 96 | } |
| 97 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 98 | type fsType int |
| 99 | |
| 100 | const ( |
| 101 | ext4Type fsType = iota |
| 102 | compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 103 | cpioType // uncompressed |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 104 | unknown |
| 105 | ) |
| 106 | |
| 107 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { |
| 108 | typeStr := proptools.StringDefault(f.properties.Type, "ext4") |
| 109 | switch typeStr { |
| 110 | case "ext4": |
| 111 | return ext4Type |
| 112 | case "compressed_cpio": |
| 113 | return compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 114 | case "cpio": |
| 115 | return cpioType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 116 | default: |
| 117 | ctx.PropertyErrorf("type", "%q not supported", typeStr) |
| 118 | return unknown |
| 119 | } |
| 120 | } |
| 121 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 122 | func (f *filesystem) installFileName() string { |
| 123 | return f.BaseModuleName() + ".img" |
| 124 | } |
| 125 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 126 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 127 | |
| 128 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 129 | switch f.fsType(ctx) { |
| 130 | case ext4Type: |
| 131 | f.output = f.buildImageUsingBuildImage(ctx) |
| 132 | case compressedCpioType: |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 133 | f.output = f.buildCpioImage(ctx, true) |
| 134 | case cpioType: |
| 135 | f.output = f.buildCpioImage(ctx, false) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 136 | default: |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | f.installDir = android.PathForModuleInstall(ctx, "etc") |
| 141 | ctx.InstallFile(f.installDir, f.installFileName(), f.output) |
| 142 | } |
| 143 | |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 144 | // root zip will contain stuffs like dirs or symlinks. |
| 145 | func (f *filesystem) buildRootZip(ctx android.ModuleContext) android.OutputPath { |
| 146 | rootDir := android.PathForModuleGen(ctx, "root").OutputPath |
| 147 | builder := android.NewRuleBuilder(pctx, ctx) |
| 148 | builder.Command().Text("rm -rf").Text(rootDir.String()) |
| 149 | builder.Command().Text("mkdir -p").Text(rootDir.String()) |
| 150 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 151 | // create dirs and symlinks |
| 152 | for _, dir := range f.properties.Dirs { |
| 153 | // OutputPath.Join verifies dir |
| 154 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) |
| 155 | } |
| 156 | |
| 157 | for _, symlink := range f.properties.Symlinks { |
| 158 | name := strings.TrimSpace(proptools.String(symlink.Name)) |
| 159 | target := strings.TrimSpace(proptools.String(symlink.Target)) |
| 160 | |
| 161 | if name == "" { |
| 162 | ctx.PropertyErrorf("symlinks", "Name can't be empty") |
| 163 | continue |
| 164 | } |
| 165 | |
| 166 | if target == "" { |
| 167 | ctx.PropertyErrorf("symlinks", "Target can't be empty") |
| 168 | continue |
| 169 | } |
| 170 | |
| 171 | // OutputPath.Join verifies name. don't need to verify target. |
| 172 | dst := rootDir.Join(ctx, name) |
| 173 | |
| 174 | builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) |
| 175 | builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) |
| 176 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 177 | |
| 178 | zipOut := android.PathForModuleGen(ctx, "root.zip").OutputPath |
| 179 | |
| 180 | builder.Command(). |
| 181 | BuiltTool("soong_zip"). |
| 182 | FlagWithOutput("-o ", zipOut). |
| 183 | FlagWithArg("-C ", rootDir.String()). |
| 184 | Flag("-L 0"). // no compression because this will be unzipped soon |
| 185 | FlagWithArg("-D ", rootDir.String()). |
| 186 | Flag("-d") // include empty directories |
| 187 | builder.Command().Text("rm -rf").Text(rootDir.String()) |
| 188 | |
| 189 | builder.Build("zip_root", fmt.Sprintf("zipping root contents for %s", ctx.ModuleName())) |
| 190 | return zipOut |
| 191 | } |
| 192 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 193 | func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath { |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 194 | depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath |
| 195 | f.CopyDepsToZip(ctx, depsZipFile) |
| 196 | |
| 197 | builder := android.NewRuleBuilder(pctx, ctx) |
| 198 | depsBase := proptools.StringDefault(f.properties.Base_dir, ".") |
| 199 | rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath |
| 200 | builder.Command(). |
| 201 | BuiltTool("zip2zip"). |
| 202 | FlagWithInput("-i ", depsZipFile). |
| 203 | FlagWithOutput("-o ", rebasedDepsZip). |
| 204 | Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 205 | |
| 206 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 207 | rootZip := f.buildRootZip(ctx) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 208 | builder.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 209 | BuiltTool("zipsync"). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 210 | FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear. |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 211 | Input(rootZip). |
| 212 | Input(rebasedDepsZip) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 213 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 214 | propFile, toolDeps := f.buildPropFile(ctx) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 215 | output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 216 | builder.Command().BuiltTool("build_image"). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 217 | Text(rootDir.String()). // input directory |
| 218 | Input(propFile). |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 219 | Implicits(toolDeps). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 220 | Output(output). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 221 | Text(rootDir.String()) // directory where to find fs_config_files|dirs |
| 222 | |
| 223 | // rootDir is not deleted. Might be useful for quick inspection. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 224 | builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 225 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 226 | return output |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 227 | } |
| 228 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 229 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath { |
| 230 | builder := android.NewRuleBuilder(pctx, ctx) |
| 231 | fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") |
| 232 | builder.Command().BuiltTool("sefcontext_compile"). |
| 233 | FlagWithOutput("-o ", fcBin). |
| 234 | Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) |
| 235 | builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) |
| 236 | return fcBin.OutputPath |
| 237 | } |
| 238 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 239 | func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) { |
| 240 | type prop struct { |
| 241 | name string |
| 242 | value string |
| 243 | } |
| 244 | |
| 245 | var props []prop |
| 246 | var deps android.Paths |
| 247 | addStr := func(name string, value string) { |
| 248 | props = append(props, prop{name, value}) |
| 249 | } |
| 250 | addPath := func(name string, path android.Path) { |
| 251 | props = append(props, prop{name, path.String()}) |
| 252 | deps = append(deps, path) |
| 253 | } |
| 254 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 255 | // Type string that build_image.py accepts. |
| 256 | fsTypeStr := func(t fsType) string { |
| 257 | switch t { |
| 258 | // TODO(jiyong): add more types like f2fs, erofs, etc. |
| 259 | case ext4Type: |
| 260 | return "ext4" |
| 261 | } |
| 262 | panic(fmt.Errorf("unsupported fs type %v", t)) |
| 263 | } |
| 264 | |
| 265 | addStr("fs_type", fsTypeStr(f.fsType(ctx))) |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 266 | addStr("mount_point", "/") |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 267 | addStr("use_dynamic_partition_size", "true") |
| 268 | addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) |
| 269 | // b/177813163 deps of the host tools have to be added. Remove this. |
| 270 | for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { |
| 271 | deps = append(deps, ctx.Config().HostToolPath(ctx, t)) |
| 272 | } |
| 273 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 274 | if proptools.Bool(f.properties.Use_avb) { |
| 275 | addStr("avb_hashtree_enable", "true") |
| 276 | addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) |
| 277 | algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") |
| 278 | addStr("avb_algorithm", algorithm) |
| 279 | key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) |
| 280 | addPath("avb_key_path", key) |
| 281 | addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec") |
| 282 | addStr("partition_name", f.Name()) |
| 283 | } |
| 284 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 285 | if proptools.String(f.properties.File_contexts) != "" { |
| 286 | addPath("selinux_fc", f.buildFileContexts(ctx)) |
| 287 | } |
| 288 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 289 | propFile = android.PathForModuleOut(ctx, "prop").OutputPath |
| 290 | builder := android.NewRuleBuilder(pctx, ctx) |
| 291 | builder.Command().Text("rm").Flag("-rf").Output(propFile) |
| 292 | for _, p := range props { |
| 293 | builder.Command(). |
Jiyong Park | 3db465d | 2021-01-26 14:08:16 +0900 | [diff] [blame] | 294 | Text("echo"). |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 295 | Flag(`"` + p.name + "=" + p.value + `"`). |
| 296 | Text(">>").Output(propFile) |
| 297 | } |
| 298 | builder.Build("build_filesystem_prop", fmt.Sprintf("Creating filesystem props for %s", f.BaseModuleName())) |
| 299 | return propFile, deps |
| 300 | } |
| 301 | |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 302 | func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 303 | if proptools.Bool(f.properties.Use_avb) { |
| 304 | ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ |
| 305 | "Consider adding this to bootimg module and signing the entire boot image.") |
| 306 | } |
| 307 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 308 | if proptools.String(f.properties.File_contexts) != "" { |
| 309 | ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") |
| 310 | } |
| 311 | |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 312 | depsZipFile := android.PathForModuleOut(ctx, "deps.zip").OutputPath |
| 313 | f.CopyDepsToZip(ctx, depsZipFile) |
| 314 | |
| 315 | builder := android.NewRuleBuilder(pctx, ctx) |
| 316 | depsBase := proptools.StringDefault(f.properties.Base_dir, ".") |
| 317 | rebasedDepsZip := android.PathForModuleOut(ctx, "rebased_deps.zip").OutputPath |
| 318 | builder.Command(). |
| 319 | BuiltTool("zip2zip"). |
| 320 | FlagWithInput("-i ", depsZipFile). |
| 321 | FlagWithOutput("-o ", rebasedDepsZip). |
| 322 | Text("**/*:" + proptools.ShellEscape(depsBase)) // zip2zip verifies depsBase |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 323 | |
| 324 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 325 | rootZip := f.buildRootZip(ctx) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 326 | builder.Command(). |
| 327 | BuiltTool("zipsync"). |
| 328 | FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear. |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 329 | Input(rootZip). |
| 330 | Input(rebasedDepsZip) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 331 | |
| 332 | output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 333 | cmd := builder.Command(). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 334 | BuiltTool("mkbootfs"). |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 335 | Text(rootDir.String()) // input directory |
| 336 | if compressed { |
| 337 | cmd.Text("|"). |
| 338 | BuiltTool("lz4"). |
| 339 | Flag("--favor-decSpeed"). // for faster boot |
| 340 | Flag("-12"). // maximum compression level |
| 341 | Flag("-l"). // legacy format for kernel |
| 342 | Text(">").Output(output) |
| 343 | } else { |
| 344 | cmd.Text(">").Output(output) |
| 345 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 346 | |
| 347 | // rootDir is not deleted. Might be useful for quick inspection. |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 348 | builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 349 | |
| 350 | return output |
| 351 | } |
| 352 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 353 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) |
| 354 | |
| 355 | // Implements android.AndroidMkEntriesProvider |
| 356 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { |
| 357 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 358 | Class: "ETC", |
| 359 | OutputFile: android.OptionalPathForPath(f.output), |
| 360 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 361 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 362 | entries.SetString("LOCAL_MODULE_PATH", f.installDir.ToMakePath().String()) |
| 363 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) |
| 364 | }, |
| 365 | }, |
| 366 | }} |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 367 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 368 | |
Jiyong Park | 940dfd4 | 2021-02-04 15:37:34 +0900 | [diff] [blame] | 369 | var _ android.OutputFileProducer = (*filesystem)(nil) |
| 370 | |
| 371 | // Implements android.OutputFileProducer |
| 372 | func (f *filesystem) OutputFiles(tag string) (android.Paths, error) { |
| 373 | if tag == "" { |
| 374 | return []android.Path{f.output}, nil |
| 375 | } |
| 376 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 377 | } |
| 378 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 379 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex |
| 380 | // package to have access to the output file. |
| 381 | type Filesystem interface { |
| 382 | android.Module |
| 383 | OutputPath() android.Path |
| 384 | } |
| 385 | |
| 386 | var _ Filesystem = (*filesystem)(nil) |
| 387 | |
| 388 | func (f *filesystem) OutputPath() android.Path { |
| 389 | return f.output |
| 390 | } |