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