mediatek: fix IPv4-only corner case and commit in 99-net-ps
[oweals/openwrt.git] / scripts / cfe-bin-header.py
1 #!/usr/bin/env python3
2
3 import argparse
4 import os
5 import struct
6
7 def auto_int(x):
8         return int(x, 0)
9
10 def create_header(args, size):
11         header = struct.pack('>III', args.entry_addr, args.load_addr, size)
12         return header
13
14 def create_output(args):
15         in_st = os.stat(args.input_file)
16         in_size = in_st.st_size
17
18         header = create_header(args, in_size)
19         print(header)
20
21         in_f = open(args.input_file, 'r+b')
22         in_bytes = in_f.read(in_size)
23         in_f.close()
24
25         out_f = open(args.output_file, 'w+b')
26         out_f.write(header)
27         out_f.write(in_bytes)
28         out_f.close()
29
30 def main():
31         global args
32
33         parser = argparse.ArgumentParser(description='')
34
35         parser.add_argument('--entry-addr',
36                 dest='entry_addr',
37                 action='store',
38                 type=auto_int,
39                 help='Entry Address')
40
41         parser.add_argument('--input-file',
42                 dest='input_file',
43                 action='store',
44                 type=str,
45                 help='Input file')
46
47         parser.add_argument('--load-addr',
48                 dest='load_addr',
49                 action='store',
50                 type=auto_int,
51                 help='Load Address')
52
53         parser.add_argument('--output-file',
54                 dest='output_file',
55                 action='store',
56                 type=str,
57                 help='Output file')
58
59         args = parser.parse_args()
60
61         if (not args.input_file) or (not args.output_file):
62                 parser.print_help()
63
64         if not args.entry_addr:
65                 args.entry_addr = 0x80010000
66
67         if not args.load_addr:
68                 args.load_addr = 0x80010000
69
70         create_output(args)
71
72 main()