blob: a0190875d0624c1eabeec0a43278b7d94c526bf8 [file] [log] [blame]
Jihoon Kang98047cf2024-10-02 17:13:54 +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 fsgen
16
17import (
Cole Faust92ccbe22024-10-03 14:38:37 -070018 "crypto/sha256"
Jihoon Kang98047cf2024-10-02 17:13:54 +000019 "fmt"
Spandan Das312cc412024-10-29 18:20:11 +000020 "path/filepath"
Jihoon Kang98047cf2024-10-02 17:13:54 +000021 "strconv"
mrziwang8f86c882024-10-03 12:34:33 -070022 "strings"
mrziwang8f86c882024-10-03 12:34:33 -070023
24 "android/soong/android"
25 "android/soong/filesystem"
Spandan Das5e336422024-11-01 22:31:20 +000026 "android/soong/kernel"
Jihoon Kang98047cf2024-10-02 17:13:54 +000027
Cole Faust92ccbe22024-10-03 14:38:37 -070028 "github.com/google/blueprint"
mrziwang8f86c882024-10-03 12:34:33 -070029 "github.com/google/blueprint/parser"
Jihoon Kang98047cf2024-10-02 17:13:54 +000030 "github.com/google/blueprint/proptools"
31)
32
Cole Faust92ccbe22024-10-03 14:38:37 -070033var pctx = android.NewPackageContext("android/soong/fsgen")
34
Jihoon Kang98047cf2024-10-02 17:13:54 +000035func init() {
36 registerBuildComponents(android.InitRegistrationContext)
37}
38
39func registerBuildComponents(ctx android.RegistrationContext) {
40 ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory)
mrziwang8f86c882024-10-03 12:34:33 -070041 ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators)
42}
43
Cole Faust92ccbe22024-10-03 14:38:37 -070044type filesystemCreatorProps struct {
45 Generated_partition_types []string `blueprint:"mutated"`
46 Unsupported_partition_types []string `blueprint:"mutated"`
Cole Faust3552eb62024-11-06 18:07:26 -080047
48 Vbmeta_module_names []string `blueprint:"mutated"`
49 Vbmeta_partition_names []string `blueprint:"mutated"`
Cole Faustf2a6e8b2024-11-14 10:54:48 -080050
Cole Faust24938e22024-11-18 14:01:58 -080051 Boot_image string `blueprint:"mutated" android:"path_device_first"`
52 Vendor_boot_image string `blueprint:"mutated" android:"path_device_first"`
Cole Faust92ccbe22024-10-03 14:38:37 -070053}
54
Jihoon Kang98047cf2024-10-02 17:13:54 +000055type filesystemCreator struct {
56 android.ModuleBase
Cole Faust92ccbe22024-10-03 14:38:37 -070057
58 properties filesystemCreatorProps
Jihoon Kang98047cf2024-10-02 17:13:54 +000059}
60
61func filesystemCreatorFactory() android.Module {
62 module := &filesystemCreator{}
63
Cole Faust69788792024-10-10 11:00:36 -070064 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
Cole Faust92ccbe22024-10-03 14:38:37 -070065 module.AddProperties(&module.properties)
Jihoon Kang98047cf2024-10-02 17:13:54 +000066 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Jihoon Kang675d4682024-10-24 23:45:11 +000067 generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx)
Jihoon Kang04f12c92024-11-12 23:03:08 +000068 avbpubkeyGenerated := createAvbpubkeyModule(ctx)
69 createFsGenState(ctx, generatedPrebuiltEtcModuleNames, avbpubkeyGenerated)
Cole Faust953476f2024-11-14 14:11:29 -080070 module.createAvbKeyFilegroups(ctx)
Jihoon Kang98047cf2024-10-02 17:13:54 +000071 module.createInternalModules(ctx)
72 })
73
74 return module
75}
76
Cole Faustf2a6e8b2024-11-14 10:54:48 -080077func generatedPartitions(ctx android.LoadHookContext) []string {
Cole Faust24938e22024-11-18 14:01:58 -080078 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faustf2a6e8b2024-11-14 10:54:48 -080079 generatedPartitions := []string{"system"}
80 if ctx.DeviceConfig().SystemExtPath() == "system_ext" {
81 generatedPartitions = append(generatedPartitions, "system_ext")
82 }
83 if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" {
84 generatedPartitions = append(generatedPartitions, "vendor")
85 }
86 if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" {
87 generatedPartitions = append(generatedPartitions, "product")
88 }
89 if ctx.DeviceConfig().BuildingOdmImage() && ctx.DeviceConfig().OdmPath() == "odm" {
90 generatedPartitions = append(generatedPartitions, "odm")
91 }
92 if ctx.DeviceConfig().BuildingUserdataImage() && ctx.DeviceConfig().UserdataPath() == "data" {
93 generatedPartitions = append(generatedPartitions, "userdata")
94 }
Cole Faust24938e22024-11-18 14:01:58 -080095 if partitionVars.BuildingSystemDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -080096 generatedPartitions = append(generatedPartitions, "system_dlkm")
97 }
Cole Faust24938e22024-11-18 14:01:58 -080098 if partitionVars.BuildingVendorDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -080099 generatedPartitions = append(generatedPartitions, "vendor_dlkm")
100 }
Cole Faust24938e22024-11-18 14:01:58 -0800101 if partitionVars.BuildingOdmDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800102 generatedPartitions = append(generatedPartitions, "odm_dlkm")
103 }
Cole Faust24938e22024-11-18 14:01:58 -0800104 if partitionVars.BuildingRamdiskImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800105 generatedPartitions = append(generatedPartitions, "ramdisk")
106 }
Cole Faust24938e22024-11-18 14:01:58 -0800107 if buildingVendorBootImage(partitionVars) {
108 generatedPartitions = append(generatedPartitions, "vendor_ramdisk")
109 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800110 return generatedPartitions
111}
112
Jihoon Kang98047cf2024-10-02 17:13:54 +0000113func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
Cole Faust3552eb62024-11-06 18:07:26 -0800114 soongGeneratedPartitions := generatedPartitions(ctx)
115 finalSoongGeneratedPartitions := make([]string, 0, len(soongGeneratedPartitions))
116 for _, partitionType := range soongGeneratedPartitions {
Cole Faust92ccbe22024-10-03 14:38:37 -0700117 if f.createPartition(ctx, partitionType) {
118 f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType)
Cole Faust3552eb62024-11-06 18:07:26 -0800119 finalSoongGeneratedPartitions = append(finalSoongGeneratedPartitions, partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700120 } else {
121 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType)
122 }
123 }
Cole Faust3552eb62024-11-06 18:07:26 -0800124
Cole Faust24938e22024-11-18 14:01:58 -0800125 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
126 if buildingBootImage(partitionVars) {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800127 if createBootImage(ctx) {
128 f.properties.Boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "boot")
129 } else {
130 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "boot")
131 }
132 }
Cole Faust24938e22024-11-18 14:01:58 -0800133 if buildingVendorBootImage(partitionVars) {
134 if createVendorBootImage(ctx) {
135 f.properties.Vendor_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "vendor_boot")
136 } else {
137 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "vendor_boot")
138 }
139 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800140
Cole Faust3552eb62024-11-06 18:07:26 -0800141 for _, x := range createVbmetaPartitions(ctx, finalSoongGeneratedPartitions) {
142 f.properties.Vbmeta_module_names = append(f.properties.Vbmeta_module_names, x.moduleName)
143 f.properties.Vbmeta_partition_names = append(f.properties.Vbmeta_partition_names, x.partitionName)
144 }
145
146 ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions = finalSoongGeneratedPartitions
147 f.createDeviceModule(ctx, finalSoongGeneratedPartitions, f.properties.Vbmeta_module_names)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000148}
149
Jihoon Kang0d545b82024-10-11 00:21:57 +0000150func generatedModuleName(cfg android.Config, suffix string) string {
Cole Faust92ccbe22024-10-03 14:38:37 -0700151 prefix := "soong"
152 if cfg.HasDeviceProduct() {
153 prefix = cfg.DeviceProduct()
154 }
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000155 return fmt.Sprintf("%s_generated_%s", prefix, suffix)
156}
157
Jihoon Kang0d545b82024-10-11 00:21:57 +0000158func generatedModuleNameForPartition(cfg android.Config, partitionType string) string {
159 return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000160}
161
Cole Faust3552eb62024-11-06 18:07:26 -0800162func (f *filesystemCreator) createDeviceModule(
163 ctx android.LoadHookContext,
164 generatedPartitionTypes []string,
165 vbmetaPartitions []string,
166) {
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000167 baseProps := &struct {
168 Name *string
169 }{
Jihoon Kang0d545b82024-10-11 00:21:57 +0000170 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")),
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000171 }
172
Priyanka Advani (xWF)dafaa7f2024-10-21 22:55:13 +0000173 // Currently, only the system and system_ext partition module is created.
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000174 partitionProps := &filesystem.PartitionNameProperties{}
Cole Faust3552eb62024-11-06 18:07:26 -0800175 if android.InList("system", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000176 partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system"))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000177 }
Cole Faust3552eb62024-11-06 18:07:26 -0800178 if android.InList("system_ext", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000179 partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext"))
Spandan Das7a46f6c2024-10-14 18:41:18 +0000180 }
Cole Faust3552eb62024-11-06 18:07:26 -0800181 if android.InList("vendor", generatedPartitionTypes) {
Spandan Dase3b65312024-10-22 00:27:27 +0000182 partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor"))
183 }
Cole Faust3552eb62024-11-06 18:07:26 -0800184 if android.InList("product", generatedPartitionTypes) {
Jihoon Kang6dd13b62024-10-22 23:21:02 +0000185 partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product"))
186 }
Cole Faust3552eb62024-11-06 18:07:26 -0800187 if android.InList("odm", generatedPartitionTypes) {
Spandan Dasc5717162024-11-01 18:33:57 +0000188 partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm"))
189 }
mrziwang23ba8762024-11-07 16:21:53 -0800190 if android.InList("userdata", f.properties.Generated_partition_types) {
191 partitionProps.Userdata_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "userdata"))
192 }
Cole Faust3552eb62024-11-06 18:07:26 -0800193 partitionProps.Vbmeta_partitions = vbmetaPartitions
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000194
195 ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps)
Cole Faust92ccbe22024-10-03 14:38:37 -0700196}
197
Jihoon Kangd098d442024-11-19 00:03:22 +0000198func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionVars android.PartitionVariables, partitionType string) {
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000199 switch partitionType {
200 case "system":
201 fsProps.Build_logtags = proptools.BoolPtr(true)
202 // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0
203 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Justin Yuned3dbce2024-11-15 11:57:24 +0900204 // Identical to that of the aosp_shared_system_image
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000205 fsProps.Fsverity.Inputs = []string{
206 "etc/boot-image.prof",
207 "etc/dirty-image-objects",
208 "etc/preloaded-classes",
209 "etc/classpaths/*.pb",
210 "framework/*",
211 "framework/*/*", // framework/{arch}
212 "framework/oat/*/*", // framework/oat/{arch}
213 }
214 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
mrziwang9afc2982024-11-05 14:29:48 -0800215 // TODO(b/377734331): only generate the symlinks if the relevant partitions exist
216 fsProps.Symlinks = []filesystem.SymlinkDefinition{
217 filesystem.SymlinkDefinition{
218 Target: proptools.StringPtr("/product"),
219 Name: proptools.StringPtr("system/product"),
220 },
221 filesystem.SymlinkDefinition{
222 Target: proptools.StringPtr("/system_ext"),
223 Name: proptools.StringPtr("system/system_ext"),
224 },
225 filesystem.SymlinkDefinition{
226 Target: proptools.StringPtr("/vendor"),
227 Name: proptools.StringPtr("system/vendor"),
228 },
229 filesystem.SymlinkDefinition{
230 Target: proptools.StringPtr("/system_dlkm/lib/modules"),
231 Name: proptools.StringPtr("system/lib/modules"),
232 },
233 }
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000234 case "system_ext":
235 fsProps.Fsverity.Inputs = []string{
236 "framework/*",
237 "framework/*/*", // framework/{arch}
238 "framework/oat/*/*", // framework/oat/{arch}
239 }
240 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000241 case "product":
242 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
243 case "vendor":
244 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Das69464c32024-10-25 20:08:06 +0000245 fsProps.Symlinks = []filesystem.SymlinkDefinition{
246 filesystem.SymlinkDefinition{
247 Target: proptools.StringPtr("/odm"),
248 Name: proptools.StringPtr("vendor/odm"),
249 },
250 filesystem.SymlinkDefinition{
251 Target: proptools.StringPtr("/vendor_dlkm/lib/modules"),
252 Name: proptools.StringPtr("vendor/lib/modules"),
253 },
254 }
Spandan Dasc5717162024-11-01 18:33:57 +0000255 case "odm":
256 fsProps.Symlinks = []filesystem.SymlinkDefinition{
257 filesystem.SymlinkDefinition{
258 Target: proptools.StringPtr("/odm_dlkm/lib/modules"),
259 Name: proptools.StringPtr("odm/lib/modules"),
260 },
261 }
mrziwang23ba8762024-11-07 16:21:53 -0800262 case "userdata":
263 fsProps.Base_dir = proptools.StringPtr("data")
Jihoon Kangd098d442024-11-19 00:03:22 +0000264 case "ramdisk":
265 // Following the logic in https://cs.android.com/android/platform/superproject/main/+/c3c5063df32748a8806ce5da5dd0db158eab9ad9:build/make/core/Makefile;l=1307
266 fsProps.Dirs = android.NewSimpleConfigurable([]string{
267 "debug_ramdisk",
268 "dev",
269 "metadata",
270 "mnt",
271 "proc",
272 "second_stage_resources",
273 "sys",
274 })
275 if partitionVars.BoardUsesGenericKernelImage {
276 fsProps.Dirs.AppendSimpleValue([]string{
277 "first_stage_ramdisk/debug_ramdisk",
278 "first_stage_ramdisk/dev",
279 "first_stage_ramdisk/metadata",
280 "first_stage_ramdisk/mnt",
281 "first_stage_ramdisk/proc",
282 "first_stage_ramdisk/second_stage_resources",
283 "first_stage_ramdisk/sys",
284 })
285 }
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000286 }
287}
Spandan Dascbe641a2024-10-14 21:07:34 +0000288
Spandan Das5b493cd2024-11-07 20:55:56 +0000289var (
290 dlkmPartitions = []string{
291 "system_dlkm",
292 "vendor_dlkm",
293 "odm_dlkm",
294 }
295)
296
Cole Faust92ccbe22024-10-03 14:38:37 -0700297// Creates a soong module to build the given partition. Returns false if we can't support building
298// it.
299func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool {
mrziwang4b0ca972024-10-17 14:56:19 -0700300 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
301
302 fsProps, supported := generateFsProps(ctx, partitionType)
303 if !supported {
304 return false
mrziwanga077b942024-10-16 16:00:06 -0700305 }
mrziwanga077b942024-10-16 16:00:06 -0700306
Spandan Das8fe68dc2024-10-29 18:20:11 +0000307 if partitionType == "vendor" || partitionType == "product" {
Spandan Das2047a4c2024-11-11 21:24:58 +0000308 fsProps.Linker_config.Gen_linker_config = proptools.BoolPtr(true)
309 fsProps.Linker_config.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType)
Spandan Das312cc412024-10-29 18:20:11 +0000310 }
311
Spandan Das5b493cd2024-11-07 20:55:56 +0000312 if android.InList(partitionType, dlkmPartitions) {
313 f.createPrebuiltKernelModules(ctx, partitionType)
Spandan Das5e336422024-11-01 22:31:20 +0000314 }
315
mrziwang4b0ca972024-10-17 14:56:19 -0700316 var module android.Module
317 if partitionType == "system" {
318 module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
319 } else {
320 // Explicitly set the partition.
321 fsProps.Partition_type = proptools.StringPtr(partitionType)
322 module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps)
323 }
324 module.HideFromMake()
Spandan Das168098c2024-10-28 19:44:34 +0000325 if partitionType == "vendor" {
Spandan Das4cd93b52024-11-05 23:27:03 +0000326 f.createVendorBuildProp(ctx)
Spandan Das168098c2024-10-28 19:44:34 +0000327 }
mrziwang4b0ca972024-10-17 14:56:19 -0700328 return true
329}
330
Cole Faust953476f2024-11-14 14:11:29 -0800331// Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH
332func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) {
333 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
334 var files []string
335
336 if len(partitionVars.BoardAvbKeyPath) > 0 {
337 files = append(files, partitionVars.BoardAvbKeyPath)
338 }
339 for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) {
340 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition]
341 if len(specificPartitionVars.BoardAvbKeyPath) > 0 {
342 files = append(files, specificPartitionVars.BoardAvbKeyPath)
343 }
344 }
345
346 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
347 for _, file := range files {
348 if _, ok := fsGenState.avbKeyFilegroups[file]; ok {
349 continue
350 }
351 if file == "external/avb/test/data/testkey_rsa4096.pem" {
352 // There already exists a checked-in filegroup for this commonly-used key, just use that
353 fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096"
354 continue
355 }
356 dir := filepath.Dir(file)
357 base := filepath.Base(file)
358 name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_"))
359 ctx.CreateModuleInDirectory(
360 android.FileGroupFactory,
361 dir,
362 &struct {
363 Name *string
364 Srcs []string
365 Visibility []string
366 }{
367 Name: proptools.StringPtr(name),
368 Srcs: []string{base},
369 Visibility: []string{"//visibility:public"},
370 },
371 )
372 fsGenState.avbKeyFilegroups[file] = name
373 }
374}
375
Spandan Das5e336422024-11-01 22:31:20 +0000376// createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the
Spandan Das7b25a512024-11-06 20:41:26 +0000377// autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency.
378// This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view.
Spandan Das5b493cd2024-11-07 20:55:56 +0000379func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string) {
Spandan Das5e336422024-11-01 22:31:20 +0000380 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Spandan Das7b25a512024-11-06 20:41:26 +0000381 name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType))
382 props := &struct {
Spandan Das912d26b2024-11-06 19:35:17 +0000383 Name *string
384 Srcs []string
Spandan Das5b493cd2024-11-07 20:55:56 +0000385 System_deps []string
Spandan Das912d26b2024-11-06 19:35:17 +0000386 System_dlkm_specific *bool
Spandan Das5b493cd2024-11-07 20:55:56 +0000387 Vendor_dlkm_specific *bool
388 Odm_dlkm_specific *bool
389 Load_by_default *bool
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000390 Blocklist_file *string
Spandan Das7b25a512024-11-06 20:41:26 +0000391 }{
392 Name: proptools.StringPtr(name),
Spandan Das5e336422024-11-01 22:31:20 +0000393 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000394 switch partitionType {
395 case "system_dlkm":
Spandan Das59ee5d72024-11-18 19:36:32 +0000396 props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules).Strings()
Spandan Das912d26b2024-11-06 19:35:17 +0000397 props.System_dlkm_specific = proptools.BoolPtr(true)
Spandan Das5b493cd2024-11-07 20:55:56 +0000398 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelLoadModules) == 0 {
399 // Create empty modules.load file for system
400 // https://source.corp.google.com/h/googleplex-android/platform/build/+/ef55daac9954896161b26db4f3ef1781b5a5694c:core/Makefile;l=695-700;drc=549fe2a5162548bd8b47867d35f907eb22332023;bpv=1;bpt=0
401 props.Load_by_default = proptools.BoolPtr(false)
402 }
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000403 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelBlocklistFile; blocklistFile != "" {
404 props.Blocklist_file = proptools.StringPtr(blocklistFile)
405 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000406 case "vendor_dlkm":
Spandan Das59ee5d72024-11-18 19:36:32 +0000407 props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelModules).Strings()
Spandan Das5b493cd2024-11-07 20:55:56 +0000408 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules) > 0 {
409 props.System_deps = []string{":" + generatedModuleName(ctx.Config(), "system_dlkm-kernel-modules") + "{.modules}"}
410 }
411 props.Vendor_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000412 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelBlocklistFile; blocklistFile != "" {
413 props.Blocklist_file = proptools.StringPtr(blocklistFile)
414 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000415 case "odm_dlkm":
Spandan Das59ee5d72024-11-18 19:36:32 +0000416 props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelModules).Strings()
Spandan Das5b493cd2024-11-07 20:55:56 +0000417 props.Odm_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000418 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" {
419 props.Blocklist_file = proptools.StringPtr(blocklistFile)
420 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000421 default:
422 ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType)
Spandan Das912d26b2024-11-06 19:35:17 +0000423 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000424
425 if len(props.Srcs) == 0 {
426 return // do not generate `prebuilt_kernel_modules` if there are no sources
427 }
428
Spandan Das7b25a512024-11-06 20:41:26 +0000429 kernelModule := ctx.CreateModuleInDirectory(
430 kernel.PrebuiltKernelModulesFactory,
431 ".", // create in root directory for now
432 props,
433 )
434 kernelModule.HideFromMake()
435 // Add to deps
436 (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
Spandan Das5e336422024-11-01 22:31:20 +0000437}
438
Spandan Das4cd93b52024-11-05 23:27:03 +0000439// Create a build_prop and android_info module. This will be used to create /vendor/build.prop
440func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) {
441 // Create a android_info for vendor
442 // The board info files might be in a directory outside the root soong namespace, so create
443 // the module in "."
444 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
445 androidInfoProps := &struct {
446 Name *string
447 Board_info_files []string
448 Bootloader_board_name *string
449 }{
450 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")),
451 Board_info_files: partitionVars.BoardInfoFiles,
452 }
453 if len(androidInfoProps.Board_info_files) == 0 {
454 androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName)
455 }
456 androidInfoProp := ctx.CreateModuleInDirectory(
457 android.AndroidInfoFactory,
458 ".",
459 androidInfoProps,
460 )
461 androidInfoProp.HideFromMake()
462 // Create a build prop for vendor
463 vendorBuildProps := &struct {
464 Name *string
465 Vendor *bool
466 Stem *string
467 Product_config *string
468 Android_info *string
469 }{
470 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")),
471 Vendor: proptools.BoolPtr(true),
472 Stem: proptools.StringPtr("build.prop"),
473 Product_config: proptools.StringPtr(":product_config"),
474 Android_info: proptools.StringPtr(":" + androidInfoProp.Name()),
475 }
476 vendorBuildProp := ctx.CreateModule(
477 android.BuildPropFactory,
478 vendorBuildProps,
479 )
480 vendorBuildProp.HideFromMake()
481}
482
Spandan Das8fe68dc2024-10-29 18:20:11 +0000483// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions
484// 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list)
485// 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list)
486// It creates a filegroup for each file in the fragment list
Spandan Das312cc412024-10-29 18:20:11 +0000487// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
Spandan Das8fe68dc2024-10-29 18:20:11 +0000488func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string {
Spandan Das312cc412024-10-29 18:20:11 +0000489 ret := []string{}
490 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Spandan Das8fe68dc2024-10-29 18:20:11 +0000491 var linkerConfigSrcs []string
492 if partitionType == "vendor" {
493 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs)
494 } else if partitionType == "product" {
495 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs)
496 } else {
497 ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`")
498 }
499
500 if len(linkerConfigSrcs) > 0 {
Spandan Das312cc412024-10-29 18:20:11 +0000501 // Create a filegroup, and add `:<filegroup_name>` to ret.
502 for index, linkerConfigSrc := range linkerConfigSrcs {
503 dir := filepath.Dir(linkerConfigSrc)
504 base := filepath.Base(linkerConfigSrc)
Spandan Das8fe68dc2024-10-29 18:20:11 +0000505 fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index)))
Spandan Das312cc412024-10-29 18:20:11 +0000506 srcs := []string{base}
507 fgProps := &struct {
508 Name *string
509 Srcs proptools.Configurable[[]string]
510 }{
511 Name: proptools.StringPtr(fgName),
512 Srcs: proptools.NewSimpleConfigurable(srcs),
513 }
514 ctx.CreateModuleInDirectory(
515 android.FileGroupFactory,
516 dir,
517 fgProps,
518 )
519 ret = append(ret, ":"+fgName)
520 }
521 }
522 return ret
523}
524
mrziwang4b0ca972024-10-17 14:56:19 -0700525type filesystemBaseProperty struct {
526 Name *string
527 Compile_multilib *string
Cole Faust3552eb62024-11-06 18:07:26 -0800528 Visibility []string
mrziwang4b0ca972024-10-17 14:56:19 -0700529}
530
531func generateBaseProps(namePtr *string) *filesystemBaseProperty {
532 return &filesystemBaseProperty{
533 Name: namePtr,
534 Compile_multilib: proptools.StringPtr("both"),
Cole Faust3552eb62024-11-06 18:07:26 -0800535 // The vbmeta modules are currently in the root directory and depend on the partitions
536 Visibility: []string{"//.", "//build/soong:__subpackages__"},
mrziwang4b0ca972024-10-17 14:56:19 -0700537 }
538}
539
540func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) {
Cole Faust953476f2024-11-14 14:11:29 -0800541 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Cole Faust92ccbe22024-10-03 14:38:37 -0700542 fsProps := &filesystem.FilesystemProperties{}
543
mrziwang4b0ca972024-10-17 14:56:19 -0700544 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faust76a6e952024-11-07 16:56:45 -0800545 var boardAvbEnable bool
Cole Faust953476f2024-11-14 14:11:29 -0800546 var boardAvbKeyPath string
547 var boardAvbAlgorithm string
548 var boardAvbRollbackIndex string
Cole Faust76a6e952024-11-07 16:56:45 -0800549 var fsType string
550 if strings.Contains(partitionType, "ramdisk") {
551 fsType = "compressed_cpio"
552 } else {
Cole Faust953476f2024-11-14 14:11:29 -0800553 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType]
Cole Faust76a6e952024-11-07 16:56:45 -0800554 fsType = specificPartitionVars.BoardFileSystemType
Cole Faust953476f2024-11-14 14:11:29 -0800555 boardAvbEnable = partitionVars.BoardAvbEnable
556 boardAvbKeyPath = specificPartitionVars.BoardAvbKeyPath
557 boardAvbAlgorithm = specificPartitionVars.BoardAvbAlgorithm
558 boardAvbRollbackIndex = specificPartitionVars.BoardAvbRollbackIndex
559 if boardAvbEnable {
560 if boardAvbKeyPath == "" {
561 boardAvbKeyPath = partitionVars.BoardAvbKeyPath
562 }
563 if boardAvbAlgorithm == "" {
564 boardAvbAlgorithm = partitionVars.BoardAvbAlgorithm
565 }
566 if boardAvbRollbackIndex == "" {
567 boardAvbRollbackIndex = partitionVars.BoardAvbRollbackIndex
568 }
569 }
570 if fsType == "" {
571 fsType = "ext4" //default
572 }
Cole Faust76a6e952024-11-07 16:56:45 -0800573 }
Cole Faust953476f2024-11-14 14:11:29 -0800574 if boardAvbKeyPath != "" {
575 boardAvbKeyPath = ":" + fsGenState.avbKeyFilegroups[boardAvbKeyPath]
mrziwang4b0ca972024-10-17 14:56:19 -0700576 }
Cole Faust76a6e952024-11-07 16:56:45 -0800577
mrziwang4b0ca972024-10-17 14:56:19 -0700578 fsProps.Type = proptools.StringPtr(fsType)
579 if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() {
580 // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs
581 return nil, false
582 }
583
Cole Faust92ccbe22024-10-03 14:38:37 -0700584 // Don't build this module on checkbuilds, the soong-built partitions are still in-progress
585 // and sometimes don't build.
586 fsProps.Unchecked_module = proptools.BoolPtr(true)
587
Jihoon Kang98047cf2024-10-02 17:13:54 +0000588 // BOARD_AVB_ENABLE
Cole Faust76a6e952024-11-07 16:56:45 -0800589 fsProps.Use_avb = proptools.BoolPtr(boardAvbEnable)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000590 // BOARD_AVB_KEY_PATH
Cole Faust953476f2024-11-14 14:11:29 -0800591 fsProps.Avb_private_key = proptools.StringPtr(boardAvbKeyPath)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000592 // BOARD_AVB_ALGORITHM
Cole Faust953476f2024-11-14 14:11:29 -0800593 fsProps.Avb_algorithm = proptools.StringPtr(boardAvbAlgorithm)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000594 // BOARD_AVB_SYSTEM_ROLLBACK_INDEX
Cole Faust953476f2024-11-14 14:11:29 -0800595 if rollbackIndex, err := strconv.ParseInt(boardAvbRollbackIndex, 10, 64); err == nil {
Jihoon Kang98047cf2024-10-02 17:13:54 +0000596 fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex)
597 }
598
Cole Faust92ccbe22024-10-03 14:38:37 -0700599 fsProps.Partition_name = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000600
Cole Faust68382192024-11-19 10:36:03 -0800601 if !strings.Contains(partitionType, "ramdisk") {
602 fsProps.Base_dir = proptools.StringPtr(partitionType)
603 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000604
Jihoon Kang0d545b82024-10-11 00:21:57 +0000605 fsProps.Is_auto_generated = proptools.BoolPtr(true)
606
Jihoon Kangd098d442024-11-19 00:03:22 +0000607 partitionSpecificFsProps(fsProps, partitionVars, partitionType)
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000608
Jihoon Kang98047cf2024-10-02 17:13:54 +0000609 // system_image properties that are not set:
610 // - filesystemProperties.Avb_hash_algorithm
611 // - filesystemProperties.File_contexts
612 // - filesystemProperties.Dirs
613 // - filesystemProperties.Symlinks
614 // - filesystemProperties.Fake_timestamp
615 // - filesystemProperties.Uuid
616 // - filesystemProperties.Mount_point
617 // - filesystemProperties.Include_make_built_files
618 // - filesystemProperties.Build_logtags
Jihoon Kang98047cf2024-10-02 17:13:54 +0000619 // - systemImageProperties.Linker_config_src
mrziwang4b0ca972024-10-17 14:56:19 -0700620
621 return fsProps, true
Cole Faust92ccbe22024-10-03 14:38:37 -0700622}
623
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800624func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000625 partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700626 systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
627 filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
628 if !ok {
629 ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName)
630 }
631 makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType))
Jihoon Kang9e866c82024-10-07 22:39:18 +0000632 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName))
Cole Faust92ccbe22024-10-03 14:38:37 -0700633
634 builder := android.NewRuleBuilder(pctx, ctx)
635 builder.Command().BuiltTool("file_list_diff").
636 Input(makeFileList).
637 Input(filesystemInfo.FileListFile).
Cole Faust56301572024-11-07 15:22:42 -0800638 Text(partitionModuleName)
Cole Faust92ccbe22024-10-03 14:38:37 -0700639 builder.Command().Text("touch").Output(diffTestResultFile)
640 builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test")
641 return diffTestResultFile
642}
643
644func createFailingCommand(ctx android.ModuleContext, message string) android.Path {
645 hasher := sha256.New()
646 hasher.Write([]byte(message))
647 filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil))
648 file := android.PathForModuleOut(ctx, filename)
649 builder := android.NewRuleBuilder(pctx, ctx)
650 builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message))
651 builder.Command().Text("exit 1 #").Output(file)
652 builder.Build("failing command "+filename, "failing command "+filename)
653 return file
654}
655
Cole Faust3552eb62024-11-06 18:07:26 -0800656func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmetaPartitionName string) android.Path {
657 vbmetaModule := ctx.GetDirectDepWithTag(vbmetaModuleName, generatedVbmetaPartitionDepTag)
658 outputFilesProvider, ok := android.OtherModuleProvider(ctx, vbmetaModule, android.OutputFilesProvider)
659 if !ok {
660 ctx.ModuleErrorf("Expected module %s to provide OutputFiles", vbmetaModule)
661 }
662 if len(outputFilesProvider.DefaultOutputFiles) != 1 {
663 ctx.ModuleErrorf("Expected 1 output file from module %s", vbmetaModule)
664 }
665 soongVbMetaFile := outputFilesProvider.DefaultOutputFiles[0]
666 makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName))
667
668 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName))
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800669 createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile)
670 return diffTestResultFile
671}
672
673func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) {
Cole Faust3552eb62024-11-06 18:07:26 -0800674 builder := android.NewRuleBuilder(pctx, ctx)
675 builder.Command().Text("diff").
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800676 Input(file1).
677 Input(file2)
Cole Faust3552eb62024-11-06 18:07:26 -0800678 builder.Command().Text("touch").Output(diffTestResultFile)
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800679 builder.Build("diff test "+diffTestResultFile.String(), "diff test")
Cole Faust3552eb62024-11-06 18:07:26 -0800680}
681
Cole Faust92ccbe22024-10-03 14:38:37 -0700682type systemImageDepTagType struct {
683 blueprint.BaseDependencyTag
684}
685
686var generatedFilesystemDepTag systemImageDepTagType
Cole Faust3552eb62024-11-06 18:07:26 -0800687var generatedVbmetaPartitionDepTag systemImageDepTagType
Cole Faust92ccbe22024-10-03 14:38:37 -0700688
689func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) {
690 for _, partitionType := range f.properties.Generated_partition_types {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000691 ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType))
Cole Faust92ccbe22024-10-03 14:38:37 -0700692 }
Cole Faust3552eb62024-11-06 18:07:26 -0800693 for _, vbmetaModule := range f.properties.Vbmeta_module_names {
694 ctx.AddDependency(ctx.Module(), generatedVbmetaPartitionDepTag, vbmetaModule)
695 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000696}
697
698func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -0700699 if ctx.ModuleDir() != "build/soong/fsgen" {
700 ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen")
701 }
702 f.HideFromMake()
Jihoon Kang98047cf2024-10-02 17:13:54 +0000703
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000704 var content strings.Builder
705 generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp")
706 for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions {
707 content.WriteString(generateBpContent(ctx, partition))
708 content.WriteString("\n")
709 }
710 android.WriteFileRule(ctx, generatedBp, content.String())
711
mrziwang8f86c882024-10-03 12:34:33 -0700712 ctx.Phony("product_config_to_bp", generatedBp)
713
Cole Faust92ccbe22024-10-03 14:38:37 -0700714 var diffTestFiles []android.Path
715 for _, partitionType := range f.properties.Generated_partition_types {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800716 diffTestFile := f.createFileListDiffTest(ctx, partitionType)
Jihoon Kang72f812f2024-10-17 18:46:24 +0000717 diffTestFiles = append(diffTestFiles, diffTestFile)
718 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700719 }
720 for _, partitionType := range f.properties.Unsupported_partition_types {
Jihoon Kang72f812f2024-10-17 18:46:24 +0000721 diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))
722 diffTestFiles = append(diffTestFiles, diffTestFile)
723 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700724 }
Cole Faust3552eb62024-11-06 18:07:26 -0800725 for i, vbmetaModule := range f.properties.Vbmeta_module_names {
726 diffTestFile := createVbmetaDiff(ctx, vbmetaModule, f.properties.Vbmeta_partition_names[i])
727 diffTestFiles = append(diffTestFiles, diffTestFile)
728 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile)
729 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800730 if f.properties.Boot_image != "" {
731 diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt")
732 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
733 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName()))
734 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
735 diffTestFiles = append(diffTestFiles, diffTestFile)
736 ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile)
737 }
Cole Faust24938e22024-11-18 14:01:58 -0800738 if f.properties.Vendor_boot_image != "" {
739 diffTestFile := android.PathForModuleOut(ctx, "vendor_boot_diff_test.txt")
740 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
741 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/vendor_boot.img", ctx.Config().DeviceName()))
742 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
743 diffTestFiles = append(diffTestFiles, diffTestFile)
744 ctx.Phony("soong_generated_vendor_boot_filesystem_test", diffTestFile)
745 }
Cole Faust92ccbe22024-10-03 14:38:37 -0700746 ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000747}
mrziwang8f86c882024-10-03 12:34:33 -0700748
mrziwang8f86c882024-10-03 12:34:33 -0700749func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string {
mrziwang4b0ca972024-10-17 14:56:19 -0700750 fsProps, fsTypeSupported := generateFsProps(ctx, partitionType)
751 if !fsTypeSupported {
752 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700753 }
754
mrziwang4b0ca972024-10-17 14:56:19 -0700755 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
Jihoon Kang0d7b0112024-11-13 20:44:05 +0000756 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
757 deps := fsGenState.fsDeps[partitionType]
758 highPriorityDeps := fsGenState.generatedPrebuiltEtcModuleNames
759 depProps := generateDepStruct(*deps, highPriorityDeps)
mrziwang8f86c882024-10-03 12:34:33 -0700760
mrziwang4b0ca972024-10-17 14:56:19 -0700761 result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps})
mrziwang8f86c882024-10-03 12:34:33 -0700762 if err != nil {
Cole Faustae3e1d32024-11-05 13:22:50 -0800763 ctx.ModuleErrorf("%s", err.Error())
764 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700765 }
766
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000767 moduleType := "android_filesystem"
768 if partitionType == "system" {
769 moduleType = "android_system_image"
770 }
771
mrziwang8f86c882024-10-03 12:34:33 -0700772 file := &parser.File{
773 Defs: []parser.Definition{
774 &parser.Module{
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000775 Type: moduleType,
mrziwang8f86c882024-10-03 12:34:33 -0700776 Map: *result,
777 },
778 },
779 }
780 bytes, err := parser.Print(file)
781 if err != nil {
782 ctx.ModuleErrorf(err.Error())
783 }
784 return strings.TrimSpace(string(bytes))
785}