blob: eb2e0367ad7dc18955a64aecd650a3b0fb3c9e7b [file] [log] [blame]
Jihoon Kangf2c53982024-10-09 17:32:52 +00001// 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
15package filesystem
16
17import (
Spandan Das258c08f2025-01-08 23:30:45 +000018 "strings"
Cole Faustb55a41c2025-01-09 16:53:58 -080019 "sync/atomic"
Spandan Das258c08f2025-01-08 23:30:45 +000020
Jihoon Kangf2c53982024-10-09 17:32:52 +000021 "android/soong/android"
22
23 "github.com/google/blueprint"
24 "github.com/google/blueprint/proptools"
25)
26
27type PartitionNameProperties struct {
Cole Faust2bdc5e52025-01-10 10:29:36 -080028 // Name of the super partition filesystem module
29 Super_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000030 // Name of the boot partition filesystem module
Jihoon Kangf2c53982024-10-09 17:32:52 +000031 Boot_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000032 // Name of the vendor boot partition filesystem module
33 Vendor_boot_partition_name *string
34 // Name of the init boot partition filesystem module
35 Init_boot_partition_name *string
36 // Name of the system partition filesystem module
Jihoon Kangf2c53982024-10-09 17:32:52 +000037 System_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000038 // Name of the system_ext partition filesystem module
Jihoon Kangf2c53982024-10-09 17:32:52 +000039 System_ext_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000040 // Name of the product partition filesystem module
Jihoon Kangf2c53982024-10-09 17:32:52 +000041 Product_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000042 // Name of the vendor partition filesystem module
Jihoon Kangf2c53982024-10-09 17:32:52 +000043 Vendor_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000044 // Name of the odm partition filesystem module
Spandan Dasc5717162024-11-01 18:33:57 +000045 Odm_partition_name *string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000046 // Name of the recovery partition filesystem module
47 Recovery_partition_name *string
Cole Faust3552eb62024-11-06 18:07:26 -080048 // The vbmeta partition and its "chained" partitions
49 Vbmeta_partitions []string
Jihoon Kange7e3ec82025-01-02 21:29:14 +000050 // Name of the userdata partition filesystem module
mrziwang23ba8762024-11-07 16:21:53 -080051 Userdata_partition_name *string
Spandan Dasa0394002025-01-07 18:38:34 +000052 // Name of the system_dlkm partition filesystem module
53 System_dlkm_partition_name *string
54 // Name of the vendor_dlkm partition filesystem module
55 Vendor_dlkm_partition_name *string
56 // Name of the odm_dlkm partition filesystem module
57 Odm_dlkm_partition_name *string
Jihoon Kangf2c53982024-10-09 17:32:52 +000058}
59
Jihoon Kang3be17162025-01-09 20:51:54 +000060type DeviceProperties struct {
61 // Path to the prebuilt bootloader that would be copied to PRODUCT_OUT
62 Bootloader *string `android:"path"`
Spandan Dase51ff952025-01-09 18:11:59 +000063 // Path to android-info.txt file containing board specific info.
64 Android_info *string `android:"path"`
Cole Faust11fda332025-01-14 16:47:19 -080065 // If this is the "main" android_device target for the build, i.e. the one that gets built
66 // when running a plain `m` command. Currently, this is the autogenerated android_device module
67 // in soong-only builds, but in the future when we check in android_device modules, the main
68 // one will be determined based on the lunch product. TODO: Figure out how to make this
69 // blueprint:"mutated" and still set it from filesystem_creator
70 Main_device *bool
Spandan Das29d44882025-01-15 21:12:36 +000071
72 Ab_ota_updater *bool
Jihoon Kang3be17162025-01-09 20:51:54 +000073}
74
Jihoon Kangf2c53982024-10-09 17:32:52 +000075type androidDevice struct {
76 android.ModuleBase
77
78 partitionProps PartitionNameProperties
Jihoon Kang3be17162025-01-09 20:51:54 +000079
80 deviceProps DeviceProperties
Jihoon Kangf2c53982024-10-09 17:32:52 +000081}
82
83func AndroidDeviceFactory() android.Module {
84 module := &androidDevice{}
Jihoon Kang3be17162025-01-09 20:51:54 +000085 module.AddProperties(&module.partitionProps, &module.deviceProps)
Cole Faust341d5f12025-01-07 15:32:38 -080086 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibFirst)
Jihoon Kangf2c53982024-10-09 17:32:52 +000087 return module
88}
89
Cole Faust11fda332025-01-14 16:47:19 -080090var numMainAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices")
Cole Faustb55a41c2025-01-09 16:53:58 -080091
Jihoon Kangf2c53982024-10-09 17:32:52 +000092type partitionDepTagType struct {
93 blueprint.BaseDependencyTag
94}
95
Cole Faust2bdc5e52025-01-10 10:29:36 -080096type superPartitionDepTagType struct {
97 blueprint.BaseDependencyTag
98}
Spandan Das29d44882025-01-15 21:12:36 +000099type targetFilesMetadataDepTagType struct {
100 blueprint.BaseDependencyTag
101}
Cole Faust2bdc5e52025-01-10 10:29:36 -0800102
103var superPartitionDepTag superPartitionDepTagType
Jihoon Kangf2c53982024-10-09 17:32:52 +0000104var filesystemDepTag partitionDepTagType
Spandan Das29d44882025-01-15 21:12:36 +0000105var targetFilesMetadataDepTag targetFilesMetadataDepTagType
Jihoon Kangf2c53982024-10-09 17:32:52 +0000106
107func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
108 addDependencyIfDefined := func(dep *string) {
109 if dep != nil {
Cole Faust341d5f12025-01-07 15:32:38 -0800110 ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep))
Jihoon Kangf2c53982024-10-09 17:32:52 +0000111 }
112 }
113
Cole Faust2bdc5e52025-01-10 10:29:36 -0800114 if a.partitionProps.Super_partition_name != nil {
115 ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name)
116 }
Jihoon Kangf2c53982024-10-09 17:32:52 +0000117 addDependencyIfDefined(a.partitionProps.Boot_partition_name)
Jihoon Kang9e087002025-01-08 19:12:23 +0000118 addDependencyIfDefined(a.partitionProps.Init_boot_partition_name)
Spandan Dasef200ac2025-01-08 01:42:45 +0000119 addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name)
Jihoon Kangf2c53982024-10-09 17:32:52 +0000120 addDependencyIfDefined(a.partitionProps.System_partition_name)
121 addDependencyIfDefined(a.partitionProps.System_ext_partition_name)
122 addDependencyIfDefined(a.partitionProps.Product_partition_name)
123 addDependencyIfDefined(a.partitionProps.Vendor_partition_name)
Spandan Dasc5717162024-11-01 18:33:57 +0000124 addDependencyIfDefined(a.partitionProps.Odm_partition_name)
mrziwang23ba8762024-11-07 16:21:53 -0800125 addDependencyIfDefined(a.partitionProps.Userdata_partition_name)
Spandan Dasa0394002025-01-07 18:38:34 +0000126 addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name)
127 addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name)
128 addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name)
Spandan Dasef200ac2025-01-08 01:42:45 +0000129 addDependencyIfDefined(a.partitionProps.Recovery_partition_name)
Cole Faust3552eb62024-11-06 18:07:26 -0800130 for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions {
131 ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition)
132 }
Spandan Das29d44882025-01-15 21:12:36 +0000133 a.addDepsForTargetFilesMetadata(ctx)
134}
135
136func (a *androidDevice) addDepsForTargetFilesMetadata(ctx android.BottomUpMutatorContext) {
137 ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), targetFilesMetadataDepTag, "liblz4") // host variant
Jihoon Kangf2c53982024-10-09 17:32:52 +0000138}
139
Cole Faust11fda332025-01-14 16:47:19 -0800140func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) {
141 if proptools.Bool(a.deviceProps.Main_device) {
142 numMainAndroidDevices := ctx.Config().Once(numMainAndroidDevicesOnceKey, func() interface{} {
143 return &atomic.Int32{}
144 }).(*atomic.Int32)
145 total := numMainAndroidDevices.Add(1)
146 if total > 1 {
147 // There should only be 1 main android_device module. That one will be
148 // made the default thing to build in soong-only builds.
149 ctx.ModuleErrorf("There cannot be more than 1 main android_device module")
150 }
Jihoon Kang3be17162025-01-09 20:51:54 +0000151 }
152
Cole Faust44080412024-12-20 14:17:07 -0800153 a.buildTargetFilesZip(ctx)
mrziwang2fd33a72025-01-08 12:22:08 -0800154 var deps []android.Path
Cole Faust2bdc5e52025-01-10 10:29:36 -0800155 if proptools.String(a.partitionProps.Super_partition_name) != "" {
Cole Faust19eb09d2025-01-14 13:27:00 -0800156 superImage := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800157 if info, ok := android.OtherModuleProvider(ctx, superImage, SuperImageProvider); ok {
158 assertUnset := func(prop *string, propName string) {
159 if prop != nil && *prop != "" {
160 ctx.PropertyErrorf(propName, "Cannot be set because it's already part of the super image")
161 }
162 }
163 for _, subPartitionType := range android.SortedKeys(info.SubImageInfo) {
164 switch subPartitionType {
165 case "system":
166 assertUnset(a.partitionProps.System_partition_name, "system_partition_name")
167 case "system_ext":
168 assertUnset(a.partitionProps.System_ext_partition_name, "system_ext_partition_name")
169 case "system_dlkm":
170 assertUnset(a.partitionProps.System_dlkm_partition_name, "system_dlkm_partition_name")
171 case "system_other":
172 // TODO
173 case "product":
174 assertUnset(a.partitionProps.Product_partition_name, "product_partition_name")
175 case "vendor":
176 assertUnset(a.partitionProps.Vendor_partition_name, "vendor_partition_name")
177 case "vendor_dlkm":
178 assertUnset(a.partitionProps.Vendor_dlkm_partition_name, "vendor_dlkm_partition_name")
179 case "odm":
180 assertUnset(a.partitionProps.Odm_partition_name, "odm_partition_name")
181 case "odm_dlkm":
182 assertUnset(a.partitionProps.Odm_dlkm_partition_name, "odm_dlkm_partition_name")
183 default:
184 ctx.ModuleErrorf("Unsupported sub-partition of super partition: %q", subPartitionType)
185 }
186 }
187
188 deps = append(deps, info.SuperImage)
189 } else {
190 ctx.ModuleErrorf("Expected super image dep to provide SuperImageProvider")
191 }
192 }
Cole Faust19eb09d2025-01-14 13:27:00 -0800193 ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(m android.ModuleProxy) {
mrziwang2fd33a72025-01-08 12:22:08 -0800194 imageOutput, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider)
195 if !ok {
196 ctx.ModuleErrorf("Partition module %s doesn't set OutputfilesProvider", m.Name())
197 }
198 if len(imageOutput.DefaultOutputFiles) != 1 {
199 ctx.ModuleErrorf("Partition module %s should provide exact 1 output file", m.Name())
200 }
201 deps = append(deps, imageOutput.DefaultOutputFiles[0])
202 })
Jihoon Kang3be17162025-01-09 20:51:54 +0000203
Cole Faustb55a41c2025-01-09 16:53:58 -0800204 allImagesStamp := android.PathForModuleOut(ctx, "all_images_stamp")
Cole Faust11fda332025-01-14 16:47:19 -0800205 var validations android.Paths
206 if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) {
Cole Faustb55a41c2025-01-09 16:53:58 -0800207 // In soong-only builds, build this module by default.
208 // This is the analogue to this make code:
209 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/main.mk;l=1396;drc=6595459cdd8164a6008335f6372c9f97b9094060
210 ctx.Phony("droidcore-unbundled", allImagesStamp)
Cole Faust11fda332025-01-14 16:47:19 -0800211
212 validations = append(validations, a.copyFilesToProductOutForSoongOnly(ctx))
Cole Faustb55a41c2025-01-09 16:53:58 -0800213 }
Cole Faust11fda332025-01-14 16:47:19 -0800214
215 ctx.Build(pctx, android.BuildParams{
216 Rule: android.Touch,
217 Output: allImagesStamp,
218 Implicits: deps,
219 Validations: validations,
220 })
221
222 // Checkbuilding it causes soong to make a phony, so you can say `m <module name>`
223 ctx.CheckbuildFile(allImagesStamp)
Cole Faust44080412024-12-20 14:17:07 -0800224}
Jihoon Kangf2c53982024-10-09 17:32:52 +0000225
Spandan Dasef775742025-01-13 22:17:40 +0000226// Helper structs for target_files.zip creation
Spandan Dasef200ac2025-01-08 01:42:45 +0000227type targetFilesZipCopy struct {
228 srcModule *string
229 destSubdir string
230}
231
Spandan Dasef775742025-01-13 22:17:40 +0000232type targetFilesystemZipCopy struct {
233 fsInfo FilesystemInfo
234 destSubdir string
235}
236
Cole Faust44080412024-12-20 14:17:07 -0800237func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext) {
238 targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir")
239 targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip")
240
241 builder := android.NewRuleBuilder(pctx, ctx)
242 builder.Command().Textf("rm -rf %s", targetFilesDir.String())
243 builder.Command().Textf("mkdir -p %s", targetFilesDir.String())
Spandan Dasef200ac2025-01-08 01:42:45 +0000244 toCopy := []targetFilesZipCopy{
245 targetFilesZipCopy{a.partitionProps.System_partition_name, "SYSTEM"},
246 targetFilesZipCopy{a.partitionProps.System_ext_partition_name, "SYSTEM_EXT"},
247 targetFilesZipCopy{a.partitionProps.Product_partition_name, "PRODUCT"},
248 targetFilesZipCopy{a.partitionProps.Vendor_partition_name, "VENDOR"},
249 targetFilesZipCopy{a.partitionProps.Odm_partition_name, "ODM"},
250 targetFilesZipCopy{a.partitionProps.System_dlkm_partition_name, "SYSTEM_DLKM"},
251 targetFilesZipCopy{a.partitionProps.Vendor_dlkm_partition_name, "VENDOR_DLKM"},
252 targetFilesZipCopy{a.partitionProps.Odm_dlkm_partition_name, "ODM_DLKM"},
253 targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"},
254 targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"},
255 targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"},
Spandan Das25649f52025-01-07 18:09:22 +0000256 }
Spandan Dasef200ac2025-01-08 01:42:45 +0000257 // TODO: Handle cases where recovery files are copied to BOOT/ or RECOVERY/
258 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=6211-6219?q=core%2FMakefile&ss=android%2Fplatform%2Fsuperproject%2Fmain
259 if ctx.DeviceConfig().BoardMoveRecoveryResourcesToVendorBoot() {
260 toCopy = append(toCopy, targetFilesZipCopy{a.partitionProps.Recovery_partition_name, "VENDOR_BOOT/RAMDISK"})
261 }
262
Spandan Dasef775742025-01-13 22:17:40 +0000263 filesystemsToCopy := []targetFilesystemZipCopy{}
Spandan Dasef200ac2025-01-08 01:42:45 +0000264 for _, zipCopy := range toCopy {
265 if zipCopy.srcModule == nil {
Spandan Das25649f52025-01-07 18:09:22 +0000266 continue
267 }
Spandan Dasef775742025-01-13 22:17:40 +0000268 filesystemsToCopy = append(
269 filesystemsToCopy,
270 targetFilesystemZipCopy{a.getFilesystemInfo(ctx, *zipCopy.srcModule), zipCopy.destSubdir},
271 )
272 }
273 // Get additional filesystems from super_partition dependency
274 if a.partitionProps.Super_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800275 superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
Spandan Dasef775742025-01-13 22:17:40 +0000276 if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
277 for _, partition := range android.SortedStringKeys(info.SubImageInfo) {
278 filesystemsToCopy = append(
279 filesystemsToCopy,
280 targetFilesystemZipCopy{info.SubImageInfo[partition], strings.ToUpper(partition)},
281 )
282 }
283 } else {
284 ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
285 }
286 }
287
288 for _, toCopy := range filesystemsToCopy {
289 rootDirString := toCopy.fsInfo.RootDir.String()
290 if toCopy.destSubdir == "SYSTEM" {
Spandan Dasef200ac2025-01-08 01:42:45 +0000291 rootDirString = rootDirString + "/system"
292 }
Spandan Dasef775742025-01-13 22:17:40 +0000293 builder.Command().Textf("mkdir -p %s/%s", targetFilesDir.String(), toCopy.destSubdir)
Cole Faust44080412024-12-20 14:17:07 -0800294 builder.Command().
295 BuiltTool("acp").
Spandan Dasef775742025-01-13 22:17:40 +0000296 Textf("-rd %s/. %s/%s", rootDirString, targetFilesDir, toCopy.destSubdir).
297 Implicit(toCopy.fsInfo.Output) // so that the staging dir is built
Spandan Dasef200ac2025-01-08 01:42:45 +0000298
Spandan Dasef775742025-01-13 22:17:40 +0000299 if toCopy.destSubdir == "SYSTEM" {
Spandan Das3ec6d062025-01-09 19:37:47 +0000300 // Create the ROOT partition in target_files.zip
Spandan Dasef775742025-01-13 22:17:40 +0000301 builder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s/ROOT", toCopy.fsInfo.RootDir, targetFilesDir.String())
Spandan Das3ec6d062025-01-09 19:37:47 +0000302 }
Cole Faust44080412024-12-20 14:17:07 -0800303 }
Spandan Das9b17df22025-01-08 23:30:45 +0000304 // Copy cmdline, kernel etc. files of boot images
Spandan Das258c08f2025-01-08 23:30:45 +0000305 if a.partitionProps.Vendor_boot_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800306 bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Vendor_boot_partition_name), filesystemDepTag)
Spandan Das258c08f2025-01-08 23:30:45 +0000307 bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
Spandan Das9b17df22025-01-08 23:30:45 +0000308 builder.Command().Textf("echo %s > %s/VENDOR_BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
309 builder.Command().Textf("echo %s > %s/VENDOR_BOOT/vendor_cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
310 if bootImgInfo.Dtb != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000311 builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_BOOT/dtb", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000312 }
Spandan Das23511372025-01-08 23:30:45 +0000313 if bootImgInfo.Bootconfig != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000314 builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/VENDOR_BOOT/vendor_bootconfig", targetFilesDir)
Spandan Das23511372025-01-08 23:30:45 +0000315 }
Spandan Das258c08f2025-01-08 23:30:45 +0000316 }
317 if a.partitionProps.Boot_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800318 bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag)
Spandan Das258c08f2025-01-08 23:30:45 +0000319 bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
Spandan Das9b17df22025-01-08 23:30:45 +0000320 builder.Command().Textf("echo %s > %s/BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
321 if bootImgInfo.Dtb != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000322 builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/BOOT/dtb", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000323 }
324 if bootImgInfo.Kernel != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000325 builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000326 // Even though kernel is not used to build vendor_boot, copy the kernel to VENDOR_BOOT to match the behavior of make packaging.
Spandan Dasfed3d042025-01-13 21:38:47 +0000327 builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/VENDOR_BOOT/kernel", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000328 }
Spandan Das23511372025-01-08 23:30:45 +0000329 if bootImgInfo.Bootconfig != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000330 builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir)
Spandan Das23511372025-01-08 23:30:45 +0000331 }
Spandan Das258c08f2025-01-08 23:30:45 +0000332 }
333
Spandan Dase51ff952025-01-09 18:11:59 +0000334 if a.deviceProps.Android_info != nil {
335 builder.Command().Textf("mkdir -p %s/OTA", targetFilesDir)
Cole Faust11fda332025-01-14 16:47:19 -0800336 builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, *a.deviceProps.Android_info)).Textf(" %s/OTA/android-info.txt", targetFilesDir)
Spandan Dase51ff952025-01-09 18:11:59 +0000337 }
338
Spandan Das0036fa32025-01-10 23:40:45 +0000339 a.copyImagesToTargetZip(ctx, builder, targetFilesDir)
Spandan Das29d44882025-01-15 21:12:36 +0000340 a.copyMetadataToTargetZip(ctx, builder, targetFilesDir)
Spandan Das0036fa32025-01-10 23:40:45 +0000341
Cole Faust44080412024-12-20 14:17:07 -0800342 builder.Command().
343 BuiltTool("soong_zip").
344 Text("-d").
345 FlagWithOutput("-o ", targetFilesZip).
346 FlagWithArg("-C ", targetFilesDir.String()).
347 FlagWithArg("-D ", targetFilesDir.String()).
348 Text("-sha256")
349 builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip")
350}
351
Spandan Das0036fa32025-01-10 23:40:45 +0000352func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) {
353 // Create an IMAGES/ subdirectory
354 builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String())
355 if a.deviceProps.Bootloader != nil {
356 builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader))).Textf(" %s/IMAGES/bootloader", targetFilesDir.String())
357 }
358 // Copy the filesystem ,boot and vbmeta img files to IMAGES/
359 ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(child android.ModuleProxy) {
Spandan Dasa9db76d2025-01-14 01:34:43 +0000360 if strings.Contains(child.Name(), "recovery") {
361 return // skip recovery.img to match the make packaging behavior
362 }
Spandan Dasef775742025-01-13 22:17:40 +0000363 if info, ok := android.OtherModuleProvider(ctx, child, BootimgInfoProvider); ok {
364 // Check Boot img first so that the boot.img is copied and not its dep ramdisk.img
Spandan Das0036fa32025-01-10 23:40:45 +0000365 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Dasef775742025-01-13 22:17:40 +0000366 } else if info, ok := android.OtherModuleProvider(ctx, child, FilesystemProvider); ok {
Spandan Das0036fa32025-01-10 23:40:45 +0000367 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
368 } else if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok {
369 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
370 } else {
371 ctx.ModuleErrorf("Module %s does not provide an .img file output for target_files.zip", child.Name())
372 }
373 })
Spandan Dasef775742025-01-13 22:17:40 +0000374
375 if a.partitionProps.Super_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800376 superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
Spandan Dasef775742025-01-13 22:17:40 +0000377 if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
Cole Faust19eb09d2025-01-14 13:27:00 -0800378 for _, partition := range android.SortedKeys(info.SubImageInfo) {
Spandan Das1f0a5a12025-01-15 00:53:15 +0000379 builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].OutputHermetic).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Das33c9c472025-01-14 19:26:23 +0000380 builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].MapFile).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Dasef775742025-01-13 22:17:40 +0000381 }
382 } else {
383 ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
384 }
385 }
Spandan Das0036fa32025-01-10 23:40:45 +0000386}
387
Spandan Das29d44882025-01-15 21:12:36 +0000388func (a *androidDevice) copyMetadataToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) {
389 // Create a META/ subdirectory
390 builder.Command().Textf("mkdir -p %s/META", targetFilesDir.String())
391 if proptools.Bool(a.deviceProps.Ab_ota_updater) {
392 ctx.VisitDirectDepsProxyWithTag(targetFilesMetadataDepTag, func(child android.ModuleProxy) {
393 info, _ := android.OtherModuleProvider(ctx, child, android.OutputFilesProvider)
394 builder.Command().Textf("cp").Inputs(info.DefaultOutputFiles).Textf(" %s/META/", targetFilesDir.String())
395 })
396 }
397 builder.Command().Textf("cp").Input(android.PathForSource(ctx, "external/zucchini/version_info.h")).Textf(" %s/META/zucchini_config.txt", targetFilesDir.String())
398 builder.Command().Textf("cp").Input(android.PathForSource(ctx, "system/update_engine/update_engine.conf")).Textf(" %s/META/update_engine_config.txt", targetFilesDir.String())
399}
400
Cole Faust44080412024-12-20 14:17:07 -0800401func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo {
Cole Faust19eb09d2025-01-14 13:27:00 -0800402 fsMod := ctx.GetDirectDepProxyWithTag(depName, filesystemDepTag)
Cole Faust44080412024-12-20 14:17:07 -0800403 fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider)
404 if !ok {
405 ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName)
406 }
407 return fsInfo
Jihoon Kangf2c53982024-10-09 17:32:52 +0000408}