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