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