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 | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 18 | "cmp" |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 19 | "fmt" |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 20 | "path/filepath" |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 21 | "slices" |
Wei Li | 7b8455f | 2025-03-05 16:05:51 -0800 | [diff] [blame] | 22 | "sort" |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 23 | "strings" |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 24 | "sync/atomic" |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 25 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 26 | "android/soong/android" |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 27 | "android/soong/java" |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint" |
| 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 33 | var proguardDictToProto = pctx.AndroidStaticRule("proguard_dict_to_proto", blueprint.RuleParams{ |
| 34 | Command: `${symbols_map} -r8 $in -location $location -write_if_changed $out`, |
| 35 | Restat: true, |
| 36 | CommandDeps: []string{"${symbols_map}"}, |
| 37 | }, "location") |
| 38 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 39 | type PartitionNameProperties struct { |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 40 | // Name of the super partition filesystem module |
| 41 | Super_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 42 | // Name of the boot partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 43 | Boot_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 44 | // Name of the vendor boot partition filesystem module |
| 45 | Vendor_boot_partition_name *string |
| 46 | // Name of the init boot partition filesystem module |
| 47 | Init_boot_partition_name *string |
| 48 | // Name of the system partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 49 | System_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 50 | // Name of the system_ext partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 51 | System_ext_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 52 | // Name of the product partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 53 | Product_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 54 | // Name of the vendor partition filesystem module |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 55 | Vendor_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 56 | // Name of the odm partition filesystem module |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 57 | Odm_partition_name *string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 58 | // Name of the recovery partition filesystem module |
| 59 | Recovery_partition_name *string |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 60 | // The vbmeta partition and its "chained" partitions |
| 61 | Vbmeta_partitions []string |
Jihoon Kang | e7e3ec8 | 2025-01-02 21:29:14 +0000 | [diff] [blame] | 62 | // Name of the userdata partition filesystem module |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 63 | Userdata_partition_name *string |
Spandan Das | a039400 | 2025-01-07 18:38:34 +0000 | [diff] [blame] | 64 | // Name of the system_dlkm partition filesystem module |
| 65 | System_dlkm_partition_name *string |
| 66 | // Name of the vendor_dlkm partition filesystem module |
| 67 | Vendor_dlkm_partition_name *string |
| 68 | // Name of the odm_dlkm partition filesystem module |
| 69 | Odm_dlkm_partition_name *string |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 72 | type DeviceProperties struct { |
| 73 | // Path to the prebuilt bootloader that would be copied to PRODUCT_OUT |
| 74 | Bootloader *string `android:"path"` |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 75 | // Path to android-info.txt file containing board specific info. |
| 76 | Android_info *string `android:"path"` |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 77 | // If this is the "main" android_device target for the build, i.e. the one that gets built |
| 78 | // when running a plain `m` command. Currently, this is the autogenerated android_device module |
| 79 | // in soong-only builds, but in the future when we check in android_device modules, the main |
| 80 | // one will be determined based on the lunch product. TODO: Figure out how to make this |
| 81 | // blueprint:"mutated" and still set it from filesystem_creator |
| 82 | Main_device *bool |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 83 | |
Spandan Das | 0094807 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 84 | Ab_ota_updater *bool |
| 85 | Ab_ota_partitions []string |
| 86 | Ab_ota_keys []string |
| 87 | Ab_ota_postinstall_config []string |
Spandan Das | 75955b1 | 2025-02-13 22:12:52 +0000 | [diff] [blame] | 88 | |
Spandan Das | 37240d9 | 2025-02-14 00:18:41 +0000 | [diff] [blame] | 89 | Ramdisk_node_list *string `android:"path"` |
| 90 | Releasetools_extension *string `android:"path"` |
Spandan Das | 3dfa17f | 2025-02-28 09:48:28 +0000 | [diff] [blame] | 91 | FastbootInfo *string `android:"path"` |
Cole Faust | 21c1146 | 2025-03-03 14:13:17 -0800 | [diff] [blame] | 92 | |
| 93 | // The kernel version in the build. Will be verified against the actual kernel. |
| 94 | // If not provided, will attempt to extract it from the loose kernel or the kernel inside |
| 95 | // the boot image. The version is later used to decide whether or not to enable uffd_gc |
| 96 | // when dexpreopting apps. So setting this doesn't really do anything except enforce that the |
| 97 | // actual kernel version is as specified here. |
| 98 | Kernel_version *string |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 101 | type androidDevice struct { |
| 102 | android.ModuleBase |
| 103 | |
| 104 | partitionProps PartitionNameProperties |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 105 | |
| 106 | deviceProps DeviceProperties |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 107 | |
| 108 | allImagesZip android.Path |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 109 | |
Spandan Das | e06dd11 | 2025-03-05 01:29:04 +0000 | [diff] [blame] | 110 | proguardDictZip android.Path |
| 111 | proguardDictMapping android.Path |
| 112 | proguardUsageZip android.Path |
| 113 | kernelConfig android.Path |
| 114 | kernelVersion android.Path |
| 115 | miscInfo android.Path |
| 116 | rootDirForFsConfig string |
| 117 | rootDirForFsConfigTimestamp android.Path |
Spandan Das | 38afe71 | 2025-03-05 23:27:55 +0000 | [diff] [blame] | 118 | apkCertsInfo android.Path |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | func AndroidDeviceFactory() android.Module { |
| 122 | module := &androidDevice{} |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 123 | module.AddProperties(&module.partitionProps, &module.deviceProps) |
Cole Faust | 341d5f1 | 2025-01-07 15:32:38 -0800 | [diff] [blame] | 124 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 125 | return module |
| 126 | } |
| 127 | |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 128 | var numMainAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices") |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 129 | |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 130 | type partitionDepTagType struct { |
| 131 | blueprint.BaseDependencyTag |
| 132 | } |
| 133 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 134 | type superPartitionDepTagType struct { |
| 135 | blueprint.BaseDependencyTag |
| 136 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 137 | type targetFilesMetadataDepTagType struct { |
| 138 | blueprint.BaseDependencyTag |
| 139 | } |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 140 | |
| 141 | var superPartitionDepTag superPartitionDepTagType |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 142 | var filesystemDepTag partitionDepTagType |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 143 | var targetFilesMetadataDepTag targetFilesMetadataDepTagType |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 144 | |
| 145 | func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 146 | addDependencyIfDefined := func(dep *string) { |
| 147 | if dep != nil { |
Cole Faust | 341d5f1 | 2025-01-07 15:32:38 -0800 | [diff] [blame] | 148 | ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep)) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 152 | if a.partitionProps.Super_partition_name != nil { |
| 153 | ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name) |
| 154 | } |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 155 | addDependencyIfDefined(a.partitionProps.Boot_partition_name) |
Jihoon Kang | 9e08700 | 2025-01-08 19:12:23 +0000 | [diff] [blame] | 156 | addDependencyIfDefined(a.partitionProps.Init_boot_partition_name) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 157 | addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name) |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 158 | addDependencyIfDefined(a.partitionProps.System_partition_name) |
| 159 | addDependencyIfDefined(a.partitionProps.System_ext_partition_name) |
| 160 | addDependencyIfDefined(a.partitionProps.Product_partition_name) |
| 161 | addDependencyIfDefined(a.partitionProps.Vendor_partition_name) |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 162 | addDependencyIfDefined(a.partitionProps.Odm_partition_name) |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 163 | addDependencyIfDefined(a.partitionProps.Userdata_partition_name) |
Spandan Das | a039400 | 2025-01-07 18:38:34 +0000 | [diff] [blame] | 164 | addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name) |
| 165 | addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name) |
| 166 | addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 167 | addDependencyIfDefined(a.partitionProps.Recovery_partition_name) |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 168 | for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions { |
| 169 | ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition) |
| 170 | } |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 171 | a.addDepsForTargetFilesMetadata(ctx) |
| 172 | } |
| 173 | |
| 174 | func (a *androidDevice) addDepsForTargetFilesMetadata(ctx android.BottomUpMutatorContext) { |
| 175 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), targetFilesMetadataDepTag, "liblz4") // host variant |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 178 | func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 179 | if proptools.Bool(a.deviceProps.Main_device) { |
| 180 | numMainAndroidDevices := ctx.Config().Once(numMainAndroidDevicesOnceKey, func() interface{} { |
| 181 | return &atomic.Int32{} |
| 182 | }).(*atomic.Int32) |
| 183 | total := numMainAndroidDevices.Add(1) |
| 184 | if total > 1 { |
| 185 | // There should only be 1 main android_device module. That one will be |
| 186 | // made the default thing to build in soong-only builds. |
| 187 | ctx.ModuleErrorf("There cannot be more than 1 main android_device module") |
| 188 | } |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 191 | allInstalledModules := a.allInstalledModules(ctx) |
| 192 | |
Spandan Das | 38afe71 | 2025-03-05 23:27:55 +0000 | [diff] [blame] | 193 | a.apkCertsInfo = a.buildApkCertsInfo(ctx, allInstalledModules) |
Spandan Das | 2dee3f7 | 2025-03-07 18:32:06 +0000 | [diff] [blame] | 194 | a.kernelVersion, a.kernelConfig = a.extractKernelVersionAndConfigs(ctx) |
Spandan Das | 447a0ab | 2025-03-04 23:10:19 +0000 | [diff] [blame] | 195 | a.miscInfo = a.addMiscInfo(ctx) |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 196 | a.buildTargetFilesZip(ctx, allInstalledModules) |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 197 | a.buildProguardZips(ctx, allInstalledModules) |
| 198 | |
mrziwang | 2fd33a7 | 2025-01-08 12:22:08 -0800 | [diff] [blame] | 199 | var deps []android.Path |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 200 | if proptools.String(a.partitionProps.Super_partition_name) != "" { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 201 | superImage := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 202 | if info, ok := android.OtherModuleProvider(ctx, superImage, SuperImageProvider); ok { |
| 203 | assertUnset := func(prop *string, propName string) { |
| 204 | if prop != nil && *prop != "" { |
| 205 | ctx.PropertyErrorf(propName, "Cannot be set because it's already part of the super image") |
| 206 | } |
| 207 | } |
| 208 | for _, subPartitionType := range android.SortedKeys(info.SubImageInfo) { |
| 209 | switch subPartitionType { |
| 210 | case "system": |
| 211 | assertUnset(a.partitionProps.System_partition_name, "system_partition_name") |
| 212 | case "system_ext": |
| 213 | assertUnset(a.partitionProps.System_ext_partition_name, "system_ext_partition_name") |
| 214 | case "system_dlkm": |
| 215 | assertUnset(a.partitionProps.System_dlkm_partition_name, "system_dlkm_partition_name") |
| 216 | case "system_other": |
| 217 | // TODO |
| 218 | case "product": |
| 219 | assertUnset(a.partitionProps.Product_partition_name, "product_partition_name") |
| 220 | case "vendor": |
| 221 | assertUnset(a.partitionProps.Vendor_partition_name, "vendor_partition_name") |
| 222 | case "vendor_dlkm": |
| 223 | assertUnset(a.partitionProps.Vendor_dlkm_partition_name, "vendor_dlkm_partition_name") |
| 224 | case "odm": |
| 225 | assertUnset(a.partitionProps.Odm_partition_name, "odm_partition_name") |
| 226 | case "odm_dlkm": |
| 227 | assertUnset(a.partitionProps.Odm_dlkm_partition_name, "odm_dlkm_partition_name") |
| 228 | default: |
| 229 | ctx.ModuleErrorf("Unsupported sub-partition of super partition: %q", subPartitionType) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | deps = append(deps, info.SuperImage) |
| 234 | } else { |
| 235 | ctx.ModuleErrorf("Expected super image dep to provide SuperImageProvider") |
| 236 | } |
| 237 | } |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 238 | ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(m android.ModuleProxy) { |
mrziwang | 2fd33a7 | 2025-01-08 12:22:08 -0800 | [diff] [blame] | 239 | imageOutput, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider) |
| 240 | if !ok { |
| 241 | ctx.ModuleErrorf("Partition module %s doesn't set OutputfilesProvider", m.Name()) |
| 242 | } |
| 243 | if len(imageOutput.DefaultOutputFiles) != 1 { |
| 244 | ctx.ModuleErrorf("Partition module %s should provide exact 1 output file", m.Name()) |
| 245 | } |
| 246 | deps = append(deps, imageOutput.DefaultOutputFiles[0]) |
| 247 | }) |
Jihoon Kang | 3be1716 | 2025-01-09 20:51:54 +0000 | [diff] [blame] | 248 | |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 249 | allImagesZip := android.PathForModuleOut(ctx, "all_images.zip") |
| 250 | allImagesZipBuilder := android.NewRuleBuilder(pctx, ctx) |
Cole Faust | 8967d75 | 2025-02-19 17:27:29 -0800 | [diff] [blame] | 251 | cmd := allImagesZipBuilder.Command().BuiltTool("soong_zip") |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 252 | for _, dep := range deps { |
| 253 | cmd.FlagWithArg("-e ", dep.Base()) |
| 254 | cmd.FlagWithInput("-f ", dep) |
| 255 | } |
| 256 | cmd.FlagWithOutput("-o ", allImagesZip) |
| 257 | allImagesZipBuilder.Build("soong_all_images_zip", "all_images.zip") |
| 258 | a.allImagesZip = allImagesZip |
| 259 | |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 260 | allImagesStamp := android.PathForModuleOut(ctx, "all_images_stamp") |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 261 | var validations android.Paths |
| 262 | if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) { |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 263 | // In soong-only builds, build this module by default. |
| 264 | // This is the analogue to this make code: |
| 265 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/main.mk;l=1396;drc=6595459cdd8164a6008335f6372c9f97b9094060 |
| 266 | ctx.Phony("droidcore-unbundled", allImagesStamp) |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 267 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 268 | deps = append(deps, a.copyFilesToProductOutForSoongOnly(ctx)) |
Cole Faust | b55a41c | 2025-01-09 16:53:58 -0800 | [diff] [blame] | 269 | } |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 270 | |
| 271 | ctx.Build(pctx, android.BuildParams{ |
| 272 | Rule: android.Touch, |
| 273 | Output: allImagesStamp, |
| 274 | Implicits: deps, |
| 275 | Validations: validations, |
| 276 | }) |
| 277 | |
| 278 | // Checkbuilding it causes soong to make a phony, so you can say `m <module name>` |
| 279 | ctx.CheckbuildFile(allImagesStamp) |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 280 | |
| 281 | a.setVbmetaPhonyTargets(ctx) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 282 | |
| 283 | a.distFiles(ctx) |
Wei Li | 7b8455f | 2025-03-05 16:05:51 -0800 | [diff] [blame] | 284 | |
| 285 | android.SetProvider(ctx, android.AndroidDeviceInfoProvider, android.AndroidDeviceInfo{ |
| 286 | Main_device: android.Bool(a.deviceProps.Main_device), |
| 287 | }) |
| 288 | |
| 289 | if proptools.String(a.partitionProps.Super_partition_name) != "" { |
| 290 | buildComplianceMetadata(ctx, superPartitionDepTag, filesystemDepTag) |
| 291 | } else { |
| 292 | buildComplianceMetadata(ctx, filesystemDepTag) |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | func buildComplianceMetadata(ctx android.ModuleContext, tags ...blueprint.DependencyTag) { |
| 297 | filesContained := make([]string, 0) |
| 298 | for _, tag := range tags { |
| 299 | ctx.VisitDirectDepsProxyWithTag(tag, func(m android.ModuleProxy) { |
| 300 | if complianceMetadataInfo, ok := android.OtherModuleProvider(ctx, m, android.ComplianceMetadataProvider); ok { |
| 301 | filesContained = append(filesContained, complianceMetadataInfo.GetFilesContained()...) |
| 302 | } |
| 303 | }) |
| 304 | } |
| 305 | sort.Strings(filesContained) |
| 306 | |
| 307 | complianceMetadataInfo := ctx.ComplianceMetadataInfo() |
| 308 | complianceMetadataInfo.SetFilesContained(filesContained) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 311 | // Returns a list of modules that are installed, which are collected from the dependency |
| 312 | // filesystem and super_image modules. |
| 313 | func (a *androidDevice) allInstalledModules(ctx android.ModuleContext) []android.Module { |
| 314 | fsInfoMap := a.getFsInfos(ctx) |
| 315 | allOwners := make(map[string][]string) |
| 316 | for _, partition := range android.SortedKeys(fsInfoMap) { |
| 317 | fsInfo := fsInfoMap[partition] |
| 318 | for _, owner := range fsInfo.Owners { |
| 319 | allOwners[owner.Name] = append(allOwners[owner.Name], owner.Variation) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | ret := []android.Module{} |
| 324 | ctx.WalkDepsProxy(func(mod, _ android.ModuleProxy) bool { |
Spandan Das | 5c78fe9 | 2025-02-26 14:25:56 +0000 | [diff] [blame] | 325 | if variations, ok := allOwners[ctx.OtherModuleName(mod)]; ok && android.InList(ctx.OtherModuleSubDir(mod), variations) { |
Jihoon Kang | abec3ec | 2025-02-19 00:55:10 +0000 | [diff] [blame] | 326 | ret = append(ret, mod) |
| 327 | } |
| 328 | return true |
| 329 | }) |
| 330 | |
| 331 | // Remove duplicates |
| 332 | ret = android.FirstUniqueFunc(ret, func(a, b android.Module) bool { |
| 333 | return a.String() == b.String() |
| 334 | }) |
| 335 | |
| 336 | // Sort the modules by their names and variants |
| 337 | slices.SortFunc(ret, func(a, b android.Module) int { |
| 338 | return cmp.Compare(a.String(), b.String()) |
| 339 | }) |
| 340 | return ret |
| 341 | } |
| 342 | |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 343 | func insertBeforeExtension(file, insertion string) string { |
| 344 | ext := filepath.Ext(file) |
| 345 | return strings.TrimSuffix(file, ext) + insertion + ext |
| 346 | } |
| 347 | |
Jihoon Kang | dd49f41 | 2025-03-07 01:30:43 +0000 | [diff] [blame] | 348 | func (a *androidDevice) distInstalledFiles(ctx android.ModuleContext) { |
| 349 | distInstalledFilesJsonAndTxt := func(installedFiles InstalledFilesStruct) { |
| 350 | if installedFiles.Json != nil { |
| 351 | ctx.DistForGoal("droidcore-unbundled", installedFiles.Json) |
| 352 | } |
| 353 | if installedFiles.Txt != nil { |
| 354 | ctx.DistForGoal("droidcore-unbundled", installedFiles.Txt) |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | fsInfoMap := a.getFsInfos(ctx) |
| 359 | for _, partition := range android.SortedKeys(fsInfoMap) { |
| 360 | // installed-files-*{.txt | .json} is not disted for userdata partition |
| 361 | if partition == "userdata" { |
| 362 | continue |
| 363 | } |
| 364 | fsInfo := fsInfoMap[partition] |
| 365 | for _, installedFiles := range fsInfo.InstalledFilesDepSet.ToList() { |
| 366 | distInstalledFilesJsonAndTxt(installedFiles) |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 371 | func (a *androidDevice) distFiles(ctx android.ModuleContext) { |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 372 | if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) { |
Jihoon Kang | dd49f41 | 2025-03-07 01:30:43 +0000 | [diff] [blame] | 373 | a.distInstalledFiles(ctx) |
Jihoon Kang | f67b7de | 2025-02-12 01:01:09 +0000 | [diff] [blame] | 374 | |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 375 | namePrefix := "" |
| 376 | if ctx.Config().HasDeviceProduct() { |
| 377 | namePrefix = ctx.Config().DeviceProduct() + "-" |
| 378 | } |
| 379 | ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardDictZip, namePrefix+insertBeforeExtension(a.proguardDictZip.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) |
| 380 | ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardDictMapping, namePrefix+insertBeforeExtension(a.proguardDictMapping.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) |
| 381 | ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardUsageZip, namePrefix+insertBeforeExtension(a.proguardUsageZip.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) |
Cole Faust | d8d570c | 2025-03-04 14:20:16 -0800 | [diff] [blame] | 382 | |
| 383 | if a.deviceProps.Android_info != nil { |
| 384 | ctx.DistForGoal("droidcore-unbundled", android.PathForModuleSrc(ctx, *a.deviceProps.Android_info)) |
| 385 | } |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 386 | } |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 387 | } |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 388 | |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame] | 389 | func (a *androidDevice) MakeVars(_ android.MakeVarsModuleContext) []android.ModuleMakeVarsValue { |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 390 | if proptools.Bool(a.deviceProps.Main_device) { |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame] | 391 | return []android.ModuleMakeVarsValue{{"SOONG_ONLY_ALL_IMAGES_ZIP", a.allImagesZip.String()}} |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 392 | } |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame] | 393 | return nil |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 396 | func (a *androidDevice) buildProguardZips(ctx android.ModuleContext, allInstalledModules []android.Module) { |
| 397 | dictZip := android.PathForModuleOut(ctx, "proguard-dict.zip") |
| 398 | dictZipBuilder := android.NewRuleBuilder(pctx, ctx) |
| 399 | dictZipCmd := dictZipBuilder.Command().BuiltTool("soong_zip").Flag("-d").FlagWithOutput("-o ", dictZip) |
| 400 | |
| 401 | dictMapping := android.PathForModuleOut(ctx, "proguard-dict-mapping.textproto") |
| 402 | dictMappingBuilder := android.NewRuleBuilder(pctx, ctx) |
| 403 | dictMappingCmd := dictMappingBuilder.Command().BuiltTool("symbols_map").Flag("-merge").Output(dictMapping) |
| 404 | |
| 405 | protosDir := android.PathForModuleOut(ctx, "proguard_mapping_protos") |
| 406 | |
| 407 | usageZip := android.PathForModuleOut(ctx, "proguard-usage.zip") |
| 408 | usageZipBuilder := android.NewRuleBuilder(pctx, ctx) |
| 409 | usageZipCmd := usageZipBuilder.Command().BuiltTool("merge_zips").Output(usageZip) |
| 410 | |
| 411 | for _, mod := range allInstalledModules { |
| 412 | if proguardInfo, ok := android.OtherModuleProvider(ctx, mod, java.ProguardProvider); ok { |
| 413 | // Maintain these out/target/common paths for backwards compatibility. They may be able |
| 414 | // to be changed if tools look up file locations from the protobuf, but I'm not |
| 415 | // exactly sure how that works. |
| 416 | dictionaryFakePath := fmt.Sprintf("out/target/common/obj/%s/%s_intermediates/proguard_dictionary", proguardInfo.Class, proguardInfo.ModuleName) |
| 417 | dictZipCmd.FlagWithArg("-e ", dictionaryFakePath) |
| 418 | dictZipCmd.FlagWithInput("-f ", proguardInfo.ProguardDictionary) |
| 419 | dictZipCmd.Textf("-e out/target/common/obj/%s/%s_intermediates/classes.jar", proguardInfo.Class, proguardInfo.ModuleName) |
| 420 | dictZipCmd.FlagWithInput("-f ", proguardInfo.ClassesJar) |
| 421 | |
| 422 | protoFile := protosDir.Join(ctx, filepath.Dir(dictionaryFakePath), "proguard_dictionary.textproto") |
| 423 | ctx.Build(pctx, android.BuildParams{ |
| 424 | Rule: proguardDictToProto, |
| 425 | Input: proguardInfo.ProguardDictionary, |
| 426 | Output: protoFile, |
| 427 | Args: map[string]string{ |
| 428 | "location": dictionaryFakePath, |
| 429 | }, |
| 430 | }) |
| 431 | dictMappingCmd.Input(protoFile) |
| 432 | |
| 433 | usageZipCmd.Input(proguardInfo.ProguardUsageZip) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | dictZipBuilder.Build("proguard_dict_zip", "Building proguard dictionary zip") |
| 438 | dictMappingBuilder.Build("proguard_dict_mapping_proto", "Building proguard mapping proto") |
| 439 | usageZipBuilder.Build("proguard_usage_zip", "Building proguard usage zip") |
Cole Faust | 54124c8 | 2025-02-21 14:46:02 -0800 | [diff] [blame] | 440 | |
| 441 | a.proguardDictZip = dictZip |
| 442 | a.proguardDictMapping = dictMapping |
| 443 | a.proguardUsageZip = usageZip |
Cole Faust | 1dcf9e4 | 2025-02-19 17:23:34 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 446 | // Helper structs for target_files.zip creation |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 447 | type targetFilesZipCopy struct { |
| 448 | srcModule *string |
| 449 | destSubdir string |
| 450 | } |
| 451 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 452 | type targetFilesystemZipCopy struct { |
| 453 | fsInfo FilesystemInfo |
| 454 | destSubdir string |
| 455 | } |
| 456 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 457 | func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext, allInstalledModules []android.Module) { |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 458 | targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir") |
| 459 | targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip") |
| 460 | |
| 461 | builder := android.NewRuleBuilder(pctx, ctx) |
| 462 | builder.Command().Textf("rm -rf %s", targetFilesDir.String()) |
| 463 | builder.Command().Textf("mkdir -p %s", targetFilesDir.String()) |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 464 | toCopy := []targetFilesZipCopy{ |
| 465 | targetFilesZipCopy{a.partitionProps.System_partition_name, "SYSTEM"}, |
| 466 | targetFilesZipCopy{a.partitionProps.System_ext_partition_name, "SYSTEM_EXT"}, |
| 467 | targetFilesZipCopy{a.partitionProps.Product_partition_name, "PRODUCT"}, |
| 468 | targetFilesZipCopy{a.partitionProps.Vendor_partition_name, "VENDOR"}, |
| 469 | targetFilesZipCopy{a.partitionProps.Odm_partition_name, "ODM"}, |
| 470 | targetFilesZipCopy{a.partitionProps.System_dlkm_partition_name, "SYSTEM_DLKM"}, |
| 471 | targetFilesZipCopy{a.partitionProps.Vendor_dlkm_partition_name, "VENDOR_DLKM"}, |
| 472 | targetFilesZipCopy{a.partitionProps.Odm_dlkm_partition_name, "ODM_DLKM"}, |
| 473 | targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"}, |
| 474 | targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"}, |
| 475 | targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"}, |
Spandan Das | 25649f5 | 2025-01-07 18:09:22 +0000 | [diff] [blame] | 476 | } |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 477 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 478 | filesystemsToCopy := []targetFilesystemZipCopy{} |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 479 | for _, zipCopy := range toCopy { |
| 480 | if zipCopy.srcModule == nil { |
Spandan Das | 25649f5 | 2025-01-07 18:09:22 +0000 | [diff] [blame] | 481 | continue |
| 482 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 483 | filesystemsToCopy = append( |
| 484 | filesystemsToCopy, |
| 485 | targetFilesystemZipCopy{a.getFilesystemInfo(ctx, *zipCopy.srcModule), zipCopy.destSubdir}, |
| 486 | ) |
| 487 | } |
| 488 | // Get additional filesystems from super_partition dependency |
| 489 | if a.partitionProps.Super_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 490 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 491 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
Cole Faust | 310de66 | 2025-02-19 16:15:07 -0800 | [diff] [blame] | 492 | for _, partition := range android.SortedKeys(info.SubImageInfo) { |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 493 | filesystemsToCopy = append( |
| 494 | filesystemsToCopy, |
| 495 | targetFilesystemZipCopy{info.SubImageInfo[partition], strings.ToUpper(partition)}, |
| 496 | ) |
| 497 | } |
| 498 | } else { |
| 499 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | for _, toCopy := range filesystemsToCopy { |
| 504 | rootDirString := toCopy.fsInfo.RootDir.String() |
| 505 | if toCopy.destSubdir == "SYSTEM" { |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 506 | rootDirString = rootDirString + "/system" |
| 507 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 508 | builder.Command().Textf("mkdir -p %s/%s", targetFilesDir.String(), toCopy.destSubdir) |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 509 | builder.Command(). |
| 510 | BuiltTool("acp"). |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 511 | Textf("-rd %s/. %s/%s", rootDirString, targetFilesDir, toCopy.destSubdir). |
| 512 | Implicit(toCopy.fsInfo.Output) // so that the staging dir is built |
Cole Faust | b36763e | 2025-02-18 15:21:44 -0800 | [diff] [blame] | 513 | for _, extraRootDir := range toCopy.fsInfo.ExtraRootDirs { |
| 514 | builder.Command(). |
| 515 | BuiltTool("acp"). |
| 516 | Textf("-rd %s/. %s/%s", extraRootDir, targetFilesDir, toCopy.destSubdir). |
| 517 | Implicit(toCopy.fsInfo.Output) // so that the staging dir is built |
| 518 | } |
Spandan Das | ef200ac | 2025-01-08 01:42:45 +0000 | [diff] [blame] | 519 | |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 520 | if toCopy.destSubdir == "SYSTEM" { |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 521 | // Create the ROOT partition in target_files.zip |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 522 | builder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s/ROOT", toCopy.fsInfo.RootDir, targetFilesDir.String()) |
Spandan Das | e06dd11 | 2025-03-05 01:29:04 +0000 | [diff] [blame] | 523 | // Add a duplicate rule to assemble the ROOT/ directory in separate intermediates. |
| 524 | // The output timestamp will be an input to a separate fs_config call. |
| 525 | a.rootDirForFsConfig = android.PathForModuleOut(ctx, "root_dir_for_fs_config").String() |
| 526 | rootDirBuilder := android.NewRuleBuilder(pctx, ctx) |
| 527 | rootDirForFsConfigTimestamp := android.PathForModuleOut(ctx, "root_dir_for_fs_config.timestamp") |
| 528 | rootDirBuilder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s", toCopy.fsInfo.RootDir, a.rootDirForFsConfig). |
| 529 | Implicit(toCopy.fsInfo.Output). |
| 530 | Text("&& touch"). |
| 531 | Output(rootDirForFsConfigTimestamp) |
| 532 | rootDirBuilder.Build("assemble_root_dir_for_fs_config", "Assemble ROOT/ for fs_config") |
| 533 | a.rootDirForFsConfigTimestamp = rootDirForFsConfigTimestamp |
Spandan Das | 3ec6d06 | 2025-01-09 19:37:47 +0000 | [diff] [blame] | 534 | } |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 535 | } |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 536 | // Copy cmdline, kernel etc. files of boot images |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 537 | if a.partitionProps.Vendor_boot_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 538 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Vendor_boot_partition_name), filesystemDepTag) |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 539 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 540 | builder.Command().Textf("echo %s > %s/VENDOR_BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 541 | builder.Command().Textf("echo %s > %s/VENDOR_BOOT/vendor_cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 542 | if bootImgInfo.Dtb != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 543 | 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] | 544 | } |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 545 | if bootImgInfo.Bootconfig != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 546 | 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] | 547 | } |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 548 | } |
| 549 | if a.partitionProps.Boot_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 550 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag) |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 551 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 552 | builder.Command().Textf("echo %s > %s/BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir) |
| 553 | if bootImgInfo.Dtb != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 554 | builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/BOOT/dtb", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 555 | } |
| 556 | if bootImgInfo.Kernel != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 557 | builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir) |
Spandan Das | 9b17df2 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 558 | // 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] | 559 | 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] | 560 | } |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 561 | if bootImgInfo.Bootconfig != nil { |
Spandan Das | fed3d04 | 2025-01-13 21:38:47 +0000 | [diff] [blame] | 562 | builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir) |
Spandan Das | 2351137 | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 563 | } |
Spandan Das | 258c08f | 2025-01-08 23:30:45 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Spandan Das | e51ff95 | 2025-01-09 18:11:59 +0000 | [diff] [blame] | 566 | if a.deviceProps.Android_info != nil { |
| 567 | builder.Command().Textf("mkdir -p %s/OTA", targetFilesDir) |
Cole Faust | 11fda33 | 2025-01-14 16:47:19 -0800 | [diff] [blame] | 568 | 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] | 569 | } |
| 570 | |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 571 | a.copyImagesToTargetZip(ctx, builder, targetFilesDir) |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 572 | a.copyMetadataToTargetZip(ctx, builder, targetFilesDir, allInstalledModules) |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 573 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 574 | builder.Command(). |
| 575 | BuiltTool("soong_zip"). |
| 576 | Text("-d"). |
| 577 | FlagWithOutput("-o ", targetFilesZip). |
| 578 | FlagWithArg("-C ", targetFilesDir.String()). |
| 579 | FlagWithArg("-D ", targetFilesDir.String()). |
| 580 | Text("-sha256") |
| 581 | builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip") |
| 582 | } |
| 583 | |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 584 | func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) { |
| 585 | // Create an IMAGES/ subdirectory |
| 586 | builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String()) |
| 587 | if a.deviceProps.Bootloader != nil { |
| 588 | builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader))).Textf(" %s/IMAGES/bootloader", targetFilesDir.String()) |
| 589 | } |
| 590 | // Copy the filesystem ,boot and vbmeta img files to IMAGES/ |
| 591 | ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(child android.ModuleProxy) { |
Spandan Das | a9db76d | 2025-01-14 01:34:43 +0000 | [diff] [blame] | 592 | if strings.Contains(child.Name(), "recovery") { |
| 593 | return // skip recovery.img to match the make packaging behavior |
| 594 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 595 | if info, ok := android.OtherModuleProvider(ctx, child, BootimgInfoProvider); ok { |
| 596 | // 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] | 597 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 598 | } else if info, ok := android.OtherModuleProvider(ctx, child, FilesystemProvider); ok { |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 599 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 600 | } else if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok { |
| 601 | builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 602 | } else { |
| 603 | ctx.ModuleErrorf("Module %s does not provide an .img file output for target_files.zip", child.Name()) |
| 604 | } |
| 605 | }) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 606 | |
| 607 | if a.partitionProps.Super_partition_name != nil { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 608 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 609 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 610 | for _, partition := range android.SortedKeys(info.SubImageInfo) { |
Spandan Das | 7a42d1c | 2025-02-12 01:32:21 +0000 | [diff] [blame] | 611 | if info.SubImageInfo[partition].OutputHermetic != nil { |
| 612 | builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].OutputHermetic).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 613 | } |
| 614 | if info.SubImageInfo[partition].MapFile != nil { |
| 615 | builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].MapFile).Textf(" %s/IMAGES/", targetFilesDir.String()) |
| 616 | } |
Spandan Das | ef77574 | 2025-01-13 22:17:40 +0000 | [diff] [blame] | 617 | } |
| 618 | } else { |
| 619 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 620 | } |
| 621 | } |
Spandan Das | 0036fa3 | 2025-01-10 23:40:45 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 624 | func (a *androidDevice) copyMetadataToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath, allInstalledModules []android.Module) { |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 625 | // Create a META/ subdirectory |
| 626 | builder.Command().Textf("mkdir -p %s/META", targetFilesDir.String()) |
| 627 | if proptools.Bool(a.deviceProps.Ab_ota_updater) { |
| 628 | ctx.VisitDirectDepsProxyWithTag(targetFilesMetadataDepTag, func(child android.ModuleProxy) { |
| 629 | info, _ := android.OtherModuleProvider(ctx, child, android.OutputFilesProvider) |
| 630 | builder.Command().Textf("cp").Inputs(info.DefaultOutputFiles).Textf(" %s/META/", targetFilesDir.String()) |
| 631 | }) |
Spandan Das | b5f40cf | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 632 | builder.Command().Textf("cp").Input(android.PathForSource(ctx, "external/zucchini/version_info.h")).Textf(" %s/META/zucchini_config.txt", targetFilesDir.String()) |
| 633 | builder.Command().Textf("cp").Input(android.PathForSource(ctx, "system/update_engine/update_engine.conf")).Textf(" %s/META/update_engine_config.txt", targetFilesDir.String()) |
| 634 | if a.getFsInfos(ctx)["system"].ErofsCompressHints != nil { |
| 635 | builder.Command().Textf("cp").Input(a.getFsInfos(ctx)["system"].ErofsCompressHints).Textf(" %s/META/erofs_default_compress_hints.txt", targetFilesDir.String()) |
| 636 | } |
| 637 | // ab_partitions.txt |
| 638 | abPartitionsSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_partitions) |
| 639 | abPartitionsSortedString := proptools.ShellEscape(strings.Join(abPartitionsSorted, "\\n")) |
| 640 | builder.Command().Textf("echo -e").Flag(abPartitionsSortedString).Textf(" > %s/META/ab_partitions.txt", targetFilesDir.String()) |
Spandan Das | 35b7874 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 641 | // otakeys.txt |
| 642 | abOtaKeysSorted := android.SortedUniqueStrings(a.deviceProps.Ab_ota_keys) |
| 643 | abOtaKeysSortedString := proptools.ShellEscape(strings.Join(abOtaKeysSorted, "\\n")) |
| 644 | builder.Command().Textf("echo -e").Flag(abOtaKeysSortedString).Textf(" > %s/META/otakeys.txt", targetFilesDir.String()) |
Spandan Das | 0094807 | 2025-02-12 19:36:03 +0000 | [diff] [blame] | 645 | // postinstall_config.txt |
| 646 | abOtaPostInstallConfigString := proptools.ShellEscape(strings.Join(a.deviceProps.Ab_ota_postinstall_config, "\\n")) |
| 647 | builder.Command().Textf("echo -e").Flag(abOtaPostInstallConfigString).Textf(" > %s/META/postinstall_config.txt", targetFilesDir.String()) |
Spandan Das | f12ff9b | 2025-02-12 22:27:43 +0000 | [diff] [blame] | 648 | // selinuxfc |
| 649 | if a.getFsInfos(ctx)["system"].SelinuxFc != nil { |
| 650 | builder.Command().Textf("cp").Input(a.getFsInfos(ctx)["system"].SelinuxFc).Textf(" %s/META/file_contexts.bin", targetFilesDir.String()) |
| 651 | } |
Spandan Das | d71af18 | 2025-02-12 18:03:29 +0000 | [diff] [blame] | 652 | } |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 653 | // Copy $partition_filesystem_config.txt |
| 654 | fsInfos := a.getFsInfos(ctx) |
| 655 | for _, partition := range android.SortedKeys(fsInfos) { |
| 656 | if fsInfos[partition].FilesystemConfig == nil { |
| 657 | continue |
| 658 | } |
| 659 | if android.InList(partition, []string{"userdata"}) { |
| 660 | continue |
| 661 | } |
Spandan Das | 853a7a4 | 2025-02-27 07:44:51 +0000 | [diff] [blame] | 662 | if partition != "vendor_ramdisk" { |
| 663 | // vendor_ramdisk will be handled separately. |
| 664 | builder.Command().Textf("cp").Input(fsInfos[partition].FilesystemConfig).Textf(" %s/META/%s", targetFilesDir.String(), a.filesystemConfigNameForTargetFiles(partition)) |
| 665 | } |
Spandan Das | 54af357 | 2025-02-27 07:42:08 +0000 | [diff] [blame] | 666 | if partition == "ramdisk" { |
| 667 | // Create an additional copy at boot_filesystem_config.txt |
| 668 | builder.Command().Textf("cp").Input(fsInfos[partition].FilesystemConfig).Textf(" %s/META/boot_filesystem_config.txt", targetFilesDir.String()) |
| 669 | } |
Spandan Das | 853a7a4 | 2025-02-27 07:44:51 +0000 | [diff] [blame] | 670 | if partition == "system" { |
| 671 | // Create root_filesystem_config from the assembled ROOT/ intermediates directory |
Spandan Das | e06dd11 | 2025-03-05 01:29:04 +0000 | [diff] [blame] | 672 | a.generateFilesystemConfigForTargetFiles(ctx, builder, a.rootDirForFsConfigTimestamp, targetFilesDir.String(), a.rootDirForFsConfig, "root_filesystem_config.txt") |
Spandan Das | 853a7a4 | 2025-02-27 07:44:51 +0000 | [diff] [blame] | 673 | } |
| 674 | if partition == "vendor_ramdisk" { |
| 675 | // Create vendor_boot_filesystem_config from the assembled VENDOR_BOOT/RAMDISK intermediates directory |
Spandan Das | f7b7cc3 | 2025-03-07 23:09:29 +0000 | [diff] [blame] | 676 | vendorRamdiskStagingDir := targetFilesDir.String() + "/VENDOR_BOOT/RAMDISK" |
| 677 | vendorRamdiskFsConfigOut := targetFilesDir.String() + "/META/vendor_boot_filesystem_config.txt" |
| 678 | fsConfigBin := ctx.Config().HostToolPath(ctx, "fs_config") |
| 679 | builder.Command().Textf( |
| 680 | `(cd %s; find . -type d | sed 's,$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,,' | %s -C -D %s -R \"\" > %s`, |
| 681 | vendorRamdiskStagingDir, fsConfigBin, vendorRamdiskStagingDir, vendorRamdiskFsConfigOut). |
| 682 | Implicit(fsConfigBin) |
Spandan Das | 853a7a4 | 2025-02-27 07:44:51 +0000 | [diff] [blame] | 683 | } |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 684 | } |
Spandan Das | 75955b1 | 2025-02-13 22:12:52 +0000 | [diff] [blame] | 685 | // Copy ramdisk_node_list |
Spandan Das | 37240d9 | 2025-02-14 00:18:41 +0000 | [diff] [blame] | 686 | if ramdiskNodeList := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Ramdisk_node_list)); ramdiskNodeList != nil { |
| 687 | builder.Command().Textf("cp").Input(ramdiskNodeList).Textf(" %s/META/", targetFilesDir.String()) |
| 688 | } |
| 689 | // Copy releasetools.py |
| 690 | if releaseTools := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Releasetools_extension)); releaseTools != nil { |
| 691 | builder.Command().Textf("cp").Input(releaseTools).Textf(" %s/META/", targetFilesDir.String()) |
| 692 | } |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 693 | // apexkeys.txt |
| 694 | var installedApexKeys []android.Path |
| 695 | for _, installedModule := range allInstalledModules { |
| 696 | if info, ok := android.OtherModuleProvider(ctx, installedModule, ApexKeyPathInfoProvider); ok { |
| 697 | installedApexKeys = append(installedApexKeys, info.ApexKeyPath) |
| 698 | } |
| 699 | } |
| 700 | installedApexKeys = android.SortedUniquePaths(installedApexKeys) // Sort by keypath to match make |
| 701 | builder.Command().Text("cat").Inputs(installedApexKeys).Textf(" >> %s/META/apexkeys.txt", targetFilesDir.String()) |
Spandan Das | 38afe71 | 2025-03-05 23:27:55 +0000 | [diff] [blame] | 702 | // apkcerts.txt |
| 703 | builder.Command().Textf("cp").Input(a.apkCertsInfo).Textf(" %s/META/", targetFilesDir.String()) |
| 704 | |
Spandan Das | 3dfa17f | 2025-02-28 09:48:28 +0000 | [diff] [blame] | 705 | // Copy fastboot-info.txt |
| 706 | if fastbootInfo := android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.FastbootInfo)); fastbootInfo != nil { |
| 707 | // TODO (b/399788523): Autogenerate fastboot-info.txt if there is no source fastboot-info.txt |
| 708 | // https://cs.android.com/android/_/android/platform/build/+/80b9546f8f69e78b8fe1870e0e745d70fc18dfcd:core/Makefile;l=5831-5893;drc=077490384423dff9eac954da5c001c6f0be3fa6e;bpv=0;bpt=0 |
| 709 | builder.Command().Textf("cp").Input(fastbootInfo).Textf(" %s/META/fastboot-info.txt", targetFilesDir.String()) |
| 710 | } |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 711 | |
Spandan Das | c09353c | 2025-03-04 00:11:21 +0000 | [diff] [blame] | 712 | // kernel_configs.txt and kernel_version.txt |
| 713 | if a.kernelConfig != nil { |
| 714 | builder.Command().Textf("cp").Input(a.kernelConfig).Textf(" %s/META/", targetFilesDir.String()) |
| 715 | } |
| 716 | if a.kernelVersion != nil { |
| 717 | builder.Command().Textf("cp").Input(a.kernelVersion).Textf(" %s/META/", targetFilesDir.String()) |
| 718 | } |
Spandan Das | 447a0ab | 2025-03-04 23:10:19 +0000 | [diff] [blame] | 719 | // misc_info.txt |
| 720 | if a.miscInfo != nil { |
| 721 | builder.Command().Textf("cp").Input(a.miscInfo).Textf(" %s/META/", targetFilesDir.String()) |
| 722 | } |
Spandan Das | 4100dd0 | 2025-03-04 23:14:34 +0000 | [diff] [blame] | 723 | // apex_info.pb, care_map.pb, vbmeta_digest.txt |
| 724 | a.addImgToTargetFiles(ctx, builder, targetFilesDir.String()) |
Spandan Das | c09353c | 2025-03-04 00:11:21 +0000 | [diff] [blame] | 725 | |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 726 | if a.partitionProps.Super_partition_name != nil { |
| 727 | superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) |
| 728 | if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok { |
| 729 | // dynamic_partitions_info.txt |
| 730 | // TODO (b/390192334): Add `building_super_empty_partition=true` |
| 731 | builder.Command().Text("cp").Input(info.DynamicPartitionsInfo).Textf(" %s/META/", targetFilesDir.String()) |
| 732 | } else { |
| 733 | ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name()) |
| 734 | } |
| 735 | } |
| 736 | |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Spandan Das | 447a0ab | 2025-03-04 23:10:19 +0000 | [diff] [blame] | 739 | // A partial implementation of make's $PRODUCT_OUT/misc_info.txt |
| 740 | // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=5894?q=misc_info.txt%20f:build%2Fmake%2Fcore%2FMakefile&ss=android%2Fplatform%2Fsuperproject%2Fmain |
| 741 | // This file is subsequently used by add_img_to_target_files to create additioanl metadata files like apex_info.pb |
| 742 | // TODO (b/399788119): Complete the migration of misc_info.txt |
| 743 | func (a *androidDevice) addMiscInfo(ctx android.ModuleContext) android.Path { |
| 744 | builder := android.NewRuleBuilder(pctx, ctx) |
| 745 | miscInfo := android.PathForModuleOut(ctx, "misc_info.txt") |
| 746 | builder.Command(). |
| 747 | Textf("rm -f %s", miscInfo). |
| 748 | Textf("&& echo recovery_api_version=%s >> %s", ctx.Config().VendorConfig("recovery").String("recovery_api_version"), miscInfo). |
| 749 | Textf("&& echo fstab_version=%s >> %s", ctx.Config().VendorConfig("recovery").String("recovery_fstab_version"), miscInfo). |
| 750 | ImplicitOutput(miscInfo) |
| 751 | |
| 752 | if a.partitionProps.Recovery_partition_name == nil { |
| 753 | builder.Command().Textf("echo no_recovery=true >> %s", miscInfo) |
| 754 | } |
| 755 | fsInfos := a.getFsInfos(ctx) |
| 756 | for _, partition := range android.SortedKeys(fsInfos) { |
| 757 | if fsInfos[partition].UseAvb { |
| 758 | builder.Command().Textf("echo 'avb_%s_hashtree_enable=true' >> %s", partition, miscInfo) |
| 759 | } |
| 760 | } |
| 761 | if len(a.partitionProps.Vbmeta_partitions) > 0 { |
| 762 | builder.Command(). |
| 763 | Textf("echo avb_enable=true >> %s", miscInfo). |
| 764 | Textf("&& echo avb_building_vbmeta_image=true >> %s", miscInfo). |
| 765 | Textf("&& echo avb_avbtool=avbtool >> %s", miscInfo) |
| 766 | } |
| 767 | if a.partitionProps.Boot_partition_name != nil { |
| 768 | builder.Command().Textf("echo boot_images=boot.img >> %s", miscInfo) |
| 769 | } |
| 770 | |
| 771 | builder.Build("misc_info", "Building misc_info") |
| 772 | |
| 773 | return miscInfo |
| 774 | } |
| 775 | |
Spandan Das | 4100dd0 | 2025-03-04 23:14:34 +0000 | [diff] [blame] | 776 | // addImgToTargetFiles invokes `add_img_to_target_files` and creates the following files in META/ |
| 777 | // - apex_info.pb |
| 778 | // - care_map.pb |
| 779 | // - vbmeta_digest.txt |
| 780 | func (a *androidDevice) addImgToTargetFiles(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir string) { |
| 781 | mkbootimg := ctx.Config().HostToolPath(ctx, "mkbootimg") |
| 782 | builder.Command(). |
| 783 | Textf("PATH=%s:$PATH", ctx.Config().HostToolDir()). |
| 784 | Textf("MKBOOTIMG=%s", mkbootimg). |
| 785 | Implicit(mkbootimg). |
| 786 | BuiltTool("add_img_to_target_files"). |
| 787 | Flag("-a -v -p"). |
| 788 | Flag(ctx.Config().HostToolDir()). |
| 789 | Text(targetFilesDir) |
| 790 | } |
| 791 | |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 792 | type ApexKeyPathInfo struct { |
| 793 | ApexKeyPath android.Path |
| 794 | } |
| 795 | |
| 796 | var ApexKeyPathInfoProvider = blueprint.NewProvider[ApexKeyPathInfo]() |
| 797 | |
Spandan Das | e06dd11 | 2025-03-05 01:29:04 +0000 | [diff] [blame] | 798 | func (a *androidDevice) generateFilesystemConfigForTargetFiles(ctx android.ModuleContext, builder *android.RuleBuilder, stagingDirTimestamp android.Path, targetFilesDir, stagingDir, filename string) { |
Spandan Das | 853a7a4 | 2025-02-27 07:44:51 +0000 | [diff] [blame] | 799 | fsConfigOut := android.PathForModuleOut(ctx, filename) |
| 800 | ctx.Build(pctx, android.BuildParams{ |
Spandan Das | e06dd11 | 2025-03-05 01:29:04 +0000 | [diff] [blame] | 801 | Rule: fsConfigRule, |
| 802 | Implicit: stagingDirTimestamp, |
| 803 | Output: fsConfigOut, |
Spandan Das | 853a7a4 | 2025-02-27 07:44:51 +0000 | [diff] [blame] | 804 | Args: map[string]string{ |
| 805 | "rootDir": stagingDir, |
| 806 | "prefix": "", |
| 807 | }, |
| 808 | }) |
| 809 | builder.Command().Textf("cp").Input(fsConfigOut).Textf(" %s/META/", targetFilesDir) |
| 810 | } |
| 811 | |
Spandan Das | dd262fb | 2025-02-13 00:15:59 +0000 | [diff] [blame] | 812 | // Filenames for the partition specific fs_config files. |
| 813 | // Hardcode the ramdisk files to their boot image prefix |
| 814 | func (a *androidDevice) filesystemConfigNameForTargetFiles(partition string) string { |
| 815 | name := partition + "_filesystem_config.txt" |
| 816 | if partition == "system" { |
| 817 | name = "filesystem_config.txt" |
| 818 | } else if partition == "ramdisk" { |
| 819 | name = "init_boot_filesystem_config.txt" |
| 820 | } |
| 821 | return name |
Spandan Das | 29d4488 | 2025-01-15 21:12:36 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 824 | func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 825 | fsMod := ctx.GetDirectDepProxyWithTag(depName, filesystemDepTag) |
Cole Faust | 4408041 | 2024-12-20 14:17:07 -0800 | [diff] [blame] | 826 | fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider) |
| 827 | if !ok { |
| 828 | ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName) |
| 829 | } |
| 830 | return fsInfo |
Jihoon Kang | f2c5398 | 2024-10-09 17:32:52 +0000 | [diff] [blame] | 831 | } |
Jihoon Kang | 0a6315b | 2025-01-30 01:14:49 +0000 | [diff] [blame] | 832 | |
| 833 | func (a *androidDevice) setVbmetaPhonyTargets(ctx android.ModuleContext) { |
| 834 | if !proptools.Bool(a.deviceProps.Main_device) { |
| 835 | return |
| 836 | } |
| 837 | |
| 838 | if !ctx.Config().KatiEnabled() { |
| 839 | for _, vbmetaPartitionName := range a.partitionProps.Vbmeta_partitions { |
| 840 | img := ctx.GetDirectDepProxyWithTag(vbmetaPartitionName, filesystemDepTag) |
| 841 | if provider, ok := android.OtherModuleProvider(ctx, img, vbmetaPartitionProvider); ok { |
| 842 | // make generates `vbmetasystemimage` phony target instead of `vbmeta_systemimage` phony target. |
| 843 | partitionName := strings.ReplaceAll(provider.Name, "_", "") |
| 844 | ctx.Phony(fmt.Sprintf("%simage", partitionName), provider.Output) |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | } |
Cole Faust | 21c1146 | 2025-03-03 14:13:17 -0800 | [diff] [blame] | 849 | |
| 850 | func (a *androidDevice) getKernel(ctx android.ModuleContext) android.Path { |
| 851 | if a.partitionProps.Boot_partition_name != nil { |
| 852 | bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag) |
| 853 | bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider) |
| 854 | return bootImgInfo.Kernel |
| 855 | } |
| 856 | return nil |
| 857 | } |
| 858 | |
| 859 | // Gets the kernel version and configs from the actual kernel file itself. Roughly equivalent to |
| 860 | // this make code: https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=5443;drc=c0b66fc59de069e06ce0ffd703d4d21613be30c6 |
| 861 | // However, it is a simplified version of that make code. Differences include: |
| 862 | // - Not handling BOARD_KERNEL_CONFIG_FILE because BOARD_KERNEL_CONFIG_FILE was never used. |
| 863 | // - Not unpacking the bootimage, as we should be able to just always export the kernel directly |
| 864 | // in the BootimgInfo. We don't currently support prebuilt boot images, but even if we add that |
| 865 | // in the future, it can be done in a prebuilt_bootimage module type that still exports the same |
| 866 | // BootimgInfo. |
| 867 | // - We don't print a warning and output '<unknown-kernel>' to kernel_version_for_uffd_gc.txt |
| 868 | // because we expect the kernel to always be present. If it's not, we will get an error that |
| 869 | // kernel_version_for_uffd_gc.txt doesn't exist. This may require later tweaking to the |
| 870 | // dexpreopt rules so that they don't attempt to access that file in builds that don't have |
| 871 | // a kernel. |
| 872 | func (a *androidDevice) extractKernelVersionAndConfigs(ctx android.ModuleContext) (android.Path, android.Path) { |
| 873 | kernel := a.getKernel(ctx) |
| 874 | // If there's no kernel, don't create kernel version / kernel config files. Reverse dependencies |
| 875 | // on those files have to account for this, for example by disabling dexpreopt in unbundled |
| 876 | // builds. |
| 877 | if kernel == nil { |
| 878 | return nil, nil |
| 879 | } |
| 880 | |
| 881 | lz4tool := ctx.Config().HostToolPath(ctx, "lz4") |
| 882 | |
| 883 | extractedVersionFile := android.PathForModuleOut(ctx, "kernel_version.txt") |
| 884 | extractedConfigsFile := android.PathForModuleOut(ctx, "kernel_configs.txt") |
| 885 | builder := android.NewRuleBuilder(pctx, ctx) |
| 886 | builder.Command().BuiltTool("extract_kernel"). |
| 887 | Flag("--tools lz4:"+lz4tool.String()).Implicit(lz4tool). |
| 888 | FlagWithInput("--input ", kernel). |
| 889 | FlagWithOutput("--output-release ", extractedVersionFile). |
Spandan Das | 2dee3f7 | 2025-03-07 18:32:06 +0000 | [diff] [blame] | 890 | FlagWithOutput("--output-configs ", extractedConfigsFile). |
| 891 | Textf(`&& printf "\n" >> %s`, extractedVersionFile) |
Cole Faust | 21c1146 | 2025-03-03 14:13:17 -0800 | [diff] [blame] | 892 | |
| 893 | if specifiedVersion := proptools.String(a.deviceProps.Kernel_version); specifiedVersion != "" { |
| 894 | specifiedVersionFile := android.PathForModuleOut(ctx, "specified_kernel_version.txt") |
Spandan Das | 2dee3f7 | 2025-03-07 18:32:06 +0000 | [diff] [blame] | 895 | android.WriteFileRule(ctx, specifiedVersionFile, specifiedVersion) |
Cole Faust | 21c1146 | 2025-03-03 14:13:17 -0800 | [diff] [blame] | 896 | builder.Command().Text("diff -q"). |
| 897 | Input(specifiedVersionFile). |
| 898 | Input(extractedVersionFile). |
| 899 | Textf(`|| (echo "Specified kernel version '$(cat %s)' does not match actual kernel version '$(cat %s)'"; exit 1)`, specifiedVersionFile, extractedVersionFile) |
| 900 | } |
| 901 | |
| 902 | builder.Build("extract_kernel_info", "Extract kernel version and configs") |
| 903 | |
| 904 | if proptools.Bool(a.deviceProps.Main_device) && !ctx.Config().KatiEnabled() { |
| 905 | if ctx.Config().EnableUffdGc() == "default" { |
| 906 | kernelVersionFile := android.PathForOutput(ctx, "dexpreopt/kernel_version_for_uffd_gc.txt") |
| 907 | ctx.Build(pctx, android.BuildParams{ |
| 908 | Rule: android.CpIfChanged, |
| 909 | Input: extractedVersionFile, |
| 910 | Output: kernelVersionFile, |
| 911 | }) |
| 912 | } |
| 913 | |
| 914 | ctx.DistForGoal("droid_targets", extractedVersionFile) |
| 915 | } |
| 916 | |
| 917 | return extractedVersionFile, extractedConfigsFile |
| 918 | } |
Spandan Das | 38afe71 | 2025-03-05 23:27:55 +0000 | [diff] [blame] | 919 | |
| 920 | func (a *androidDevice) buildApkCertsInfo(ctx android.ModuleContext, allInstalledModules []android.Module) android.Path { |
| 921 | // TODO (spandandas): Add compressed |
| 922 | formatLine := func(cert java.Certificate, name, partition string) string { |
| 923 | pem := cert.AndroidMkString() |
| 924 | var key string |
| 925 | if cert.Key == nil { |
| 926 | key = "" |
| 927 | } else { |
| 928 | key = cert.Key.String() |
| 929 | } |
| 930 | return fmt.Sprintf(`name="%s" certificate="%s" private_key="%s" partition="%s"`, name, pem, key, partition) |
| 931 | } |
| 932 | |
| 933 | apkCerts := []string{} |
| 934 | for _, installedModule := range allInstalledModules { |
| 935 | partition := "" |
| 936 | if commonInfo, ok := android.OtherModuleProvider(ctx, installedModule, android.CommonModuleInfoKey); ok { |
| 937 | partition = commonInfo.PartitionTag |
| 938 | } else { |
| 939 | ctx.ModuleErrorf("%s does not set CommonModuleInfoKey", installedModule.Name()) |
| 940 | } |
| 941 | if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfoProvider); ok { |
| 942 | apkCerts = append(apkCerts, formatLine(info.Certificate, info.InstallApkName+".apk", partition)) |
| 943 | } else if info, ok := android.OtherModuleProvider(ctx, installedModule, java.AppInfosProvider); ok { |
| 944 | for _, certInfo := range info { |
Spandan Das | 0284ed4 | 2025-03-08 00:43:08 +0000 | [diff] [blame^] | 945 | // Partition information of apk-in-apex is not exported to the legacy Make packaging system. |
| 946 | // Hardcode the partition to "system" |
| 947 | apkCerts = append(apkCerts, formatLine(certInfo.Certificate, certInfo.InstallApkName+".apk", "system")) |
Spandan Das | 38afe71 | 2025-03-05 23:27:55 +0000 | [diff] [blame] | 948 | } |
| 949 | } else if info, ok := android.OtherModuleProvider(ctx, installedModule, java.RuntimeResourceOverlayInfoProvider); ok { |
| 950 | apkCerts = append(apkCerts, formatLine(info.Certificate, info.OutputFile.Base(), partition)) |
| 951 | } |
| 952 | } |
| 953 | slices.Sort(apkCerts) // sort by name |
| 954 | fsInfos := a.getFsInfos(ctx) |
| 955 | if fsInfos["system"].HasFsverity { |
| 956 | defaultPem, defaultKey := ctx.Config().DefaultAppCertificate(ctx) |
| 957 | apkCerts = append(apkCerts, formatLine(java.Certificate{Pem: defaultPem, Key: defaultKey}, "BuildManifest.apk", "system")) |
| 958 | if info, ok := fsInfos["system_ext"]; ok && info.HasFsverity { |
| 959 | apkCerts = append(apkCerts, formatLine(java.Certificate{Pem: defaultPem, Key: defaultKey}, "BuildManifestSystemExt.apk", "system_ext")) |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | apkCertsInfo := android.PathForModuleOut(ctx, "apkcerts.txt") |
| 964 | android.WriteFileRuleVerbatim(ctx, apkCertsInfo, strings.Join(apkCerts, "\n")+"\n") |
| 965 | return apkCertsInfo |
| 966 | } |