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