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 "github.com/google/blueprint/proptools" 23) 24 25func buildingSuperImage(partitionVars android.PartitionVariables) bool { 26 return partitionVars.ProductBuildSuperPartition 27} 28 29func createSuperImage(ctx android.LoadHookContext, partitions []string, partitionVars android.PartitionVariables) { 30 baseProps := &struct { 31 Name *string 32 }{ 33 Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "super")), 34 } 35 36 superImageProps := &filesystem.SuperImageProperties{ 37 Metadata_device: proptools.StringPtr(partitionVars.BoardSuperPartitionMetadataDevice), 38 Block_devices: partitionVars.BoardSuperPartitionBlockDevices, 39 Ab_update: proptools.BoolPtr(partitionVars.AbOtaUpdater), 40 Retrofit: proptools.BoolPtr(partitionVars.ProductRetrofitDynamicPartitions), 41 Virtual_ab: proptools.BoolPtr(partitionVars.ProductVirtualAbOta), 42 Virtual_ab_retrofit: proptools.BoolPtr(partitionVars.ProductVirtualAbOtaRetrofit), 43 Use_dynamic_partitions: proptools.BoolPtr(partitionVars.ProductUseDynamicPartitions), 44 } 45 size, _ := strconv.ParseInt(partitionVars.BoardSuperPartitionSize, 10, 64) 46 superImageProps.Size = proptools.Int64Ptr(size) 47 sparse := !partitionVars.TargetUserimagesSparseExtDisabled && !partitionVars.TargetUserimagesSparseF2fsDisabled 48 superImageProps.Sparse = proptools.BoolPtr(sparse) 49 50 var partitionGroupsInfo []filesystem.PartitionGroupsInfo 51 for _, groupName := range android.SortedKeys(partitionVars.BoardSuperPartitionGroups) { 52 info := filesystem.PartitionGroupsInfo{ 53 Name: groupName, 54 GroupSize: partitionVars.BoardSuperPartitionGroups[groupName].GroupSize, 55 PartitionList: partitionVars.BoardSuperPartitionGroups[groupName].PartitionList, 56 } 57 partitionGroupsInfo = append(partitionGroupsInfo, info) 58 } 59 superImageProps.Partition_groups = partitionGroupsInfo 60 61 partitionNameProps := &filesystem.SuperImagePartitionNameProperties{} 62 if android.InList("system", partitions) { 63 partitionNameProps.System_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system")) 64 } 65 if android.InList("system_ext", partitions) { 66 partitionNameProps.System_ext_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext")) 67 } 68 if android.InList("system_dlkm", partitions) { 69 partitionNameProps.System_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_dlkm")) 70 } 71 if android.InList("system_other", partitions) { 72 partitionNameProps.System_other_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_other")) 73 } 74 if android.InList("product", partitions) { 75 partitionNameProps.Product_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product")) 76 } 77 if android.InList("vendor", partitions) { 78 partitionNameProps.Vendor_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor")) 79 } 80 if android.InList("vendor_dlkm", partitions) { 81 partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor_dlkm")) 82 } 83 if android.InList("odm", partitions) { 84 partitionNameProps.Odm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm")) 85 } 86 if android.InList("odm_dlkm", partitions) { 87 partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm_dlkm")) 88 } 89 90 ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps) 91} 92