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