Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 1 | // Copyright (C) 2022 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 | "fmt" |
| 19 | |
| 20 | "github.com/google/blueprint/proptools" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
| 25 | type avbGenVbmetaImage struct { |
| 26 | android.ModuleBase |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 27 | android.DefaultableModuleBase |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 28 | |
| 29 | properties avbGenVbmetaImageProperties |
| 30 | |
| 31 | output android.OutputPath |
| 32 | installDir android.InstallPath |
| 33 | } |
| 34 | |
| 35 | type avbGenVbmetaImageProperties struct { |
| 36 | // Source file of this image. Can reference a genrule type module with the ":module" syntax. |
| 37 | Src *string `android:"path,arch_variant"` |
| 38 | |
| 39 | // Name of the image partition. Defaults to the name of this module. |
| 40 | Partition_name *string |
| 41 | |
| 42 | // The salt in hex. Required for reproducible builds. |
| 43 | Salt *string |
| 44 | } |
| 45 | |
| 46 | // The avbGenVbmetaImage generates an unsigned VBMeta image output for the given image. |
| 47 | func avbGenVbmetaImageFactory() android.Module { |
| 48 | module := &avbGenVbmetaImage{} |
| 49 | module.AddProperties(&module.properties) |
| 50 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 51 | android.InitDefaultableModule(module) |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 52 | return module |
| 53 | } |
| 54 | |
| 55 | func (a *avbGenVbmetaImage) installFileName() string { |
| 56 | return a.Name() + ".img" |
| 57 | } |
| 58 | |
| 59 | func (a *avbGenVbmetaImage) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 60 | builder := android.NewRuleBuilder(pctx, ctx) |
| 61 | cmd := builder.Command().BuiltTool("avbtool").Text("add_hash_footer") |
| 62 | cmd.Flag("--dynamic_partition_size") |
| 63 | cmd.Flag("--do_not_append_vbmeta_image") |
| 64 | |
| 65 | partition_name := proptools.StringDefault(a.properties.Partition_name, a.Name()) |
| 66 | cmd.FlagWithArg("--partition_name ", partition_name) |
| 67 | |
| 68 | if a.properties.Src == nil { |
| 69 | ctx.PropertyErrorf("src", "missing source file") |
| 70 | return |
| 71 | } |
| 72 | input := android.PathForModuleSrc(ctx, proptools.String(a.properties.Src)) |
| 73 | cmd.FlagWithInput("--image ", input) |
| 74 | |
| 75 | if a.properties.Salt == nil { |
| 76 | ctx.PropertyErrorf("salt", "missing salt value") |
| 77 | return |
| 78 | } |
| 79 | cmd.FlagWithArg("--salt ", proptools.String(a.properties.Salt)) |
| 80 | |
| 81 | a.output = android.PathForModuleOut(ctx, a.installFileName()).OutputPath |
| 82 | cmd.FlagWithOutput("--output_vbmeta_image ", a.output) |
| 83 | builder.Build("avbGenVbmetaImage", fmt.Sprintf("avbGenVbmetaImage %s", ctx.ModuleName())) |
mrziwang | 555d133 | 2024-06-07 11:15:33 -0700 | [diff] [blame^] | 84 | |
| 85 | ctx.SetOutputFiles([]android.Path{a.output}, "") |
Alice Wang | 000e3a3 | 2023-01-03 16:11:20 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | var _ android.AndroidMkEntriesProvider = (*avbGenVbmetaImage)(nil) |
| 89 | |
| 90 | // Implements android.AndroidMkEntriesProvider |
| 91 | func (a *avbGenVbmetaImage) AndroidMkEntries() []android.AndroidMkEntries { |
| 92 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 93 | Class: "ETC", |
| 94 | OutputFile: android.OptionalPathForPath(a.output), |
| 95 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 96 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
| 97 | entries.SetString("LOCAL_MODULE_PATH", a.installDir.String()) |
| 98 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", a.installFileName()) |
| 99 | }, |
| 100 | }, |
| 101 | }} |
| 102 | } |
| 103 | |
Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 104 | type avbGenVbmetaImageDefaults struct { |
| 105 | android.ModuleBase |
| 106 | android.DefaultsModuleBase |
| 107 | } |
| 108 | |
| 109 | // avb_gen_vbmeta_image_defaults provides a set of properties that can be inherited by other |
| 110 | // avb_gen_vbmeta_image modules. A module can use the properties from an |
| 111 | // avb_gen_vbmeta_image_defaults using `defaults: ["<:default_module_name>"]`. Properties of both |
| 112 | // modules are erged (when possible) by prepending the default module's values to the depending |
| 113 | // module's values. |
| 114 | func avbGenVbmetaImageDefaultsFactory() android.Module { |
| 115 | module := &avbGenVbmetaImageDefaults{} |
| 116 | module.AddProperties(&avbGenVbmetaImageProperties{}) |
| 117 | android.InitDefaultsModule(module) |
| 118 | return module |
| 119 | } |