blob: 6bfb097afa7d0932db8e79bdffe1faf4f27b18ac [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"`
Jihoon Kang95eb1da2024-11-19 20:55:20 +000053 Init_boot_image string `blueprint:"mutated" android:"path_device_first"`
Cole Faust92ccbe22024-10-03 14:38:37 -070054}
55
Jihoon Kang98047cf2024-10-02 17:13:54 +000056type filesystemCreator struct {
57 android.ModuleBase
Cole Faust92ccbe22024-10-03 14:38:37 -070058
59 properties filesystemCreatorProps
Jihoon Kang98047cf2024-10-02 17:13:54 +000060}
61
62func filesystemCreatorFactory() android.Module {
63 module := &filesystemCreator{}
64
Cole Faust69788792024-10-10 11:00:36 -070065 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
Cole Faust92ccbe22024-10-03 14:38:37 -070066 module.AddProperties(&module.properties)
Jihoon Kang98047cf2024-10-02 17:13:54 +000067 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Jihoon Kang675d4682024-10-24 23:45:11 +000068 generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx)
Jihoon Kang04f12c92024-11-12 23:03:08 +000069 avbpubkeyGenerated := createAvbpubkeyModule(ctx)
70 createFsGenState(ctx, generatedPrebuiltEtcModuleNames, avbpubkeyGenerated)
Cole Faust953476f2024-11-14 14:11:29 -080071 module.createAvbKeyFilegroups(ctx)
Jihoon Kang98047cf2024-10-02 17:13:54 +000072 module.createInternalModules(ctx)
73 })
74
75 return module
76}
77
Cole Faustf2a6e8b2024-11-14 10:54:48 -080078func generatedPartitions(ctx android.LoadHookContext) []string {
Cole Faust24938e22024-11-18 14:01:58 -080079 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faustf2a6e8b2024-11-14 10:54:48 -080080 generatedPartitions := []string{"system"}
81 if ctx.DeviceConfig().SystemExtPath() == "system_ext" {
82 generatedPartitions = append(generatedPartitions, "system_ext")
83 }
84 if ctx.DeviceConfig().BuildingVendorImage() && ctx.DeviceConfig().VendorPath() == "vendor" {
85 generatedPartitions = append(generatedPartitions, "vendor")
86 }
87 if ctx.DeviceConfig().BuildingProductImage() && ctx.DeviceConfig().ProductPath() == "product" {
88 generatedPartitions = append(generatedPartitions, "product")
89 }
90 if ctx.DeviceConfig().BuildingOdmImage() && ctx.DeviceConfig().OdmPath() == "odm" {
91 generatedPartitions = append(generatedPartitions, "odm")
92 }
93 if ctx.DeviceConfig().BuildingUserdataImage() && ctx.DeviceConfig().UserdataPath() == "data" {
94 generatedPartitions = append(generatedPartitions, "userdata")
95 }
Cole Faust24938e22024-11-18 14:01:58 -080096 if partitionVars.BuildingSystemDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -080097 generatedPartitions = append(generatedPartitions, "system_dlkm")
98 }
Cole Faust24938e22024-11-18 14:01:58 -080099 if partitionVars.BuildingVendorDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800100 generatedPartitions = append(generatedPartitions, "vendor_dlkm")
101 }
Cole Faust24938e22024-11-18 14:01:58 -0800102 if partitionVars.BuildingOdmDlkmImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800103 generatedPartitions = append(generatedPartitions, "odm_dlkm")
104 }
Cole Faust24938e22024-11-18 14:01:58 -0800105 if partitionVars.BuildingRamdiskImage {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800106 generatedPartitions = append(generatedPartitions, "ramdisk")
107 }
Cole Faust24938e22024-11-18 14:01:58 -0800108 if buildingVendorBootImage(partitionVars) {
109 generatedPartitions = append(generatedPartitions, "vendor_ramdisk")
110 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800111 return generatedPartitions
112}
113
Jihoon Kang98047cf2024-10-02 17:13:54 +0000114func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
Cole Faust3552eb62024-11-06 18:07:26 -0800115 soongGeneratedPartitions := generatedPartitions(ctx)
116 finalSoongGeneratedPartitions := make([]string, 0, len(soongGeneratedPartitions))
117 for _, partitionType := range soongGeneratedPartitions {
Cole Faust92ccbe22024-10-03 14:38:37 -0700118 if f.createPartition(ctx, partitionType) {
119 f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType)
Cole Faust3552eb62024-11-06 18:07:26 -0800120 finalSoongGeneratedPartitions = append(finalSoongGeneratedPartitions, partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700121 } else {
122 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType)
123 }
124 }
Cole Faust3552eb62024-11-06 18:07:26 -0800125
Cole Faust24938e22024-11-18 14:01:58 -0800126 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
127 if buildingBootImage(partitionVars) {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800128 if createBootImage(ctx) {
129 f.properties.Boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "boot")
130 } else {
131 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "boot")
132 }
133 }
Cole Faust24938e22024-11-18 14:01:58 -0800134 if buildingVendorBootImage(partitionVars) {
135 if createVendorBootImage(ctx) {
136 f.properties.Vendor_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "vendor_boot")
137 } else {
138 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "vendor_boot")
139 }
140 }
Jihoon Kang95eb1da2024-11-19 20:55:20 +0000141 if buildingInitBootImage(partitionVars) {
142 if createInitBootImage(ctx) {
143 f.properties.Init_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "init_boot")
144 } else {
145 f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "init_boot")
146 }
147 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800148
Cole Faust3552eb62024-11-06 18:07:26 -0800149 for _, x := range createVbmetaPartitions(ctx, finalSoongGeneratedPartitions) {
150 f.properties.Vbmeta_module_names = append(f.properties.Vbmeta_module_names, x.moduleName)
151 f.properties.Vbmeta_partition_names = append(f.properties.Vbmeta_partition_names, x.partitionName)
152 }
153
154 ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions = finalSoongGeneratedPartitions
155 f.createDeviceModule(ctx, finalSoongGeneratedPartitions, f.properties.Vbmeta_module_names)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000156}
157
Jihoon Kang0d545b82024-10-11 00:21:57 +0000158func generatedModuleName(cfg android.Config, suffix string) string {
Cole Faust92ccbe22024-10-03 14:38:37 -0700159 prefix := "soong"
160 if cfg.HasDeviceProduct() {
161 prefix = cfg.DeviceProduct()
162 }
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000163 return fmt.Sprintf("%s_generated_%s", prefix, suffix)
164}
165
Jihoon Kang0d545b82024-10-11 00:21:57 +0000166func generatedModuleNameForPartition(cfg android.Config, partitionType string) string {
167 return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000168}
169
Cole Faust3552eb62024-11-06 18:07:26 -0800170func (f *filesystemCreator) createDeviceModule(
171 ctx android.LoadHookContext,
172 generatedPartitionTypes []string,
173 vbmetaPartitions []string,
174) {
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000175 baseProps := &struct {
176 Name *string
177 }{
Jihoon Kang0d545b82024-10-11 00:21:57 +0000178 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")),
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000179 }
180
Priyanka Advani (xWF)dafaa7f2024-10-21 22:55:13 +0000181 // Currently, only the system and system_ext partition module is created.
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000182 partitionProps := &filesystem.PartitionNameProperties{}
Cole Faust3552eb62024-11-06 18:07:26 -0800183 if android.InList("system", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000184 partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system"))
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000185 }
Cole Faust3552eb62024-11-06 18:07:26 -0800186 if android.InList("system_ext", generatedPartitionTypes) {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000187 partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext"))
Spandan Das7a46f6c2024-10-14 18:41:18 +0000188 }
Cole Faust3552eb62024-11-06 18:07:26 -0800189 if android.InList("vendor", generatedPartitionTypes) {
Spandan Dase3b65312024-10-22 00:27:27 +0000190 partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor"))
191 }
Cole Faust3552eb62024-11-06 18:07:26 -0800192 if android.InList("product", generatedPartitionTypes) {
Jihoon Kang6dd13b62024-10-22 23:21:02 +0000193 partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product"))
194 }
Cole Faust3552eb62024-11-06 18:07:26 -0800195 if android.InList("odm", generatedPartitionTypes) {
Spandan Dasc5717162024-11-01 18:33:57 +0000196 partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm"))
197 }
mrziwang23ba8762024-11-07 16:21:53 -0800198 if android.InList("userdata", f.properties.Generated_partition_types) {
199 partitionProps.Userdata_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "userdata"))
200 }
Cole Faust3552eb62024-11-06 18:07:26 -0800201 partitionProps.Vbmeta_partitions = vbmetaPartitions
Jihoon Kangf1c79ca2024-10-09 20:18:38 +0000202
203 ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps)
Cole Faust92ccbe22024-10-03 14:38:37 -0700204}
205
Jihoon Kangd098d442024-11-19 00:03:22 +0000206func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionVars android.PartitionVariables, partitionType string) {
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000207 switch partitionType {
208 case "system":
209 fsProps.Build_logtags = proptools.BoolPtr(true)
210 // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0
211 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Justin Yuned3dbce2024-11-15 11:57:24 +0900212 // Identical to that of the aosp_shared_system_image
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000213 fsProps.Fsverity.Inputs = []string{
214 "etc/boot-image.prof",
215 "etc/dirty-image-objects",
216 "etc/preloaded-classes",
217 "etc/classpaths/*.pb",
218 "framework/*",
219 "framework/*/*", // framework/{arch}
220 "framework/oat/*/*", // framework/oat/{arch}
221 }
222 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
mrziwang9afc2982024-11-05 14:29:48 -0800223 // TODO(b/377734331): only generate the symlinks if the relevant partitions exist
224 fsProps.Symlinks = []filesystem.SymlinkDefinition{
225 filesystem.SymlinkDefinition{
226 Target: proptools.StringPtr("/product"),
227 Name: proptools.StringPtr("system/product"),
228 },
229 filesystem.SymlinkDefinition{
230 Target: proptools.StringPtr("/system_ext"),
231 Name: proptools.StringPtr("system/system_ext"),
232 },
233 filesystem.SymlinkDefinition{
234 Target: proptools.StringPtr("/vendor"),
235 Name: proptools.StringPtr("system/vendor"),
236 },
237 filesystem.SymlinkDefinition{
238 Target: proptools.StringPtr("/system_dlkm/lib/modules"),
239 Name: proptools.StringPtr("system/lib/modules"),
240 },
241 }
Spandan Dasa8fa6b42024-10-23 00:45:29 +0000242 case "system_ext":
243 fsProps.Fsverity.Inputs = []string{
244 "framework/*",
245 "framework/*/*", // framework/{arch}
246 "framework/oat/*/*", // framework/oat/{arch}
247 }
248 fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"}
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000249 case "product":
250 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
251 case "vendor":
252 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
Spandan Das69464c32024-10-25 20:08:06 +0000253 fsProps.Symlinks = []filesystem.SymlinkDefinition{
254 filesystem.SymlinkDefinition{
255 Target: proptools.StringPtr("/odm"),
256 Name: proptools.StringPtr("vendor/odm"),
257 },
258 filesystem.SymlinkDefinition{
259 Target: proptools.StringPtr("/vendor_dlkm/lib/modules"),
260 Name: proptools.StringPtr("vendor/lib/modules"),
261 },
262 }
Spandan Dasc5717162024-11-01 18:33:57 +0000263 case "odm":
264 fsProps.Symlinks = []filesystem.SymlinkDefinition{
265 filesystem.SymlinkDefinition{
266 Target: proptools.StringPtr("/odm_dlkm/lib/modules"),
267 Name: proptools.StringPtr("odm/lib/modules"),
268 },
269 }
mrziwang23ba8762024-11-07 16:21:53 -0800270 case "userdata":
271 fsProps.Base_dir = proptools.StringPtr("data")
Jihoon Kangd098d442024-11-19 00:03:22 +0000272 case "ramdisk":
273 // Following the logic in https://cs.android.com/android/platform/superproject/main/+/c3c5063df32748a8806ce5da5dd0db158eab9ad9:build/make/core/Makefile;l=1307
274 fsProps.Dirs = android.NewSimpleConfigurable([]string{
275 "debug_ramdisk",
276 "dev",
277 "metadata",
278 "mnt",
279 "proc",
280 "second_stage_resources",
281 "sys",
282 })
283 if partitionVars.BoardUsesGenericKernelImage {
284 fsProps.Dirs.AppendSimpleValue([]string{
285 "first_stage_ramdisk/debug_ramdisk",
286 "first_stage_ramdisk/dev",
287 "first_stage_ramdisk/metadata",
288 "first_stage_ramdisk/mnt",
289 "first_stage_ramdisk/proc",
290 "first_stage_ramdisk/second_stage_resources",
291 "first_stage_ramdisk/sys",
292 })
293 }
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000294 }
295}
Spandan Dascbe641a2024-10-14 21:07:34 +0000296
Spandan Das5b493cd2024-11-07 20:55:56 +0000297var (
298 dlkmPartitions = []string{
299 "system_dlkm",
300 "vendor_dlkm",
301 "odm_dlkm",
302 }
303)
304
Cole Faust92ccbe22024-10-03 14:38:37 -0700305// Creates a soong module to build the given partition. Returns false if we can't support building
306// it.
307func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool {
mrziwang4b0ca972024-10-17 14:56:19 -0700308 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
309
310 fsProps, supported := generateFsProps(ctx, partitionType)
311 if !supported {
312 return false
mrziwanga077b942024-10-16 16:00:06 -0700313 }
mrziwanga077b942024-10-16 16:00:06 -0700314
Spandan Das8fe68dc2024-10-29 18:20:11 +0000315 if partitionType == "vendor" || partitionType == "product" {
Spandan Das2047a4c2024-11-11 21:24:58 +0000316 fsProps.Linker_config.Gen_linker_config = proptools.BoolPtr(true)
317 fsProps.Linker_config.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType)
Spandan Das312cc412024-10-29 18:20:11 +0000318 }
319
Spandan Das5b493cd2024-11-07 20:55:56 +0000320 if android.InList(partitionType, dlkmPartitions) {
321 f.createPrebuiltKernelModules(ctx, partitionType)
Spandan Das5e336422024-11-01 22:31:20 +0000322 }
323
mrziwang4b0ca972024-10-17 14:56:19 -0700324 var module android.Module
325 if partitionType == "system" {
326 module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
327 } else {
328 // Explicitly set the partition.
329 fsProps.Partition_type = proptools.StringPtr(partitionType)
330 module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps)
331 }
332 module.HideFromMake()
Spandan Das168098c2024-10-28 19:44:34 +0000333 if partitionType == "vendor" {
Spandan Das4cd93b52024-11-05 23:27:03 +0000334 f.createVendorBuildProp(ctx)
Spandan Das168098c2024-10-28 19:44:34 +0000335 }
mrziwang4b0ca972024-10-17 14:56:19 -0700336 return true
337}
338
Cole Faust953476f2024-11-14 14:11:29 -0800339// Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH
340func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) {
341 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
342 var files []string
343
344 if len(partitionVars.BoardAvbKeyPath) > 0 {
345 files = append(files, partitionVars.BoardAvbKeyPath)
346 }
347 for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) {
348 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition]
349 if len(specificPartitionVars.BoardAvbKeyPath) > 0 {
350 files = append(files, specificPartitionVars.BoardAvbKeyPath)
351 }
352 }
353
354 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
355 for _, file := range files {
356 if _, ok := fsGenState.avbKeyFilegroups[file]; ok {
357 continue
358 }
359 if file == "external/avb/test/data/testkey_rsa4096.pem" {
360 // There already exists a checked-in filegroup for this commonly-used key, just use that
361 fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096"
362 continue
363 }
364 dir := filepath.Dir(file)
365 base := filepath.Base(file)
366 name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_"))
367 ctx.CreateModuleInDirectory(
368 android.FileGroupFactory,
369 dir,
370 &struct {
371 Name *string
372 Srcs []string
373 Visibility []string
374 }{
375 Name: proptools.StringPtr(name),
376 Srcs: []string{base},
377 Visibility: []string{"//visibility:public"},
378 },
379 )
380 fsGenState.avbKeyFilegroups[file] = name
381 }
382}
383
Spandan Das5e336422024-11-01 22:31:20 +0000384// createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the
Spandan Das7b25a512024-11-06 20:41:26 +0000385// autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency.
386// This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view.
Spandan Das5b493cd2024-11-07 20:55:56 +0000387func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string) {
Spandan Das5e336422024-11-01 22:31:20 +0000388 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Spandan Das7b25a512024-11-06 20:41:26 +0000389 name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType))
390 props := &struct {
Spandan Das912d26b2024-11-06 19:35:17 +0000391 Name *string
392 Srcs []string
Spandan Das5b493cd2024-11-07 20:55:56 +0000393 System_deps []string
Spandan Das912d26b2024-11-06 19:35:17 +0000394 System_dlkm_specific *bool
Spandan Das5b493cd2024-11-07 20:55:56 +0000395 Vendor_dlkm_specific *bool
396 Odm_dlkm_specific *bool
397 Load_by_default *bool
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000398 Blocklist_file *string
Spandan Das7b25a512024-11-06 20:41:26 +0000399 }{
400 Name: proptools.StringPtr(name),
Spandan Das5e336422024-11-01 22:31:20 +0000401 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000402 switch partitionType {
403 case "system_dlkm":
Spandan Das59ee5d72024-11-18 19:36:32 +0000404 props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules).Strings()
Spandan Das912d26b2024-11-06 19:35:17 +0000405 props.System_dlkm_specific = proptools.BoolPtr(true)
Spandan Das5b493cd2024-11-07 20:55:56 +0000406 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelLoadModules) == 0 {
407 // Create empty modules.load file for system
408 // https://source.corp.google.com/h/googleplex-android/platform/build/+/ef55daac9954896161b26db4f3ef1781b5a5694c:core/Makefile;l=695-700;drc=549fe2a5162548bd8b47867d35f907eb22332023;bpv=1;bpt=0
409 props.Load_by_default = proptools.BoolPtr(false)
410 }
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000411 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelBlocklistFile; blocklistFile != "" {
412 props.Blocklist_file = proptools.StringPtr(blocklistFile)
413 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000414 case "vendor_dlkm":
Spandan Das59ee5d72024-11-18 19:36:32 +0000415 props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelModules).Strings()
Spandan Das5b493cd2024-11-07 20:55:56 +0000416 if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules) > 0 {
417 props.System_deps = []string{":" + generatedModuleName(ctx.Config(), "system_dlkm-kernel-modules") + "{.modules}"}
418 }
419 props.Vendor_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000420 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelBlocklistFile; blocklistFile != "" {
421 props.Blocklist_file = proptools.StringPtr(blocklistFile)
422 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000423 case "odm_dlkm":
Spandan Das59ee5d72024-11-18 19:36:32 +0000424 props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelModules).Strings()
Spandan Das5b493cd2024-11-07 20:55:56 +0000425 props.Odm_dlkm_specific = proptools.BoolPtr(true)
Spandan Das6dfcbdf2024-11-11 18:43:07 +0000426 if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" {
427 props.Blocklist_file = proptools.StringPtr(blocklistFile)
428 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000429 default:
430 ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType)
Spandan Das912d26b2024-11-06 19:35:17 +0000431 }
Spandan Das5b493cd2024-11-07 20:55:56 +0000432
433 if len(props.Srcs) == 0 {
434 return // do not generate `prebuilt_kernel_modules` if there are no sources
435 }
436
Spandan Das7b25a512024-11-06 20:41:26 +0000437 kernelModule := ctx.CreateModuleInDirectory(
438 kernel.PrebuiltKernelModulesFactory,
439 ".", // create in root directory for now
440 props,
441 )
442 kernelModule.HideFromMake()
443 // Add to deps
444 (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config())
Spandan Das5e336422024-11-01 22:31:20 +0000445}
446
Spandan Das4cd93b52024-11-05 23:27:03 +0000447// Create a build_prop and android_info module. This will be used to create /vendor/build.prop
448func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) {
449 // Create a android_info for vendor
450 // The board info files might be in a directory outside the root soong namespace, so create
451 // the module in "."
452 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
453 androidInfoProps := &struct {
454 Name *string
455 Board_info_files []string
456 Bootloader_board_name *string
457 }{
458 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")),
459 Board_info_files: partitionVars.BoardInfoFiles,
460 }
461 if len(androidInfoProps.Board_info_files) == 0 {
462 androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName)
463 }
464 androidInfoProp := ctx.CreateModuleInDirectory(
465 android.AndroidInfoFactory,
466 ".",
467 androidInfoProps,
468 )
469 androidInfoProp.HideFromMake()
470 // Create a build prop for vendor
471 vendorBuildProps := &struct {
472 Name *string
473 Vendor *bool
474 Stem *string
475 Product_config *string
476 Android_info *string
477 }{
478 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")),
479 Vendor: proptools.BoolPtr(true),
480 Stem: proptools.StringPtr("build.prop"),
481 Product_config: proptools.StringPtr(":product_config"),
482 Android_info: proptools.StringPtr(":" + androidInfoProp.Name()),
483 }
484 vendorBuildProp := ctx.CreateModule(
485 android.BuildPropFactory,
486 vendorBuildProps,
487 )
488 vendorBuildProp.HideFromMake()
489}
490
Spandan Das8fe68dc2024-10-29 18:20:11 +0000491// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions
492// 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list)
493// 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list)
494// It creates a filegroup for each file in the fragment list
Spandan Das312cc412024-10-29 18:20:11 +0000495// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
Spandan Das8fe68dc2024-10-29 18:20:11 +0000496func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string {
Spandan Das312cc412024-10-29 18:20:11 +0000497 ret := []string{}
498 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Spandan Das8fe68dc2024-10-29 18:20:11 +0000499 var linkerConfigSrcs []string
500 if partitionType == "vendor" {
501 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs)
502 } else if partitionType == "product" {
503 linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs)
504 } else {
505 ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`")
506 }
507
508 if len(linkerConfigSrcs) > 0 {
Spandan Das312cc412024-10-29 18:20:11 +0000509 // Create a filegroup, and add `:<filegroup_name>` to ret.
510 for index, linkerConfigSrc := range linkerConfigSrcs {
511 dir := filepath.Dir(linkerConfigSrc)
512 base := filepath.Base(linkerConfigSrc)
Spandan Das8fe68dc2024-10-29 18:20:11 +0000513 fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index)))
Spandan Das312cc412024-10-29 18:20:11 +0000514 srcs := []string{base}
515 fgProps := &struct {
516 Name *string
517 Srcs proptools.Configurable[[]string]
518 }{
519 Name: proptools.StringPtr(fgName),
520 Srcs: proptools.NewSimpleConfigurable(srcs),
521 }
522 ctx.CreateModuleInDirectory(
523 android.FileGroupFactory,
524 dir,
525 fgProps,
526 )
527 ret = append(ret, ":"+fgName)
528 }
529 }
530 return ret
531}
532
mrziwang4b0ca972024-10-17 14:56:19 -0700533type filesystemBaseProperty struct {
534 Name *string
535 Compile_multilib *string
Cole Faust3552eb62024-11-06 18:07:26 -0800536 Visibility []string
mrziwang4b0ca972024-10-17 14:56:19 -0700537}
538
539func generateBaseProps(namePtr *string) *filesystemBaseProperty {
540 return &filesystemBaseProperty{
541 Name: namePtr,
542 Compile_multilib: proptools.StringPtr("both"),
Cole Faust3552eb62024-11-06 18:07:26 -0800543 // The vbmeta modules are currently in the root directory and depend on the partitions
544 Visibility: []string{"//.", "//build/soong:__subpackages__"},
mrziwang4b0ca972024-10-17 14:56:19 -0700545 }
546}
547
548func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) {
Cole Faust953476f2024-11-14 14:11:29 -0800549 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
Cole Faust92ccbe22024-10-03 14:38:37 -0700550 fsProps := &filesystem.FilesystemProperties{}
551
mrziwang4b0ca972024-10-17 14:56:19 -0700552 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
Cole Faust76a6e952024-11-07 16:56:45 -0800553 var boardAvbEnable bool
Cole Faust953476f2024-11-14 14:11:29 -0800554 var boardAvbKeyPath string
555 var boardAvbAlgorithm string
556 var boardAvbRollbackIndex string
Cole Faust76a6e952024-11-07 16:56:45 -0800557 var fsType string
558 if strings.Contains(partitionType, "ramdisk") {
559 fsType = "compressed_cpio"
560 } else {
Cole Faust953476f2024-11-14 14:11:29 -0800561 specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType]
Cole Faust76a6e952024-11-07 16:56:45 -0800562 fsType = specificPartitionVars.BoardFileSystemType
Cole Faust953476f2024-11-14 14:11:29 -0800563 boardAvbEnable = partitionVars.BoardAvbEnable
564 boardAvbKeyPath = specificPartitionVars.BoardAvbKeyPath
565 boardAvbAlgorithm = specificPartitionVars.BoardAvbAlgorithm
566 boardAvbRollbackIndex = specificPartitionVars.BoardAvbRollbackIndex
567 if boardAvbEnable {
568 if boardAvbKeyPath == "" {
569 boardAvbKeyPath = partitionVars.BoardAvbKeyPath
570 }
571 if boardAvbAlgorithm == "" {
572 boardAvbAlgorithm = partitionVars.BoardAvbAlgorithm
573 }
574 if boardAvbRollbackIndex == "" {
575 boardAvbRollbackIndex = partitionVars.BoardAvbRollbackIndex
576 }
577 }
578 if fsType == "" {
579 fsType = "ext4" //default
580 }
Cole Faust76a6e952024-11-07 16:56:45 -0800581 }
Cole Faust953476f2024-11-14 14:11:29 -0800582 if boardAvbKeyPath != "" {
583 boardAvbKeyPath = ":" + fsGenState.avbKeyFilegroups[boardAvbKeyPath]
mrziwang4b0ca972024-10-17 14:56:19 -0700584 }
Cole Faust76a6e952024-11-07 16:56:45 -0800585
mrziwang4b0ca972024-10-17 14:56:19 -0700586 fsProps.Type = proptools.StringPtr(fsType)
587 if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() {
588 // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs
589 return nil, false
590 }
591
Cole Faust92ccbe22024-10-03 14:38:37 -0700592 // Don't build this module on checkbuilds, the soong-built partitions are still in-progress
593 // and sometimes don't build.
594 fsProps.Unchecked_module = proptools.BoolPtr(true)
595
Jihoon Kang98047cf2024-10-02 17:13:54 +0000596 // BOARD_AVB_ENABLE
Cole Faust76a6e952024-11-07 16:56:45 -0800597 fsProps.Use_avb = proptools.BoolPtr(boardAvbEnable)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000598 // BOARD_AVB_KEY_PATH
Cole Faust953476f2024-11-14 14:11:29 -0800599 fsProps.Avb_private_key = proptools.StringPtr(boardAvbKeyPath)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000600 // BOARD_AVB_ALGORITHM
Cole Faust953476f2024-11-14 14:11:29 -0800601 fsProps.Avb_algorithm = proptools.StringPtr(boardAvbAlgorithm)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000602 // BOARD_AVB_SYSTEM_ROLLBACK_INDEX
Cole Faust953476f2024-11-14 14:11:29 -0800603 if rollbackIndex, err := strconv.ParseInt(boardAvbRollbackIndex, 10, 64); err == nil {
Jihoon Kang98047cf2024-10-02 17:13:54 +0000604 fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex)
605 }
606
Cole Faust92ccbe22024-10-03 14:38:37 -0700607 fsProps.Partition_name = proptools.StringPtr(partitionType)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000608
Cole Faust68382192024-11-19 10:36:03 -0800609 if !strings.Contains(partitionType, "ramdisk") {
610 fsProps.Base_dir = proptools.StringPtr(partitionType)
611 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000612
Jihoon Kang0d545b82024-10-11 00:21:57 +0000613 fsProps.Is_auto_generated = proptools.BoolPtr(true)
614
Jihoon Kangd098d442024-11-19 00:03:22 +0000615 partitionSpecificFsProps(fsProps, partitionVars, partitionType)
Jihoon Kang6850d8f2024-10-17 20:45:58 +0000616
Jihoon Kang98047cf2024-10-02 17:13:54 +0000617 // system_image properties that are not set:
618 // - filesystemProperties.Avb_hash_algorithm
619 // - filesystemProperties.File_contexts
620 // - filesystemProperties.Dirs
621 // - filesystemProperties.Symlinks
622 // - filesystemProperties.Fake_timestamp
623 // - filesystemProperties.Uuid
624 // - filesystemProperties.Mount_point
625 // - filesystemProperties.Include_make_built_files
626 // - filesystemProperties.Build_logtags
Jihoon Kang98047cf2024-10-02 17:13:54 +0000627 // - systemImageProperties.Linker_config_src
mrziwang4b0ca972024-10-17 14:56:19 -0700628
629 return fsProps, true
Cole Faust92ccbe22024-10-03 14:38:37 -0700630}
631
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800632func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000633 partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
Cole Faust92ccbe22024-10-03 14:38:37 -0700634 systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
635 filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
636 if !ok {
637 ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName)
638 }
639 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 +0000640 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName))
Cole Faust92ccbe22024-10-03 14:38:37 -0700641
642 builder := android.NewRuleBuilder(pctx, ctx)
643 builder.Command().BuiltTool("file_list_diff").
644 Input(makeFileList).
645 Input(filesystemInfo.FileListFile).
Cole Faust56301572024-11-07 15:22:42 -0800646 Text(partitionModuleName)
Cole Faust92ccbe22024-10-03 14:38:37 -0700647 builder.Command().Text("touch").Output(diffTestResultFile)
648 builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test")
649 return diffTestResultFile
650}
651
652func createFailingCommand(ctx android.ModuleContext, message string) android.Path {
653 hasher := sha256.New()
654 hasher.Write([]byte(message))
655 filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil))
656 file := android.PathForModuleOut(ctx, filename)
657 builder := android.NewRuleBuilder(pctx, ctx)
658 builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message))
659 builder.Command().Text("exit 1 #").Output(file)
660 builder.Build("failing command "+filename, "failing command "+filename)
661 return file
662}
663
Cole Faust3552eb62024-11-06 18:07:26 -0800664func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmetaPartitionName string) android.Path {
665 vbmetaModule := ctx.GetDirectDepWithTag(vbmetaModuleName, generatedVbmetaPartitionDepTag)
666 outputFilesProvider, ok := android.OtherModuleProvider(ctx, vbmetaModule, android.OutputFilesProvider)
667 if !ok {
668 ctx.ModuleErrorf("Expected module %s to provide OutputFiles", vbmetaModule)
669 }
670 if len(outputFilesProvider.DefaultOutputFiles) != 1 {
671 ctx.ModuleErrorf("Expected 1 output file from module %s", vbmetaModule)
672 }
673 soongVbMetaFile := outputFilesProvider.DefaultOutputFiles[0]
674 makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName))
675
676 diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName))
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800677 createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile)
678 return diffTestResultFile
679}
680
681func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) {
Cole Faust3552eb62024-11-06 18:07:26 -0800682 builder := android.NewRuleBuilder(pctx, ctx)
683 builder.Command().Text("diff").
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800684 Input(file1).
685 Input(file2)
Cole Faust3552eb62024-11-06 18:07:26 -0800686 builder.Command().Text("touch").Output(diffTestResultFile)
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800687 builder.Build("diff test "+diffTestResultFile.String(), "diff test")
Cole Faust3552eb62024-11-06 18:07:26 -0800688}
689
Cole Faust92ccbe22024-10-03 14:38:37 -0700690type systemImageDepTagType struct {
691 blueprint.BaseDependencyTag
692}
693
694var generatedFilesystemDepTag systemImageDepTagType
Cole Faust3552eb62024-11-06 18:07:26 -0800695var generatedVbmetaPartitionDepTag systemImageDepTagType
Cole Faust92ccbe22024-10-03 14:38:37 -0700696
697func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) {
698 for _, partitionType := range f.properties.Generated_partition_types {
Jihoon Kang0d545b82024-10-11 00:21:57 +0000699 ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType))
Cole Faust92ccbe22024-10-03 14:38:37 -0700700 }
Cole Faust3552eb62024-11-06 18:07:26 -0800701 for _, vbmetaModule := range f.properties.Vbmeta_module_names {
702 ctx.AddDependency(ctx.Module(), generatedVbmetaPartitionDepTag, vbmetaModule)
703 }
Jihoon Kang98047cf2024-10-02 17:13:54 +0000704}
705
706func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Cole Faust92ccbe22024-10-03 14:38:37 -0700707 if ctx.ModuleDir() != "build/soong/fsgen" {
708 ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen")
709 }
710 f.HideFromMake()
Jihoon Kang98047cf2024-10-02 17:13:54 +0000711
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000712 var content strings.Builder
713 generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp")
714 for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions {
715 content.WriteString(generateBpContent(ctx, partition))
716 content.WriteString("\n")
717 }
718 android.WriteFileRule(ctx, generatedBp, content.String())
719
mrziwang8f86c882024-10-03 12:34:33 -0700720 ctx.Phony("product_config_to_bp", generatedBp)
721
Cole Faust92ccbe22024-10-03 14:38:37 -0700722 var diffTestFiles []android.Path
723 for _, partitionType := range f.properties.Generated_partition_types {
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800724 diffTestFile := f.createFileListDiffTest(ctx, partitionType)
Jihoon Kang72f812f2024-10-17 18:46:24 +0000725 diffTestFiles = append(diffTestFiles, diffTestFile)
726 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700727 }
728 for _, partitionType := range f.properties.Unsupported_partition_types {
Jihoon Kang72f812f2024-10-17 18:46:24 +0000729 diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType))
730 diffTestFiles = append(diffTestFiles, diffTestFile)
731 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile)
Cole Faust92ccbe22024-10-03 14:38:37 -0700732 }
Cole Faust3552eb62024-11-06 18:07:26 -0800733 for i, vbmetaModule := range f.properties.Vbmeta_module_names {
734 diffTestFile := createVbmetaDiff(ctx, vbmetaModule, f.properties.Vbmeta_partition_names[i])
735 diffTestFiles = append(diffTestFiles, diffTestFile)
736 ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile)
737 }
Cole Faustf2a6e8b2024-11-14 10:54:48 -0800738 if f.properties.Boot_image != "" {
739 diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt")
740 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image)
741 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName()))
742 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
743 diffTestFiles = append(diffTestFiles, diffTestFile)
744 ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile)
745 }
Cole Faust24938e22024-11-18 14:01:58 -0800746 if f.properties.Vendor_boot_image != "" {
747 diffTestFile := android.PathForModuleOut(ctx, "vendor_boot_diff_test.txt")
Jihoon Kang95eb1da2024-11-19 20:55:20 +0000748 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Vendor_boot_image)
Cole Faust24938e22024-11-18 14:01:58 -0800749 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/vendor_boot.img", ctx.Config().DeviceName()))
750 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
751 diffTestFiles = append(diffTestFiles, diffTestFile)
752 ctx.Phony("soong_generated_vendor_boot_filesystem_test", diffTestFile)
753 }
Jihoon Kang95eb1da2024-11-19 20:55:20 +0000754 if f.properties.Init_boot_image != "" {
755 diffTestFile := android.PathForModuleOut(ctx, "init_boot_diff_test.txt")
756 soongBootImg := android.PathForModuleSrc(ctx, f.properties.Init_boot_image)
757 makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/init_boot.img", ctx.Config().DeviceName()))
758 createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage)
759 diffTestFiles = append(diffTestFiles, diffTestFile)
760 ctx.Phony("soong_generated_init_boot_filesystem_test", diffTestFile)
761 }
Cole Faust92ccbe22024-10-03 14:38:37 -0700762 ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000763}
mrziwang8f86c882024-10-03 12:34:33 -0700764
mrziwang8f86c882024-10-03 12:34:33 -0700765func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string {
mrziwang4b0ca972024-10-17 14:56:19 -0700766 fsProps, fsTypeSupported := generateFsProps(ctx, partitionType)
767 if !fsTypeSupported {
768 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700769 }
770
mrziwang4b0ca972024-10-17 14:56:19 -0700771 baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)))
Jihoon Kang0d7b0112024-11-13 20:44:05 +0000772 fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState)
773 deps := fsGenState.fsDeps[partitionType]
774 highPriorityDeps := fsGenState.generatedPrebuiltEtcModuleNames
775 depProps := generateDepStruct(*deps, highPriorityDeps)
mrziwang8f86c882024-10-03 12:34:33 -0700776
mrziwang4b0ca972024-10-17 14:56:19 -0700777 result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps})
mrziwang8f86c882024-10-03 12:34:33 -0700778 if err != nil {
Cole Faustae3e1d32024-11-05 13:22:50 -0800779 ctx.ModuleErrorf("%s", err.Error())
780 return ""
mrziwang8f86c882024-10-03 12:34:33 -0700781 }
782
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000783 moduleType := "android_filesystem"
784 if partitionType == "system" {
785 moduleType = "android_system_image"
786 }
787
mrziwang8f86c882024-10-03 12:34:33 -0700788 file := &parser.File{
789 Defs: []parser.Definition{
790 &parser.Module{
Jihoon Kang4e5d8de2024-10-19 01:59:58 +0000791 Type: moduleType,
mrziwang8f86c882024-10-03 12:34:33 -0700792 Map: *result,
793 },
794 },
795 }
796 bytes, err := parser.Print(file)
797 if err != nil {
798 ctx.ModuleErrorf(err.Error())
799 }
800 return strings.TrimSpace(string(bytes))
801}