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 ( |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 18 | "crypto/sha256" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 19 | "fmt" |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 20 | "io" |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 21 | "path/filepath" |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 22 | "slices" |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 23 | "strconv" |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 24 | "strings" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 25 | |
| 26 | "android/soong/android" |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 27 | "android/soong/cc" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint" |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | func init() { |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 34 | registerBuildComponents(android.InitRegistrationContext) |
| 35 | } |
| 36 | |
| 37 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 38 | ctx.RegisterModuleType("android_filesystem", filesystemFactory) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 39 | ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 40 | ctx.RegisterModuleType("android_system_image", systemImageFactory) |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 41 | ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 42 | ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory) |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 43 | ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 44 | ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | type filesystem struct { |
| 48 | android.ModuleBase |
| 49 | android.PackagingBase |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 50 | android.DefaultableModuleBase |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 51 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 52 | properties filesystemProperties |
| 53 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 54 | // Function that builds extra files under the root directory and returns the files |
| 55 | buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths |
| 56 | |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 57 | // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() |
| 58 | filterPackagingSpec func(spec android.PackagingSpec) bool |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 59 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 60 | output android.OutputPath |
| 61 | installDir android.InstallPath |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 62 | |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 63 | fileListFile android.OutputPath |
| 64 | |
| 65 | // Keeps the entries installed from this filesystem |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 66 | entries []string |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 67 | } |
| 68 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 69 | type symlinkDefinition struct { |
| 70 | Target *string |
| 71 | Name *string |
| 72 | } |
| 73 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 74 | type filesystemProperties struct { |
| 75 | // When set to true, sign the image with avbtool. Default is false. |
| 76 | Use_avb *bool |
| 77 | |
| 78 | // Path to the private key that avbtool will use to sign this filesystem image. |
| 79 | // TODO(jiyong): allow apex_key to be specified here |
| 80 | Avb_private_key *string `android:"path"` |
| 81 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 82 | // Signing algorithm for avbtool. Default is SHA256_RSA4096. |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 83 | Avb_algorithm *string |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 84 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 85 | // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to |
| 86 | // avbtool. Default used by avbtool is sha1. |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 87 | Avb_hash_algorithm *string |
| 88 | |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 89 | // The index used to prevent rollback of the image. Only used if use_avb is true. |
| 90 | Rollback_index *int64 |
| 91 | |
Jiyong Park | ac4076d | 2021-03-15 23:21:30 +0900 | [diff] [blame] | 92 | // Name of the partition stored in vbmeta desc. Defaults to the name of this module. |
| 93 | Partition_name *string |
| 94 | |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 95 | // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default |
| 96 | // is ext4. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 97 | Type *string |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 98 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 99 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 100 | // checks, and will be used in the future for API surface checks. |
| 101 | Partition_type *string |
| 102 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 103 | // file_contexts file to make image. Currently, only ext4 is supported. |
| 104 | File_contexts *string `android:"path"` |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 105 | |
| 106 | // Base directory relative to root, to which deps are installed, e.g. "system". Default is "." |
| 107 | // (root). |
| 108 | Base_dir *string |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 109 | |
| 110 | // Directories to be created under root. e.g. /dev, /proc, etc. |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 111 | Dirs proptools.Configurable[[]string] |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 112 | |
| 113 | // Symbolic links to be created under root with "ln -sf <target> <name>". |
| 114 | Symlinks []symlinkDefinition |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 115 | |
| 116 | // Seconds since unix epoch to override timestamps of file entries |
| 117 | Fake_timestamp *string |
| 118 | |
| 119 | // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed. |
| 120 | // Otherwise, they'll be set as random which might cause indeterministic build output. |
| 121 | Uuid *string |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 122 | |
| 123 | // Mount point for this image. Default is "/" |
| 124 | Mount_point *string |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 125 | |
| 126 | // If set to the name of a partition ("system", "vendor", etc), this filesystem module |
| 127 | // will also include the contents of the make-built staging directories. If any soong |
| 128 | // modules would be installed to the same location as a make module, they will overwrite |
| 129 | // the make version. |
| 130 | Include_make_built_files string |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 131 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 132 | // When set, builds etc/event-log-tags file by merging logtags from all dependencies. |
| 133 | // Default is false |
| 134 | Build_logtags *bool |
| 135 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 136 | // Install aconfig_flags.pb file for the modules installed in this partition. |
| 137 | Gen_aconfig_flags_pb *bool |
| 138 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 139 | Fsverity fsverityProperties |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 140 | } |
| 141 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 142 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem |
| 143 | // image. The filesystem images are expected to be mounted in the target device, which means the |
| 144 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). |
| 145 | // The modules are placed in the filesystem image just like they are installed to the ordinary |
| 146 | // 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] | 147 | func filesystemFactory() android.Module { |
| 148 | module := &filesystem{} |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 149 | module.filterPackagingSpec = module.filterInstallablePackagingSpec |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 150 | initFilesystemModule(module) |
| 151 | return module |
| 152 | } |
| 153 | |
| 154 | func initFilesystemModule(module *filesystem) { |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 155 | module.AddProperties(&module.properties) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 156 | android.InitPackageModule(module) |
Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 157 | module.PackagingBase.DepsCollectFirstTargetOnly = true |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 158 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 159 | android.InitDefaultableModule(module) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 160 | } |
| 161 | |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 162 | var dependencyTag = struct { |
| 163 | blueprint.BaseDependencyTag |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 164 | android.PackagingItemAlwaysDepTag |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 165 | }{} |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 166 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 167 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 168 | f.AddDeps(ctx, dependencyTag) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 169 | } |
| 170 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 171 | type fsType int |
| 172 | |
| 173 | const ( |
| 174 | ext4Type fsType = iota |
| 175 | compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 176 | cpioType // uncompressed |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 177 | unknown |
| 178 | ) |
| 179 | |
| 180 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { |
| 181 | typeStr := proptools.StringDefault(f.properties.Type, "ext4") |
| 182 | switch typeStr { |
| 183 | case "ext4": |
| 184 | return ext4Type |
| 185 | case "compressed_cpio": |
| 186 | return compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 187 | case "cpio": |
| 188 | return cpioType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 189 | default: |
| 190 | ctx.PropertyErrorf("type", "%q not supported", typeStr) |
| 191 | return unknown |
| 192 | } |
| 193 | } |
| 194 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 195 | func (f *filesystem) installFileName() string { |
| 196 | return f.BaseModuleName() + ".img" |
| 197 | } |
| 198 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 199 | func (f *filesystem) partitionName() string { |
| 200 | return proptools.StringDefault(f.properties.Partition_name, f.Name()) |
| 201 | } |
| 202 | |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 203 | func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool { |
| 204 | // Filesystem module respects the installation semantic. A PackagingSpec from a module with |
| 205 | // IsSkipInstall() is skipped. |
| 206 | return !ps.SkipInstall() |
| 207 | } |
| 208 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 209 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 210 | |
| 211 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 212 | validatePartitionType(ctx, f) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 213 | switch f.fsType(ctx) { |
| 214 | case ext4Type: |
| 215 | f.output = f.buildImageUsingBuildImage(ctx) |
| 216 | case compressedCpioType: |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 217 | f.output = f.buildCpioImage(ctx, true) |
| 218 | case cpioType: |
| 219 | f.output = f.buildCpioImage(ctx, false) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 220 | default: |
| 221 | return |
| 222 | } |
| 223 | |
| 224 | f.installDir = android.PathForModuleInstall(ctx, "etc") |
| 225 | ctx.InstallFile(f.installDir, f.installFileName(), f.output) |
mrziwang | 555d133 | 2024-06-07 11:15:33 -0700 | [diff] [blame] | 226 | ctx.SetOutputFiles([]android.Path{f.output}, "") |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 227 | |
| 228 | f.fileListFile = android.PathForModuleOut(ctx, "fileList").OutputPath |
| 229 | android.WriteFileRule(ctx, f.fileListFile, f.installedFilesList()) |
| 230 | } |
| 231 | |
| 232 | func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) { |
| 233 | partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/" |
| 234 | |
| 235 | relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) |
| 236 | if inTargetPartition { |
| 237 | f.entries = append(f.entries, relPath) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func (f *filesystem) installedFilesList() string { |
| 242 | installedFilePaths := android.FirstUniqueStrings(f.entries) |
| 243 | slices.Sort(installedFilePaths) |
| 244 | |
| 245 | return strings.Join(installedFilePaths, "\n") |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 246 | } |
| 247 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 248 | func validatePartitionType(ctx android.ModuleContext, p partition) { |
| 249 | if !android.InList(p.PartitionType(), validPartitions) { |
| 250 | ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType()) |
| 251 | } |
| 252 | |
| 253 | ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) { |
| 254 | if fdm, ok := m.(*filesystemDefaults); ok { |
| 255 | if p.PartitionType() != fdm.PartitionType() { |
| 256 | ctx.PropertyErrorf("partition_type", |
| 257 | "%s doesn't match with the partition type %s of the filesystem default module %s", |
| 258 | p.PartitionType(), fdm.PartitionType(), m.Name()) |
| 259 | } |
| 260 | } |
| 261 | }) |
| 262 | } |
| 263 | |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 264 | // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files |
| 265 | // already in `rootDir`. |
| 266 | func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 267 | // create dirs and symlinks |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 268 | for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 269 | // OutputPath.Join verifies dir |
| 270 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) |
| 271 | } |
| 272 | |
| 273 | for _, symlink := range f.properties.Symlinks { |
| 274 | name := strings.TrimSpace(proptools.String(symlink.Name)) |
| 275 | target := strings.TrimSpace(proptools.String(symlink.Target)) |
| 276 | |
| 277 | if name == "" { |
| 278 | ctx.PropertyErrorf("symlinks", "Name can't be empty") |
| 279 | continue |
| 280 | } |
| 281 | |
| 282 | if target == "" { |
| 283 | ctx.PropertyErrorf("symlinks", "Target can't be empty") |
| 284 | continue |
| 285 | } |
| 286 | |
| 287 | // OutputPath.Join verifies name. don't need to verify target. |
| 288 | dst := rootDir.Join(ctx, name) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 289 | builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst) |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 290 | builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) |
| 291 | builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 292 | f.appendToEntry(ctx, dst) |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 293 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 294 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 295 | // create extra files if there's any |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 296 | if f.buildExtraFiles != nil { |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 297 | rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath |
| 298 | extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 299 | for _, extraFile := range extraFiles { |
| 300 | rel, err := filepath.Rel(rootForExtraFiles.String(), extraFile.String()) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 301 | if err != nil || strings.HasPrefix(rel, "..") { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 302 | ctx.ModuleErrorf("can't make %q relative to %q", extraFile, rootForExtraFiles) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 303 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 304 | f.appendToEntry(ctx, rootDir.Join(ctx, rel)) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 305 | } |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 306 | if len(extraFiles) > 0 { |
| 307 | builder.Command().BuiltTool("merge_directories"). |
| 308 | Implicits(extraFiles.Paths()). |
| 309 | Text(rootDir.String()). |
| 310 | Text(rootForExtraFiles.String()) |
| 311 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 312 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 313 | } |
| 314 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame^] | 315 | func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { |
| 316 | rootDirSpecs := make(map[string]android.PackagingSpec) |
| 317 | rebasedDirSpecs := make(map[string]android.PackagingSpec) |
| 318 | |
| 319 | for rel, spec := range specs { |
| 320 | if spec.Partition() == "root" { |
| 321 | rootDirSpecs[rel] = spec |
| 322 | } else { |
| 323 | rebasedDirSpecs[rel] = spec |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec) |
| 328 | dirsToSpecs[rootDir] = rootDirSpecs |
| 329 | dirsToSpecs[rebasedDir] = rebasedDirSpecs |
| 330 | |
| 331 | return f.CopySpecsToDirs(ctx, builder, dirsToSpecs) |
| 332 | } |
| 333 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 334 | func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 335 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 336 | rebasedDir := rootDir |
| 337 | if f.properties.Base_dir != nil { |
| 338 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 339 | } |
| 340 | builder := android.NewRuleBuilder(pctx, ctx) |
| 341 | // Wipe the root dir to get rid of leftover files from prior builds |
| 342 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 343 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame^] | 344 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 345 | |
| 346 | f.buildNonDepsFiles(ctx, builder, rootDir) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 347 | f.addMakeBuiltFiles(ctx, builder, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 348 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 349 | f.buildEventLogtagsFile(ctx, builder, rebasedDir) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 350 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 351 | |
Nikita Ioffe | 519015f | 2022-12-23 15:36:29 +0000 | [diff] [blame] | 352 | // run host_init_verifier |
| 353 | // Ideally we should have a concept of pluggable linters that verify the generated image. |
| 354 | // While such concept is not implement this will do. |
| 355 | // TODO(b/263574231): substitute with pluggable linter. |
| 356 | builder.Command(). |
| 357 | BuiltTool("host_init_verifier"). |
| 358 | FlagWithArg("--out_system=", rootDir.String()+"/system") |
| 359 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 360 | propFile, toolDeps := f.buildPropFile(ctx) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 361 | output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 362 | builder.Command().BuiltTool("build_image"). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 363 | Text(rootDir.String()). // input directory |
| 364 | Input(propFile). |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 365 | Implicits(toolDeps). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 366 | Output(output). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 367 | Text(rootDir.String()) // directory where to find fs_config_files|dirs |
| 368 | |
| 369 | // rootDir is not deleted. Might be useful for quick inspection. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 370 | builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 371 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 372 | return output |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 373 | } |
| 374 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 375 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath { |
| 376 | builder := android.NewRuleBuilder(pctx, ctx) |
| 377 | fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") |
| 378 | builder.Command().BuiltTool("sefcontext_compile"). |
| 379 | FlagWithOutput("-o ", fcBin). |
| 380 | Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) |
| 381 | builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) |
| 382 | return fcBin.OutputPath |
| 383 | } |
| 384 | |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 385 | // Calculates avb_salt from entry list (sorted) for deterministic output. |
| 386 | func (f *filesystem) salt() string { |
| 387 | return sha1sum(f.entries) |
| 388 | } |
| 389 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 390 | func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) { |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 391 | var deps android.Paths |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 392 | var propFileString strings.Builder |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 393 | addStr := func(name string, value string) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 394 | propFileString.WriteString(name) |
| 395 | propFileString.WriteRune('=') |
| 396 | propFileString.WriteString(value) |
| 397 | propFileString.WriteRune('\n') |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 398 | } |
| 399 | addPath := func(name string, path android.Path) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 400 | addStr(name, path.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 401 | deps = append(deps, path) |
| 402 | } |
| 403 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 404 | // Type string that build_image.py accepts. |
| 405 | fsTypeStr := func(t fsType) string { |
| 406 | switch t { |
| 407 | // TODO(jiyong): add more types like f2fs, erofs, etc. |
| 408 | case ext4Type: |
| 409 | return "ext4" |
| 410 | } |
| 411 | panic(fmt.Errorf("unsupported fs type %v", t)) |
| 412 | } |
| 413 | |
| 414 | addStr("fs_type", fsTypeStr(f.fsType(ctx))) |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 415 | addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 416 | addStr("use_dynamic_partition_size", "true") |
| 417 | addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) |
| 418 | // b/177813163 deps of the host tools have to be added. Remove this. |
| 419 | for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { |
| 420 | deps = append(deps, ctx.Config().HostToolPath(ctx, t)) |
| 421 | } |
| 422 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 423 | if proptools.Bool(f.properties.Use_avb) { |
| 424 | addStr("avb_hashtree_enable", "true") |
| 425 | addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) |
| 426 | algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") |
| 427 | addStr("avb_algorithm", algorithm) |
| 428 | key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) |
| 429 | addPath("avb_key_path", key) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 430 | addStr("partition_name", f.partitionName()) |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 431 | avb_add_hashtree_footer_args := "--do_not_generate_fec" |
| 432 | if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { |
| 433 | avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm |
| 434 | } |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 435 | if f.properties.Rollback_index != nil { |
| 436 | rollbackIndex := proptools.Int(f.properties.Rollback_index) |
| 437 | if rollbackIndex < 0 { |
| 438 | ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") |
| 439 | } |
| 440 | avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) |
| 441 | } |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 442 | securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch" |
Seungjae Yoo | a30e450 | 2023-11-09 14:55:44 +0900 | [diff] [blame] | 443 | securityPatchValue := ctx.Config().PlatformSecurityPatch() |
| 444 | avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 445 | addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 446 | addStr("avb_salt", f.salt()) |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 447 | } |
| 448 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 449 | if proptools.String(f.properties.File_contexts) != "" { |
| 450 | addPath("selinux_fc", f.buildFileContexts(ctx)) |
| 451 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 452 | if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" { |
| 453 | addStr("timestamp", timestamp) |
| 454 | } |
| 455 | if uuid := proptools.String(f.properties.Uuid); uuid != "" { |
| 456 | addStr("uuid", uuid) |
| 457 | addStr("hash_seed", uuid) |
| 458 | } |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 459 | propFile = android.PathForModuleOut(ctx, "prop").OutputPath |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 460 | android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 461 | return propFile, deps |
| 462 | } |
| 463 | |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 464 | func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 465 | if proptools.Bool(f.properties.Use_avb) { |
| 466 | ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ |
| 467 | "Consider adding this to bootimg module and signing the entire boot image.") |
| 468 | } |
| 469 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 470 | if proptools.String(f.properties.File_contexts) != "" { |
| 471 | ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") |
| 472 | } |
| 473 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 474 | if f.properties.Include_make_built_files != "" { |
| 475 | ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.") |
| 476 | } |
| 477 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 478 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 479 | rebasedDir := rootDir |
| 480 | if f.properties.Base_dir != nil { |
| 481 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 482 | } |
| 483 | builder := android.NewRuleBuilder(pctx, ctx) |
| 484 | // Wipe the root dir to get rid of leftover files from prior builds |
| 485 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 486 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame^] | 487 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 488 | |
| 489 | f.buildNonDepsFiles(ctx, builder, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 490 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 491 | f.buildEventLogtagsFile(ctx, builder, rebasedDir) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 492 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 493 | |
| 494 | output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 495 | cmd := builder.Command(). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 496 | BuiltTool("mkbootfs"). |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 497 | Text(rootDir.String()) // input directory |
| 498 | if compressed { |
| 499 | cmd.Text("|"). |
| 500 | BuiltTool("lz4"). |
| 501 | Flag("--favor-decSpeed"). // for faster boot |
| 502 | Flag("-12"). // maximum compression level |
| 503 | Flag("-l"). // legacy format for kernel |
| 504 | Text(">").Output(output) |
| 505 | } else { |
| 506 | cmd.Text(">").Output(output) |
| 507 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 508 | |
| 509 | // rootDir is not deleted. Might be useful for quick inspection. |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 510 | builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 511 | |
| 512 | return output |
| 513 | } |
| 514 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 515 | var validPartitions = []string{ |
| 516 | "system", |
| 517 | "userdata", |
| 518 | "cache", |
| 519 | "system_other", |
| 520 | "vendor", |
| 521 | "product", |
| 522 | "system_ext", |
| 523 | "odm", |
| 524 | "vendor_dlkm", |
| 525 | "odm_dlkm", |
| 526 | "system_dlkm", |
| 527 | } |
| 528 | |
| 529 | func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) { |
| 530 | partition := f.properties.Include_make_built_files |
| 531 | if partition == "" { |
| 532 | return |
| 533 | } |
| 534 | if !slices.Contains(validPartitions, partition) { |
| 535 | ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition) |
| 536 | return |
| 537 | } |
| 538 | stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition) |
| 539 | fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition) |
| 540 | stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition) |
| 541 | |
| 542 | builder.Command().BuiltTool("merge_directories"). |
| 543 | Implicit(android.PathForArbitraryOutput(ctx, stampFile)). |
| 544 | Text("--ignore-duplicates"). |
| 545 | FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)). |
| 546 | Text(rootDir.String()). |
| 547 | Text(android.PathForArbitraryOutput(ctx, stagingDir).String()) |
| 548 | } |
| 549 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 550 | func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { |
| 551 | if !proptools.Bool(f.properties.Build_logtags) { |
| 552 | return |
| 553 | } |
| 554 | |
| 555 | logtagsFilePaths := make(map[string]bool) |
| 556 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 557 | if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok { |
| 558 | for _, path := range logtagsInfo.Logtags { |
| 559 | logtagsFilePaths[path.String()] = true |
| 560 | } |
| 561 | } |
| 562 | return true |
| 563 | }) |
| 564 | |
| 565 | if len(logtagsFilePaths) == 0 { |
| 566 | return |
| 567 | } |
| 568 | |
| 569 | etcPath := rebasedDir.Join(ctx, "etc") |
| 570 | eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") |
| 571 | builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) |
| 572 | cmd := builder.Command().BuiltTool("merge-event-log-tags"). |
| 573 | FlagWithArg("-o ", eventLogtagsPath.String()). |
| 574 | FlagWithInput("-m ", android.MergedLogtagsPath(ctx)) |
| 575 | |
| 576 | for _, path := range android.SortedKeys(logtagsFilePaths) { |
| 577 | cmd.Text(path) |
| 578 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 579 | |
| 580 | f.appendToEntry(ctx, eventLogtagsPath) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 581 | } |
| 582 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 583 | type partition interface { |
| 584 | PartitionType() string |
| 585 | } |
| 586 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 587 | func (f *filesystem) PartitionType() string { |
| 588 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 589 | } |
| 590 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 591 | var _ partition = (*filesystem)(nil) |
| 592 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 593 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) |
| 594 | |
| 595 | // Implements android.AndroidMkEntriesProvider |
| 596 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { |
| 597 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 598 | Class: "ETC", |
| 599 | OutputFile: android.OptionalPathForPath(f.output), |
| 600 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 601 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 602 | entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 603 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 604 | entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 605 | }, |
| 606 | }, |
| 607 | }} |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 608 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 609 | |
| 610 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex |
| 611 | // package to have access to the output file. |
| 612 | type Filesystem interface { |
| 613 | android.Module |
| 614 | OutputPath() android.Path |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 615 | |
| 616 | // Returns the output file that is signed by avbtool. If this module is not signed, returns |
| 617 | // nil. |
| 618 | SignedOutputPath() android.Path |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | var _ Filesystem = (*filesystem)(nil) |
| 622 | |
| 623 | func (f *filesystem) OutputPath() android.Path { |
| 624 | return f.output |
| 625 | } |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 626 | |
| 627 | func (f *filesystem) SignedOutputPath() android.Path { |
| 628 | if proptools.Bool(f.properties.Use_avb) { |
| 629 | return f.OutputPath() |
| 630 | } |
| 631 | return nil |
| 632 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 633 | |
| 634 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. |
| 635 | // Note that "apex" module installs its contents to "apex"(fake partition) as well |
| 636 | // for symbol lookup by imitating "activated" paths. |
| 637 | func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 638 | specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec) |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 639 | return specs |
| 640 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 641 | |
| 642 | func sha1sum(values []string) string { |
| 643 | h := sha256.New() |
| 644 | for _, value := range values { |
| 645 | io.WriteString(h, value) |
| 646 | } |
| 647 | return fmt.Sprintf("%x", h.Sum(nil)) |
| 648 | } |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 649 | |
| 650 | // Base cc.UseCoverage |
| 651 | |
| 652 | var _ cc.UseCoverage = (*filesystem)(nil) |
| 653 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 654 | func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 655 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 656 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 657 | |
| 658 | // android_filesystem_defaults |
| 659 | |
| 660 | type filesystemDefaults struct { |
| 661 | android.ModuleBase |
| 662 | android.DefaultsModuleBase |
| 663 | |
| 664 | properties filesystemDefaultsProperties |
| 665 | } |
| 666 | |
| 667 | type filesystemDefaultsProperties struct { |
| 668 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 669 | // checks, and will be used in the future for API surface checks. |
| 670 | Partition_type *string |
| 671 | } |
| 672 | |
| 673 | // android_filesystem_defaults is a default module for android_filesystem and android_system_image |
| 674 | func filesystemDefaultsFactory() android.Module { |
| 675 | module := &filesystemDefaults{} |
| 676 | module.AddProperties(&module.properties) |
| 677 | module.AddProperties(&android.PackagingProperties{}) |
| 678 | android.InitDefaultsModule(module) |
| 679 | return module |
| 680 | } |
| 681 | |
| 682 | func (f *filesystemDefaults) PartitionType() string { |
| 683 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 684 | } |
| 685 | |
| 686 | var _ partition = (*filesystemDefaults)(nil) |
| 687 | |
| 688 | func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 689 | validatePartitionType(ctx, f) |
| 690 | } |