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