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