Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 1 | // Copyright (C) 2021 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 ( |
| 18 | "android/soong/android" |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 19 | "android/soong/cc" |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 20 | "android/soong/linkerconfig" |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 21 | |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 22 | "strings" |
| 23 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | type systemImage struct { |
| 28 | filesystem |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 29 | } |
| 30 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 31 | var _ filesystemBuilder = (*systemImage)(nil) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 32 | |
| 33 | // android_system_image is a specialization of android_filesystem for the 'system' partition. |
| 34 | // Currently, the only difference is the inclusion of linker.config.pb file which specifies |
| 35 | // the provided and the required libraries to and from APEXes. |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 36 | func SystemImageFactory() android.Module { |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 37 | module := &systemImage{} |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 38 | module.filesystemBuilder = module |
Cole Faust | 2cfe696 | 2024-09-17 11:31:14 -0700 | [diff] [blame] | 39 | initFilesystemModule(module, &module.filesystem) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 40 | return module |
| 41 | } |
| 42 | |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 43 | func (s systemImage) FsProps() FilesystemProperties { |
| 44 | return s.filesystem.properties |
| 45 | } |
| 46 | |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 47 | func (s *systemImage) BuildLinkerConfigFile( |
| 48 | ctx android.ModuleContext, |
| 49 | builder *android.RuleBuilder, |
| 50 | rebasedDir android.OutputPath, |
| 51 | fullInstallPaths *[]FullInstallPathInfo, |
| 52 | ) { |
Spandan Das | 2047a4c | 2024-11-11 21:24:58 +0000 | [diff] [blame] | 53 | if !proptools.Bool(s.filesystem.properties.Linker_config.Gen_linker_config) { |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 54 | return |
Cole Faust | 9a24d90 | 2024-03-18 15:38:12 -0700 | [diff] [blame] | 55 | } |
Jooyung Han | df09d17 | 2021-05-11 11:13:30 +0900 | [diff] [blame] | 56 | |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 57 | output := rebasedDir.Join(ctx, "etc", "linker.config.pb") |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 58 | if s.filesystem.properties.Linker_config.Linker_config_srcs != nil { |
| 59 | provideModules, requireModules := s.getLibsForLinkerConfig(ctx) |
| 60 | intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb") |
| 61 | linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, s.filesystem.properties.Linker_config.Linker_config_srcs), provideModules, requireModules, intermediateOutput) |
| 62 | builder.Command().Text("cp").Input(intermediateOutput).Output(output) |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 63 | |
| 64 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 65 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, s.PartitionType(), "etc", "linker.config.pb"), |
| 66 | SourcePath: intermediateOutput, |
| 67 | }) |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 68 | } else { |
| 69 | // TODO: This branch is the logic that make uses for the linker config file, which is |
| 70 | // different than linkerconfig.BuildLinkerConfig used above. Keeping both branches for now |
| 71 | // because microdroid uses the other method and is in theory happy with it. But we should |
| 72 | // consider deduping them. |
| 73 | stubLibraries := cc.StubLibrariesFile(ctx) |
| 74 | llndkMovedToApexLibraries := cc.MovedToApexLlndkLibrariesFile(ctx) |
| 75 | outputStep1 := android.PathForModuleOut(ctx, "linker.config.pb.step1") |
| 76 | builder.Command(). |
| 77 | BuiltTool("conv_linker_config"). |
| 78 | Text("proto --force"). |
| 79 | FlagWithInput("-s ", android.PathForSource(ctx, "system/core/rootdir/etc/linker.config.json")). |
| 80 | FlagWithOutput("-o ", outputStep1) |
| 81 | builder.Temporary(outputStep1) |
| 82 | builder.Command(). |
| 83 | BuiltTool("conv_linker_config"). |
| 84 | Text("systemprovide"). |
| 85 | FlagWithInput("--source ", outputStep1). |
| 86 | FlagWithArg("--output ", output.String()). |
| 87 | Textf(`--value "$(cat %s)"`, stubLibraries). |
| 88 | Implicit(stubLibraries). |
| 89 | FlagWithArg("--system ", rebasedDir.String()) |
| 90 | builder.Command(). |
| 91 | BuiltTool("conv_linker_config"). |
| 92 | Text("append"). |
| 93 | FlagWithArg("--source ", output.String()). |
| 94 | FlagWithOutput("--output ", output). |
| 95 | FlagWithArg("--key ", "requireLibs"). |
| 96 | Textf(`--value "$(cat %s)"`, llndkMovedToApexLibraries). |
| 97 | Implicit(llndkMovedToApexLibraries) |
| 98 | // TODO: Make also supports adding an extra append command with PRODUCT_EXTRA_STUB_LIBRARIES, |
| 99 | // but that variable appears to have no usages. |
Cole Faust | 19fbb07 | 2025-01-30 18:19:29 -0800 | [diff] [blame] | 100 | |
| 101 | *fullInstallPaths = append(*fullInstallPaths, FullInstallPathInfo{ |
| 102 | FullInstallPath: android.PathForModuleInPartitionInstall(ctx, s.PartitionType(), "etc", "linker.config.pb"), |
| 103 | SourcePath: output, |
| 104 | }) |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 105 | } |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 106 | |
| 107 | s.appendToEntry(ctx, output) |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 108 | } |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 109 | |
Inseob Kim | 33f95a9 | 2024-07-11 15:44:49 +0900 | [diff] [blame] | 110 | // Filter the result of GatherPackagingSpecs to discard items targeting outside "system" / "root" |
| 111 | // partition. Note that "apex" module installs its contents to "apex"(fake partition) as well |
Jooyung Han | 0fbbc2b | 2022-03-25 12:35:46 +0900 | [diff] [blame] | 112 | // for symbol lookup by imitating "activated" paths. |
Kiyoung Kim | 6711821 | 2024-11-07 13:23:44 +0900 | [diff] [blame] | 113 | func (s *systemImage) FilterPackagingSpec(ps android.PackagingSpec) bool { |
Hugo Drumond Jacob | 69d829a | 2024-10-21 09:55:45 +0000 | [diff] [blame] | 114 | return !ps.SkipInstall() && |
Inseob Kim | 3c0a042 | 2024-11-05 17:21:37 +0900 | [diff] [blame] | 115 | (ps.Partition() == "system" || ps.Partition() == "root" || |
| 116 | strings.HasPrefix(ps.Partition(), "system/")) |
| 117 | } |
Kiyoung Kim | 23be5bb | 2024-11-27 00:50:30 +0000 | [diff] [blame] | 118 | |
| 119 | func (s *systemImage) ShouldUseVintfFragmentModuleOnly() bool { |
| 120 | return true |
| 121 | } |