xref: /btstack/chipset/cc256x/convert_bts_init_scripts.py (revision 58026f5a5377139dccd24ca4e328dd8c7b7fdd9c)
1c9921182SMatthias Ringwald#!/usr/bin/env python3
2d5814ca7SMatthias Ringwald# BlueKitchen GmbH (c) 2012-2014
3d5814ca7SMatthias Ringwald
4d5814ca7SMatthias Ringwald# documentation for TI Vendor Specific commands:
5d5814ca7SMatthias Ringwald# http://processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands
6d5814ca7SMatthias Ringwald
7d5814ca7SMatthias Ringwaldimport glob
8d5814ca7SMatthias Ringwaldimport re
9d5814ca7SMatthias Ringwaldimport sys
10d5814ca7SMatthias Ringwaldimport os
11d5814ca7SMatthias Ringwald
1206ee659aSMatthias Ringwaldusage = '''
1306ee659aSMatthias RingwaldCC256x init script conversion tool for use with BTstack, v0.2
14fb904c26SMatthias RingwaldCopyright 2012-2017 BlueKitchen GmbH
15d5814ca7SMatthias Ringwald
1606ee659aSMatthias RingwaldUsage:
1706ee659aSMatthias Ringwald$ ./convert_bts_init_scripts.py main.bts [ble-add-on.bts] output.c
18d5814ca7SMatthias Ringwald
1906ee659aSMatthias RingwaldPlease specify the main .bts script and optionally the BLE Add-on to generate the init script .c file.
2006ee659aSMatthias Ringwald
2106ee659aSMatthias RingwaldThe Makefile include chipset/cc256x/Makefile.inc automates the process of downloading and converting .bts files.
2206ee659aSMatthias Ringwald
2306ee659aSMatthias RingwaldIf this is not an option, you can download the Service Packs for your module from http://processors.wiki.ti.com/index.php/CC256x_Downloads
2406ee659aSMatthias RingwaldThen, unzip it and copy the *.bts file into this folder before start the script again.
25d5814ca7SMatthias Ringwald'''
26d5814ca7SMatthias Ringwald
27d5814ca7SMatthias Ringwaldfartext = '''
28d5814ca7SMatthias Ringwald#if defined(__GNUC__) && defined(__MSP430X__) && (__MSP430X__ > 0)
29d5814ca7SMatthias Ringwald__attribute__((section (".fartext")))
30d5814ca7SMatthias Ringwald#endif
31d5814ca7SMatthias Ringwald#ifdef __AVR__
32d5814ca7SMatthias Ringwald__attribute__((__progmem__))
33d5814ca7SMatthias Ringwald#endif
34d5814ca7SMatthias Ringwald'''
35d5814ca7SMatthias Ringwald
36ed5d91baSMatthias Ringwaldget_lmp_subversion = '''
37ed5d91baSMatthias Ringwaldconst uint16_t {prefix}_init_script_lmp_subversion = {lmp_subversion};
38ed5d91baSMatthias Ringwald
39ed5d91baSMatthias Ringwalduint16_t btstack_chipset_cc256x_lmp_subversion(void){{
40ed5d91baSMatthias Ringwald    return {prefix}_init_script_lmp_subversion;
41ed5d91baSMatthias Ringwald}}
42ed5d91baSMatthias Ringwald'''
43ed5d91baSMatthias Ringwald
44d5814ca7SMatthias Ringwalddata_indent = '    '
45d5814ca7SMatthias Ringwald
46d5814ca7SMatthias Ringwalddef read_little_endian_16(f):
47d5814ca7SMatthias Ringwald    low  = f.read(1)
48f55dd2adSMatthias Ringwald    if len(low) == 0:
49d5814ca7SMatthias Ringwald        return -1
50d5814ca7SMatthias Ringwald    high = f.read(1)
51d5814ca7SMatthias Ringwald    return ord(high) << 8 | ord(low)
52d5814ca7SMatthias Ringwald
53d5814ca7SMatthias Ringwalddef append_power_vector_gfsk(additions, str_list, data_indent):
54d5814ca7SMatthias Ringwald    additions.append("- added HCI_VS_SET_POWER_VECTOR(GFSK) template")
55d5814ca7SMatthias Ringwald    str_list.append(data_indent)
56d5814ca7SMatthias Ringwald    str_list.append('// BTstack: added HCI_VS_SET_POWER_VECTOR(GFSK) 0xFD82 template\n');
57d5814ca7SMatthias Ringwald    str_list.append(data_indent)
58d5814ca7SMatthias Ringwald    str_list.append("0x01, 0x82, 0xfd, 0x14, 0x00, 0x9c, 0x18, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xdc,\n");
59d5814ca7SMatthias Ringwald    str_list.append(data_indent)
60d5814ca7SMatthias Ringwald    str_list.append("0xe6, 0xf0, 0xfa, 0x04, 0x0e, 0x18, 0xff, 0x00, 0x00,\n\n");
61c4054521SMatthias Ringwald    return 24
62d5814ca7SMatthias Ringwald
63d5814ca7SMatthias Ringwalddef append_power_vector_edr2(additions, str_list, data_indent):
64d5814ca7SMatthias Ringwald    additions.append("- added HCI_VS_SET_POWER_VECTOR(EDR2) template")
65d5814ca7SMatthias Ringwald    str_list.append(data_indent)
66d5814ca7SMatthias Ringwald    str_list.append('// BTstack: added HCI_VS_SET_POWER_VECTOR(EDR2) 0xFD82 template\n');
67d5814ca7SMatthias Ringwald    str_list.append(data_indent)
68d5814ca7SMatthias Ringwald    str_list.append("0x01, 0x82, 0xfd, 0x14, 0x01, 0x9c, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xd8, \n");
69d5814ca7SMatthias Ringwald    str_list.append(data_indent)
70d5814ca7SMatthias Ringwald    str_list.append("0xe2, 0xec, 0xf6, 0x00, 0x0a, 0x14, 0xff, 0x00, 0x00,\n\n");
71c4054521SMatthias Ringwald    return 24
72d5814ca7SMatthias Ringwald
73d5814ca7SMatthias Ringwalddef append_power_vector_edr3(additions, str_list, data_indent):
74d5814ca7SMatthias Ringwald    additions.append("- added HCI_VS_SET_POWER_VECTOR(EDR3) template")
75d5814ca7SMatthias Ringwald    str_list.append(data_indent)
76d5814ca7SMatthias Ringwald    str_list.append('// BTstack: added HCI_VS_SET_POWER_VECTOR(EDR3) 0xFD82 for EDR3 template\n');
77d5814ca7SMatthias Ringwald    str_list.append(data_indent)
78d5814ca7SMatthias Ringwald    str_list.append("0x01, 0x82, 0xfd, 0x14, 0x02, 0x9c, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, 0xd8,\n");
79d5814ca7SMatthias Ringwald    str_list.append(data_indent)
80d5814ca7SMatthias Ringwald    str_list.append("0xe2, 0xec, 0xf6, 0x00, 0x0a, 0x14, 0xff, 0x00, 0x00,\n\n");
81c4054521SMatthias Ringwald    return 24
82d5814ca7SMatthias Ringwald
83d5814ca7SMatthias Ringwalddef append_class2_single_power(additions, str_list, data_indent):
84d5814ca7SMatthias Ringwald    additions.append("- added HCI_VS_SET_CLASS2_SINGLE_POWER template")
85d5814ca7SMatthias Ringwald    str_list.append(data_indent)
86d5814ca7SMatthias Ringwald    str_list.append('// BTstack: added HCI_VS_SET_CLASS2_SINGLE_POWER 0xFD87 template\n');
87d5814ca7SMatthias Ringwald    str_list.append(data_indent)
88d5814ca7SMatthias Ringwald    str_list.append("0x01, 0x87, 0xfd, 0x03, 0x0d, 0x0d, 0x0d,\n\n");
89d5814ca7SMatthias Ringwald    return 7
90d5814ca7SMatthias Ringwald
91d5814ca7SMatthias Ringwalddef append_ehcill(additions, str_list, data_indent):
92d5814ca7SMatthias Ringwald    additions.append("- added eHCILL template")
93d5814ca7SMatthias Ringwald    str_list.append('\n')
94d5814ca7SMatthias Ringwald    str_list.append(data_indent)
95d5814ca7SMatthias Ringwald    str_list.append('// BTstack: added HCI_VS_Sleep_Mode_Configurations 0xFD0C template for eHCILL\n');
96d5814ca7SMatthias Ringwald    str_list.append(data_indent)
97d5814ca7SMatthias Ringwald    str_list.append('0x01, 0x0c, 0xfd, 9 , 1, 0, 0,  0xff, 0xff, 0xff, 0xff, 100, 0,\n\n');
98d5814ca7SMatthias Ringwald    return 13
99d5814ca7SMatthias Ringwald
100d5814ca7SMatthias Ringwalddef append_calibration_sequence(additions, str_list, data_indent):
101d5814ca7SMatthias Ringwald    additions.append("- added calibration sequence")
102d5814ca7SMatthias Ringwald    str_list.append(data_indent)
103d5814ca7SMatthias Ringwald    str_list.append("// BTstack: added calibration sequence\n")
104d5814ca7SMatthias Ringwald    str_list.append(data_indent)
105d5814ca7SMatthias Ringwald    str_list.append("0x01, 0x80, 0xfd, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,\n")
106d5814ca7SMatthias Ringwald    str_list.append(data_indent)
107d5814ca7SMatthias Ringwald    str_list.append("0x01, 0x80, 0xfd, 0x06, 0x3c, 0xf0, 0x5f, 0x00, 0x00, 0x00,\n\n")
108d5814ca7SMatthias Ringwald    return 20
109d5814ca7SMatthias Ringwald
110ed5d91baSMatthias Ringwald
11106ee659aSMatthias Ringwalddef convert_bts(output_file, main_bts_file, bts_add_on, aka, lmp_subversion):
112d5814ca7SMatthias Ringwald    array_name = 'cc256x'
113d5814ca7SMatthias Ringwald
114d5814ca7SMatthias Ringwald    input_files = [ main_bts_file ]
115d5814ca7SMatthias Ringwald    if bts_add_on != "":
116d5814ca7SMatthias Ringwald        input_files.append(bts_add_on)
117d5814ca7SMatthias Ringwald
11806ee659aSMatthias Ringwald    with open(output_file, 'w') as fout:
119d5814ca7SMatthias Ringwald
120d5814ca7SMatthias Ringwald        # assert script contains templates for configuration by BTstack
121d5814ca7SMatthias Ringwald        have_eHCILL = False
122d5814ca7SMatthias Ringwald        have_power_vector_gfsk = False;
123d5814ca7SMatthias Ringwald        have_power_vector_edr2 = False;
124d5814ca7SMatthias Ringwald        have_power_vector_edr3 = False;
125d5814ca7SMatthias Ringwald        have_class2_single_power = False;
126d5814ca7SMatthias Ringwald
12706ee659aSMatthias Ringwald        print("Creating {0}".format(output_file))
128d5814ca7SMatthias Ringwald
129d5814ca7SMatthias Ringwald        part_size = 0
130d5814ca7SMatthias Ringwald
131d5814ca7SMatthias Ringwald        parts = 0
132d5814ca7SMatthias Ringwald        str_list = []
133d5814ca7SMatthias Ringwald        part_strings = []
134d5814ca7SMatthias Ringwald        part_sizes   = []
135d5814ca7SMatthias Ringwald        additions = []
136d5814ca7SMatthias Ringwald
137d5814ca7SMatthias Ringwald        for bts_file in input_files:
138d5814ca7SMatthias Ringwald
139d5814ca7SMatthias Ringwald            with open (bts_file, 'rb') as fin:
140d5814ca7SMatthias Ringwald
141f55dd2adSMatthias Ringwald                print("- parsing {0:32}".format(bts_file))
142d5814ca7SMatthias Ringwald
143d5814ca7SMatthias Ringwald                header = fin.read(32)
144f55dd2adSMatthias Ringwald                if header[0:4].decode('ascii') != 'BTSB':
145f55dd2adSMatthias Ringwald                    print('Error', bts_file, 'is not a valid .BTS file')
146d5814ca7SMatthias Ringwald                    sys.exit(1)
147d5814ca7SMatthias Ringwald
148d5814ca7SMatthias Ringwald
149d5814ca7SMatthias Ringwald                while True:
150d5814ca7SMatthias Ringwald                    action_type = read_little_endian_16(fin)
151d5814ca7SMatthias Ringwald                    action_size = read_little_endian_16(fin)
152f55dd2adSMatthias Ringwald                    action_data = bytearray(fin.read(action_size))
153d5814ca7SMatthias Ringwald
154d5814ca7SMatthias Ringwald                    if (action_type == 1):  # hci command
155d5814ca7SMatthias Ringwald
156f55dd2adSMatthias Ringwald                        opcode = (action_data[2] << 8) | action_data[1]
157d5814ca7SMatthias Ringwald                        if opcode == 0xFF36:
158d5814ca7SMatthias Ringwald                            continue    # skip baud rate command
159d5814ca7SMatthias Ringwald                        if opcode == 0xFD0C:
160d5814ca7SMatthias Ringwald                            have_eHCILL = True
161d5814ca7SMatthias Ringwald                        if opcode == 0xFD82:
162a3fe55ccSMatthias Ringwald                            modulation_type = action_data[4]
163d5814ca7SMatthias Ringwald                            if modulation_type == 0:
164d5814ca7SMatthias Ringwald                                have_power_vector_gfsk = True
165d5814ca7SMatthias Ringwald                            elif modulation_type == 1:
166d5814ca7SMatthias Ringwald                                have_power_vector_edr2 + True
167d5814ca7SMatthias Ringwald                            elif modulation_type == 2:
168d5814ca7SMatthias Ringwald                                have_power_vector_edr3 = True
169d5814ca7SMatthias Ringwald                        if opcode == 0xFD80:
170d5814ca7SMatthias Ringwald                            # add missing power command templates
171d5814ca7SMatthias Ringwald                            if not have_power_vector_gfsk:
172d5814ca7SMatthias Ringwald                                part_size += append_power_vector_gfsk(additions, str_list, data_indent)
173d5814ca7SMatthias Ringwald                                have_power_vector_gfsk = True;
174d5814ca7SMatthias Ringwald                            if not have_power_vector_edr2:
175d5814ca7SMatthias Ringwald                                part_size += append_power_vector_edr2(additions, str_list, data_indent)
176d5814ca7SMatthias Ringwald                                have_power_vector_edr2 = True;
177d5814ca7SMatthias Ringwald                            if not have_power_vector_edr3:
1783342e387SMatthias Ringwald                                part_size += append_power_vector_edr3(additions, str_list, data_indent)
179d5814ca7SMatthias Ringwald                                have_power_vector_edr3 = True;
180d5814ca7SMatthias Ringwald                            if not have_class2_single_power:
181d5814ca7SMatthias Ringwald                                part_size += append_class2_single_power(additions, str_list, data_indent)
182d5814ca7SMatthias Ringwald                                have_class2_single_power = True;
183d5814ca7SMatthias Ringwald
184d5814ca7SMatthias Ringwald                        counter = 0
185d5814ca7SMatthias Ringwald                        str_list.append(data_indent)
186d5814ca7SMatthias Ringwald                        for byte in action_data:
187f55dd2adSMatthias Ringwald                            str_list.append("0x{0:02x}, ".format(byte))
188d5814ca7SMatthias Ringwald                            counter = counter + 1
189d5814ca7SMatthias Ringwald                            if (counter != 15):
190d5814ca7SMatthias Ringwald                                continue
191d5814ca7SMatthias Ringwald                            counter = 0
192d5814ca7SMatthias Ringwald                            str_list.append("\n")
193d5814ca7SMatthias Ringwald                            str_list.append(data_indent)
194d5814ca7SMatthias Ringwald                        str_list.append("\n\n")
195d5814ca7SMatthias Ringwald
196d5814ca7SMatthias Ringwald                        part_size = part_size + action_size
197d5814ca7SMatthias Ringwald
198d5814ca7SMatthias Ringwald                        # 30 kB chunks
199d5814ca7SMatthias Ringwald                        if part_size < 30 * 1024:
200d5814ca7SMatthias Ringwald                            continue
201d5814ca7SMatthias Ringwald
202d5814ca7SMatthias Ringwald                        part_strings.append(''.join(str_list))
203d5814ca7SMatthias Ringwald                        part_sizes.append(part_size)
204d5814ca7SMatthias Ringwald                        parts += 1
205d5814ca7SMatthias Ringwald
206d5814ca7SMatthias Ringwald                        str_list = []
207d5814ca7SMatthias Ringwald                        part_size = 0
208d5814ca7SMatthias Ringwald
209d5814ca7SMatthias Ringwald                    if (action_type == 6):  # comment
210f55dd2adSMatthias Ringwald                        action_data = action_data.decode('ascii').rstrip('\0')
211d5814ca7SMatthias Ringwald                        str_list.append(data_indent)
212d5814ca7SMatthias Ringwald                        str_list.append("// " + action_data + "\n")
213d5814ca7SMatthias Ringwald
214d5814ca7SMatthias Ringwald                    if (action_type < 0):   # EOF
215d5814ca7SMatthias Ringwald                        break;
216d5814ca7SMatthias Ringwald
217d5814ca7SMatthias Ringwald
218d5814ca7SMatthias Ringwald        if not have_eHCILL:
219d5814ca7SMatthias Ringwald            part_size += append_ehcill(additions, str_list, data_indent)
220d5814ca7SMatthias Ringwald
221d5814ca7SMatthias Ringwald        # append calibration step, if missing so far
222d5814ca7SMatthias Ringwald        all_power_commands_provided = have_power_vector_gfsk and have_power_vector_edr2 and have_power_vector_edr3 and have_class2_single_power
223d5814ca7SMatthias Ringwald        if not all_power_commands_provided:
224d5814ca7SMatthias Ringwald            str_list.append("\n" + data_indent + "// BTstack: no calibration sequence found, adding power commands and calibration\n\n")
225d5814ca7SMatthias Ringwald            part_size += append_power_vector_gfsk(additions, str_list, data_indent)
226d5814ca7SMatthias Ringwald            part_size += append_power_vector_edr2(additions, str_list, data_indent)
22788aeaf6cSMatthias Ringwald            part_size += append_power_vector_edr3(additions, str_list, data_indent)
228d5814ca7SMatthias Ringwald            part_size += append_class2_single_power(additions, str_list, data_indent)
229d5814ca7SMatthias Ringwald            part_size += append_calibration_sequence(additions, str_list, data_indent)
230d5814ca7SMatthias Ringwald
231d5814ca7SMatthias Ringwald        part_strings.append(''.join(str_list))
232d5814ca7SMatthias Ringwald        part_sizes.append(part_size)
233d5814ca7SMatthias Ringwald        parts += 1
234d5814ca7SMatthias Ringwald
235d5814ca7SMatthias Ringwald        fout.write( '// init script created from\n')
236d5814ca7SMatthias Ringwald        fout.write( '// - {0}\n'.format(main_bts_file))
2376ab4420aSMatthias Ringwald        if aka != "":
2386ab4420aSMatthias Ringwald            fout.write( '// - AKA TIInit_{0}.bts\n'.format(aka))
239d5814ca7SMatthias Ringwald        if bts_add_on != "":
240d5814ca7SMatthias Ringwald            fout.write( '// - {0}\n'.format(bts_add_on))
241d5814ca7SMatthias Ringwald        fout.write( '#include <stdint.h>\n')
2428084ae4aSMatthias Ringwald        fout.write( '#include "btstack_chipset_cc256x.h"\n')
2436ab4420aSMatthias Ringwald        fout.write( '\n')
2446ab4420aSMatthias Ringwald        # if aka != "":
2456ab4420aSMatthias Ringwald        #     fout.write( 'const char * {0}_init_script_aka = "{1}";\n'.format(array_name, aka))
24673ff2b1cSMatthias Ringwald        if lmp_subversion != 0:
247ed5d91baSMatthias Ringwald            fout.write( get_lmp_subversion.format(prefix = array_name, lmp_subversion = "0x%04x" % lmp_subversion))
248d5814ca7SMatthias Ringwald        part = 0
249d5814ca7SMatthias Ringwald        size = 0
250d5814ca7SMatthias Ringwald        for part_size in part_sizes:
251d5814ca7SMatthias Ringwald            part += 1
252d5814ca7SMatthias Ringwald            size += part_size
25369316fe8SMatthias Ringwald            print("- part %u, size %u" % (part,part_size))
254d5814ca7SMatthias Ringwald
25569316fe8SMatthias Ringwald        print('- total size %u' % size)
256d5814ca7SMatthias Ringwald
257f55dd2adSMatthias Ringwald        print("\n".join(additions))
258d5814ca7SMatthias Ringwald
259d5814ca7SMatthias Ringwald
260d5814ca7SMatthias Ringwald        part = 0
261d5814ca7SMatthias Ringwald        for part_text in part_strings:
262d5814ca7SMatthias Ringwald            part += 1
263d5814ca7SMatthias Ringwald            suffix = ''
264d5814ca7SMatthias Ringwald
265d5814ca7SMatthias Ringwald            if part == 1:
266d5814ca7SMatthias Ringwald                fout.write( fartext )
267d5814ca7SMatthias Ringwald
268d5814ca7SMatthias Ringwald            if (part > 1):
269d5814ca7SMatthias Ringwald                suffix = '_{0}'.format(part)
270d5814ca7SMatthias Ringwald                fout.write('#if defined(__GNUC__) && defined(__GNUC__) && (__MSP430X__ > 0)\n')
271d5814ca7SMatthias Ringwald                fout.write('};\n')
272d5814ca7SMatthias Ringwald                fout.write('__attribute__((section (".fartext")))\n')
273d5814ca7SMatthias Ringwald
274d5814ca7SMatthias Ringwald            fout.write('const uint8_t {0}_init_script{1}[] = {2}\n\n'.format(array_name, suffix, '{'))
275d5814ca7SMatthias Ringwald
276d5814ca7SMatthias Ringwald            if (part > 1):
277d5814ca7SMatthias Ringwald                fout.write('#endif\n')
278d5814ca7SMatthias Ringwald
279d5814ca7SMatthias Ringwald            fout.write(part_text)
280d5814ca7SMatthias Ringwald
281d5814ca7SMatthias Ringwald
282d5814ca7SMatthias Ringwald        fout.write('};\n\n')
283d5814ca7SMatthias Ringwald
284*58026f5aSMatthias Ringwald        fout.write('const uint32_t {0}_init_script_size = sizeof({0}_init_script); // size = {1} bytes\n\n'.format(array_name,size));
285d5814ca7SMatthias Ringwald
28606ee659aSMatthias Ringwald# check usage: 2-3 param
28706ee659aSMatthias Ringwaldif len(sys.argv) < 3 or len(sys.argv) > 4:
288f55dd2adSMatthias Ringwald    print(usage)
289d5814ca7SMatthias Ringwald    sys.exit(1)
290d5814ca7SMatthias Ringwald
29106ee659aSMatthias Ringwaldmain_bts = sys.argv[1]
29206ee659aSMatthias Ringwaldadd_on = ""
29306ee659aSMatthias Ringwaldif len(sys.argv) == 4:
29406ee659aSMatthias Ringwald    add_on = sys.argv[2]
29506ee659aSMatthias Ringwaldoutput_file = sys.argv[-1]
296d5814ca7SMatthias Ringwald
297ed5d91baSMatthias Ringwald# get AKA from file names that include model name
2986ab4420aSMatthias Ringwaldaka = ""
2996ab4420aSMatthias Ringwaldlmp_subversion = 0
30006ee659aSMatthias Ringwaldname_lower = main_bts.lower()
30106ee659aSMatthias Ringwaldif 'cc2560_' in name_lower:
3026ab4420aSMatthias Ringwald    aka = "6.2.31"
3030e1ffed0SMatthias Ringwaldif 'cc2560a_' in name_lower or 'cc2564_' in name_lower or 'cc2567_' in name_lower:
3046ab4420aSMatthias Ringwald    aka = "6.6.15"
30506ee659aSMatthias Ringwaldif 'cc2560b_' in name_lower or 'cc2564b_' in name_lower:
3066ab4420aSMatthias Ringwald    aka = "6.7.16"
30706ee659aSMatthias Ringwaldif 'cc2564c_' in name_lower:
3086ab4420aSMatthias Ringwald    aka = "6.12.26"
3096ab4420aSMatthias Ringwald
3100e1ffed0SMatthias Ringwald# hardcode AKA for CC2567 v2.8
3110e1ffed0SMatthias Ringwaldif 'cc256x_bt_service_pack_2.8_ant_1.16' in name_lower:
3120e1ffed0SMatthias Ringwald    aka = "6.6.15"
3130e1ffed0SMatthias Ringwald
31406ee659aSMatthias Ringwald# use AKA from .bts file that it
31506ee659aSMatthias Ringwaldname_parts = re.match('.*TIInit_(\d*\.\d*\.\d*).*.bts', main_bts)
316edc52946SMatthias Ringwaldif name_parts:
3176ab4420aSMatthias Ringwald    aka = name_parts.group(1)
318edc52946SMatthias Ringwald
3191a26f7a4SMatthias Ringwald# calculate subversion from AKA "CHIP.MAJ.MIN"
3201a26f7a4SMatthias Ringwald# lmp scheme: ABBB BBCC CDDD DDDD
3211a26f7a4SMatthias Ringwald# - chip = BBB
3221a26f7a4SMatthias Ringwald# - maj  = ACCC
3231a26f7a4SMatthias Ringwald# - min  = DDDD DDD
3241a26f7a4SMatthias Ringwaldif len(aka) > 0:
3251a26f7a4SMatthias Ringwald    nums = aka.split('.')
3261a26f7a4SMatthias Ringwald    chip     = int(nums[0])
3271a26f7a4SMatthias Ringwald    maj_ver  = int(nums[1])
3281a26f7a4SMatthias Ringwald    min_ver  = int(nums[2])
3291a26f7a4SMatthias Ringwald    lmp_subversion = ((maj_ver & 0x08) << 12) | (chip << 10) | ((maj_ver & 0x07) << 7) | min_ver
330ed5d91baSMatthias Ringwald
331ed5d91baSMatthias Ringwald# print summary
33206ee659aSMatthias Ringwaldprint ("Main file: %s"% main_bts)
33306ee659aSMatthias Ringwaldif add_on != "":
33406ee659aSMatthias Ringwald    print ("Add-on file: %s" % add_on)
3356ab4420aSMatthias Ringwaldif aka != "":
3366ab4420aSMatthias Ringwald    print ("- AKA TIInit_%s.bts" % aka)
3376ab4420aSMatthias Ringwald
33873ff2b1cSMatthias Ringwaldif lmp_subversion:
33973ff2b1cSMatthias Ringwald    print ("- LMP Subversion: 0x%04x" % lmp_subversion)
34073ff2b1cSMatthias Ringwaldelse:
34173ff2b1cSMatthias Ringwald    print ("- LMP Subversion: Unknown")
34273ff2b1cSMatthias Ringwald
34306ee659aSMatthias Ringwaldconvert_bts(output_file, main_bts, add_on, aka, lmp_subversion)
34469316fe8SMatthias Ringwaldprint
345d5814ca7SMatthias Ringwald
346d5814ca7SMatthias Ringwald
347d5814ca7SMatthias Ringwald
348