blob: b125824b1bf3e3a6d1a80f064589f016582ee4b0 [file] [log] [blame]
Jihoon Kang4004cc62024-11-21 23:57:19 +00001// Copyright 2024 Google Inc. All rights reserved.
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 filesystem
16
17import (
18 "android/soong/android"
19 "strings"
20
21 "github.com/google/blueprint/proptools"
22)
23
24func init() {
25 android.RegisterModuleType("bootconfig", BootconfigModuleFactory)
26 pctx.Import("android/soong/android")
27}
28
29type bootconfigProperty struct {
30 // List of bootconfig parameters that will be written as a line separated list in the output
31 // file.
32 Boot_config []string
33 // Path to the file that contains the list of bootconfig parameters. This will be appended
34 // to the output file, after the entries in boot_config.
35 Boot_config_file *string `android:"path"`
36}
37
38type BootconfigModule struct {
39 android.ModuleBase
40
41 properties bootconfigProperty
42}
43
44// bootconfig module generates the `vendor-bootconfig.img` file, which lists the bootconfig
45// parameters and can be passed as a `--vendor_bootconfig` value in mkbootimg invocation.
46func BootconfigModuleFactory() android.Module {
47 module := &BootconfigModule{}
48 module.AddProperties(&module.properties)
49 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
50 return module
51}
52
53func (m *BootconfigModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
54 bootConfig := m.properties.Boot_config
55 bootConfigFileStr := proptools.String(m.properties.Boot_config_file)
56 if len(bootConfig) == 0 && len(bootConfigFileStr) == 0 {
57 return
58 }
59
60 var bootConfigFile android.Path
61 if len(bootConfigFileStr) > 0 {
62 bootConfigFile = android.PathForModuleSrc(ctx, bootConfigFileStr)
63 }
64
65 outputPath := android.PathForModuleOut(ctx, ctx.ModuleName(), "vendor-bootconfig.img")
66 bootConfigOutput := android.PathForModuleOut(ctx, ctx.ModuleName(), "bootconfig.txt")
67 android.WriteFileRule(ctx, bootConfigOutput, strings.Join(bootConfig, "\n"))
68
69 bcFiles := android.Paths{bootConfigOutput}
70 if bootConfigFile != nil {
71 bcFiles = append(bcFiles, bootConfigFile)
72 }
73 ctx.Build(pctx, android.BuildParams{
74 Rule: android.Cat,
75 Description: "concatenate bootconfig parameters",
76 Inputs: bcFiles,
77 Output: outputPath,
78 })
79 ctx.SetOutputFiles(android.Paths{outputPath}, "")
80}