blob: 1d610f63c43bf169036cd2130cf22ba54c57a804 [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),
Spandan Dasd73441e2025-03-10 22:34:25 +000049 Create_super_empty: proptools.BoolPtr(partitionVars.BuildingSuperEmptyImage),
mrziwang79730d42024-12-02 22:13:59 -080050 }
Cole Faust498ffc12025-01-15 14:19:32 -080051 if partitionVars.ProductVirtualAbOta {
52 superImageProps.Virtual_ab.Enable = proptools.BoolPtr(true)
53 superImageProps.Virtual_ab.Retrofit = proptools.BoolPtr(partitionVars.ProductVirtualAbOtaRetrofit)
54 superImageProps.Virtual_ab.Compression = proptools.BoolPtr(partitionVars.ProductVirtualAbCompression)
55 if partitionVars.ProductVirtualAbCompressionMethod != "" {
56 superImageProps.Virtual_ab.Compression_method = proptools.StringPtr(partitionVars.ProductVirtualAbCompressionMethod)
57 }
58 if partitionVars.ProductVirtualAbCompressionFactor != "" {
59 factor, err := strconv.ParseInt(partitionVars.ProductVirtualAbCompressionFactor, 10, 32)
60 if err != nil {
61 ctx.ModuleErrorf("Compression factor must be an int, got %q", partitionVars.ProductVirtualAbCompressionFactor)
62 }
63 superImageProps.Virtual_ab.Compression_factor = proptools.Int64Ptr(factor)
64 }
65 if partitionVars.ProductVirtualAbCowVersion != "" {
66 version, err := strconv.ParseInt(partitionVars.ProductVirtualAbCowVersion, 10, 32)
67 if err != nil {
Cole Faust29e333d2025-01-15 16:53:44 -080068 ctx.ModuleErrorf("COW version must be an int, got %q", partitionVars.ProductVirtualAbCowVersion)
Cole Faust498ffc12025-01-15 14:19:32 -080069 }
70 superImageProps.Virtual_ab.Cow_version = proptools.Int64Ptr(version)
71 }
72 }
mrziwang79730d42024-12-02 22:13:59 -080073 size, _ := strconv.ParseInt(partitionVars.BoardSuperPartitionSize, 10, 64)
74 superImageProps.Size = proptools.Int64Ptr(size)
75 sparse := !partitionVars.TargetUserimagesSparseExtDisabled && !partitionVars.TargetUserimagesSparseF2fsDisabled
76 superImageProps.Sparse = proptools.BoolPtr(sparse)
77
78 var partitionGroupsInfo []filesystem.PartitionGroupsInfo
79 for _, groupName := range android.SortedKeys(partitionVars.BoardSuperPartitionGroups) {
80 info := filesystem.PartitionGroupsInfo{
81 Name: groupName,
82 GroupSize: partitionVars.BoardSuperPartitionGroups[groupName].GroupSize,
83 PartitionList: partitionVars.BoardSuperPartitionGroups[groupName].PartitionList,
84 }
85 partitionGroupsInfo = append(partitionGroupsInfo, info)
86 }
87 superImageProps.Partition_groups = partitionGroupsInfo
88
Cole Faust74ee4e02025-01-16 14:55:35 -080089 if systemOtherImageName != "" {
90 superImageProps.System_other_partition = proptools.StringPtr(systemOtherImageName)
91 }
92
Cole Faust2bdc5e52025-01-10 10:29:36 -080093 var superImageSubpartitions []string
mrziwang79730d42024-12-02 22:13:59 -080094 partitionNameProps := &filesystem.SuperImagePartitionNameProperties{}
Cole Faust76e8aa12025-01-27 18:21:31 -080095 if modName := partitions.nameForType("system"); modName != "" {
96 partitionNameProps.System_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -080097 superImageSubpartitions = append(superImageSubpartitions, "system")
mrziwang79730d42024-12-02 22:13:59 -080098 }
Cole Faust76e8aa12025-01-27 18:21:31 -080099 if modName := partitions.nameForType("system_ext"); modName != "" {
100 partitionNameProps.System_ext_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800101 superImageSubpartitions = append(superImageSubpartitions, "system_ext")
mrziwang79730d42024-12-02 22:13:59 -0800102 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800103 if modName := partitions.nameForType("system_dlkm"); modName != "" {
104 partitionNameProps.System_dlkm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800105 superImageSubpartitions = append(superImageSubpartitions, "system_dlkm")
mrziwang79730d42024-12-02 22:13:59 -0800106 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800107 if modName := partitions.nameForType("system_other"); modName != "" {
108 partitionNameProps.System_other_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800109 superImageSubpartitions = append(superImageSubpartitions, "system_other")
mrziwang79730d42024-12-02 22:13:59 -0800110 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800111 if modName := partitions.nameForType("product"); modName != "" {
112 partitionNameProps.Product_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800113 superImageSubpartitions = append(superImageSubpartitions, "product")
mrziwang79730d42024-12-02 22:13:59 -0800114 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800115 if modName := partitions.nameForType("vendor"); modName != "" {
116 partitionNameProps.Vendor_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800117 superImageSubpartitions = append(superImageSubpartitions, "vendor")
mrziwang79730d42024-12-02 22:13:59 -0800118 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800119 if modName := partitions.nameForType("vendor_dlkm"); modName != "" {
120 partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800121 superImageSubpartitions = append(superImageSubpartitions, "vendor_dlkm")
mrziwang79730d42024-12-02 22:13:59 -0800122 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800123 if modName := partitions.nameForType("odm"); modName != "" {
124 partitionNameProps.Odm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800125 superImageSubpartitions = append(superImageSubpartitions, "odm")
mrziwang79730d42024-12-02 22:13:59 -0800126 }
Cole Faust76e8aa12025-01-27 18:21:31 -0800127 if modName := partitions.nameForType("odm_dlkm"); modName != "" {
128 partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(modName)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800129 superImageSubpartitions = append(superImageSubpartitions, "odm_dlkm")
mrziwang79730d42024-12-02 22:13:59 -0800130 }
131
132 ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps)
Cole Faust2bdc5e52025-01-10 10:29:36 -0800133 return superImageSubpartitions
mrziwang79730d42024-12-02 22:13:59 -0800134}