Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [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 | "android/soong/android" |
| 19 | "android/soong/filesystem" |
| 20 | "fmt" |
| 21 | "strconv" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
| 26 | func init() { |
| 27 | registerBuildComponents(android.InitRegistrationContext) |
| 28 | } |
| 29 | |
| 30 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 31 | ctx.RegisterModuleType("soong_filesystem_creator", filesystemCreatorFactory) |
| 32 | } |
| 33 | |
| 34 | type filesystemCreator struct { |
| 35 | android.ModuleBase |
| 36 | } |
| 37 | |
| 38 | func 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 | |
| 49 | func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) { |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 50 | f.createSystemImage(ctx) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 51 | } |
| 52 | |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 53 | func (f *filesystemCreator) createSystemImage(ctx android.LoadHookContext) { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 54 | baseProps := &struct { |
| 55 | Name *string |
| 56 | }{ |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 57 | Name: proptools.StringPtr(fmt.Sprintf("%s_generated_system_image", ctx.Config().DeviceProduct())), |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | fsProps := &(filesystem.FilesystemProperties{}) |
| 61 | partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 62 | systemPartitionVars := partitionVars.PartitionQualifiedVariables["system"] |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 63 | |
| 64 | // BOARD_AVB_ENABLE |
| 65 | fsProps.Use_avb = proptools.BoolPtr(partitionVars.BoardAvbEnable) |
| 66 | // BOARD_AVB_KEY_PATH |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 67 | fsProps.Avb_private_key = proptools.StringPtr(systemPartitionVars.BoardAvbKeyPath) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 68 | // BOARD_AVB_ALGORITHM |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 69 | fsProps.Avb_algorithm = proptools.StringPtr(systemPartitionVars.BoardAvbAlgorithm) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 70 | // BOARD_AVB_SYSTEM_ROLLBACK_INDEX |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 71 | if rollbackIndex, err := strconv.ParseInt(systemPartitionVars.BoardAvbRollbackIndex, 10, 64); err == nil { |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 72 | fsProps.Rollback_index = proptools.Int64Ptr(rollbackIndex) |
| 73 | } |
| 74 | |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 75 | fsProps.Partition_name = proptools.StringPtr("system") |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 76 | // BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 77 | fsProps.Type = proptools.StringPtr(systemPartitionVars.BoardFileSystemType) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 78 | |
PODISHETTY KUMAR (xWF) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 79 | fsProps.Base_dir = proptools.StringPtr("system") |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 80 | |
| 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) | 7f9bcd0 | 2024-10-04 07:39:10 +0000 | [diff] [blame^] | 106 | ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | func (f *filesystemCreator) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 110 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 111 | } |