avb_gen_vbmeta_image.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. package filesystem
  15. import (
  16. "fmt"
  17. "github.com/google/blueprint/proptools"
  18. "android/soong/android"
  19. )
  20. type avbGenVbmetaImage struct {
  21. android.ModuleBase
  22. properties avbGenVbmetaImageProperties
  23. output android.OutputPath
  24. installDir android.InstallPath
  25. }
  26. type avbGenVbmetaImageProperties struct {
  27. // Source file of this image. Can reference a genrule type module with the ":module" syntax.
  28. Src *string `android:"path,arch_variant"`
  29. // Name of the image partition. Defaults to the name of this module.
  30. Partition_name *string
  31. // The salt in hex. Required for reproducible builds.
  32. Salt *string
  33. }
  34. // The avbGenVbmetaImage generates an unsigned VBMeta image output for the given image.
  35. func avbGenVbmetaImageFactory() android.Module {
  36. module := &avbGenVbmetaImage{}
  37. module.AddProperties(&module.properties)
  38. android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
  39. return module
  40. }
  41. func (a *avbGenVbmetaImage) installFileName() string {
  42. return a.Name() + ".img"
  43. }
  44. func (a *avbGenVbmetaImage) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  45. builder := android.NewRuleBuilder(pctx, ctx)
  46. cmd := builder.Command().BuiltTool("avbtool").Text("add_hash_footer")
  47. cmd.Flag("--dynamic_partition_size")
  48. cmd.Flag("--do_not_append_vbmeta_image")
  49. partition_name := proptools.StringDefault(a.properties.Partition_name, a.Name())
  50. cmd.FlagWithArg("--partition_name ", partition_name)
  51. if a.properties.Src == nil {
  52. ctx.PropertyErrorf("src", "missing source file")
  53. return
  54. }
  55. input := android.PathForModuleSrc(ctx, proptools.String(a.properties.Src))
  56. cmd.FlagWithInput("--image ", input)
  57. if a.properties.Salt == nil {
  58. ctx.PropertyErrorf("salt", "missing salt value")
  59. return
  60. }
  61. cmd.FlagWithArg("--salt ", proptools.String(a.properties.Salt))
  62. a.output = android.PathForModuleOut(ctx, a.installFileName()).OutputPath
  63. cmd.FlagWithOutput("--output_vbmeta_image ", a.output)
  64. builder.Build("avbGenVbmetaImage", fmt.Sprintf("avbGenVbmetaImage %s", ctx.ModuleName()))
  65. }
  66. var _ android.AndroidMkEntriesProvider = (*avbGenVbmetaImage)(nil)
  67. // Implements android.AndroidMkEntriesProvider
  68. func (a *avbGenVbmetaImage) AndroidMkEntries() []android.AndroidMkEntries {
  69. return []android.AndroidMkEntries{android.AndroidMkEntries{
  70. Class: "ETC",
  71. OutputFile: android.OptionalPathForPath(a.output),
  72. ExtraEntries: []android.AndroidMkExtraEntriesFunc{
  73. func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
  74. entries.SetString("LOCAL_MODULE_PATH", a.installDir.String())
  75. entries.SetString("LOCAL_INSTALLED_MODULE_STEM", a.installFileName())
  76. },
  77. },
  78. }}
  79. }
  80. var _ android.OutputFileProducer = (*avbGenVbmetaImage)(nil)
  81. // Implements android.OutputFileProducer
  82. func (a *avbGenVbmetaImage) OutputFiles(tag string) (android.Paths, error) {
  83. if tag == "" {
  84. return []android.Path{a.output}, nil
  85. }
  86. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  87. }