fwcutter.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef _FWCUTTER_H_
  2. #define _FWCUTTER_H_
  3. #define FW_FLAG_LE 0x01 /* little endian? convert */
  4. #define FW_FLAG_V4 0x02 /* b43 vs. b43legacy */
  5. #define FW_FLAG_UNSUPPORTED 0x04 /* not supported/working */
  6. #define fwcutter_stringify_1(x) #x
  7. #define fwcutter_stringify(x) fwcutter_stringify_1(x)
  8. #define FWCUTTER_VERSION fwcutter_stringify(FWCUTTER_VERSION_)
  9. #undef ARRAY_SIZE
  10. #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
  11. typedef uint16_t be16_t; /* Big-endian 16bit */
  12. typedef uint32_t be32_t; /* Big-endian 32bit */
  13. typedef uint32_t le32_t; /* Little-endian 32bit */
  14. #if defined(__DragonFly__) || defined(__FreeBSD__)
  15. #define bswap_16 bswap16
  16. #define bswap_32 bswap32
  17. #elif defined(__APPLE__)
  18. #define bswap_16 OSSwapInt16
  19. #define bswap_32 OSSwapInt32
  20. #endif
  21. #define ARG_MATCH 0
  22. #define ARG_NOMATCH 1
  23. #define ARG_ERROR -1
  24. enum fwcutter_mode {
  25. FWCM_EXTRACT_B43 = 0, /* default */
  26. FWCM_LIST,
  27. FWCM_IDENTIFY,
  28. FWCM_EXTRACT_BRCMSMAC,
  29. };
  30. struct cmdline_args {
  31. const char *infile;
  32. const char *target_dir;
  33. enum fwcutter_mode mode;
  34. int unsupported;
  35. };
  36. struct insn {
  37. uint32_t opcode;
  38. uint16_t op1, op2, op3;
  39. };
  40. /* The IV how it's done in the binary driver files. */
  41. struct iv {
  42. be16_t reg, size;
  43. be32_t val;
  44. } __attribute__((__packed__));
  45. enum extract_type {
  46. EXT_UNDEFINED, /* error catcher */
  47. EXT_UCODE_1, /* rev <= 4 ucode */
  48. EXT_UCODE_2, /* rev 5..14 ucode */
  49. EXT_UCODE_3, /* rev >= 15 ucode */
  50. EXT_PCM, /* "pcm" values */
  51. EXT_IV, /* initial values */
  52. };
  53. struct extract {
  54. const char *name;
  55. const uint32_t offset;
  56. const uint32_t length;
  57. const enum extract_type type;
  58. };
  59. #define EXTRACT_LIST_END { .name = NULL, }
  60. struct file {
  61. const char *name;
  62. const char *ucode_version;
  63. const char *md5;
  64. const struct extract *extract;
  65. const uint32_t flags;
  66. };
  67. /* The header that's put in to every .fw file */
  68. struct fw_header {
  69. /* Type of the firmware data */
  70. uint8_t type;
  71. /* Version number of the firmware data format */
  72. uint8_t ver;
  73. uint8_t __padding[2];
  74. /* Size of the data. For ucode and PCM this is in bytes.
  75. * For IV this is in number-of-ivs. */
  76. be32_t size;
  77. } __attribute__((__packed__));
  78. #define FW_TYPE_UCODE 'u'
  79. #define FW_TYPE_PCM 'p'
  80. #define FW_TYPE_IV 'i'
  81. #define FW_HDR_VER 0x01
  82. /* The IV in the .fw file */
  83. struct b43_iv {
  84. be16_t offset_size;
  85. union {
  86. be16_t d16;
  87. be32_t d32;
  88. } data __attribute__((__packed__));
  89. } __attribute__((__packed__));
  90. #define FW_IV_OFFSET_MASK 0x7FFF
  91. #define FW_IV_32BIT 0x8000
  92. /* header format for brcmsmac firmware */
  93. struct firmware_hdr {
  94. le32_t offset;
  95. le32_t len;
  96. le32_t idx;
  97. };
  98. /* numbers of firmware types for brcmsmac firmware */
  99. enum firmware_brcmsmac {
  100. D11UCODE_NAMETAG_START = 0,
  101. D11LCN0BSINITVALS24,
  102. D11LCN0INITVALS24,
  103. D11LCN1BSINITVALS24,
  104. D11LCN1INITVALS24,
  105. D11LCN2BSINITVALS24,
  106. D11LCN2INITVALS24,
  107. D11N0ABSINITVALS16,
  108. D11N0BSINITVALS16,
  109. D11N0INITVALS16,
  110. D11UCODE_OVERSIGHT16_MIMO,
  111. D11UCODE_OVERSIGHT16_MIMOSZ,
  112. D11UCODE_OVERSIGHT24_LCN,
  113. D11UCODE_OVERSIGHT24_LCNSZ,
  114. D11UCODE_OVERSIGHT_BOMMAJOR,
  115. D11UCODE_OVERSIGHT_BOMMINOR
  116. };
  117. #endif /* _FWCUTTER_H_ */