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 |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 83 | // Whether a super_empty.img should be created |
| 84 | Create_super_empty *bool |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | type PartitionGroupsInfo struct { |
| 88 | Name string |
| 89 | GroupSize string |
| 90 | PartitionList []string |
| 91 | } |
| 92 | |
| 93 | type SuperImagePartitionNameProperties struct { |
| 94 | // Name of the System partition filesystem module |
| 95 | System_partition *string |
| 96 | // Name of the System_ext partition filesystem module |
| 97 | System_ext_partition *string |
| 98 | // Name of the System_dlkm partition filesystem module |
| 99 | System_dlkm_partition *string |
| 100 | // Name of the System_other partition filesystem module |
| 101 | System_other_partition *string |
| 102 | // Name of the Product partition filesystem module |
| 103 | Product_partition *string |
| 104 | // Name of the Vendor partition filesystem module |
| 105 | Vendor_partition *string |
| 106 | // Name of the Vendor_dlkm partition filesystem module |
| 107 | Vendor_dlkm_partition *string |
| 108 | // Name of the Odm partition filesystem module |
| 109 | Odm_partition *string |
| 110 | // Name of the Odm_dlkm partition filesystem module |
| 111 | Odm_dlkm_partition *string |
| 112 | } |
| 113 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 114 | type SuperImageInfo struct { |
| 115 | // The built super.img file, which contains the sub-partitions |
| 116 | SuperImage android.Path |
| 117 | |
| 118 | // Mapping from the sub-partition type to its re-exported FileSystemInfo providers from the |
| 119 | // sub-partitions. |
| 120 | SubImageInfo map[string]FilesystemInfo |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 121 | |
| 122 | DynamicPartitionsInfo android.Path |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 123 | |
| 124 | SuperEmptyImage android.Path |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | var SuperImageProvider = blueprint.NewProvider[SuperImageInfo]() |
| 128 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 129 | func SuperImageFactory() android.Module { |
| 130 | module := &superImage{} |
| 131 | module.AddProperties(&module.properties, &module.partitionProps) |
| 132 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 133 | return module |
| 134 | } |
| 135 | |
| 136 | type superImageDepTagType struct { |
| 137 | blueprint.BaseDependencyTag |
| 138 | } |
| 139 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 140 | var subImageDepTag superImageDepTagType |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 141 | |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 142 | type systemOtherDepTagType struct { |
| 143 | blueprint.BaseDependencyTag |
| 144 | } |
| 145 | |
| 146 | var systemOtherDepTag systemOtherDepTagType |
| 147 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 148 | func (s *superImage) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 149 | addDependencyIfDefined := func(dep *string) { |
| 150 | if dep != nil { |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 151 | ctx.AddDependency(ctx.Module(), subImageDepTag, proptools.String(dep)) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | addDependencyIfDefined(s.partitionProps.System_partition) |
| 156 | addDependencyIfDefined(s.partitionProps.System_ext_partition) |
| 157 | addDependencyIfDefined(s.partitionProps.System_dlkm_partition) |
| 158 | addDependencyIfDefined(s.partitionProps.System_other_partition) |
| 159 | addDependencyIfDefined(s.partitionProps.Product_partition) |
| 160 | addDependencyIfDefined(s.partitionProps.Vendor_partition) |
| 161 | addDependencyIfDefined(s.partitionProps.Vendor_dlkm_partition) |
| 162 | addDependencyIfDefined(s.partitionProps.Odm_partition) |
| 163 | addDependencyIfDefined(s.partitionProps.Odm_dlkm_partition) |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 164 | if s.properties.System_other_partition != nil { |
| 165 | ctx.AddDependency(ctx.Module(), systemOtherDepTag, *s.properties.System_other_partition) |
| 166 | } |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | func (s *superImage) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 170 | miscInfo, deps, subImageInfos := s.buildMiscInfo(ctx, false) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 171 | builder := android.NewRuleBuilder(pctx, ctx) |
| 172 | output := android.PathForModuleOut(ctx, s.installFileName()) |
| 173 | lpMake := ctx.Config().HostToolPath(ctx, "lpmake") |
| 174 | lpMakeDir := filepath.Dir(lpMake.String()) |
| 175 | deps = append(deps, lpMake) |
| 176 | builder.Command().Textf("PATH=%s:\\$PATH", lpMakeDir). |
| 177 | BuiltTool("build_super_image"). |
| 178 | Text("-v"). |
| 179 | Input(miscInfo). |
| 180 | Implicits(deps). |
| 181 | Output(output) |
| 182 | builder.Build("build_super_image", fmt.Sprintf("Creating super image %s", s.BaseModuleName())) |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 183 | var superEmptyImage android.WritablePath |
| 184 | if proptools.Bool(s.properties.Create_super_empty) { |
| 185 | superEmptyImageBuilder := android.NewRuleBuilder(pctx, ctx) |
| 186 | superEmptyImage = android.PathForModuleOut(ctx, "super_empty.img") |
| 187 | superEmptyMiscInfo, superEmptyDeps, _ := s.buildMiscInfo(ctx, true) |
| 188 | if superEmptyDeps != nil { |
| 189 | ctx.ModuleErrorf("TODO: Handle additional deps when building super_empty.img") |
| 190 | } |
| 191 | superEmptyImageBuilder.Command().Textf("PATH=%s:\\$PATH", lpMakeDir). |
| 192 | BuiltTool("build_super_image"). |
| 193 | Text("-v"). |
| 194 | Input(superEmptyMiscInfo). |
| 195 | Implicit(lpMake). |
| 196 | Output(superEmptyImage) |
| 197 | superEmptyImageBuilder.Build("build_super_empty_image", fmt.Sprintf("Creating super empty image %s", s.BaseModuleName())) |
| 198 | } |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 199 | android.SetProvider(ctx, SuperImageProvider, SuperImageInfo{ |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 200 | SuperImage: output, |
| 201 | SubImageInfo: subImageInfos, |
| 202 | DynamicPartitionsInfo: s.generateDynamicPartitionsInfo(ctx), |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 203 | SuperEmptyImage: superEmptyImage, |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 204 | }) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 205 | ctx.SetOutputFiles([]android.Path{output}, "") |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 206 | ctx.CheckbuildFile(output) |
Wei Li | 7b8455f | 2025-03-05 16:05:51 -0800 | [diff] [blame] | 207 | |
| 208 | buildComplianceMetadata(ctx, subImageDepTag) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | func (s *superImage) installFileName() string { |
Cole Faust | a472a6f | 2025-02-10 16:10:04 -0800 | [diff] [blame] | 212 | return "super.img" |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 215 | func (s *superImage) buildMiscInfo(ctx android.ModuleContext, superEmpty bool) (android.Path, android.Paths, map[string]FilesystemInfo) { |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 216 | var miscInfoString strings.Builder |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 217 | partitionList := s.dumpDynamicPartitionInfo(ctx, &miscInfoString) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 218 | addStr := func(name string, value string) { |
| 219 | miscInfoString.WriteString(name) |
| 220 | miscInfoString.WriteRune('=') |
| 221 | miscInfoString.WriteString(value) |
| 222 | miscInfoString.WriteRune('\n') |
| 223 | } |
Spandan Das | 9284f67 | 2025-03-10 17:29:53 +0000 | [diff] [blame] | 224 | addStr("ab_update", strconv.FormatBool(proptools.Bool(s.properties.Ab_update))) |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 225 | if superEmpty { |
| 226 | miscInfo := android.PathForModuleOut(ctx, "misc_info_super_empty.txt") |
| 227 | android.WriteFileRule(ctx, miscInfo, miscInfoString.String()) |
| 228 | return miscInfo, nil, nil |
| 229 | } |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 230 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 231 | subImageInfo := make(map[string]FilesystemInfo) |
| 232 | var deps android.Paths |
| 233 | |
| 234 | missingPartitionErrorMessage := "" |
| 235 | handleSubPartition := func(partitionType string, name *string) { |
| 236 | if proptools.String(name) == "" { |
| 237 | missingPartitionErrorMessage += fmt.Sprintf("%s image listed in partition groups, but its module was not specified. ", partitionType) |
| 238 | return |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 239 | } |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 240 | mod := ctx.GetDirectDepWithTag(*name, subImageDepTag) |
| 241 | if mod == nil { |
| 242 | ctx.ModuleErrorf("Could not get dep %q", *name) |
| 243 | return |
| 244 | } |
| 245 | info, ok := android.OtherModuleProvider(ctx, mod, FilesystemProvider) |
| 246 | if !ok { |
| 247 | ctx.ModuleErrorf("Expected dep %q to provide FilesystemInfo", *name) |
| 248 | return |
| 249 | } |
| 250 | addStr(partitionType+"_image", info.Output.String()) |
| 251 | deps = append(deps, info.Output) |
| 252 | if _, ok := subImageInfo[partitionType]; ok { |
| 253 | ctx.ModuleErrorf("Already set subimageInfo for %q", partitionType) |
| 254 | } |
| 255 | subImageInfo[partitionType] = info |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // Build partitionToImagePath, because system partition may need system_other |
| 259 | // partition image path |
| 260 | for _, p := range partitionList { |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 261 | switch p { |
| 262 | case "system": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 263 | handleSubPartition("system", s.partitionProps.System_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 264 | case "system_dlkm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 265 | handleSubPartition("system_dlkm", s.partitionProps.System_dlkm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 266 | case "system_ext": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 267 | handleSubPartition("system_ext", s.partitionProps.System_ext_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 268 | case "product": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 269 | handleSubPartition("product", s.partitionProps.Product_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 270 | case "vendor": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 271 | handleSubPartition("vendor", s.partitionProps.Vendor_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 272 | case "vendor_dlkm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 273 | handleSubPartition("vendor_dlkm", s.partitionProps.Vendor_dlkm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 274 | case "odm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 275 | handleSubPartition("odm", s.partitionProps.Odm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 276 | case "odm_dlkm": |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 277 | handleSubPartition("odm_dlkm", s.partitionProps.Odm_dlkm_partition) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 278 | default: |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 279 | ctx.ModuleErrorf("partition %q is not a super image supported partition", p) |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 283 | if s.properties.System_other_partition != nil { |
| 284 | if !slices.Contains(partitionList, "system") { |
| 285 | ctx.PropertyErrorf("system_other_partition", "Must have a system partition to use a system_other partition") |
| 286 | } |
| 287 | systemOther := ctx.GetDirectDepProxyWithTag(*s.properties.System_other_partition, systemOtherDepTag) |
| 288 | systemOtherFiles := android.OutputFilesForModule(ctx, systemOther, "") |
| 289 | if len(systemOtherFiles) != 1 { |
| 290 | ctx.PropertyErrorf("system_other_partition", "Expected 1 output file from module %q", *&s.properties.System_other_partition) |
| 291 | } else { |
Spandan Das | 7a42d1c | 2025-02-12 01:32:21 +0000 | [diff] [blame] | 292 | handleSubPartition("system_other", s.partitionProps.System_other_partition) |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 296 | // Delay the error message until execution time because on aosp-main-future-without-vendor, |
| 297 | // BUILDING_VENDOR_IMAGE is false so we don't get the vendor image, but it's still listed in |
| 298 | // BOARD_GOOGLE_DYNAMIC_PARTITIONS_PARTITION_LIST. |
| 299 | missingPartitionErrorMessageFile := android.PathForModuleOut(ctx, "missing_partition_error.txt") |
| 300 | if missingPartitionErrorMessage != "" { |
| 301 | ctx.Build(pctx, android.BuildParams{ |
| 302 | Rule: android.ErrorRule, |
| 303 | Output: missingPartitionErrorMessageFile, |
| 304 | Args: map[string]string{ |
| 305 | "error": missingPartitionErrorMessage, |
| 306 | }, |
| 307 | }) |
| 308 | } else { |
| 309 | ctx.Build(pctx, android.BuildParams{ |
| 310 | Rule: android.Touch, |
| 311 | Output: missingPartitionErrorMessageFile, |
| 312 | }) |
Naresh Kumar Podishetty (xWF) | 4173c5b | 2025-01-09 20:20:32 -0800 | [diff] [blame] | 313 | } |
| 314 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 315 | miscInfo := android.PathForModuleOut(ctx, "misc_info.txt") |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 316 | android.WriteFileRule(ctx, miscInfo, miscInfoString.String(), missingPartitionErrorMessageFile) |
| 317 | return miscInfo, deps, subImageInfo |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 318 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 319 | |
| 320 | func (s *superImage) dumpDynamicPartitionInfo(ctx android.ModuleContext, sb *strings.Builder) []string { |
| 321 | addStr := func(name string, value string) { |
| 322 | sb.WriteString(name) |
| 323 | sb.WriteRune('=') |
| 324 | sb.WriteString(value) |
| 325 | sb.WriteRune('\n') |
| 326 | } |
| 327 | |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 328 | addStr("use_dynamic_partitions", strconv.FormatBool(proptools.Bool(s.properties.Use_dynamic_partitions))) |
| 329 | if proptools.Bool(s.properties.Retrofit) { |
| 330 | addStr("dynamic_partition_retrofit", "true") |
| 331 | } |
| 332 | addStr("lpmake", "lpmake") |
Spandan Das | 0ff1dcd | 2025-03-11 18:21:40 +0000 | [diff] [blame] | 333 | addStr("build_super_partition", "true") |
| 334 | if proptools.Bool(s.properties.Create_super_empty) { |
| 335 | addStr("build_super_empty_partition", "true") |
| 336 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 337 | addStr("super_metadata_device", proptools.String(s.properties.Metadata_device)) |
| 338 | if len(s.properties.Block_devices) > 0 { |
| 339 | addStr("super_block_devices", strings.Join(s.properties.Block_devices, " ")) |
| 340 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 341 | // TODO: In make, there's more complicated logic than just this surrounding super_*_device_size |
| 342 | addStr("super_super_device_size", strconv.Itoa(proptools.Int(s.properties.Size))) |
| 343 | var groups, partitionList []string |
| 344 | for _, groupInfo := range s.properties.Partition_groups { |
| 345 | groups = append(groups, groupInfo.Name) |
| 346 | partitionList = append(partitionList, groupInfo.PartitionList...) |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 347 | } |
Spandan Das | 0ff1dcd | 2025-03-11 18:21:40 +0000 | [diff] [blame] | 348 | addStr("dynamic_partition_list", strings.Join(android.SortedUniqueStrings(partitionList), " ")) |
| 349 | addStr("super_partition_groups", strings.Join(groups, " ")) |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 350 | initialPartitionListLen := len(partitionList) |
| 351 | partitionList = android.SortedUniqueStrings(partitionList) |
| 352 | if len(partitionList) != initialPartitionListLen { |
| 353 | ctx.ModuleErrorf("Duplicate partitions found in the partition_groups property") |
| 354 | } |
Spandan Das | 0ff1dcd | 2025-03-11 18:21:40 +0000 | [diff] [blame] | 355 | // Add Partition group info after adding `super_partition_groups` and `dynamic_partition_list` |
| 356 | for _, groupInfo := range s.properties.Partition_groups { |
| 357 | addStr("super_"+groupInfo.Name+"_group_size", groupInfo.GroupSize) |
| 358 | addStr("super_"+groupInfo.Name+"_partition_list", strings.Join(groupInfo.PartitionList, " ")) |
| 359 | } |
| 360 | |
| 361 | if proptools.Bool(s.properties.Super_image_in_update_package) { |
| 362 | addStr("super_image_in_update_package", "true") |
| 363 | } |
| 364 | addStr("super_partition_size", strconv.Itoa(proptools.Int(s.properties.Size))) |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 365 | |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 366 | if proptools.Bool(s.properties.Virtual_ab.Enable) { |
| 367 | addStr("virtual_ab", "true") |
| 368 | if proptools.Bool(s.properties.Virtual_ab.Retrofit) { |
| 369 | addStr("virtual_ab_retrofit", "true") |
| 370 | } |
| 371 | addStr("virtual_ab_compression", strconv.FormatBool(proptools.Bool(s.properties.Virtual_ab.Compression))) |
| 372 | if s.properties.Virtual_ab.Compression_method != nil { |
| 373 | matched, _ := regexp.MatchString("^[a-zA-Z0-9_-]+$", *s.properties.Virtual_ab.Compression_method) |
| 374 | if !matched { |
| 375 | ctx.PropertyErrorf("virtual_ab.compression_method", "compression_method cannot have special characters") |
| 376 | } |
| 377 | addStr("virtual_ab_compression_method", *s.properties.Virtual_ab.Compression_method) |
| 378 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 379 | if s.properties.Virtual_ab.Cow_version != nil { |
| 380 | addStr("virtual_ab_cow_version", strconv.FormatInt(*s.properties.Virtual_ab.Cow_version, 10)) |
| 381 | } |
Spandan Das | 0ff1dcd | 2025-03-11 18:21:40 +0000 | [diff] [blame] | 382 | if s.properties.Virtual_ab.Compression_factor != nil { |
| 383 | addStr("virtual_ab_compression_factor", strconv.FormatInt(*s.properties.Virtual_ab.Compression_factor, 10)) |
| 384 | } |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 385 | |
| 386 | } else { |
| 387 | if s.properties.Virtual_ab.Retrofit != nil { |
| 388 | ctx.PropertyErrorf("virtual_ab.retrofit", "This property cannot be set when virtual_ab is disabled") |
| 389 | } |
| 390 | if s.properties.Virtual_ab.Compression != nil { |
| 391 | ctx.PropertyErrorf("virtual_ab.compression", "This property cannot be set when virtual_ab is disabled") |
| 392 | } |
| 393 | if s.properties.Virtual_ab.Compression_method != nil { |
| 394 | ctx.PropertyErrorf("virtual_ab.compression_method", "This property cannot be set when virtual_ab is disabled") |
| 395 | } |
| 396 | if s.properties.Virtual_ab.Compression_factor != nil { |
| 397 | ctx.PropertyErrorf("virtual_ab.compression_factor", "This property cannot be set when virtual_ab is disabled") |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return partitionList |
| 402 | } |
| 403 | |
| 404 | func (s *superImage) generateDynamicPartitionsInfo(ctx android.ModuleContext) android.Path { |
| 405 | var contents strings.Builder |
| 406 | s.dumpDynamicPartitionInfo(ctx, &contents) |
| 407 | dynamicPartitionsInfo := android.PathForModuleOut(ctx, "dynamic_partitions_info.txt") |
Spandan Das | 0ff1dcd | 2025-03-11 18:21:40 +0000 | [diff] [blame] | 408 | android.WriteFileRuleVerbatim(ctx, dynamicPartitionsInfo, contents.String()) |
Spandan Das | f079f0d | 2025-02-27 13:13:50 +0000 | [diff] [blame] | 409 | return dynamicPartitionsInfo |
| 410 | } |