Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package fsgen |
| 16 | |
| 17 | import ( |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 18 | "crypto/sha256" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 19 | "fmt" |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 20 | "path/filepath" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 21 | "strconv" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 22 | "strings" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 23 | |
| 24 | "android/soong/android" |
| 25 | "android/soong/filesystem" |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 26 | "android/soong/kernel" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 27 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint/parser" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 33 | var pctx = android.NewPackageContext("android/soong/fsgen") |
| 34 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 35 | func init() { |
| 36 | registerBuildComponents(android.InitRegistrationContext) |
| 37 | } |
| 38 | |
| 39 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 40 | ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 41 | ctx.PreDepsMutators(RegisterCollectFileSystemDepsMutators) |
| 42 | } |
| 43 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 44 | type filesystemCreatorProps struct { |
| 45 | Generated_partition_types []string `blueprint:"mutated"` |
| 46 | Unsupported_partition_types []string `blueprint:"mutated"` |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 47 | |
| 48 | Vbmeta_module_names []string `blueprint:"mutated"` |
| 49 | Vbmeta_partition_names []string `blueprint:"mutated"` |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 50 | |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 51 | Boot_image string `blueprint:"mutated" android:"path_device_first"` |
| 52 | Vendor_boot_image string `blueprint:"mutated" android:"path_device_first"` |
Jihoon Kang | 95eb1da | 2024-11-19 20:55:20 +0000 | [diff] [blame] | 53 | Init_boot_image string `blueprint:"mutated" android:"path_device_first"` |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 56 | type filesystemCreator struct { |
| 57 | android.ModuleBase |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 58 | |
| 59 | properties filesystemCreatorProps |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | func filesystemCreatorFactory() android.Module { |
| 63 | module := &filesystemCreator{} |
| 64 | |
Cole Faust | 6978879 | 2024-10-10 11:00:36 -0700 | [diff] [blame] | 65 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 66 | module.AddProperties(&module.properties) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 67 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
Jihoon Kang | 675d468 | 2024-10-24 23:45:11 +0000 | [diff] [blame] | 68 | generatedPrebuiltEtcModuleNames := createPrebuiltEtcModules(ctx) |
Jihoon Kang | 04f12c9 | 2024-11-12 23:03:08 +0000 | [diff] [blame] | 69 | avbpubkeyGenerated := createAvbpubkeyModule(ctx) |
| 70 | createFsGenState(ctx, generatedPrebuiltEtcModuleNames, avbpubkeyGenerated) |
Cole Faust | 953476f | 2024-11-14 14:11:29 -0800 | [diff] [blame] | 71 | module.createAvbKeyFilegroups(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 72 | module.createInternalModules(ctx) |
| 73 | }) |
| 74 | |
| 75 | return module |
| 76 | } |
| 77 | |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 78 | func generatedPartitions(ctx android.LoadHookContext) []string { |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 79 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 80 | 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 Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 96 | if partitionVars.BuildingSystemDlkmImage { |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 97 | generatedPartitions = append(generatedPartitions, "system_dlkm") |
| 98 | } |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 99 | if partitionVars.BuildingVendorDlkmImage { |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 100 | generatedPartitions = append(generatedPartitions, "vendor_dlkm") |
| 101 | } |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 102 | if partitionVars.BuildingOdmDlkmImage { |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 103 | generatedPartitions = append(generatedPartitions, "odm_dlkm") |
| 104 | } |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 105 | if partitionVars.BuildingRamdiskImage { |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 106 | generatedPartitions = append(generatedPartitions, "ramdisk") |
| 107 | } |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 108 | if buildingVendorBootImage(partitionVars) { |
| 109 | generatedPartitions = append(generatedPartitions, "vendor_ramdisk") |
| 110 | } |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 111 | return generatedPartitions |
| 112 | } |
| 113 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 114 | func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 115 | soongGeneratedPartitions := generatedPartitions(ctx) |
| 116 | finalSoongGeneratedPartitions := make([]string, 0, len(soongGeneratedPartitions)) |
| 117 | for _, partitionType := range soongGeneratedPartitions { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 118 | if f.createPartition(ctx, partitionType) { |
| 119 | f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType) |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 120 | finalSoongGeneratedPartitions = append(finalSoongGeneratedPartitions, partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 121 | } else { |
| 122 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, partitionType) |
| 123 | } |
| 124 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 125 | |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 126 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Jihoon Kang | 70c1c68 | 2024-11-20 23:58:38 +0000 | [diff] [blame] | 127 | dtbImg := createDtbImgFilegroup(ctx) |
| 128 | |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 129 | if buildingBootImage(partitionVars) { |
Jihoon Kang | 70c1c68 | 2024-11-20 23:58:38 +0000 | [diff] [blame] | 130 | if createBootImage(ctx, dtbImg) { |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 131 | f.properties.Boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "boot") |
| 132 | } else { |
| 133 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "boot") |
| 134 | } |
| 135 | } |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 136 | if buildingVendorBootImage(partitionVars) { |
Jihoon Kang | 70c1c68 | 2024-11-20 23:58:38 +0000 | [diff] [blame] | 137 | if createVendorBootImage(ctx, dtbImg) { |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 138 | f.properties.Vendor_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "vendor_boot") |
| 139 | } else { |
| 140 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "vendor_boot") |
| 141 | } |
| 142 | } |
Jihoon Kang | 95eb1da | 2024-11-19 20:55:20 +0000 | [diff] [blame] | 143 | if buildingInitBootImage(partitionVars) { |
| 144 | if createInitBootImage(ctx) { |
| 145 | f.properties.Init_boot_image = ":" + generatedModuleNameForPartition(ctx.Config(), "init_boot") |
| 146 | } else { |
| 147 | f.properties.Unsupported_partition_types = append(f.properties.Unsupported_partition_types, "init_boot") |
| 148 | } |
| 149 | } |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 150 | |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 151 | for _, x := range createVbmetaPartitions(ctx, finalSoongGeneratedPartitions) { |
| 152 | f.properties.Vbmeta_module_names = append(f.properties.Vbmeta_module_names, x.moduleName) |
| 153 | f.properties.Vbmeta_partition_names = append(f.properties.Vbmeta_partition_names, x.partitionName) |
| 154 | } |
| 155 | |
| 156 | ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions = finalSoongGeneratedPartitions |
| 157 | f.createDeviceModule(ctx, finalSoongGeneratedPartitions, f.properties.Vbmeta_module_names) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 160 | func generatedModuleName(cfg android.Config, suffix string) string { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 161 | prefix := "soong" |
| 162 | if cfg.HasDeviceProduct() { |
| 163 | prefix = cfg.DeviceProduct() |
| 164 | } |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 165 | return fmt.Sprintf("%s_generated_%s", prefix, suffix) |
| 166 | } |
| 167 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 168 | func generatedModuleNameForPartition(cfg android.Config, partitionType string) string { |
| 169 | return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType)) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 172 | func (f *filesystemCreator) createDeviceModule( |
| 173 | ctx android.LoadHookContext, |
| 174 | generatedPartitionTypes []string, |
| 175 | vbmetaPartitions []string, |
| 176 | ) { |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 177 | baseProps := &struct { |
| 178 | Name *string |
| 179 | }{ |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 180 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")), |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Priyanka Advani (xWF) | dafaa7f | 2024-10-21 22:55:13 +0000 | [diff] [blame] | 183 | // Currently, only the system and system_ext partition module is created. |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 184 | partitionProps := &filesystem.PartitionNameProperties{} |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 185 | if android.InList("system", generatedPartitionTypes) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 186 | partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system")) |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 187 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 188 | if android.InList("system_ext", generatedPartitionTypes) { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 189 | partitionProps.System_ext_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext")) |
Spandan Das | 7a46f6c | 2024-10-14 18:41:18 +0000 | [diff] [blame] | 190 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 191 | if android.InList("vendor", generatedPartitionTypes) { |
Spandan Das | e3b6531 | 2024-10-22 00:27:27 +0000 | [diff] [blame] | 192 | partitionProps.Vendor_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor")) |
| 193 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 194 | if android.InList("product", generatedPartitionTypes) { |
Jihoon Kang | 6dd13b6 | 2024-10-22 23:21:02 +0000 | [diff] [blame] | 195 | partitionProps.Product_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product")) |
| 196 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 197 | if android.InList("odm", generatedPartitionTypes) { |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 198 | partitionProps.Odm_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm")) |
| 199 | } |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 200 | if android.InList("userdata", f.properties.Generated_partition_types) { |
| 201 | partitionProps.Userdata_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "userdata")) |
| 202 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 203 | partitionProps.Vbmeta_partitions = vbmetaPartitions |
Jihoon Kang | f1c79ca | 2024-10-09 20:18:38 +0000 | [diff] [blame] | 204 | |
| 205 | ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Jihoon Kang | d098d44 | 2024-11-19 00:03:22 +0000 | [diff] [blame] | 208 | func partitionSpecificFsProps(fsProps *filesystem.FilesystemProperties, partitionVars android.PartitionVariables, partitionType string) { |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 209 | switch partitionType { |
| 210 | case "system": |
| 211 | fsProps.Build_logtags = proptools.BoolPtr(true) |
| 212 | // https://source.corp.google.com/h/googleplex-android/platform/build//639d79f5012a6542ab1f733b0697db45761ab0f3:core/packaging/flags.mk;l=21;drc=5ba8a8b77507f93aa48cc61c5ba3f31a4d0cbf37;bpv=1;bpt=0 |
| 213 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Justin Yun | ed3dbce | 2024-11-15 11:57:24 +0900 | [diff] [blame] | 214 | // Identical to that of the aosp_shared_system_image |
Spandan Das | a8fa6b4 | 2024-10-23 00:45:29 +0000 | [diff] [blame] | 215 | fsProps.Fsverity.Inputs = []string{ |
| 216 | "etc/boot-image.prof", |
| 217 | "etc/dirty-image-objects", |
| 218 | "etc/preloaded-classes", |
| 219 | "etc/classpaths/*.pb", |
| 220 | "framework/*", |
| 221 | "framework/*/*", // framework/{arch} |
| 222 | "framework/oat/*/*", // framework/oat/{arch} |
| 223 | } |
| 224 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
mrziwang | 9afc298 | 2024-11-05 14:29:48 -0800 | [diff] [blame] | 225 | // TODO(b/377734331): only generate the symlinks if the relevant partitions exist |
| 226 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 227 | filesystem.SymlinkDefinition{ |
| 228 | Target: proptools.StringPtr("/product"), |
| 229 | Name: proptools.StringPtr("system/product"), |
| 230 | }, |
| 231 | filesystem.SymlinkDefinition{ |
| 232 | Target: proptools.StringPtr("/system_ext"), |
| 233 | Name: proptools.StringPtr("system/system_ext"), |
| 234 | }, |
| 235 | filesystem.SymlinkDefinition{ |
| 236 | Target: proptools.StringPtr("/vendor"), |
| 237 | Name: proptools.StringPtr("system/vendor"), |
| 238 | }, |
| 239 | filesystem.SymlinkDefinition{ |
| 240 | Target: proptools.StringPtr("/system_dlkm/lib/modules"), |
| 241 | Name: proptools.StringPtr("system/lib/modules"), |
| 242 | }, |
| 243 | } |
Spandan Das | a8fa6b4 | 2024-10-23 00:45:29 +0000 | [diff] [blame] | 244 | case "system_ext": |
| 245 | fsProps.Fsverity.Inputs = []string{ |
| 246 | "framework/*", |
| 247 | "framework/*/*", // framework/{arch} |
| 248 | "framework/oat/*/*", // framework/oat/{arch} |
| 249 | } |
| 250 | fsProps.Fsverity.Libs = []string{":framework-res{.export-package.apk}"} |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 251 | case "product": |
| 252 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
| 253 | case "vendor": |
| 254 | fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true) |
Spandan Das | 69464c3 | 2024-10-25 20:08:06 +0000 | [diff] [blame] | 255 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 256 | filesystem.SymlinkDefinition{ |
| 257 | Target: proptools.StringPtr("/odm"), |
| 258 | Name: proptools.StringPtr("vendor/odm"), |
| 259 | }, |
| 260 | filesystem.SymlinkDefinition{ |
| 261 | Target: proptools.StringPtr("/vendor_dlkm/lib/modules"), |
| 262 | Name: proptools.StringPtr("vendor/lib/modules"), |
| 263 | }, |
| 264 | } |
Spandan Das | c571716 | 2024-11-01 18:33:57 +0000 | [diff] [blame] | 265 | case "odm": |
| 266 | fsProps.Symlinks = []filesystem.SymlinkDefinition{ |
| 267 | filesystem.SymlinkDefinition{ |
| 268 | Target: proptools.StringPtr("/odm_dlkm/lib/modules"), |
| 269 | Name: proptools.StringPtr("odm/lib/modules"), |
| 270 | }, |
| 271 | } |
mrziwang | 23ba876 | 2024-11-07 16:21:53 -0800 | [diff] [blame] | 272 | case "userdata": |
| 273 | fsProps.Base_dir = proptools.StringPtr("data") |
Jihoon Kang | d098d44 | 2024-11-19 00:03:22 +0000 | [diff] [blame] | 274 | case "ramdisk": |
| 275 | // Following the logic in https://cs.android.com/android/platform/superproject/main/+/c3c5063df32748a8806ce5da5dd0db158eab9ad9:build/make/core/Makefile;l=1307 |
| 276 | fsProps.Dirs = android.NewSimpleConfigurable([]string{ |
| 277 | "debug_ramdisk", |
| 278 | "dev", |
| 279 | "metadata", |
| 280 | "mnt", |
| 281 | "proc", |
| 282 | "second_stage_resources", |
| 283 | "sys", |
| 284 | }) |
| 285 | if partitionVars.BoardUsesGenericKernelImage { |
| 286 | fsProps.Dirs.AppendSimpleValue([]string{ |
| 287 | "first_stage_ramdisk/debug_ramdisk", |
| 288 | "first_stage_ramdisk/dev", |
| 289 | "first_stage_ramdisk/metadata", |
| 290 | "first_stage_ramdisk/mnt", |
| 291 | "first_stage_ramdisk/proc", |
| 292 | "first_stage_ramdisk/second_stage_resources", |
| 293 | "first_stage_ramdisk/sys", |
| 294 | }) |
| 295 | } |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
Spandan Das | cbe641a | 2024-10-14 21:07:34 +0000 | [diff] [blame] | 298 | |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 299 | var ( |
| 300 | dlkmPartitions = []string{ |
| 301 | "system_dlkm", |
| 302 | "vendor_dlkm", |
| 303 | "odm_dlkm", |
| 304 | } |
| 305 | ) |
| 306 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 307 | // Creates a soong module to build the given partition. Returns false if we can't support building |
| 308 | // it. |
| 309 | func (f *filesystemCreator) createPartition(ctx android.LoadHookContext, partitionType string) bool { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 310 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
| 311 | |
| 312 | fsProps, supported := generateFsProps(ctx, partitionType) |
| 313 | if !supported { |
| 314 | return false |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 315 | } |
mrziwang | a077b94 | 2024-10-16 16:00:06 -0700 | [diff] [blame] | 316 | |
Cole Faust | 7db0575 | 2024-11-21 13:30:41 -0800 | [diff] [blame] | 317 | if partitionType == "vendor" || partitionType == "product" || partitionType == "system" { |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 318 | fsProps.Linker_config.Gen_linker_config = proptools.BoolPtr(true) |
Cole Faust | 7db0575 | 2024-11-21 13:30:41 -0800 | [diff] [blame] | 319 | if partitionType != "system" { |
| 320 | fsProps.Linker_config.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx, partitionType) |
| 321 | } |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Jihoon Kang | a8fa071 | 2024-11-26 23:11:07 +0000 | [diff] [blame^] | 324 | if android.InList(partitionType, append(dlkmPartitions, "vendor_ramdisk")) { |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 325 | f.createPrebuiltKernelModules(ctx, partitionType) |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 326 | } |
| 327 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 328 | var module android.Module |
| 329 | if partitionType == "system" { |
| 330 | module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
| 331 | } else { |
| 332 | // Explicitly set the partition. |
| 333 | fsProps.Partition_type = proptools.StringPtr(partitionType) |
| 334 | module = ctx.CreateModule(filesystem.FilesystemFactory, baseProps, fsProps) |
| 335 | } |
| 336 | module.HideFromMake() |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 337 | if partitionType == "vendor" { |
Spandan Das | 4cd93b5 | 2024-11-05 23:27:03 +0000 | [diff] [blame] | 338 | f.createVendorBuildProp(ctx) |
Spandan Das | 168098c | 2024-10-28 19:44:34 +0000 | [diff] [blame] | 339 | } |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 340 | return true |
| 341 | } |
| 342 | |
Cole Faust | 953476f | 2024-11-14 14:11:29 -0800 | [diff] [blame] | 343 | // Creates filegroups for the files specified in BOARD_(partition_)AVB_KEY_PATH |
| 344 | func (f *filesystemCreator) createAvbKeyFilegroups(ctx android.LoadHookContext) { |
| 345 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 346 | var files []string |
| 347 | |
| 348 | if len(partitionVars.BoardAvbKeyPath) > 0 { |
| 349 | files = append(files, partitionVars.BoardAvbKeyPath) |
| 350 | } |
| 351 | for _, partition := range android.SortedKeys(partitionVars.PartitionQualifiedVariables) { |
| 352 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partition] |
| 353 | if len(specificPartitionVars.BoardAvbKeyPath) > 0 { |
| 354 | files = append(files, specificPartitionVars.BoardAvbKeyPath) |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 359 | for _, file := range files { |
| 360 | if _, ok := fsGenState.avbKeyFilegroups[file]; ok { |
| 361 | continue |
| 362 | } |
| 363 | if file == "external/avb/test/data/testkey_rsa4096.pem" { |
| 364 | // There already exists a checked-in filegroup for this commonly-used key, just use that |
| 365 | fsGenState.avbKeyFilegroups[file] = "avb_testkey_rsa4096" |
| 366 | continue |
| 367 | } |
| 368 | dir := filepath.Dir(file) |
| 369 | base := filepath.Base(file) |
| 370 | name := fmt.Sprintf("avb_key_%x", strings.ReplaceAll(file, "/", "_")) |
| 371 | ctx.CreateModuleInDirectory( |
| 372 | android.FileGroupFactory, |
| 373 | dir, |
| 374 | &struct { |
| 375 | Name *string |
| 376 | Srcs []string |
| 377 | Visibility []string |
| 378 | }{ |
| 379 | Name: proptools.StringPtr(name), |
| 380 | Srcs: []string{base}, |
| 381 | Visibility: []string{"//visibility:public"}, |
| 382 | }, |
| 383 | ) |
| 384 | fsGenState.avbKeyFilegroups[file] = name |
| 385 | } |
| 386 | } |
| 387 | |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 388 | // createPrebuiltKernelModules creates `prebuilt_kernel_modules`. These modules will be added to deps of the |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 389 | // autogenerated *_dlkm filsystem modules. Each _dlkm partition should have a single prebuilt_kernel_modules dependency. |
| 390 | // This ensures that the depmod artifacts (modules.* installed in /lib/modules/) are generated with a complete view. |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 391 | func (f *filesystemCreator) createPrebuiltKernelModules(ctx android.LoadHookContext, partitionType string) { |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 392 | fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 393 | name := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-kernel-modules", partitionType)) |
| 394 | props := &struct { |
Spandan Das | 912d26b | 2024-11-06 19:35:17 +0000 | [diff] [blame] | 395 | Name *string |
| 396 | Srcs []string |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 397 | System_deps []string |
Spandan Das | 912d26b | 2024-11-06 19:35:17 +0000 | [diff] [blame] | 398 | System_dlkm_specific *bool |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 399 | Vendor_dlkm_specific *bool |
| 400 | Odm_dlkm_specific *bool |
Jihoon Kang | a8fa071 | 2024-11-26 23:11:07 +0000 | [diff] [blame^] | 401 | Vendor_ramdisk *bool |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 402 | Load_by_default *bool |
Spandan Das | 6dfcbdf | 2024-11-11 18:43:07 +0000 | [diff] [blame] | 403 | Blocklist_file *string |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 404 | }{ |
| 405 | Name: proptools.StringPtr(name), |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 406 | } |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 407 | switch partitionType { |
| 408 | case "system_dlkm": |
Spandan Das | 59ee5d7 | 2024-11-18 19:36:32 +0000 | [diff] [blame] | 409 | props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules).Strings() |
Spandan Das | 912d26b | 2024-11-06 19:35:17 +0000 | [diff] [blame] | 410 | props.System_dlkm_specific = proptools.BoolPtr(true) |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 411 | if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelLoadModules) == 0 { |
| 412 | // Create empty modules.load file for system |
| 413 | // https://source.corp.google.com/h/googleplex-android/platform/build/+/ef55daac9954896161b26db4f3ef1781b5a5694c:core/Makefile;l=695-700;drc=549fe2a5162548bd8b47867d35f907eb22332023;bpv=1;bpt=0 |
| 414 | props.Load_by_default = proptools.BoolPtr(false) |
| 415 | } |
Spandan Das | 6dfcbdf | 2024-11-11 18:43:07 +0000 | [diff] [blame] | 416 | if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelBlocklistFile; blocklistFile != "" { |
| 417 | props.Blocklist_file = proptools.StringPtr(blocklistFile) |
| 418 | } |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 419 | case "vendor_dlkm": |
Spandan Das | 59ee5d7 | 2024-11-18 19:36:32 +0000 | [diff] [blame] | 420 | props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelModules).Strings() |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 421 | if len(ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.SystemKernelModules) > 0 { |
| 422 | props.System_deps = []string{":" + generatedModuleName(ctx.Config(), "system_dlkm-kernel-modules") + "{.modules}"} |
| 423 | } |
| 424 | props.Vendor_dlkm_specific = proptools.BoolPtr(true) |
Spandan Das | 6dfcbdf | 2024-11-11 18:43:07 +0000 | [diff] [blame] | 425 | if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorKernelBlocklistFile; blocklistFile != "" { |
| 426 | props.Blocklist_file = proptools.StringPtr(blocklistFile) |
| 427 | } |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 428 | case "odm_dlkm": |
Spandan Das | 59ee5d7 | 2024-11-18 19:36:32 +0000 | [diff] [blame] | 429 | props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelModules).Strings() |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 430 | props.Odm_dlkm_specific = proptools.BoolPtr(true) |
Spandan Das | 6dfcbdf | 2024-11-11 18:43:07 +0000 | [diff] [blame] | 431 | if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.OdmKernelBlocklistFile; blocklistFile != "" { |
| 432 | props.Blocklist_file = proptools.StringPtr(blocklistFile) |
| 433 | } |
Jihoon Kang | a8fa071 | 2024-11-26 23:11:07 +0000 | [diff] [blame^] | 434 | case "vendor_ramdisk": |
| 435 | props.Srcs = android.ExistentPathsForSources(ctx, ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorRamdiskKernelModules).Strings() |
| 436 | props.Vendor_ramdisk = proptools.BoolPtr(true) |
| 437 | if blocklistFile := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.VendorRamdiskKernelBlocklistFile; blocklistFile != "" { |
| 438 | props.Blocklist_file = proptools.StringPtr(blocklistFile) |
| 439 | } |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 440 | default: |
| 441 | ctx.ModuleErrorf("DLKM is not supported for %s\n", partitionType) |
Spandan Das | 912d26b | 2024-11-06 19:35:17 +0000 | [diff] [blame] | 442 | } |
Spandan Das | 5b493cd | 2024-11-07 20:55:56 +0000 | [diff] [blame] | 443 | |
| 444 | if len(props.Srcs) == 0 { |
| 445 | return // do not generate `prebuilt_kernel_modules` if there are no sources |
| 446 | } |
| 447 | |
Spandan Das | 7b25a51 | 2024-11-06 20:41:26 +0000 | [diff] [blame] | 448 | kernelModule := ctx.CreateModuleInDirectory( |
| 449 | kernel.PrebuiltKernelModulesFactory, |
| 450 | ".", // create in root directory for now |
| 451 | props, |
| 452 | ) |
| 453 | kernelModule.HideFromMake() |
| 454 | // Add to deps |
| 455 | (*fsGenState.fsDeps[partitionType])[name] = defaultDepCandidateProps(ctx.Config()) |
Spandan Das | 5e33642 | 2024-11-01 22:31:20 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Spandan Das | 4cd93b5 | 2024-11-05 23:27:03 +0000 | [diff] [blame] | 458 | // Create a build_prop and android_info module. This will be used to create /vendor/build.prop |
| 459 | func (f *filesystemCreator) createVendorBuildProp(ctx android.LoadHookContext) { |
| 460 | // Create a android_info for vendor |
| 461 | // The board info files might be in a directory outside the root soong namespace, so create |
| 462 | // the module in "." |
| 463 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 464 | androidInfoProps := &struct { |
| 465 | Name *string |
| 466 | Board_info_files []string |
| 467 | Bootloader_board_name *string |
| 468 | }{ |
| 469 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "android-info.prop")), |
| 470 | Board_info_files: partitionVars.BoardInfoFiles, |
| 471 | } |
| 472 | if len(androidInfoProps.Board_info_files) == 0 { |
| 473 | androidInfoProps.Bootloader_board_name = proptools.StringPtr(partitionVars.BootLoaderBoardName) |
| 474 | } |
| 475 | androidInfoProp := ctx.CreateModuleInDirectory( |
| 476 | android.AndroidInfoFactory, |
| 477 | ".", |
| 478 | androidInfoProps, |
| 479 | ) |
| 480 | androidInfoProp.HideFromMake() |
| 481 | // Create a build prop for vendor |
| 482 | vendorBuildProps := &struct { |
| 483 | Name *string |
| 484 | Vendor *bool |
| 485 | Stem *string |
| 486 | Product_config *string |
| 487 | Android_info *string |
| 488 | }{ |
| 489 | Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "vendor-build.prop")), |
| 490 | Vendor: proptools.BoolPtr(true), |
| 491 | Stem: proptools.StringPtr("build.prop"), |
| 492 | Product_config: proptools.StringPtr(":product_config"), |
| 493 | Android_info: proptools.StringPtr(":" + androidInfoProp.Name()), |
| 494 | } |
| 495 | vendorBuildProp := ctx.CreateModule( |
| 496 | android.BuildPropFactory, |
| 497 | vendorBuildProps, |
| 498 | ) |
| 499 | vendorBuildProp.HideFromMake() |
| 500 | } |
| 501 | |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 502 | // createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for the following partitions |
| 503 | // 1. vendor: Using PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 504 | // 1. product: Using PRODUCT_PRODUCT_LINKER_CONFIG_FRAGMENTS (space separated file list) |
| 505 | // It creates a filegroup for each file in the fragment list |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 506 | // The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`. |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 507 | func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext, partitionType string) []string { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 508 | ret := []string{} |
| 509 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 510 | var linkerConfigSrcs []string |
| 511 | if partitionType == "vendor" { |
| 512 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs) |
| 513 | } else if partitionType == "product" { |
| 514 | linkerConfigSrcs = android.FirstUniqueStrings(partitionVars.ProductLinkerConfigSrcs) |
| 515 | } else { |
| 516 | ctx.ModuleErrorf("linker.config.pb is only supported for vendor and product partitions. For system partition, use `android_system_image`") |
| 517 | } |
| 518 | |
| 519 | if len(linkerConfigSrcs) > 0 { |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 520 | // Create a filegroup, and add `:<filegroup_name>` to ret. |
| 521 | for index, linkerConfigSrc := range linkerConfigSrcs { |
| 522 | dir := filepath.Dir(linkerConfigSrc) |
| 523 | base := filepath.Base(linkerConfigSrc) |
Spandan Das | 8fe68dc | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 524 | fgName := generatedModuleName(ctx.Config(), fmt.Sprintf("%s-linker-config-src%s", partitionType, strconv.Itoa(index))) |
Spandan Das | 312cc41 | 2024-10-29 18:20:11 +0000 | [diff] [blame] | 525 | srcs := []string{base} |
| 526 | fgProps := &struct { |
| 527 | Name *string |
| 528 | Srcs proptools.Configurable[[]string] |
| 529 | }{ |
| 530 | Name: proptools.StringPtr(fgName), |
| 531 | Srcs: proptools.NewSimpleConfigurable(srcs), |
| 532 | } |
| 533 | ctx.CreateModuleInDirectory( |
| 534 | android.FileGroupFactory, |
| 535 | dir, |
| 536 | fgProps, |
| 537 | ) |
| 538 | ret = append(ret, ":"+fgName) |
| 539 | } |
| 540 | } |
| 541 | return ret |
| 542 | } |
| 543 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 544 | type filesystemBaseProperty struct { |
| 545 | Name *string |
| 546 | Compile_multilib *string |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 547 | Visibility []string |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | func generateBaseProps(namePtr *string) *filesystemBaseProperty { |
| 551 | return &filesystemBaseProperty{ |
| 552 | Name: namePtr, |
| 553 | Compile_multilib: proptools.StringPtr("both"), |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 554 | // The vbmeta modules are currently in the root directory and depend on the partitions |
| 555 | Visibility: []string{"//.", "//build/soong:__subpackages__"}, |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
| 559 | func generateFsProps(ctx android.EarlyModuleContext, partitionType string) (*filesystem.FilesystemProperties, bool) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 560 | fsProps := &filesystem.FilesystemProperties{} |
| 561 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 562 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 563 | var avbInfo avbInfo |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 564 | var fsType string |
| 565 | if strings.Contains(partitionType, "ramdisk") { |
| 566 | fsType = "compressed_cpio" |
| 567 | } else { |
Cole Faust | 953476f | 2024-11-14 14:11:29 -0800 | [diff] [blame] | 568 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 569 | fsType = specificPartitionVars.BoardFileSystemType |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 570 | avbInfo = getAvbInfo(ctx.Config(), partitionType) |
Cole Faust | 953476f | 2024-11-14 14:11:29 -0800 | [diff] [blame] | 571 | if fsType == "" { |
| 572 | fsType = "ext4" //default |
| 573 | } |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 574 | } |
Cole Faust | 76a6e95 | 2024-11-07 16:56:45 -0800 | [diff] [blame] | 575 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 576 | fsProps.Type = proptools.StringPtr(fsType) |
| 577 | if filesystem.GetFsTypeFromString(ctx, *fsProps.Type).IsUnknown() { |
| 578 | // Currently the android_filesystem module type only supports a handful of FS types like ext4, erofs |
| 579 | return nil, false |
| 580 | } |
| 581 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 582 | // Don't build this module on checkbuilds, the soong-built partitions are still in-progress |
| 583 | // and sometimes don't build. |
| 584 | fsProps.Unchecked_module = proptools.BoolPtr(true) |
| 585 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 586 | // BOARD_AVB_ENABLE |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 587 | fsProps.Use_avb = avbInfo.avbEnable |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 588 | // BOARD_AVB_KEY_PATH |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 589 | fsProps.Avb_private_key = avbInfo.avbkeyFilegroup |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 590 | // BOARD_AVB_ALGORITHM |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 591 | fsProps.Avb_algorithm = avbInfo.avbAlgorithm |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 592 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 593 | fsProps.Rollback_index = avbInfo.avbRollbackIndex |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 594 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 595 | fsProps.Partition_name = proptools.StringPtr(partitionType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 596 | |
Cole Faust | 6838219 | 2024-11-19 10:36:03 -0800 | [diff] [blame] | 597 | if !strings.Contains(partitionType, "ramdisk") { |
| 598 | fsProps.Base_dir = proptools.StringPtr(partitionType) |
| 599 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 600 | |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 601 | fsProps.Is_auto_generated = proptools.BoolPtr(true) |
| 602 | |
Jihoon Kang | d098d44 | 2024-11-19 00:03:22 +0000 | [diff] [blame] | 603 | partitionSpecificFsProps(fsProps, partitionVars, partitionType) |
Jihoon Kang | 6850d8f | 2024-10-17 20:45:58 +0000 | [diff] [blame] | 604 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 605 | // system_image properties that are not set: |
| 606 | // - filesystemProperties.Avb_hash_algorithm |
| 607 | // - filesystemProperties.File_contexts |
| 608 | // - filesystemProperties.Dirs |
| 609 | // - filesystemProperties.Symlinks |
| 610 | // - filesystemProperties.Fake_timestamp |
| 611 | // - filesystemProperties.Uuid |
| 612 | // - filesystemProperties.Mount_point |
| 613 | // - filesystemProperties.Include_make_built_files |
| 614 | // - filesystemProperties.Build_logtags |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 615 | // - systemImageProperties.Linker_config_src |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 616 | |
| 617 | return fsProps, true |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Cole Faust | 0c4b415 | 2024-11-20 16:42:53 -0800 | [diff] [blame] | 620 | type avbInfo struct { |
| 621 | avbEnable *bool |
| 622 | avbKeyPath *string |
| 623 | avbkeyFilegroup *string |
| 624 | avbAlgorithm *string |
| 625 | avbRollbackIndex *int64 |
| 626 | avbMode *string |
| 627 | } |
| 628 | |
| 629 | func getAvbInfo(config android.Config, partitionType string) avbInfo { |
| 630 | partitionVars := config.ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
| 631 | specificPartitionVars := partitionVars.PartitionQualifiedVariables[partitionType] |
| 632 | var result avbInfo |
| 633 | boardAvbEnable := partitionVars.BoardAvbEnable |
| 634 | if boardAvbEnable { |
| 635 | result.avbEnable = proptools.BoolPtr(true) |
| 636 | if specificPartitionVars.BoardAvbKeyPath != "" { |
| 637 | result.avbKeyPath = proptools.StringPtr(specificPartitionVars.BoardAvbKeyPath) |
| 638 | } else if partitionVars.BoardAvbKeyPath != "" { |
| 639 | result.avbKeyPath = proptools.StringPtr(partitionVars.BoardAvbKeyPath) |
| 640 | } |
| 641 | if specificPartitionVars.BoardAvbAlgorithm != "" { |
| 642 | result.avbAlgorithm = proptools.StringPtr(specificPartitionVars.BoardAvbAlgorithm) |
| 643 | } else if partitionVars.BoardAvbAlgorithm != "" { |
| 644 | result.avbAlgorithm = proptools.StringPtr(partitionVars.BoardAvbAlgorithm) |
| 645 | } |
| 646 | if specificPartitionVars.BoardAvbRollbackIndex != "" { |
| 647 | parsed, err := strconv.ParseInt(specificPartitionVars.BoardAvbRollbackIndex, 10, 64) |
| 648 | if err != nil { |
| 649 | panic(fmt.Sprintf("Rollback index must be an int, got %s", specificPartitionVars.BoardAvbRollbackIndex)) |
| 650 | } |
| 651 | result.avbRollbackIndex = &parsed |
| 652 | } else if partitionVars.BoardAvbRollbackIndex != "" { |
| 653 | parsed, err := strconv.ParseInt(partitionVars.BoardAvbRollbackIndex, 10, 64) |
| 654 | if err != nil { |
| 655 | panic(fmt.Sprintf("Rollback index must be an int, got %s", partitionVars.BoardAvbRollbackIndex)) |
| 656 | } |
| 657 | result.avbRollbackIndex = &parsed |
| 658 | } |
| 659 | result.avbMode = proptools.StringPtr("make_legacy") |
| 660 | } |
| 661 | if result.avbKeyPath != nil { |
| 662 | fsGenState := config.Get(fsGenStateOnceKey).(*FsGenState) |
| 663 | filegroup := fsGenState.avbKeyFilegroups[*result.avbKeyPath] |
| 664 | result.avbkeyFilegroup = proptools.StringPtr(":" + filegroup) |
| 665 | } |
| 666 | return result |
| 667 | } |
| 668 | |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 669 | func (f *filesystemCreator) createFileListDiffTest(ctx android.ModuleContext, partitionType string) android.Path { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 670 | partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 671 | systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag) |
| 672 | filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider) |
| 673 | if !ok { |
| 674 | ctx.ModuleErrorf("Expected module %s to provide FileysystemInfo", partitionModuleName) |
| 675 | } |
| 676 | makeFileList := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partitionType)) |
Jihoon Kang | 9e866c8 | 2024-10-07 22:39:18 +0000 | [diff] [blame] | 677 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", partitionModuleName)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 678 | |
| 679 | builder := android.NewRuleBuilder(pctx, ctx) |
| 680 | builder.Command().BuiltTool("file_list_diff"). |
| 681 | Input(makeFileList). |
| 682 | Input(filesystemInfo.FileListFile). |
Cole Faust | 5630157 | 2024-11-07 15:22:42 -0800 | [diff] [blame] | 683 | Text(partitionModuleName) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 684 | builder.Command().Text("touch").Output(diffTestResultFile) |
| 685 | builder.Build(partitionModuleName+" diff test", partitionModuleName+" diff test") |
| 686 | return diffTestResultFile |
| 687 | } |
| 688 | |
| 689 | func createFailingCommand(ctx android.ModuleContext, message string) android.Path { |
| 690 | hasher := sha256.New() |
| 691 | hasher.Write([]byte(message)) |
| 692 | filename := fmt.Sprintf("failing_command_%x.txt", hasher.Sum(nil)) |
| 693 | file := android.PathForModuleOut(ctx, filename) |
| 694 | builder := android.NewRuleBuilder(pctx, ctx) |
| 695 | builder.Command().Textf("echo %s", proptools.NinjaAndShellEscape(message)) |
| 696 | builder.Command().Text("exit 1 #").Output(file) |
| 697 | builder.Build("failing command "+filename, "failing command "+filename) |
| 698 | return file |
| 699 | } |
| 700 | |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 701 | func createVbmetaDiff(ctx android.ModuleContext, vbmetaModuleName string, vbmetaPartitionName string) android.Path { |
| 702 | vbmetaModule := ctx.GetDirectDepWithTag(vbmetaModuleName, generatedVbmetaPartitionDepTag) |
| 703 | outputFilesProvider, ok := android.OtherModuleProvider(ctx, vbmetaModule, android.OutputFilesProvider) |
| 704 | if !ok { |
| 705 | ctx.ModuleErrorf("Expected module %s to provide OutputFiles", vbmetaModule) |
| 706 | } |
| 707 | if len(outputFilesProvider.DefaultOutputFiles) != 1 { |
| 708 | ctx.ModuleErrorf("Expected 1 output file from module %s", vbmetaModule) |
| 709 | } |
| 710 | soongVbMetaFile := outputFilesProvider.DefaultOutputFiles[0] |
| 711 | makeVbmetaFile := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/%s.img", ctx.Config().DeviceName(), vbmetaPartitionName)) |
| 712 | |
| 713 | diffTestResultFile := android.PathForModuleOut(ctx, fmt.Sprintf("diff_test_%s.txt", vbmetaModuleName)) |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 714 | createDiffTest(ctx, diffTestResultFile, soongVbMetaFile, makeVbmetaFile) |
| 715 | return diffTestResultFile |
| 716 | } |
| 717 | |
| 718 | func createDiffTest(ctx android.ModuleContext, diffTestResultFile android.WritablePath, file1 android.Path, file2 android.Path) { |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 719 | builder := android.NewRuleBuilder(pctx, ctx) |
| 720 | builder.Command().Text("diff"). |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 721 | Input(file1). |
| 722 | Input(file2) |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 723 | builder.Command().Text("touch").Output(diffTestResultFile) |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 724 | builder.Build("diff test "+diffTestResultFile.String(), "diff test") |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 727 | type systemImageDepTagType struct { |
| 728 | blueprint.BaseDependencyTag |
| 729 | } |
| 730 | |
| 731 | var generatedFilesystemDepTag systemImageDepTagType |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 732 | var generatedVbmetaPartitionDepTag systemImageDepTagType |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 733 | |
| 734 | func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 735 | for _, partitionType := range f.properties.Generated_partition_types { |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 736 | ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType)) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 737 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 738 | for _, vbmetaModule := range f.properties.Vbmeta_module_names { |
| 739 | ctx.AddDependency(ctx.Module(), generatedVbmetaPartitionDepTag, vbmetaModule) |
| 740 | } |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 744 | if ctx.ModuleDir() != "build/soong/fsgen" { |
| 745 | ctx.ModuleErrorf("There can only be one soong_filesystem_creator in build/soong/fsgen") |
| 746 | } |
| 747 | f.HideFromMake() |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 748 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 749 | var content strings.Builder |
| 750 | generatedBp := android.PathForModuleOut(ctx, "soong_generated_product_config.bp") |
| 751 | for _, partition := range ctx.Config().Get(fsGenStateOnceKey).(*FsGenState).soongGeneratedPartitions { |
| 752 | content.WriteString(generateBpContent(ctx, partition)) |
| 753 | content.WriteString("\n") |
| 754 | } |
| 755 | android.WriteFileRule(ctx, generatedBp, content.String()) |
| 756 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 757 | ctx.Phony("product_config_to_bp", generatedBp) |
| 758 | |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 759 | var diffTestFiles []android.Path |
| 760 | for _, partitionType := range f.properties.Generated_partition_types { |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 761 | diffTestFile := f.createFileListDiffTest(ctx, partitionType) |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 762 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 763 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 764 | } |
| 765 | for _, partitionType := range f.properties.Unsupported_partition_types { |
Jihoon Kang | 72f812f | 2024-10-17 18:46:24 +0000 | [diff] [blame] | 766 | diffTestFile := createFailingCommand(ctx, fmt.Sprintf("Couldn't build %s partition", partitionType)) |
| 767 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 768 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", partitionType), diffTestFile) |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 769 | } |
Cole Faust | 3552eb6 | 2024-11-06 18:07:26 -0800 | [diff] [blame] | 770 | for i, vbmetaModule := range f.properties.Vbmeta_module_names { |
| 771 | diffTestFile := createVbmetaDiff(ctx, vbmetaModule, f.properties.Vbmeta_partition_names[i]) |
| 772 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 773 | ctx.Phony(fmt.Sprintf("soong_generated_%s_filesystem_test", f.properties.Vbmeta_partition_names[i]), diffTestFile) |
| 774 | } |
Cole Faust | f2a6e8b | 2024-11-14 10:54:48 -0800 | [diff] [blame] | 775 | if f.properties.Boot_image != "" { |
| 776 | diffTestFile := android.PathForModuleOut(ctx, "boot_diff_test.txt") |
| 777 | soongBootImg := android.PathForModuleSrc(ctx, f.properties.Boot_image) |
| 778 | makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/boot.img", ctx.Config().DeviceName())) |
| 779 | createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage) |
| 780 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 781 | ctx.Phony("soong_generated_boot_filesystem_test", diffTestFile) |
| 782 | } |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 783 | if f.properties.Vendor_boot_image != "" { |
| 784 | diffTestFile := android.PathForModuleOut(ctx, "vendor_boot_diff_test.txt") |
Jihoon Kang | 95eb1da | 2024-11-19 20:55:20 +0000 | [diff] [blame] | 785 | soongBootImg := android.PathForModuleSrc(ctx, f.properties.Vendor_boot_image) |
Cole Faust | 24938e2 | 2024-11-18 14:01:58 -0800 | [diff] [blame] | 786 | makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/vendor_boot.img", ctx.Config().DeviceName())) |
| 787 | createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage) |
| 788 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 789 | ctx.Phony("soong_generated_vendor_boot_filesystem_test", diffTestFile) |
| 790 | } |
Jihoon Kang | 95eb1da | 2024-11-19 20:55:20 +0000 | [diff] [blame] | 791 | if f.properties.Init_boot_image != "" { |
| 792 | diffTestFile := android.PathForModuleOut(ctx, "init_boot_diff_test.txt") |
| 793 | soongBootImg := android.PathForModuleSrc(ctx, f.properties.Init_boot_image) |
| 794 | makeBootImage := android.PathForArbitraryOutput(ctx, fmt.Sprintf("target/product/%s/init_boot.img", ctx.Config().DeviceName())) |
| 795 | createDiffTest(ctx, diffTestFile, soongBootImg, makeBootImage) |
| 796 | diffTestFiles = append(diffTestFiles, diffTestFile) |
| 797 | ctx.Phony("soong_generated_init_boot_filesystem_test", diffTestFile) |
| 798 | } |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 799 | ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 800 | } |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 801 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 802 | func generateBpContent(ctx android.EarlyModuleContext, partitionType string) string { |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 803 | fsProps, fsTypeSupported := generateFsProps(ctx, partitionType) |
| 804 | if !fsTypeSupported { |
| 805 | return "" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 806 | } |
| 807 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 808 | baseProps := generateBaseProps(proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType))) |
Jihoon Kang | 0d7b011 | 2024-11-13 20:44:05 +0000 | [diff] [blame] | 809 | fsGenState := ctx.Config().Get(fsGenStateOnceKey).(*FsGenState) |
| 810 | deps := fsGenState.fsDeps[partitionType] |
| 811 | highPriorityDeps := fsGenState.generatedPrebuiltEtcModuleNames |
| 812 | depProps := generateDepStruct(*deps, highPriorityDeps) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 813 | |
mrziwang | 4b0ca97 | 2024-10-17 14:56:19 -0700 | [diff] [blame] | 814 | result, err := proptools.RepackProperties([]interface{}{baseProps, fsProps, depProps}) |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 815 | if err != nil { |
Cole Faust | ae3e1d3 | 2024-11-05 13:22:50 -0800 | [diff] [blame] | 816 | ctx.ModuleErrorf("%s", err.Error()) |
| 817 | return "" |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 820 | moduleType := "android_filesystem" |
| 821 | if partitionType == "system" { |
| 822 | moduleType = "android_system_image" |
| 823 | } |
| 824 | |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 825 | file := &parser.File{ |
| 826 | Defs: []parser.Definition{ |
| 827 | &parser.Module{ |
Jihoon Kang | 4e5d8de | 2024-10-19 01:59:58 +0000 | [diff] [blame] | 828 | Type: moduleType, |
mrziwang | 8f86c88 | 2024-10-03 12:34:33 -0700 | [diff] [blame] | 829 | Map: *result, |
| 830 | }, |
| 831 | }, |
| 832 | } |
| 833 | bytes, err := parser.Print(file) |
| 834 | if err != nil { |
| 835 | ctx.ModuleErrorf(err.Error()) |
| 836 | } |
| 837 | return strings.TrimSpace(string(bytes)) |
| 838 | } |