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