b43-tools: b43-fwsquash.py: manually remove LP-PHY 16 support
[openwrt/staging/chunkeey.git] / tools / b43-tools / files / b43-fwsquash.py
1 #!/usr/bin/env python
2 #
3 # b43 firmware file squasher
4 # Removes unnecessary firmware files
5 #
6 # Copyright (c) 2009 Michael Buesch <mb@bu3sch.de>
7 #
8 # Licensed under the GNU/GPL version 2 or (at your option) any later version.
9 #
10
11 import sys
12 import os
13
14 def usage():
15 print("Usage: %s PHYTYPES COREREVS /path/to/extracted/firmware" % sys.argv[0])
16 print("")
17 print("PHYTYPES is a comma separated list of:")
18 print("A => A-PHY")
19 print("AG => Dual A-PHY G-PHY")
20 print("G => G-PHY")
21 print("LP => LP-PHY")
22 print("N => N-PHY")
23 print("HT => HT-PHY")
24 print("LCN => LCN-PHY")
25 print("LCN40 => LCN40-PHY")
26 print("AC => AC-PHY")
27 print("")
28 print("COREREVS is a comma separated list of core revision numbers.")
29
30 if len(sys.argv) != 4:
31 usage()
32 sys.exit(1)
33
34 phytypes = sys.argv[1]
35 corerevs = sys.argv[2]
36 fwpath = sys.argv[3]
37
38 phytypes = phytypes.split(',')
39 try:
40 corerevs = map(lambda r: int(r), corerevs.split(','))
41 except ValueError:
42 print("ERROR: \"%s\" is not a valid COREREVS string\n" % corerevs)
43 usage()
44 sys.exit(1)
45
46
47 fwfiles = os.listdir(fwpath)
48 fwfiles = filter(lambda str: str.endswith(".fw"), fwfiles)
49 if not fwfiles:
50 print("ERROR: No firmware files found in %s" % fwpath)
51 sys.exit(1)
52
53 required_fwfiles = []
54
55 def revs_match(revs_a, revs_b):
56 for rev in revs_a:
57 if rev in revs_b:
58 return True
59 return False
60
61 def phytypes_match(types_a, types_b):
62 for type in types_a:
63 type = type.strip().upper()
64 if type in types_b:
65 return True
66 return False
67
68 revmapping = {
69 "ucode2.fw" : ( (2,3,), ("G",), ),
70 "ucode4.fw" : ( (4,), ("G",), ),
71 "ucode5.fw" : ( (5,6,7,8,9,10,), ("G","A","AG",), ),
72 "ucode11.fw" : ( (11,12,), ("N",), ),
73 "ucode13.fw" : ( (13,), ("LP","G",), ),
74 "ucode14.fw" : ( (14,), ("LP",), ),
75 "ucode15.fw" : ( (15,), ("LP",), ),
76 "ucode16_mimo.fw" : ( (16,17,18,19,23,), ("N",), ),
77 # "ucode16_lp.fw" : ( (16,17,18,19,), ("LP",), ),
78 "ucode24_lcn.fw" : ( (24,), ("LCN",), ),
79 "ucode25_mimo.fw" : ( (25,28,), ("N",), ),
80 "ucode25_lcn.fw" : ( (25,28,), ("LCN",), ),
81 "ucode26_mimo.fw" : ( (26,), ("HT",), ),
82 "ucode29_mimo.fw" : ( (29,), ("HT",), ),
83 "ucode30_mimo.fw" : ( (30,), ("N",), ),
84 "ucode33_lcn40.fw" : ( (33,), ("LCN40",), ),
85 "ucode40.fw" : ( (40,), ("AC",), ),
86 "ucode42.fw" : ( (42,), ("AC",), ),
87 "pcm4.fw" : ( (1,2,3,4,), ("G",), ),
88 "pcm5.fw" : ( (5,6,7,8,9,10,), ("G","A","AG",), ),
89 }
90
91 initvalmapping = {
92 "a0g1initvals5.fw" : ( (5,6,7,8,9,10,), ("AG",), ),
93 "a0g0initvals5.fw" : ( (5,6,7,8,9,10,), ("A", "AG",), ),
94 "b0g0initvals2.fw" : ( (2,4,), ("G",), ),
95 "b0g0initvals5.fw" : ( (5,6,7,8,9,10,), ("G",), ),
96 "b0g0initvals13.fw" : ( (13,), ("G",), ),
97 "n0initvals11.fw" : ( (11,12,), ("N",), ),
98 "n0initvals16.fw" : ( (16,17,18,23,), ("N",), ),
99 "n0initvals24.fw" : ( (24,), ("N",), ),
100 "n0initvals25.fw" : ( (25,28,), ("N",), ),
101 "n16initvals30.fw" : ( (30,), ("N",), ),
102 "lp0initvals13.fw" : ( (13,), ("LP",), ),
103 "lp0initvals14.fw" : ( (14,), ("LP",), ),
104 "lp0initvals15.fw" : ( (15,), ("LP",), ),
105 # "lp0initvals16.fw" : ( (16,17,18,), ("LP",), ),
106 "lcn0initvals24.fw" : ( (24,), ("LCN",), ),
107 "ht0initvals26.fw" : ( (26,), ("HT",), ),
108 "ht0initvals29.fw" : ( (29,), ("HT",), ),
109 "lcn400initvals33.fw" : ( (33,), ("LCN40",), ),
110 "ac0initvals40.fw" : ( (40,), ("AC",), ),
111 "ac1initvals42.fw" : ( (42,), ("AC",), ),
112 "a0g1bsinitvals5.fw" : ( (5,6,7,8,9,10,), ("AG",), ),
113 "a0g0bsinitvals5.fw" : ( (5,6,7,8,9,10,), ("A", "AG"), ),
114 "b0g0bsinitvals5.fw" : ( (5,6,7,8,9,10,), ("G",), ),
115 "n0bsinitvals11.fw" : ( (11,12,), ("N",), ),
116 "n0bsinitvals16.fw" : ( (16,17,18,23,), ("N",), ),
117 "n0bsinitvals24.fw" : ( (24,), ("N",), ),
118 "n0bsinitvals25.fw" : ( (25,28,), ("N",), ),
119 "n16bsinitvals30.fw" : ( (30,), ("N",), ),
120 "lp0bsinitvals13.fw" : ( (13,), ("LP",), ),
121 "lp0bsinitvals14.fw" : ( (14,), ("LP",), ),
122 "lp0bsinitvals15.fw" : ( (15,), ("LP",), ),
123 # "lp0bsinitvals16.fw" : ( (16,17,18,), ("LP",), ),
124 "lcn0bsinitvals24.fw" : ( (24,), ("LCN",), ),
125 "ht0bsinitvals26.fw" : ( (26,), ("HT",), ),
126 "ht0bsinitvals29.fw" : ( (29,), ("HT",), ),
127 "lcn400bsinitvals33.fw" : ( (33,), ("LCN40",), ),
128 "ac0bsinitvals40.fw" : ( (40,), ("AC",), ),
129 "ac1bsinitvals42.fw" : ( (42,), ("AC",), ),
130 }
131
132 for f in fwfiles:
133 if f in revmapping:
134 if revs_match(corerevs, revmapping[f][0]) and\
135 phytypes_match(phytypes, revmapping[f][1]):
136 required_fwfiles += [f]
137 continue
138 if f in initvalmapping:
139 if revs_match(corerevs, initvalmapping[f][0]) and\
140 phytypes_match(phytypes, initvalmapping[f][1]):
141 required_fwfiles += [f]
142 continue
143 print("WARNING: Firmware file %s not found in the mapping lists" % f)
144
145 for f in fwfiles:
146 if f not in required_fwfiles:
147 print("Deleting %s" % f)
148 os.unlink(fwpath + '/' + f)
149