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 | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 30 | func createSuperImage(ctx android.LoadHookContext, partitions []string, partitionVars android.PartitionVariables) []string { |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 31 | baseProps := &struct { |
| 32 | Name *string |
| 33 | }{ |
Jihoon Kang | 1259eff | 2025-01-09 22:11:03 +0000 | [diff] [blame] | 34 | Name: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "super")), |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | superImageProps := &filesystem.SuperImageProperties{ |
| 38 | Metadata_device: proptools.StringPtr(partitionVars.BoardSuperPartitionMetadataDevice), |
mrziwang | f3c8ddf | 2024-12-05 17:15:11 -0800 | [diff] [blame] | 39 | Block_devices: partitionVars.BoardSuperPartitionBlockDevices, |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 40 | Ab_update: proptools.BoolPtr(partitionVars.AbOtaUpdater), |
| 41 | Retrofit: proptools.BoolPtr(partitionVars.ProductRetrofitDynamicPartitions), |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 42 | Use_dynamic_partitions: proptools.BoolPtr(partitionVars.ProductUseDynamicPartitions), |
| 43 | } |
Cole Faust | 498ffc1 | 2025-01-15 14:19:32 -0800 | [diff] [blame] | 44 | if partitionVars.ProductVirtualAbOta { |
| 45 | superImageProps.Virtual_ab.Enable = proptools.BoolPtr(true) |
| 46 | superImageProps.Virtual_ab.Retrofit = proptools.BoolPtr(partitionVars.ProductVirtualAbOtaRetrofit) |
| 47 | superImageProps.Virtual_ab.Compression = proptools.BoolPtr(partitionVars.ProductVirtualAbCompression) |
| 48 | if partitionVars.ProductVirtualAbCompressionMethod != "" { |
| 49 | superImageProps.Virtual_ab.Compression_method = proptools.StringPtr(partitionVars.ProductVirtualAbCompressionMethod) |
| 50 | } |
| 51 | if partitionVars.ProductVirtualAbCompressionFactor != "" { |
| 52 | factor, err := strconv.ParseInt(partitionVars.ProductVirtualAbCompressionFactor, 10, 32) |
| 53 | if err != nil { |
| 54 | ctx.ModuleErrorf("Compression factor must be an int, got %q", partitionVars.ProductVirtualAbCompressionFactor) |
| 55 | } |
| 56 | superImageProps.Virtual_ab.Compression_factor = proptools.Int64Ptr(factor) |
| 57 | } |
| 58 | if partitionVars.ProductVirtualAbCowVersion != "" { |
| 59 | version, err := strconv.ParseInt(partitionVars.ProductVirtualAbCowVersion, 10, 32) |
| 60 | if err != nil { |
| 61 | ctx.ModuleErrorf("Compression factor must be an int, got %q", partitionVars.ProductVirtualAbCowVersion) |
| 62 | } |
| 63 | superImageProps.Virtual_ab.Cow_version = proptools.Int64Ptr(version) |
| 64 | } |
| 65 | } |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 66 | size, _ := strconv.ParseInt(partitionVars.BoardSuperPartitionSize, 10, 64) |
| 67 | superImageProps.Size = proptools.Int64Ptr(size) |
| 68 | sparse := !partitionVars.TargetUserimagesSparseExtDisabled && !partitionVars.TargetUserimagesSparseF2fsDisabled |
| 69 | superImageProps.Sparse = proptools.BoolPtr(sparse) |
| 70 | |
| 71 | var partitionGroupsInfo []filesystem.PartitionGroupsInfo |
| 72 | for _, groupName := range android.SortedKeys(partitionVars.BoardSuperPartitionGroups) { |
| 73 | info := filesystem.PartitionGroupsInfo{ |
| 74 | Name: groupName, |
| 75 | GroupSize: partitionVars.BoardSuperPartitionGroups[groupName].GroupSize, |
| 76 | PartitionList: partitionVars.BoardSuperPartitionGroups[groupName].PartitionList, |
| 77 | } |
| 78 | partitionGroupsInfo = append(partitionGroupsInfo, info) |
| 79 | } |
| 80 | superImageProps.Partition_groups = partitionGroupsInfo |
| 81 | |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 82 | var superImageSubpartitions []string |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 83 | partitionNameProps := &filesystem.SuperImagePartitionNameProperties{} |
| 84 | if android.InList("system", partitions) { |
| 85 | partitionNameProps.System_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 86 | superImageSubpartitions = append(superImageSubpartitions, "system") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 87 | } |
| 88 | if android.InList("system_ext", partitions) { |
| 89 | partitionNameProps.System_ext_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_ext")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 90 | superImageSubpartitions = append(superImageSubpartitions, "system_ext") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 91 | } |
| 92 | if android.InList("system_dlkm", partitions) { |
| 93 | partitionNameProps.System_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_dlkm")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 94 | superImageSubpartitions = append(superImageSubpartitions, "system_dlkm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 95 | } |
| 96 | if android.InList("system_other", partitions) { |
| 97 | partitionNameProps.System_other_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system_other")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 98 | superImageSubpartitions = append(superImageSubpartitions, "system_other") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 99 | } |
| 100 | if android.InList("product", partitions) { |
| 101 | partitionNameProps.Product_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "product")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 102 | superImageSubpartitions = append(superImageSubpartitions, "product") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 103 | } |
| 104 | if android.InList("vendor", partitions) { |
| 105 | partitionNameProps.Vendor_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 106 | superImageSubpartitions = append(superImageSubpartitions, "vendor") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 107 | } |
| 108 | if android.InList("vendor_dlkm", partitions) { |
| 109 | partitionNameProps.Vendor_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "vendor_dlkm")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 110 | superImageSubpartitions = append(superImageSubpartitions, "vendor_dlkm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 111 | } |
| 112 | if android.InList("odm", partitions) { |
| 113 | partitionNameProps.Odm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 114 | superImageSubpartitions = append(superImageSubpartitions, "odm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 115 | } |
| 116 | if android.InList("odm_dlkm", partitions) { |
| 117 | partitionNameProps.Odm_dlkm_partition = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "odm_dlkm")) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 118 | superImageSubpartitions = append(superImageSubpartitions, "odm_dlkm") |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | ctx.CreateModule(filesystem.SuperImageFactory, baseProps, superImageProps, partitionNameProps) |
Cole Faust | 2bdc5e5 | 2025-01-10 10:29:36 -0800 | [diff] [blame] | 122 | return superImageSubpartitions |
mrziwang | 79730d4 | 2024-12-02 22:13:59 -0800 | [diff] [blame] | 123 | } |