| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 1 | // Copyright (C) 2020 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 filesystem | 
 | 16 |  | 
 | 17 | import ( | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 18 | 	"crypto/sha256" | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 19 | 	"fmt" | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 20 | 	"io" | 
| Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 21 | 	"path/filepath" | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 22 | 	"slices" | 
| Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 23 | 	"strconv" | 
| Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 24 | 	"strings" | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 25 |  | 
 | 26 | 	"android/soong/android" | 
| Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 27 | 	"android/soong/cc" | 
| Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 28 |  | 
 | 29 | 	"github.com/google/blueprint" | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 30 | 	"github.com/google/blueprint/proptools" | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 31 | ) | 
 | 32 |  | 
 | 33 | func init() { | 
| Jooyung Han | 9706cbc | 2021-04-15 22:43:48 +0900 | [diff] [blame] | 34 | 	registerBuildComponents(android.InitRegistrationContext) | 
 | 35 | } | 
 | 36 |  | 
 | 37 | func registerBuildComponents(ctx android.RegistrationContext) { | 
 | 38 | 	ctx.RegisterModuleType("android_filesystem", filesystemFactory) | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 39 | 	ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory) | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 40 | 	ctx.RegisterModuleType("android_system_image", systemImageFactory) | 
| Jiyong Park | bc48548 | 2022-11-15 22:31:49 +0900 | [diff] [blame] | 41 | 	ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory) | 
| Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 42 | 	ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory) | 
| Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 43 | 	ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory) | 
| Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 44 | 	ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory) | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 45 | } | 
 | 46 |  | 
 | 47 | type filesystem struct { | 
 | 48 | 	android.ModuleBase | 
 | 49 | 	android.PackagingBase | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 50 | 	android.DefaultableModuleBase | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 51 |  | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 52 | 	properties filesystemProperties | 
 | 53 |  | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 54 | 	// Function that builds extra files under the root directory and returns the files | 
 | 55 | 	buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths | 
 | 56 |  | 
| Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 57 | 	// Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs() | 
 | 58 | 	filterPackagingSpec func(spec android.PackagingSpec) bool | 
| Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 59 |  | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 60 | 	output     android.OutputPath | 
 | 61 | 	installDir android.InstallPath | 
| Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 62 |  | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 63 | 	// For testing. Keeps the result of CopySpecsToDir() | 
| Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 64 | 	entries []string | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 65 | } | 
 | 66 |  | 
| Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 67 | type symlinkDefinition struct { | 
 | 68 | 	Target *string | 
 | 69 | 	Name   *string | 
 | 70 | } | 
 | 71 |  | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 72 | type filesystemProperties struct { | 
 | 73 | 	// When set to true, sign the image with avbtool. Default is false. | 
 | 74 | 	Use_avb *bool | 
 | 75 |  | 
 | 76 | 	// Path to the private key that avbtool will use to sign this filesystem image. | 
 | 77 | 	// TODO(jiyong): allow apex_key to be specified here | 
 | 78 | 	Avb_private_key *string `android:"path"` | 
 | 79 |  | 
| Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 80 | 	// Signing algorithm for avbtool. Default is SHA256_RSA4096. | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 81 | 	Avb_algorithm *string | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 82 |  | 
| Shikha Panwar | 01403bb | 2022-12-22 12:22:57 +0000 | [diff] [blame] | 83 | 	// Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to | 
 | 84 | 	// avbtool. Default used by avbtool is sha1. | 
| Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 85 | 	Avb_hash_algorithm *string | 
 | 86 |  | 
| Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 87 | 	// The index used to prevent rollback of the image. Only used if use_avb is true. | 
 | 88 | 	Rollback_index *int64 | 
 | 89 |  | 
| Jiyong Park | ac4076d | 2021-03-15 23:21:30 +0900 | [diff] [blame] | 90 | 	// Name of the partition stored in vbmeta desc. Defaults to the name of this module. | 
 | 91 | 	Partition_name *string | 
 | 92 |  | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 93 | 	// Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default | 
 | 94 | 	// is ext4. | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 95 | 	Type *string | 
| Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 96 |  | 
| Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 97 | 	// Identifies which partition this is for //visibility:any_system_image (and others) visibility | 
 | 98 | 	// checks, and will be used in the future for API surface checks. | 
 | 99 | 	Partition_type *string | 
 | 100 |  | 
| Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 101 | 	// file_contexts file to make image. Currently, only ext4 is supported. | 
 | 102 | 	File_contexts *string `android:"path"` | 
| Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 103 |  | 
 | 104 | 	// Base directory relative to root, to which deps are installed, e.g. "system". Default is "." | 
 | 105 | 	// (root). | 
 | 106 | 	Base_dir *string | 
| Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 107 |  | 
 | 108 | 	// Directories to be created under root. e.g. /dev, /proc, etc. | 
 | 109 | 	Dirs []string | 
 | 110 |  | 
 | 111 | 	// Symbolic links to be created under root with "ln -sf <target> <name>". | 
 | 112 | 	Symlinks []symlinkDefinition | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 113 |  | 
 | 114 | 	// Seconds since unix epoch to override timestamps of file entries | 
 | 115 | 	Fake_timestamp *string | 
 | 116 |  | 
 | 117 | 	// When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed. | 
 | 118 | 	// Otherwise, they'll be set as random which might cause indeterministic build output. | 
 | 119 | 	Uuid *string | 
| Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 120 |  | 
 | 121 | 	// Mount point for this image. Default is "/" | 
 | 122 | 	Mount_point *string | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 123 |  | 
 | 124 | 	// If set to the name of a partition ("system", "vendor", etc), this filesystem module | 
 | 125 | 	// will also include the contents of the make-built staging directories. If any soong | 
 | 126 | 	// modules would be installed to the same location as a make module, they will overwrite | 
 | 127 | 	// the make version. | 
 | 128 | 	Include_make_built_files string | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 129 |  | 
| Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 130 | 	// When set, builds etc/event-log-tags file by merging logtags from all dependencies. | 
 | 131 | 	// Default is false | 
 | 132 | 	Build_logtags *bool | 
 | 133 |  | 
| Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 134 | 	// Install aconfig_flags.pb file for the modules installed in this partition. | 
 | 135 | 	Gen_aconfig_flags_pb *bool | 
 | 136 |  | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 137 | 	Fsverity fsverityProperties | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 138 | } | 
 | 139 |  | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 140 | // android_filesystem packages a set of modules and their transitive dependencies into a filesystem | 
 | 141 | // image. The filesystem images are expected to be mounted in the target device, which means the | 
 | 142 | // modules in the filesystem image are built for the target device (i.e. Android, not Linux host). | 
 | 143 | // The modules are placed in the filesystem image just like they are installed to the ordinary | 
 | 144 | // partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory. | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 145 | func filesystemFactory() android.Module { | 
 | 146 | 	module := &filesystem{} | 
| Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 147 | 	module.filterPackagingSpec = module.filterInstallablePackagingSpec | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 148 | 	initFilesystemModule(module) | 
 | 149 | 	return module | 
 | 150 | } | 
 | 151 |  | 
 | 152 | func initFilesystemModule(module *filesystem) { | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 153 | 	module.AddProperties(&module.properties) | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 154 | 	android.InitPackageModule(module) | 
| Jiyong Park | 3ea9b65 | 2024-05-15 23:01:54 +0900 | [diff] [blame] | 155 | 	module.PackagingBase.DepsCollectFirstTargetOnly = true | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 156 | 	android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 157 | 	android.InitDefaultableModule(module) | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 158 | } | 
 | 159 |  | 
| Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 160 | var dependencyTag = struct { | 
 | 161 | 	blueprint.BaseDependencyTag | 
| Jooyung Han | 092ef81 | 2021-03-10 15:40:34 +0900 | [diff] [blame] | 162 | 	android.PackagingItemAlwaysDepTag | 
| Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 163 | }{} | 
| Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 164 |  | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 165 | func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 166 | 	f.AddDeps(ctx, dependencyTag) | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 167 | } | 
 | 168 |  | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 169 | type fsType int | 
 | 170 |  | 
 | 171 | const ( | 
 | 172 | 	ext4Type fsType = iota | 
 | 173 | 	compressedCpioType | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 174 | 	cpioType // uncompressed | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 175 | 	unknown | 
 | 176 | ) | 
 | 177 |  | 
 | 178 | func (f *filesystem) fsType(ctx android.ModuleContext) fsType { | 
 | 179 | 	typeStr := proptools.StringDefault(f.properties.Type, "ext4") | 
 | 180 | 	switch typeStr { | 
 | 181 | 	case "ext4": | 
 | 182 | 		return ext4Type | 
 | 183 | 	case "compressed_cpio": | 
 | 184 | 		return compressedCpioType | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 185 | 	case "cpio": | 
 | 186 | 		return cpioType | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 187 | 	default: | 
 | 188 | 		ctx.PropertyErrorf("type", "%q not supported", typeStr) | 
 | 189 | 		return unknown | 
 | 190 | 	} | 
 | 191 | } | 
 | 192 |  | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 193 | func (f *filesystem) installFileName() string { | 
 | 194 | 	return f.BaseModuleName() + ".img" | 
 | 195 | } | 
 | 196 |  | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 197 | func (f *filesystem) partitionName() string { | 
 | 198 | 	return proptools.StringDefault(f.properties.Partition_name, f.Name()) | 
 | 199 | } | 
 | 200 |  | 
