xref: /aosp_15_r20/build/soong/fsgen/super_img.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright (C) 2024 The Android Open Source Project
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage fsgen
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"strconv"
19*333d2b36SAndroid Build Coastguard Worker
20*333d2b36SAndroid Build Coastguard Worker	"android/soong/android"
21*333d2b36SAndroid Build Coastguard Worker	"android/soong/filesystem"
22*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint/proptools"
23*333d2b36SAndroid Build Coastguard Worker)
24*333d2b36SAndroid Build Coastguard Worker
25*333d2b36SAndroid Build Coastguard Workerfunc buildingSuperImage(partitionVars android.PartitionVariables) bool {
26*333d2b36SAndroid Build Coastguard Worker	return partitionVars.ProductBuildSuperPartition
27*333d2b36SAndroid Build Coastguard Worker}
28*333d2b36SAndroid Build Coastguard Worker
29*333d2b36SAndroid Build Coastguard Workerfunc createSuperImage(ctx android.LoadHookContext, partitions []string, partitionVars android.PartitionVariables) {
30*333d2b36SAndroid Build Coastguard Worker	baseProps := &struct {
31*333d2b36SAndroid Build Coastguard Worker		Name *string
32*333d2b36SAndroid Build Coastguard Worker	}{
33*333d2b36SAndroid Build Coastguard Worker		Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "super")),
34*333d2b36SAndroid Build Coastguard Worker	}
35*333d2b36SAndroid Build Coastguard Worker
36*333d2b36SAndroid Build Coastguard Worker	superImageProps := &filesystem.SuperImageProperties{
37*333d2b36SAndroid Build Coastguard Worker		Metadata_device:        proptools.StringPtr(partitionVars.BoardSuperPartitionMetadataDevice),
38*333d2b36SAndroid Build Coastguard Worker		Block_devices:          partitionVars.BoardSuperPartitionBlockDevices,
39*333d2b36SAndroid Build Coastguard Worker		Ab_update:              proptools.BoolPtr(partitionVars.AbOtaUpdater),
40*333d2b36SAndroid Build Coastguard Worker		Retrofit:               proptools.BoolPtr(partitionVars.ProductRetrofitDynamicPartitions),
41*333d2b36SAndroid Build Coastguard Worker		Virtual_ab:             proptools.BoolPtr(partitionVars.ProductVirtualAbOta),
42*333d2b36SAndroid Build Coastguard Worker		Virtual_ab_retrofit:    proptools.BoolPtr(partitionVars.ProductVirtualAbOtaRetrofit),
43*333d2b36SAndroid Build Coastguard Worker		Use_dynamic_partitions: proptools.BoolPtr(partitionVars.ProductUseDynamicPartitions),
44*333d2b36SAndroid Build Coastguard Worker	}
45*333d2b36SAndroid Build Coastguard Worker	size, _ := strconv.ParseInt(partitionVars.BoardSuperPartitionSize, 10, 64)
46*333d2b36SAndroid Build Coastguard Worker	superImageProps.Size = proptools.Int64Ptr(size)
47*333d2b36SAndroid Build Coastguard Worker	sparse := !partitionVars.TargetUserimagesSparseExtDisabled && !partitionVars.TargetUserimagesSparseF2fsDisabled
48*333d2b36SAndroid Build Coastguard Worker	superImageProps.Sparse = proptools.BoolPtr(sparse)
49*333d2b36SAndroid Build Coastguard Worker
50*333d2b36SAndroid Build Coastguard Worker	var partitionGroupsInfo []filesystem.PartitionGroupsInfo
51*333d2b36SAndroid Build Coastguard Worker	for _, groupName := range android.SortedKeys(partitionVars.BoardSuperPartitionGroups) {
52*333d2b36SAndroid Build Coastguard Worker		info := filesystem.PartitionGroupsInfo{
53*333d2b36SAndroid Build Coastguard Worker			Name:          groupName,
54*333d2b36SAndroid Build Coastguard Worker			GroupSize:     partitionVars.BoardSuperPartitionGroups[groupName].GroupSize,
55*333d2b36SAndroid Build Coastguard Worker			PartitionList: partitionVars.BoardSuperPartitionGroups[groupName].PartitionList,
56*333d2b36SAndroid Build Coastguard Worker		}
57*333d2b36SAndroid Build Coastguard Worker		partitionGroupsInfo = append(partitionGroupsInfo, info)
58*333d2b36SAndroid Build Coastguard Worker	}
59*333d2b36SAndroid Build Coastguard Worker	superImageProps.Partition_groups = partitionGroupsInfo
60*333d2b36SAndroid Build Coastguard Worker
61*333d2b36SAndroid Build Coastguard Worker	partitionNameProps := &filesystem.SuperImagePartitionNameProperties{}
62*333d2b36SAndroid Build Coastguard Worker	if android.InList("system", partitions) {
63*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.System_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system"))
64*333d2b36SAndroid Build Coastguard Worker	}
65*333d2b36SAndroid Build Coastguard Worker	if android.InList("system_ext", partitions) {
66*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.System_ext_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext"))
67*333d2b36SAndroid Build Coastguard Worker	}
68*333d2b36SAndroid Build Coastguard Worker	if android.InList("system_dlkm", partitions) {
69*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.System_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_dlkm"))
70*333d2b36SAndroid Build Coastguard Worker	}
71*333d2b36SAndroid Build Coastguard Worker	if android.InList("system_other", partitions) {
72*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.System_other_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_other"))
73*333d2b36SAndroid Build Coastguard Worker	}
74*333d2b36SAndroid Build Coastguard Worker	if android.InList("product", partitions) {
75*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.Product_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product"))
76*333d2b36SAndroid Build Coastguard Worker	}
77*333d2b36SAndroid Build Coastguard Worker	if android.InList("vendor", partitions) {
78*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.Vendor_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor"))
79*333d2b36SAndroid Build Coastguard Worker	}
80*333d2b36SAndroid Build Coastguard Worker	if android.InList("vendor_dlkm", partitions) {
81*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor_dlkm"))
82*333d2b36SAndroid Build Coastguard Worker	}
83*333d2b36SAndroid Build Coastguard Worker	if android.InList("odm", partitions) {
84*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.Odm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm"))
85*333d2b36SAndroid Build Coastguard Worker	}
86*333d2b36SAndroid Build Coastguard Worker	if android.InList("odm_dlkm", partitions) {
87*333d2b36SAndroid Build Coastguard Worker		partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm_dlkm"))
88*333d2b36SAndroid Build Coastguard Worker	}
89*333d2b36SAndroid Build Coastguard Worker
90*333d2b36SAndroid Build Coastguard Worker	ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps)
91*333d2b36SAndroid Build Coastguard Worker}
92