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) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 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) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [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 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 52 | properties FilesystemProperties |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 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 | |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 69 | type SymlinkDefinition struct { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 70 | Target *string |
| 71 | Name *string |
| 72 | } |
| 73 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 74 | type FilesystemProperties struct { |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 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 | |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 95 | // Type of the filesystem. Currently, ext4, erofs, cpio, and compressed_cpio are supported. Default |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 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>". |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 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 |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 140 | |
| 141 | // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing |
| 142 | // it to not be built on checkbuilds. Used for the automatic migration from make to soong |
| 143 | // build modules, where we want to emit some not-yet-working filesystems and we don't want them |
| 144 | // to be built. |
| 145 | Unchecked_module *bool `blueprint:"mutated"` |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 146 | |
| 147 | Erofs ErofsProperties |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 148 | |
| 149 | // Determines if the module is auto-generated from Soong or not. If the module is |
| 150 | // auto-generated, its deps are exempted from visibility enforcement. |
| 151 | Is_auto_generated *bool |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | // Additional properties required to generate erofs FS partitions. |
| 155 | type ErofsProperties struct { |
| 156 | // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9) |
| 157 | // Please see external/erofs-utils/README for complete documentation. |
| 158 | Compressor *string |
| 159 | |
| 160 | // Used as --compress-hints for mkfs.erofs |
| 161 | Compress_hints *string `android:"path"` |
| 162 | |
| 163 | Sparse *bool |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 164 | } |
| 165 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 166 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem |
| 167 | // image. The filesystem images are expected to be mounted in the target device, which means the |
| 168 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). |
| 169 | // The modules are placed in the filesystem image just like they are installed to the ordinary |
| 170 | // partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory. |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 171 | func FilesystemFactory() android.Module { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 172 | module := &filesystem{} |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 173 | module.filterPackagingSpec = module.filterInstallablePackagingSpec |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 174 | initFilesystemModule(module, module) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 175 | return module |
| 176 | } |
| 177 | |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 178 | func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) { |
| 179 | module.AddProperties(&filesystemModule.properties) |
| 180 | android.InitPackageModule(filesystemModule) |
| 181 | filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 182 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 183 | android.InitDefaultableModule(module) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 186 | type depTag struct { |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 187 | blueprint.BaseDependencyTag |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 188 | android.PackagingItemAlwaysDepTag |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | var dependencyTag = depTag{} |
| 192 | |
| 193 | type depTagWithVisibilityEnforcementBypass struct { |
| 194 | depTag |
| 195 | } |
| 196 | |
| 197 | var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil) |
| 198 | |
| 199 | func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {} |
| 200 | |
| 201 | var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{} |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 202 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 203 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 204 | if proptools.Bool(f.properties.Is_auto_generated) { |
| 205 | f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass) |
| 206 | } else { |
| 207 | f.AddDeps(ctx, dependencyTag) |
| 208 | } |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 209 | } |
| 210 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 211 | type fsType int |
| 212 | |
| 213 | const ( |
| 214 | ext4Type fsType = iota |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 215 | erofsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 216 | compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 217 | cpioType // uncompressed |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 218 | unknown |
| 219 | ) |
| 220 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 221 | func (fs fsType) IsUnknown() bool { |
| 222 | return fs == unknown |
| 223 | } |
| 224 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 225 | type FilesystemInfo struct { |
| 226 | // A text file containing the list of paths installed on the partition. |
| 227 | FileListFile android.Path |
| 228 | } |
| 229 | |
| 230 | var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]() |
| 231 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 232 | func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 233 | switch typeStr { |
| 234 | case "ext4": |
| 235 | return ext4Type |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 236 | case "erofs": |
| 237 | return erofsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 238 | case "compressed_cpio": |
| 239 | return compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 240 | case "cpio": |
| 241 | return cpioType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 242 | default: |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 243 | return unknown |
| 244 | } |
| 245 | } |
| 246 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 247 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { |
| 248 | typeStr := proptools.StringDefault(f.properties.Type, "ext4") |
| 249 | fsType := GetFsTypeFromString(ctx, typeStr) |
| 250 | if fsType == unknown { |
| 251 | ctx.PropertyErrorf("type", "%q not supported", typeStr) |
| 252 | } |
| 253 | return fsType |
| 254 | } |
| 255 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 256 | func (f *filesystem) installFileName() string { |
| 257 | return f.BaseModuleName() + ".img" |
| 258 | } |
| 259 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 260 | func (f *filesystem) partitionName() string { |
| 261 | return proptools.StringDefault(f.properties.Partition_name, f.Name()) |
| 262 | } |
| 263 | |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 264 | func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool { |
| 265 | // Filesystem module respects the installation semantic. A PackagingSpec from a module with |
| 266 | // IsSkipInstall() is skipped. |
Spandan Das | 6d05650 | 2024-10-21 15:40:32 +0000 | [diff] [blame] | 267 | if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this. |
| 268 | return !ps.SkipInstall() && (ps.Partition() == f.PartitionType()) |
| 269 | } |
| 270 | return !ps.SkipInstall() |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 273 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 274 | |
| 275 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 276 | validatePartitionType(ctx, f) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 277 | switch f.fsType(ctx) { |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 278 | case ext4Type, erofsType: |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 279 | f.output = f.buildImageUsingBuildImage(ctx) |
| 280 | case compressedCpioType: |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 281 | f.output = f.buildCpioImage(ctx, true) |
| 282 | case cpioType: |
| 283 | f.output = f.buildCpioImage(ctx, false) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 284 | default: |
| 285 | return |
| 286 | } |
| 287 | |
| 288 | f.installDir = android.PathForModuleInstall(ctx, "etc") |
| 289 | ctx.InstallFile(f.installDir, f.installFileName(), f.output) |
mrziwang | 555d133 | 2024-06-07 11:15:33 -0700 | [diff] [blame] | 290 | ctx.SetOutputFiles([]android.Path{f.output}, "") |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 291 | |
| 292 | f.fileListFile = android.PathForModuleOut(ctx, "fileList").OutputPath |
| 293 | android.WriteFileRule(ctx, f.fileListFile, f.installedFilesList()) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 294 | |
| 295 | android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{ |
| 296 | FileListFile: f.fileListFile, |
| 297 | }) |
| 298 | |
| 299 | if proptools.Bool(f.properties.Unchecked_module) { |
| 300 | ctx.UncheckedModule() |
| 301 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.OutputPath) { |
| 305 | partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/" |
| 306 | |
| 307 | relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) |
| 308 | if inTargetPartition { |
| 309 | f.entries = append(f.entries, relPath) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | func (f *filesystem) installedFilesList() string { |
| 314 | installedFilePaths := android.FirstUniqueStrings(f.entries) |
| 315 | slices.Sort(installedFilePaths) |
| 316 | |
| 317 | return strings.Join(installedFilePaths, "\n") |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 318 | } |
| 319 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 320 | func validatePartitionType(ctx android.ModuleContext, p partition) { |
| 321 | if !android.InList(p.PartitionType(), validPartitions) { |
| 322 | ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType()) |
| 323 | } |
| 324 | |
| 325 | ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) { |
| 326 | if fdm, ok := m.(*filesystemDefaults); ok { |
| 327 | if p.PartitionType() != fdm.PartitionType() { |
| 328 | ctx.PropertyErrorf("partition_type", |
| 329 | "%s doesn't match with the partition type %s of the filesystem default module %s", |
| 330 | p.PartitionType(), fdm.PartitionType(), m.Name()) |
| 331 | } |
| 332 | } |
| 333 | }) |
| 334 | } |
| 335 | |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 336 | // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files |
| 337 | // already in `rootDir`. |
| 338 | 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] | 339 | // create dirs and symlinks |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 340 | for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 341 | // OutputPath.Join verifies dir |
| 342 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) |
| 343 | } |
| 344 | |
| 345 | for _, symlink := range f.properties.Symlinks { |
| 346 | name := strings.TrimSpace(proptools.String(symlink.Name)) |
| 347 | target := strings.TrimSpace(proptools.String(symlink.Target)) |
| 348 | |
| 349 | if name == "" { |
| 350 | ctx.PropertyErrorf("symlinks", "Name can't be empty") |
| 351 | continue |
| 352 | } |
| 353 | |
| 354 | if target == "" { |
| 355 | ctx.PropertyErrorf("symlinks", "Target can't be empty") |
| 356 | continue |
| 357 | } |
| 358 | |
| 359 | // OutputPath.Join verifies name. don't need to verify target. |
| 360 | dst := rootDir.Join(ctx, name) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 361 | 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] | 362 | builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) |
| 363 | builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 364 | f.appendToEntry(ctx, dst) |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 365 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 366 | |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 367 | // create extra files if there's any |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 368 | if f.buildExtraFiles != nil { |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 369 | rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath |
| 370 | extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 371 | for _, extraFile := range extraFiles { |
| 372 | rel, err := filepath.Rel(rootForExtraFiles.String(), extraFile.String()) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 373 | if err != nil || strings.HasPrefix(rel, "..") { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 374 | ctx.ModuleErrorf("can't make %q relative to %q", extraFile, rootForExtraFiles) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 375 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 376 | f.appendToEntry(ctx, rootDir.Join(ctx, rel)) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 377 | } |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 378 | if len(extraFiles) > 0 { |
| 379 | builder.Command().BuiltTool("merge_directories"). |
| 380 | Implicits(extraFiles.Paths()). |
| 381 | Text(rootDir.String()). |
| 382 | Text(rootForExtraFiles.String()) |
| 383 | } |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 384 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 385 | } |
| 386 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 387 | func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { |
| 388 | rootDirSpecs := make(map[string]android.PackagingSpec) |
| 389 | rebasedDirSpecs := make(map[string]android.PackagingSpec) |
| 390 | |
| 391 | for rel, spec := range specs { |
| 392 | if spec.Partition() == "root" { |
| 393 | rootDirSpecs[rel] = spec |
| 394 | } else { |
| 395 | rebasedDirSpecs[rel] = spec |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec) |
| 400 | dirsToSpecs[rootDir] = rootDirSpecs |
| 401 | dirsToSpecs[rebasedDir] = rebasedDirSpecs |
| 402 | |
| 403 | return f.CopySpecsToDirs(ctx, builder, dirsToSpecs) |
| 404 | } |
| 405 | |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 406 | func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { |
Justin Yun | 2cc4250 | 2024-09-11 14:10:20 +0900 | [diff] [blame] | 407 | if f.Name() != ctx.Config().SoongDefinedSystemImage() { |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 408 | return |
| 409 | } |
| 410 | installPath := android.PathForModuleInPartitionInstall(ctx, f.partitionName()) |
| 411 | builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath) |
| 412 | } |
| 413 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 414 | func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 415 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 416 | rebasedDir := rootDir |
| 417 | if f.properties.Base_dir != nil { |
| 418 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 419 | } |
| 420 | builder := android.NewRuleBuilder(pctx, ctx) |
| 421 | // Wipe the root dir to get rid of leftover files from prior builds |
| 422 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 423 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 424 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 425 | |
| 426 | f.buildNonDepsFiles(ctx, builder, rootDir) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 427 | f.addMakeBuiltFiles(ctx, builder, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 428 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 429 | f.buildEventLogtagsFile(ctx, builder, rebasedDir) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 430 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 431 | f.copyFilesToProductOut(ctx, builder, rebasedDir) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 432 | |
Nikita Ioffe | 519015f | 2022-12-23 15:36:29 +0000 | [diff] [blame] | 433 | // run host_init_verifier |
| 434 | // Ideally we should have a concept of pluggable linters that verify the generated image. |
| 435 | // While such concept is not implement this will do. |
| 436 | // TODO(b/263574231): substitute with pluggable linter. |
| 437 | builder.Command(). |
| 438 | BuiltTool("host_init_verifier"). |
| 439 | FlagWithArg("--out_system=", rootDir.String()+"/system") |
| 440 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 441 | propFile, toolDeps := f.buildPropFile(ctx) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 442 | output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 443 | builder.Command().BuiltTool("build_image"). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 444 | Text(rootDir.String()). // input directory |
| 445 | Input(propFile). |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 446 | Implicits(toolDeps). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 447 | Output(output). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 448 | Text(rootDir.String()) // directory where to find fs_config_files|dirs |
| 449 | |
| 450 | // rootDir is not deleted. Might be useful for quick inspection. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 451 | builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 452 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 453 | return output |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 454 | } |
| 455 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 456 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath { |
| 457 | builder := android.NewRuleBuilder(pctx, ctx) |
| 458 | fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") |
| 459 | builder.Command().BuiltTool("sefcontext_compile"). |
| 460 | FlagWithOutput("-o ", fcBin). |
| 461 | Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) |
| 462 | builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) |
| 463 | return fcBin.OutputPath |
| 464 | } |
| 465 | |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 466 | // Calculates avb_salt from entry list (sorted) for deterministic output. |
| 467 | func (f *filesystem) salt() string { |
| 468 | return sha1sum(f.entries) |
| 469 | } |
| 470 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 471 | 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] | 472 | var deps android.Paths |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 473 | var propFileString strings.Builder |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 474 | addStr := func(name string, value string) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 475 | propFileString.WriteString(name) |
| 476 | propFileString.WriteRune('=') |
| 477 | propFileString.WriteString(value) |
| 478 | propFileString.WriteRune('\n') |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 479 | } |
| 480 | addPath := func(name string, path android.Path) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 481 | addStr(name, path.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 482 | deps = append(deps, path) |
| 483 | } |
| 484 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 485 | // Type string that build_image.py accepts. |
| 486 | fsTypeStr := func(t fsType) string { |
| 487 | switch t { |
Spandan Das | 9466882 | 2024-10-09 20:51:33 +0000 | [diff] [blame] | 488 | // TODO(372522486): add more types like f2fs, erofs, etc. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 489 | case ext4Type: |
| 490 | return "ext4" |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 491 | case erofsType: |
| 492 | return "erofs" |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 493 | } |
| 494 | panic(fmt.Errorf("unsupported fs type %v", t)) |
| 495 | } |
| 496 | |
| 497 | addStr("fs_type", fsTypeStr(f.fsType(ctx))) |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 498 | addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 499 | addStr("use_dynamic_partition_size", "true") |
| 500 | addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) |
| 501 | // b/177813163 deps of the host tools have to be added. Remove this. |
| 502 | for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { |
| 503 | deps = append(deps, ctx.Config().HostToolPath(ctx, t)) |
| 504 | } |
| 505 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 506 | if proptools.Bool(f.properties.Use_avb) { |
| 507 | addStr("avb_hashtree_enable", "true") |
| 508 | addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) |
| 509 | algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") |
| 510 | addStr("avb_algorithm", algorithm) |
| 511 | key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) |
| 512 | addPath("avb_key_path", key) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 513 | addStr("partition_name", f.partitionName()) |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 514 | avb_add_hashtree_footer_args := "--do_not_generate_fec" |
| 515 | if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { |
| 516 | avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm |
| 517 | } |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 518 | if f.properties.Rollback_index != nil { |
| 519 | rollbackIndex := proptools.Int(f.properties.Rollback_index) |
| 520 | if rollbackIndex < 0 { |
| 521 | ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") |
| 522 | } |
| 523 | avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) |
| 524 | } |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 525 | securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch" |
Seungjae Yoo | a30e450 | 2023-11-09 14:55:44 +0900 | [diff] [blame] | 526 | securityPatchValue := ctx.Config().PlatformSecurityPatch() |
| 527 | avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 528 | addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 529 | addStr("avb_salt", f.salt()) |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 530 | } |
| 531 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 532 | if proptools.String(f.properties.File_contexts) != "" { |
| 533 | addPath("selinux_fc", f.buildFileContexts(ctx)) |
| 534 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 535 | if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" { |
| 536 | addStr("timestamp", timestamp) |
| 537 | } |
| 538 | if uuid := proptools.String(f.properties.Uuid); uuid != "" { |
| 539 | addStr("uuid", uuid) |
| 540 | addStr("hash_seed", uuid) |
| 541 | } |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 542 | // Add erofs properties |
| 543 | if f.fsType(ctx) == erofsType { |
| 544 | if compressor := f.properties.Erofs.Compressor; compressor != nil { |
| 545 | addStr("erofs_default_compressor", proptools.String(compressor)) |
| 546 | } |
| 547 | if compressHints := f.properties.Erofs.Compress_hints; compressHints != nil { |
Cole Faust | 7cd4bad | 2024-10-11 10:31:12 -0700 | [diff] [blame] | 548 | addPath("erofs_default_compress_hints", android.PathForModuleSrc(ctx, *compressHints)) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 549 | } |
| 550 | if proptools.BoolDefault(f.properties.Erofs.Sparse, true) { |
| 551 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b |
| 552 | addStr("erofs_sparse_flag", "-s") |
| 553 | } |
Cole Faust | 7cd4bad | 2024-10-11 10:31:12 -0700 | [diff] [blame] | 554 | } else if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil { |
| 555 | // Raise an exception if the propfile contains erofs properties, but the fstype is not erofs |
| 556 | fs := fsTypeStr(f.fsType(ctx)) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 557 | ctx.PropertyErrorf("erofs", "erofs is non-empty, but FS type is %s\n. Please delete erofs properties if this partition should use %s\n", fs, fs) |
| 558 | } |
| 559 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 560 | propFile = android.PathForModuleOut(ctx, "prop").OutputPath |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 561 | android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 562 | return propFile, deps |
| 563 | } |
| 564 | |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 565 | func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 566 | if proptools.Bool(f.properties.Use_avb) { |
| 567 | ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ |
| 568 | "Consider adding this to bootimg module and signing the entire boot image.") |
| 569 | } |
| 570 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 571 | if proptools.String(f.properties.File_contexts) != "" { |
| 572 | ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") |
| 573 | } |
| 574 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 575 | if f.properties.Include_make_built_files != "" { |
| 576 | ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.") |
| 577 | } |
| 578 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 579 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 580 | rebasedDir := rootDir |
| 581 | if f.properties.Base_dir != nil { |
| 582 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 583 | } |
| 584 | builder := android.NewRuleBuilder(pctx, ctx) |
| 585 | // Wipe the root dir to get rid of leftover files from prior builds |
| 586 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 587 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 588 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 589 | |
| 590 | f.buildNonDepsFiles(ctx, builder, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 591 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 592 | f.buildEventLogtagsFile(ctx, builder, rebasedDir) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 593 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 594 | f.copyFilesToProductOut(ctx, builder, rebasedDir) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 595 | |
| 596 | output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 597 | cmd := builder.Command(). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 598 | BuiltTool("mkbootfs"). |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 599 | Text(rootDir.String()) // input directory |
| 600 | if compressed { |
| 601 | cmd.Text("|"). |
| 602 | BuiltTool("lz4"). |
| 603 | Flag("--favor-decSpeed"). // for faster boot |
| 604 | Flag("-12"). // maximum compression level |
| 605 | Flag("-l"). // legacy format for kernel |
| 606 | Text(">").Output(output) |
| 607 | } else { |
| 608 | cmd.Text(">").Output(output) |
| 609 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 610 | |
| 611 | // rootDir is not deleted. Might be useful for quick inspection. |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 612 | builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 613 | |
| 614 | return output |
| 615 | } |
| 616 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 617 | var validPartitions = []string{ |
| 618 | "system", |
| 619 | "userdata", |
| 620 | "cache", |
| 621 | "system_other", |
| 622 | "vendor", |
| 623 | "product", |
| 624 | "system_ext", |
| 625 | "odm", |
| 626 | "vendor_dlkm", |
| 627 | "odm_dlkm", |
| 628 | "system_dlkm", |
| 629 | } |
| 630 | |
| 631 | func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) { |
| 632 | partition := f.properties.Include_make_built_files |
| 633 | if partition == "" { |
| 634 | return |
| 635 | } |
| 636 | if !slices.Contains(validPartitions, partition) { |
| 637 | ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition) |
| 638 | return |
| 639 | } |
| 640 | stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition) |
| 641 | fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition) |
| 642 | stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition) |
| 643 | |
| 644 | builder.Command().BuiltTool("merge_directories"). |
| 645 | Implicit(android.PathForArbitraryOutput(ctx, stampFile)). |
| 646 | Text("--ignore-duplicates"). |
| 647 | FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)). |
| 648 | Text(rootDir.String()). |
| 649 | Text(android.PathForArbitraryOutput(ctx, stagingDir).String()) |
| 650 | } |
| 651 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 652 | func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { |
| 653 | if !proptools.Bool(f.properties.Build_logtags) { |
| 654 | return |
| 655 | } |
| 656 | |
| 657 | logtagsFilePaths := make(map[string]bool) |
| 658 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 659 | if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok { |
| 660 | for _, path := range logtagsInfo.Logtags { |
| 661 | logtagsFilePaths[path.String()] = true |
| 662 | } |
| 663 | } |
| 664 | return true |
| 665 | }) |
| 666 | |
| 667 | if len(logtagsFilePaths) == 0 { |
| 668 | return |
| 669 | } |
| 670 | |
| 671 | etcPath := rebasedDir.Join(ctx, "etc") |
| 672 | eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") |
| 673 | builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) |
| 674 | cmd := builder.Command().BuiltTool("merge-event-log-tags"). |
| 675 | FlagWithArg("-o ", eventLogtagsPath.String()). |
| 676 | FlagWithInput("-m ", android.MergedLogtagsPath(ctx)) |
| 677 | |
| 678 | for _, path := range android.SortedKeys(logtagsFilePaths) { |
| 679 | cmd.Text(path) |
| 680 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 681 | |
| 682 | f.appendToEntry(ctx, eventLogtagsPath) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 683 | } |
| 684 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 685 | type partition interface { |
| 686 | PartitionType() string |
| 687 | } |
| 688 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 689 | func (f *filesystem) PartitionType() string { |
| 690 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 691 | } |
| 692 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 693 | var _ partition = (*filesystem)(nil) |
| 694 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 695 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) |
| 696 | |
| 697 | // Implements android.AndroidMkEntriesProvider |
| 698 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { |
| 699 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 700 | Class: "ETC", |
| 701 | OutputFile: android.OptionalPathForPath(f.output), |
| 702 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 703 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 704 | entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 705 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 706 | entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 707 | }, |
| 708 | }, |
| 709 | }} |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 710 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 711 | |
| 712 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex |
| 713 | // package to have access to the output file. |
| 714 | type Filesystem interface { |
| 715 | android.Module |
| 716 | OutputPath() android.Path |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 717 | |
| 718 | // Returns the output file that is signed by avbtool. If this module is not signed, returns |
| 719 | // nil. |
| 720 | SignedOutputPath() android.Path |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | var _ Filesystem = (*filesystem)(nil) |
| 724 | |
| 725 | func (f *filesystem) OutputPath() android.Path { |
| 726 | return f.output |
| 727 | } |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 728 | |
| 729 | func (f *filesystem) SignedOutputPath() android.Path { |
| 730 | if proptools.Bool(f.properties.Use_avb) { |
| 731 | return f.OutputPath() |
| 732 | } |
| 733 | return nil |
| 734 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 735 | |
| 736 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. |
| 737 | // Note that "apex" module installs its contents to "apex"(fake partition) as well |
| 738 | // for symbol lookup by imitating "activated" paths. |
| 739 | func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { |
Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 740 | specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec) |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 741 | return specs |
| 742 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 743 | |
| 744 | func sha1sum(values []string) string { |
| 745 | h := sha256.New() |
| 746 | for _, value := range values { |
| 747 | io.WriteString(h, value) |
| 748 | } |
| 749 | return fmt.Sprintf("%x", h.Sum(nil)) |
| 750 | } |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 751 | |
| 752 | // Base cc.UseCoverage |
| 753 | |
| 754 | var _ cc.UseCoverage = (*filesystem)(nil) |
| 755 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 756 | func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 757 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 758 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 759 | |
| 760 | // android_filesystem_defaults |
| 761 | |
| 762 | type filesystemDefaults struct { |
| 763 | android.ModuleBase |
| 764 | android.DefaultsModuleBase |
| 765 | |
| 766 | properties filesystemDefaultsProperties |
| 767 | } |
| 768 | |
| 769 | type filesystemDefaultsProperties struct { |
| 770 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 771 | // checks, and will be used in the future for API surface checks. |
| 772 | Partition_type *string |
| 773 | } |
| 774 | |
| 775 | // android_filesystem_defaults is a default module for android_filesystem and android_system_image |
| 776 | func filesystemDefaultsFactory() android.Module { |
| 777 | module := &filesystemDefaults{} |
| 778 | module.AddProperties(&module.properties) |
| 779 | module.AddProperties(&android.PackagingProperties{}) |
| 780 | android.InitDefaultsModule(module) |
| 781 | return module |
| 782 | } |
| 783 | |
| 784 | func (f *filesystemDefaults) PartitionType() string { |
| 785 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 786 | } |
| 787 | |
| 788 | var _ partition = (*filesystemDefaults)(nil) |
| 789 | |
| 790 | func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 791 | validatePartitionType(ctx, f) |
| 792 | } |