blob: ca948f406edfadee0ce613ee6fcc1306b0dd1616 [file] [log] [blame]
Jihoon Kang98047cf2024-10-02 17:13:54 +00001// 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
15package fsgen
16
17import (
18 "android/soong/android"
19 "android/soong/filesystem"
20 "fmt"
21 "strconv"
22
23 "github.com/google/blueprint/proptools"
24)
25
26func init() {
27 registerBuildComponents(android.InitRegistrationContext)
28}
29
30func registerBuildComponents(ctx android.RegistrationContext) {
31 ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory)
32}
33
34type filesystemCreator struct {
35 android.ModuleBase
36}
37
38func filesystemCreatorFactory() android.Module {
39 module := &filesystemCreator{}
40
41 android.InitAndroidModule(module)
42 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
43 module.createInternalModules(ctx)
44 })
45
46 return module
47}
48
49func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000050 f.createSystemImage(ctx)
Jihoon Kang98047cf2024-10-02 17:13:54 +000051}
52
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000053func (f *filesystemCreator) createSystemImage(ctx android.LoadHookContext) {
Jihoon Kang98047cf2024-10-02 17:13:54 +000054 baseProps := &struct {
55 Name *string
56 }{
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000057 Name: proptools.StringPtr(fmt.Sprintf("%s_generated_system_image", ctx.Config().DeviceProduct())),
Jihoon Kang98047cf2024-10-02 17:13:54 +000058 }
59
60 fsProps := &(filesystem.FilesystemProperties{})
61 partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000062 systemPartitionVars := partitionVars.PartitionQualifiedVariables["system"]
Jihoon Kang98047cf2024-10-02 17:13:54 +000063
64 // BOARD_AVB_ENABLE
65 fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable)
66 // BOARD_AVB_KEY_PATH
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000067 fsProps.Avb_private_key = proptools.StringPtr(systemPartitionVars.BoardAvbKeyPath)
Jihoon Kang98047cf2024-10-02 17:13:54 +000068 // BOARD_AVB_ALGORITHM
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000069 fsProps.Avb_algorithm = proptools.StringPtr(systemPartitionVars.BoardAvbAlgorithm)
Jihoon Kang98047cf2024-10-02 17:13:54 +000070 // BOARD_AVB_SYSTEM_ROLLBACK_INDEX
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000071 if rollbackIndex, err := strconv.ParseInt(systemPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil {
Jihoon Kang98047cf2024-10-02 17:13:54 +000072 fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex)
73 }
74
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000075 fsProps.Partition_name = proptools.StringPtr("system")
Jihoon Kang98047cf2024-10-02 17:13:54 +000076 // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000077 fsProps.Type = proptools.StringPtr(systemPartitionVars.BoardFileSystemType)
Jihoon Kang98047cf2024-10-02 17:13:54 +000078
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +000079 fsProps.Base_dir = proptools.StringPtr("system")
Jihoon Kang98047cf2024-10-02 17:13:54 +000080
81 fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
82
83 // Identical to that of the generic_system_image
84 fsProps.Fsverity.Inputs = []string{
85 "etc/boot-image.prof",
86 "etc/dirty-image-objects",
87 "etc/preloaded-classes",
88 "etc/classpaths/*.pb",
89 "framework/*",
90 "framework/*/*", // framework/{arch}
91 "framework/oat/*/*", // framework/oat/{arch}
92 }
93
94 // system_image properties that are not set:
95 // - filesystemProperties.Avb_hash_algorithm
96 // - filesystemProperties.File_contexts
97 // - filesystemProperties.Dirs
98 // - filesystemProperties.Symlinks
99 // - filesystemProperties.Fake_timestamp
100 // - filesystemProperties.Uuid
101 // - filesystemProperties.Mount_point
102 // - filesystemProperties.Include_make_built_files
103 // - filesystemProperties.Build_logtags
104 // - filesystemProperties.Fsverity.Libs
105 // - systemImageProperties.Linker_config_src
PODISHETTY KUMAR (xWF)7f9bcd02024-10-04 07:39:10 +0000106 ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
Jihoon Kang98047cf2024-10-02 17:13:54 +0000107}
108
109func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
110
Jihoon Kang98047cf2024-10-02 17:13:54 +0000111}