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