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