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" |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 28 | "android/soong/java" |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 29 | "android/soong/linkerconfig" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 30 | |
| 31 | "github.com/google/blueprint" |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 32 | "github.com/google/blueprint/proptools" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | func init() { |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 36 | registerBuildComponents(android.InitRegistrationContext) |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 37 | registerMutators(android.InitRegistrationContext) |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | func registerBuildComponents(ctx android.RegistrationContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 41 | ctx.RegisterModuleType("android_filesystem", FilesystemFactory) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 42 | ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 43 | ctx.RegisterModuleType("android_system_image", SystemImageFactory) |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 44 | ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 45 | ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory) |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 46 | ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 47 | ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 48 | } |
| 49 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 50 | func registerMutators(ctx android.RegistrationContext) { |
| 51 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 52 | ctx.BottomUp("add_autogenerated_rro_deps", addAutogeneratedRroDeps) |
| 53 | }) |
| 54 | } |
| 55 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 56 | type filesystem struct { |
| 57 | android.ModuleBase |
| 58 | android.PackagingBase |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 59 | android.DefaultableModuleBase |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 60 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 61 | properties FilesystemProperties |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 62 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 63 | output android.Path |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 64 | installDir android.InstallPath |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 65 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 66 | fileListFile android.Path |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 67 | |
| 68 | // Keeps the entries installed from this filesystem |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 69 | entries []string |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 70 | |
| 71 | filesystemBuilder filesystemBuilder |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 72 | } |
| 73 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 74 | type filesystemBuilder interface { |
| 75 | BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) |
| 76 | // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() |
| 77 | FilterPackagingSpec(spec android.PackagingSpec) bool |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 78 | // Function that modifies PackagingSpec in PackagingBase.GatherPackagingSpecs() to customize. |
| 79 | // For example, GSI system.img contains system_ext and product artifacts and their |
| 80 | // relPathInPackage need to be rebased to system/system_ext and system/system_product. |
| 81 | ModifyPackagingSpec(spec *android.PackagingSpec) |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 82 | |
| 83 | // Function to check if the filesystem should not use `vintf_fragments` property, |
| 84 | // but use `vintf_fragment` module type instead |
| 85 | ShouldUseVintfFragmentModuleOnly() bool |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | var _ filesystemBuilder = (*filesystem)(nil) |
| 89 | |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 90 | type SymlinkDefinition struct { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 91 | Target *string |
| 92 | Name *string |
| 93 | } |
| 94 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 95 | type FilesystemProperties struct { |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 96 | // When set to true, sign the image with avbtool. Default is false. |
| 97 | Use_avb *bool |
| 98 | |
| 99 | // Path to the private key that avbtool will use to sign this filesystem image. |
| 100 | // TODO(jiyong): allow apex_key to be specified here |
| 101 | Avb_private_key *string `android:"path"` |
| 102 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 103 | // Signing algorithm for avbtool. Default is SHA256_RSA4096. |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 104 | Avb_algorithm *string |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 105 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 106 | // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to |
| 107 | // avbtool. Default used by avbtool is sha1. |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 108 | Avb_hash_algorithm *string |
| 109 | |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 110 | // The index used to prevent rollback of the image. Only used if use_avb is true. |
| 111 | Rollback_index *int64 |
| 112 | |
Jiyong Park | ac4076d | 2021-03-15 23:21:30 +0900 | [diff] [blame] | 113 | // Name of the partition stored in vbmeta desc. Defaults to the name of this module. |
| 114 | Partition_name *string |
| 115 | |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 116 | // 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] | 117 | // is ext4. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 118 | Type *string |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 119 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 120 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 121 | // checks, and will be used in the future for API surface checks. |
| 122 | Partition_type *string |
| 123 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 124 | // file_contexts file to make image. Currently, only ext4 is supported. |
| 125 | File_contexts *string `android:"path"` |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 126 | |
| 127 | // Base directory relative to root, to which deps are installed, e.g. "system". Default is "." |
| 128 | // (root). |
| 129 | Base_dir *string |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 130 | |
| 131 | // Directories to be created under root. e.g. /dev, /proc, etc. |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 132 | Dirs proptools.Configurable[[]string] |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 133 | |
| 134 | // Symbolic links to be created under root with "ln -sf <target> <name>". |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 135 | Symlinks []SymlinkDefinition |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 136 | |
| 137 | // Seconds since unix epoch to override timestamps of file entries |
| 138 | Fake_timestamp *string |
| 139 | |
| 140 | // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed. |
| 141 | // Otherwise, they'll be set as random which might cause indeterministic build output. |
| 142 | Uuid *string |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 143 | |
| 144 | // Mount point for this image. Default is "/" |
| 145 | Mount_point *string |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 146 | |
| 147 | // If set to the name of a partition ("system", "vendor", etc), this filesystem module |
| 148 | // will also include the contents of the make-built staging directories. If any soong |
| 149 | // modules would be installed to the same location as a make module, they will overwrite |
| 150 | // the make version. |
| 151 | Include_make_built_files string |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 152 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 153 | // When set, builds etc/event-log-tags file by merging logtags from all dependencies. |
| 154 | // Default is false |
| 155 | Build_logtags *bool |
| 156 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 157 | // Install aconfig_flags.pb file for the modules installed in this partition. |
| 158 | Gen_aconfig_flags_pb *bool |
| 159 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 160 | Fsverity fsverityProperties |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 161 | |
| 162 | // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing |
| 163 | // it to not be built on checkbuilds. Used for the automatic migration from make to soong |
| 164 | // build modules, where we want to emit some not-yet-working filesystems and we don't want them |
| 165 | // to be built. |
| 166 | Unchecked_module *bool `blueprint:"mutated"` |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 167 | |
| 168 | Erofs ErofsProperties |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 169 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 170 | F2fs F2fsProperties |
| 171 | |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 172 | Linker_config LinkerConfigProperties |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 173 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 174 | // Determines if the module is auto-generated from Soong or not. If the module is |
| 175 | // auto-generated, its deps are exempted from visibility enforcement. |
| 176 | Is_auto_generated *bool |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 177 | |
| 178 | // Path to the dev nodes description file. This is only needed for building the ramdisk |
| 179 | // partition and should not be explicitly specified. |
| 180 | Dev_nodes_description_file *string `android:"path" blueprint:"mutated"` |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 181 | |
| 182 | // Additional dependencies used for building android products |
| 183 | Android_filesystem_deps AndroidFilesystemDeps |
| 184 | } |
| 185 | |
| 186 | type AndroidFilesystemDeps struct { |
| 187 | System *string |
| 188 | System_ext *string |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Additional properties required to generate erofs FS partitions. |
| 192 | type ErofsProperties struct { |
| 193 | // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9) |
| 194 | // Please see external/erofs-utils/README for complete documentation. |
| 195 | Compressor *string |
| 196 | |
| 197 | // Used as --compress-hints for mkfs.erofs |
| 198 | Compress_hints *string `android:"path"` |
| 199 | |
| 200 | Sparse *bool |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 201 | } |
| 202 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 203 | // Additional properties required to generate f2fs FS partitions. |
| 204 | type F2fsProperties struct { |
| 205 | Sparse *bool |
| 206 | } |
| 207 | |
Spandan Das | 173256b | 2024-10-31 19:59:30 +0000 | [diff] [blame] | 208 | type LinkerConfigProperties struct { |
| 209 | |
| 210 | // Build a linker.config.pb file |
| 211 | Gen_linker_config *bool |
| 212 | |
| 213 | // List of files (in .json format) that will be converted to a linker config file (in .pb format). |
| 214 | // The linker config file be installed in the filesystem at /etc/linker.config.pb |
| 215 | Linker_config_srcs []string `android:"path"` |
| 216 | } |
| 217 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 218 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem |
| 219 | // image. The filesystem images are expected to be mounted in the target device, which means the |
| 220 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). |
| 221 | // The modules are placed in the filesystem image just like they are installed to the ordinary |
| 222 | // 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] | 223 | func FilesystemFactory() android.Module { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 224 | module := &filesystem{} |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 225 | module.filesystemBuilder = module |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 226 | initFilesystemModule(module, module) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 227 | return module |
| 228 | } |
| 229 | |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 230 | func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) { |
| 231 | module.AddProperties(&filesystemModule.properties) |
| 232 | android.InitPackageModule(filesystemModule) |
| 233 | filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 234 | filesystemModule.PackagingBase.AllowHighPriorityDeps = true |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 235 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 236 | android.InitDefaultableModule(module) |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 237 | |
| 238 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 239 | filesystemModule.setDevNodesDescriptionProp() |
| 240 | }) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 241 | } |
| 242 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 243 | type depTag struct { |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 244 | blueprint.BaseDependencyTag |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 245 | android.PackagingItemAlwaysDepTag |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | var dependencyTag = depTag{} |
| 249 | |
| 250 | type depTagWithVisibilityEnforcementBypass struct { |
| 251 | depTag |
| 252 | } |
| 253 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 254 | type interPartitionDepTag struct { |
| 255 | blueprint.BaseDependencyTag |
| 256 | } |
| 257 | |
| 258 | var interPartitionDependencyTag = interPartitionDepTag{} |
| 259 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 260 | var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil) |
| 261 | |
| 262 | func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {} |
| 263 | |
| 264 | var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{} |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 265 | |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 266 | // ramdiskDevNodesDescription is the name of the filegroup module that provides the file that |
| 267 | // contains the description of dev nodes added to the CPIO archive for the ramdisk partition. |
| 268 | const ramdiskDevNodesDescription = "ramdisk_node_list" |
| 269 | |
| 270 | func (f *filesystem) setDevNodesDescriptionProp() { |
| 271 | if proptools.String(f.properties.Partition_name) == "ramdisk" { |
| 272 | f.properties.Dev_nodes_description_file = proptools.StringPtr(":" + ramdiskDevNodesDescription) |
| 273 | } |
| 274 | } |
| 275 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 276 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 277 | if proptools.Bool(f.properties.Is_auto_generated) { |
| 278 | f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass) |
| 279 | } else { |
| 280 | f.AddDeps(ctx, dependencyTag) |
| 281 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 282 | if f.properties.Android_filesystem_deps.System != nil { |
| 283 | ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System)) |
| 284 | } |
| 285 | if f.properties.Android_filesystem_deps.System_ext != nil { |
| 286 | ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System_ext)) |
| 287 | } |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 288 | } |
| 289 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 290 | type fsType int |
| 291 | |
| 292 | const ( |
| 293 | ext4Type fsType = iota |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 294 | erofsType |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 295 | f2fsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 296 | compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 297 | cpioType // uncompressed |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 298 | unknown |
| 299 | ) |
| 300 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 301 | func (fs fsType) IsUnknown() bool { |
| 302 | return fs == unknown |
| 303 | } |
| 304 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 305 | type FilesystemInfo struct { |
| 306 | // A text file containing the list of paths installed on the partition. |
| 307 | FileListFile android.Path |
| 308 | } |
| 309 | |
| 310 | var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]() |
| 311 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 312 | func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 313 | switch typeStr { |
| 314 | case "ext4": |
| 315 | return ext4Type |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 316 | case "erofs": |
| 317 | return erofsType |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 318 | case "f2fs": |
| 319 | return f2fsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 320 | case "compressed_cpio": |
| 321 | return compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 322 | case "cpio": |
| 323 | return cpioType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 324 | default: |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 325 | return unknown |
| 326 | } |
| 327 | } |
| 328 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 329 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { |
| 330 | typeStr := proptools.StringDefault(f.properties.Type, "ext4") |
| 331 | fsType := GetFsTypeFromString(ctx, typeStr) |
| 332 | if fsType == unknown { |
| 333 | ctx.PropertyErrorf("type", "%q not supported", typeStr) |
| 334 | } |
| 335 | return fsType |
| 336 | } |
| 337 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 338 | func (f *filesystem) installFileName() string { |
| 339 | return f.BaseModuleName() + ".img" |
| 340 | } |
| 341 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 342 | func (f *filesystem) partitionName() string { |
| 343 | return proptools.StringDefault(f.properties.Partition_name, f.Name()) |
| 344 | } |
| 345 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 346 | func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool { |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 347 | // Filesystem module respects the installation semantic. A PackagingSpec from a module with |
| 348 | // IsSkipInstall() is skipped. |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 349 | if ps.SkipInstall() { |
| 350 | return false |
Spandan Das | 6d05650 | 2024-10-21 15:40:32 +0000 | [diff] [blame] | 351 | } |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 352 | if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this. |
| 353 | pt := f.PartitionType() |
Cole Faust | c88cff1 | 2024-11-12 13:24:05 -0800 | [diff] [blame] | 354 | return ps.Partition() == pt || strings.HasPrefix(ps.Partition(), pt+"/") |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 355 | } |
| 356 | return true |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 359 | func (f *filesystem) ModifyPackagingSpec(ps *android.PackagingSpec) { |
Cole Faust | c88cff1 | 2024-11-12 13:24:05 -0800 | [diff] [blame] | 360 | // Sometimes, android.modulePartition() returns a path with >1 path components. |
| 361 | // This makes the partition field of packagingSpecs have multiple components, like |
| 362 | // "system/product". Right now, the filesystem module doesn't look at the partition field |
| 363 | // when deciding what path to install the file under, only the RelPathInPackage field, so |
| 364 | // we move the later path components from partition to relPathInPackage. This should probably |
| 365 | // be revisited in the future. |
| 366 | prefix := f.PartitionType() + "/" |
| 367 | if strings.HasPrefix(ps.Partition(), prefix) { |
| 368 | subPartition := strings.TrimPrefix(ps.Partition(), prefix) |
| 369 | ps.SetPartition(f.PartitionType()) |
| 370 | ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage())) |
| 371 | } |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 372 | } |
| 373 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 374 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 375 | |
| 376 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 377 | validatePartitionType(ctx, f) |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 378 | if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() { |
| 379 | f.validateVintfFragments(ctx) |
| 380 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 381 | switch f.fsType(ctx) { |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 382 | case ext4Type, erofsType, f2fsType: |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 383 | f.output = f.buildImageUsingBuildImage(ctx) |
| 384 | case compressedCpioType: |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 385 | f.output = f.buildCpioImage(ctx, true) |
| 386 | case cpioType: |
| 387 | f.output = f.buildCpioImage(ctx, false) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 388 | default: |
| 389 | return |
| 390 | } |
| 391 | |
| 392 | f.installDir = android.PathForModuleInstall(ctx, "etc") |
| 393 | ctx.InstallFile(f.installDir, f.installFileName(), f.output) |
mrziwang | 555d133 | 2024-06-07 11:15:33 -0700 | [diff] [blame] | 394 | ctx.SetOutputFiles([]android.Path{f.output}, "") |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 395 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 396 | fileListFile := android.PathForModuleOut(ctx, "fileList") |
| 397 | android.WriteFileRule(ctx, fileListFile, f.installedFilesList()) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 398 | |
| 399 | android.SetProvider(ctx, FilesystemProvider, FilesystemInfo{ |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 400 | FileListFile: fileListFile, |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 401 | }) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 402 | f.fileListFile = fileListFile |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 403 | |
| 404 | if proptools.Bool(f.properties.Unchecked_module) { |
| 405 | ctx.UncheckedModule() |
| 406 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 407 | } |
| 408 | |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 409 | func (f *filesystem) validateVintfFragments(ctx android.ModuleContext) { |
| 410 | visitedModule := map[string]bool{} |
| 411 | packagingSpecs := f.gatherFilteredPackagingSpecs(ctx) |
| 412 | |
| 413 | moduleInFileSystem := func(mod android.Module) bool { |
| 414 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 415 | ctx, mod, android.InstallFilesProvider).PackagingSpecs { |
| 416 | if _, ok := packagingSpecs[ps.RelPathInPackage()]; ok { |
| 417 | return true |
| 418 | } |
| 419 | } |
| 420 | return false |
| 421 | } |
| 422 | |
| 423 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 424 | if visitedModule[child.Name()] { |
| 425 | return false |
| 426 | } |
| 427 | if !moduleInFileSystem(child) { |
| 428 | visitedModule[child.Name()] = true |
| 429 | return true |
| 430 | } |
| 431 | if vintfFragments := child.VintfFragments(ctx); vintfFragments != nil { |
| 432 | ctx.PropertyErrorf( |
| 433 | "vintf_fragments", |
| 434 | "Module %s is referenced by soong-defined filesystem %s with property vintf_fragments(%s) in use."+ |
| 435 | " Use vintf_fragment_modules property instead.", |
| 436 | child.Name(), |
| 437 | f.BaseModuleName(), |
| 438 | strings.Join(vintfFragments, ", "), |
| 439 | ) |
| 440 | } |
| 441 | visitedModule[child.Name()] = true |
| 442 | return true |
| 443 | }) |
| 444 | } |
| 445 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 446 | func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) { |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 447 | partitionBaseDir := android.PathForModuleOut(ctx, "root", f.partitionName()).String() + "/" |
| 448 | |
| 449 | relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) |
| 450 | if inTargetPartition { |
| 451 | f.entries = append(f.entries, relPath) |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | func (f *filesystem) installedFilesList() string { |
| 456 | installedFilePaths := android.FirstUniqueStrings(f.entries) |
| 457 | slices.Sort(installedFilePaths) |
| 458 | |
| 459 | return strings.Join(installedFilePaths, "\n") |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 460 | } |
| 461 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 462 | func validatePartitionType(ctx android.ModuleContext, p partition) { |
| 463 | if !android.InList(p.PartitionType(), validPartitions) { |
| 464 | ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType()) |
| 465 | } |
| 466 | |
| 467 | ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) { |
| 468 | if fdm, ok := m.(*filesystemDefaults); ok { |
| 469 | if p.PartitionType() != fdm.PartitionType() { |
| 470 | ctx.PropertyErrorf("partition_type", |
| 471 | "%s doesn't match with the partition type %s of the filesystem default module %s", |
| 472 | p.PartitionType(), fdm.PartitionType(), m.Name()) |
| 473 | } |
| 474 | } |
| 475 | }) |
| 476 | } |
| 477 | |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 478 | // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files |
| 479 | // already in `rootDir`. |
| 480 | 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] | 481 | // create dirs and symlinks |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 482 | for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 483 | // OutputPath.Join verifies dir |
| 484 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) |
| 485 | } |
| 486 | |
| 487 | for _, symlink := range f.properties.Symlinks { |
| 488 | name := strings.TrimSpace(proptools.String(symlink.Name)) |
| 489 | target := strings.TrimSpace(proptools.String(symlink.Target)) |
| 490 | |
| 491 | if name == "" { |
| 492 | ctx.PropertyErrorf("symlinks", "Name can't be empty") |
| 493 | continue |
| 494 | } |
| 495 | |
| 496 | if target == "" { |
| 497 | ctx.PropertyErrorf("symlinks", "Target can't be empty") |
| 498 | continue |
| 499 | } |
| 500 | |
| 501 | // OutputPath.Join verifies name. don't need to verify target. |
| 502 | dst := rootDir.Join(ctx, name) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 503 | 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] | 504 | builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) |
| 505 | builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 506 | f.appendToEntry(ctx, dst) |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 507 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 508 | } |
| 509 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 510 | func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { |
| 511 | rootDirSpecs := make(map[string]android.PackagingSpec) |
| 512 | rebasedDirSpecs := make(map[string]android.PackagingSpec) |
| 513 | |
| 514 | for rel, spec := range specs { |
| 515 | if spec.Partition() == "root" { |
| 516 | rootDirSpecs[rel] = spec |
| 517 | } else { |
| 518 | rebasedDirSpecs[rel] = spec |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec) |
| 523 | dirsToSpecs[rootDir] = rootDirSpecs |
| 524 | dirsToSpecs[rebasedDir] = rebasedDirSpecs |
| 525 | |
| 526 | return f.CopySpecsToDirs(ctx, builder, dirsToSpecs) |
| 527 | } |
| 528 | |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 529 | 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] | 530 | if f.Name() != ctx.Config().SoongDefinedSystemImage() { |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 531 | return |
| 532 | } |
| 533 | installPath := android.PathForModuleInPartitionInstall(ctx, f.partitionName()) |
| 534 | builder.Command().Textf("cp -prf %s/* %s", rebasedDir, installPath) |
| 535 | } |
| 536 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 537 | func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.Path { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 538 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 539 | rebasedDir := rootDir |
| 540 | if f.properties.Base_dir != nil { |
| 541 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 542 | } |
| 543 | builder := android.NewRuleBuilder(pctx, ctx) |
| 544 | // Wipe the root dir to get rid of leftover files from prior builds |
| 545 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 546 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 547 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 548 | |
| 549 | f.buildNonDepsFiles(ctx, builder, rootDir) |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 550 | f.addMakeBuiltFiles(ctx, builder, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 551 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 552 | f.buildEventLogtagsFile(ctx, builder, rebasedDir) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 553 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 554 | f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir) |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 555 | f.copyFilesToProductOut(ctx, builder, rebasedDir) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 556 | |
Nikita Ioffe | 519015f | 2022-12-23 15:36:29 +0000 | [diff] [blame] | 557 | // run host_init_verifier |
| 558 | // Ideally we should have a concept of pluggable linters that verify the generated image. |
| 559 | // While such concept is not implement this will do. |
| 560 | // TODO(b/263574231): substitute with pluggable linter. |
| 561 | builder.Command(). |
| 562 | BuiltTool("host_init_verifier"). |
| 563 | FlagWithArg("--out_system=", rootDir.String()+"/system") |
| 564 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 565 | propFile, toolDeps := f.buildPropFile(ctx) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 566 | output := android.PathForModuleOut(ctx, f.installFileName()) |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 567 | builder.Command().BuiltTool("build_image"). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 568 | Text(rootDir.String()). // input directory |
| 569 | Input(propFile). |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 570 | Implicits(toolDeps). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 571 | Output(output). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 572 | Text(rootDir.String()) // directory where to find fs_config_files|dirs |
| 573 | |
| 574 | // rootDir is not deleted. Might be useful for quick inspection. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 575 | builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 576 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 577 | return output |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 578 | } |
| 579 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 580 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path { |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 581 | builder := android.NewRuleBuilder(pctx, ctx) |
| 582 | fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") |
| 583 | builder.Command().BuiltTool("sefcontext_compile"). |
| 584 | FlagWithOutput("-o ", fcBin). |
| 585 | Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) |
| 586 | builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 587 | return fcBin |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 588 | } |
| 589 | |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 590 | // Calculates avb_salt from entry list (sorted) for deterministic output. |
| 591 | func (f *filesystem) salt() string { |
| 592 | return sha1sum(f.entries) |
| 593 | } |
| 594 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 595 | func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, android.Paths) { |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 596 | var deps android.Paths |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 597 | var propFileString strings.Builder |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 598 | addStr := func(name string, value string) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 599 | propFileString.WriteString(name) |
| 600 | propFileString.WriteRune('=') |
| 601 | propFileString.WriteString(value) |
| 602 | propFileString.WriteRune('\n') |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 603 | } |
| 604 | addPath := func(name string, path android.Path) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 605 | addStr(name, path.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 606 | deps = append(deps, path) |
| 607 | } |
| 608 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 609 | // Type string that build_image.py accepts. |
| 610 | fsTypeStr := func(t fsType) string { |
| 611 | switch t { |
Spandan Das | 9466882 | 2024-10-09 20:51:33 +0000 | [diff] [blame] | 612 | // TODO(372522486): add more types like f2fs, erofs, etc. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 613 | case ext4Type: |
| 614 | return "ext4" |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 615 | case erofsType: |
| 616 | return "erofs" |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 617 | case f2fsType: |
| 618 | return "f2fs" |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 619 | } |
| 620 | panic(fmt.Errorf("unsupported fs type %v", t)) |
| 621 | } |
| 622 | |
| 623 | addStr("fs_type", fsTypeStr(f.fsType(ctx))) |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 624 | addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 625 | addStr("use_dynamic_partition_size", "true") |
| 626 | addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) |
| 627 | // b/177813163 deps of the host tools have to be added. Remove this. |
| 628 | for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { |
| 629 | deps = append(deps, ctx.Config().HostToolPath(ctx, t)) |
| 630 | } |
| 631 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 632 | if proptools.Bool(f.properties.Use_avb) { |
| 633 | addStr("avb_hashtree_enable", "true") |
| 634 | addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) |
| 635 | algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") |
| 636 | addStr("avb_algorithm", algorithm) |
| 637 | key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) |
| 638 | addPath("avb_key_path", key) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 639 | addStr("partition_name", f.partitionName()) |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 640 | avb_add_hashtree_footer_args := "--do_not_generate_fec" |
| 641 | if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { |
| 642 | avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm |
| 643 | } |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 644 | if f.properties.Rollback_index != nil { |
| 645 | rollbackIndex := proptools.Int(f.properties.Rollback_index) |
| 646 | if rollbackIndex < 0 { |
| 647 | ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") |
| 648 | } |
| 649 | avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) |
| 650 | } |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 651 | securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch" |
Seungjae Yoo | a30e450 | 2023-11-09 14:55:44 +0900 | [diff] [blame] | 652 | securityPatchValue := ctx.Config().PlatformSecurityPatch() |
| 653 | avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 654 | addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 655 | addStr("avb_salt", f.salt()) |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 656 | } |
| 657 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 658 | if proptools.String(f.properties.File_contexts) != "" { |
| 659 | addPath("selinux_fc", f.buildFileContexts(ctx)) |
| 660 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 661 | if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" { |
| 662 | addStr("timestamp", timestamp) |
| 663 | } |
| 664 | if uuid := proptools.String(f.properties.Uuid); uuid != "" { |
| 665 | addStr("uuid", uuid) |
| 666 | addStr("hash_seed", uuid) |
| 667 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 668 | |
Cole Faust | 43a52c7 | 2024-11-26 12:46:08 -0800 | [diff] [blame] | 669 | // TODO(b/381120092): This should only be added if none of the size-related properties are set, |
| 670 | // but currently soong built partitions don't have size properties. Make code: |
| 671 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2262;drc=39cd33701c9278db0e7e481a090605f428d5b12d |
| 672 | // Make uses system_disable_sparse but disable_sparse has the same effect, and we shouldn't need |
| 673 | // to qualify it because each partition gets its own property file built. |
| 674 | addStr("disable_sparse", "true") |
| 675 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 676 | fst := f.fsType(ctx) |
| 677 | switch fst { |
| 678 | case erofsType: |
| 679 | // Add erofs properties |
Cole Faust | 3e73097 | 2024-12-03 13:12:08 -0800 | [diff] [blame^] | 680 | addStr("erofs_default_compressor", proptools.StringDefault(f.properties.Erofs.Compressor, "lz4hc,9")) |
| 681 | if f.properties.Erofs.Compress_hints != nil { |
| 682 | src := android.PathForModuleSrc(ctx, *f.properties.Erofs.Compress_hints) |
| 683 | addPath("erofs_default_compress_hints", src) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 684 | } |
| 685 | if proptools.BoolDefault(f.properties.Erofs.Sparse, true) { |
| 686 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b |
| 687 | addStr("erofs_sparse_flag", "-s") |
| 688 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 689 | case f2fsType: |
| 690 | if proptools.BoolDefault(f.properties.F2fs.Sparse, true) { |
| 691 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2294;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b;bpv=1;bpt=0 |
| 692 | addStr("f2fs_sparse_flag", "-S") |
| 693 | } |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 694 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 695 | f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst)) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 696 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 697 | propFile := android.PathForModuleOut(ctx, "prop") |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 698 | android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 699 | return propFile, deps |
| 700 | } |
| 701 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 702 | // This method checks if there is any property set for the fstype(s) other than |
| 703 | // the current fstype. |
| 704 | func (f *filesystem) checkFsTypePropertyError(ctx android.ModuleContext, t fsType, fs string) { |
| 705 | raiseError := func(otherFsType, currentFsType string) { |
| 706 | errMsg := fmt.Sprintf("%s is non-empty, but FS type is %s\n. Please delete %s properties if this partition should use %s\n", otherFsType, currentFsType, otherFsType, currentFsType) |
| 707 | ctx.PropertyErrorf(otherFsType, errMsg) |
| 708 | } |
| 709 | |
| 710 | if t != erofsType { |
| 711 | if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil { |
| 712 | raiseError("erofs", fs) |
| 713 | } |
| 714 | } |
| 715 | if t != f2fsType { |
| 716 | if f.properties.F2fs.Sparse != nil { |
| 717 | raiseError("f2fs", fs) |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 722 | func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.Path { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 723 | if proptools.Bool(f.properties.Use_avb) { |
| 724 | ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ |
| 725 | "Consider adding this to bootimg module and signing the entire boot image.") |
| 726 | } |
| 727 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 728 | if proptools.String(f.properties.File_contexts) != "" { |
| 729 | ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") |
| 730 | } |
| 731 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 732 | if f.properties.Include_make_built_files != "" { |
| 733 | ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.") |
| 734 | } |
| 735 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 736 | rootDir := android.PathForModuleOut(ctx, "root").OutputPath |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 737 | rebasedDir := rootDir |
| 738 | if f.properties.Base_dir != nil { |
| 739 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 740 | } |
| 741 | builder := android.NewRuleBuilder(pctx, ctx) |
| 742 | // Wipe the root dir to get rid of leftover files from prior builds |
| 743 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 744 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 745 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 746 | |
| 747 | f.buildNonDepsFiles(ctx, builder, rootDir) |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 748 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 749 | f.buildEventLogtagsFile(ctx, builder, rebasedDir) |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 750 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 751 | f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir) |
Justin Yun | 34baa2e | 2024-08-30 21:11:33 +0900 | [diff] [blame] | 752 | f.copyFilesToProductOut(ctx, builder, rebasedDir) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 753 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 754 | output := android.PathForModuleOut(ctx, f.installFileName()) |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 755 | cmd := builder.Command(). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 756 | BuiltTool("mkbootfs"). |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 757 | Text(rootDir.String()) // input directory |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 758 | if nodeList := f.properties.Dev_nodes_description_file; nodeList != nil { |
| 759 | cmd.FlagWithInput("-n ", android.PathForModuleSrc(ctx, proptools.String(nodeList))) |
| 760 | } |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 761 | if compressed { |
| 762 | cmd.Text("|"). |
| 763 | BuiltTool("lz4"). |
| 764 | Flag("--favor-decSpeed"). // for faster boot |
| 765 | Flag("-12"). // maximum compression level |
| 766 | Flag("-l"). // legacy format for kernel |
| 767 | Text(">").Output(output) |
| 768 | } else { |
| 769 | cmd.Text(">").Output(output) |
| 770 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 771 | |
| 772 | // rootDir is not deleted. Might be useful for quick inspection. |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 773 | builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 774 | |
| 775 | return output |
| 776 | } |
| 777 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 778 | var validPartitions = []string{ |
| 779 | "system", |
| 780 | "userdata", |
| 781 | "cache", |
| 782 | "system_other", |
| 783 | "vendor", |
| 784 | "product", |
| 785 | "system_ext", |
| 786 | "odm", |
| 787 | "vendor_dlkm", |
| 788 | "odm_dlkm", |
| 789 | "system_dlkm", |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 790 | "ramdisk", |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 791 | "vendor_ramdisk", |
Jihoon Kang | 3216c98 | 2024-12-02 19:42:20 +0000 | [diff] [blame] | 792 | "recovery", |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) { |
| 796 | partition := f.properties.Include_make_built_files |
| 797 | if partition == "" { |
| 798 | return |
| 799 | } |
| 800 | if !slices.Contains(validPartitions, partition) { |
| 801 | ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition) |
| 802 | return |
| 803 | } |
| 804 | stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition) |
| 805 | fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition) |
| 806 | stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition) |
| 807 | |
| 808 | builder.Command().BuiltTool("merge_directories"). |
| 809 | Implicit(android.PathForArbitraryOutput(ctx, stampFile)). |
| 810 | Text("--ignore-duplicates"). |
| 811 | FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)). |
| 812 | Text(rootDir.String()). |
| 813 | Text(android.PathForArbitraryOutput(ctx, stagingDir).String()) |
| 814 | } |
| 815 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 816 | func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { |
| 817 | if !proptools.Bool(f.properties.Build_logtags) { |
| 818 | return |
| 819 | } |
| 820 | |
| 821 | logtagsFilePaths := make(map[string]bool) |
| 822 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 823 | if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok { |
| 824 | for _, path := range logtagsInfo.Logtags { |
| 825 | logtagsFilePaths[path.String()] = true |
| 826 | } |
| 827 | } |
| 828 | return true |
| 829 | }) |
| 830 | |
| 831 | if len(logtagsFilePaths) == 0 { |
| 832 | return |
| 833 | } |
| 834 | |
| 835 | etcPath := rebasedDir.Join(ctx, "etc") |
| 836 | eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") |
| 837 | builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) |
| 838 | cmd := builder.Command().BuiltTool("merge-event-log-tags"). |
| 839 | FlagWithArg("-o ", eventLogtagsPath.String()). |
| 840 | FlagWithInput("-m ", android.MergedLogtagsPath(ctx)) |
| 841 | |
| 842 | for _, path := range android.SortedKeys(logtagsFilePaths) { |
| 843 | cmd.Text(path) |
| 844 | } |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 845 | |
| 846 | f.appendToEntry(ctx, eventLogtagsPath) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 847 | } |
| 848 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 849 | func (f *filesystem) BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 850 | if !proptools.Bool(f.properties.Linker_config.Gen_linker_config) { |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 851 | return |
| 852 | } |
| 853 | |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 854 | provideModules, _ := f.getLibsForLinkerConfig(ctx) |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 855 | output := rebasedDir.Join(ctx, "etc", "linker.config.pb") |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 856 | linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linker_config.Linker_config_srcs), provideModules, nil, output) |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 857 | |
| 858 | f.appendToEntry(ctx, output) |
| 859 | } |
| 860 | |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 861 | func (f *filesystem) ShouldUseVintfFragmentModuleOnly() bool { |
| 862 | return false |
| 863 | } |
| 864 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 865 | type partition interface { |
| 866 | PartitionType() string |
| 867 | } |
| 868 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 869 | func (f *filesystem) PartitionType() string { |
| 870 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 871 | } |
| 872 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 873 | var _ partition = (*filesystem)(nil) |
| 874 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 875 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) |
| 876 | |
| 877 | // Implements android.AndroidMkEntriesProvider |
| 878 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { |
| 879 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 880 | Class: "ETC", |
| 881 | OutputFile: android.OptionalPathForPath(f.output), |
| 882 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 883 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 884 | entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 885 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 886 | entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 887 | }, |
| 888 | }, |
| 889 | }} |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 890 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 891 | |
| 892 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex |
| 893 | // package to have access to the output file. |
| 894 | type Filesystem interface { |
| 895 | android.Module |
| 896 | OutputPath() android.Path |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 897 | |
| 898 | // Returns the output file that is signed by avbtool. If this module is not signed, returns |
| 899 | // nil. |
| 900 | SignedOutputPath() android.Path |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | var _ Filesystem = (*filesystem)(nil) |
| 904 | |
| 905 | func (f *filesystem) OutputPath() android.Path { |
| 906 | return f.output |
| 907 | } |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 908 | |
| 909 | func (f *filesystem) SignedOutputPath() android.Path { |
| 910 | if proptools.Bool(f.properties.Use_avb) { |
| 911 | return f.OutputPath() |
| 912 | } |
| 913 | return nil |
| 914 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 915 | |
| 916 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. |
| 917 | // Note that "apex" module installs its contents to "apex"(fake partition) as well |
| 918 | // for symbol lookup by imitating "activated" paths. |
| 919 | func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 920 | specs := f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec) |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 921 | return specs |
| 922 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 923 | |
| 924 | func sha1sum(values []string) string { |
| 925 | h := sha256.New() |
| 926 | for _, value := range values { |
| 927 | io.WriteString(h, value) |
| 928 | } |
| 929 | return fmt.Sprintf("%x", h.Sum(nil)) |
| 930 | } |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 931 | |
| 932 | // Base cc.UseCoverage |
| 933 | |
| 934 | var _ cc.UseCoverage = (*filesystem)(nil) |
| 935 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 936 | func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 937 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 938 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 939 | |
| 940 | // android_filesystem_defaults |
| 941 | |
| 942 | type filesystemDefaults struct { |
| 943 | android.ModuleBase |
| 944 | android.DefaultsModuleBase |
| 945 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 946 | properties FilesystemProperties |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | // android_filesystem_defaults is a default module for android_filesystem and android_system_image |
| 950 | func filesystemDefaultsFactory() android.Module { |
| 951 | module := &filesystemDefaults{} |
| 952 | module.AddProperties(&module.properties) |
| 953 | module.AddProperties(&android.PackagingProperties{}) |
| 954 | android.InitDefaultsModule(module) |
| 955 | return module |
| 956 | } |
| 957 | |
| 958 | func (f *filesystemDefaults) PartitionType() string { |
| 959 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 960 | } |
| 961 | |
| 962 | var _ partition = (*filesystemDefaults)(nil) |
| 963 | |
| 964 | func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 965 | validatePartitionType(ctx, f) |
| 966 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 967 | |
| 968 | // getLibsForLinkerConfig returns |
| 969 | // 1. A list of libraries installed in this filesystem |
| 970 | // 2. A list of dep libraries _not_ installed in this filesystem |
| 971 | // |
| 972 | // `linkerconfig.BuildLinkerConfig` will convert these two to a linker.config.pb for the filesystem |
| 973 | // (1) will be added to --provideLibs if they are C libraries with a stable interface (has stubs) |
| 974 | // (2) will be added to --requireLibs if they are C libraries with a stable interface (has stubs) |
| 975 | func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]android.Module, []android.Module) { |
| 976 | // we need "Module"s for packaging items |
| 977 | modulesInPackageByModule := make(map[android.Module]bool) |
| 978 | modulesInPackageByName := make(map[string]bool) |
| 979 | |
| 980 | deps := f.gatherFilteredPackagingSpecs(ctx) |
| 981 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 982 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 983 | ctx, child, android.InstallFilesProvider).PackagingSpecs { |
| 984 | if _, ok := deps[ps.RelPathInPackage()]; ok { |
| 985 | modulesInPackageByModule[child] = true |
| 986 | modulesInPackageByName[child.Name()] = true |
| 987 | return true |
| 988 | } |
| 989 | } |
| 990 | return true |
| 991 | }) |
| 992 | |
| 993 | provideModules := make([]android.Module, 0, len(modulesInPackageByModule)) |
| 994 | for mod := range modulesInPackageByModule { |
| 995 | provideModules = append(provideModules, mod) |
| 996 | } |
| 997 | |
| 998 | var requireModules []android.Module |
| 999 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 1000 | _, parentInPackage := modulesInPackageByModule[parent] |
| 1001 | _, childInPackageName := modulesInPackageByName[child.Name()] |
| 1002 | |
| 1003 | // When parent is in the package, and child (or its variant) is not, this can be from an interface. |
| 1004 | if parentInPackage && !childInPackageName { |
| 1005 | requireModules = append(requireModules, child) |
| 1006 | } |
| 1007 | return true |
| 1008 | }) |
| 1009 | |
| 1010 | return provideModules, requireModules |
| 1011 | } |
Cole Faust | 26bdac5 | 2024-11-19 13:37:53 -0800 | [diff] [blame] | 1012 | |
| 1013 | // Checks that the given file doesn't exceed the given size, and will also print a warning |
| 1014 | // if it's nearing the maximum size. Equivalent to assert-max-image-size in make: |
| 1015 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10 |
| 1016 | func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) { |
| 1017 | if addAvbLater { |
| 1018 | // The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool. |
| 1019 | // Logic copied from make: |
| 1020 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6 |
| 1021 | maxSize -= 69632 |
| 1022 | } |
| 1023 | cmd := builder.Command() |
| 1024 | cmd.Textf(`file="%s"; maxsize="%d";`+ |
| 1025 | `total=$(stat -c "%%s" "$file" | tr -d '\n');`+ |
| 1026 | `if [ "$total" -gt "$maxsize" ]; then `+ |
| 1027 | ` echo "error: $file too large ($total > $maxsize)";`+ |
| 1028 | ` false;`+ |
| 1029 | `elif [ "$total" -gt $((maxsize - 32768)) ]; then `+ |
| 1030 | ` echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+ |
| 1031 | `fi`, |
| 1032 | image, maxSize) |
| 1033 | cmd.Implicit(image) |
| 1034 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 1035 | |
| 1036 | // addAutogeneratedRroDeps walks the transitive closure of vendor and product partitions. |
| 1037 | // It visits apps installed in system and system_ext partitions, and adds the autogenerated |
| 1038 | // RRO modules to its own deps. |
| 1039 | func addAutogeneratedRroDeps(ctx android.BottomUpMutatorContext) { |
| 1040 | f, ok := ctx.Module().(*filesystem) |
| 1041 | if !ok { |
| 1042 | return |
| 1043 | } |
| 1044 | thisPartition := f.PartitionType() |
| 1045 | if thisPartition != "vendor" && thisPartition != "product" { |
| 1046 | return |
| 1047 | } |
| 1048 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 1049 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1050 | if parent.Name() == f.Name() && depTag != interPartitionDependencyTag { |
| 1051 | return false // This is a module listed in deps of vendor/product filesystem |
| 1052 | } |
| 1053 | if vendorOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "vendor"); ctx.OtherModuleExists(vendorOverlay) && thisPartition == "vendor" { |
| 1054 | ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, vendorOverlay) |
| 1055 | } |
| 1056 | if productOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "product"); ctx.OtherModuleExists(productOverlay) && thisPartition == "product" { |
| 1057 | ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, productOverlay) |
| 1058 | } |
| 1059 | return true |
| 1060 | }) |
| 1061 | } |