blob: f5646365f8d4d5b4d6f9b229446b12c21b161fdb [file] [log] [blame]
mrziwang79730d42024-12-02 22:13:59 -08001// 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
15package fsgen
16
17import (
18 "strconv"
19
20 "android/soong/android"
21 "android/soong/filesystem"
Jihoon Kang1259eff2025-01-09 22:11:03 +000022
mrziwang79730d42024-12-02 22:13:59 -080023 "github.com/google/blueprint/proptools"
24)
25
26func buildingSuperImage(partitionVars android.PartitionVariables) bool {
27 return partitionVars.ProductBuildSuperPartition
28}
29
Cole Faust74ee4e02025-01-16 14:55:35 -080030func createSuperImage(
31 ctx android.LoadHookContext,
Cole Faust76e8aa12025-01-27 18:21:31 -080032 partitions allGeneratedPartitionData,
Cole Faust74ee4e02025-01-16 14:55:35 -080033 partitionVars android.PartitionVariables,
34 systemOtherImageName string,
35) []string {
mrziwang79730d42024-12-02 22:13:59 -080036 baseProps := &struct {
37 Name *string
38 }{
Jihoon Kang1259eff2025-01-09 22:11:03 +000039 Name: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "super")),
mrziwang79730d42024-12-02 22:13:59 -080040 }
41
42 superImageProps := &filesystem.SuperImageProperties{
Spandan Das9da8a2d2025-02-28 07:45:30 +000043 Metadata_device: proptools.StringPtr(partitionVars.BoardSuperPartitionMetadataDevice),
44 Block_devices: partitionVars.BoardSuperPartitionBlockDevices,
45 Ab_update: proptools.BoolPtr(partitionVars.AbOtaUpdater),
46 Retrofit: proptools.BoolPtr(partitionVars.ProductRetrofitDynamicPartitions),
47 Use_dynamic_partitions: proptools.BoolPtr(partitionVars.ProductUseDynamicPartitions),
48 Super_image_in_update_package: proptools.BoolPtr(partitionVars.BoardSuperImageInUpdatePackage),
mrziwang79730d42024-12-02 22:13:59 -080049 }
Cole Faust498ffc12025-01-15 14:19:32 -080050 if partitionVars.ProductVirtualAbOta {
51 superImageProps.Virtual_ab.Enable = proptools.BoolPtr(true)
52 superImageProps.Virtual_ab.Retrofit = proptools.BoolPtr(partitionVars.ProductVirtualAbOtaRetrofit)
53 superImageProps.Virtual_ab.Compression = proptools.BoolPtr(partitionVars.ProductVirtualAbCompression)
54 if partitionVars.ProductVirtualAbCompressionMethod != "" {
55 superImageProps.Virtual_ab.Compression_method = proptools.StringPtr(partitionVars.ProductVirtualAbCompressionMethod)
56 }
57 if partitionVars.ProductVirtualAbCompressionFactor != "" {
58 factor, err := strconv.ParseInt(partitionVars.ProductVirtualAbCompressionFactor, 10, 32)
59 if err != nil {
60 ctx.ModuleErrorf("Compression factor must be an int, got %q", partitionVars.ProductVirtualAbCompressionFactor)
61 }
62 superImageProps.Virtual_ab.Compression_factor = proptools.Int64Ptr(factor)
63 }
64 if partitionVars.ProductVirtualAbCowVersion != "" {
65 version, err := strconv.ParseInt(partitionVars.ProductVirtualAbCowVersion, 10, 32)
66 if err != nil {
Cole Faust29e333d2025-01-15 16:53:44 -080067 ctx.ModuleErrorf("COW version must be an int, got %q", partitionVars.ProductVirtualAbCowVersion)
Cole Faust498ffc12025-01-15 14:19:32 -080068 }
69 superImageProps.Virtual_ab.Cow_version = proptools.Int64Ptr(version)
70 }
71 }
mrziwang79730d42024-12-02 22:13:59 -080072 size, _ := strconv.ParseInt(partitionVars.BoardSuperPartitionSize, 10, 64)
73 superImageProps.Size = proptools.Int64Ptr(size)
74 sparse := !partitionVars.TargetUserimagesSparseExtDisabled && !partitionVars.TargetUserimagesSparseF2fsDisabled
75 superImageProps.Sparse = proptools.BoolPtr(sparse)
76
77 var partitionGroupsInfo []filesystem.PartitionGroupsInfo
78 for _, groupName := range android.SortedKeys(partitionVars.BoardSuperPartitionGroups) {
79 info := filesystem.PartitionGroupsInfo{
80 Name: groupName,
81 GroupSize: partitionVars.BoardSuperPartitionGroups[groupName].GroupSize,
82 PartitionList: partitionVars.BoardSuperPartitionGroups[groupName].PartitionList,
83 }
84 partitionGroupsInfo = append(partitionGroupsInfo, info)
85 }
86 superImageProps.Partition_groups = partitionGroupsInfo
87
Cole Faust74ee4e02025-01-16 14:55:35 -080088 if systemOtherImageName != "" {
89 superImageProps.System_other_partition = proptools.StringPtr(systemOtherImageName)
90 }
91
Cole Faust2bdc5e52025-01-10 10:29:36 -080092 var superImageSubpartitions []string
mrziwang79730d42024-12-02 22:13:59 -080093 partitionNameProps := &filesystem.SuperImagePartitionNameProperties{}
Cole Faust76e8aa12025-01-27 18:21:31 -080094 if modName := partitions.nameForType("system"); modName != "" {
95 partitionNameProps.System_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -080096 superImageSubpartitions = append(superImageSubpartitions, "system")
mrziwang79730d42024-12-02 22:13:59 -080097 }
Cole Faust76e8aa12025-01-27 18:21:31 -080098 if modName := partitions.nameForType("system_ext"); modName != "" {
99 partitionNameProps.System_ext_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800100 superImageSubpartitions = append(superImageSubpartitions, "system_ext")
mrziwang79730d42024-12-02 22:13:59 -0800101 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800102 if modName := partitions.nameForType("system_dlkm"); modName != "" {
103 partitionNameProps.System_dlkm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800104 superImageSubpartitions = append(superImageSubpartitions, "system_dlkm")
mrziwang79730d42024-12-02 22:13:59 -0800105 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800106 if modName := partitions.nameForType("system_other"); modName != "" {
107 partitionNameProps.System_other_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800108 superImageSubpartitions = append(superImageSubpartitions, "system_other")
mrziwang79730d42024-12-02 22:13:59 -0800109 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800110 if modName := partitions.nameForType("product"); modName != "" {
111 partitionNameProps.Product_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800112 superImageSubpartitions = append(superImageSubpartitions, "product")
mrziwang79730d42024-12-02 22:13:59 -0800113 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800114 if modName := partitions.nameForType("vendor"); modName != "" {
115 partitionNameProps.Vendor_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800116 superImageSubpartitions = append(superImageSubpartitions, "vendor")
mrziwang79730d42024-12-02 22:13:59 -0800117 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800118 if modName := partitions.nameForType("vendor_dlkm"); modName != "" {
119 partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800120 superImageSubpartitions = append(superImageSubpartitions, "vendor_dlkm")
mrziwang79730d42024-12-02 22:13:59 -0800121 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800122 if modName := partitions.nameForType("odm"); modName != "" {
123 partitionNameProps.Odm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800124 superImageSubpartitions = append(superImageSubpartitions, "odm")
mrziwang79730d42024-12-02 22:13:59 -0800125 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800126 if modName := partitions.nameForType("odm_dlkm"); modName != "" {
127 partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800128 superImageSubpartitions = append(superImageSubpartitions, "odm_dlkm")
mrziwang79730d42024-12-02 22:13:59 -0800129 }
130
131 ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800132 return superImageSubpartitions
mrziwang79730d42024-12-02 22:13:59 -0800133}