summaryrefslogtreecommitdiff
path: root/package/mac80211/files/host_bin/b43-fwsquash.py
blob: 088ed484500c823da04a0fa6b5a059361bb41edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
#
# b43 firmware file squasher
# Removes unnecessary firmware files
#
# Copyright (c) 2009 Michael Buesch <mb@bu3sch.de>
#
# Licensed under the GNU/GPL version 2 or (at your option) any later version.
#

import sys
import os

def usage():
	print "Usage: %s PHYTYPES COREREVS /path/to/extracted/firmware" % sys.argv[0]
	print ""
	print "PHYTYPES is a comma separated list of:"
	print "A         => A-PHY"
	print "AG        => Dual A-PHY G-PHY"
	print "G         => G-PHY"
	print "LP        => LP-PHY"
	print "N         => N-PHY"
	print ""
	print "COREREVS is a comma separated list of core revision numbers."

if len(sys.argv) != 4:
	usage()
	sys.exit(1)

phytypes = sys.argv[1]
corerevs = sys.argv[2]
fwpath = sys.argv[3]

phytypes = phytypes.split(',')
try:
	corerevs = map(lambda r: int(r), corerevs.split(','))
except ValueError:
	print "ERROR: \"%s\" is not a valid COREREVS string\n" % corerevs
	usage()
	sys.exit(1)


fwfiles = os.listdir(fwpath)
fwfiles = filter(lambda str: str.endswith(".fw"), fwfiles)
if not fwfiles:
	print "ERROR: No firmware files found in %s" % fwpath
	sys.exit(1)

required_fwfiles = []

def revs_match(revs_a, revs_b):
	for rev in revs_a:
		if rev in revs_b:
			return True
	return False

def phytypes_match(types_a, types_b):
	for type in types_a:
		type = type.strip().upper()
		if type in types_b:
			return True
	return False

revmapping = {
	"ucode5.fw"		: (5,6,7,8,9,10,),
	"ucode11.fw"		: (11,12,),
	"ucode13.fw"		: (13,),
	"ucode14.fw"		: (14,),
	"ucode15.fw"		: (15,),
	"pcm5.fw"		: (5,6,7,8,9,10,),
}

initvalmapping = {
	"a0g1initvals5.fw"	: ( (5,6,7,8,9,10,),	("AG",), ),
	"a0g0initvals5.fw"	: ( (5,6,7,8,9,10,),	("A", "AG",), ),
	"b0g0initvals5.fw"	: ( (5,6,7,8,9,10,),	("G",), ),
	"b0g0initvals13.fw"	: ( (13,),		("G",), ),
	"n0initvals11.fw"	: ( (11,12,),		("N",), ),
	"lp0initvals13.fw"	: ( (13,),		("LP",), ),
	"lp0initvals14.fw"	: ( (14,),		("LP",), ),
	"lp0initvals15.fw"	: ( (15,),		("LP",), ),
	"a0g1bsinitvals5.fw"	: ( (5,6,7,8,9,10,),	("AG",), ),
	"a0g0bsinitvals5.fw"	: ( (5,6,7,8,9,10,),	("A", "AG"), ),
	"b0g0bsinitvals5.fw"	: ( (5,6,7,8,9,10,),	("G",), ),
	"n0bsinitvals11.fw"	: ( (11,12,),		("N",), ),
	"lp0bsinitvals13.fw"	: ( (13,),		("LP",), ),
	"lp0bsinitvals14.fw"	: ( (14,),		("LP",), ),
	"lp0bsinitvals15.fw"	: ( (15,),		("LP",), ),
}

for f in fwfiles:
	if f in revmapping:
		if revs_match(corerevs, revmapping[f]):
			required_fwfiles += [f]
		continue
	if f in initvalmapping:
		if revs_match(corerevs, initvalmapping[f][0]) and\
		   phytypes_match(phytypes, initvalmapping[f][1]):
			required_fwfiles += [f]
		continue
	print "WARNING: Firmware file %s not found in the mapping lists" % f

for f in fwfiles:
	if f not in required_fwfiles:
		print "Deleting %s" % f
		os.unlink(fwpath + '/' + f)