1// Copyright 2024 Google Inc. All rights reserved. 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 15package etc 16 17import ( 18 "android/soong/android" 19 20 "github.com/google/blueprint" 21 "github.com/google/blueprint/proptools" 22) 23 24func init() { 25 android.RegisterModuleType("avbpubkey", AvbpubkeyModuleFactory) 26 pctx.HostBinToolVariable("avbtool", "avbtool") 27} 28 29type avbpubkeyProperty struct { 30 Private_key *string `android:"path"` 31} 32 33type AvbpubkeyModule struct { 34 android.ModuleBase 35 36 properties avbpubkeyProperty 37 38 outputPath android.WritablePath 39 installPath android.InstallPath 40} 41 42func AvbpubkeyModuleFactory() android.Module { 43 module := &AvbpubkeyModule{} 44 module.AddProperties(&module.properties) 45 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) 46 return module 47} 48 49var avbPubKeyRule = pctx.AndroidStaticRule("avbpubkey", 50 blueprint.RuleParams{ 51 Command: `${avbtool} extract_public_key --key ${in} --output ${out}.tmp` + 52 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`, 53 CommandDeps: []string{"${avbtool}"}, 54 Restat: true, 55 Description: "Extracting system_other avb key", 56 }) 57 58func (m *AvbpubkeyModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { 59 if !m.ProductSpecific() { 60 ctx.ModuleErrorf("avbpubkey module type must set product_specific to true") 61 } 62 63 m.outputPath = android.PathForModuleOut(ctx, ctx.ModuleName(), "system_other.avbpubkey") 64 65 ctx.Build(pctx, android.BuildParams{ 66 Rule: avbPubKeyRule, 67 Input: android.PathForModuleSrc(ctx, proptools.String(m.properties.Private_key)), 68 Output: m.outputPath, 69 }) 70 71 m.installPath = android.PathForModuleInstall(ctx, "etc/security/avb") 72 ctx.InstallFile(m.installPath, "system_other.avbpubkey", m.outputPath) 73} 74 75func (m *AvbpubkeyModule) AndroidMkEntries() []android.AndroidMkEntries { 76 if m.IsSkipInstall() { 77 return []android.AndroidMkEntries{} 78 } 79 80 return []android.AndroidMkEntries{ 81 { 82 Class: "ETC", 83 OutputFile: android.OptionalPathForPath(m.outputPath), 84 }} 85} 86