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