• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package fsgen
16
17import (
18	"strconv"
19
20	"android/soong/android"
21	"android/soong/filesystem"
22
23	"github.com/google/blueprint/proptools"
24)
25
26func buildingSuperImage(partitionVars android.PartitionVariables) bool {
27	return partitionVars.ProductBuildSuperPartition
28}
29
30func createSuperImage(
31	ctx android.LoadHookContext,
32	partitions allGeneratedPartitionData,
33	partitionVars android.PartitionVariables,
34	systemOtherImageName string,
35) []string {
36	baseProps := &struct {
37		Name *string
38	}{
39		Name: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "super")),
40	}
41
42	superImageProps := &filesystem.SuperImageProperties{
43		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),
49		Create_super_empty:            proptools.BoolPtr(partitionVars.BuildingSuperEmptyImage),
50	}
51	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 {
68				ctx.ModuleErrorf("COW version must be an int, got %q", partitionVars.ProductVirtualAbCowVersion)
69			}
70			superImageProps.Virtual_ab.Cow_version = proptools.Int64Ptr(version)
71		}
72	}
73	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
89	if systemOtherImageName != "" {
90		superImageProps.System_other_partition = proptools.StringPtr(systemOtherImageName)
91	}
92
93	var superImageSubpartitions []string
94	partitionNameProps := &filesystem.SuperImagePartitionNameProperties{}
95	if modName := partitions.nameForType("system"); modName != "" {
96		partitionNameProps.System_partition = proptools.StringPtr(modName)
97		superImageSubpartitions = append(superImageSubpartitions, "system")
98	}
99	if modName := partitions.nameForType("system_ext"); modName != "" {
100		partitionNameProps.System_ext_partition = proptools.StringPtr(modName)
101		superImageSubpartitions = append(superImageSubpartitions, "system_ext")
102	}
103	if modName := partitions.nameForType("system_dlkm"); modName != "" {
104		partitionNameProps.System_dlkm_partition = proptools.StringPtr(modName)
105		superImageSubpartitions = append(superImageSubpartitions, "system_dlkm")
106	}
107	if modName := partitions.nameForType("system_other"); modName != "" {
108		partitionNameProps.System_other_partition = proptools.StringPtr(modName)
109		superImageSubpartitions = append(superImageSubpartitions, "system_other")
110	}
111	if modName := partitions.nameForType("product"); modName != "" {
112		partitionNameProps.Product_partition = proptools.StringPtr(modName)
113		superImageSubpartitions = append(superImageSubpartitions, "product")
114	}
115	if modName := partitions.nameForType("vendor"); modName != "" {
116		partitionNameProps.Vendor_partition = proptools.StringPtr(modName)
117		superImageSubpartitions = append(superImageSubpartitions, "vendor")
118	}
119	if modName := partitions.nameForType("vendor_dlkm"); modName != "" {
120		partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(modName)
121		superImageSubpartitions = append(superImageSubpartitions, "vendor_dlkm")
122	}
123	if modName := partitions.nameForType("odm"); modName != "" {
124		partitionNameProps.Odm_partition = proptools.StringPtr(modName)
125		superImageSubpartitions = append(superImageSubpartitions, "odm")
126	}
127	if modName := partitions.nameForType("odm_dlkm"); modName != "" {
128		partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(modName)
129		superImageSubpartitions = append(superImageSubpartitions, "odm_dlkm")
130	}
131
132	ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps)
133	return superImageSubpartitions
134}
135