Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 1 | // Copyright (C) 2024 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 ( |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 18 | "fmt" |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 19 | "strings" |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 20 | "sync/atomic" |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 21 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | |
| 24 | "github.com/google/blueprint" |
| 25 | "github.com/google/blueprint/proptools" |
| 26 | ) |
| 27 | |
| 28 | type PartitionNameProperties struct { |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 29 | // Name of the super partition filesystem module |
| 30 | Super_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 31 | // Name of the boot partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 32 | Boot_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 33 | // Name of the vendor boot partition filesystem module |
| 34 | Vendor_boot_partition_name *string |
| 35 | // Name of the init boot partition filesystem module |
| 36 | Init_boot_partition_name *string |
| 37 | // Name of the system partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 38 | System_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 39 | // Name of the system_ext partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 40 | System_ext_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 41 | // Name of the product partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 42 | Product_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 43 | // Name of the vendor partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 44 | Vendor_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 45 | // Name of the odm partition filesystem module |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 46 | Odm_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 47 | // Name of the recovery partition filesystem module |
| 48 | Recovery_partition_name *string |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 49 | // The vbmeta partition and its "chained" partitions |
| 50 | Vbmeta_partitions []string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 51 | // Name of the userdata partition filesystem module |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 52 | Userdata_partition_name *string |
Spandan Das | a039400 | 2025-01-07 18:38:34 +0000 | [diff] [blame] | 53 | // Name of the system_dlkm partition filesystem module |
| 54 | System_dlkm_partition_name *string |
| 55 | // Name of the vendor_dlkm partition filesystem module |
| 56 | Vendor_dlkm_partition_name *string |
| 57 | // Name of the odm_dlkm partition filesystem module |
| 58 | Odm_dlkm_partition_name *string |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 61 | type DeviceProperties struct { |
| 62 | // Path to the prebuilt bootloader that would be copied to PRODUCT_OUT |
| 63 | Bootloader *string `android:"path"` |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 64 | // Path to android-info.txt file containing board specific info. |
| 65 | Android_info *string `android:"path"` |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 66 | // If this is the "main" android_device target for the build, i.e. the one that gets built |
| 67 | // when running a plain `m` command. Currently, this is the autogenerated android_device module |
| 68 | // in soong-only builds, but in the future when we check in android_device modules, the main |
| 69 | // one will be determined based on the lunch product. TODO: Figure out how to make this |
| 70 | // blueprint:"mutated" and still set it from filesystem_creator |
| 71 | Main_device *bool |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 72 | |
Spandan Das | b5f40cf | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 73 | Ab_ota_updater *bool |
| 74 | Ab_ota_partitions []string |
Spandan Das | 35b7874 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 75 | Ab_ota_keys []string |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 78 | type androidDevice struct { |
| 79 | android.ModuleBase |
| 80 | |
| 81 | partitionProps PartitionNameProperties |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 82 | |
| 83 | deviceProps DeviceProperties |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 84 | |
| 85 | allImagesZip android.Path |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | func AndroidDeviceFactory() android.Module { |
| 89 | module := &androidDevice{} |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 90 | module.AddProperties(&module.partitionProps, &module.deviceProps) |
Cole Faust | 341d5f1 | 2025-01-07 15:32:38 -0800 | [diff] [blame] | 91 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 92 | return module |
| 93 | } |
| 94 | |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 95 | var numMainAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices") |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 96 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 97 | type partitionDepTagType struct { |
| 98 | blueprint.BaseDependencyTag |
| 99 | } |
| 100 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 101 | type superPartitionDepTagType struct { |
| 102 | blueprint.BaseDependencyTag |
| 103 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 104 | type targetFilesMetadataDepTagType struct { |
| 105 | blueprint.BaseDependencyTag |
| 106 | } |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 107 | |
| 108 | var superPartitionDepTag superPartitionDepTagType |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 109 | var filesystemDepTag partitionDepTagType |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 110 | var targetFilesMetadataDepTag targetFilesMetadataDepTagType |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 111 | |
| 112 | func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 113 | addDependencyIfDefined := func(dep *string) { |
| 114 | if dep != nil { |
Cole Faust | 341d5f1 | 2025-01-07 15:32:38 -0800 | [diff] [blame] | 115 | ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep)) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 119 | if a.partitionProps.Super_partition_name != nil { |
| 120 | ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name) |
| 121 | } |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 122 | addDependencyIfDefined(a.partitionProps.Boot_partition_name) |
Jihoon Kang | 9e08700 | 2025-01-08 19:12:23 +0000 | [diff] [blame] | 123 | addDependencyIfDefined(a.partitionProps.Init_boot_partition_name) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 124 | addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 125 | addDependencyIfDefined(a.partitionProps.System_partition_name) |
| 126 | addDependencyIfDefined(a.partitionProps.System_ext_partition_name) |
| 127 | addDependencyIfDefined(a.partitionProps.Product_partition_name) |
| 128 | addDependencyIfDefined(a.partitionProps.Vendor_partition_name) |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 129 | addDependencyIfDefined(a.partitionProps.Odm_partition_name) |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 130 | addDependencyIfDefined(a.partitionProps.Userdata_partition_name) |
Spandan Das | a039400 | 2025-01-07 18:38:34 +0000 | [diff] [blame] | 131 | addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name) |
| 132 | addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name) |
| 133 | addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 134 | addDependencyIfDefined(a.partitionProps.Recovery_partition_name) |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 135 | for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions { |
| 136 | ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition) |
| 137 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 138 | a.addDepsForTargetFilesMetadata(ctx) |
| 139 | } |
| 140 | |
| 141 | func (a *androidDevice) addDepsForTargetFilesMetadata(ctx android.BottomUpMutatorContext) { |
| 142 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), targetFilesMetadataDepTag, "liblz4") // host variant |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 145 | func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 146 | if proptools.Bool(a.deviceProps.Main_device) { |
| 147 | numMainAndroidDevices := ctx.Config().Once(numMainAndroidDevicesOnceKey, func() interface{} { |
| 148 | return &atomic.Int32{} |
| 149 | }).(*atomic.Int32) |
| 150 | total := numMainAndroidDevices.Add(1) |
| 151 | if total > 1 { |
| 152 | // There should only be 1 main android_device module. That one will be |
| 153 | // made the default thing to build in soong-only builds. |
| 154 | ctx.ModuleErrorf("There cannot be more than 1 main android_device module") |
| 155 | } |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Spandan Das | 5ef1a9c | 2025-02-11 18:50:17 +0000 | [diff] [blame] | 158 | a.buildTargetFilesZip(ctx) |
mrziwang | 2fd33a7 | 2025-01-08 12:22:08 -0800 | [diff] [blame] | 159 | var deps []android.Path |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 160 | if proptools.String(a.partitionProps.Super_partition_name) != "" { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 161 | superImage := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 162 | if info, ok := android.OtherModuleProvider(ctx, superImage, SuperImageProvider); ok { |
| 163 | assertUnset := func(prop *string, propName string) { |
| 164 | if prop != nil && *prop != "" { |
| 165 | ctx.PropertyErrorf(propName, "Cannot be set because it's already part of the super image") |
| 166 | } |
| 167 | } |
| 168 | for _, subPartitionType := range android.SortedKeys(info.SubImageInfo) { |
| 169 | switch subPartitionType { |
| 170 | case "system": |
| 171 | assertUnset(a.partitionProps.System_partition_name, "system_partition_name") |
| 172 | case "system_ext": |
| 173 | assertUnset(a.partitionProps.System_ext_partition_name, "system_ext_partition_name") |
| 174 | case "system_dlkm": |
| 175 | assertUnset(a.partitionProps.System_dlkm_partition_name, "system_dlkm_partition_name") |
| 176 | case "system_other": |
| 177 | // TODO |
| 178 | case "product": |
| 179 | assertUnset(a.partitionProps.Product_partition_name, "product_partition_name") |
| 180 | case "vendor": |
| 181 | assertUnset(a.partitionProps.Vendor_partition_name, "vendor_partition_name") |
| 182 | case "vendor_dlkm": |
| 183 | assertUnset(a.partitionProps.Vendor_dlkm_partition_name, "vendor_dlkm_partition_name") |
| 184 | case "odm": |
| 185 | assertUnset(a.partitionProps.Odm_partition_name, "odm_partition_name") |
| 186 | case "odm_dlkm": |
| 187 | assertUnset(a.partitionProps.Odm_dlkm_partition_name, "odm_dlkm_partition_name") |
| 188 | default: |
| 189 | ctx.ModuleErrorf("Unsupported sub-partition of super partition: %q", subPartitionType) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | deps = append(deps, info.SuperImage) |
| 194 | } else { |
| 195 | ctx.ModuleErrorf("Expected super image dep to provide SuperImageProvider") |
| 196 | } |
| 197 | } |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 198 | ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(m android.ModuleProxy) { |
mrziwang | 2fd33a7 | 2025-01-08 12:22:08 -0800 | [diff] [blame] | 199 | imageOutput, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider) |
| 200 | if !ok { |
| 201 | ctx.ModuleErrorf("Partition module %s doesn't set OutputfilesProvider", m.Name()) |
| 202 | } |
| 203 | if len(imageOutput.DefaultOutputFiles) != 1 { |
| 204 | ctx.ModuleErrorf("Partition module %s should provide exact 1 output file", m.Name()) |
| 205 | } |
| 206 | deps = append(deps, imageOutput.DefaultOutputFiles[0]) |
| 207 | }) |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 208 | |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 209 | allImagesZip := android.PathForModuleOut(ctx, "all_images.zip") |
| 210 | allImagesZipBuilder := android.NewRuleBuilder(pctx, ctx) |
| 211 | cmd := allImagesZipBuilder.Command().BuiltTool("soong_zip").Flag("--sort_entries") |
| 212 | for _, dep := range deps { |
| 213 | cmd.FlagWithArg("-e ", dep.Base()) |
| 214 | cmd.FlagWithInput("-f ", dep) |
| 215 | } |
| 216 | cmd.FlagWithOutput("-o ", allImagesZip) |
| 217 | allImagesZipBuilder.Build("soong_all_images_zip", "all_images.zip") |
| 218 | a.allImagesZip = allImagesZip |
| 219 | |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 220 | allImagesStamp := android.PathForModuleOut(ctx, "all_images_stamp") |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 221 | var validations android.Paths |
| 222 | if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) { |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 223 | // In soong-only builds, build this module by default. |
| 224 | // This is the analogue to this make code: |
| 225 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/main.mk;l=1396;drc=6595459cdd8164a6008335f6372c9f97b9094060 |
| 226 | ctx.Phony("droidcore-unbundled", allImagesStamp) |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 227 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 228 | deps = append(deps, a.copyFilesToProductOutForSoongOnly(ctx)) |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 229 | } |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 230 | |
| 231 | ctx.Build(pctx, android.BuildParams{ |
| 232 | Rule: android.Touch, |
| 233 | Output: allImagesStamp, |
| 234 | Implicits: deps, |
| 235 | Validations: validations, |
| 236 | }) |
| 237 | |
| 238 | // Checkbuilding it causes soong to make a phony, so you can say `m <module name>` |
| 239 | ctx.CheckbuildFile(allImagesStamp) |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 240 | |
| 241 | a.setVbmetaPhonyTargets(ctx) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 242 | |
| 243 | a.distFiles(ctx) |
| 244 | } |
| 245 | |
| 246 | func (a *androidDevice) distFiles(ctx android.ModuleContext) { |
| 247 | if !ctx.Config().KatiEnabled() { |
| 248 | if proptools.Bool(a.deviceProps.Main_device) { |
| 249 | fsInfoMap := a.getFsInfos(ctx) |
| 250 | for _, partition := range android.SortedKeys(fsInfoMap) { |
| 251 | fsInfo := fsInfoMap[partition] |
| 252 | if fsInfo.InstalledFiles.Json != nil { |
| 253 | ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Json) |
| 254 | } |
| 255 | if fsInfo.InstalledFiles.Txt != nil { |
| 256 | ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Txt) |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 262 | } |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 263 | |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 264 | func (a *androidDevice) MakeVars(ctx android.MakeVarsModuleContext) { |
| 265 | if proptools.Bool(a.deviceProps.Main_device) { |
| 266 | ctx.StrictRaw("SOONG_ONLY_ALL_IMAGES_ZIP", a.allImagesZip.String()) |
| 267 | } |
| 268 | } |
| 269 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 270 | // Helper structs for target_files.zip creation |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 271 | type targetFilesZipCopy struct { |
| 272 | srcModule *string |
| 273 | destSubdir string |
| 274 | } |
| 275 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 276 | type targetFilesystemZipCopy struct { |
| 277 | fsInfo FilesystemInfo |
| 278 | destSubdir string |
| 279 | } |
| 280 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 281 | func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext) { |
| 282 | targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir") |
| 283 | targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip") |
| 284 | |
| 285 | builder := android.NewRuleBuilder(pctx, ctx) |
| 286 | builder.Command().Textf("rm -rf %s", targetFilesDir.String()) |
| 287 | builder.Command().Textf("mkdir -p %s", targetFilesDir.String()) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 288 | toCopy := []targetFilesZipCopy{ |
| 289 | targetFilesZipCopy{a.partitionProps.System_partition_name, "SYSTEM"}, |
| 290 | targetFilesZipCopy{a.partitionProps.System_ext_partition_name, "SYSTEM_EXT"}, |
| 291 | targetFilesZipCopy{a.partitionProps.Product_partition_name, "PRODUCT"}, |
| 292 | targetFilesZipCopy{a.partitionProps.Vendor_partition_name, "VENDOR"}, |
| 293 | targetFilesZipCopy{a.partitionProps.Odm_partition_name, "ODM"}, |
| 294 | targetFilesZipCopy{a.partitionProps.System_dlkm_partition_name, "SYSTEM_DLKM"}, |
| 295 | targetFilesZipCopy{a.partitionProps.Vendor_dlkm_partition_name, "VENDOR_DLKM"}, |
| 296 | targetFilesZipCopy{a.partitionProps.Odm_dlkm_partition_name, "ODM_DLKM"}, |
| 297 | targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"}, |
| 298 | targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"}, |
| 299 | targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"}, |
Spandan Das | 25649f5 | 2025-01-07 18:09:22 +0000 | [diff] [blame] | 300 | } |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 301 | // TODO: Handle cases where recovery files are copied to BOOT/ or RECOVERY/ |
| 302 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=6211-6219?q=core%2FMakefile&ss=android%2Fplatform%2Fsuperproject%2Fmain |
| 303 | if ctx.DeviceConfig().BoardMoveRecoveryResourcesToVendorBoot() { |
| 304 | toCopy = append(toCopy, targetFilesZipCopy{a.partitionProps.Recovery_partition_name, "VENDOR_BOOT/RAMDISK"}) |
| 305 | } |
| 306 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 307 | filesystemsToCopy := []targetFilesystemZipCopy{} |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 308 | for _, zipCopy := range toCopy { |
| 309 | if zipCopy.srcModule == nil { |
Spandan Das | 25649f5 | 2025-01-07 18:09:22 +0000 | [diff] [blame] | 310 | continue |
| 311 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 312 | filesystemsToCopy = append( |
| 313 | filesystemsToCopy, |
| 314 | targetFilesystemZipCopy{a.getFilesystemInfo(ctx, *zipCopy.srcModule), zipCopy.destSubdir}, |
| 315 | ) |
| 316 | } |
| 317 | // Get additional filesystems from super_partition dependency |
| 318 | if a.partitionProps.Super_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 319 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 320 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
| 321 | for _, partition := range android.SortedStringKeys(info.SubImageInfo) { |
| 322 | filesystemsToCopy = append( |
| 323 | filesystemsToCopy, |
| 324 | targetFilesystemZipCopy{info.SubImageInfo[partition], strings.ToUpper(partition)}, |
| 325 | ) |
| 326 | } |
| 327 | } else { |
| 328 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | for _, toCopy := range filesystemsToCopy { |
| 333 | rootDirString := toCopy.fsInfo.RootDir.String() |
| 334 | if toCopy.destSubdir == "SYSTEM" { |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 335 | rootDirString = rootDirString + "/system" |
| 336 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 337 | builder.Command().Textf("mkdir -p %s/%s", targetFilesDir.String(), toCopy.destSubdir) |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 338 | builder.Command(). |
| 339 | BuiltTool("acp"). |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 340 | Textf("-rd %s/. %s/%s", rootDirString, targetFilesDir, toCopy.destSubdir). |
| 341 | Implicit(toCopy.fsInfo.Output) // so that the staging dir is built |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 342 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 343 | if toCopy.destSubdir == "SYSTEM" { |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 344 | // Create the ROOT partition in target_files.zip |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 345 | builder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s/ROOT", toCopy.fsInfo.RootDir, targetFilesDir.String()) |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 346 | } |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 347 | } |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 348 | // Copy cmdline, kernel etc. files of boot images |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 349 | if a.partitionProps.Vendor_boot_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 350 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Vendor_boot_partition_name), filesystemDepTag) |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 351 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 352 | builder.Command().Textf("echo %s > %s/VENDOR_BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 353 | builder.Command().Textf("echo %s > %s/VENDOR_BOOT/vendor_cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 354 | if bootImgInfo.Dtb != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 355 | builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_BOOT/dtb", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 356 | } |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 357 | if bootImgInfo.Bootconfig != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 358 | builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/VENDOR_BOOT/vendor_bootconfig", targetFilesDir) |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 359 | } |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 360 | } |
| 361 | if a.partitionProps.Boot_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 362 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag) |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 363 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 364 | builder.Command().Textf("echo %s > %s/BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 365 | if bootImgInfo.Dtb != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 366 | builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/BOOT/dtb", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 367 | } |
| 368 | if bootImgInfo.Kernel != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 369 | builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 370 | // Even though kernel is not used to build vendor_boot, copy the kernel to VENDOR_BOOT to match the behavior of make packaging. |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 371 | builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/VENDOR_BOOT/kernel", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 372 | } |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 373 | if bootImgInfo.Bootconfig != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 374 | builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir) |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 375 | } |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 378 | if a.deviceProps.Android_info != nil { |
| 379 | builder.Command().Textf("mkdir -p %s/OTA", targetFilesDir) |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 380 | builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, *a.deviceProps.Android_info)).Textf(" %s/OTA/android-info.txt", targetFilesDir) |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 383 | a.copyImagesToTargetZip(ctx, builder, targetFilesDir) |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 384 | a.copyMetadataToTargetZip(ctx, builder, targetFilesDir) |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 385 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 386 | builder.Command(). |
| 387 | BuiltTool("soong_zip"). |
| 388 | Text("-d"). |
| 389 | FlagWithOutput("-o ", targetFilesZip). |
| 390 | FlagWithArg("-C ", targetFilesDir.String()). |
| 391 | FlagWithArg("-D ", targetFilesDir.String()). |
| 392 | Text("-sha256") |
| 393 | builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip") |
| 394 | } |
| 395 | |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 396 | func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) { |
| 397 | // Create an IMAGES/ subdirectory |
| 398 | builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String()) |
| 399 | if a.deviceProps.Bootloader != nil { |
| 400 | builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader))).Textf(" %s/IMAGES/bootloader", targetFilesDir.String()) |
| 401 | } |
| 402 | // Copy the filesystem ,boot and vbmeta img files to IMAGES/ |
| 403 | ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(child android.ModuleProxy) { |
Spandan Das | a9db76d | 2025-01-14 01:34:43 +0000 | [diff] [blame] | 404 | if strings.Contains(child.Name(), "recovery") { |
| 405 | return // skip recovery.img to match the make packaging behavior |
| 406 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 407 | if info, ok := android.OtherModuleProvider(ctx, child, BootimgInfoProvider); ok { |
| 408 | // Check Boot img first so that the boot.img is copied and not its dep ramdisk.img |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 409 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 410 | } else if info, ok := android.OtherModuleProvider(ctx, child, FilesystemProvider); ok { |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 411 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 412 | } else if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok { |
| 413 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 414 | } else { |
| 415 | ctx.ModuleErrorf("Module %s does not provide an .img file output for target_files.zip", child.Name()) |
| 416 | } |
| 417 | }) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 418 | |
| 419 | if a.partitionProps.Super_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 420 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 421 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 422 | for _, partition := range android.SortedKeys(info.SubImageInfo) { |
Spandan Das | 7a42d1c | 2025-02-12 01:32:21 +0000 | [diff] [blame] | 423 | if info.SubImageInfo[partition].OutputHermetic != nil { |
| 424 | builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].OutputHermetic).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 425 | } |
| 426 | if info.SubImageInfo[partition].MapFile != nil { |
| 427 | builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].MapFile).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 428 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 429 | } |
| 430 | } else { |
| 431 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 432 | } |
| 433 | } |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 436 | func (a *androidDevice) copyMetadataToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) { |
| 437 | // Create a META/ subdirectory |
| 438 | builder.Command().Textf("mkdir -p %s/META", targetFilesDir.String()) |
| 439 | if proptools.Bool(a.deviceProps.Ab_ota_updater) { |
| 440 | ctx.VisitDirectDepsProxyWithTag(targetFilesMetadataDepTag, func(child android.ModuleProxy) { |
| 441 | info, _ := android.OtherModuleProvider(ctx, child, android.OutputFilesProvider) |
| 442 | builder.Command().Textf("cp").Inputs(info.DefaultOutputFiles).Textf(" %s/META/", targetFilesDir.String()) |
| 443 | }) |
Spandan Das | b5f40cf | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 444 | builder.Command().Textf("cp").Input(android.PathForSource(ctx, "external/zucchini/version_info.h")).Textf(" %s/META/zucchini_config.txt", targetFilesDir.String()) |
| 445 | builder.Command().Textf("cp").Input(android.PathForSource(ctx, "system/update_engine/update_engine.conf")).Textf(" %s/META/update_engine_config.txt", targetFilesDir.String()) |
| 446 | if a.getFsInfos(ctx)["system"].ErofsCompressHints != nil { |
| 447 | builder.Command().Textf("cp").Input(a.getFsInfos(ctx)["system"].ErofsCompressHints).Textf(" %s/META/erofs_default_compress_hints.txt", targetFilesDir.String()) |
| 448 | } |
| 449 | // ab_partitions.txt |
| 450 | abPartitionsSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_partitions) |
| 451 | abPartitionsSortedString := proptools.ShellEscape(strings.Join(abPartitionsSorted, "\\n")) |
| 452 | builder.Command().Textf("echo -e").Flag(abPartitionsSortedString).Textf(" > %s/META/ab_partitions.txt", targetFilesDir.String()) |
Spandan Das | 35b7874 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 453 | // otakeys.txt |
| 454 | abOtaKeysSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_keys) |
| 455 | abOtaKeysSortedString := proptools.ShellEscape(strings.Join(abOtaKeysSorted, "\\n")) |
| 456 | builder.Command().Textf("echo -e").Flag(abOtaKeysSortedString).Textf(" > %s/META/otakeys.txt", targetFilesDir.String()) |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame^] | 457 | // selinuxfc |
| 458 | if a.getFsInfos(ctx)["system"].SelinuxFc != nil { |
| 459 | builder.Command().Textf("cp").Input(a.getFsInfos(ctx)["system"].SelinuxFc).Textf(" %s/META/file_contexts.bin", targetFilesDir.String()) |
| 460 | } |
Spandan Das | d71af18 | 2025-02-12 18:03:29 +0000 | [diff] [blame] | 461 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 464 | func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 465 | fsMod := ctx.GetDirectDepProxyWithTag(depName, filesystemDepTag) |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 466 | fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider) |
| 467 | if !ok { |
| 468 | ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName) |
| 469 | } |
| 470 | return fsInfo |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 471 | } |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 472 | |
| 473 | func (a *androidDevice) setVbmetaPhonyTargets(ctx android.ModuleContext) { |
| 474 | if !proptools.Bool(a.deviceProps.Main_device) { |
| 475 | return |
| 476 | } |
| 477 | |
| 478 | if !ctx.Config().KatiEnabled() { |
| 479 | for _, vbmetaPartitionName := range a.partitionProps.Vbmeta_partitions { |
| 480 | img := ctx.GetDirectDepProxyWithTag(vbmetaPartitionName, filesystemDepTag) |
| 481 | if provider, ok := android.OtherModuleProvider(ctx, img, vbmetaPartitionProvider); ok { |
| 482 | // make generates `vbmetasystemimage` phony target instead of `vbmeta_systemimage` phony target. |
| 483 | partitionName := strings.ReplaceAll(provider.Name, "_", "") |
| 484 | ctx.Phony(fmt.Sprintf("%simage", partitionName), provider.Output) |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | } |