Add props property to add_avb_hash_footer
It is used to provide name:value properties to the footer. Value can be from a text in *.bp file or a binary file referenced via the `file` prop. e.g. ``` avb_add_hash_footer { ... props: [ { name: "string_prop", value: "string_value", }, { name: "binary_prop", file: "a_binary_file_name", }, ], } ``` This CL also adds a test for the module type which has been missing. Bug: 256148237 Test: m nothing Change-Id: Idf55b308c8ce760387c01a847846b42d1aebe4ea
This commit is contained in:
@@ -23,10 +23,6 @@ import (
|
|||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
android.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
|
|
||||||
}
|
|
||||||
|
|
||||||
type avbAddHashFooter struct {
|
type avbAddHashFooter struct {
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
|
|
||||||
@@ -36,6 +32,17 @@ type avbAddHashFooter struct {
|
|||||||
installDir android.InstallPath
|
installDir android.InstallPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type avbProp struct {
|
||||||
|
// Name of a property
|
||||||
|
Name *string
|
||||||
|
|
||||||
|
// Value of a property. Can't be used together with `file`.
|
||||||
|
Value *string
|
||||||
|
|
||||||
|
// File from which the value of the prop is read from. Can't be used together with `value`.
|
||||||
|
File *string `android:"path,arch_variant"`
|
||||||
|
}
|
||||||
|
|
||||||
type avbAddHashFooterProperties struct {
|
type avbAddHashFooterProperties struct {
|
||||||
// Source file of this image. Can reference a genrule type module with the ":module" syntax.
|
// Source file of this image. Can reference a genrule type module with the ":module" syntax.
|
||||||
Src *string `android:"path,arch_variant"`
|
Src *string `android:"path,arch_variant"`
|
||||||
@@ -57,6 +64,9 @@ type avbAddHashFooterProperties struct {
|
|||||||
|
|
||||||
// The salt in hex. Required for reproducible builds.
|
// The salt in hex. Required for reproducible builds.
|
||||||
Salt *string
|
Salt *string
|
||||||
|
|
||||||
|
// List of properties to add to the footer
|
||||||
|
Props []avbProp
|
||||||
}
|
}
|
||||||
|
|
||||||
// The AVB footer adds verification information to the image.
|
// The AVB footer adds verification information to the image.
|
||||||
@@ -106,6 +116,10 @@ func (a *avbAddHashFooter) GenerateAndroidBuildActions(ctx android.ModuleContext
|
|||||||
}
|
}
|
||||||
cmd.FlagWithArg("--salt ", proptools.String(a.properties.Salt))
|
cmd.FlagWithArg("--salt ", proptools.String(a.properties.Salt))
|
||||||
|
|
||||||
|
for _, prop := range a.properties.Props {
|
||||||
|
addAvbProp(ctx, cmd, prop)
|
||||||
|
}
|
||||||
|
|
||||||
cmd.FlagWithOutput("--image ", a.output)
|
cmd.FlagWithOutput("--image ", a.output)
|
||||||
|
|
||||||
builder.Build("avbAddHashFooter", fmt.Sprintf("avbAddHashFooter %s", ctx.ModuleName()))
|
builder.Build("avbAddHashFooter", fmt.Sprintf("avbAddHashFooter %s", ctx.ModuleName()))
|
||||||
@@ -114,6 +128,32 @@ func (a *avbAddHashFooter) GenerateAndroidBuildActions(ctx android.ModuleContext
|
|||||||
ctx.InstallFile(a.installDir, a.installFileName(), a.output)
|
ctx.InstallFile(a.installDir, a.installFileName(), a.output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addAvbProp(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, prop avbProp) {
|
||||||
|
name := proptools.String(prop.Name)
|
||||||
|
value := proptools.String(prop.Value)
|
||||||
|
file := proptools.String(prop.File)
|
||||||
|
if name == "" {
|
||||||
|
ctx.PropertyErrorf("name", "can't be empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if value == "" && file == "" {
|
||||||
|
ctx.PropertyErrorf("value", "either value or file should be set")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if value != "" && file != "" {
|
||||||
|
ctx.PropertyErrorf("value", "value and file can't be set at the same time")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if value != "" {
|
||||||
|
cmd.FlagWithArg("--prop ", proptools.ShellEscape(fmt.Sprintf("%s:%s", name, value)))
|
||||||
|
} else {
|
||||||
|
p := android.PathForModuleSrc(ctx, file)
|
||||||
|
cmd.Input(p)
|
||||||
|
cmd.FlagWithArg("--prop_from_file ", proptools.ShellEscape(fmt.Sprintf("%s:%s", name, cmd.PathForInput(p))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var _ android.AndroidMkEntriesProvider = (*avbAddHashFooter)(nil)
|
var _ android.AndroidMkEntriesProvider = (*avbAddHashFooter)(nil)
|
||||||
|
|
||||||
// Implements android.AndroidMkEntriesProvider
|
// Implements android.AndroidMkEntriesProvider
|
||||||
|
@@ -34,6 +34,7 @@ func init() {
|
|||||||
func registerBuildComponents(ctx android.RegistrationContext) {
|
func registerBuildComponents(ctx android.RegistrationContext) {
|
||||||
ctx.RegisterModuleType("android_filesystem", filesystemFactory)
|
ctx.RegisterModuleType("android_filesystem", filesystemFactory)
|
||||||
ctx.RegisterModuleType("android_system_image", systemImageFactory)
|
ctx.RegisterModuleType("android_system_image", systemImageFactory)
|
||||||
|
ctx.RegisterModuleType("avb_add_hash_footer", avbAddHashFooterFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type filesystem struct {
|
type filesystem struct {
|
||||||
|
@@ -125,3 +125,37 @@ func TestFileSystemGathersItemsOnlyInSystemPartition(t *testing.T) {
|
|||||||
module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
|
module := result.ModuleForTests("myfilesystem", "android_common").Module().(*systemImage)
|
||||||
android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
|
android.AssertDeepEquals(t, "entries should have foo only", []string{"components/foo"}, module.entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAvbAddHashFooter(t *testing.T) {
|
||||||
|
result := fixture.RunTestWithBp(t, `
|
||||||
|
avb_add_hash_footer {
|
||||||
|
name: "myfooter",
|
||||||
|
src: "input.img",
|
||||||
|
filename: "output.img",
|
||||||
|
partition_name: "mypartition",
|
||||||
|
private_key: "mykey",
|
||||||
|
salt: "1111",
|
||||||
|
props: [
|
||||||
|
{
|
||||||
|
name: "prop1",
|
||||||
|
value: "value1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prop2",
|
||||||
|
file: "value_file",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
cmd := result.ModuleForTests("myfooter", "android_arm64_armv8-a").Rule("avbAddHashFooter").RuleParams.Command
|
||||||
|
android.AssertStringDoesContain(t, "Can't find correct --partition_name argument",
|
||||||
|
cmd, "--partition_name mypartition")
|
||||||
|
android.AssertStringDoesContain(t, "Can't find correct --key argument",
|
||||||
|
cmd, "--key mykey")
|
||||||
|
android.AssertStringDoesContain(t, "Can't find --salt argument",
|
||||||
|
cmd, "--salt 1111")
|
||||||
|
android.AssertStringDoesContain(t, "Can't find --prop argument",
|
||||||
|
cmd, "--prop 'prop1:value1'")
|
||||||
|
android.AssertStringDoesContain(t, "Can't find --prop_from_file argument",
|
||||||
|
cmd, "--prop_from_file 'prop2:value_file'")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user