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