mac80211: fix spacing
[openwrt/svn-archive/archive.git] / package / mac80211 / files / host_bin / 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("")
26 print("COREREVS is a comma separated list of core revision numbers.")
27
28 if len(sys.argv) != 4:
29 usage()
30 sys.exit(1)
31
32 phytypes = sys.argv[1]
33 corerevs = sys.argv[2]
34 fwpath = sys.argv[3]
35
36 phytypes = phytypes.split(',')
37 try:
38 corerevs = map(lambda r: int(r), corerevs.split(','))
39 except ValueError:
40 print("ERROR: \"%s\" is not a valid COREREVS string\n" % corerevs)
41 usage()
42 sys.exit(1)
43
44
45 fwfiles = os.listdir(fwpath)
46 fwfiles = filter(lambda str: str.endswith(".fw"), fwfiles)
47 if not fwfiles:
48 print("ERROR: No firmware files found in %s" % fwpath)
49 sys.exit(1)
50
51 required_fwfiles = []
52
53 def revs_match(revs_a, revs_b):
54 for rev in revs_a:
55 if rev in revs_b:
56 return True
57 return False
58
59 def phytypes_match(types_a, types_b):
60 for type in types_a:
61 type = type.strip().upper()
62 if type in types_b:
63 return True
64 return False
65
66 revmapping = {
67 "ucode2.fw" : (2,3,),
68 "ucode4.fw" : (4,),
69 "ucode5.fw" : (5,6,7,8,9,10,),
70 "ucode11.fw" : (11,12,),
71 "ucode13.fw" : (13,),
72 "ucode14.fw" : (14,),
73 "ucode15.fw" : (15,),
74 "ucode16_mimo.fw" : (16,),
75 "ucode24_mimo.fw" : (24,),
76 "ucode29_mimo.fw" : (29,),
77 "pcm4.fw" : (1,2,3,4,),
78 "pcm5.fw" : (5,6,7,8,9,10,),
79 }
80
81 initvalmapping = {
82 "a0g1initvals5.fw" : ( (5,6,7,8,9,10,), ("AG",), ),
83 "a0g0initvals5.fw" : ( (5,6,7,8,9,10,), ("A", "AG",), ),
84 "b0g0initvals2.fw" : ( (2,4,), ("G",), ),
85 "b0g0initvals5.fw" : ( (5,6,7,8,9,10,), ("G",), ),
86 "b0g0initvals13.fw" : ( (13,), ("G",), ),
87 "n0initvals11.fw" : ( (11,12,), ("N",), ),
88 "n0initvals16.fw" : ( (16,), ("N",), ),
89 "lp0initvals13.fw" : ( (13,), ("LP",), ),
90 "lp0initvals14.fw" : ( (14,), ("LP",), ),
91 "lp0initvals15.fw" : ( (15,), ("LP",), ),
92 "lcn0initvals24.fw" : ( (24,), ("LCN",), ),
93 "ht0initvals29.fw" : ( (29,), ("HT",), ),
94 "a0g1bsinitvals5.fw" : ( (5,6,7,8,9,10,), ("AG",), ),
95 "a0g0bsinitvals5.fw" : ( (5,6,7,8,9,10,), ("A", "AG"), ),
96 "b0g0bsinitvals5.fw" : ( (5,6,7,8,9,10,), ("G",), ),
97 "n0bsinitvals11.fw" : ( (11,12,), ("N",), ),
98 "n0bsinitvals16.fw" : ( (16,), ("N",), ),
99 "lp0bsinitvals13.fw" : ( (13,), ("LP",), ),
100 "lp0bsinitvals14.fw" : ( (14,), ("LP",), ),
101 "lp0bsinitvals15.fw" : ( (15,), ("LP",), ),
102 "lcn0bsinitvals24.fw" : ( (24,), ("LCN",), ),
103 "ht0bsinitvals29.fw" : ( (29,), ("HT",), ),
104 }
105
106 for f in fwfiles:
107 if f in revmapping:
108 if revs_match(corerevs, revmapping[f]):
109 required_fwfiles += [f]
110 continue
111 if f in initvalmapping:
112 if revs_match(corerevs, initvalmapping[f][0]) and\
113 phytypes_match(phytypes, initvalmapping[f][1]):
114 required_fwfiles += [f]
115 continue
116 print("WARNING: Firmware file %s not found in the mapping lists" % f)
117
118 for f in fwfiles:
119 if f not in required_fwfiles:
120 print("Deleting %s" % f)
121 os.unlink(fwpath + '/' + f)
122