xref: /OK3568_Linux_fs/u-boot/lib/optee_clientApi/tabinary_to_cfile.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/usr/bin/env python
2#
3# Copyright 2017, Rockchip Electronics Co., Ltd
4# hisping lin, <hisping.lin@rock-chips.com>
5#
6# SPDX-License-Identifier:	GPL-2.0+
7#
8
9def get_args():
10	import argparse
11
12	parser = argparse.ArgumentParser()
13	parser.add_argument('--prefix', required=True, \
14		help='Prefix for the TA array in c file')
15
16	parser.add_argument('--out', required=True, \
17		help='Name of c file for the TA')
18
19	parser.add_argument('--TA', required=True, help='Name of TA')
20
21	return parser.parse_args()
22
23def main():
24	import array
25#	from Crypto.PublicKey import RSA
26#	from Crypto.Util.number import long_to_bytes
27
28	args = get_args();
29
30	f = open(args.TA, 'r')
31	TAdata = f.read()
32	f.close
33
34	f = open(args.out, 'w')
35
36	f.write("#include <stdint.h>\n");
37	f.write("#include <stddef.h>\n\n");
38
39#	f.write("const uint32_t " + args.prefix + "_exponent = " +
40#		str(key.publickey().e) + ";\n\n")
41
42	f.write("const uint8_t " + args.prefix + "_data[] = {\n")
43	i = 0;
44	for x in array.array("B", TAdata):
45		f.write("0x" + '{0:02x}'.format(x) + ",")
46		i = i + 1;
47		if i % 8 == 0:
48			f.write("\n");
49		else:
50			f.write(" ");
51	f.write("};\n");
52
53	f.write("const uint32_t " + args.prefix + "_size = " + str(i) + ";\n" )
54
55	f.close()
56
57if __name__ == "__main__":
58	main()
59