Add 'generate_gki_certificate' standalone tool to certify GKI am: 6ec5817b45 am: c7d21760d2

Original change: https://android-review.googlesource.com/c/platform/system/tools/mkbootimg/+/1933194

Change-Id: I9f02d070454ca931f2f07b7ffd37d1d192be56ca
diff --git a/Android.bp b/Android.bp
index 77a5a32..5881443 100644
--- a/Android.bp
+++ b/Android.bp
@@ -54,6 +54,18 @@
 }
 
 python_binary_host {
+    name: "generate_gki_certificate",
+    defaults: ["mkbootimg_defaults"],
+    main: "gki/generate_gki_certificate.py",
+    srcs: [
+        "gki/generate_gki_certificate.py",
+    ],
+    required: [
+        "avbtool",
+    ],
+}
+
+python_binary_host {
     name: "mkbootimg",
     defaults: ["mkbootimg_defaults"],
     main: "mkbootimg.py",
diff --git a/gki/generate_gki_certificate.py b/gki/generate_gki_certificate.py
index 94bec88..f3802a0 100755
--- a/gki/generate_gki_certificate.py
+++ b/gki/generate_gki_certificate.py
@@ -45,3 +45,42 @@
     avbtool_cmd += additional_avb_args
 
     subprocess.check_call(avbtool_cmd)
+
+
+def parse_cmdline():
+    parser = ArgumentParser(add_help=True)
+
+    # Required args.
+    parser.add_argument('image', help='path to the image')
+    parser.add_argument('-o', '--output', required=True,
+                        help='output certificate file name')
+    parser.add_argument('--name', required=True,
+                        choices=['generic_kernel', 'generic_ramdisk'],
+                        help='name of the image to be certified')
+    parser.add_argument('--algorithm', required=True,
+                        help='AVB signing algorithm')
+    parser.add_argument('--key', required=True,
+                        help='path to the RSA private key')
+
+    # Optional args.
+    parser.add_argument('--avbtool', default='avbtool',
+                        help='path to the avbtool executable')
+    parser.add_argument('--salt', help='salt to use when computing image hash')
+    parser.add_argument('--additional_avb_args', default='',
+                        help='additional arguments to be forwarded to avbtool')
+
+    return parser.parse_args()
+
+
+def main():
+    args = parse_cmdline()
+    generate_gki_certificate(
+        image=args.image, avbtool=args.avbtool, name=args.name,
+        algorithm=args.algorithm, key=args.key, salt=args.salt,
+        additional_avb_args=args.additional_avb_args.split(),
+        output=args.output,
+    )
+
+
+if __name__ == '__main__':
+    main()