mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [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 filesystem |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "path/filepath" |
Cole Faust | 498ffc1 | 2025-01-15 14:19:32 -0800 | [diff] [blame] | 20 | "regexp" |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 21 | "slices" |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 22 | "strconv" |
| 23 | "strings" |
| 24 | |
| 25 | "android/soong/android" |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 26 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 27 | "github.com/google/blueprint" |
| 28 | "github.com/google/blueprint/proptools" |
| 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | android.RegisterModuleType("super_image", SuperImageFactory) |
| 33 | } |
| 34 | |
| 35 | type superImage struct { |
| 36 | android.ModuleBase |
| 37 | |
| 38 | properties SuperImageProperties |
| 39 | partitionProps SuperImagePartitionNameProperties |
| 40 | |
| 41 | installDir android.InstallPath |
| 42 | } |
| 43 | |
| 44 | type SuperImageProperties struct { |
| 45 | // the size of the super partition |
| 46 | Size *int64 |
| 47 | // the block device where metadata for dynamic partitions is stored |
| 48 | Metadata_device *string |
| 49 | // the super partition block device list |
mrziwang | f3c8ddf | 2024-12-05 17:15:11 -0800 | [diff] [blame] | 50 | Block_devices []string |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 51 | // whether A/B updater is used |
| 52 | Ab_update *bool |
| 53 | // whether dynamic partitions is enabled on devices that were launched without this support |
| 54 | Retrofit *bool |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 55 | // whether the output is a sparse image |
| 56 | Sparse *bool |
| 57 | // information about how partitions within the super partition are grouped together |
| 58 | Partition_groups []PartitionGroupsInfo |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 59 | // Name of the system_other partition filesystem module. This module will be installed to |
| 60 | // the "b" slot of the system partition in a/b partition builds. |
| 61 | System_other_partition *string |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 62 | // whether dynamic partitions is used |
| 63 | Use_dynamic_partitions *bool |
Cole Faust | 498ffc1 | 2025-01-15 14:19:32 -0800 | [diff] [blame] | 64 | Virtual_ab struct { |
| 65 | // whether virtual A/B seamless update is enabled |
| 66 | Enable *bool |
| 67 | // whether retrofitting virtual A/B seamless update is enabled |
| 68 | Retrofit *bool |
| 69 | // If set, device uses virtual A/B Compression |
| 70 | Compression *bool |
| 71 | // This value controls the compression algorithm used for VABC. |
| 72 | // Valid options are defined in system/core/fs_mgr/libsnapshot/cow_writer.cpp |
| 73 | // e.g. "none", "gz", "brotli" |
| 74 | Compression_method *string |
| 75 | // Specifies maximum bytes to be compressed at once during ota. Options: 4096, 8192, 16384, 32768, 65536, 131072, 262144. |
| 76 | Compression_factor *int64 |
| 77 | // Specifies COW version to be used by update_engine and libsnapshot. If this value is not |
| 78 | // specified we default to COW version 2 in update_engine for backwards compatibility |
| 79 | Cow_version *int64 |
| 80 | } |
Spandan Das | 9da8a2d | 2025-02-28 07:45:30 +0000 | [diff] [blame] | 81 | // Whether the super image will be disted in the update package |
| 82 | Super_image_in_update_package *bool |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | type PartitionGroupsInfo struct { |
| 86 | Name string |
| 87 | GroupSize string |
| 88 | PartitionList []string |
| 89 | } |
| 90 | |
| 91 | type SuperImagePartitionNameProperties struct { |
| 92 | // Name of the System partition filesystem module |
| 93 | System_partition *string |
| 94 | // Name of the System_ext partition filesystem module |
| 95 | System_ext_partition *string |
| 96 | // Name of the System_dlkm partition filesystem module |
| 97 | System_dlkm_partition *string |
| 98 | // Name of the System_other partition filesystem module |
| 99 | System_other_partition *string |
| 100 | // Name of the Product partition filesystem module |
| 101 | Product_partition *string |
| 102 | // Name of the Vendor partition filesystem module |
| 103 | Vendor_partition *string |
| 104 | // Name of the Vendor_dlkm partition filesystem module |
| 105 | Vendor_dlkm_partition *string |
| 106 | // Name of the Odm partition filesystem module |
| 107 | Odm_partition *string |
| 108 | // Name of the Odm_dlkm partition filesystem module |
| 109 | Odm_dlkm_partition *string |
| 110 | } |
| 111 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 112 | type SuperImageInfo struct { |
| 113 | // The built super.img file, which contains the sub-partitions |
| 114 | SuperImage android.Path |
| 115 | |
| 116 | // Mapping from the sub-partition type to its re-exported FileSystemInfo providers from the |
| 117 | // sub-partitions. |
| 118 | SubImageInfo map[string]FilesystemInfo |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 119 | |
| 120 | DynamicPartitionsInfo android.Path |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | var SuperImageProvider = blueprint.NewProvider[SuperImageInfo]() |
| 124 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 125 | func SuperImageFactory() android.Module { |
| 126 | module := &superImage{} |
| 127 | module.AddProperties(&module.properties, &module.partitionProps) |
| 128 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 129 | return module |
| 130 | } |
| 131 | |
| 132 | type superImageDepTagType struct { |
| 133 | blueprint.BaseDependencyTag |
| 134 | } |
| 135 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 136 | var subImageDepTag superImageDepTagType |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 137 | |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 138 | type systemOtherDepTagType struct { |
| 139 | blueprint.BaseDependencyTag |
| 140 | } |
| 141 | |
| 142 | var systemOtherDepTag systemOtherDepTagType |
| 143 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 144 | func (s *superImage) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 145 | addDependencyIfDefined := func(dep *string) { |
| 146 | if dep != nil { |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 147 | ctx.AddDependency(ctx.Module(), subImageDepTag, proptools.String(dep)) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| 151 | addDependencyIfDefined(s.partitionProps.System_partition) |
| 152 | addDependencyIfDefined(s.partitionProps.System_ext_partition) |
| 153 | addDependencyIfDefined(s.partitionProps.System_dlkm_partition) |
| 154 | addDependencyIfDefined(s.partitionProps.System_other_partition) |
| 155 | addDependencyIfDefined(s.partitionProps.Product_partition) |
| 156 | addDependencyIfDefined(s.partitionProps.Vendor_partition) |
| 157 | addDependencyIfDefined(s.partitionProps.Vendor_dlkm_partition) |
| 158 | addDependencyIfDefined(s.partitionProps.Odm_partition) |
| 159 | addDependencyIfDefined(s.partitionProps.Odm_dlkm_partition) |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 160 | if s.properties.System_other_partition != nil { |
| 161 | ctx.AddDependency(ctx.Module(), systemOtherDepTag, *s.properties.System_other_partition) |
| 162 | } |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | func (s *superImage) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 166 | miscInfo, deps, subImageInfos := s.buildMiscInfo(ctx) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 167 | builder := android.NewRuleBuilder(pctx, ctx) |
| 168 | output := android.PathForModuleOut(ctx, s.installFileName()) |
| 169 | lpMake := ctx.Config().HostToolPath(ctx, "lpmake") |
| 170 | lpMakeDir := filepath.Dir(lpMake.String()) |
| 171 | deps = append(deps, lpMake) |
| 172 | builder.Command().Textf("PATH=%s:\\$PATH", lpMakeDir). |
| 173 | BuiltTool("build_super_image"). |
| 174 | Text("-v"). |
| 175 | Input(miscInfo). |
| 176 | Implicits(deps). |
| 177 | Output(output) |
| 178 | builder.Build("build_super_image", fmt.Sprintf("Creating super image %s", s.BaseModuleName())) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 179 | android.SetProvider(ctx, SuperImageProvider, SuperImageInfo{ |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 180 | SuperImage: output, |
| 181 | SubImageInfo: subImageInfos, |
| 182 | DynamicPartitionsInfo: s.generateDynamicPartitionsInfo(ctx), |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 183 | }) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 184 | ctx.SetOutputFiles([]android.Path{output}, "") |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 185 | ctx.CheckbuildFile(output) |
Wei Li | 7b8455f | 2025-03-05 16:05:51 -0800 | [diff] [blame] | 186 | |
| 187 | buildComplianceMetadata(ctx, subImageDepTag) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | func (s *superImage) installFileName() string { |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 191 | return "super.img" |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 194 | func (s *superImage) buildMiscInfo(ctx android.ModuleContext) (android.Path, android.Paths, map[string]FilesystemInfo) { |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 195 | var miscInfoString strings.Builder |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 196 | partitionList := s.dumpDynamicPartitionInfo(ctx, &miscInfoString) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 197 | addStr := func(name string, value string) { |
| 198 | miscInfoString.WriteString(name) |
| 199 | miscInfoString.WriteRune('=') |
| 200 | miscInfoString.WriteString(value) |
| 201 | miscInfoString.WriteRune('\n') |
| 202 | } |
Spandan Das | 9284f67 | 2025-03-10 17:29:53 +0000 | [diff] [blame^] | 203 | addStr("ab_update", strconv.FormatBool(proptools.Bool(s.properties.Ab_update))) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 204 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 205 | subImageInfo := make(map[string]FilesystemInfo) |
| 206 | var deps android.Paths |
| 207 | |
| 208 | missingPartitionErrorMessage := "" |
| 209 | handleSubPartition := func(partitionType string, name *string) { |
| 210 | if proptools.String(name) == "" { |
| 211 | missingPartitionErrorMessage += fmt.Sprintf("%s image listed in partition groups, but its module was not specified. ", partitionType) |
| 212 | return |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 213 | } |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 214 | mod := ctx.GetDirectDepWithTag(*name, subImageDepTag) |
| 215 | if mod == nil { |
| 216 | ctx.ModuleErrorf("Could not get dep %q", *name) |
| 217 | return |
| 218 | } |
| 219 | info, ok := android.OtherModuleProvider(ctx, mod, FilesystemProvider) |
| 220 | if !ok { |
| 221 | ctx.ModuleErrorf("Expected dep %q to provide FilesystemInfo", *name) |
| 222 | return |
| 223 | } |
| 224 | addStr(partitionType+"_image", info.Output.String()) |
| 225 | deps = append(deps, info.Output) |
| 226 | if _, ok := subImageInfo[partitionType]; ok { |
| 227 | ctx.ModuleErrorf("Already set subimageInfo for %q", partitionType) |
| 228 | } |
| 229 | subImageInfo[partitionType] = info |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // Build partitionToImagePath, because system partition may need system_other |
| 233 | // partition image path |
| 234 | for _, p := range partitionList { |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 235 | switch p { |
| 236 | case "system": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 237 | handleSubPartition("system", s.partitionProps.System_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 238 | case "system_dlkm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 239 | handleSubPartition("system_dlkm", s.partitionProps.System_dlkm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 240 | case "system_ext": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 241 | handleSubPartition("system_ext", s.partitionProps.System_ext_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 242 | case "product": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 243 | handleSubPartition("product", s.partitionProps.Product_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 244 | case "vendor": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 245 | handleSubPartition("vendor", s.partitionProps.Vendor_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 246 | case "vendor_dlkm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 247 | handleSubPartition("vendor_dlkm", s.partitionProps.Vendor_dlkm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 248 | case "odm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 249 | handleSubPartition("odm", s.partitionProps.Odm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 250 | case "odm_dlkm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 251 | handleSubPartition("odm_dlkm", s.partitionProps.Odm_dlkm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 252 | default: |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 253 | ctx.ModuleErrorf("partition %q is not a super image supported partition", p) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 257 | if s.properties.System_other_partition != nil { |
| 258 | if !slices.Contains(partitionList, "system") { |
| 259 | ctx.PropertyErrorf("system_other_partition", "Must have a system partition to use a system_other partition") |
| 260 | } |
| 261 | systemOther := ctx.GetDirectDepProxyWithTag(*s.properties.System_other_partition, systemOtherDepTag) |
| 262 | systemOtherFiles := android.OutputFilesForModule(ctx, systemOther, "") |
| 263 | if len(systemOtherFiles) != 1 { |
| 264 | ctx.PropertyErrorf("system_other_partition", "Expected 1 output file from module %q", *&s.properties.System_other_partition) |
| 265 | } else { |
Spandan Das | 7a42d1c | 2025-02-12 01:32:21 +0000 | [diff] [blame] | 266 | handleSubPartition("system_other", s.partitionProps.System_other_partition) |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 270 | // Delay the error message until execution time because on aosp-main-future-without-vendor, |
| 271 | // BUILDING_VENDOR_IMAGE is false so we don't get the vendor image, but it's still listed in |
| 272 | // BOARD_GOOGLE_DYNAMIC_PARTITIONS_PARTITION_LIST. |
| 273 | missingPartitionErrorMessageFile := android.PathForModuleOut(ctx, "missing_partition_error.txt") |
| 274 | if missingPartitionErrorMessage != "" { |
| 275 | ctx.Build(pctx, android.BuildParams{ |
| 276 | Rule: android.ErrorRule, |
| 277 | Output: missingPartitionErrorMessageFile, |
| 278 | Args: map[string]string{ |
| 279 | "error": missingPartitionErrorMessage, |
| 280 | }, |
| 281 | }) |
| 282 | } else { |
| 283 | ctx.Build(pctx, android.BuildParams{ |
| 284 | Rule: android.Touch, |
| 285 | Output: missingPartitionErrorMessageFile, |
| 286 | }) |
Naresh Kumar Podishetty (xWF) | 4173c5b | 2025-01-09 20:20:32 -0800 | [diff] [blame] | 287 | } |
| 288 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 289 | miscInfo := android.PathForModuleOut(ctx, "misc_info.txt") |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 290 | android.WriteFileRule(ctx, miscInfo, miscInfoString.String(), missingPartitionErrorMessageFile) |
| 291 | return miscInfo, deps, subImageInfo |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 292 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 293 | |
| 294 | func (s *superImage) dumpDynamicPartitionInfo(ctx android.ModuleContext, sb *strings.Builder) []string { |
| 295 | addStr := func(name string, value string) { |
| 296 | sb.WriteString(name) |
| 297 | sb.WriteRune('=') |
| 298 | sb.WriteString(value) |
| 299 | sb.WriteRune('\n') |
| 300 | } |
| 301 | |
| 302 | addStr("build_super_partition", "true") |
| 303 | addStr("use_dynamic_partitions", strconv.FormatBool(proptools.Bool(s.properties.Use_dynamic_partitions))) |
| 304 | if proptools.Bool(s.properties.Retrofit) { |
| 305 | addStr("dynamic_partition_retrofit", "true") |
| 306 | } |
| 307 | addStr("lpmake", "lpmake") |
| 308 | addStr("super_metadata_device", proptools.String(s.properties.Metadata_device)) |
| 309 | if len(s.properties.Block_devices) > 0 { |
| 310 | addStr("super_block_devices", strings.Join(s.properties.Block_devices, " ")) |
| 311 | } |
Spandan Das | 9da8a2d | 2025-02-28 07:45:30 +0000 | [diff] [blame] | 312 | if proptools.Bool(s.properties.Super_image_in_update_package) { |
| 313 | addStr("super_image_in_update_package", "true") |
| 314 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 315 | addStr("super_partition_size", strconv.Itoa(proptools.Int(s.properties.Size))) |
| 316 | // TODO: In make, there's more complicated logic than just this surrounding super_*_device_size |
| 317 | addStr("super_super_device_size", strconv.Itoa(proptools.Int(s.properties.Size))) |
| 318 | var groups, partitionList []string |
| 319 | for _, groupInfo := range s.properties.Partition_groups { |
| 320 | groups = append(groups, groupInfo.Name) |
| 321 | partitionList = append(partitionList, groupInfo.PartitionList...) |
| 322 | addStr("super_"+groupInfo.Name+"_group_size", groupInfo.GroupSize) |
| 323 | addStr("super_"+groupInfo.Name+"_partition_list", strings.Join(groupInfo.PartitionList, " ")) |
| 324 | } |
| 325 | initialPartitionListLen := len(partitionList) |
| 326 | partitionList = android.SortedUniqueStrings(partitionList) |
| 327 | if len(partitionList) != initialPartitionListLen { |
| 328 | ctx.ModuleErrorf("Duplicate partitions found in the partition_groups property") |
| 329 | } |
| 330 | addStr("super_partition_groups", strings.Join(groups, " ")) |
| 331 | addStr("dynamic_partition_list", strings.Join(partitionList, " ")) |
| 332 | |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 333 | if proptools.Bool(s.properties.Virtual_ab.Enable) { |
| 334 | addStr("virtual_ab", "true") |
| 335 | if proptools.Bool(s.properties.Virtual_ab.Retrofit) { |
| 336 | addStr("virtual_ab_retrofit", "true") |
| 337 | } |
| 338 | addStr("virtual_ab_compression", strconv.FormatBool(proptools.Bool(s.properties.Virtual_ab.Compression))) |
| 339 | if s.properties.Virtual_ab.Compression_method != nil { |
| 340 | matched, _ := regexp.MatchString("^[a-zA-Z0-9_-]+$", *s.properties.Virtual_ab.Compression_method) |
| 341 | if !matched { |
| 342 | ctx.PropertyErrorf("virtual_ab.compression_method", "compression_method cannot have special characters") |
| 343 | } |
| 344 | addStr("virtual_ab_compression_method", *s.properties.Virtual_ab.Compression_method) |
| 345 | } |
| 346 | if s.properties.Virtual_ab.Compression_factor != nil { |
| 347 | addStr("virtual_ab_compression_factor", strconv.FormatInt(*s.properties.Virtual_ab.Compression_factor, 10)) |
| 348 | } |
| 349 | if s.properties.Virtual_ab.Cow_version != nil { |
| 350 | addStr("virtual_ab_cow_version", strconv.FormatInt(*s.properties.Virtual_ab.Cow_version, 10)) |
| 351 | } |
| 352 | |
| 353 | } else { |
| 354 | if s.properties.Virtual_ab.Retrofit != nil { |
| 355 | ctx.PropertyErrorf("virtual_ab.retrofit", "This property cannot be set when virtual_ab is disabled") |
| 356 | } |
| 357 | if s.properties.Virtual_ab.Compression != nil { |
| 358 | ctx.PropertyErrorf("virtual_ab.compression", "This property cannot be set when virtual_ab is disabled") |
| 359 | } |
| 360 | if s.properties.Virtual_ab.Compression_method != nil { |
| 361 | ctx.PropertyErrorf("virtual_ab.compression_method", "This property cannot be set when virtual_ab is disabled") |
| 362 | } |
| 363 | if s.properties.Virtual_ab.Compression_factor != nil { |
| 364 | ctx.PropertyErrorf("virtual_ab.compression_factor", "This property cannot be set when virtual_ab is disabled") |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return partitionList |
| 369 | } |
| 370 | |
| 371 | func (s *superImage) generateDynamicPartitionsInfo(ctx android.ModuleContext) android.Path { |
| 372 | var contents strings.Builder |
| 373 | s.dumpDynamicPartitionInfo(ctx, &contents) |
| 374 | dynamicPartitionsInfo := android.PathForModuleOut(ctx, "dynamic_partitions_info.txt") |
| 375 | android.WriteFileRule(ctx, dynamicPartitionsInfo, contents.String()) |
| 376 | return dynamicPartitionsInfo |
| 377 | } |