Jihoon Kang | 4325cbe | 2024-11-06 18:41:44 +0000 | [diff] [blame] | 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 | |
| 15 | package etc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | "github.com/google/blueprint/proptools" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | android.RegisterModuleType("avbpubkey", AvbpubkeyModuleFactory) |
| 26 | pctx.HostBinToolVariable("avbtool", "avbtool") |
| 27 | } |
| 28 | |
| 29 | type avbpubkeyProperty struct { |
| 30 | Private_key *string `android:"path"` |
| 31 | } |
| 32 | |
| 33 | type AvbpubkeyModule struct { |
| 34 | android.ModuleBase |
| 35 | |
| 36 | properties avbpubkeyProperty |
| 37 | |
| 38 | outputPath android.WritablePath |
| 39 | installPath android.InstallPath |
| 40 | } |
| 41 | |
| 42 | func AvbpubkeyModuleFactory() android.Module { |
| 43 | module := &AvbpubkeyModule{} |
| 44 | module.AddProperties(&module.properties) |
| 45 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
| 46 | return module |
| 47 | } |
| 48 | |
| 49 | var 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 | Description: "Extracting system_other avb key", |
| 55 | }) |
| 56 | |
| 57 | func (m *AvbpubkeyModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 58 | if !m.ProductSpecific() { |
| 59 | ctx.ModuleErrorf("avbpubkey module type must set product_specific to true") |
| 60 | } |
| 61 | |
| 62 | m.outputPath = android.PathForModuleOut(ctx, ctx.ModuleName(), "system_other.avbpubkey") |
| 63 | |
| 64 | ctx.Build(pctx, android.BuildParams{ |
| 65 | Rule: avbPubKeyRule, |
| 66 | Input: android.PathForModuleSrc(ctx, proptools.String(m.properties.Private_key)), |
| 67 | Output: m.outputPath, |
| 68 | }) |
| 69 | |
| 70 | m.installPath = android.PathForModuleInstall(ctx, "etc/security/avb") |
| 71 | ctx.InstallFile(m.installPath, "system_other.avbpubkey", m.outputPath) |
| 72 | } |
| 73 | |
| 74 | func (m *AvbpubkeyModule) AndroidMkEntries() []android.AndroidMkEntries { |
| 75 | if m.IsSkipInstall() { |
| 76 | return []android.AndroidMkEntries{} |
| 77 | } |
| 78 | |
| 79 | return []android.AndroidMkEntries{ |
| 80 | { |
| 81 | Class: "ETC", |
| 82 | OutputFile: android.OptionalPathForPath(m.outputPath), |
| 83 | }} |
| 84 | } |