Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jaewan Kim | 329c710 | 2023-08-30 16:50:55 +0900 | [diff] [blame] | 17 | package com.android.pvmfw; |
Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 18 | |
Jaewan Kim | 329c710 | 2023-08-30 16:50:55 +0900 | [diff] [blame] | 19 | import com.android.pvmfw.test.host.Pvmfw; |
Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 20 | |
| 21 | import java.io.File; |
| 22 | import java.io.IOException; |
| 23 | |
| 24 | /** CLI for {@link com.android.microdroid.test.host.Pvmfw}. */ |
| 25 | public class PvmfwTool { |
| 26 | public static void printUsage() { |
| 27 | System.out.println("pvmfw-tool: Appends pvmfw.bin and config payloads."); |
Jaewan Kim | 59009e9 | 2024-05-17 18:12:30 +0900 | [diff] [blame] | 28 | System.out.println(" Requires BCC. VM Reference DT, VM DTBO, and Debug policy"); |
| 29 | System.out.println(" can optionally be specified"); |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 30 | System.out.println( |
Jaewan Kim | 59009e9 | 2024-05-17 18:12:30 +0900 | [diff] [blame] | 31 | "Usage: pvmfw-tool <out> <pvmfw.bin> <bcc.dat> [VM reference DT] [VM DTBO] [debug" |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 32 | + " policy]"); |
Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | public static void main(String[] args) { |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 36 | if (args.length < 3 || args.length > 6) { |
Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 37 | printUsage(); |
| 38 | System.exit(1); |
| 39 | } |
| 40 | |
| 41 | File out = new File(args[0]); |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 42 | File pvmfwBin = new File(args[1]); |
| 43 | File bccData = new File(args[2]); |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 44 | |
Jaewan Kim | 59009e9 | 2024-05-17 18:12:30 +0900 | [diff] [blame] | 45 | File vmReferenceDt = null; |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 46 | File vmDtbo = null; |
| 47 | File dp = null; |
Jaewan Kim | 59009e9 | 2024-05-17 18:12:30 +0900 | [diff] [blame] | 48 | if (args.length > 3) { |
| 49 | vmReferenceDt = new File(args[3]); |
| 50 | } |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 51 | if (args.length > 4) { |
| 52 | vmDtbo = new File(args[4]); |
| 53 | } |
| 54 | if (args.length > 5) { |
| 55 | dp = new File(args[5]); |
| 56 | } |
Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 57 | |
| 58 | try { |
Jaewan Kim | 59009e9 | 2024-05-17 18:12:30 +0900 | [diff] [blame] | 59 | Pvmfw.Builder builder = |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 60 | new Pvmfw.Builder(pvmfwBin, bccData) |
| 61 | .setVmReferenceDt(vmReferenceDt) |
| 62 | .setDebugPolicyOverlay(dp) |
Jaewan Kim | 59009e9 | 2024-05-17 18:12:30 +0900 | [diff] [blame] | 63 | .setVmDtbo(vmDtbo); |
| 64 | if (vmReferenceDt == null) { |
| 65 | builder.setVersion(1, 1); |
| 66 | } else { |
| 67 | builder.setVersion(1, 2); |
| 68 | } |
| 69 | |
| 70 | Pvmfw pvmfw = builder.build(); |
Jaewan Kim | 541cb0c | 2024-03-12 21:09:16 +0900 | [diff] [blame] | 71 | pvmfw.serialize(out); |
Jaewan Kim | 0ccb99b | 2023-02-08 16:10:12 +0900 | [diff] [blame] | 72 | } catch (IOException e) { |
| 73 | e.printStackTrace(); |
| 74 | printUsage(); |
| 75 | System.exit(1); |
| 76 | } |
| 77 | } |
| 78 | } |