b43-fwsquash.py 4.7 KB

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