fwcutter: Add unique firmware IDs
[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 typedef uint16_t be16_t; /* Big-endian 16bit */
13 typedef uint32_t be32_t; /* Big-endian 32bit */
14
15 #ifdef __DragonFly__
16 #define bswap_16        bswap16
17 #define bswap_32        bswap32
18 #endif
19
20 #define ARG_MATCH       0
21 #define ARG_NOMATCH     1
22 #define ARG_ERROR       -1
23
24 enum fwcutter_mode {
25         FWCM_EXTRACT = 0,       /* default */
26         FWCM_LIST,
27         FWCM_IDENTIFY,
28 };
29
30 struct cmdline_args {
31         const char *infile;
32         const char *target_dir;
33         enum fwcutter_mode mode;
34         int unsupported;
35 };
36
37 struct insn {
38         uint32_t opcode;
39         uint16_t op1, op2, op3;
40 };
41
42 /* The IV how it's done in the binary driver files. */
43 struct iv {
44         be16_t reg, size;
45         be32_t val;
46 } __attribute__((__packed__));
47
48 enum extract_type {
49         EXT_UNDEFINED, /* error catcher  */
50         EXT_UCODE_1,   /* rev  <= 4 ucode */
51         EXT_UCODE_2,   /* rev 5..14 ucode */
52         EXT_UCODE_3,   /* rev >= 15 ucode */
53         EXT_PCM,       /* "pcm" values   */
54         EXT_IV,        /* initial values */
55 };
56
57 struct extract {
58         const char *name;
59         const uint32_t offset;
60         const uint32_t length;
61         const enum extract_type type;
62 };
63
64 #define EXTRACT_LIST_END { .name = NULL, }
65
66 struct file {
67         const char *name;
68         const char *id;
69         const char *ucode_version;
70         const char *md5;
71         const struct extract *extract;
72         const uint32_t flags;
73 };
74
75 /* The header that's put in to every .fw file */
76 struct fw_header {
77         /* Type of the firmware data */
78         uint8_t type;
79         /* Version number of the firmware data format */
80         uint8_t ver;
81         uint8_t __padding[2];
82         /* Size of the data. For ucode and PCM this is in bytes.
83          * For IV this is in number-of-ivs. */
84         be32_t size;
85 } __attribute__((__packed__));
86
87 #define FW_TYPE_UCODE   'u'
88 #define FW_TYPE_PCM     'p'
89 #define FW_TYPE_IV      'i'
90
91 #define FW_HDR_VER      0x01
92
93 /* The IV in the .fw file */
94 struct b43_iv {
95         be16_t offset_size;
96         union {
97                 be16_t d16;
98                 be32_t d32;
99         } data __attribute__((__packed__));
100 } __attribute__((__packed__));
101
102 #define FW_IV_OFFSET_MASK       0x7FFF
103 #define FW_IV_32BIT             0x8000
104
105
106 #endif /* _FWCUTTER_H_ */