2020-11-12 12:14:30 +08: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 (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-11-25 11:44:59 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2020-11-12 12:14:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterModuleType("android_filesystem", filesystemFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
type filesystem struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.PackagingBase
|
2020-11-24 13:23:26 +08:00
|
|
|
|
|
|
|
output android.OutputPath
|
|
|
|
installDir android.InstallPath
|
2020-11-12 12:14:30 +08:00
|
|
|
}
|
|
|
|
|
2020-11-24 13:23:26 +08: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 12:14:30 +08:00
|
|
|
func filesystemFactory() android.Module {
|
|
|
|
module := &filesystem{}
|
|
|
|
android.InitPackageModule(module)
|
|
|
|
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2020-11-25 11:44:59 +08:00
|
|
|
var dependencyTag = struct{ blueprint.BaseDependencyTag }{}
|
|
|
|
|
2020-11-12 12:14:30 +08:00
|
|
|
func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2020-11-25 11:44:59 +08:00
|
|
|
f.AddDeps(ctx, dependencyTag)
|
2020-11-12 12:14:30 +08:00
|
|
|
}
|
|
|
|
|
2020-11-24 13:23:26 +08:00
|
|
|
func (f *filesystem) installFileName() string {
|
|
|
|
return f.BaseModuleName() + ".img"
|
|
|
|
}
|
|
|
|
|
2020-11-12 12:14:30 +08:00
|
|
|
var pctx = android.NewPackageContext("android/soong/filesystem")
|
|
|
|
|
|
|
|
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
|
|
|
|
f.CopyDepsToZip(ctx, zipFile)
|
|
|
|
|
|
|
|
rootDir := android.PathForModuleOut(ctx, "root").OutputPath
|
2020-11-17 09:32:30 +08:00
|
|
|
builder := android.NewRuleBuilder(pctx, ctx)
|
2020-11-12 12:14:30 +08:00
|
|
|
builder.Command().
|
2020-11-17 09:32:30 +08:00
|
|
|
BuiltTool("zipsync").
|
2020-11-12 12:14:30 +08:00
|
|
|
FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
|
|
|
|
Input(zipFile)
|
|
|
|
|
|
|
|
mkuserimg := ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs")
|
|
|
|
propFile := android.PathForModuleOut(ctx, "prop").OutputPath
|
|
|
|
// TODO(jiyong): support more filesystem types other than ext4
|
|
|
|
propsText := fmt.Sprintf(`mount_point=system\n`+
|
|
|
|
`fs_type=ext4\n`+
|
|
|
|
`use_dynamic_partition_size=true\n`+
|
|
|
|
`ext_mkuserimg=%s\n`, mkuserimg.String())
|
|
|
|
builder.Command().Text("echo").Flag("-e").Flag(`"` + propsText + `"`).
|
|
|
|
Text(">").Output(propFile).
|
|
|
|
Implicit(mkuserimg)
|
|
|
|
|
2020-11-24 13:23:26 +08:00
|
|
|
f.output = android.PathForModuleOut(ctx, "filesystem.img").OutputPath
|
2020-11-17 09:32:30 +08:00
|
|
|
builder.Command().BuiltTool("build_image").
|
2020-11-12 12:14:30 +08:00
|
|
|
Text(rootDir.String()). // input directory
|
|
|
|
Input(propFile).
|
2020-11-24 13:23:26 +08:00
|
|
|
Output(f.output).
|
2020-11-12 12:14:30 +08: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 09:32:30 +08:00
|
|
|
builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
|
2020-11-24 13:23:26 +08:00
|
|
|
|
|
|
|
f.installDir = android.PathForModuleInstall(ctx, "etc")
|
|
|
|
ctx.InstallFile(f.installDir, f.installFileName(), f.output)
|
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
|
|
|
func(entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetString("LOCAL_MODULE_PATH", f.installDir.ToMakePath().String())
|
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
2020-11-12 12:14:30 +08:00
|
|
|
}
|