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