| Jiyong Park | 7e7d4af | 2024-05-01 12:36:10 +0000 | [diff] [blame] | 201 | func (f *filesystem) filterInstallablePackagingSpec(ps android.PackagingSpec) bool { | 
 | 202 | 	// Filesystem module respects the installation semantic. A PackagingSpec from a module with | 
 | 203 | 	// IsSkipInstall() is skipped. | 
 | 204 | 	return !ps.SkipInstall() | 
 | 205 | } | 
 | 206 |  | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 207 | var pctx = android.NewPackageContext("android/soong/filesystem") | 
 | 208 |  | 
 | 209 | func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 210 | 	validatePartitionType(ctx, f) | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 211 | 	switch f.fsType(ctx) { | 
 | 212 | 	case ext4Type: | 
 | 213 | 		f.output = f.buildImageUsingBuildImage(ctx) | 
 | 214 | 	case compressedCpioType: | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 215 | 		f.output = f.buildCpioImage(ctx, true) | 
 | 216 | 	case cpioType: | 
 | 217 | 		f.output = f.buildCpioImage(ctx, false) | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 218 | 	default: | 
 | 219 | 		return | 
 | 220 | 	} | 
 | 221 |  | 
 | 222 | 	f.installDir = android.PathForModuleInstall(ctx, "etc") | 
 | 223 | 	ctx.InstallFile(f.installDir, f.installFileName(), f.output) | 
 | 224 | } | 
 | 225 |  | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 226 | func validatePartitionType(ctx android.ModuleContext, p partition) { | 
 | 227 | 	if !android.InList(p.PartitionType(), validPartitions) { | 
 | 228 | 		ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType()) | 
 | 229 | 	} | 
 | 230 |  | 
 | 231 | 	ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) { | 
 | 232 | 		if fdm, ok := m.(*filesystemDefaults); ok { | 
 | 233 | 			if p.PartitionType() != fdm.PartitionType() { | 
 | 234 | 				ctx.PropertyErrorf("partition_type", | 
 | 235 | 					"%s doesn't match with the partition type %s of the filesystem default module %s", | 
 | 236 | 					p.PartitionType(), fdm.PartitionType(), m.Name()) | 
 | 237 | 			} | 
 | 238 | 		} | 
 | 239 | 	}) | 
 | 240 | } | 
 | 241 |  | 
| Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 242 | // Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files | 
 | 243 | // already in `rootDir`. | 
 | 244 | func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) { | 
| Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 245 | 	// create dirs and symlinks | 
 | 246 | 	for _, dir := range f.properties.Dirs { | 
 | 247 | 		// OutputPath.Join verifies dir | 
 | 248 | 		builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String()) | 
 | 249 | 	} | 
 | 250 |  | 
 | 251 | 	for _, symlink := range f.properties.Symlinks { | 
 | 252 | 		name := strings.TrimSpace(proptools.String(symlink.Name)) | 
 | 253 | 		target := strings.TrimSpace(proptools.String(symlink.Target)) | 
 | 254 |  | 
 | 255 | 		if name == "" { | 
 | 256 | 			ctx.PropertyErrorf("symlinks", "Name can't be empty") | 
 | 257 | 			continue | 
 | 258 | 		} | 
 | 259 |  | 
 | 260 | 		if target == "" { | 
 | 261 | 			ctx.PropertyErrorf("symlinks", "Target can't be empty") | 
 | 262 | 			continue | 
 | 263 | 		} | 
 | 264 |  | 
 | 265 | 		// OutputPath.Join verifies name. don't need to verify target. | 
 | 266 | 		dst := rootDir.Join(ctx, name) | 
| Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 267 | 		builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst) | 
| Inseob Kim | 14199b0 | 2021-02-09 21:18:31 +0900 | [diff] [blame] | 268 | 		builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String())) | 
 | 269 | 		builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String()) | 
 | 270 | 	} | 
| Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 271 |  | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 272 | 	// create extra files if there's any | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 273 | 	if f.buildExtraFiles != nil { | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 274 | 		rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath | 
 | 275 | 		extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles) | 
 | 276 | 		for _, f := range extraFiles { | 
 | 277 | 			rel, err := filepath.Rel(rootForExtraFiles.String(), f.String()) | 
 | 278 | 			if err != nil || strings.HasPrefix(rel, "..") { | 
 | 279 | 				ctx.ModuleErrorf("can't make %q relative to %q", f, rootForExtraFiles) | 
 | 280 | 			} | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 281 | 		} | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 282 | 		if len(extraFiles) > 0 { | 
 | 283 | 			builder.Command().BuiltTool("merge_directories"). | 
 | 284 | 				Implicits(extraFiles.Paths()). | 
 | 285 | 				Text(rootDir.String()). | 
 | 286 | 				Text(rootForExtraFiles.String()) | 
 | 287 | 		} | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 288 | 	} | 
| Inseob Kim | 2ce1b5d | 2021-02-15 17:01:04 +0900 | [diff] [blame] | 289 | } | 
 | 290 |  | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 291 | func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath { | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 292 | 	rootDir := android.PathForModuleOut(ctx, "root").OutputPath | 
| Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 293 | 	rebasedDir := rootDir | 
 | 294 | 	if f.properties.Base_dir != nil { | 
 | 295 | 		rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) | 
 | 296 | 	} | 
 | 297 | 	builder := android.NewRuleBuilder(pctx, ctx) | 
 | 298 | 	// Wipe the root dir to get rid of leftover files from prior builds | 
 | 299 | 	builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 300 | 	specs := f.gatherFilteredPackagingSpecs(ctx) | 
 | 301 | 	f.entries = f.CopySpecsToDir(ctx, builder, specs, rebasedDir) | 
| Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 302 |  | 
 | 303 | 	f.buildNonDepsFiles(ctx, builder, rootDir) | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 304 | 	f.addMakeBuiltFiles(ctx, builder, rootDir) | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 305 | 	f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) | 
| Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 306 | 	f.buildEventLogtagsFile(ctx, builder, rebasedDir) | 
| Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 307 | 	f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 308 |  | 
| Nikita Ioffe | 519015f | 2022-12-23 15:36:29 +0000 | [diff] [blame] | 309 | 	// run host_init_verifier | 
 | 310 | 	// Ideally we should have a concept of pluggable linters that verify the generated image. | 
 | 311 | 	// While such concept is not implement this will do. | 
 | 312 | 	// TODO(b/263574231): substitute with pluggable linter. | 
 | 313 | 	builder.Command(). | 
 | 314 | 		BuiltTool("host_init_verifier"). | 
 | 315 | 		FlagWithArg("--out_system=", rootDir.String()+"/system") | 
 | 316 |  | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 317 | 	propFile, toolDeps := f.buildPropFile(ctx) | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 318 | 	output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 319 | 	builder.Command().BuiltTool("build_image"). | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 320 | 		Text(rootDir.String()). // input directory | 
 | 321 | 		Input(propFile). | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 322 | 		Implicits(toolDeps). | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 323 | 		Output(output). | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 324 | 		Text(rootDir.String()) // directory where to find fs_config_files|dirs | 
 | 325 |  | 
 | 326 | 	// rootDir is not deleted. Might be useful for quick inspection. | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 327 | 	builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 328 |  | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 329 | 	return output | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 330 | } | 
 | 331 |  | 
| Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 332 | func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath { | 
 | 333 | 	builder := android.NewRuleBuilder(pctx, ctx) | 
 | 334 | 	fcBin := android.PathForModuleOut(ctx, "file_contexts.bin") | 
 | 335 | 	builder.Command().BuiltTool("sefcontext_compile"). | 
 | 336 | 		FlagWithOutput("-o ", fcBin). | 
 | 337 | 		Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts))) | 
 | 338 | 	builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName())) | 
 | 339 | 	return fcBin.OutputPath | 
 | 340 | } | 
 | 341 |  | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 342 | // Calculates avb_salt from entry list (sorted) for deterministic output. | 
 | 343 | func (f *filesystem) salt() string { | 
 | 344 | 	return sha1sum(f.entries) | 
 | 345 | } | 
 | 346 |  | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 347 | func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) { | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 348 | 	var deps android.Paths | 
| Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 349 | 	var propFileString strings.Builder | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 350 | 	addStr := func(name string, value string) { | 
| Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 351 | 		propFileString.WriteString(name) | 
 | 352 | 		propFileString.WriteRune('=') | 
 | 353 | 		propFileString.WriteString(value) | 
 | 354 | 		propFileString.WriteRune('\n') | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 355 | 	} | 
 | 356 | 	addPath := func(name string, path android.Path) { | 
| Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 357 | 		addStr(name, path.String()) | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 358 | 		deps = append(deps, path) | 
 | 359 | 	} | 
 | 360 |  | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 361 | 	// Type string that build_image.py accepts. | 
 | 362 | 	fsTypeStr := func(t fsType) string { | 
 | 363 | 		switch t { | 
 | 364 | 		// TODO(jiyong): add more types like f2fs, erofs, etc. | 
 | 365 | 		case ext4Type: | 
 | 366 | 			return "ext4" | 
 | 367 | 		} | 
 | 368 | 		panic(fmt.Errorf("unsupported fs type %v", t)) | 
 | 369 | 	} | 
 | 370 |  | 
 | 371 | 	addStr("fs_type", fsTypeStr(f.fsType(ctx))) | 
| Inseob Kim | 376d72f | 2023-11-01 15:40:25 +0900 | [diff] [blame] | 372 | 	addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/")) | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 373 | 	addStr("use_dynamic_partition_size", "true") | 
 | 374 | 	addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")) | 
 | 375 | 	// b/177813163 deps of the host tools have to be added. Remove this. | 
 | 376 | 	for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} { | 
 | 377 | 		deps = append(deps, ctx.Config().HostToolPath(ctx, t)) | 
 | 378 | 	} | 
 | 379 |  | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 380 | 	if proptools.Bool(f.properties.Use_avb) { | 
 | 381 | 		addStr("avb_hashtree_enable", "true") | 
 | 382 | 		addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool")) | 
 | 383 | 		algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096") | 
 | 384 | 		addStr("avb_algorithm", algorithm) | 
 | 385 | 		key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) | 
 | 386 | 		addPath("avb_key_path", key) | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 387 | 		addStr("partition_name", f.partitionName()) | 
| Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 388 | 		avb_add_hashtree_footer_args := "--do_not_generate_fec" | 
 | 389 | 		if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { | 
 | 390 | 			avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm | 
 | 391 | 		} | 
| Nikita Ioffe | 2c8cdc6 | 2024-03-27 22:19:30 +0000 | [diff] [blame] | 392 | 		if f.properties.Rollback_index != nil { | 
 | 393 | 			rollbackIndex := proptools.Int(f.properties.Rollback_index) | 
 | 394 | 			if rollbackIndex < 0 { | 
 | 395 | 				ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative") | 
 | 396 | 			} | 
 | 397 | 			avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex) | 
 | 398 | 		} | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 399 | 		securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch" | 
| Seungjae Yoo | a30e450 | 2023-11-09 14:55:44 +0900 | [diff] [blame] | 400 | 		securityPatchValue := ctx.Config().PlatformSecurityPatch() | 
 | 401 | 		avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue | 
| Shikha Panwar | e6f3063 | 2022-12-21 12:54:45 +0000 | [diff] [blame] | 402 | 		addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 403 | 		addStr("avb_salt", f.salt()) | 
| Jiyong Park | 71baa76 | 2021-01-18 21:11:03 +0900 | [diff] [blame] | 404 | 	} | 
 | 405 |  | 
| Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 406 | 	if proptools.String(f.properties.File_contexts) != "" { | 
 | 407 | 		addPath("selinux_fc", f.buildFileContexts(ctx)) | 
 | 408 | 	} | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 409 | 	if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" { | 
 | 410 | 		addStr("timestamp", timestamp) | 
 | 411 | 	} | 
 | 412 | 	if uuid := proptools.String(f.properties.Uuid); uuid != "" { | 
 | 413 | 		addStr("uuid", uuid) | 
 | 414 | 		addStr("hash_seed", uuid) | 
 | 415 | 	} | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 416 | 	propFile = android.PathForModuleOut(ctx, "prop").OutputPath | 
