Merge "bootimg signs image using verity_utils"

This commit is contained in:
Treehugger Robot 2021-03-17 23:37:04 +00:00 committed by Gerrit Code Review
commit ab534a3b5c
2 changed files with 38 additions and 9 deletions

View File

@ -17,6 +17,7 @@ package filesystem
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@ -217,22 +218,46 @@ func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android
} }
func (b *bootimg) signImage(ctx android.ModuleContext, unsignedImage android.OutputPath) android.OutputPath { func (b *bootimg) signImage(ctx android.ModuleContext, unsignedImage android.OutputPath) android.OutputPath {
output := android.PathForModuleOut(ctx, b.installFileName()).OutputPath propFile, toolDeps := b.buildPropFile(ctx)
key := android.PathForModuleSrc(ctx, proptools.String(b.properties.Avb_private_key))
output := android.PathForModuleOut(ctx, b.installFileName()).OutputPath
builder := android.NewRuleBuilder(pctx, ctx) builder := android.NewRuleBuilder(pctx, ctx)
builder.Command().Text("cp").Input(unsignedImage).Output(output) builder.Command().Text("cp").Input(unsignedImage).Output(output)
builder.Command(). builder.Command().BuiltTool("verity_utils").
BuiltTool("avbtool"). Input(propFile).
Flag("add_hash_footer"). Implicits(toolDeps).
FlagWithArg("--partition_name ", b.partitionName()). Output(output)
FlagWithInput("--key ", key).
FlagWithOutput("--image ", output)
builder.Build("sign_bootimg", fmt.Sprintf("Signing %s", b.BaseModuleName())) builder.Build("sign_bootimg", fmt.Sprintf("Signing %s", b.BaseModuleName()))
return output return output
} }
func (b *bootimg) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
var sb strings.Builder
var deps android.Paths
addStr := func(name string, value string) {
fmt.Fprintf(&sb, "%s=%s\n", name, value)
}
addPath := func(name string, path android.Path) {
addStr(name, path.String())
deps = append(deps, path)
}
addStr("avb_hash_enable", "true")
addPath("avb_avbtool", ctx.Config().HostToolPath(ctx, "avbtool"))
algorithm := proptools.StringDefault(b.properties.Avb_algorithm, "SHA256_RSA4096")
addStr("avb_algorithm", algorithm)
key := android.PathForModuleSrc(ctx, proptools.String(b.properties.Avb_private_key))
addPath("avb_key_path", key)
addStr("avb_add_hash_footer_args", "") // TODO(jiyong): add --rollback_index
partitionName := proptools.StringDefault(b.properties.Partition_name, b.Name())
addStr("partition_name", partitionName)
propFile = android.PathForModuleOut(ctx, "prop").OutputPath
android.WriteFileRule(ctx, propFile, sb.String())
return propFile, deps
}
var _ android.AndroidMkEntriesProvider = (*bootimg)(nil) var _ android.AndroidMkEntriesProvider = (*bootimg)(nil)
// Implements android.AndroidMkEntriesProvider // Implements android.AndroidMkEntriesProvider

View File

@ -55,6 +55,9 @@ type filesystemProperties struct {
// Hash and signing algorithm for avbtool. Default is SHA256_RSA4096. // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
Avb_algorithm *string Avb_algorithm *string
// Name of the partition stored in vbmeta desc. Defaults to the name of this module.
Partition_name *string
// Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default // Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
// is ext4. // is ext4.
Type *string Type *string
@ -279,7 +282,8 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key))
addPath("avb_key_path", key) addPath("avb_key_path", key)
addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec") addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec")
addStr("partition_name", f.Name()) partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name())
addStr("partition_name", partitionName)
} }
if proptools.String(f.properties.File_contexts) != "" { if proptools.String(f.properties.File_contexts) != "" {