blob: d9f38163be9feacb2fdb11ac01245e1ee3b180a4 [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"`
Jihoon Kang3be17162025-01-09 20:51:54 +000065}
66
Jihoon Kangf2c53982024-10-09 17:32:52 +000067type androidDevice struct {
68 android.ModuleBase
69
70 partitionProps PartitionNameProperties
Jihoon Kang3be17162025-01-09 20:51:54 +000071
72 deviceProps DeviceProperties
73
74 // copyToProductOutTimestamp for copying necessary files to PRODUCT_OUT
75 copyToProductOutTimestamp android.WritablePath
Jihoon Kangf2c53982024-10-09 17:32:52 +000076}
77
78func AndroidDeviceFactory() android.Module {
79 module := &androidDevice{}
Jihoon Kang3be17162025-01-09 20:51:54 +000080 module.AddProperties(&module.partitionProps, &module.deviceProps)
Cole Faust341d5f12025-01-07 15:32:38 -080081 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibFirst)
Jihoon Kangf2c53982024-10-09 17:32:52 +000082 return module
83}
84
Cole Faustb55a41c2025-01-09 16:53:58 -080085var numAutogeneratedAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices")
86
Jihoon Kangf2c53982024-10-09 17:32:52 +000087type partitionDepTagType struct {
88 blueprint.BaseDependencyTag
89}
90
Cole Faust2bdc5e52025-01-10 10:29:36 -080091type superPartitionDepTagType struct {
92 blueprint.BaseDependencyTag
93}
94
95var superPartitionDepTag superPartitionDepTagType
Jihoon Kangf2c53982024-10-09 17:32:52 +000096var filesystemDepTag partitionDepTagType
97
98func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
99 addDependencyIfDefined := func(dep *string) {
100 if dep != nil {
Cole Faust341d5f12025-01-07 15:32:38 -0800101 ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep))
Jihoon Kangf2c53982024-10-09 17:32:52 +0000102 }
103 }
104
Cole Faust2bdc5e52025-01-10 10:29:36 -0800105 if a.partitionProps.Super_partition_name != nil {
106 ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name)
107 }
Jihoon Kangf2c53982024-10-09 17:32:52 +0000108 addDependencyIfDefined(a.partitionProps.Boot_partition_name)
Jihoon Kang9e087002025-01-08 19:12:23 +0000109 addDependencyIfDefined(a.partitionProps.Init_boot_partition_name)
Spandan Dasef200ac2025-01-08 01:42:45 +0000110 addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name)
Jihoon Kangf2c53982024-10-09 17:32:52 +0000111 addDependencyIfDefined(a.partitionProps.System_partition_name)
112 addDependencyIfDefined(a.partitionProps.System_ext_partition_name)
113 addDependencyIfDefined(a.partitionProps.Product_partition_name)
114 addDependencyIfDefined(a.partitionProps.Vendor_partition_name)
Spandan Dasc5717162024-11-01 18:33:57 +0000115 addDependencyIfDefined(a.partitionProps.Odm_partition_name)
mrziwang23ba8762024-11-07 16:21:53 -0800116 addDependencyIfDefined(a.partitionProps.Userdata_partition_name)
Spandan Dasa0394002025-01-07 18:38:34 +0000117 addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name)
118 addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name)
119 addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name)
Spandan Dasef200ac2025-01-08 01:42:45 +0000120 addDependencyIfDefined(a.partitionProps.Recovery_partition_name)
Cole Faust3552eb62024-11-06 18:07:26 -0800121 for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions {
122 ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition)
123 }
Jihoon Kangf2c53982024-10-09 17:32:52 +0000124}
125
Jihoon Kang3be17162025-01-09 20:51:54 +0000126func (a *androidDevice) copyToProductOut(ctx android.ModuleContext, builder *android.RuleBuilder, src android.Path, dest string) {
127 destPath := android.PathForModuleInPartitionInstall(ctx, "").Join(ctx, dest)
128 builder.Command().Text("rsync").Flag("-a").Flag("--checksum").Input(src).Text(destPath.String())
129}
130
131func (a *androidDevice) copyFilesToProductOut(ctx android.ModuleContext) {
132 a.copyToProductOutTimestamp = android.PathForModuleOut(ctx, "timestamp")
133 builder := android.NewRuleBuilder(pctx, ctx)
134 builder.Command().Text("touch").Output(a.copyToProductOutTimestamp)
135
136 // List all individual files to be copied to PRODUCT_OUT here
137 if a.deviceProps.Bootloader != nil {
138 a.copyToProductOut(ctx, builder, android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader)), "bootloader")
139 }
140
141 builder.Build("copy_to_product_out", "Copy files to PRODUCT_OUT")
142}
143
Jihoon Kangf2c53982024-10-09 17:32:52 +0000144func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faust44080412024-12-20 14:17:07 -0800145 a.buildTargetFilesZip(ctx)
mrziwang2fd33a72025-01-08 12:22:08 -0800146 var deps []android.Path
Cole Faust2bdc5e52025-01-10 10:29:36 -0800147 if proptools.String(a.partitionProps.Super_partition_name) != "" {
148 superImage := ctx.GetDirectDepWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
149 if info, ok := android.OtherModuleProvider(ctx, superImage, SuperImageProvider); ok {
150 assertUnset := func(prop *string, propName string) {
151 if prop != nil && *prop != "" {
152 ctx.PropertyErrorf(propName, "Cannot be set because it's already part of the super image")
153 }
154 }
155 for _, subPartitionType := range android.SortedKeys(info.SubImageInfo) {
156 switch subPartitionType {
157 case "system":
158 assertUnset(a.partitionProps.System_partition_name, "system_partition_name")
159 case "system_ext":
160 assertUnset(a.partitionProps.System_ext_partition_name, "system_ext_partition_name")
161 case "system_dlkm":
162 assertUnset(a.partitionProps.System_dlkm_partition_name, "system_dlkm_partition_name")
163 case "system_other":
164 // TODO
165 case "product":
166 assertUnset(a.partitionProps.Product_partition_name, "product_partition_name")
167 case "vendor":
168 assertUnset(a.partitionProps.Vendor_partition_name, "vendor_partition_name")
169 case "vendor_dlkm":
170 assertUnset(a.partitionProps.Vendor_dlkm_partition_name, "vendor_dlkm_partition_name")
171 case "odm":
172 assertUnset(a.partitionProps.Odm_partition_name, "odm_partition_name")
173 case "odm_dlkm":
174 assertUnset(a.partitionProps.Odm_dlkm_partition_name, "odm_dlkm_partition_name")
175 default:
176 ctx.ModuleErrorf("Unsupported sub-partition of super partition: %q", subPartitionType)
177 }
178 }
179
180 deps = append(deps, info.SuperImage)
181 } else {
182 ctx.ModuleErrorf("Expected super image dep to provide SuperImageProvider")
183 }
184 }
mrziwang2fd33a72025-01-08 12:22:08 -0800185 ctx.VisitDirectDepsWithTag(filesystemDepTag, func(m android.Module) {
186 imageOutput, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider)
187 if !ok {
188 ctx.ModuleErrorf("Partition module %s doesn't set OutputfilesProvider", m.Name())
189 }
190 if len(imageOutput.DefaultOutputFiles) != 1 {
191 ctx.ModuleErrorf("Partition module %s should provide exact 1 output file", m.Name())
192 }
193 deps = append(deps, imageOutput.DefaultOutputFiles[0])
194 })
Jihoon Kang3be17162025-01-09 20:51:54 +0000195
196 a.copyFilesToProductOut(ctx)
197
Cole Faustb55a41c2025-01-09 16:53:58 -0800198 allImagesStamp := android.PathForModuleOut(ctx, "all_images_stamp")
mrziwang2fd33a72025-01-08 12:22:08 -0800199 ctx.Build(pctx, android.BuildParams{
Jihoon Kang3be17162025-01-09 20:51:54 +0000200 Rule: android.Touch,
Cole Faustb55a41c2025-01-09 16:53:58 -0800201 Output: allImagesStamp,
Jihoon Kang3be17162025-01-09 20:51:54 +0000202 Implicits: deps,
203 Validation: a.copyToProductOutTimestamp,
mrziwang2fd33a72025-01-08 12:22:08 -0800204 })
Cole Faustb55a41c2025-01-09 16:53:58 -0800205 ctx.SetOutputFiles(android.Paths{allImagesStamp}, "")
206 ctx.CheckbuildFile(allImagesStamp)
207
208 if ctx.OtherModuleIsAutoGenerated(ctx.Module()) {
209 numAutogeneratedAndroidDevices := ctx.Config().Once(numAutogeneratedAndroidDevicesOnceKey, func() interface{} {
210 return &atomic.Int32{}
211 }).(*atomic.Int32)
212 total := numAutogeneratedAndroidDevices.Add(1)
213 if total > 1 {
214 // There should only be 1 autogenerated android_device module. That one will be
215 // made the default thing to build in soong-only builds.
216 ctx.ModuleErrorf("There cannot be more than 1 autogenerated android_device module")
217 }
218 }
219
220 if !ctx.Config().KatiEnabled() && ctx.OtherModuleIsAutoGenerated(ctx.Module()) {
221 // In soong-only builds, build this module by default.
222 // This is the analogue to this make code:
223 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/main.mk;l=1396;drc=6595459cdd8164a6008335f6372c9f97b9094060
224 ctx.Phony("droidcore-unbundled", allImagesStamp)
225 }
Cole Faust44080412024-12-20 14:17:07 -0800226}
Jihoon Kangf2c53982024-10-09 17:32:52 +0000227
Spandan Dasef775742025-01-13 22:17:40 +0000228// Helper structs for target_files.zip creation
Spandan Dasef200ac2025-01-08 01:42:45 +0000229type targetFilesZipCopy struct {
230 srcModule *string
231 destSubdir string
232}
233
Spandan Dasef775742025-01-13 22:17:40 +0000234type targetFilesystemZipCopy struct {
235 fsInfo FilesystemInfo
236 destSubdir string
237}
238
Cole Faust44080412024-12-20 14:17:07 -0800239func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext) {
240 targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir")
241 targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip")
242
243 builder := android.NewRuleBuilder(pctx, ctx)
244 builder.Command().Textf("rm -rf %s", targetFilesDir.String())
245 builder.Command().Textf("mkdir -p %s", targetFilesDir.String())
Spandan Dasef200ac2025-01-08 01:42:45 +0000246 toCopy := []targetFilesZipCopy{
247 targetFilesZipCopy{a.partitionProps.System_partition_name, "SYSTEM"},
248 targetFilesZipCopy{a.partitionProps.System_ext_partition_name, "SYSTEM_EXT"},
249 targetFilesZipCopy{a.partitionProps.Product_partition_name, "PRODUCT"},
250 targetFilesZipCopy{a.partitionProps.Vendor_partition_name, "VENDOR"},
251 targetFilesZipCopy{a.partitionProps.Odm_partition_name, "ODM"},
252 targetFilesZipCopy{a.partitionProps.System_dlkm_partition_name, "SYSTEM_DLKM"},
253 targetFilesZipCopy{a.partitionProps.Vendor_dlkm_partition_name, "VENDOR_DLKM"},
254 targetFilesZipCopy{a.partitionProps.Odm_dlkm_partition_name, "ODM_DLKM"},
255 targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"},
256 targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"},
257 targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"},
Spandan Das25649f52025-01-07 18:09:22 +0000258 }
Spandan Dasef200ac2025-01-08 01:42:45 +0000259 // TODO: Handle cases where recovery files are copied to BOOT/ or RECOVERY/
260 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=6211-6219?q=core%2FMakefile&ss=android%2Fplatform%2Fsuperproject%2Fmain
261 if ctx.DeviceConfig().BoardMoveRecoveryResourcesToVendorBoot() {
262 toCopy = append(toCopy, targetFilesZipCopy{a.partitionProps.Recovery_partition_name, "VENDOR_BOOT/RAMDISK"})
263 }
264
Spandan Dasef775742025-01-13 22:17:40 +0000265 filesystemsToCopy := []targetFilesystemZipCopy{}
Spandan Dasef200ac2025-01-08 01:42:45 +0000266 for _, zipCopy := range toCopy {
267 if zipCopy.srcModule == nil {
Spandan Das25649f52025-01-07 18:09:22 +0000268 continue
269 }
Spandan Dasef775742025-01-13 22:17:40 +0000270 filesystemsToCopy = append(
271 filesystemsToCopy,
272 targetFilesystemZipCopy{a.getFilesystemInfo(ctx, *zipCopy.srcModule), zipCopy.destSubdir},
273 )
274 }
275 // Get additional filesystems from super_partition dependency
276 if a.partitionProps.Super_partition_name != nil {
277 superPartition := ctx.GetDirectDepWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
278 if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
279 for _, partition := range android.SortedStringKeys(info.SubImageInfo) {
280 filesystemsToCopy = append(
281 filesystemsToCopy,
282 targetFilesystemZipCopy{info.SubImageInfo[partition], strings.ToUpper(partition)},
283 )
284 }
285 } else {
286 ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
287 }
288 }
289
290 for _, toCopy := range filesystemsToCopy {
291 rootDirString := toCopy.fsInfo.RootDir.String()
292 if toCopy.destSubdir == "SYSTEM" {
Spandan Dasef200ac2025-01-08 01:42:45 +0000293 rootDirString = rootDirString + "/system"
294 }
Spandan Dasef775742025-01-13 22:17:40 +0000295 builder.Command().Textf("mkdir -p %s/%s", targetFilesDir.String(), toCopy.destSubdir)
Cole Faust44080412024-12-20 14:17:07 -0800296 builder.Command().
297 BuiltTool("acp").
Spandan Dasef775742025-01-13 22:17:40 +0000298 Textf("-rd %s/. %s/%s", rootDirString, targetFilesDir, toCopy.destSubdir).
299 Implicit(toCopy.fsInfo.Output) // so that the staging dir is built
Spandan Dasef200ac2025-01-08 01:42:45 +0000300
Spandan Dasef775742025-01-13 22:17:40 +0000301 if toCopy.destSubdir == "SYSTEM" {
Spandan Das3ec6d062025-01-09 19:37:47 +0000302 // Create the ROOT partition in target_files.zip
Spandan Dasef775742025-01-13 22:17:40 +0000303 builder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s/ROOT", toCopy.fsInfo.RootDir, targetFilesDir.String())
Spandan Das3ec6d062025-01-09 19:37:47 +0000304 }
Cole Faust44080412024-12-20 14:17:07 -0800305 }
Spandan Das9b17df22025-01-08 23:30:45 +0000306 // Copy cmdline, kernel etc. files of boot images
Spandan Das258c08f2025-01-08 23:30:45 +0000307 if a.partitionProps.Vendor_boot_partition_name != nil {
308 bootImg := ctx.GetDirectDepWithTag(proptools.String(a.partitionProps.Vendor_boot_partition_name), filesystemDepTag)
309 bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
Spandan Das9b17df22025-01-08 23:30:45 +0000310 builder.Command().Textf("echo %s > %s/VENDOR_BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
311 builder.Command().Textf("echo %s > %s/VENDOR_BOOT/vendor_cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
312 if bootImgInfo.Dtb != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000313 builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_BOOT/dtb", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000314 }
Spandan Das23511372025-01-08 23:30:45 +0000315 if bootImgInfo.Bootconfig != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000316 builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/VENDOR_BOOT/vendor_bootconfig", targetFilesDir)
Spandan Das23511372025-01-08 23:30:45 +0000317 }
Spandan Das258c08f2025-01-08 23:30:45 +0000318 }
319 if a.partitionProps.Boot_partition_name != nil {
320 bootImg := ctx.GetDirectDepWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag)
321 bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
Spandan Das9b17df22025-01-08 23:30:45 +0000322 builder.Command().Textf("echo %s > %s/BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
323 if bootImgInfo.Dtb != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000324 builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/BOOT/dtb", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000325 }
326 if bootImgInfo.Kernel != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000327 builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000328 // 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 +0000329 builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/VENDOR_BOOT/kernel", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000330 }
Spandan Das23511372025-01-08 23:30:45 +0000331 if bootImgInfo.Bootconfig != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000332 builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir)
Spandan Das23511372025-01-08 23:30:45 +0000333 }
Spandan Das258c08f2025-01-08 23:30:45 +0000334 }
335
Spandan Dase51ff952025-01-09 18:11:59 +0000336 if a.deviceProps.Android_info != nil {
337 builder.Command().Textf("mkdir -p %s/OTA", targetFilesDir)
Spandan Dasfed3d042025-01-13 21:38:47 +0000338 builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Android_info))).Textf(" %s/OTA/android-info.txt", targetFilesDir)
Spandan Dase51ff952025-01-09 18:11:59 +0000339 }
340
Spandan Das0036fa32025-01-10 23:40:45 +0000341 a.copyImagesToTargetZip(ctx, builder, targetFilesDir)
342
Cole Faust44080412024-12-20 14:17:07 -0800343 builder.Command().
344 BuiltTool("soong_zip").
345 Text("-d").
346 FlagWithOutput("-o ", targetFilesZip).
347 FlagWithArg("-C ", targetFilesDir.String()).
348 FlagWithArg("-D ", targetFilesDir.String()).
349 Text("-sha256")
350 builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip")
351}
352
Spandan Das0036fa32025-01-10 23:40:45 +0000353func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) {
354 // Create an IMAGES/ subdirectory
355 builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String())
356 if a.deviceProps.Bootloader != nil {
357 builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader))).Textf(" %s/IMAGES/bootloader", targetFilesDir.String())
358 }
359 // Copy the filesystem ,boot and vbmeta img files to IMAGES/
360 ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(child android.ModuleProxy) {
Spandan Dasef775742025-01-13 22:17:40 +0000361 if info, ok := android.OtherModuleProvider(ctx, child, BootimgInfoProvider); ok {
362 // Check Boot img first so that the boot.img is copied and not its dep ramdisk.img
Spandan Das0036fa32025-01-10 23:40:45 +0000363 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Dasef775742025-01-13 22:17:40 +0000364 } else if info, ok := android.OtherModuleProvider(ctx, child, FilesystemProvider); ok {
Spandan Das0036fa32025-01-10 23:40:45 +0000365 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
366 } else if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok {
367 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
368 } else {
369 ctx.ModuleErrorf("Module %s does not provide an .img file output for target_files.zip", child.Name())
370 }
371 })
Spandan Dasef775742025-01-13 22:17:40 +0000372
373 if a.partitionProps.Super_partition_name != nil {
374 superPartition := ctx.GetDirectDepWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
375 if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
376 for _, partition := range android.SortedStringKeys(info.SubImageInfo) {
377 builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].Output).Textf(" %s/IMAGES/", targetFilesDir.String())
378 }
379 } else {
380 ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
381 }
382 }
Spandan Das0036fa32025-01-10 23:40:45 +0000383}
384
Cole Faust44080412024-12-20 14:17:07 -0800385func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo {
386 fsMod := ctx.GetDirectDepWithTag(depName, filesystemDepTag)
387 fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider)
388 if !ok {
389 ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName)
390 }
391 return fsInfo
Jihoon Kangf2c53982024-10-09 17:32:52 +0000392}