| 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())) | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | var _ android.AndroidMkEntriesProvider = (*avbGenVbmetaImage)(nil) | 
|  | 87 |  | 
|  | 88 | // Implements android.AndroidMkEntriesProvider | 
|  | 89 | func (a *avbGenVbmetaImage) AndroidMkEntries() []android.AndroidMkEntries { | 
|  | 90 | return []android.AndroidMkEntries{android.AndroidMkEntries{ | 
|  | 91 | Class:      "ETC", | 
|  | 92 | OutputFile: android.OptionalPathForPath(a.output), | 
|  | 93 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
|  | 94 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { | 
|  | 95 | entries.SetString("LOCAL_MODULE_PATH", a.installDir.String()) | 
|  | 96 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", a.installFileName()) | 
|  | 97 | }, | 
|  | 98 | }, | 
|  | 99 | }} | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | var _ android.OutputFileProducer = (*avbGenVbmetaImage)(nil) | 
|  | 103 |  | 
|  | 104 | // Implements android.OutputFileProducer | 
|  | 105 | func (a *avbGenVbmetaImage) OutputFiles(tag string) (android.Paths, error) { | 
|  | 106 | if tag == "" { | 
|  | 107 | return []android.Path{a.output}, nil | 
|  | 108 | } | 
|  | 109 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 110 | } | 
| Inseob Kim | 87230e6 | 2023-11-22 18:55:07 +0900 | [diff] [blame] | 111 |  | 
|  | 112 | type avbGenVbmetaImageDefaults struct { | 
|  | 113 | android.ModuleBase | 
|  | 114 | android.DefaultsModuleBase | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | // avb_gen_vbmeta_image_defaults provides a set of properties that can be inherited by other | 
|  | 118 | // avb_gen_vbmeta_image modules. A module can use the properties from an | 
|  | 119 | // avb_gen_vbmeta_image_defaults using `defaults: ["<:default_module_name>"]`. Properties of both | 
|  | 120 | // modules are erged (when possible) by prepending the default module's values to the depending | 
|  | 121 | // module's values. | 
|  | 122 | func avbGenVbmetaImageDefaultsFactory() android.Module { | 
|  | 123 | module := &avbGenVbmetaImageDefaults{} | 
|  | 124 | module.AddProperties(&avbGenVbmetaImageProperties{}) | 
|  | 125 | android.InitDefaultsModule(module) | 
|  | 126 | return module | 
|  | 127 | } |