| Cole Faust | cec230a | 2024-03-07 15:51:12 -0800 | [diff] [blame] | 417 | 	android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String()) | 
| Jiyong Park | 7267831 | 2021-01-18 17:29:49 +0900 | [diff] [blame] | 418 | 	return propFile, deps | 
 | 419 | } | 
 | 420 |  | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 421 | func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath { | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 422 | 	if proptools.Bool(f.properties.Use_avb) { | 
 | 423 | 		ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+ | 
 | 424 | 			"Consider adding this to bootimg module and signing the entire boot image.") | 
 | 425 | 	} | 
 | 426 |  | 
| Inseob Kim | cc8e536 | 2021-02-03 14:05:24 +0900 | [diff] [blame] | 427 | 	if proptools.String(f.properties.File_contexts) != "" { | 
 | 428 | 		ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.") | 
 | 429 | 	} | 
 | 430 |  | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 431 | 	if f.properties.Include_make_built_files != "" { | 
 | 432 | 		ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.") | 
 | 433 | 	} | 
 | 434 |  | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 435 | 	rootDir := android.PathForModuleOut(ctx, "root").OutputPath | 
| Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 436 | 	rebasedDir := rootDir | 
 | 437 | 	if f.properties.Base_dir != nil { | 
 | 438 | 		rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir) | 
 | 439 | 	} | 
 | 440 | 	builder := android.NewRuleBuilder(pctx, ctx) | 
 | 441 | 	// Wipe the root dir to get rid of leftover files from prior builds | 
 | 442 | 	builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir) | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 443 | 	specs := f.gatherFilteredPackagingSpecs(ctx) | 
 | 444 | 	f.entries = f.CopySpecsToDir(ctx, builder, specs, rebasedDir) | 
| Cole Faust | 3b806d3 | 2024-03-11 15:15:03 -0700 | [diff] [blame] | 445 |  | 
 | 446 | 	f.buildNonDepsFiles(ctx, builder, rootDir) | 
| Inseob Kim | 5339184 | 2024-03-29 17:44:07 +0900 | [diff] [blame] | 447 | 	f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) | 
| Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 448 | 	f.buildEventLogtagsFile(ctx, builder, rebasedDir) | 
| Justin Yun | 74f3f30 | 2024-05-07 14:32:14 +0900 | [diff] [blame] | 449 | 	f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 450 |  | 
 | 451 | 	output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 452 | 	cmd := builder.Command(). | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 453 | 		BuiltTool("mkbootfs"). | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 454 | 		Text(rootDir.String()) // input directory | 
 | 455 | 	if compressed { | 
 | 456 | 		cmd.Text("|"). | 
 | 457 | 			BuiltTool("lz4"). | 
 | 458 | 			Flag("--favor-decSpeed"). // for faster boot | 
 | 459 | 			Flag("-12").              // maximum compression level | 
 | 460 | 			Flag("-l").               // legacy format for kernel | 
 | 461 | 			Text(">").Output(output) | 
 | 462 | 	} else { | 
 | 463 | 		cmd.Text(">").Output(output) | 
 | 464 | 	} | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 465 |  | 
 | 466 | 	// rootDir is not deleted. Might be useful for quick inspection. | 
| Jiyong Park | 837cdb2 | 2021-02-05 00:17:14 +0900 | [diff] [blame] | 467 | 	builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName())) | 
| Jiyong Park | 11a6597 | 2021-02-01 21:09:38 +0900 | [diff] [blame] | 468 |  | 
 | 469 | 	return output | 
 | 470 | } | 
 | 471 |  | 
| Cole Faust | 4a2a7c9 | 2024-03-12 12:44:40 -0700 | [diff] [blame] | 472 | var validPartitions = []string{ | 
 | 473 | 	"system", | 
 | 474 | 	"userdata", | 
 | 475 | 	"cache", | 
 | 476 | 	"system_other", | 
 | 477 | 	"vendor", | 
 | 478 | 	"product", | 
 | 479 | 	"system_ext", | 
 | 480 | 	"odm", | 
 | 481 | 	"vendor_dlkm", | 
 | 482 | 	"odm_dlkm", | 
 | 483 | 	"system_dlkm", | 
 | 484 | } | 
 | 485 |  | 
 | 486 | func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) { | 
 | 487 | 	partition := f.properties.Include_make_built_files | 
 | 488 | 	if partition == "" { | 
 | 489 | 		return | 
 | 490 | 	} | 
 | 491 | 	if !slices.Contains(validPartitions, partition) { | 
 | 492 | 		ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition) | 
 | 493 | 		return | 
 | 494 | 	} | 
 | 495 | 	stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition) | 
 | 496 | 	fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition) | 
 | 497 | 	stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition) | 
 | 498 |  | 
 | 499 | 	builder.Command().BuiltTool("merge_directories"). | 
 | 500 | 		Implicit(android.PathForArbitraryOutput(ctx, stampFile)). | 
 | 501 | 		Text("--ignore-duplicates"). | 
 | 502 | 		FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)). | 
 | 503 | 		Text(rootDir.String()). | 
 | 504 | 		Text(android.PathForArbitraryOutput(ctx, stagingDir).String()) | 
 | 505 | } | 
 | 506 |  | 
