mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 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 | |
| 15 | package fsgen |
| 16 | |
| 17 | import ( |
| 18 | "strconv" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/filesystem" |
Jihoon Kang | 1259eff | 2025-01-09 22:11:03 +0000 | [diff] [blame] | 22 | |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
| 26 | func buildingSuperImage(partitionVars android.PartitionVariables) bool { |
| 27 | return partitionVars.ProductBuildSuperPartition |
| 28 | } |
| 29 | |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 30 | func createSuperImage( |
| 31 | ctx android.LoadHookContext, |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 32 | partitions allGeneratedPartitionData, |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 33 | partitionVars android.PartitionVariables, |
| 34 | systemOtherImageName string, |
| 35 | ) []string { |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 36 | baseProps := &struct { |
| 37 | Name *string |
| 38 | }{ |
Jihoon Kang | 1259eff | 2025-01-09 22:11:03 +0000 | [diff] [blame] | 39 | Name: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "super")), |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | superImageProps := &filesystem.SuperImageProperties{ |
Spandan Das | 9da8a2d | 2025-02-28 07:45:30 +0000 | [diff] [blame] | 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), |
Spandan Das | d73441e | 2025-03-10 22:34:25 +0000 | [diff] [blame] | 49 | Create_super_empty: proptools.BoolPtr(partitionVars.BuildingSuperEmptyImage), |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 50 | } |
Cole Faust | 498ffc1 | 2025-01-15 14:19:32 -0800 | [diff] [blame] | 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 { |
Cole Faust | 29e333d | 2025-01-15 16:53:44 -0800 | [diff] [blame] | 68 | ctx.ModuleErrorf("COW version must be an int, got %q", partitionVars.ProductVirtualAbCowVersion) |
Cole Faust | 498ffc1 | 2025-01-15 14:19:32 -0800 | [diff] [blame] | 69 | } |
| 70 | superImageProps.Virtual_ab.Cow_version = proptools.Int64Ptr(version) |
| 71 | } |
| 72 | } |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 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 | |
Cole Faust | 74ee4e0 | 2025-01-16 14:55:35 -0800 | [diff] [blame] | 89 | if systemOtherImageName != "" { |
| 90 | superImageProps.System_other_partition = proptools.StringPtr(systemOtherImageName) |
| 91 | } |
| 92 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 93 | var superImageSubpartitions []string |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 94 | partitionNameProps := &filesystem.SuperImagePartitionNameProperties{} |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 95 | if modName := partitions.nameForType("system"); modName != "" { |
| 96 | partitionNameProps.System_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 97 | superImageSubpartitions = append(superImageSubpartitions, "system") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 98 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 99 | if modName := partitions.nameForType("system_ext"); modName != "" { |
| 100 | partitionNameProps.System_ext_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 101 | superImageSubpartitions = append(superImageSubpartitions, "system_ext") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 102 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 103 | if modName := partitions.nameForType("system_dlkm"); modName != "" { |
| 104 | partitionNameProps.System_dlkm_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 105 | superImageSubpartitions = append(superImageSubpartitions, "system_dlkm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 106 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 107 | if modName := partitions.nameForType("system_other"); modName != "" { |
| 108 | partitionNameProps.System_other_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 109 | superImageSubpartitions = append(superImageSubpartitions, "system_other") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 110 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 111 | if modName := partitions.nameForType("product"); modName != "" { |
| 112 | partitionNameProps.Product_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 113 | superImageSubpartitions = append(superImageSubpartitions, "product") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 114 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 115 | if modName := partitions.nameForType("vendor"); modName != "" { |
| 116 | partitionNameProps.Vendor_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 117 | superImageSubpartitions = append(superImageSubpartitions, "vendor") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 118 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 119 | if modName := partitions.nameForType("vendor_dlkm"); modName != "" { |
| 120 | partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 121 | superImageSubpartitions = append(superImageSubpartitions, "vendor_dlkm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 122 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 123 | if modName := partitions.nameForType("odm"); modName != "" { |
| 124 | partitionNameProps.Odm_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 125 | superImageSubpartitions = append(superImageSubpartitions, "odm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 126 | } |
Cole Faust | 76e8aa1 | 2025-01-27 18:21:31 -0800 | [diff] [blame] | 127 | if modName := partitions.nameForType("odm_dlkm"); modName != "" { |
| 128 | partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(modName) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 129 | superImageSubpartitions = append(superImageSubpartitions, "odm_dlkm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 133 | return superImageSubpartitions |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 134 | } |