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" |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 23 | "sort" |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 24 | "strconv" |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 25 | "strings" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 26 | |
| 27 | "android/soong/android" |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 28 | "android/soong/cc" |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 29 | "android/soong/java" |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 30 | "android/soong/linkerconfig" |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 31 | |
| 32 | "github.com/google/blueprint" |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 33 | "github.com/google/blueprint/proptools" |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | func init() { |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 37 | registerBuildComponents(android.InitRegistrationContext) |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 38 | registerMutators(android.InitRegistrationContext) |
Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func registerBuildComponents(ctx android.RegistrationContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 42 | ctx.RegisterModuleType("android_filesystem", FilesystemFactory) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 43 | ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 44 | ctx.RegisterModuleType("android_system_image", SystemImageFactory) |
Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 45 | ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 46 | ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory) |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 47 | ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 48 | ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 49 | } |
| 50 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 51 | func registerMutators(ctx android.RegistrationContext) { |
| 52 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 53 | ctx.BottomUp("add_autogenerated_rro_deps", addAutogeneratedRroDeps) |
| 54 | }) |
| 55 | } |
| 56 | |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 57 | // Remember to add referenced files to implicits! |
| 58 | var textFileProcessorRule = pctx.AndroidStaticRule("text_file_processing", blueprint.RuleParams{ |
| 59 | Command: "build/soong/scripts/text_file_processor.py $in $out", |
| 60 | CommandDeps: []string{"build/soong/scripts/text_file_processor.py"}, |
| 61 | }) |
| 62 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 63 | type filesystem struct { |
| 64 | android.ModuleBase |
| 65 | android.PackagingBase |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 66 | android.DefaultableModuleBase |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 67 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 68 | properties FilesystemProperties |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 69 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 70 | output android.Path |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 71 | installDir android.InstallPath |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 72 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 73 | fileListFile android.Path |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 74 | |
| 75 | // Keeps the entries installed from this filesystem |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 76 | entries []string |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 77 | |
| 78 | filesystemBuilder filesystemBuilder |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 79 | } |
| 80 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 81 | type filesystemBuilder interface { |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 82 | BuildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath, fullInstallPaths *[]FullInstallPathInfo) |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 83 | // Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() |
| 84 | FilterPackagingSpec(spec android.PackagingSpec) bool |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 85 | // Function that modifies PackagingSpec in PackagingBase.GatherPackagingSpecs() to customize. |
| 86 | // For example, GSI system.img contains system_ext and product artifacts and their |
| 87 | // relPathInPackage need to be rebased to system/system_ext and system/system_product. |
| 88 | ModifyPackagingSpec(spec *android.PackagingSpec) |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 89 | |
| 90 | // Function to check if the filesystem should not use `vintf_fragments` property, |
| 91 | // but use `vintf_fragment` module type instead |
| 92 | ShouldUseVintfFragmentModuleOnly() bool |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | var _ filesystemBuilder = (*filesystem)(nil) |
| 96 | |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 97 | type SymlinkDefinition struct { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 98 | Target *string |
| 99 | Name *string |
| 100 | } |
| 101 | |
Jihoon Kang | 0a45389 | 2024-12-09 22:16:26 +0000 | [diff] [blame] | 102 | // CopyWithNamePrefix returns a new [SymlinkDefinition] with prefix added to Name. |
| 103 | func (s *SymlinkDefinition) CopyWithNamePrefix(prefix string) SymlinkDefinition { |
| 104 | return SymlinkDefinition{ |
| 105 | Target: s.Target, |
| 106 | Name: proptools.StringPtr(filepath.Join(prefix, proptools.String(s.Name))), |
| 107 | } |
| 108 | } |
| 109 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 110 | type FilesystemProperties struct { |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 111 | // When set to true, sign the image with avbtool. Default is false. |
| 112 | Use_avb *bool |
| 113 | |
| 114 | // Path to the private key that avbtool will use to sign this filesystem image. |
| 115 | // TODO(jiyong): allow apex_key to be specified here |
| 116 | Avb_private_key *string `android:"path"` |
| 117 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 118 | // Signing algorithm for avbtool. Default is SHA256_RSA4096. |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 119 | Avb_algorithm *string |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 120 | |
Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 121 | // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to |
| 122 | // avbtool. Default used by avbtool is sha1. |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 123 | Avb_hash_algorithm *string |
| 124 | |
Spandan Das | e5c393c | 2024-12-12 19:25:07 +0000 | [diff] [blame] | 125 | // The security patch passed to as the com.android.build.<type>.security_patch avb property. |
| 126 | Security_patch *string |
| 127 | |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 128 | // Whether or not to use forward-error-correction codes when signing with AVB. Defaults to true. |
| 129 | Use_fec *bool |
| 130 | |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 131 | // The index used to prevent rollback of the image. Only used if use_avb is true. |
| 132 | Rollback_index *int64 |
| 133 | |
Jihoon Kang | 2f0d193 | 2025-01-17 19:22:44 +0000 | [diff] [blame] | 134 | // Rollback index location of this image. Must be 0, 1, 2, etc. |
| 135 | Rollback_index_location *int64 |
| 136 | |
Jiyong Park | ac4076d | 2021-03-15 23:21:30 +0900 | [diff] [blame] | 137 | // Name of the partition stored in vbmeta desc. Defaults to the name of this module. |
| 138 | Partition_name *string |
| 139 | |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 140 | // 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] | 141 | // is ext4. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 142 | Type *string |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 143 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 144 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 145 | // checks, and will be used in the future for API surface checks. |
| 146 | Partition_type *string |
| 147 | |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 148 | // file_contexts file to make image. Currently, only ext4 is supported. These file contexts |
| 149 | // will be compiled with sefcontext_compile |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 150 | File_contexts *string `android:"path"` |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 151 | |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 152 | // The selinux file contexts, after having already run them through sefcontext_compile |
| 153 | Precompiled_file_contexts *string `android:"path"` |
| 154 | |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 155 | // Base directory relative to root, to which deps are installed, e.g. "system". Default is "." |
| 156 | // (root). |
| 157 | Base_dir *string |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 158 | |
| 159 | // Directories to be created under root. e.g. /dev, /proc, etc. |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 160 | Dirs proptools.Configurable[[]string] |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 161 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 162 | // List of filesystem modules to include in creating the partition. The root directory of |
| 163 | // the provided filesystem modules are included in creating the partition. |
| 164 | // This is only supported for cpio and compressed cpio filesystem types. |
| 165 | Include_files_of []string |
| 166 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 167 | // Symbolic links to be created under root with "ln -sf <target> <name>". |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 168 | Symlinks []SymlinkDefinition |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 169 | |
| 170 | // Seconds since unix epoch to override timestamps of file entries |
| 171 | Fake_timestamp *string |
| 172 | |
| 173 | // When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed. |
| 174 | // Otherwise, they'll be set as random which might cause indeterministic build output. |
| 175 | Uuid *string |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 176 | |
| 177 | // Mount point for this image. Default is "/" |
| 178 | Mount_point *string |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 179 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 180 | // When set, builds etc/event-log-tags file by merging logtags from all dependencies. |
| 181 | // Default is false |
| 182 | Build_logtags *bool |
| 183 | |
Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 184 | // Install aconfig_flags.pb file for the modules installed in this partition. |
| 185 | Gen_aconfig_flags_pb *bool |
| 186 | |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 187 | // List of names of other filesystem partitions to import their aconfig flags from. |
| 188 | // This is used for the system partition to import system_ext's aconfig flags, as currently |
| 189 | // those are considered one "container": aosp/3261300 |
| 190 | Import_aconfig_flags_from []string |
| 191 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 192 | Fsverity fsverityProperties |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 193 | |
| 194 | // If this property is set to true, the filesystem will call ctx.UncheckedModule(), causing |
| 195 | // it to not be built on checkbuilds. Used for the automatic migration from make to soong |
| 196 | // build modules, where we want to emit some not-yet-working filesystems and we don't want them |
| 197 | // to be built. |
| 198 | Unchecked_module *bool `blueprint:"mutated"` |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 199 | |
| 200 | Erofs ErofsProperties |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 201 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 202 | F2fs F2fsProperties |
| 203 | |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 204 | Linker_config LinkerConfigProperties |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 205 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 206 | // Determines if the module is auto-generated from Soong or not. If the module is |
| 207 | // auto-generated, its deps are exempted from visibility enforcement. |
| 208 | Is_auto_generated *bool |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 209 | |
| 210 | // Path to the dev nodes description file. This is only needed for building the ramdisk |
| 211 | // partition and should not be explicitly specified. |
| 212 | Dev_nodes_description_file *string `android:"path" blueprint:"mutated"` |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 213 | |
| 214 | // Additional dependencies used for building android products |
| 215 | Android_filesystem_deps AndroidFilesystemDeps |
Spandan Das | c49b85e | 2025-01-10 00:51:25 +0000 | [diff] [blame] | 216 | |
| 217 | // Name of the output. Default is $(module_name).img |
| 218 | Stem *string |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 219 | |
| 220 | // The size of the partition on the device. It will be a build error if this built partition |
| 221 | // image exceeds this size. |
| 222 | Partition_size *int64 |
Jihoon Kang | 6d08d92 | 2025-01-14 18:31:57 +0000 | [diff] [blame] | 223 | |
| 224 | // Whether to format f2fs and ext4 in a way that supports casefolding |
| 225 | Support_casefolding *bool |
| 226 | |
| 227 | // Whether to format f2fs and ext4 in a way that supports project quotas |
| 228 | Support_project_quota *bool |
| 229 | |
| 230 | // Whether to enable per-file compression in f2fs |
| 231 | Enable_compression *bool |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | type AndroidFilesystemDeps struct { |
| 235 | System *string |
| 236 | System_ext *string |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // Additional properties required to generate erofs FS partitions. |
| 240 | type ErofsProperties struct { |
| 241 | // Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9) |
| 242 | // Please see external/erofs-utils/README for complete documentation. |
| 243 | Compressor *string |
| 244 | |
| 245 | // Used as --compress-hints for mkfs.erofs |
| 246 | Compress_hints *string `android:"path"` |
| 247 | |
| 248 | Sparse *bool |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 249 | } |
| 250 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 251 | // Additional properties required to generate f2fs FS partitions. |
| 252 | type F2fsProperties struct { |
| 253 | Sparse *bool |
| 254 | } |
| 255 | |
Spandan Das | 173256b | 2024-10-31 19:59:30 +0000 | [diff] [blame] | 256 | type LinkerConfigProperties struct { |
| 257 | |
| 258 | // Build a linker.config.pb file |
| 259 | Gen_linker_config *bool |
| 260 | |
| 261 | // List of files (in .json format) that will be converted to a linker config file (in .pb format). |
| 262 | // The linker config file be installed in the filesystem at /etc/linker.config.pb |
| 263 | Linker_config_srcs []string `android:"path"` |
| 264 | } |
| 265 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 266 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem |
| 267 | // image. The filesystem images are expected to be mounted in the target device, which means the |
| 268 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). |
| 269 | // The modules are placed in the filesystem image just like they are installed to the ordinary |
| 270 | // 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] | 271 | func FilesystemFactory() android.Module { |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 272 | module := &filesystem{} |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 273 | module.filesystemBuilder = module |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 274 | initFilesystemModule(module, module) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 275 | return module |
| 276 | } |
| 277 | |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 278 | func initFilesystemModule(module android.DefaultableModule, filesystemModule *filesystem) { |
| 279 | module.AddProperties(&filesystemModule.properties) |
| 280 | android.InitPackageModule(filesystemModule) |
| 281 | filesystemModule.PackagingBase.DepsCollectFirstTargetOnly = true |
Jihoon Kang | 79196c5 | 2024-10-30 18:49:47 +0000 | [diff] [blame] | 282 | filesystemModule.PackagingBase.AllowHighPriorityDeps = true |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 283 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 284 | android.InitDefaultableModule(module) |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 285 | |
| 286 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 287 | filesystemModule.setDevNodesDescriptionProp() |
| 288 | }) |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 289 | } |
| 290 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 291 | type depTag struct { |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 292 | blueprint.BaseDependencyTag |
Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 293 | android.PackagingItemAlwaysDepTag |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | var dependencyTag = depTag{} |
| 297 | |
| 298 | type depTagWithVisibilityEnforcementBypass struct { |
| 299 | depTag |
| 300 | } |
| 301 | |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 302 | type interPartitionDepTag struct { |
| 303 | blueprint.BaseDependencyTag |
| 304 | } |
| 305 | |
| 306 | var interPartitionDependencyTag = interPartitionDepTag{} |
| 307 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 308 | var interPartitionInstallDependencyTag = interPartitionDepTag{} |
| 309 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 310 | var _ android.ExcludeFromVisibilityEnforcementTag = (*depTagWithVisibilityEnforcementBypass)(nil) |
| 311 | |
| 312 | func (t depTagWithVisibilityEnforcementBypass) ExcludeFromVisibilityEnforcement() {} |
| 313 | |
| 314 | var dependencyTagWithVisibilityEnforcementBypass = depTagWithVisibilityEnforcementBypass{} |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 315 | |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 316 | // ramdiskDevNodesDescription is the name of the filegroup module that provides the file that |
| 317 | // contains the description of dev nodes added to the CPIO archive for the ramdisk partition. |
| 318 | const ramdiskDevNodesDescription = "ramdisk_node_list" |
| 319 | |
| 320 | func (f *filesystem) setDevNodesDescriptionProp() { |
| 321 | if proptools.String(f.properties.Partition_name) == "ramdisk" { |
| 322 | f.properties.Dev_nodes_description_file = proptools.StringPtr(":" + ramdiskDevNodesDescription) |
| 323 | } |
| 324 | } |
| 325 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 326 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 327 | if proptools.Bool(f.properties.Is_auto_generated) { |
| 328 | f.AddDeps(ctx, dependencyTagWithVisibilityEnforcementBypass) |
| 329 | } else { |
| 330 | f.AddDeps(ctx, dependencyTag) |
| 331 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 332 | if f.properties.Android_filesystem_deps.System != nil { |
| 333 | ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System)) |
| 334 | } |
| 335 | if f.properties.Android_filesystem_deps.System_ext != nil { |
| 336 | ctx.AddDependency(ctx.Module(), interPartitionDependencyTag, proptools.String(f.properties.Android_filesystem_deps.System_ext)) |
| 337 | } |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 338 | for _, partition := range f.properties.Import_aconfig_flags_from { |
| 339 | ctx.AddDependency(ctx.Module(), importAconfigDependencyTag, partition) |
| 340 | } |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 341 | for _, partition := range f.properties.Include_files_of { |
| 342 | ctx.AddDependency(ctx.Module(), interPartitionInstallDependencyTag, partition) |
| 343 | } |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 344 | } |
| 345 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 346 | type fsType int |
| 347 | |
| 348 | const ( |
| 349 | ext4Type fsType = iota |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 350 | erofsType |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 351 | f2fsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 352 | compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 353 | cpioType // uncompressed |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 354 | unknown |
| 355 | ) |
| 356 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 357 | func (fs fsType) IsUnknown() bool { |
| 358 | return fs == unknown |
| 359 | } |
| 360 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 361 | type FilesystemInfo struct { |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 362 | // The built filesystem image |
| 363 | Output android.Path |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 364 | // An additional hermetic filesystem image. |
| 365 | // e.g. this will contain inodes with pinned timestamps. |
| 366 | // This will be copied to target_files.zip |
| 367 | OutputHermetic android.Path |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 368 | // A text file containing the list of paths installed on the partition. |
| 369 | FileListFile android.Path |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 370 | // The root staging directory used to build the output filesystem. If consuming this, make sure |
| 371 | // to add a dependency on the Output file, as you cannot add dependencies on directories |
| 372 | // in ninja. |
| 373 | RootDir android.Path |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 374 | // The rebased staging directory used to build the output filesystem. If consuming this, make |
| 375 | // sure to add a dependency on the Output file, as you cannot add dependencies on directories |
| 376 | // in ninja. In many cases this is the same as RootDir, only in the system partition is it |
| 377 | // different. There, it points to the "system" sub-directory of RootDir. |
| 378 | RebasedDir android.Path |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 379 | // A text file with block data of the .img file |
| 380 | // This is an implicit output of `build_image` |
| 381 | MapFile android.Path |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 382 | // Name of the module that produced this FilesystemInfo origionally. (though it may be |
| 383 | // re-exported by super images or boot images) |
| 384 | ModuleName string |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 385 | // The property file generated by this module and passed to build_image. |
| 386 | // It's exported here so that system_other can reuse system's property file. |
| 387 | BuildImagePropFile android.Path |
| 388 | // Paths to all the tools referenced inside of the build image property file. |
| 389 | BuildImagePropFileDeps android.Paths |
Cole Faust | b8e280f | 2025-01-16 16:33:26 -0800 | [diff] [blame] | 390 | // Packaging specs to be installed on the system_other image, for the initial boot's dexpreopt. |
| 391 | SpecsForSystemOther map[string]android.PackagingSpec |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 392 | |
| 393 | FullInstallPaths []FullInstallPathInfo |
| 394 | } |
| 395 | |
| 396 | // FullInstallPathInfo contains information about the "full install" paths of all the files |
| 397 | // inside this partition. The full install paths are the files installed in |
| 398 | // out/target/product/<device>/<partition>. This is essentially legacy behavior, maintained for |
| 399 | // tools like adb sync and adevice, but we should update them to query the build system for the |
| 400 | // installed files no matter where they are. |
| 401 | type FullInstallPathInfo struct { |
| 402 | // RequiresFullInstall tells us if the origional module did the install to FullInstallPath |
| 403 | // already. If it's false, the android_device module needs to emit the install rule. |
| 404 | RequiresFullInstall bool |
| 405 | // The "full install" paths for the files in this filesystem. This is the paths in the |
| 406 | // out/target/product/<device>/<partition> folder. They're not used by this filesystem, |
| 407 | // but can be depended on by the top-level android_device module to cause the staging |
| 408 | // directories to be built. |
| 409 | FullInstallPath android.InstallPath |
| 410 | |
| 411 | // The file that's copied to FullInstallPath. May be nil if SymlinkTarget is set or IsDir is |
| 412 | // true. |
| 413 | SourcePath android.Path |
| 414 | |
| 415 | // The target of the symlink, if this file is a symlink. |
| 416 | SymlinkTarget string |
| 417 | |
| 418 | // If this file is a directory. Only used for empty directories, which are mostly mount points. |
| 419 | IsDir bool |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | var FilesystemProvider = blueprint.NewProvider[FilesystemInfo]() |
| 423 | |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 424 | type FilesystemDefaultsInfo struct { |
| 425 | // Identifies which partition this is for //visibility:any_system_image (and others) visibility |
| 426 | // checks, and will be used in the future for API surface checks. |
| 427 | PartitionType string |
| 428 | } |
| 429 | |
| 430 | var FilesystemDefaultsInfoProvider = blueprint.NewProvider[FilesystemDefaultsInfo]() |
| 431 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 432 | func GetFsTypeFromString(ctx android.EarlyModuleContext, typeStr string) fsType { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 433 | switch typeStr { |
| 434 | case "ext4": |
| 435 | return ext4Type |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 436 | case "erofs": |
| 437 | return erofsType |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 438 | case "f2fs": |
| 439 | return f2fsType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 440 | case "compressed_cpio": |
| 441 | return compressedCpioType |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 442 | case "cpio": |
| 443 | return cpioType |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 444 | default: |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 445 | return unknown |
| 446 | } |
| 447 | } |
| 448 | |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 449 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { |
| 450 | typeStr := proptools.StringDefault(f.properties.Type, "ext4") |
| 451 | fsType := GetFsTypeFromString(ctx, typeStr) |
| 452 | if fsType == unknown { |
| 453 | ctx.PropertyErrorf("type", "%q not supported", typeStr) |
| 454 | } |
| 455 | return fsType |
| 456 | } |
| 457 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 458 | func (f *filesystem) installFileName() string { |
Spandan Das | c49b85e | 2025-01-10 00:51:25 +0000 | [diff] [blame] | 459 | return proptools.StringDefault(f.properties.Stem, f.BaseModuleName()+".img") |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 460 | } |
| 461 | |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 462 | func (f *filesystem) partitionName() string { |
| 463 | return proptools.StringDefault(f.properties.Partition_name, f.Name()) |
| 464 | } |
| 465 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 466 | func (f *filesystem) FilterPackagingSpec(ps android.PackagingSpec) bool { |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 467 | // Filesystem module respects the installation semantic. A PackagingSpec from a module with |
| 468 | // IsSkipInstall() is skipped. |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 469 | if ps.SkipInstall() { |
| 470 | return false |
Spandan Das | 6d05650 | 2024-10-21 15:40:32 +0000 | [diff] [blame] | 471 | } |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 472 | if proptools.Bool(f.properties.Is_auto_generated) { // TODO (spandandas): Remove this. |
| 473 | pt := f.PartitionType() |
Cole Faust | c88cff1 | 2024-11-12 13:24:05 -0800 | [diff] [blame] | 474 | return ps.Partition() == pt || strings.HasPrefix(ps.Partition(), pt+"/") |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 475 | } |
| 476 | return true |
Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 479 | func (f *filesystem) ModifyPackagingSpec(ps *android.PackagingSpec) { |
Cole Faust | c88cff1 | 2024-11-12 13:24:05 -0800 | [diff] [blame] | 480 | // Sometimes, android.modulePartition() returns a path with >1 path components. |
| 481 | // This makes the partition field of packagingSpecs have multiple components, like |
| 482 | // "system/product". Right now, the filesystem module doesn't look at the partition field |
| 483 | // when deciding what path to install the file under, only the RelPathInPackage field, so |
| 484 | // we move the later path components from partition to relPathInPackage. This should probably |
| 485 | // be revisited in the future. |
| 486 | prefix := f.PartitionType() + "/" |
| 487 | if strings.HasPrefix(ps.Partition(), prefix) { |
| 488 | subPartition := strings.TrimPrefix(ps.Partition(), prefix) |
| 489 | ps.SetPartition(f.PartitionType()) |
| 490 | ps.SetRelPathInPackage(filepath.Join(subPartition, ps.RelPathInPackage())) |
| 491 | } |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 492 | } |
| 493 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 494 | var pctx = android.NewPackageContext("android/soong/filesystem") |
| 495 | |
| 496 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 497 | validatePartitionType(ctx, f) |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 498 | if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() { |
| 499 | f.validateVintfFragments(ctx) |
| 500 | } |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 501 | |
| 502 | if len(f.properties.Include_files_of) > 0 && !android.InList(f.fsType(ctx), []fsType{compressedCpioType, cpioType}) { |
| 503 | ctx.PropertyErrorf("include_files_of", "include_files_of is only supported for cpio and compressed cpio filesystem types.") |
| 504 | } |
| 505 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 506 | rootDir := android.PathForModuleOut(ctx, f.rootDirString()).OutputPath |
| 507 | rebasedDir := rootDir |
| 508 | if f.properties.Base_dir != nil { |
| 509 | rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) |
| 510 | } |
| 511 | builder := android.NewRuleBuilder(pctx, ctx) |
| 512 | |
| 513 | // Wipe the root dir to get rid of leftover files from prior builds |
| 514 | builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) |
| 515 | specs := f.gatherFilteredPackagingSpecs(ctx) |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 516 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 517 | var fullInstallPaths []FullInstallPathInfo |
| 518 | for _, spec := range specs { |
| 519 | fullInstallPaths = append(fullInstallPaths, FullInstallPathInfo{ |
| 520 | FullInstallPath: spec.FullInstallPath(), |
| 521 | RequiresFullInstall: spec.RequiresFullInstall(), |
| 522 | SourcePath: spec.SrcPath(), |
| 523 | SymlinkTarget: spec.ToGob().SymlinkTarget, |
| 524 | }) |
| 525 | } |
| 526 | |
| 527 | f.entries = f.copyPackagingSpecs(ctx, builder, specs, rootDir, rebasedDir) |
| 528 | f.buildNonDepsFiles(ctx, builder, rootDir, rebasedDir, &fullInstallPaths) |
| 529 | f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir, &fullInstallPaths) |
| 530 | f.buildEventLogtagsFile(ctx, builder, rebasedDir, &fullInstallPaths) |
| 531 | f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir, &fullInstallPaths) |
| 532 | f.filesystemBuilder.BuildLinkerConfigFile(ctx, builder, rebasedDir, &fullInstallPaths) |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 533 | |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 534 | var mapFile android.Path |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 535 | var outputHermetic android.Path |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 536 | var buildImagePropFile android.Path |
| 537 | var buildImagePropFileDeps android.Paths |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 538 | switch f.fsType(ctx) { |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 539 | case ext4Type, erofsType, f2fsType: |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 540 | f.output, outputHermetic, buildImagePropFile, buildImagePropFileDeps = f.buildImageUsingBuildImage(ctx, builder, rootDir, rebasedDir) |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 541 | mapFile = f.getMapFile(ctx) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 542 | case compressedCpioType: |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 543 | f.output = f.buildCpioImage(ctx, builder, rootDir, true) |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 544 | case cpioType: |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 545 | f.output = f.buildCpioImage(ctx, builder, rootDir, false) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 546 | default: |
| 547 | return |
| 548 | } |
| 549 | |
| 550 | f.installDir = android.PathForModuleInstall(ctx, "etc") |
| 551 | ctx.InstallFile(f.installDir, f.installFileName(), f.output) |
mrziwang | 555d133 | 2024-06-07 11:15:33 -0700 | [diff] [blame] | 552 | ctx.SetOutputFiles([]android.Path{f.output}, "") |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 553 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 554 | if f.partitionName() == "recovery" { |
| 555 | rootDir = rootDir.Join(ctx, "root") |
| 556 | } |
| 557 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 558 | fileListFile := android.PathForModuleOut(ctx, "fileList") |
| 559 | android.WriteFileRule(ctx, fileListFile, f.installedFilesList()) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 560 | |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 561 | fsInfo := FilesystemInfo{ |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 562 | Output: f.output, |
| 563 | OutputHermetic: outputHermetic, |
| 564 | FileListFile: fileListFile, |
| 565 | RootDir: rootDir, |
| 566 | RebasedDir: rebasedDir, |
| 567 | MapFile: mapFile, |
| 568 | ModuleName: ctx.ModuleName(), |
| 569 | BuildImagePropFile: buildImagePropFile, |
| 570 | BuildImagePropFileDeps: buildImagePropFileDeps, |
Cole Faust | b8e280f | 2025-01-16 16:33:26 -0800 | [diff] [blame] | 571 | SpecsForSystemOther: f.systemOtherFiles(ctx), |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 572 | FullInstallPaths: fullInstallPaths, |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 573 | } |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 574 | |
| 575 | android.SetProvider(ctx, FilesystemProvider, fsInfo) |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 576 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 577 | f.fileListFile = fileListFile |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 578 | |
| 579 | if proptools.Bool(f.properties.Unchecked_module) { |
| 580 | ctx.UncheckedModule() |
| 581 | } |
Jihoon Kang | 2f0d193 | 2025-01-17 19:22:44 +0000 | [diff] [blame] | 582 | |
| 583 | f.setVbmetaPartitionProvider(ctx) |
| 584 | } |
| 585 | |
| 586 | func (f *filesystem) setVbmetaPartitionProvider(ctx android.ModuleContext) { |
| 587 | var extractedPublicKey android.ModuleOutPath |
| 588 | if f.properties.Avb_private_key != nil { |
| 589 | key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) |
| 590 | extractedPublicKey = android.PathForModuleOut(ctx, f.partitionName()+".avbpubkey") |
| 591 | ctx.Build(pctx, android.BuildParams{ |
| 592 | Rule: extractPublicKeyRule, |
| 593 | Input: key, |
| 594 | Output: extractedPublicKey, |
| 595 | }) |
| 596 | } |
| 597 | |
| 598 | var ril int |
| 599 | if f.properties.Rollback_index_location != nil { |
| 600 | ril = proptools.Int(f.properties.Rollback_index_location) |
| 601 | } |
| 602 | |
| 603 | android.SetProvider(ctx, vbmetaPartitionProvider, vbmetaPartitionInfo{ |
| 604 | Name: f.partitionName(), |
| 605 | RollbackIndexLocation: ril, |
| 606 | PublicKey: extractedPublicKey, |
| 607 | Output: f.output, |
| 608 | }) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 609 | } |
| 610 | |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 611 | func (f *filesystem) getMapFile(ctx android.ModuleContext) android.WritablePath { |
| 612 | // create the filepath by replacing the extension of the corresponding img file |
| 613 | return android.PathForModuleOut(ctx, f.installFileName()).ReplaceExtension(ctx, "map") |
| 614 | } |
| 615 | |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 616 | func (f *filesystem) validateVintfFragments(ctx android.ModuleContext) { |
| 617 | visitedModule := map[string]bool{} |
| 618 | packagingSpecs := f.gatherFilteredPackagingSpecs(ctx) |
| 619 | |
| 620 | moduleInFileSystem := func(mod android.Module) bool { |
| 621 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 622 | ctx, mod, android.InstallFilesProvider).PackagingSpecs { |
| 623 | if _, ok := packagingSpecs[ps.RelPathInPackage()]; ok { |
| 624 | return true |
| 625 | } |
| 626 | } |
| 627 | return false |
| 628 | } |
| 629 | |
| 630 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 631 | if visitedModule[child.Name()] { |
| 632 | return false |
| 633 | } |
| 634 | if !moduleInFileSystem(child) { |
| 635 | visitedModule[child.Name()] = true |
| 636 | return true |
| 637 | } |
| 638 | if vintfFragments := child.VintfFragments(ctx); vintfFragments != nil { |
| 639 | ctx.PropertyErrorf( |
| 640 | "vintf_fragments", |
| 641 | "Module %s is referenced by soong-defined filesystem %s with property vintf_fragments(%s) in use."+ |
| 642 | " Use vintf_fragment_modules property instead.", |
| 643 | child.Name(), |
| 644 | f.BaseModuleName(), |
| 645 | strings.Join(vintfFragments, ", "), |
| 646 | ) |
| 647 | } |
| 648 | visitedModule[child.Name()] = true |
| 649 | return true |
| 650 | }) |
| 651 | } |
| 652 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 653 | func (f *filesystem) appendToEntry(ctx android.ModuleContext, installedFile android.Path) { |
Spandan Das | 420e16a | 2024-12-11 18:10:52 +0000 | [diff] [blame] | 654 | partitionBaseDir := android.PathForModuleOut(ctx, f.rootDirString(), proptools.String(f.properties.Base_dir)).String() + "/" |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 655 | |
| 656 | relPath, inTargetPartition := strings.CutPrefix(installedFile.String(), partitionBaseDir) |
| 657 | if inTargetPartition { |
| 658 | f.entries = append(f.entries, relPath) |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | func (f *filesystem) installedFilesList() string { |
| 663 | installedFilePaths := android.FirstUniqueStrings(f.entries) |
| 664 | slices.Sort(installedFilePaths) |
| 665 | |
| 666 | return strings.Join(installedFilePaths, "\n") |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 667 | } |
| 668 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 669 | func validatePartitionType(ctx android.ModuleContext, p partition) { |
| 670 | if !android.InList(p.PartitionType(), validPartitions) { |
| 671 | ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType()) |
| 672 | } |
| 673 | |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 674 | ctx.VisitDirectDepsProxyWithTag(android.DefaultsDepTag, func(m android.ModuleProxy) { |
| 675 | if fdm, ok := android.OtherModuleProvider(ctx, m, FilesystemDefaultsInfoProvider); ok { |
| 676 | if p.PartitionType() != fdm.PartitionType { |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 677 | ctx.PropertyErrorf("partition_type", |
| 678 | "%s doesn't match with the partition type %s of the filesystem default module %s", |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 679 | p.PartitionType(), fdm.PartitionType, m.Name()) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | }) |
| 683 | } |
| 684 | |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 685 | // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files |
| 686 | // already in `rootDir`. |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 687 | func (f *filesystem) buildNonDepsFiles( |
| 688 | ctx android.ModuleContext, |
| 689 | builder *android.RuleBuilder, |
| 690 | rootDir android.OutputPath, |
| 691 | rebasedDir android.OutputPath, |
| 692 | fullInstallPaths *[]FullInstallPathInfo, |
| 693 | ) { |
| 694 | rebasedPrefix, err := filepath.Rel(rootDir.String(), rebasedDir.String()) |
| 695 | if err != nil || strings.HasPrefix(rebasedPrefix, "../") { |
| 696 | panic("rebasedDir could not be made relative to rootDir") |
| 697 | } |
| 698 | if !strings.HasSuffix(rebasedPrefix, "/") { |
| 699 | rebasedPrefix += "/" |
| 700 | } |
| 701 | if rebasedPrefix == "./" { |
| 702 | rebasedPrefix = "" |
| 703 | } |
| 704 | |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 705 | // create dirs and symlinks |
Cole Faust | d9c6a5b | 2024-05-21 14:54:00 -0700 | [diff] [blame] | 706 | for _, dir := range f.properties.Dirs.GetOrDefault(ctx, nil) { |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 707 | // OutputPath.Join verifies dir |
| 708 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 709 | // Only add the fullInstallPath logic for files in the rebased dir. The root dir |
| 710 | // is harder to install to. |
| 711 | if strings.HasPrefix(dir, rebasedPrefix) { |
| 712 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 713 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), strings.TrimPrefix(dir, rebasedPrefix)), |
| 714 | IsDir: true, |
| 715 | }) |
| 716 | } |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | for _, symlink := range f.properties.Symlinks { |
| 720 | name := strings.TrimSpace(proptools.String(symlink.Name)) |
| 721 | target := strings.TrimSpace(proptools.String(symlink.Target)) |
| 722 | |
| 723 | if name == "" { |
| 724 | ctx.PropertyErrorf("symlinks", "Name can't be empty") |
| 725 | continue |
| 726 | } |
| 727 | |
| 728 | if target == "" { |
| 729 | ctx.PropertyErrorf("symlinks", "Target can't be empty") |
| 730 | continue |
| 731 | } |
| 732 | |
| 733 | // OutputPath.Join verifies name. don't need to verify target. |
| 734 | dst := rootDir.Join(ctx, name) |
Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 735 | 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] | 736 | builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) |
| 737 | builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 738 | f.appendToEntry(ctx, dst) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 739 | // Only add the fullInstallPath logic for files in the rebased dir. The root dir |
| 740 | // is harder to install to. |
| 741 | if strings.HasPrefix(name, rebasedPrefix) { |
| 742 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 743 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), strings.TrimPrefix(name, rebasedPrefix)), |
| 744 | SymlinkTarget: target, |
| 745 | }) |
| 746 | } |
Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 747 | } |
Jihoon Kang | 89e8a69 | 2024-12-18 19:28:33 +0000 | [diff] [blame] | 748 | |
| 749 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2835;drc=b186569ef00ff2f2a1fab28aedc75ebc32bcd67b |
| 750 | if f.partitionName() == "recovery" { |
| 751 | builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, "root/linkerconfig").String()) |
| 752 | builder.Command().Text("touch").Text(rootDir.Join(ctx, "root/linkerconfig/ld.config.txt").String()) |
| 753 | } |
Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 754 | } |
| 755 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 756 | func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *android.RuleBuilder, specs map[string]android.PackagingSpec, rootDir, rebasedDir android.WritablePath) []string { |
| 757 | rootDirSpecs := make(map[string]android.PackagingSpec) |
| 758 | rebasedDirSpecs := make(map[string]android.PackagingSpec) |
| 759 | |
| 760 | for rel, spec := range specs { |
| 761 | if spec.Partition() == "root" { |
| 762 | rootDirSpecs[rel] = spec |
| 763 | } else { |
| 764 | rebasedDirSpecs[rel] = spec |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | dirsToSpecs := make(map[android.WritablePath]map[string]android.PackagingSpec) |
| 769 | dirsToSpecs[rootDir] = rootDirSpecs |
| 770 | dirsToSpecs[rebasedDir] = rebasedDirSpecs |
| 771 | |
| 772 | return f.CopySpecsToDirs(ctx, builder, dirsToSpecs) |
| 773 | } |
| 774 | |
Spandan Das | 420e16a | 2024-12-11 18:10:52 +0000 | [diff] [blame] | 775 | func (f *filesystem) rootDirString() string { |
| 776 | return f.partitionName() |
| 777 | } |
| 778 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 779 | func (f *filesystem) buildImageUsingBuildImage( |
| 780 | ctx android.ModuleContext, |
| 781 | builder *android.RuleBuilder, |
| 782 | rootDir android.OutputPath, |
| 783 | rebasedDir android.OutputPath, |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 784 | ) (android.Path, android.Path, android.Path, android.Paths) { |
Nikita Ioffe | 519015f | 2022-12-23 15:36:29 +0000 | [diff] [blame] | 785 | // run host_init_verifier |
| 786 | // Ideally we should have a concept of pluggable linters that verify the generated image. |
| 787 | // While such concept is not implement this will do. |
| 788 | // TODO(b/263574231): substitute with pluggable linter. |
| 789 | builder.Command(). |
| 790 | BuiltTool("host_init_verifier"). |
| 791 | FlagWithArg("--out_system=", rootDir.String()+"/system") |
| 792 | |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 793 | propFile, toolDeps := f.buildPropFile(ctx) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 794 | |
| 795 | // Most of the time, if build_image were to call a host tool, it accepts the path to the |
| 796 | // host tool in a field in the prop file. However, it doesn't have that option for fec, which |
| 797 | // it expects to just be on the PATH. Add fec to the PATH. |
| 798 | fec := ctx.Config().HostToolPath(ctx, "fec") |
| 799 | pathToolDirs := []string{filepath.Dir(fec.String())} |
| 800 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 801 | output := android.PathForModuleOut(ctx, f.installFileName()) |
Spandan Das | 33c9c47 | 2025-01-14 19:26:23 +0000 | [diff] [blame] | 802 | builder.Command().Text("touch").Output(f.getMapFile(ctx)) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 803 | builder.Command(). |
| 804 | Textf("PATH=%s:$PATH", strings.Join(pathToolDirs, ":")). |
| 805 | BuiltTool("build_image"). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 806 | Text(rootDir.String()). // input directory |
| 807 | Input(propFile). |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 808 | Implicits(toolDeps). |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 809 | Implicit(fec). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 810 | Output(output). |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 811 | Text(rootDir.String()) // directory where to find fs_config_files|dirs |
| 812 | |
Spandan Das | 3ccda6e | 2025-01-30 00:22:05 +0000 | [diff] [blame] | 813 | // TODO (b/393203512): Re-enable hermetic img file creation for target_files.zip |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 814 | // Add an additional cmd to create a hermetic img file. This will contain pinned timestamps e.g. |
Spandan Das | 3ccda6e | 2025-01-30 00:22:05 +0000 | [diff] [blame] | 815 | //propFilePinnedTimestamp := android.PathForModuleOut(ctx, "for_target_files", "prop") |
| 816 | //builder.Command().Textf("cat").Input(propFile).Flag(">").Output(propFilePinnedTimestamp). |
| 817 | // Textf(" && echo use_fixed_timestamp=true >> %s", propFilePinnedTimestamp). |
| 818 | // Textf(" && echo block_list=%s >> %s", f.getMapFile(ctx).String(), propFilePinnedTimestamp) // mapfile will be an implicit output |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 819 | |
Spandan Das | 3ccda6e | 2025-01-30 00:22:05 +0000 | [diff] [blame] | 820 | //outputHermetic := android.PathForModuleOut(ctx, "for_target_files", f.installFileName()) |
| 821 | //builder.Command(). |
| 822 | // Textf("PATH=%s:$PATH", strings.Join(pathToolDirs, ":")). |
| 823 | // BuiltTool("build_image"). |
| 824 | // Text(rootDir.String()). // input directory |
| 825 | // Flag(propFilePinnedTimestamp.String()). |
| 826 | // Implicits(toolDeps). |
| 827 | // Implicit(fec). |
| 828 | // Output(outputHermetic). |
| 829 | // Text(rootDir.String()) // directory where to find fs_config_files|dirs |
Spandan Das | 1f0a5a1 | 2025-01-15 00:53:15 +0000 | [diff] [blame] | 830 | |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 831 | if f.properties.Partition_size != nil { |
| 832 | assertMaxImageSize(builder, output, *f.properties.Partition_size, false) |
| 833 | } |
| 834 | |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 835 | // rootDir is not deleted. Might be useful for quick inspection. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 836 | builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 837 | |
Spandan Das | 3ccda6e | 2025-01-30 00:22:05 +0000 | [diff] [blame] | 838 | return output, nil, propFile, toolDeps |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 839 | } |
| 840 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 841 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.Path { |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 842 | builder := android.NewRuleBuilder(pctx, ctx) |
| 843 | fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") |
| 844 | builder.Command().BuiltTool("sefcontext_compile"). |
| 845 | FlagWithOutput("-o ", fcBin). |
| 846 | Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) |
| 847 | 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] | 848 | return fcBin |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 849 | } |
| 850 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 851 | func (f *filesystem) buildPropFile(ctx android.ModuleContext) (android.Path, android.Paths) { |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 852 | var deps android.Paths |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 853 | var lines []string |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 854 | addStr := func(name string, value string) { |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 855 | lines = append(lines, fmt.Sprintf("%s=%s", name, value)) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 856 | } |
| 857 | addPath := func(name string, path android.Path) { |
Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 858 | addStr(name, path.String()) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 859 | deps = append(deps, path) |
| 860 | } |
| 861 | |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 862 | // Type string that build_image.py accepts. |
| 863 | fsTypeStr := func(t fsType) string { |
| 864 | switch t { |
Spandan Das | 9466882 | 2024-10-09 20:51:33 +0000 | [diff] [blame] | 865 | // TODO(372522486): add more types like f2fs, erofs, etc. |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 866 | case ext4Type: |
| 867 | return "ext4" |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 868 | case erofsType: |
| 869 | return "erofs" |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 870 | case f2fsType: |
| 871 | return "f2fs" |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 872 | } |
| 873 | panic(fmt.Errorf("unsupported fs type %v", t)) |
| 874 | } |
| 875 | |
| 876 | addStr("fs_type", fsTypeStr(f.fsType(ctx))) |
Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 877 | addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 878 | addStr("use_dynamic_partition_size", "true") |
| 879 | addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) |
| 880 | // b/177813163 deps of the host tools have to be added. Remove this. |
| 881 | for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { |
| 882 | deps = append(deps, ctx.Config().HostToolPath(ctx, t)) |
| 883 | } |
| 884 | |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 885 | if proptools.Bool(f.properties.Use_avb) { |
| 886 | addStr("avb_hashtree_enable", "true") |
| 887 | addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) |
| 888 | algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") |
| 889 | addStr("avb_algorithm", algorithm) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 890 | if f.properties.Avb_private_key != nil { |
| 891 | key := android.PathForModuleSrc(ctx, *f.properties.Avb_private_key) |
| 892 | addPath("avb_key_path", key) |
| 893 | } |
Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 894 | addStr("partition_name", f.partitionName()) |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 895 | avb_add_hashtree_footer_args := "" |
| 896 | if !proptools.BoolDefault(f.properties.Use_fec, true) { |
| 897 | avb_add_hashtree_footer_args += " --do_not_generate_fec" |
| 898 | } |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 899 | if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { |
| 900 | avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm |
| 901 | } |
Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 902 | if f.properties.Rollback_index != nil { |
| 903 | rollbackIndex := proptools.Int(f.properties.Rollback_index) |
| 904 | if rollbackIndex < 0 { |
| 905 | ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") |
| 906 | } |
| 907 | avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) |
| 908 | } |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 909 | avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.os_version:%s", f.partitionName(), ctx.Config().PlatformVersionLastStable()) |
Cole Faust | efeb5c4 | 2024-12-16 10:47:26 -0800 | [diff] [blame] | 910 | // We're not going to add BuildFingerPrintFile as a dep. If it changed, it's likely because |
| 911 | // the build number changed, and we don't want to trigger rebuilds solely based on the build |
| 912 | // number. |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 913 | avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.fingerprint:{CONTENTS_OF:%s}", f.partitionName(), ctx.Config().BuildFingerprintFile(ctx)) |
Spandan Das | e5c393c | 2024-12-12 19:25:07 +0000 | [diff] [blame] | 914 | if f.properties.Security_patch != nil && proptools.String(f.properties.Security_patch) != "" { |
| 915 | avb_add_hashtree_footer_args += fmt.Sprintf(" --prop com.android.build.%s.security_patch:%s", f.partitionName(), proptools.String(f.properties.Security_patch)) |
| 916 | } |
Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 917 | addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) |
Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 918 | } |
| 919 | |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 920 | if f.properties.File_contexts != nil && f.properties.Precompiled_file_contexts != nil { |
| 921 | ctx.ModuleErrorf("file_contexts and precompiled_file_contexts cannot both be set") |
| 922 | } else if f.properties.File_contexts != nil { |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 923 | addPath("selinux_fc", f.buildFileContexts(ctx)) |
Cole Faust | 0d46705 | 2024-12-04 17:19:19 -0800 | [diff] [blame] | 924 | } else if f.properties.Precompiled_file_contexts != nil { |
| 925 | src := android.PathForModuleSrc(ctx, *f.properties.Precompiled_file_contexts) |
| 926 | if src != nil { |
| 927 | addPath("selinux_fc", src) |
| 928 | } |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 929 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 930 | if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" { |
| 931 | addStr("timestamp", timestamp) |
Spandan Das | a0ddc51 | 2025-01-06 20:23:55 +0000 | [diff] [blame] | 932 | } else if ctx.Config().Getenv("USE_FIXED_TIMESTAMP_IMG_FILES") == "true" { |
| 933 | addStr("use_fixed_timestamp", "true") |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 934 | } |
Spandan Das | a0ddc51 | 2025-01-06 20:23:55 +0000 | [diff] [blame] | 935 | |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 936 | if uuid := proptools.String(f.properties.Uuid); uuid != "" { |
| 937 | addStr("uuid", uuid) |
| 938 | addStr("hash_seed", uuid) |
| 939 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 940 | |
Jihoon Kang | 40551e6 | 2025-01-14 21:55:08 +0000 | [diff] [blame] | 941 | // Disable sparse only when partition size is not defined. disable_sparse has the same |
| 942 | // effect as <partition name>_disable_sparse. |
| 943 | if f.properties.Partition_size == nil { |
| 944 | addStr("disable_sparse", "true") |
| 945 | } |
Cole Faust | 43a52c7 | 2024-11-26 12:46:08 -0800 | [diff] [blame] | 946 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 947 | fst := f.fsType(ctx) |
| 948 | switch fst { |
| 949 | case erofsType: |
| 950 | // Add erofs properties |
Cole Faust | 3e73097 | 2024-12-03 13:12:08 -0800 | [diff] [blame] | 951 | addStr("erofs_default_compressor", proptools.StringDefault(f.properties.Erofs.Compressor, "lz4hc,9")) |
| 952 | if f.properties.Erofs.Compress_hints != nil { |
| 953 | src := android.PathForModuleSrc(ctx, *f.properties.Erofs.Compress_hints) |
| 954 | addPath("erofs_default_compress_hints", src) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 955 | } |
| 956 | if proptools.BoolDefault(f.properties.Erofs.Sparse, true) { |
| 957 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b |
| 958 | addStr("erofs_sparse_flag", "-s") |
| 959 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 960 | case f2fsType: |
| 961 | if proptools.BoolDefault(f.properties.F2fs.Sparse, true) { |
| 962 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2294;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b;bpv=1;bpt=0 |
| 963 | addStr("f2fs_sparse_flag", "-S") |
| 964 | } |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 965 | } |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 966 | f.checkFsTypePropertyError(ctx, fst, fsTypeStr(fst)) |
Spandan Das | c35d6fb | 2024-10-10 17:51:14 +0000 | [diff] [blame] | 967 | |
Jihoon Kang | 983dd88 | 2025-01-13 23:14:11 +0000 | [diff] [blame] | 968 | if f.properties.Partition_size != nil { |
| 969 | addStr("partition_size", strconv.FormatInt(*f.properties.Partition_size, 10)) |
| 970 | } |
| 971 | |
Jihoon Kang | 6d08d92 | 2025-01-14 18:31:57 +0000 | [diff] [blame] | 972 | if proptools.BoolDefault(f.properties.Support_casefolding, false) { |
| 973 | addStr("needs_casefold", "1") |
| 974 | } |
| 975 | |
| 976 | if proptools.BoolDefault(f.properties.Support_project_quota, false) { |
| 977 | addStr("needs_projid", "1") |
| 978 | } |
| 979 | |
| 980 | if proptools.BoolDefault(f.properties.Enable_compression, false) { |
| 981 | addStr("needs_compress", "1") |
| 982 | } |
| 983 | |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 984 | sort.Strings(lines) |
| 985 | |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 986 | propFilePreProcessing := android.PathForModuleOut(ctx, "prop_pre_processing") |
Cole Faust | e03ab89 | 2025-01-17 13:55:04 -0800 | [diff] [blame] | 987 | android.WriteFileRule(ctx, propFilePreProcessing, strings.Join(lines, "\n")) |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 988 | propFile := android.PathForModuleOut(ctx, "prop") |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 989 | ctx.Build(pctx, android.BuildParams{ |
Cole Faust | efeb5c4 | 2024-12-16 10:47:26 -0800 | [diff] [blame] | 990 | Rule: textFileProcessorRule, |
| 991 | Input: propFilePreProcessing, |
| 992 | Output: propFile, |
Cole Faust | e167612 | 2024-12-03 17:32:25 -0800 | [diff] [blame] | 993 | }) |
Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 994 | return propFile, deps |
| 995 | } |
| 996 | |
mrziwang | 1a6291f | 2024-11-07 14:29:25 -0800 | [diff] [blame] | 997 | // This method checks if there is any property set for the fstype(s) other than |
| 998 | // the current fstype. |
| 999 | func (f *filesystem) checkFsTypePropertyError(ctx android.ModuleContext, t fsType, fs string) { |
| 1000 | raiseError := func(otherFsType, currentFsType string) { |
| 1001 | 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) |
| 1002 | ctx.PropertyErrorf(otherFsType, errMsg) |
| 1003 | } |
| 1004 | |
| 1005 | if t != erofsType { |
| 1006 | if f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil { |
| 1007 | raiseError("erofs", fs) |
| 1008 | } |
| 1009 | } |
| 1010 | if t != f2fsType { |
| 1011 | if f.properties.F2fs.Sparse != nil { |
| 1012 | raiseError("f2fs", fs) |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 1017 | func includeFilesRootDir(ctx android.ModuleContext) (rootDirs android.Paths, partitions android.Paths) { |
| 1018 | ctx.VisitDirectDepsWithTag(interPartitionInstallDependencyTag, func(m android.Module) { |
| 1019 | if fsProvider, ok := android.OtherModuleProvider(ctx, m, FilesystemProvider); ok { |
| 1020 | rootDirs = append(rootDirs, fsProvider.RootDir) |
| 1021 | partitions = append(partitions, fsProvider.Output) |
| 1022 | } else { |
| 1023 | ctx.PropertyErrorf("include_files_of", "only filesystem modules can be listed in "+ |
| 1024 | "include_files_of but %s is not a filesystem module", m.Name()) |
| 1025 | } |
| 1026 | }) |
| 1027 | return rootDirs, partitions |
| 1028 | } |
| 1029 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 1030 | func (f *filesystem) buildCpioImage( |
| 1031 | ctx android.ModuleContext, |
| 1032 | builder *android.RuleBuilder, |
| 1033 | rootDir android.OutputPath, |
| 1034 | compressed bool, |
| 1035 | ) android.Path { |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1036 | if proptools.Bool(f.properties.Use_avb) { |
| 1037 | ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ |
| 1038 | "Consider adding this to bootimg module and signing the entire boot image.") |
| 1039 | } |
| 1040 | |
Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 1041 | if proptools.String(f.properties.File_contexts) != "" { |
| 1042 | ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") |
| 1043 | } |
| 1044 | |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 1045 | rootDirs, partitions := includeFilesRootDir(ctx) |
| 1046 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 1047 | output := android.PathForModuleOut(ctx, f.installFileName()) |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1048 | cmd := builder.Command(). |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1049 | BuiltTool("mkbootfs"). |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1050 | Text(rootDir.String()) // input directory |
Jihoon Kang | 6da8075 | 2024-12-23 18:53:32 +0000 | [diff] [blame] | 1051 | |
| 1052 | for i := range len(rootDirs) { |
| 1053 | cmd.Text(rootDirs[i].String()) |
| 1054 | } |
| 1055 | cmd.Implicits(partitions) |
| 1056 | |
Jihoon Kang | 6c03c8e | 2024-11-18 21:30:22 +0000 | [diff] [blame] | 1057 | if nodeList := f.properties.Dev_nodes_description_file; nodeList != nil { |
| 1058 | cmd.FlagWithInput("-n ", android.PathForModuleSrc(ctx, proptools.String(nodeList))) |
| 1059 | } |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1060 | if compressed { |
| 1061 | cmd.Text("|"). |
| 1062 | BuiltTool("lz4"). |
| 1063 | Flag("--favor-decSpeed"). // for faster boot |
| 1064 | Flag("-12"). // maximum compression level |
| 1065 | Flag("-l"). // legacy format for kernel |
| 1066 | Text(">").Output(output) |
| 1067 | } else { |
| 1068 | cmd.Text(">").Output(output) |
| 1069 | } |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1070 | |
| 1071 | // rootDir is not deleted. Might be useful for quick inspection. |
Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 1072 | builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1073 | |
Cole Faust | 62cfaeb | 2025-01-15 18:06:40 -0800 | [diff] [blame] | 1074 | return output |
Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 1075 | } |
| 1076 | |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 1077 | var validPartitions = []string{ |
| 1078 | "system", |
| 1079 | "userdata", |
| 1080 | "cache", |
| 1081 | "system_other", |
| 1082 | "vendor", |
| 1083 | "product", |
| 1084 | "system_ext", |
| 1085 | "odm", |
| 1086 | "vendor_dlkm", |
| 1087 | "odm_dlkm", |
| 1088 | "system_dlkm", |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 1089 | "ramdisk", |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 1090 | "vendor_ramdisk", |
Jihoon Kang | 3216c98 | 2024-12-02 19:42:20 +0000 | [diff] [blame] | 1091 | "recovery", |
Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1094 | func (f *filesystem) buildEventLogtagsFile( |
| 1095 | ctx android.ModuleContext, |
| 1096 | builder *android.RuleBuilder, |
| 1097 | rebasedDir android.OutputPath, |
| 1098 | fullInstallPaths *[]FullInstallPathInfo, |
| 1099 | ) { |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 1100 | if !proptools.Bool(f.properties.Build_logtags) { |
| 1101 | return |
| 1102 | } |
| 1103 | |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 1104 | etcPath := rebasedDir.Join(ctx, "etc") |
| 1105 | eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") |
| 1106 | builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) |
Cole Faust | e4506af | 2024-12-11 14:14:50 -0800 | [diff] [blame] | 1107 | builder.Command().Text("cp").Input(android.MergedLogtagsPath(ctx)).Text(eventLogtagsPath.String()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 1108 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1109 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 1110 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc", "event-log-tags"), |
| 1111 | SourcePath: android.MergedLogtagsPath(ctx), |
| 1112 | }) |
| 1113 | |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 1114 | f.appendToEntry(ctx, eventLogtagsPath) |
Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 1115 | } |
| 1116 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1117 | func (f *filesystem) BuildLinkerConfigFile( |
| 1118 | ctx android.ModuleContext, |
| 1119 | builder *android.RuleBuilder, |
| 1120 | rebasedDir android.OutputPath, |
| 1121 | fullInstallPaths *[]FullInstallPathInfo, |
| 1122 | ) { |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 1123 | if !proptools.Bool(f.properties.Linker_config.Gen_linker_config) { |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1124 | return |
| 1125 | } |
| 1126 | |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1127 | provideModules, _ := f.getLibsForLinkerConfig(ctx) |
Cole Faust | fee2701 | 2024-12-13 14:10:31 -0800 | [diff] [blame] | 1128 | intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb") |
| 1129 | linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, f.properties.Linker_config.Linker_config_srcs), provideModules, nil, intermediateOutput) |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1130 | output := rebasedDir.Join(ctx, "etc", "linker.config.pb") |
Cole Faust | fee2701 | 2024-12-13 14:10:31 -0800 | [diff] [blame] | 1131 | builder.Command().Text("cp").Input(intermediateOutput).Output(output) |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1132 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 1133 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 1134 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, f.PartitionType(), "etc", "linker.config.pb"), |
| 1135 | SourcePath: intermediateOutput, |
| 1136 | }) |
| 1137 | |
Spandan Das | 9263188 | 2024-10-28 22:49:38 +0000 | [diff] [blame] | 1138 | f.appendToEntry(ctx, output) |
| 1139 | } |
| 1140 | |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 1141 | func (f *filesystem) ShouldUseVintfFragmentModuleOnly() bool { |
| 1142 | return false |
| 1143 | } |
| 1144 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1145 | type partition interface { |
| 1146 | PartitionType() string |
| 1147 | } |
| 1148 | |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 1149 | func (f *filesystem) PartitionType() string { |
| 1150 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 1151 | } |
| 1152 | |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1153 | var _ partition = (*filesystem)(nil) |
| 1154 | |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 1155 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) |
| 1156 | |
| 1157 | // Implements android.AndroidMkEntriesProvider |
| 1158 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { |
| 1159 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1160 | Class: "ETC", |
| 1161 | OutputFile: android.OptionalPathForPath(f.output), |
| 1162 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 1163 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 1164 | entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 1165 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) |
Kiyoung Kim | 99a954d | 2024-06-21 14:22:20 +0900 | [diff] [blame] | 1166 | entries.SetString("LOCAL_FILESYSTEM_FILELIST", f.fileListFile.String()) |
Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 1167 | }, |
| 1168 | }, |
| 1169 | }} |
Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 1170 | } |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1171 | |
| 1172 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex |
| 1173 | // package to have access to the output file. |
| 1174 | type Filesystem interface { |
| 1175 | android.Module |
| 1176 | OutputPath() android.Path |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 1177 | |
| 1178 | // Returns the output file that is signed by avbtool. If this module is not signed, returns |
| 1179 | // nil. |
| 1180 | SignedOutputPath() android.Path |
Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | var _ Filesystem = (*filesystem)(nil) |
| 1184 | |
| 1185 | func (f *filesystem) OutputPath() android.Path { |
| 1186 | return f.output |
| 1187 | } |
Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 1188 | |
| 1189 | func (f *filesystem) SignedOutputPath() android.Path { |
| 1190 | if proptools.Bool(f.properties.Use_avb) { |
| 1191 | return f.OutputPath() |
| 1192 | } |
| 1193 | return nil |
| 1194 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 1195 | |
| 1196 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. |
| 1197 | // Note that "apex" module installs its contents to "apex"(fake partition) as well |
| 1198 | // for symbol lookup by imitating "activated" paths. |
| 1199 | func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { |
Cole Faust | b8e280f | 2025-01-16 16:33:26 -0800 | [diff] [blame] | 1200 | return f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, f.filesystemBuilder.FilterPackagingSpec, f.filesystemBuilder.ModifyPackagingSpec) |
| 1201 | } |
| 1202 | |
| 1203 | // Dexpreopt files are installed to system_other. Collect the packaingSpecs for the dexpreopt files |
| 1204 | // from this partition to export to the system_other partition later. |
| 1205 | func (f *filesystem) systemOtherFiles(ctx android.ModuleContext) map[string]android.PackagingSpec { |
| 1206 | filter := func(spec android.PackagingSpec) bool { |
| 1207 | // For some reason system_other packaging specs don't set the partition field. |
| 1208 | return strings.HasPrefix(spec.RelPathInPackage(), "system_other/") |
| 1209 | } |
| 1210 | modifier := func(spec *android.PackagingSpec) { |
| 1211 | spec.SetRelPathInPackage(strings.TrimPrefix(spec.RelPathInPackage(), "system_other/")) |
| 1212 | spec.SetPartition("system_other") |
| 1213 | } |
| 1214 | return f.PackagingBase.GatherPackagingSpecsWithFilterAndModifier(ctx, filter, modifier) |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 1215 | } |
Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 1216 | |
| 1217 | func sha1sum(values []string) string { |
| 1218 | h := sha256.New() |
| 1219 | for _, value := range values { |
| 1220 | io.WriteString(h, value) |
| 1221 | } |
| 1222 | return fmt.Sprintf("%x", h.Sum(nil)) |
| 1223 | } |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 1224 | |
| 1225 | // Base cc.UseCoverage |
| 1226 | |
| 1227 | var _ cc.UseCoverage = (*filesystem)(nil) |
| 1228 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 1229 | func (*filesystem) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 1230 | return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() |
| 1231 | } |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1232 | |
| 1233 | // android_filesystem_defaults |
| 1234 | |
| 1235 | type filesystemDefaults struct { |
| 1236 | android.ModuleBase |
| 1237 | android.DefaultsModuleBase |
| 1238 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 1239 | properties FilesystemProperties |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | // android_filesystem_defaults is a default module for android_filesystem and android_system_image |
| 1243 | func filesystemDefaultsFactory() android.Module { |
| 1244 | module := &filesystemDefaults{} |
| 1245 | module.AddProperties(&module.properties) |
| 1246 | module.AddProperties(&android.PackagingProperties{}) |
| 1247 | android.InitDefaultsModule(module) |
| 1248 | return module |
| 1249 | } |
| 1250 | |
| 1251 | func (f *filesystemDefaults) PartitionType() string { |
| 1252 | return proptools.StringDefault(f.properties.Partition_type, "system") |
| 1253 | } |
| 1254 | |
| 1255 | var _ partition = (*filesystemDefaults)(nil) |
| 1256 | |
| 1257 | func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1258 | validatePartitionType(ctx, f) |
Yu Liu | fc8d5c1 | 2025-01-09 00:19:06 +0000 | [diff] [blame] | 1259 | android.SetProvider(ctx, FilesystemDefaultsInfoProvider, FilesystemDefaultsInfo{ |
| 1260 | PartitionType: f.PartitionType(), |
| 1261 | }) |
Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 1262 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1263 | |
| 1264 | // getLibsForLinkerConfig returns |
| 1265 | // 1. A list of libraries installed in this filesystem |
| 1266 | // 2. A list of dep libraries _not_ installed in this filesystem |
| 1267 | // |
| 1268 | // `linkerconfig.BuildLinkerConfig` will convert these two to a linker.config.pb for the filesystem |
| 1269 | // (1) will be added to --provideLibs if they are C libraries with a stable interface (has stubs) |
| 1270 | // (2) will be added to --requireLibs if they are C libraries with a stable interface (has stubs) |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1271 | func (f *filesystem) getLibsForLinkerConfig(ctx android.ModuleContext) ([]android.ModuleProxy, []android.ModuleProxy) { |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1272 | // we need "Module"s for packaging items |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1273 | modulesInPackageByModule := make(map[android.ModuleProxy]bool) |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1274 | modulesInPackageByName := make(map[string]bool) |
| 1275 | |
| 1276 | deps := f.gatherFilteredPackagingSpecs(ctx) |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1277 | ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { |
| 1278 | if !android.OtherModuleProviderOrDefault(ctx, child, android.CommonModuleInfoKey).Enabled { |
Yu Liu | 9c6b676 | 2025-01-08 22:04:35 +0000 | [diff] [blame] | 1279 | return false |
| 1280 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1281 | for _, ps := range android.OtherModuleProviderOrDefault( |
| 1282 | ctx, child, android.InstallFilesProvider).PackagingSpecs { |
Spandan Das | ecf667f | 2024-12-05 00:58:56 +0000 | [diff] [blame] | 1283 | if _, ok := deps[ps.RelPathInPackage()]; ok && ps.Partition() == f.PartitionType() { |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1284 | modulesInPackageByModule[child] = true |
| 1285 | modulesInPackageByName[child.Name()] = true |
| 1286 | return true |
| 1287 | } |
| 1288 | } |
| 1289 | return true |
| 1290 | }) |
| 1291 | |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1292 | provideModules := make([]android.ModuleProxy, 0, len(modulesInPackageByModule)) |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1293 | for mod := range modulesInPackageByModule { |
| 1294 | provideModules = append(provideModules, mod) |
| 1295 | } |
| 1296 | |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 1297 | var requireModules []android.ModuleProxy |
| 1298 | ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool { |
| 1299 | if !android.OtherModuleProviderOrDefault(ctx, child, android.CommonModuleInfoKey).Enabled { |
Yu Liu | 9c6b676 | 2025-01-08 22:04:35 +0000 | [diff] [blame] | 1300 | return false |
| 1301 | } |
Spandan Das | 918191e | 2024-10-31 18:27:23 +0000 | [diff] [blame] | 1302 | _, parentInPackage := modulesInPackageByModule[parent] |
| 1303 | _, childInPackageName := modulesInPackageByName[child.Name()] |
| 1304 | |
| 1305 | // When parent is in the package, and child (or its variant) is not, this can be from an interface. |
| 1306 | if parentInPackage && !childInPackageName { |
| 1307 | requireModules = append(requireModules, child) |
| 1308 | } |
| 1309 | return true |
| 1310 | }) |
| 1311 | |
| 1312 | return provideModules, requireModules |
| 1313 | } |
Cole Faust | 26bdac5 | 2024-11-19 13:37:53 -0800 | [diff] [blame] | 1314 | |
| 1315 | // Checks that the given file doesn't exceed the given size, and will also print a warning |
| 1316 | // if it's nearing the maximum size. Equivalent to assert-max-image-size in make: |
| 1317 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/definitions.mk;l=3455;drc=993c4de29a02a6accd60ceaaee153307e1a18d10 |
| 1318 | func assertMaxImageSize(builder *android.RuleBuilder, image android.Path, maxSize int64, addAvbLater bool) { |
| 1319 | if addAvbLater { |
| 1320 | // The value 69632 is derived from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in avbtool. |
| 1321 | // Logic copied from make: |
| 1322 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=228;drc=a6a0007ef24e16c0b79f439beac4a118416717e6 |
| 1323 | maxSize -= 69632 |
| 1324 | } |
| 1325 | cmd := builder.Command() |
| 1326 | cmd.Textf(`file="%s"; maxsize="%d";`+ |
| 1327 | `total=$(stat -c "%%s" "$file" | tr -d '\n');`+ |
| 1328 | `if [ "$total" -gt "$maxsize" ]; then `+ |
| 1329 | ` echo "error: $file too large ($total > $maxsize)";`+ |
| 1330 | ` false;`+ |
| 1331 | `elif [ "$total" -gt $((maxsize - 32768)) ]; then `+ |
| 1332 | ` echo "WARNING: $file approaching size limit ($total now; limit $maxsize)";`+ |
| 1333 | `fi`, |
| 1334 | image, maxSize) |
| 1335 | cmd.Implicit(image) |
| 1336 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 1337 | |
| 1338 | // addAutogeneratedRroDeps walks the transitive closure of vendor and product partitions. |
| 1339 | // It visits apps installed in system and system_ext partitions, and adds the autogenerated |
| 1340 | // RRO modules to its own deps. |
| 1341 | func addAutogeneratedRroDeps(ctx android.BottomUpMutatorContext) { |
| 1342 | f, ok := ctx.Module().(*filesystem) |
| 1343 | if !ok { |
| 1344 | return |
| 1345 | } |
| 1346 | thisPartition := f.PartitionType() |
| 1347 | if thisPartition != "vendor" && thisPartition != "product" { |
Cole Faust | 34592c0 | 2024-12-13 11:20:24 -0800 | [diff] [blame] | 1348 | if f.properties.Android_filesystem_deps.System != nil { |
| 1349 | ctx.PropertyErrorf("android_filesystem_deps.system", "only vendor or product partitions can use android_filesystem_deps") |
| 1350 | } |
| 1351 | if f.properties.Android_filesystem_deps.System_ext != nil { |
| 1352 | ctx.PropertyErrorf("android_filesystem_deps.system_ext", "only vendor or product partitions can use android_filesystem_deps") |
| 1353 | } |
Spandan Das | 71be42d | 2024-11-20 18:34:16 +0000 | [diff] [blame] | 1354 | return |
| 1355 | } |
| 1356 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 1357 | depTag := ctx.OtherModuleDependencyTag(child) |
| 1358 | if parent.Name() == f.Name() && depTag != interPartitionDependencyTag { |
| 1359 | return false // This is a module listed in deps of vendor/product filesystem |
| 1360 | } |
| 1361 | if vendorOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "vendor"); ctx.OtherModuleExists(vendorOverlay) && thisPartition == "vendor" { |
| 1362 | ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, vendorOverlay) |
| 1363 | } |
| 1364 | if productOverlay := java.AutogeneratedRroModuleName(ctx, child.Name(), "product"); ctx.OtherModuleExists(productOverlay) && thisPartition == "product" { |
| 1365 | ctx.AddFarVariationDependencies(nil, dependencyTagWithVisibilityEnforcementBypass, productOverlay) |
| 1366 | } |
| 1367 | return true |
| 1368 | }) |
| 1369 | } |