2020-11-12 05:14:30 +01:00
|
|
|
// Copyright (C) 2020 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package filesystem
|
|
|
|
|
|
|
|
import (
|
2022-04-21 07:24:04 +02:00
|
|
|
"crypto/sha256"
|
2020-11-12 05:14:30 +01:00
|
|
|
"fmt"
|
2022-04-21 07:24:04 +02:00
|
|
|
"io"
|
2021-02-09 13:18:31 +01:00
|
|
|
"path/filepath"
|
2024-03-12 20:44:40 +01:00
|
|
|
"slices"
|
2024-03-27 23:19:30 +01:00
|
|
|
"strconv"
|
2021-02-09 13:18:31 +01:00
|
|
|
"strings"
|
2020-11-12 05:14:30 +01:00
|
|
|
|
|
|
|
"android/soong/android"
|
2023-03-16 05:11:17 +01:00
|
|
|
"android/soong/cc"
|
2020-11-25 04:44:59 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2021-01-18 13:11:03 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2020-11-12 05:14:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-04-15 15:43:48 +02:00
|
|
|
registerBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("android_filesystem", filesystemFactory)
|
2024-04-05 11:13:33 +02:00
|
|
|
ctx.RegisterModuleType("android_filesystem_defaults", filesystemDefaultsFactory)
|
2021-04-20 04:36:40 +02:00
|
|
|
ctx.RegisterModuleType("android_system_image", systemImageFactory)
|
2022-11-15 14:31:49 +01:00
|
|
|
ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
|
2023-11-22 10:55:07 +01:00
|
|
|
ctx.RegisterModuleType("avb_add_hash_footer_defaults", avbAddHashFooterDefaultsFactory)
|
2023-01-03 17:11:20 +01:00
|
|
|
ctx.RegisterModuleType("avb_gen_vbmeta_image", avbGenVbmetaImageFactory)
|
2023-11-22 10:55:07 +01:00
|
|
|
ctx.RegisterModuleType("avb_gen_vbmeta_image_defaults", avbGenVbmetaImageDefaultsFactory)
|
2020-11-12 05:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type filesystem struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.PackagingBase
|
2024-04-05 11:13:33 +02:00
|
|
|
android.DefaultableModuleBase
|
2020-11-24 06:23:26 +01:00
|
|
|
|
2021-01-18 13:11:03 +01:00
|
|
|
properties filesystemProperties
|
|
|
|
|
2021-04-20 04:36:40 +02:00
|
|
|
// Function that builds extra files under the root directory and returns the files
|
|
|
|
buildExtraFiles func(ctx android.ModuleContext, root android.OutputPath) android.OutputPaths
|
|
|
|
|
2024-02-08 02:44:37 +01:00
|
|
|
// Function that filters PackagingSpec in PackagingBase.GatherPackagingSpecs()
|
|
|
|
filterPackagingSpec func(spec android.PackagingSpec) bool
|
2022-03-25 04:35:46 +01:00
|
|
|
|
2020-11-24 06:23:26 +01:00
|
|
|
output android.OutputPath
|
|
|
|
installDir android.InstallPath
|
2022-03-25 04:35:46 +01:00
|
|
|
|
2024-03-29 09:44:07 +01:00
|
|
|
// For testing. Keeps the result of CopySpecsToDir()
|
2022-03-25 04:35:46 +01:00
|
|
|
entries []string
|
2020-11-12 05:14:30 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 13:18:31 +01:00
|
|
|
type symlinkDefinition struct {
|
|
|
|
Target *string
|
|
|
|
Name *string
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:11:03 +01:00
|
|
|
type filesystemProperties struct {
|
|
|
|
// When set to true, sign the image with avbtool. Default is false.
|
|
|
|
Use_avb *bool
|
|
|
|
|
|
|
|
// Path to the private key that avbtool will use to sign this filesystem image.
|
|
|
|
// TODO(jiyong): allow apex_key to be specified here
|
|
|
|
Avb_private_key *string `android:"path"`
|
|
|
|
|
2022-12-22 13:22:57 +01:00
|
|
|
// Signing algorithm for avbtool. Default is SHA256_RSA4096.
|
2021-01-18 13:11:03 +01:00
|
|
|
Avb_algorithm *string
|
2021-02-01 13:09:38 +01:00
|
|
|
|
2022-12-22 13:22:57 +01:00
|
|
|
// Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to
|
|
|
|
// avbtool. Default used by avbtool is sha1.
|
2022-12-21 13:54:45 +01:00
|
|
|
Avb_hash_algorithm *string
|
|
|
|
|
2024-03-27 23:19:30 +01:00
|
|
|
// The index used to prevent rollback of the image. Only used if use_avb is true.
|
|
|
|
Rollback_index *int64
|
|
|
|
|
2021-03-15 15:21:30 +01:00
|
|
|
// Name of the partition stored in vbmeta desc. Defaults to the name of this module.
|
|
|
|
Partition_name *string
|
|
|
|
|
2021-02-04 16:17:14 +01:00
|
|
|
// Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
|
|
|
|
// is ext4.
|
2021-02-01 13:09:38 +01:00
|
|
|
Type *string
|
2021-02-03 06:05:24 +01:00
|
|
|
|
2024-03-18 23:38:12 +01:00
|
|
|
// Identifies which partition this is for //visibility:any_system_image (and others) visibility
|
|
|
|
// checks, and will be used in the future for API surface checks.
|
|
|
|
Partition_type *string
|
|
|
|
|
2021-02-03 06:05:24 +01:00
|
|
|
// file_contexts file to make image. Currently, only ext4 is supported.
|
|
|
|
File_contexts *string `android:"path"`
|
2021-02-15 09:01:04 +01:00
|
|
|
|
|
|
|
// Base directory relative to root, to which deps are installed, e.g. "system". Default is "."
|
|
|
|
// (root).
|
|
|
|
Base_dir *string
|
2021-02-09 13:18:31 +01:00
|
|
|
|
|
|
|
// Directories to be created under root. e.g. /dev, /proc, etc.
|
|
|
|
Dirs []string
|
|
|
|
|
|
|
|
// Symbolic links to be created under root with "ln -sf <target> <name>".
|
|
|
|
Symlinks []symlinkDefinition
|
2022-04-21 07:24:04 +02:00
|
|
|
|
|
|
|
// Seconds since unix epoch to override timestamps of file entries
|
|
|
|
Fake_timestamp *string
|
|
|
|
|
|
|
|
// When set, passed to mkuserimg_mke2fs --mke2fs_uuid & --mke2fs_hash_seed.
|
|
|
|
// Otherwise, they'll be set as random which might cause indeterministic build output.
|
|
|
|
Uuid *string
|
2023-11-01 07:40:25 +01:00
|
|
|
|
|
|
|
// Mount point for this image. Default is "/"
|
|
|
|
Mount_point *string
|
2024-03-12 20:44:40 +01:00
|
|
|
|
|
|
|
// If set to the name of a partition ("system", "vendor", etc), this filesystem module
|
|
|
|
// will also include the contents of the make-built staging directories. If any soong
|
|
|
|
// modules would be installed to the same location as a make module, they will overwrite
|
|
|
|
// the make version.
|
|
|
|
Include_make_built_files string
|
2024-03-29 09:44:07 +01:00
|
|
|
|
|
|
|
Fsverity fsverityProperties
|
2021-01-18 13:11:03 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 06:23:26 +01:00
|
|
|
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
|
|
|
|
// image. The filesystem images are expected to be mounted in the target device, which means the
|
|
|
|
// modules in the filesystem image are built for the target device (i.e. Android, not Linux host).
|
|
|
|
// The modules are placed in the filesystem image just like they are installed to the ordinary
|
|
|
|
// partitions like system.img. For example, cc_library modules are placed under ./lib[64] directory.
|
2020-11-12 05:14:30 +01:00
|
|
|
func filesystemFactory() android.Module {
|
|
|
|
module := &filesystem{}
|
2021-04-20 04:36:40 +02:00
|
|
|
initFilesystemModule(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func initFilesystemModule(module *filesystem) {
|
2021-01-18 13:11:03 +01:00
|
|
|
module.AddProperties(&module.properties)
|
2020-11-12 05:14:30 +01:00
|
|
|
android.InitPackageModule(module)
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
2024-04-05 11:13:33 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2020-11-12 05:14:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 07:31:24 +01:00
|
|
|
var dependencyTag = struct {
|
|
|
|
blueprint.BaseDependencyTag
|
2021-03-10 07:40:34 +01:00
|
|
|
android.PackagingItemAlwaysDepTag
|
2021-01-07 07:31:24 +01:00
|
|
|
}{}
|
2020-11-25 04:44:59 +01:00
|
|
|
|
2020-11-12 05:14:30 +01:00
|
|
|
func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2020-11-25 04:44:59 +01:00
|
|
|
f.AddDeps(ctx, dependencyTag)
|
2020-11-12 05:14:30 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 13:09:38 +01:00
|
|
|
type fsType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ext4Type fsType = iota
|
|
|
|
compressedCpioType
|
2021-02-04 16:17:14 +01:00
|
|
|
cpioType // uncompressed
|
2021-02-01 13:09:38 +01:00
|
|
|
unknown
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
|
|
|
|
typeStr := proptools.StringDefault(f.properties.Type, "ext4")
|
|
|
|
switch typeStr {
|
|
|
|
case "ext4":
|
|
|
|
return ext4Type
|
|
|
|
case "compressed_cpio":
|
|
|
|
return compressedCpioType
|
2021-02-04 16:17:14 +01:00
|
|
|
case "cpio":
|
|
|
|
return cpioType
|
2021-02-01 13:09:38 +01:00
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("type", "%q not supported", typeStr)
|
|
|
|
return unknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 06:23:26 +01:00
|
|
|
func (f *filesystem) installFileName() string {
|
|
|
|
return f.BaseModuleName() + ".img"
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:44:07 +01:00
|
|
|
func (f *filesystem) partitionName() string {
|
|
|
|
return proptools.StringDefault(f.properties.Partition_name, f.Name())
|
|
|
|
}
|
|
|
|
|
2020-11-12 05:14:30 +01:00
|
|
|
var pctx = android.NewPackageContext("android/soong/filesystem")
|
|
|
|
|
|
|
|
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2024-04-05 11:13:33 +02:00
|
|
|
validatePartitionType(ctx, f)
|
2021-02-01 13:09:38 +01:00
|
|
|
switch f.fsType(ctx) {
|
|
|
|
case ext4Type:
|
|
|
|
f.output = f.buildImageUsingBuildImage(ctx)
|
|
|
|
case compressedCpioType:
|
2021-02-04 16:17:14 +01:00
|
|
|
f.output = f.buildCpioImage(ctx, true)
|
|
|
|
case cpioType:
|
|
|
|
f.output = f.buildCpioImage(ctx, false)
|
2021-02-01 13:09:38 +01:00
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f.installDir = android.PathForModuleInstall(ctx, "etc")
|
|
|
|
ctx.InstallFile(f.installDir, f.installFileName(), f.output)
|
|
|
|
}
|
|
|
|
|
2024-04-05 11:13:33 +02:00
|
|
|
func validatePartitionType(ctx android.ModuleContext, p partition) {
|
|
|
|
if !android.InList(p.PartitionType(), validPartitions) {
|
|
|
|
ctx.PropertyErrorf("partition_type", "partition_type must be one of %s, found: %s", validPartitions, p.PartitionType())
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.VisitDirectDepsWithTag(android.DefaultsDepTag, func(m android.Module) {
|
|
|
|
if fdm, ok := m.(*filesystemDefaults); ok {
|
|
|
|
if p.PartitionType() != fdm.PartitionType() {
|
|
|
|
ctx.PropertyErrorf("partition_type",
|
|
|
|
"%s doesn't match with the partition type %s of the filesystem default module %s",
|
|
|
|
p.PartitionType(), fdm.PartitionType(), m.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-11 23:15:03 +01:00
|
|
|
// Copy extra files/dirs that are not from the `deps` property to `rootDir`, checking for conflicts with files
|
|
|
|
// already in `rootDir`.
|
|
|
|
func (f *filesystem) buildNonDepsFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.OutputPath) {
|
2021-02-09 13:18:31 +01:00
|
|
|
// create dirs and symlinks
|
|
|
|
for _, dir := range f.properties.Dirs {
|
|
|
|
// OutputPath.Join verifies dir
|
|
|
|
builder.Command().Text("mkdir -p").Text(rootDir.Join(ctx, dir).String())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, symlink := range f.properties.Symlinks {
|
|
|
|
name := strings.TrimSpace(proptools.String(symlink.Name))
|
|
|
|
target := strings.TrimSpace(proptools.String(symlink.Target))
|
|
|
|
|
|
|
|
if name == "" {
|
|
|
|
ctx.PropertyErrorf("symlinks", "Name can't be empty")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if target == "" {
|
|
|
|
ctx.PropertyErrorf("symlinks", "Target can't be empty")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// OutputPath.Join verifies name. don't need to verify target.
|
|
|
|
dst := rootDir.Join(ctx, name)
|
2024-03-11 23:15:03 +01:00
|
|
|
builder.Command().Textf("(! [ -e %s -o -L %s ] || (echo \"%s already exists from an earlier stage of the build\" && exit 1))", dst, dst, dst)
|
2021-02-09 13:18:31 +01:00
|
|
|
builder.Command().Text("mkdir -p").Text(filepath.Dir(dst.String()))
|
|
|
|
builder.Command().Text("ln -sf").Text(proptools.ShellEscape(target)).Text(dst.String())
|
|
|
|
}
|
2021-02-15 09:01:04 +01:00
|
|
|
|
2021-04-20 04:36:40 +02:00
|
|
|
// create extra files if there's any
|
|
|
|
if f.buildExtraFiles != nil {
|
2024-03-12 20:44:40 +01:00
|
|
|
rootForExtraFiles := android.PathForModuleGen(ctx, "root-extra").OutputPath
|
|
|
|
extraFiles := f.buildExtraFiles(ctx, rootForExtraFiles)
|
|
|
|
for _, f := range extraFiles {
|
|
|
|
rel, err := filepath.Rel(rootForExtraFiles.String(), f.String())
|
|
|
|
if err != nil || strings.HasPrefix(rel, "..") {
|
|
|
|
ctx.ModuleErrorf("can't make %q relative to %q", f, rootForExtraFiles)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(extraFiles) > 0 {
|
|
|
|
builder.Command().BuiltTool("merge_directories").
|
|
|
|
Implicits(extraFiles.Paths()).
|
|
|
|
Text(rootDir.String()).
|
|
|
|
Text(rootForExtraFiles.String())
|
2021-04-20 04:36:40 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-15 09:01:04 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 13:09:38 +01:00
|
|
|
func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
|
2024-03-11 23:15:03 +01:00
|
|
|
rootDir := android.PathForModuleOut(ctx, "root").OutputPath
|
|
|
|
rebasedDir := rootDir
|
|
|
|
if f.properties.Base_dir != nil {
|
|
|
|
rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
|
|
|
|
}
|
2020-11-17 02:32:30 +01:00
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
2024-03-11 23:15:03 +01:00
|
|
|
// Wipe the root dir to get rid of leftover files from prior builds
|
|
|
|
builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
|
2024-03-29 09:44:07 +01:00
|
|
|
specs := f.gatherFilteredPackagingSpecs(ctx)
|
|
|
|
f.entries = f.CopySpecsToDir(ctx, builder, specs, rebasedDir)
|
2021-02-15 09:01:04 +01:00
|
|
|
|
2024-03-11 23:15:03 +01:00
|
|
|
f.buildNonDepsFiles(ctx, builder, rootDir)
|
2024-03-12 20:44:40 +01:00
|
|
|
f.addMakeBuiltFiles(ctx, builder, rootDir)
|
2024-03-29 09:44:07 +01:00
|
|
|
f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
|
2020-11-12 05:14:30 +01:00
|
|
|
|
2022-12-23 16:36:29 +01:00
|
|
|
// run host_init_verifier
|
|
|
|
// Ideally we should have a concept of pluggable linters that verify the generated image.
|
|
|
|
// While such concept is not implement this will do.
|
|
|
|
// TODO(b/263574231): substitute with pluggable linter.
|
|
|
|
builder.Command().
|
|
|
|
BuiltTool("host_init_verifier").
|
|
|
|
FlagWithArg("--out_system=", rootDir.String()+"/system")
|
|
|
|
|
2021-01-18 09:29:49 +01:00
|
|
|
propFile, toolDeps := f.buildPropFile(ctx)
|
2021-02-01 13:09:38 +01:00
|
|
|
output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
|
2020-11-17 02:32:30 +01:00
|
|
|
builder.Command().BuiltTool("build_image").
|
2020-11-12 05:14:30 +01:00
|
|
|
Text(rootDir.String()). // input directory
|
|
|
|
Input(propFile).
|
2021-01-18 09:29:49 +01:00
|
|
|
Implicits(toolDeps).
|
2021-02-01 13:09:38 +01:00
|
|
|
Output(output).
|
2020-11-12 05:14:30 +01:00
|
|
|
Text(rootDir.String()) // directory where to find fs_config_files|dirs
|
|
|
|
|
|
|
|
// rootDir is not deleted. Might be useful for quick inspection.
|
2020-11-17 02:32:30 +01:00
|
|
|
builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
|
2020-11-24 06:23:26 +01:00
|
|
|
|
2021-02-01 13:09:38 +01:00
|
|
|
return output
|
2020-11-24 06:23:26 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 06:05:24 +01:00
|
|
|
func (f *filesystem) buildFileContexts(ctx android.ModuleContext) android.OutputPath {
|
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
fcBin := android.PathForModuleOut(ctx, "file_contexts.bin")
|
|
|
|
builder.Command().BuiltTool("sefcontext_compile").
|
|
|
|
FlagWithOutput("-o ", fcBin).
|
|
|
|
Input(android.PathForModuleSrc(ctx, proptools.String(f.properties.File_contexts)))
|
|
|
|
builder.Build("build_filesystem_file_contexts", fmt.Sprintf("Creating filesystem file contexts for %s", f.BaseModuleName()))
|
|
|
|
return fcBin.OutputPath
|
|
|
|
}
|
|
|
|
|
2022-04-21 07:24:04 +02:00
|
|
|
// Calculates avb_salt from entry list (sorted) for deterministic output.
|
|
|
|
func (f *filesystem) salt() string {
|
|
|
|
return sha1sum(f.entries)
|
|
|
|
}
|
|
|
|
|
2021-01-18 09:29:49 +01:00
|
|
|
func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
|
|
|
|
var deps android.Paths
|
2024-03-08 00:51:12 +01:00
|
|
|
var propFileString strings.Builder
|
2021-01-18 09:29:49 +01:00
|
|
|
addStr := func(name string, value string) {
|
2024-03-08 00:51:12 +01:00
|
|
|
propFileString.WriteString(name)
|
|
|
|
propFileString.WriteRune('=')
|
|
|
|
propFileString.WriteString(value)
|
|
|
|
propFileString.WriteRune('\n')
|
2021-01-18 09:29:49 +01:00
|
|
|
}
|
|
|
|
addPath := func(name string, path android.Path) {
|
2024-03-08 00:51:12 +01:00
|
|
|
addStr(name, path.String())
|
2021-01-18 09:29:49 +01:00
|
|
|
deps = append(deps, path)
|
|
|
|
}
|
|
|
|
|
2021-02-01 13:09:38 +01:00
|
|
|
// Type string that build_image.py accepts.
|
|
|
|
fsTypeStr := func(t fsType) string {
|
|
|
|
switch t {
|
|
|
|
// TODO(jiyong): add more types like f2fs, erofs, etc.
|
|
|
|
case ext4Type:
|
|
|
|
return "ext4"
|
|
|
|
}
|
|
|
|
panic(fmt.Errorf("unsupported fs type %v", t))
|
|
|
|
}
|
|
|
|
|
|
|
|
addStr("fs_type", fsTypeStr(f.fsType(ctx)))
|
2023-11-01 07:40:25 +01:00
|
|
|
addStr("mount_point", proptools.StringDefault(f.properties.Mount_point, "/"))
|
2021-01-18 09:29:49 +01:00
|
|
|
addStr("use_dynamic_partition_size", "true")
|
|
|
|
addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
|
|
|
|
// b/177813163 deps of the host tools have to be added. Remove this.
|
|
|
|
for _, t := range []string{"mke2fs", "e2fsdroid", "tune2fs"} {
|
|
|
|
deps = append(deps, ctx.Config().HostToolPath(ctx, t))
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:11:03 +01:00
|
|
|
if proptools.Bool(f.properties.Use_avb) {
|
|
|
|
addStr("avb_hashtree_enable", "true")
|
|
|
|
addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
|
|
|
|
algorithm := proptools.StringDefault(f.properties.Avb_algorithm, "SHA256_RSA4096")
|
|
|
|
addStr("avb_algorithm", algorithm)
|
|
|
|
key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
|
|
|
|
addPath("avb_key_path", key)
|
2024-03-29 09:44:07 +01:00
|
|
|
addStr("partition_name", f.partitionName())
|
2022-12-21 13:54:45 +01:00
|
|
|
avb_add_hashtree_footer_args := "--do_not_generate_fec"
|
|
|
|
if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" {
|
|
|
|
avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm
|
|
|
|
}
|
2024-03-27 23:19:30 +01:00
|
|
|
if f.properties.Rollback_index != nil {
|
|
|
|
rollbackIndex := proptools.Int(f.properties.Rollback_index)
|
|
|
|
if rollbackIndex < 0 {
|
|
|
|
ctx.PropertyErrorf("rollback_index", "Rollback index must be non-negative")
|
|
|
|
}
|
|
|
|
avb_add_hashtree_footer_args += " --rollback_index " + strconv.Itoa(rollbackIndex)
|
|
|
|
}
|
2024-03-29 09:44:07 +01:00
|
|
|
securityPatchKey := "com.android.build." + f.partitionName() + ".security_patch"
|
2023-11-09 06:55:44 +01:00
|
|
|
securityPatchValue := ctx.Config().PlatformSecurityPatch()
|
|
|
|
avb_add_hashtree_footer_args += " --prop " + securityPatchKey + ":" + securityPatchValue
|
2022-12-21 13:54:45 +01:00
|
|
|
addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args)
|
2022-04-21 07:24:04 +02:00
|
|
|
addStr("avb_salt", f.salt())
|
2021-01-18 13:11:03 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 06:05:24 +01:00
|
|
|
if proptools.String(f.properties.File_contexts) != "" {
|
|
|
|
addPath("selinux_fc", f.buildFileContexts(ctx))
|
|
|
|
}
|
2022-04-21 07:24:04 +02:00
|
|
|
if timestamp := proptools.String(f.properties.Fake_timestamp); timestamp != "" {
|
|
|
|
addStr("timestamp", timestamp)
|
|
|
|
}
|
|
|
|
if uuid := proptools.String(f.properties.Uuid); uuid != "" {
|
|
|
|
addStr("uuid", uuid)
|
|
|
|
addStr("hash_seed", uuid)
|
|
|
|
}
|
2021-01-18 09:29:49 +01:00
|
|
|
propFile = android.PathForModuleOut(ctx, "prop").OutputPath
|
2024-03-08 00:51:12 +01:00
|
|
|
android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
|
2021-01-18 09:29:49 +01:00
|
|
|
return propFile, deps
|
|
|
|
}
|
|
|
|
|
2021-02-04 16:17:14 +01:00
|
|
|
func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) android.OutputPath {
|
2021-02-01 13:09:38 +01:00
|
|
|
if proptools.Bool(f.properties.Use_avb) {
|
|
|
|
ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
|
|
|
|
"Consider adding this to bootimg module and signing the entire boot image.")
|
|
|
|
}
|
|
|
|
|
2021-02-03 06:05:24 +01:00
|
|
|
if proptools.String(f.properties.File_contexts) != "" {
|
|
|
|
ctx.PropertyErrorf("file_contexts", "file_contexts is not supported for compressed cpio image.")
|
|
|
|
}
|
|
|
|
|
2024-03-12 20:44:40 +01:00
|
|
|
if f.properties.Include_make_built_files != "" {
|
|
|
|
ctx.PropertyErrorf("include_make_built_files", "include_make_built_files is not supported for compressed cpio image.")
|
|
|
|
}
|
|
|
|
|
2024-03-11 23:15:03 +01:00
|
|
|
rootDir := android.PathForModuleOut(ctx, "root").OutputPath
|
|
|
|
rebasedDir := rootDir
|
|
|
|
if f.properties.Base_dir != nil {
|
|
|
|
rebasedDir = rootDir.Join(ctx, *f.properties.Base_dir)
|
|
|
|
}
|
2021-02-01 13:09:38 +01:00
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
2024-03-11 23:15:03 +01:00
|
|
|
// Wipe the root dir to get rid of leftover files from prior builds
|
|
|
|
builder.Command().Textf("rm -rf %s && mkdir -p %s", rootDir, rootDir)
|
2024-03-29 09:44:07 +01:00
|
|
|
specs := f.gatherFilteredPackagingSpecs(ctx)
|
|
|
|
f.entries = f.CopySpecsToDir(ctx, builder, specs, rebasedDir)
|
2021-02-15 09:01:04 +01:00
|
|
|
|
2024-03-11 23:15:03 +01:00
|
|
|
f.buildNonDepsFiles(ctx, builder, rootDir)
|
2024-03-29 09:44:07 +01:00
|
|
|
f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir)
|
2021-02-01 13:09:38 +01:00
|
|
|
|
|
|
|
output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
|
2021-02-04 16:17:14 +01:00
|
|
|
cmd := builder.Command().
|
2021-02-01 13:09:38 +01:00
|
|
|
BuiltTool("mkbootfs").
|
2021-02-04 16:17:14 +01:00
|
|
|
Text(rootDir.String()) // input directory
|
|
|
|
if compressed {
|
|
|
|
cmd.Text("|").
|
|
|
|
BuiltTool("lz4").
|
|
|
|
Flag("--favor-decSpeed"). // for faster boot
|
|
|
|
Flag("-12"). // maximum compression level
|
|
|
|
Flag("-l"). // legacy format for kernel
|
|
|
|
Text(">").Output(output)
|
|
|
|
} else {
|
|
|
|
cmd.Text(">").Output(output)
|
|
|
|
}
|
2021-02-01 13:09:38 +01:00
|
|
|
|
|
|
|
// rootDir is not deleted. Might be useful for quick inspection.
|
2021-02-04 16:17:14 +01:00
|
|
|
builder.Build("build_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
|
2021-02-01 13:09:38 +01:00
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2024-03-12 20:44:40 +01:00
|
|
|
var validPartitions = []string{
|
|
|
|
"system",
|
|
|
|
"userdata",
|
|
|
|
"cache",
|
|
|
|
"system_other",
|
|
|
|
"vendor",
|
|
|
|
"product",
|
|
|
|
"system_ext",
|
|
|
|
"odm",
|
|
|
|
"vendor_dlkm",
|
|
|
|
"odm_dlkm",
|
|
|
|
"system_dlkm",
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *filesystem) addMakeBuiltFiles(ctx android.ModuleContext, builder *android.RuleBuilder, rootDir android.Path) {
|
|
|
|
partition := f.properties.Include_make_built_files
|
|
|
|
if partition == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !slices.Contains(validPartitions, partition) {
|
|
|
|
ctx.PropertyErrorf("include_make_built_files", "Expected one of %#v, found %q", validPartitions, partition)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
stampFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/staging_dir.stamp", ctx.Config().DeviceName(), partition)
|
|
|
|
fileListFile := fmt.Sprintf("target/product/%s/obj/PACKAGING/%s_intermediates/file_list.txt", ctx.Config().DeviceName(), partition)
|
|
|
|
stagingDir := fmt.Sprintf("target/product/%s/%s", ctx.Config().DeviceName(), partition)
|
|
|
|
|
|
|
|
builder.Command().BuiltTool("merge_directories").
|
|
|
|
Implicit(android.PathForArbitraryOutput(ctx, stampFile)).
|
|
|
|
Text("--ignore-duplicates").
|
|
|
|
FlagWithInput("--file-list", android.PathForArbitraryOutput(ctx, fileListFile)).
|
|
|
|
Text(rootDir.String()).
|
|
|
|
Text(android.PathForArbitraryOutput(ctx, stagingDir).String())
|
|
|
|
}
|
|
|
|
|
2024-04-05 11:13:33 +02:00
|
|
|
type partition interface {
|
|
|
|
PartitionType() string
|
|
|
|
}
|
|
|
|
|
2024-03-18 23:38:12 +01:00
|
|
|
func (f *filesystem) PartitionType() string {
|
|
|
|
return proptools.StringDefault(f.properties.Partition_type, "system")
|
|
|
|
}
|
|
|
|
|
2024-04-05 11:13:33 +02:00
|
|
|
var _ partition = (*filesystem)(nil)
|
|
|
|
|
2020-11-24 06:23:26 +01:00
|
|
|
var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
|
|
|
|
|
|
|
|
// Implements android.AndroidMkEntriesProvider
|
|
|
|
func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
|
|
|
Class: "ETC",
|
|
|
|
OutputFile: android.OptionalPathForPath(f.output),
|
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-03 22:18:24 +02:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2021-11-12 03:59:15 +01:00
|
|
|
entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())
|
2020-11-24 06:23:26 +01:00
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
2020-11-12 05:14:30 +01:00
|
|
|
}
|
2021-01-07 07:31:24 +01:00
|
|
|
|
2021-02-04 07:37:34 +01:00
|
|
|
var _ android.OutputFileProducer = (*filesystem)(nil)
|
|
|
|
|
|
|
|
// Implements android.OutputFileProducer
|
|
|
|
func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
if tag == "" {
|
|
|
|
return []android.Path{f.output}, nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
|
2021-01-07 07:31:24 +01:00
|
|
|
// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
|
|
|
|
// package to have access to the output file.
|
|
|
|
type Filesystem interface {
|
|
|
|
android.Module
|
|
|
|
OutputPath() android.Path
|
2021-03-15 15:32:49 +01:00
|
|
|
|
|
|
|
// Returns the output file that is signed by avbtool. If this module is not signed, returns
|
|
|
|
// nil.
|
|
|
|
SignedOutputPath() android.Path
|
2021-01-07 07:31:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ Filesystem = (*filesystem)(nil)
|
|
|
|
|
|
|
|
func (f *filesystem) OutputPath() android.Path {
|
|
|
|
return f.output
|
|
|
|
}
|
2021-03-15 15:32:49 +01:00
|
|
|
|
|
|
|
func (f *filesystem) SignedOutputPath() android.Path {
|
|
|
|
if proptools.Bool(f.properties.Use_avb) {
|
|
|
|
return f.OutputPath()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-25 04:35:46 +01:00
|
|
|
|
|
|
|
// Filter the result of GatherPackagingSpecs to discard items targeting outside "system" partition.
|
|
|
|
// Note that "apex" module installs its contents to "apex"(fake partition) as well
|
|
|
|
// for symbol lookup by imitating "activated" paths.
|
|
|
|
func (f *filesystem) gatherFilteredPackagingSpecs(ctx android.ModuleContext) map[string]android.PackagingSpec {
|
2024-02-08 02:44:37 +01:00
|
|
|
specs := f.PackagingBase.GatherPackagingSpecsWithFilter(ctx, f.filterPackagingSpec)
|
2022-03-25 04:35:46 +01:00
|
|
|
return specs
|
|
|
|
}
|
2022-04-21 07:24:04 +02:00
|
|
|
|
|
|
|
func sha1sum(values []string) string {
|
|
|
|
h := sha256.New()
|
|
|
|
for _, value := range values {
|
|
|
|
io.WriteString(h, value)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%x", h.Sum(nil))
|
|
|
|
}
|
2023-03-16 05:11:17 +01:00
|
|
|
|
|
|
|
// Base cc.UseCoverage
|
|
|
|
|
|
|
|
var _ cc.UseCoverage = (*filesystem)(nil)
|
|
|
|
|
2024-01-20 00:41:48 +01:00
|
|
|
func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool {
|
2023-03-16 05:11:17 +01:00
|
|
|
return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
|
|
|
|
}
|
2024-04-05 11:13:33 +02:00
|
|
|
|
|
|
|
// android_filesystem_defaults
|
|
|
|
|
|
|
|
type filesystemDefaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
|
|
|
|
properties filesystemDefaultsProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
type filesystemDefaultsProperties struct {
|
|
|
|
// Identifies which partition this is for //visibility:any_system_image (and others) visibility
|
|
|
|
// checks, and will be used in the future for API surface checks.
|
|
|
|
Partition_type *string
|
|
|
|
}
|
|
|
|
|
|
|
|
// android_filesystem_defaults is a default module for android_filesystem and android_system_image
|
|
|
|
func filesystemDefaultsFactory() android.Module {
|
|
|
|
module := &filesystemDefaults{}
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
module.AddProperties(&android.PackagingProperties{})
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *filesystemDefaults) PartitionType() string {
|
|
|
|
return proptools.StringDefault(f.properties.Partition_type, "system")
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ partition = (*filesystemDefaults)(nil)
|
|
|
|
|
|
|
|
func (f *filesystemDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
validatePartitionType(ctx, f)
|
|
|
|
}
|