| Inseob Kim | b7b8457 | 2024-04-30 10:51:47 +0900 | [diff] [blame] | 507 | func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { | 
 | 508 | 	if !proptools.Bool(f.properties.Build_logtags) { | 
 | 509 | 		return | 
 | 510 | 	} | 
 | 511 |  | 
 | 512 | 	logtagsFilePaths := make(map[string]bool) | 
 | 513 | 	ctx.WalkDeps(func(child, parent android.Module) bool { | 
 | 514 | 		if logtagsInfo, ok := android.OtherModuleProvider(ctx, child, android.LogtagsProviderKey); ok { | 
 | 515 | 			for _, path := range logtagsInfo.Logtags { | 
 | 516 | 				logtagsFilePaths[path.String()] = true | 
 | 517 | 			} | 
 | 518 | 		} | 
 | 519 | 		return true | 
 | 520 | 	}) | 
 | 521 |  | 
 | 522 | 	if len(logtagsFilePaths) == 0 { | 
 | 523 | 		return | 
 | 524 | 	} | 
 | 525 |  | 
 | 526 | 	etcPath := rebasedDir.Join(ctx, "etc") | 
 | 527 | 	eventLogtagsPath := etcPath.Join(ctx, "event-log-tags") | 
 | 528 | 	builder.Command().Text("mkdir").Flag("-p").Text(etcPath.String()) | 
 | 529 | 	cmd := builder.Command().BuiltTool("merge-event-log-tags"). | 
 | 530 | 		FlagWithArg("-o ", eventLogtagsPath.String()). | 
 | 531 | 		FlagWithInput("-m ", android.MergedLogtagsPath(ctx)) | 
 | 532 |  | 
 | 533 | 	for _, path := range android.SortedKeys(logtagsFilePaths) { | 
 | 534 | 		cmd.Text(path) | 
 | 535 | 	} | 
 | 536 | } | 
 | 537 |  | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 538 | type partition interface { | 
 | 539 | 	PartitionType() string | 
 | 540 | } | 
 | 541 |  | 
| Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 542 | func (f *filesystem) PartitionType() string { | 
 | 543 | 	return proptools.StringDefault(f.properties.Partition_type, "system") | 
 | 544 | } | 
 | 545 |  | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 546 | var _ partition = (*filesystem)(nil) | 
 | 547 |  | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 548 | var _ android.AndroidMkEntriesProvider = (*filesystem)(nil) | 
 | 549 |  | 
 | 550 | // Implements android.AndroidMkEntriesProvider | 
 | 551 | func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { | 
 | 552 | 	return []android.AndroidMkEntries{android.AndroidMkEntries{ | 
 | 553 | 		Class:      "ETC", | 
 | 554 | 		OutputFile: android.OptionalPathForPath(f.output), | 
 | 555 | 		ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 556 | 			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 557 | 				entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) | 
| Jiyong Park | 65c49f5 | 2020-11-24 14:23:26 +0900 | [diff] [blame] | 558 | 				entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) | 
 | 559 | 			}, | 
 | 560 | 		}, | 
 | 561 | 	}} | 
| Jiyong Park | 6f0f688 | 2020-11-12 13:14:30 +0900 | [diff] [blame] | 562 | } | 
| Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 563 |  | 
| Jiyong Park | 940dfd4 | 2021-02-04 15:37:34 +0900 | [diff] [blame] | 564 | var _ android.OutputFileProducer = (*filesystem)(nil) | 
 | 565 |  | 
 | 566 | // Implements android.OutputFileProducer | 
 | 567 | func (f *filesystem) OutputFiles(tag string) (android.Paths, error) { | 
 | 568 | 	if tag == "" { | 
 | 569 | 		return []android.Path{f.output}, nil | 
 | 570 | 	} | 
 | 571 | 	return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
 | 572 | } | 
 | 573 |  | 
| Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 574 | // Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex | 
 | 575 | // package to have access to the output file. | 
 | 576 | type Filesystem interface { | 
 | 577 | 	android.Module | 
 | 578 | 	OutputPath() android.Path | 
| Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 579 |  | 
 | 580 | 	// Returns the output file that is signed by avbtool. If this module is not signed, returns | 
 | 581 | 	// nil. | 
 | 582 | 	SignedOutputPath() android.Path | 
| Jiyong Park | 12a719c | 2021-01-07 15:31:24 +0900 | [diff] [blame] | 583 | } | 
 | 584 |  | 
 | 585 | var _ Filesystem = (*filesystem)(nil) | 
 | 586 |  | 
 | 587 | func (f *filesystem) OutputPath() android.Path { | 
 | 588 | 	return f.output | 
 | 589 | } | 
| Jiyong Park | 972e06c | 2021-03-15 23:32:49 +0900 | [diff] [blame] | 590 |  | 
 | 591 | func (f *filesystem) SignedOutputPath() android.Path { | 
 | 592 | 	if proptools.Bool(f.properties.Use_avb) { | 
 | 593 | 		return f.OutputPath() | 
 | 594 | 	} | 
 | 595 | 	return nil | 
 | 596 | } | 
| Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 597 |  | 
 | 598 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition. | 
 | 599 | // Note that "apex" module installs its contents to "apex"(fake partition) as well | 
 | 600 | // for symbol lookup by imitating "activated" paths. | 
 | 601 | func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec { | 
| Jeongik Cha | 54bf875 | 2024-02-08 10:44:37 +0900 | [diff] [blame] | 602 | 	specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec) | 
| Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 603 | 	return specs | 
 | 604 | } | 
| Jooyung Han | 65f402b | 2022-04-21 14:24:04 +0900 | [diff] [blame] | 605 |  | 
 | 606 | func sha1sum(values []string) string { | 
 | 607 | 	h := sha256.New() | 
 | 608 | 	for _, value := range values { | 
 | 609 | 		io.WriteString(h, value) | 
 | 610 | 	} | 
 | 611 | 	return fmt.Sprintf("%x", h.Sum(nil)) | 
 | 612 | } | 
| Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 613 |  | 
 | 614 | // Base cc.UseCoverage | 
 | 615 |  | 
 | 616 | var _ cc.UseCoverage = (*filesystem)(nil) | 
 | 617 |  | 
| Colin Cross | f5f4ad3 | 2024-01-19 15:41:48 -0800 | [diff] [blame] | 618 | func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { | 
| Jooyung Han | e606759 | 2023-03-16 13:11:17 +0900 | [diff] [blame] | 619 | 	return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() | 
 | 620 | } | 
| Jiyong Park | f46b1af | 2024-04-05 18:13:33 +0900 | [diff] [blame] | 621 |  | 
 | 622 | // android_filesystem_defaults | 
 | 623 |  | 
 | 624 | type filesystemDefaults struct { | 
 | 625 | 	android.ModuleBase | 
 | 626 | 	android.DefaultsModuleBase | 
 | 627 |  | 
 | 628 | 	properties filesystemDefaultsProperties | 
 | 629 | } | 
 | 630 |  | 
 | 631 | type filesystemDefaultsProperties struct { | 
 | 632 | 	// Identifies which partition this is for //visibility:any_system_image (and others) visibility | 
 | 633 | 	// checks, and will be used in the future for API surface checks. | 
 | 634 | 	Partition_type *string | 
 | 635 | } | 
 | 636 |  | 
 | 637 | // android_filesystem_defaults is a default module for android_filesystem and android_system_image | 
 | 638 | func filesystemDefaultsFactory() android.Module { | 
 | 639 | 	module := &filesystemDefaults{} | 
 | 640 | 	module.AddProperties(&module.properties) | 
 | 641 | 	module.AddProperties(&android.PackagingProperties{}) | 
 | 642 | 	android.InitDefaultsModule(module) | 
 | 643 | 	return module | 
 | 644 | } | 
 | 645 |  | 
 | 646 | func (f *filesystemDefaults) PartitionType() string { | 
 | 647 | 	return proptools.StringDefault(f.properties.Partition_type, "system") | 
 | 648 | } | 
 | 649 |  | 
 | 650 | var _ partition = (*filesystemDefaults)(nil) | 
 | 651 |  | 
 | 652 | func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
 | 653 | 	validatePartitionType(ctx, f) | 
 | 654 | } |