blob: e340602cdf70ca5a56590c1377452d6f7f999a3e [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
Jihoon Kang3be17162025-01-09 20:51:54 +000071}
72
Jihoon Kangf2c53982024-10-09 17:32:52 +000073type androidDevice struct {
74 android.ModuleBase
75
76 partitionProps PartitionNameProperties
Jihoon Kang3be17162025-01-09 20:51:54 +000077
78 deviceProps DeviceProperties
Jihoon Kangf2c53982024-10-09 17:32:52 +000079}
80
81func AndroidDeviceFactory() android.Module {
82 module := &androidDevice{}
Jihoon Kang3be17162025-01-09 20:51:54 +000083 module.AddProperties(&module.partitionProps, &module.deviceProps)
Cole Faust341d5f12025-01-07 15:32:38 -080084 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibFirst)
Jihoon Kangf2c53982024-10-09 17:32:52 +000085 return module
86}
87
Cole Faust11fda332025-01-14 16:47:19 -080088var numMainAndroidDevicesOnceKey android.OnceKey = android.NewOnceKey("num_auto_generated_anroid_devices")
Cole Faustb55a41c2025-01-09 16:53:58 -080089
Jihoon Kangf2c53982024-10-09 17:32:52 +000090type partitionDepTagType struct {
91 blueprint.BaseDependencyTag
92}
93
Cole Faust2bdc5e52025-01-10 10:29:36 -080094type superPartitionDepTagType struct {
95 blueprint.BaseDependencyTag
96}
97
98var superPartitionDepTag superPartitionDepTagType
Jihoon Kangf2c53982024-10-09 17:32:52 +000099var filesystemDepTag partitionDepTagType
100
101func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
102 addDependencyIfDefined := func(dep *string) {
103 if dep != nil {
Cole Faust341d5f12025-01-07 15:32:38 -0800104 ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep))
Jihoon Kangf2c53982024-10-09 17:32:52 +0000105 }
106 }
107
Cole Faust2bdc5e52025-01-10 10:29:36 -0800108 if a.partitionProps.Super_partition_name != nil {
109 ctx.AddDependency(ctx.Module(), superPartitionDepTag, *a.partitionProps.Super_partition_name)
110 }
Jihoon Kangf2c53982024-10-09 17:32:52 +0000111 addDependencyIfDefined(a.partitionProps.Boot_partition_name)
Jihoon Kang9e087002025-01-08 19:12:23 +0000112 addDependencyIfDefined(a.partitionProps.Init_boot_partition_name)
Spandan Dasef200ac2025-01-08 01:42:45 +0000113 addDependencyIfDefined(a.partitionProps.Vendor_boot_partition_name)
Jihoon Kangf2c53982024-10-09 17:32:52 +0000114 addDependencyIfDefined(a.partitionProps.System_partition_name)
115 addDependencyIfDefined(a.partitionProps.System_ext_partition_name)
116 addDependencyIfDefined(a.partitionProps.Product_partition_name)
117 addDependencyIfDefined(a.partitionProps.Vendor_partition_name)
Spandan Dasc5717162024-11-01 18:33:57 +0000118 addDependencyIfDefined(a.partitionProps.Odm_partition_name)
mrziwang23ba8762024-11-07 16:21:53 -0800119 addDependencyIfDefined(a.partitionProps.Userdata_partition_name)
Spandan Dasa0394002025-01-07 18:38:34 +0000120 addDependencyIfDefined(a.partitionProps.System_dlkm_partition_name)
121 addDependencyIfDefined(a.partitionProps.Vendor_dlkm_partition_name)
122 addDependencyIfDefined(a.partitionProps.Odm_dlkm_partition_name)
Spandan Dasef200ac2025-01-08 01:42:45 +0000123 addDependencyIfDefined(a.partitionProps.Recovery_partition_name)
Cole Faust3552eb62024-11-06 18:07:26 -0800124 for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions {
125 ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition)
126 }
Jihoon Kangf2c53982024-10-09 17:32:52 +0000127}
128
Cole Faust11fda332025-01-14 16:47:19 -0800129func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) {
130 if proptools.Bool(a.deviceProps.Main_device) {
131 numMainAndroidDevices := ctx.Config().Once(numMainAndroidDevicesOnceKey, func() interface{} {
132 return &atomic.Int32{}
133 }).(*atomic.Int32)
134 total := numMainAndroidDevices.Add(1)
135 if total > 1 {
136 // There should only be 1 main android_device module. That one will be
137 // made the default thing to build in soong-only builds.
138 ctx.ModuleErrorf("There cannot be more than 1 main android_device module")
139 }
Jihoon Kang3be17162025-01-09 20:51:54 +0000140 }
141
Cole Faust44080412024-12-20 14:17:07 -0800142 a.buildTargetFilesZip(ctx)
mrziwang2fd33a72025-01-08 12:22:08 -0800143 var deps []android.Path
Cole Faust2bdc5e52025-01-10 10:29:36 -0800144 if proptools.String(a.partitionProps.Super_partition_name) != "" {
Cole Faust19eb09d2025-01-14 13:27:00 -0800145 superImage := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800146 if info, ok := android.OtherModuleProvider(ctx, superImage, SuperImageProvider); ok {
147 assertUnset := func(prop *string, propName string) {
148 if prop != nil && *prop != "" {
149 ctx.PropertyErrorf(propName, "Cannot be set because it's already part of the super image")
150 }
151 }
152 for _, subPartitionType := range android.SortedKeys(info.SubImageInfo) {
153 switch subPartitionType {
154 case "system":
155 assertUnset(a.partitionProps.System_partition_name, "system_partition_name")
156 case "system_ext":
157 assertUnset(a.partitionProps.System_ext_partition_name, "system_ext_partition_name")
158 case "system_dlkm":
159 assertUnset(a.partitionProps.System_dlkm_partition_name, "system_dlkm_partition_name")
160 case "system_other":
161 // TODO
162 case "product":
163 assertUnset(a.partitionProps.Product_partition_name, "product_partition_name")
164 case "vendor":
165 assertUnset(a.partitionProps.Vendor_partition_name, "vendor_partition_name")
166 case "vendor_dlkm":
167 assertUnset(a.partitionProps.Vendor_dlkm_partition_name, "vendor_dlkm_partition_name")
168 case "odm":
169 assertUnset(a.partitionProps.Odm_partition_name, "odm_partition_name")
170 case "odm_dlkm":
171 assertUnset(a.partitionProps.Odm_dlkm_partition_name, "odm_dlkm_partition_name")
172 default:
173 ctx.ModuleErrorf("Unsupported sub-partition of super partition: %q", subPartitionType)
174 }
175 }
176
177 deps = append(deps, info.SuperImage)
178 } else {
179 ctx.ModuleErrorf("Expected super image dep to provide SuperImageProvider")
180 }
181 }
Cole Faust19eb09d2025-01-14 13:27:00 -0800182 ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(m android.ModuleProxy) {
mrziwang2fd33a72025-01-08 12:22:08 -0800183 imageOutput, ok := android.OtherModuleProvider(ctx, m, android.OutputFilesProvider)
184 if !ok {
185 ctx.ModuleErrorf("Partition module %s doesn't set OutputfilesProvider", m.Name())
186 }
187 if len(imageOutput.DefaultOutputFiles) != 1 {
188 ctx.ModuleErrorf("Partition module %s should provide exact 1 output file", m.Name())
189 }
190 deps = append(deps, imageOutput.DefaultOutputFiles[0])
191 })
Jihoon Kang3be17162025-01-09 20:51:54 +0000192
Cole Faustb55a41c2025-01-09 16:53:58 -0800193 allImagesStamp := android.PathForModuleOut(ctx, "all_images_stamp")
Cole Faust11fda332025-01-14 16:47:19 -0800194 var validations android.Paths
195 if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) {
Cole Faustb55a41c2025-01-09 16:53:58 -0800196 // In soong-only builds, build this module by default.
197 // This is the analogue to this make code:
198 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/main.mk;l=1396;drc=6595459cdd8164a6008335f6372c9f97b9094060
199 ctx.Phony("droidcore-unbundled", allImagesStamp)
Cole Faust11fda332025-01-14 16:47:19 -0800200
201 validations = append(validations, a.copyFilesToProductOutForSoongOnly(ctx))
Cole Faustb55a41c2025-01-09 16:53:58 -0800202 }
Cole Faust11fda332025-01-14 16:47:19 -0800203
204 ctx.Build(pctx, android.BuildParams{
205 Rule: android.Touch,
206 Output: allImagesStamp,
207 Implicits: deps,
208 Validations: validations,
209 })
210
211 // Checkbuilding it causes soong to make a phony, so you can say `m <module name>`
212 ctx.CheckbuildFile(allImagesStamp)
Cole Faust44080412024-12-20 14:17:07 -0800213}
Jihoon Kangf2c53982024-10-09 17:32:52 +0000214
Spandan Dasef775742025-01-13 22:17:40 +0000215// Helper structs for target_files.zip creation
Spandan Dasef200ac2025-01-08 01:42:45 +0000216type targetFilesZipCopy struct {
217 srcModule *string
218 destSubdir string
219}
220
Spandan Dasef775742025-01-13 22:17:40 +0000221type targetFilesystemZipCopy struct {
222 fsInfo FilesystemInfo
223 destSubdir string
224}
225
Cole Faust44080412024-12-20 14:17:07 -0800226func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext) {
227 targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir")
228 targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip")
229
230 builder := android.NewRuleBuilder(pctx, ctx)
231 builder.Command().Textf("rm -rf %s", targetFilesDir.String())
232 builder.Command().Textf("mkdir -p %s", targetFilesDir.String())
Spandan Dasef200ac2025-01-08 01:42:45 +0000233 toCopy := []targetFilesZipCopy{
234 targetFilesZipCopy{a.partitionProps.System_partition_name, "SYSTEM"},
235 targetFilesZipCopy{a.partitionProps.System_ext_partition_name, "SYSTEM_EXT"},
236 targetFilesZipCopy{a.partitionProps.Product_partition_name, "PRODUCT"},
237 targetFilesZipCopy{a.partitionProps.Vendor_partition_name, "VENDOR"},
238 targetFilesZipCopy{a.partitionProps.Odm_partition_name, "ODM"},
239 targetFilesZipCopy{a.partitionProps.System_dlkm_partition_name, "SYSTEM_DLKM"},
240 targetFilesZipCopy{a.partitionProps.Vendor_dlkm_partition_name, "VENDOR_DLKM"},
241 targetFilesZipCopy{a.partitionProps.Odm_dlkm_partition_name, "ODM_DLKM"},
242 targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "BOOT/RAMDISK"},
243 targetFilesZipCopy{a.partitionProps.Init_boot_partition_name, "INIT_BOOT/RAMDISK"},
244 targetFilesZipCopy{a.partitionProps.Vendor_boot_partition_name, "VENDOR_BOOT/RAMDISK"},
Spandan Das25649f52025-01-07 18:09:22 +0000245 }
Spandan Dasef200ac2025-01-08 01:42:45 +0000246 // TODO: Handle cases where recovery files are copied to BOOT/ or RECOVERY/
247 // https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=6211-6219?q=core%2FMakefile&ss=android%2Fplatform%2Fsuperproject%2Fmain
248 if ctx.DeviceConfig().BoardMoveRecoveryResourcesToVendorBoot() {
249 toCopy = append(toCopy, targetFilesZipCopy{a.partitionProps.Recovery_partition_name, "VENDOR_BOOT/RAMDISK"})
250 }
251
Spandan Dasef775742025-01-13 22:17:40 +0000252 filesystemsToCopy := []targetFilesystemZipCopy{}
Spandan Dasef200ac2025-01-08 01:42:45 +0000253 for _, zipCopy := range toCopy {
254 if zipCopy.srcModule == nil {
Spandan Das25649f52025-01-07 18:09:22 +0000255 continue
256 }
Spandan Dasef775742025-01-13 22:17:40 +0000257 filesystemsToCopy = append(
258 filesystemsToCopy,
259 targetFilesystemZipCopy{a.getFilesystemInfo(ctx, *zipCopy.srcModule), zipCopy.destSubdir},
260 )
261 }
262 // Get additional filesystems from super_partition dependency
263 if a.partitionProps.Super_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800264 superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
Spandan Dasef775742025-01-13 22:17:40 +0000265 if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
266 for _, partition := range android.SortedStringKeys(info.SubImageInfo) {
267 filesystemsToCopy = append(
268 filesystemsToCopy,
269 targetFilesystemZipCopy{info.SubImageInfo[partition], strings.ToUpper(partition)},
270 )
271 }
272 } else {
273 ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
274 }
275 }
276
277 for _, toCopy := range filesystemsToCopy {
278 rootDirString := toCopy.fsInfo.RootDir.String()
279 if toCopy.destSubdir == "SYSTEM" {
Spandan Dasef200ac2025-01-08 01:42:45 +0000280 rootDirString = rootDirString + "/system"
281 }
Spandan Dasef775742025-01-13 22:17:40 +0000282 builder.Command().Textf("mkdir -p %s/%s", targetFilesDir.String(), toCopy.destSubdir)
Cole Faust44080412024-12-20 14:17:07 -0800283 builder.Command().
284 BuiltTool("acp").
Spandan Dasef775742025-01-13 22:17:40 +0000285 Textf("-rd %s/. %s/%s", rootDirString, targetFilesDir, toCopy.destSubdir).
286 Implicit(toCopy.fsInfo.Output) // so that the staging dir is built
Spandan Dasef200ac2025-01-08 01:42:45 +0000287
Spandan Dasef775742025-01-13 22:17:40 +0000288 if toCopy.destSubdir == "SYSTEM" {
Spandan Das3ec6d062025-01-09 19:37:47 +0000289 // Create the ROOT partition in target_files.zip
Spandan Dasef775742025-01-13 22:17:40 +0000290 builder.Command().Textf("rsync --links --exclude=system/* %s/ -r %s/ROOT", toCopy.fsInfo.RootDir, targetFilesDir.String())
Spandan Das3ec6d062025-01-09 19:37:47 +0000291 }
Cole Faust44080412024-12-20 14:17:07 -0800292 }
Spandan Das9b17df22025-01-08 23:30:45 +0000293 // Copy cmdline, kernel etc. files of boot images
Spandan Das258c08f2025-01-08 23:30:45 +0000294 if a.partitionProps.Vendor_boot_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800295 bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Vendor_boot_partition_name), filesystemDepTag)
Spandan Das258c08f2025-01-08 23:30:45 +0000296 bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
Spandan Das9b17df22025-01-08 23:30:45 +0000297 builder.Command().Textf("echo %s > %s/VENDOR_BOOT/cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
298 builder.Command().Textf("echo %s > %s/VENDOR_BOOT/vendor_cmdline", proptools.ShellEscape(strings.Join(bootImgInfo.Cmdline, " ")), targetFilesDir)
299 if bootImgInfo.Dtb != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000300 builder.Command().Textf("cp ").Input(bootImgInfo.Dtb).Textf(" %s/VENDOR_BOOT/dtb", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000301 }
Spandan Das23511372025-01-08 23:30:45 +0000302 if bootImgInfo.Bootconfig != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000303 builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/VENDOR_BOOT/vendor_bootconfig", targetFilesDir)
Spandan Das23511372025-01-08 23:30:45 +0000304 }
Spandan Das258c08f2025-01-08 23:30:45 +0000305 }
306 if a.partitionProps.Boot_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800307 bootImg := ctx.GetDirectDepProxyWithTag(proptools.String(a.partitionProps.Boot_partition_name), filesystemDepTag)
Spandan Das258c08f2025-01-08 23:30:45 +0000308 bootImgInfo, _ := android.OtherModuleProvider(ctx, bootImg, BootimgInfoProvider)
Spandan Das9b17df22025-01-08 23:30:45 +0000309 builder.Command().Textf("echo %s > %s/BOOT/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/BOOT/dtb", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000312 }
313 if bootImgInfo.Kernel != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000314 builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/BOOT/kernel", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000315 // 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 +0000316 builder.Command().Textf("cp ").Input(bootImgInfo.Kernel).Textf(" %s/VENDOR_BOOT/kernel", targetFilesDir)
Spandan Das9b17df22025-01-08 23:30:45 +0000317 }
Spandan Das23511372025-01-08 23:30:45 +0000318 if bootImgInfo.Bootconfig != nil {
Spandan Dasfed3d042025-01-13 21:38:47 +0000319 builder.Command().Textf("cp ").Input(bootImgInfo.Bootconfig).Textf(" %s/BOOT/bootconfig", targetFilesDir)
Spandan Das23511372025-01-08 23:30:45 +0000320 }
Spandan Das258c08f2025-01-08 23:30:45 +0000321 }
322
Spandan Dase51ff952025-01-09 18:11:59 +0000323 if a.deviceProps.Android_info != nil {
324 builder.Command().Textf("mkdir -p %s/OTA", targetFilesDir)
Cole Faust11fda332025-01-14 16:47:19 -0800325 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 +0000326 }
327
Spandan Das0036fa32025-01-10 23:40:45 +0000328 a.copyImagesToTargetZip(ctx, builder, targetFilesDir)
329
Cole Faust44080412024-12-20 14:17:07 -0800330 builder.Command().
331 BuiltTool("soong_zip").
332 Text("-d").
333 FlagWithOutput("-o ", targetFilesZip).
334 FlagWithArg("-C ", targetFilesDir.String()).
335 FlagWithArg("-D ", targetFilesDir.String()).
336 Text("-sha256")
337 builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip")
338}
339
Spandan Das0036fa32025-01-10 23:40:45 +0000340func (a *androidDevice) copyImagesToTargetZip(ctx android.ModuleContext, builder *android.RuleBuilder, targetFilesDir android.WritablePath) {
341 // Create an IMAGES/ subdirectory
342 builder.Command().Textf("mkdir -p %s/IMAGES", targetFilesDir.String())
343 if a.deviceProps.Bootloader != nil {
344 builder.Command().Textf("cp ").Input(android.PathForModuleSrc(ctx, proptools.String(a.deviceProps.Bootloader))).Textf(" %s/IMAGES/bootloader", targetFilesDir.String())
345 }
346 // Copy the filesystem ,boot and vbmeta img files to IMAGES/
347 ctx.VisitDirectDepsProxyWithTag(filesystemDepTag, func(child android.ModuleProxy) {
Spandan Dasa9db76d2025-01-14 01:34:43 +0000348 if strings.Contains(child.Name(), "recovery") {
349 return // skip recovery.img to match the make packaging behavior
350 }
Spandan Dasef775742025-01-13 22:17:40 +0000351 if info, ok := android.OtherModuleProvider(ctx, child, BootimgInfoProvider); ok {
352 // Check Boot img first so that the boot.img is copied and not its dep ramdisk.img
Spandan Das0036fa32025-01-10 23:40:45 +0000353 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Dasef775742025-01-13 22:17:40 +0000354 } else if info, ok := android.OtherModuleProvider(ctx, child, FilesystemProvider); ok {
Spandan Das0036fa32025-01-10 23:40:45 +0000355 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
356 } else if info, ok := android.OtherModuleProvider(ctx, child, vbmetaPartitionProvider); ok {
357 builder.Command().Textf("cp ").Input(info.Output).Textf(" %s/IMAGES/", targetFilesDir.String())
358 } else {
359 ctx.ModuleErrorf("Module %s does not provide an .img file output for target_files.zip", child.Name())
360 }
361 })
Spandan Dasef775742025-01-13 22:17:40 +0000362
363 if a.partitionProps.Super_partition_name != nil {
Cole Faust19eb09d2025-01-14 13:27:00 -0800364 superPartition := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag)
Spandan Dasef775742025-01-13 22:17:40 +0000365 if info, ok := android.OtherModuleProvider(ctx, superPartition, SuperImageProvider); ok {
Cole Faust19eb09d2025-01-14 13:27:00 -0800366 for _, partition := range android.SortedKeys(info.SubImageInfo) {
Spandan Das1f0a5a12025-01-15 00:53:15 +0000367 builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].OutputHermetic).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Das33c9c472025-01-14 19:26:23 +0000368 builder.Command().Textf("cp ").Input(info.SubImageInfo[partition].MapFile).Textf(" %s/IMAGES/", targetFilesDir.String())
Spandan Dasef775742025-01-13 22:17:40 +0000369 }
370 } else {
371 ctx.ModuleErrorf("Super partition %s does set SuperImageProvider\n", superPartition.Name())
372 }
373 }
Spandan Das0036fa32025-01-10 23:40:45 +0000374}
375
Cole Faust44080412024-12-20 14:17:07 -0800376func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo {
Cole Faust19eb09d2025-01-14 13:27:00 -0800377 fsMod := ctx.GetDirectDepProxyWithTag(depName, filesystemDepTag)
Cole Faust44080412024-12-20 14:17:07 -0800378 fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider)
379 if !ok {
380 ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName)
381 }
382 return fsInfo
Jihoon Kangf2c53982024-10-09 17:32:52 +0000383}