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