blob: c6b35835ef9dbaf807953a3f0e53a468601fb5a1 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001import os
2import sys
3
4def read_dtb(filename, raw_data):
5 fin = open(filename, 'rb')
6 fin.seek(0, 0)
7 while True:
8 t_byte = fin.read(1)
9 if len(t_byte) == 0:
10 break
11 else :
12 raw_data.append("0x%.2X" % ord(t_byte))
13
14def write_blob_head_file(filename, raw_data, length):
15 fout = open(filename, 'w+')
16 fout.write('#define CHECK_RSA 1 \n')
17 fout.write('#define CHECK_HASH 1 \n')
18 fout.write('const unsigned char blob[] __attribute__((aligned(4))) = \n')
19 fout.write('{\n ')
20
21 i = 0
22 for data in raw_data:
23 i += 1
24 if i != length:
25 fout.write(data + ', ')
26 else:
27 fout.write(data)
28 if i % 16 == 0:
29 fout.write('\n ')
30 if i == length:
31 break;
32 fout.write('\n};')
33 fout.close()
34
35if __name__ == "__main__":
36 raw_data = []
37 in_path = str(sys.argv[1]);
38 out_path = str(sys.argv[2]);
39 length = int(sys.argv[3],16);
40 read_dtb(in_path, raw_data)
41 write_blob_head_file(out_path, raw_data, length)