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