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