3 Broadcom Sonics Silicon Backplane bus SPROM data modification tool
5 Copyright (c) 2006-2008 Michael Buesch <mb@bu3sch.de>
6 Copyright (c) 2008 Larry Finger <Larry.Finger@lwfinger.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
25 #include "ssb_sprom.h"
35 struct cmdline_args cmdargs;
36 static uint8_t sprom_rev;
37 static uint16_t sprom_size;
39 /* SPROM layouts are described by the following table. The entries are as follows:
41 * uint16_t rev_mask A bit mask of the sprom revisions that contain this data
42 * enum valuetype type The type of datum represented by this table entry
43 * uint16_t length The length of this datum in bits. A value of 34 means a MAC address.
44 * A value of 33 means a 2 character country code.
45 * uint16_t offset The offset (in bytes) from the start of the sprom.
46 * uint16_t mask The mask needed to extract this datum from the 16-bit word.
47 * uint16_t shift The shift needed to right align this datum.
48 * char *desc The short character string used to describe this datum.
49 * char *label The long character string that tells the function of this datum.
51 * The table is ended with a rev_mask of zero.
54 static const struct var_entry sprom_table[] = {
55 { MASK_1_8, VAL_SUBP, 16, 0x04, 0xFFFF, 0x00, "subp", "Subsystem Product ID" },
56 { MASK_1_8, VAL_SUBV, 16, 0x06, 0xFFFF, 0x00, "subv", "Subsystem Vendor ID " },
57 { MASK_1_8, VAL_PPID, 16, 0x08, 0xFFFF, 0x00, "ppid", "PCI Product ID " },
58 { MASK_2_3, VAL_BFLHI, 16, 0x38, 0xFFFF, 0x00, "bflhi", "High 16 bits of boardflags" },
59 { MASK_4, VAL_BFLHI, 16, 0x46, 0xFFFF, 0x00, "bflhi", "High 16 bits of boardflags" },
60 { MASK_5, VAL_BFLHI, 16, 0x4C, 0xFFFF, 0x00, "bflhi", "High 16 bits of boardflags" },
61 { MASK_8, VAL_BFLHI, 16, 0x86, 0xFFFF, 0x00, "bflhi", "High 16 bits of boardflags" },
62 { MASK_1_3, VAL_BFL, 16, 0x72, 0xFFFF, 0x00, "bfl", "Low 16 bits of boardflags " },
63 { MASK_4, VAL_BFL, 16, 0x44, 0xFFFF, 0x00, "bfl", "Low 16 bits of boardflags " },
64 { MASK_5, VAL_BFL, 16, 0x4A, 0xFFFF, 0x00, "bfl", "Low 16 bits of boardflags " },
65 { MASK_8, VAL_BFL, 16, 0x84, 0xFFFF, 0x00, "bfl", "Low 16 bits of boardflags " },
66 { MASK_1_2, VAL_BGMAC, 34, 0x48, 0xFFFF, 0x00, "bgmac", "MAC Address for 802.11b/g" },
67 { MASK_3, VAL_BGMAC, 34, 0x4A, 0xFFFF, 0x00, "bgmac", "MAC Address for 802.11b/g" },
68 { MASK_4, VAL_BGMAC, 34, 0x4C, 0xFFFF, 0x00, "macadr", "MAC Address" },
69 { MASK_5, VAL_BGMAC, 34, 0x52, 0xFFFF, 0x00, "macadr", "MAC Address" },
70 { MASK_8, VAL_BGMAC, 34, 0x8C, 0xFFFF, 0x00, "macadr", "MAC Address" },
71 { MASK_1_2, VAL_ETMAC, 34, 0x4E, 0xFFFF, 0x00, "etmac", "MAC Address for ethernet " },
72 { MASK_1_2, VAL_AMAC, 34, 0x54, 0xFFFF, 0x00, "amac", "MAC Address for 802.11a " },
73 { MASK_1_3, VAL_ET0PHY, 5, 0x5A, 0x001F, 0x00, "et0phy", "Ethernet phy settings(0)" },
74 { MASK_1_3, VAL_ET1PHY, 5, 0x5A, 0x03E0, 0x05, "et1phy", "Ethernet phy settings(1)" },
75 { MASK_1_3, VAL_ET0MDC, 1, 0x5A, 0x4000, 0x0E, "et0mdc", "MDIO for ethernet 0" },
76 { MASK_1_3, VAL_ET1MDC, 1, 0x5A, 0x8000, 0x0F, "et1mdc", "MDIO for ethernet 1" },
77 { MASK_1_3, VAL_BREV, 8, 0x5C, 0x00FF, 0x00, "brev", "Board revision" },
78 { MASK_4_5, VAL_BREV, 8, 0x42, 0x00FF, 0x00, "brev", "Board revision" },
79 { MASK_8, VAL_BREV, 8, 0x82, 0x00FF, 0x00, "brev", "Board revision" },
80 { MASK_1_3, VAL_LOC, 4, 0x5C, 0x0300, 0x08, "loc", "Locale / Country Code" },
81 { MASK_4, VAL_LOC, 33, 0x52, 0xFFFF, 0x00, "ccode", "Country Code" },
82 { MASK_5, VAL_LOC, 33, 0x44, 0xFFFF, 0x00, "ccode", "Country Code" },
83 { MASK_8, VAL_LOC, 33, 0x92, 0xFFFF, 0x00, "ccode", "Country Code" },
84 { MASK_4_5, VAL_REGREV, 16, 0x54, 0xFFFF, 0x00, "regrev", "Regulatory revision" },
85 { MASK_8, VAL_REGREV, 16, 0x94, 0xFFFF, 0x00, "regrev", "Regulatory revision" },
86 { MASK_1_3, VAL_ANTBG0, 1, 0x5C, 0x1000, 0x0C, "antbg0", "Antenna 0 available for B/G PHY" },
87 { MASK_1_3, VAL_ANTBG1, 1, 0x5C, 0x2000, 0x0D, "antbg1", "Antenna 1 available for B/G PHY" },
88 { MASK_1_3, VAL_ANTA0, 1, 0x5C, 0x4000, 0x0E, "anta0", "Antenna 0 available for A PHY" },
89 { MASK_1_3, VAL_ANTA1, 1, 0x5C, 0x8000, 0x0F, "anta1", "Antenna 1 available for A PHY" },
90 { MASK_4_5, VAL_ANTBG0, 8, 0x5C, 0x00FF, 0x00, "antbg0", "Available antenna bitmask for 2 GHz" },
91 { MASK_8, VAL_ANTBG0, 8, 0x9C, 0x00FF, 0x00, "antbg0", "Available antenna bitmask for 2 GHz" },
92 { MASK_4_5, VAL_ANTA0, 8, 0x5C, 0xFF00, 0x08, "anta0", "Available antenna bitmask for 5 GHz" },
93 { MASK_8, VAL_ANTA0, 8, 0x9C, 0xFF00, 0x08, "anta0", "Available antenna bitmask for 5 GHz" },
94 { MASK_1_3, VAL_ANTGA, 8, 0x74, 0xFF00, 0x08, "antga" , "Antenna gain (5 GHz)" },
95 { MASK_1_3, VAL_ANTGBG, 8, 0x74, 0x00FF, 0x00, "antgbg", "Antenna gain (2 GHz)" },
96 { MASK_4_5, VAL_ANTG0, 8, 0x5E, 0x00FF, 0x00, "antg0", "Antenna 0 gain" },
97 { MASK_4_5, VAL_ANTG1, 8, 0x5E, 0xFF00, 0x08, "antg1", "Antenna 1 gain" },
98 { MASK_4_5, VAL_ANTG2, 8, 0x60, 0x00FF, 0x00, "antg2", "Antenna 2 gain" },
99 { MASK_4_5, VAL_ANTG3, 8, 0x60, 0xFF00, 0x08, "antg3", "Antenna 3 gain" },
100 { MASK_8, VAL_ANTG0, 8, 0x9E, 0x00FF, 0x00, "antg0", "Antenna 0 gain" },
101 { MASK_8, VAL_ANTG1, 8, 0x9E, 0xFF00, 0x08, "antg1", "Antenna 1 gain" },
102 { MASK_8, VAL_ANTG2, 8, 0xA0, 0x00FF, 0x00, "antg2", "Antenna 2 gain" },
103 { MASK_8, VAL_ANTG3, 8, 0xA0, 0xFF00, 0x08, "antg3", "Antenna 3 gain" },
104 { MASK_1_3, VAL_PA0B0, 16, 0x5E, 0xFFFF, 0x00, "pa0b0", "Power Amplifier W0 PAB0" },
105 { MASK_1_3, VAL_PA0B1, 16, 0x60, 0xFFFF, 0x00, "pa0b1", "Power Amplifier W0 PAB1" },
106 { MASK_1_3, VAL_PA0B2, 16, 0x62, 0xFFFF, 0x00, "pa0b2", "Power Amplifier W0 PAB2" },
107 { MASK_1_3, VAL_PA1B0, 16, 0x6A, 0xFFFF, 0x00, "pa1b0", "Power Amplifier W1 PAB0" },
108 { MASK_1_3, VAL_PA1B1, 16, 0x6C, 0xFFFF, 0x00, "pa1b1", "Power Amplifier W1 PAB1" },
109 { MASK_1_3, VAL_PA1B2, 16, 0x6E, 0xFFFF, 0x00, "pa1b2", "Power Amplifier W1 PAB2" },
110 { MASK_1_3, VAL_LED0, 8, 0x64, 0x00FF, 0x00, "led0", "LED 0 behavior" },
111 { MASK_1_3, VAL_LED1, 8, 0x64, 0xFF00, 0x08, "led1", "LED 1 behavior" },
112 { MASK_1_3, VAL_LED2, 8, 0x66, 0x00FF, 0x00, "led2", "LED 2 behavior" },
113 { MASK_1_3, VAL_LED3, 8, 0x66, 0xFF00, 0x08, "led3", "LED 3 behavior" },
114 { MASK_4, VAL_LED0, 8, 0x56, 0x00FF, 0x00, "led0", "LED 0 behavior" },
115 { MASK_4, VAL_LED1, 8, 0x56, 0xFF00, 0x08, "led1", "LED 1 behavior" },
116 { MASK_4, VAL_LED2, 8, 0x58, 0x00FF, 0x00, "led2", "LED 2 behavior" },
117 { MASK_4, VAL_LED3, 8, 0x58, 0xFF00, 0x08, "led3", "LED 3 behavior" },
118 { MASK_5, VAL_LED0, 8, 0x76, 0x00FF, 0x00, "led0", "LED 0 behavior" },
119 { MASK_5, VAL_LED1, 8, 0x76, 0xFF00, 0x08, "led1", "LED 1 behavior" },
120 { MASK_5, VAL_LED2, 8, 0x78, 0x00FF, 0x00, "led2", "LED 2 behavior" },
121 { MASK_5, VAL_LED3, 8, 0x78, 0xFF00, 0x08, "led3", "LED 3 behavior" },
122 { MASK_1_3, VAL_MAXPBG, 8, 0x68, 0x00FF, 0x00, "maxpbg", "B/G PHY max power out" },
123 { MASK_4_5, VAL_MAXPBG, 8, 0x80, 0x00FF, 0x00, "maxpbg", "Max power 2GHz - Path 1" },
124 { MASK_8, VAL_MAXPBG, 8, 0xC0, 0x00FF, 0x00, "maxpbg", "Max power 2GHz - Path 1" },
125 { MASK_1_3, VAL_MAXPA, 8, 0x68, 0xFF00, 0x08, "maxpa", "A PHY max power out " },
126 { MASK_4_5, VAL_MAXPA, 8, 0x8A, 0x00FF, 0x00, "maxpa", "Max power 5GHz - Path 1" },
127 { MASK_8, VAL_MAXPA, 8, 0xCA, 0xFF00, 0x08, "maxpa", "Max power 5GHz - Path 1" },
128 { MASK_1_3, VAL_ITSSIBG, 8, 0x70, 0x00FF, 0x00, "itssibg", "Idle TSSI target 2 GHz" },
129 { MASK_1_3, VAL_ITSSIA, 8, 0x70, 0xFF00, 0x08, "itssia", "Idle TSSI target 5 GHz" },
130 { MASK_4_5, VAL_ITSSIBG, 8, 0x80, 0xFF00, 0x08, "itssibg", "Idle TSSI target 2 GHz - Path 1" },
131 { MASK_4_5, VAL_ITSSIA, 8, 0x8A, 0xFF00, 0x08, "itssia", "Idle TSSI target 5 GHz - Path 1" },
132 { MASK_8, VAL_ITSSIBG, 8, 0xC0, 0xFF00, 0x08, "itssibg", "Idle TSSI target 2 GHz - Path 1" },
133 { MASK_8, VAL_ITSSIA, 8, 0xCA, 0xFF00, 0x08, "itssia", "Idle TSSI target 5 GHz - Path 1" },
134 { MASK_8, VAL_TPI2G0, 16, 0x62, 0xFFFF, 0x00, "tpi2g0", "TX Power Index 2GHz" },
135 { MASK_8, VAL_TPI2G1, 16, 0x64, 0xFFFF, 0x00, "tpi2g1", "TX Power Index 2GHz" },
136 { MASK_8, VAL_TPI5GM0,16, 0x66, 0xFFFF, 0x00, "tpi5gm0", "TX Power Index 5GHz middle subband" },
137 { MASK_8, VAL_TPI5GM1,16, 0x68, 0xFFFF, 0x00, "tpi5gm1", "TX Power Index 5GHz middle subband" },
138 { MASK_8, VAL_TPI5GL0,16, 0x6A, 0xFFFF, 0x00, "tpi5gl0", "TX Power Index 5GHz low subband " },
139 { MASK_8, VAL_TPI5GL1,16, 0x6C, 0xFFFF, 0x00, "tpi5gl1", "TX Power Index 5GHz low subband " },
140 { MASK_8, VAL_TPI5GH0,16, 0x6E, 0xFFFF, 0x00, "tpi5gh0", "TX Power Index 5GHz high subband " },
141 { MASK_8, VAL_TPI5GH1,16, 0x70, 0xFFFF, 0x00, "tpi5gh1", "TX Power Index 5GHz high subband " },
142 { MASK_8, VAL_2CCKPO, 16, 0x140,0xFFFF, 0x00, "cckpo2g", "2 GHz CCK power offset " },
143 { MASK_8, VAL_2OFDMPO,32, 0x142,0xFFFF, 0x00, "ofdm2g", "2 GHz OFDM power offset" },
144 { MASK_8, VAL_5MPO, 32, 0x146,0xFFFF, 0x00, "ofdm5gm", "5 GHz OFDM middle subband power offset" },
145 { MASK_8, VAL_5LPO, 32, 0x14A,0xFFFF, 0x00, "ofdm5gl", "5 GHz OFDM low subband power offset " },
146 { MASK_8, VAL_5HPO, 32, 0x14E,0xFFFF, 0x00, "ofdm5gh", "5 GHz OFDM high subband power offset " },
147 { MASK_8, VAL_2MCSPO, 16, 0x152,0xFFFF, 0x00, "mcspo2", "2 GHz MCS power offset" },
148 { MASK_8, VAL_5MMCSPO,16, 0x162,0xFFFF, 0x00, "mcspo5m", "5 GHz middle subband MCS power offset" },
149 { MASK_8, VAL_5LMCSPO,16, 0x172,0xFFFF, 0x00, "mcspo5l", "5 GHz low subband MCS power offset " },
150 { MASK_8, VAL_5HMCSPO,16, 0x182,0xFFFF, 0x00, "mcspo5h", "5 GHz high subband MCS power offset " },
151 { MASK_8, VAL_CCDPO, 16, 0x192,0xFFFF, 0x00, "ccdpo", "CCD power offset " },
152 { MASK_8, VAL_STBCPO, 16, 0x194,0xFFFF, 0x00, "stbcpo", "STBC power offset " },
153 { MASK_8, VAL_BW40PO, 16, 0x196,0xFFFF, 0x00, "bw40po", "BW40 power offset " },
154 { MASK_8, VAL_BWDUPPO,16, 0x198,0xFFFF, 0x00, "bwduppo", "BWDUP power offset" },
155 { MASK_4_5, VAL_TPI2G0, 16, 0x62, 0xFFFF, 0x00, "tpi2g0", "TX Power Index 2GHz" },
156 { MASK_4_5, VAL_TPI2G1, 16, 0x64, 0xFFFF, 0x00, "tpi2g1", "TX Power Index 2GHz" },
157 { MASK_4_5, VAL_TPI5GM0,16, 0x66, 0xFFFF, 0x00, "tpi5gm0", "TX Power Index 5GHz middle subband" },
158 { MASK_4_5, VAL_TPI5GM1,16, 0x68, 0xFFFF, 0x00, "tpi5gm1", "TX Power Index 5GHz middle subband" },
159 { MASK_4_5, VAL_TPI5GL0,16, 0x6A, 0xFFFF, 0x00, "tpi5gl0", "TX Power Index 5GHz low subband " },
160 { MASK_4_5, VAL_TPI5GL1,16, 0x6C, 0xFFFF, 0x00, "tpi5gl1", "TX Power Index 5GHz low subband " },
161 { MASK_4_5, VAL_TPI5GH0,16, 0x6E, 0xFFFF, 0x00, "tpi5gh0", "TX Power Index 5GHz high subband " },
162 { MASK_4_5, VAL_TPI5GH1,16, 0x70, 0xFFFF, 0x00, "tpi5gh1", "TX Power Index 5GHz high subband " },
163 { MASK_4_5, VAL_2CCKPO, 16, 0x138,0xFFFF, 0x00, "cckpo2g", "2 GHz CCK power offset " },
164 { MASK_4_5, VAL_2OFDMPO,32, 0x13A,0xFFFF, 0x00, "ofdm2g", "2 GHz OFDM power offset" },
165 { MASK_4_5, VAL_5MPO, 32, 0x13E,0xFFFF, 0x00, "ofdm5gm", "5 GHz OFDM middle subband power offset" },
166 { MASK_4_5, VAL_5LPO, 32, 0x142,0xFFFF, 0x00, "ofdm5gl", "5 GHz OFDM low subband power offset " },
167 { MASK_4_5, VAL_5HPO, 32, 0x146,0xFFFF, 0x00, "ofdm5gh", "5 GHz OFDM high subband power offset " },
168 { MASK_4_5, VAL_2MCSPO, 16, 0x14A,0xFFFF, 0x00, "mcspo2", "2 GHz MCS power offset" },
169 { MASK_4_5, VAL_5MMCSPO,16, 0x15A,0xFFFF, 0x00, "mcspo5m", "5 GHz middle subband MCS power offset" },
170 { MASK_4_5, VAL_5LMCSPO,16, 0x16A,0xFFFF, 0x00, "mcspo5l", "5 GHz low subband MCS power offset " },
171 { MASK_4_5, VAL_5HMCSPO,16, 0x17A,0xFFFF, 0x00, "mcspo5h", "5 GHz high subband MCS power offset " },
172 { MASK_4_5, VAL_CCDPO, 16, 0x18A,0xFFFF, 0x00, "ccdpo", "CCD power offset " },
173 { MASK_4_5, VAL_STBCPO, 16, 0x18C,0xFFFF, 0x00, "stbcpo", "STBC power offset " },
174 { MASK_4_5, VAL_BW40PO, 16, 0x18E,0xFFFF, 0x00, "bw40po", "BW40 power offset " },
175 { MASK_4_5, VAL_BWDUPPO,16, 0x190,0xFFFF, 0x00, "bwduppo", "BWDUP power offset" },
176 /* per path variables are below here - only path 1 decoded for now */
177 { MASK_4_5, VAL_PA0B0, 16, 0xC2, 0xFFFF, 0x00, "pa0b0", "Path 1: Power Amplifier W0 PAB0" },
178 { MASK_4_5, VAL_PA0B1, 16, 0xC4, 0xFFFF, 0x00, "pa0b1", "Path 1: Power Amplifier W0 PAB1" },
179 { MASK_4_5, VAL_PA0B2, 16, 0xC6, 0xFFFF, 0x00, "pa0b2", "Path 1: Power Amplifier W0 PAB2" },
180 { MASK_4_5, VAL_PA0B3, 16, 0xC8, 0xFFFF, 0x00, "pa0b3", "Path 1: Power Amplifier W0 PAB3" },
181 { MASK_4_5, VAL_PA1B0, 8, 0xCC, 0x00FF, 0x00, "pam5h", "Path 1: 5 GHz high subband PAM " },
182 { MASK_4_5, VAL_PA1B0, 8, 0xCC, 0xFF00, 0x08, "pam5l", "Path 1: 5 GHz low subband PAM " },
183 { MASK_4_5, VAL_5MPA0, 16, 0xCE, 0xFFFF, 0x00, "pa5m0", "Path 1: 5 GHz Power Amplifier middle 0" },
184 { MASK_4_5, VAL_5MPA1, 16, 0xD0, 0xFFFF, 0x00, "pa5m1", "Path 1: 5 GHz Power Amplifier middle 1" },
185 { MASK_4_5, VAL_5MPA2, 16, 0xD2, 0xFFFF, 0x00, "pa5m2", "Path 1: 5 GHz Power Amplifier middle 2" },
186 { MASK_4_5, VAL_5MPA3, 16, 0xD4, 0xFFFF, 0x00, "pa5m3", "Path 1: 5 GHz Power Amplifier middle 3" },
187 { MASK_4_5, VAL_5LPA0, 16, 0xD6, 0xFFFF, 0x00, "pa5l0", "Path 1: 5 GHz Power Amplifier low 0 " },
188 { MASK_4_5, VAL_5LPA1, 16, 0xD8, 0xFFFF, 0x00, "pa5l1", "Path 1: 5 GHz Power Amplifier low 1 " },
189 { MASK_4_5, VAL_5LPA2, 16, 0xDA, 0xFFFF, 0x00, "pa5l2", "Path 1: 5 GHz Power Amplifier low 2 " },
190 { MASK_4_5, VAL_5LPA3, 16, 0xDC, 0xFFFF, 0x00, "pa5l3", "Path 1: 5 GHz Power Amplifier low 3 " },
191 { MASK_4_5, VAL_5HPA0, 16, 0xDE, 0xFFFF, 0x00, "pa5h0", "Path 1: 5 GHz Power Amplifier high 0 " },
192 { MASK_4_5, VAL_5HPA1, 16, 0xE0, 0xFFFF, 0x00, "pa5h1", "Path 1: 5 GHz Power Amplifier high 1 " },
193 { MASK_4_5, VAL_5HPA2, 16, 0xE2, 0xFFFF, 0x00, "pa5h2", "Path 1: 5 GHz Power Amplifier high 2 " },
194 { MASK_4_5, VAL_5HPA3, 16, 0xE4, 0xFFFF, 0x00, "pa5h3", "Path 1: 5 GHz Power Amplifier high 3 " },
195 { MASK_8, VAL_PA0B0, 16, 0xC2, 0xFFFF, 0x00, "pa0b0", "SISO (Path 1) Power Amplifier W0 PAB0" },
196 { MASK_8, VAL_PA0B1, 16, 0xC4, 0xFFFF, 0x00, "pa0b1", "SISO (Path 1) Power Amplifier W0 PAB1" },
197 { MASK_8, VAL_PA0B2, 16, 0xC6, 0xFFFF, 0x00, "pa0b2", "SISO (Path 1) Power Amplifier W0 PAB2" },
198 { MASK_8, VAL_PA1B0, 16, 0xCC, 0xFFFF, 0x00, "pa5m0", "SISO (Path 1) 5 GHz Power Amplifier middle 0" },
199 { MASK_8, VAL_PA1B1, 16, 0xCE, 0xFFFF, 0x00, "pa5m1", "SISO (Path 1) 5 GHz Power Amplifier middle 1" },
200 { MASK_8, VAL_PA1B2, 16, 0xD0, 0xFFFF, 0x00, "pa5m2", "SISO (Path 1) 5 GHz Power Amplifier middle 2" },
201 { MASK_8, VAL_5MPA0, 16, 0xD2, 0xFFFF, 0x00, "pa5l0", "SISO (Path 1) 5 GHz Power Amplifier low 0 " },
202 { MASK_8, VAL_5MPA1, 16, 0xD4, 0xFFFF, 0x00, "pa5l1", "SISO (Path 1) 5 GHz Power Amplifier low 1 " },
203 { MASK_8, VAL_5MPA2, 16, 0xD6, 0xFFFF, 0x00, "pa5l2", "SISO (Path 1) 5 GHz Power Amplifier low 2 " },
204 { MASK_8, VAL_5LPA0, 16, 0xD8, 0xFFFF, 0x00, "pa5h0", "SISO (Path 1) 5 GHz Power Amplifier high 0 " },
205 { MASK_8, VAL_5LPA1, 16, 0xDA, 0xFFFF, 0x00, "pa5h1", "SISO (Path 1) 5 GHz Power Amplifier high 1 " },
206 { MASK_8, VAL_5LPA2, 16, 0xDC, 0xFFFF, 0x00, "pa5h2", "SISO (Path 1) 5 GHz Power Amplifier high 2 " },
211 /* find an item in the table by sprom revision and short description
212 * returns length and type. The function value is -1 if the item is not
213 * found, otherwise 0.
216 static int locate_item_by_desc(int rev, enum valuetype *type, uint16_t *length, char *desc)
221 if (sprom_table[i].rev_mask == 0)
222 return -1; /* end of table */
223 if ((sprom_table[i].rev_mask & rev) &&
224 (!strcmp(sprom_table[i].desc, desc))) {
225 /* this is the record we want */
226 *length = sprom_table[i].length;
227 *type = sprom_table[i].type;
231 return -1; /* flow cannot reach here, but this statement makes gcc happy */
234 /* find an item in the table by sprom revision and type
235 * return length, offset, mask, shift, desc, and label
236 * The function returns -1 if no item matches the request.
239 static int locate_item_rev(int rev, enum valuetype type, uint16_t *length, uint16_t *offset,
240 uint16_t *mask, uint16_t *shift, char *desc, char *label)
245 if (sprom_table[i].rev_mask == 0)
246 return -1; /* end of table */
247 if ((sprom_table[i].rev_mask & rev) &&
248 (sprom_table[i].type == type)) {
249 /* this is the record we want */
250 *length = sprom_table[i].length;
251 *offset = sprom_table[i].offset;
252 *mask = sprom_table[i].mask;
253 *shift = sprom_table[i].shift;
254 strcpy(desc, sprom_table[i].desc);
255 strcpy(label, sprom_table[i].label);
259 return -1; /* flow cannot reach here, but this statement makes gcc happy */
262 static int check_rev(uint16_t rev)
264 if ((rev < 0) || (rev > 8) || (rev == 6) || (rev == 7)) {
265 prerror("\nIllegal value for sprom_rev\n");
271 static int hexdump_sprom(const uint8_t *sprom, char *buffer, size_t bsize)
275 for (i = 0; i < sprom_size; i++) {
276 pos += snprintf(buffer + pos, bsize - pos - 1,
277 "%02X", sprom[i] & 0xFF);
283 static uint8_t sprom_crc(const uint8_t *sprom)
288 for (i = 0; i < sprom_size - 1; i++)
289 crc = crc8(crc, sprom[i]);
295 static int write_output_binary(int fd, const uint8_t *sprom)
299 w = write(fd, sprom, sprom_size);
306 static int write_output_hex(int fd, const uint8_t *sprom)
309 char tmp[SPROM4_SIZE * 2 + 10] = { 0 };
311 hexdump_sprom(sprom, tmp, sizeof(tmp));
312 prinfo("Raw output: %s\n", tmp);
313 w = write(fd, tmp, sprom_size * 2);
320 static int write_output(int fd, const uint8_t *sprom)
324 if (cmdargs.outfile) {
325 err = ftruncate(fd, 0);
327 prerror("Could not truncate --outfile %s\n",
333 if (cmdargs.bin_mode)
334 err = write_output_binary(fd, sprom);
336 err = write_output_hex(fd, sprom);
338 prerror("Could not write output data.\n");
343 static int modify_value(uint8_t *sprom,
344 struct cmdline_vparm *vparm)
346 const uint32_t v = vparm->u.value;
357 int rev_bit = BIT(sprom_rev);
360 if (vparm->type == VAL_RAW) {
361 sprom[vparm->u.raw.offset] = vparm->u.raw.value;
364 if (locate_item_rev(rev_bit, vparm->type, &length, &offset, &mask,
365 &shift, desc, label))
369 old_value = sprom[offset + 0];
370 old_value |= sprom[offset + 1] << 8;
373 value = (old_value & ~mask) | tmp;
376 sprom[offset + 0] = (value & 0x00FF);
377 sprom[offset + 1] = (value & 0xFF00) >> 8;
378 } else if (length == 32) {
380 sprom[offset + 0] = (value & 0x00FF);
381 sprom[offset + 1] = (value >> 8) & 0xFF;
382 sprom[offset + 2] = (value >> 16) & 0xFF;
383 sprom[offset + 3] = (value >> 24) & 0xFF;
384 } else if (length == 34) { /* MAC address */
385 sprom[offset + 1] = vparm->u.mac[0];
386 sprom[offset + 0] = vparm->u.mac[1];
387 sprom[offset + 3] = vparm->u.mac[2];
388 sprom[offset + 2] = vparm->u.mac[3];
389 sprom[offset + 5] = vparm->u.mac[4];
390 sprom[offset + 4] = vparm->u.mac[5];
391 } else if (length == 33) { /* country code */
392 sprom[offset + 1] = vparm->u.ccode[0];
393 sprom[offset + 0] = vparm->u.ccode[1];
395 prerror("Incorrect value for length (%d)\n", length);
402 static int modify_sprom(uint8_t *sprom)
404 struct cmdline_vparm *vparm;
409 for (i = 0; i < cmdargs.nr_vparm; i++) {
410 vparm = &(cmdargs.vparm[i]);
413 modify_value(sprom, vparm);
417 /* Recalculate the CRC. */
418 crc = sprom_crc(sprom);
419 sprom[sprom_size - 1] = crc;
425 static void display_value(const uint8_t *sprom,
426 struct cmdline_vparm *vparm)
437 int rev_bit = BIT(sprom_rev);
441 if (locate_item_rev(rev_bit, vparm->type, &length, &offset, &mask,
442 &shift, desc, label))
445 value = sprom[offset + 0];
446 value |= sprom[offset + 1] << 8;
447 value = (value & mask) >> shift;
448 } else if (length == 32) {
449 value = sprom[offset + 0];
450 value |= sprom[offset + 1] << 8;
451 value |= sprom[offset + 2] << 16;
452 value |= sprom[offset + 3] << 24;
454 sprintf(buffer, "SPROM(0x%03X), %s, ", offset, desc);
456 p = &(sprom[offset]);
460 prdata("%s%s = %s\n", buffer, label, value ? "ON" : "OFF");
463 prdata("%s%s = 0x%01X\n", buffer, label, (value & 0xF));
466 prdata("%s%s = 0x%02X\n", buffer, label, (value & 0x1F));
469 prdata("%s%s = 0x%02X\n", buffer, label, (value & 0xFF));
472 prdata("%s%s = 0x%04X\n", buffer, label, value);
475 prdata("%s%s = 0x%08X\n", buffer, label, value);
477 case 33: /* alphabetic country code */
478 for (i = 0; i < 2; i++) {
480 if (!tbuf[i]) /* if not encoded, the value is zero */
483 prdata("%s%s = \"%c%c\"\n", buffer, label, tbuf[1], tbuf[0]);
487 prdata("%s%s = %02x:%02x:%02x:%02x:%02x:%02x\n",
488 buffer, label, p[1], p[0], p[3], p[2], p[5], p[4]);
491 prerror("vparm->bits internal error (%d)\n",
497 static int display_sprom(const uint8_t *sprom)
499 struct cmdline_vparm *vparm;
502 for (i = 0; i < cmdargs.nr_vparm; i++) {
503 vparm = &(cmdargs.vparm[i]);
506 display_value(sprom, vparm);
512 static int validate_input(const uint8_t *sprom)
514 uint8_t crc, expected_crc;
516 crc = sprom_crc(sprom);
517 expected_crc = sprom[sprom_size - 1];
519 if (crc != expected_crc) {
520 prerror("Corrupt input data (crc: 0x%02X, expected: 0x%02X)\n",
529 static int parse_input(uint8_t *sprom, char *buffer, size_t bsize)
534 unsigned long parsed;
535 char tmp[SPROM4_SIZE * 2 + 10] = { 0 };
537 if (cmdargs.bin_mode) {
538 /* The input buffer already contains
539 * the binary sprom data.
541 internal_error_on(bsize != SPROM_SIZE && bsize != SPROM4_SIZE);
542 memcpy(sprom, buffer, bsize);
547 input = strchr(buffer, ':');
550 inlen -= input - buffer;
554 if (inlen < SPROM_SIZE * 2) {
555 prerror("Input data too short\n");
558 for (cnt = 0; cnt < inlen / 2; cnt++) {
559 memcpy(tmp, input + cnt * 2, 2);
560 parsed = strtoul(tmp, NULL, 16);
561 sprom[cnt] = parsed & 0xFF;
563 /* check for 440 byte versions (V4 and higher) */
565 sprom_rev = sprom[SPROM4_SIZE - 2];
566 sprom_size = SPROM4_SIZE;
568 sprom_rev = sprom[SPROM_SIZE - 2];
569 sprom_size = SPROM_SIZE;
571 if (check_rev(sprom_rev))
573 if (cmdargs.verbose) {
574 hexdump_sprom(sprom, tmp, sizeof(tmp));
575 prinfo("Raw input: %s\n", tmp);
581 static int read_infile(int fd, char **buffer, size_t *bsize)
589 prerror("Could not stat input file.\n");
592 if (s.st_size == 0) {
593 prerror("No input data\n");
596 if (cmdargs.bin_mode) {
597 if (s.st_size != SPROM_SIZE && s.st_size != SPROM4_SIZE) {
598 prerror("The input data is not SPROM Binary data. "
599 "The size must be exactly %d (V1-3) "
600 "or %d (V4-8) bytes, "
601 "but it is %u bytes\n",
602 SPROM_SIZE, SPROM4_SIZE,
603 (unsigned int)(s.st_size));
607 if (s.st_size > 1024 * 1024) {
608 prerror("The input data does not look "
609 "like SPROM HEX data (too long).\n");
615 if (!cmdargs.bin_mode)
617 *buffer = malloce(*bsize);
618 r = read(fd, *buffer, s.st_size);
619 if (r != s.st_size) {
620 prerror("Could not read input data.\n");
623 if (!cmdargs.bin_mode)
629 static void close_infile(int fd)
635 static void close_outfile(int fd)
641 static int open_infile(int *fd)
646 *fd = open(cmdargs.infile, O_RDONLY);
648 prerror("Could not open --infile %s\n",
656 static int open_outfile(int *fd)
659 if (!cmdargs.outfile)
661 *fd = open(cmdargs.outfile, O_RDWR | O_CREAT, 0644);
663 prerror("Could not open --outfile %s\n",
671 static void print_banner(int forceprint)
673 const char *str = "Broadcom-SSB SPROM data modification tool.\n"
675 "Copyright (C) Michael Buesch\n"
676 "Licensed under the GNU/GPL version 2 or later\n"
678 "Be exceedingly careful with this tool. Improper"
679 " usage WILL BRICK YOUR DEVICE.\n";
686 static void print_usage(int argc, char *argv[])
699 prdata("\nUsage: %s [OPTION]\n", argv[0]);
700 prdata(" -i|--input FILE Input file\n");
701 prdata(" -o|--output FILE Output file\n");
702 prdata(" -b|--binmode The Input data is plain binary data and Output will be binary\n");
703 prdata(" -V|--verbose Be verbose\n");
704 prdata(" -f|--force Override error checks\n");
705 prdata(" -v|--version Print version\n");
706 prdata(" -h|--help Print this help\n");
707 prdata("\nValue Parameters:\n");
709 prdata(" -s|--rawset OFF,VAL Set a VALue at a byte-OFFset\n");
710 prdata(" -g|--rawget OFF Get a value at a byte-OFFset\n");
713 for (sprom_rev = 1; sprom_rev < 9; sprom_rev++) {
714 if (sprom_rev == 6 || sprom_rev == 7)
717 rev_bit = BIT(sprom_rev);
718 prdata("\n================================================================\n"
719 "Rev. %d: Predefined values (for displaying (GET) or modification)\n"
720 "================================================================\n", sprom_rev);
722 for (loop = 0; loop <= VAL_LAST; loop++) {
723 if (locate_item_rev(rev_bit, loop, &length, &offset, &mask,
724 &shift, desc, label))
729 sprintf(buffer, " --%s [MAC-ADDR]%30s", desc, " ");
732 sprintf(buffer, " --%s [2 Char String]%30s", desc, " ");
735 sprintf(buffer, " --%s [0xFFFFFFFF]%30s", desc, " ");
738 sprintf(buffer, " --%s [0xFFFF]%30s", desc, " ");
741 sprintf(buffer, " --%s [0xFF]%30s", desc, " ");
744 sprintf(buffer, " --%s [0x1F]%30s", desc, " ");
747 sprintf(buffer, " --%s [0xF]%30s", desc, " ");
750 sprintf(buffer, " --%s [BOOL]%30s", desc, " ");
753 prerror("Program error: Incorrect value of item length (%d)\n", length);
757 prdata("%s%s\n", buffer, label);
762 prdata(" -P|--print-all Display all values\n");
764 prdata(" BOOL is a boolean value. Either 0 or 1\n");
765 prdata(" 0xF.. is a hexadecimal value\n");
766 prdata(" MAC-ADDR is a MAC address in the format 00:00:00:00:00:00\n");
767 prdata(" If the value parameter is \"GET\", the value will be printed;\n");
768 prdata(" otherwise it is modified.\n");
769 prdata("\nBe exceedingly careful with this tool. Improper"
770 " usage WILL BRICK YOUR DEVICE.\n");
774 #define ARG_NOMATCH 1
777 static int do_cmp_arg(char **argv, int *pos,
778 const char *template,
784 size_t arg_len, template_len;
787 next_arg = argv[*pos + 1];
788 arg_len = strlen(arg);
789 template_len = strlen(template);
792 /* Maybe we have a merged parameter here.
793 * A merged parameter is "-pfoobar" for example.
795 if (allow_merged && arg_len > template_len) {
796 if (memcmp(arg, template, template_len) == 0) {
797 *param = arg + template_len;
801 } else if (arg_len != template_len)
805 if (strcmp(arg, template) == 0) {
807 if (*param == NULL) {
808 prerror("%s needs a parameter\n", arg);
811 /* Skip the parameter on the next iteration. */
820 /* Simple and lean command line argument parsing. */
821 static int cmp_arg(char **argv, int *pos,
822 const char *long_template,
823 const char *short_template,
829 err = do_cmp_arg(argv, pos, long_template, 0, param);
830 if (err == ARG_MATCH || err == ARG_ERROR)
835 err = do_cmp_arg(argv, pos, short_template, 1, param);
839 static int parse_err;
841 static int arg_match(char **argv, int *i,
842 const char *long_template,
843 const char *short_template,
848 res = cmp_arg(argv, i, long_template,
849 short_template, param);
850 if (res == ARG_ERROR) {
854 return (res == ARG_MATCH);
857 static int parse_value(const char *str,
858 struct cmdline_vparm *vparm,
865 if (strcmp(str, "GET") == 0 || strcmp(str, "get") == 0) {
869 if (vparm->bits > 32)
871 if (vparm->bits == 1) {
872 /* This is a boolean value. */
873 if (strcmp(str, "0") == 0)
875 else if (strcmp(str, "1") == 0)
882 if (strncmp(str, "0x", 2) != 0)
885 /* The following logic presents a problem because the offsets
886 * for V4 SPROMs can be greater than 0xFF; however, the arguments
887 * are parsed before the SPROM revision is known. To fix this
888 * problem, if an input is expecting 0xFF-type input, then input
889 * of 0xFFF will be permitted */
890 for (i = 0; i < vparm->bits / 4; i++) {
894 if (str[i] != '\0') {
896 i++; /* add an extra character */
901 v = strtoul(str, NULL, 16);
909 prerror("%s value parsing error. Format: 0x", param);
910 for (i = 0; i < vparm->bits / 4; i++)
918 prerror("%s value parsing error. Format: 0 or 1 (boolean)\n", param);
922 static int parse_ccode(const char *str,
923 struct cmdline_vparm *vparm,
926 const char *in = str;
927 char *out = vparm->u.ccode;
931 if (strcmp(str, "GET") == 0 || strcmp(str, "get") == 0) {
940 static int parse_mac(const char *str,
941 struct cmdline_vparm *vparm,
946 const char *in = str;
947 uint8_t *out = vparm->u.mac;
951 if (strcmp(str, "GET") == 0 || strcmp(str, "get") == 0) {
958 out[i] = strtoul(in, NULL, 16);
962 if (in[1] != '\0' && in[2] != '\0')
966 delim = strchr(in, ':');
974 prerror("%s MAC parsing error. Format: 00:00:00:00:00:00\n", param);
978 static int parse_rawset(const char *str,
979 struct cmdline_vparm *vparm)
986 vparm->type = VAL_RAW;
988 delim = strchr(str, ',');
992 err = parse_value(str, vparm, NULL);
995 offset = vparm->u.value;
996 if (offset >= SPROM4_SIZE) {
997 prerror("--rawset offset too big (>= 0x%02X)\n",
1001 err = parse_value(delim + 1, vparm, NULL);
1004 value = vparm->u.value;
1006 vparm->u.raw.value = value;
1007 vparm->u.raw.offset = offset;
1012 prerror("--rawset value parsing error. Format: 0xFF,0xFF "
1013 "(first Offset, second Value)\n");
1017 static int parse_rawget(const char *str,
1018 struct cmdline_vparm *vparm)
1023 vparm->type = VAL_RAW;
1025 err = parse_value(str, vparm, "--rawget");
1028 offset = vparm->u.value;
1029 if (offset >= SPROM4_SIZE) {
1030 prerror("--rawget offset too big (>= 0x%02X)\n",
1035 vparm->u.raw.offset = offset;
1036 vparm->type = VAL_RAW;
1042 static int generate_printall(void)
1044 enum valuetype vt = 0;
1047 for (vt = 0; vt <= VAL_LAST; vt++) {
1048 if (cmdargs.nr_vparm == MAX_VPARM) {
1049 prerror("Too many value parameters.\n");
1052 for (j = 0; ; j++) {
1053 enum valuetype type = sprom_table[j].type;
1054 short mask = sprom_table[j].rev_mask;
1058 if ((mask & BIT(sprom_rev)) && (type == vt)) {
1059 cmdargs.vparm[cmdargs.nr_vparm].type = vt;
1060 cmdargs.vparm[cmdargs.nr_vparm].set = 0;
1061 cmdargs.vparm[cmdargs.nr_vparm++].bits = sprom_table[j].length;
1068 static int parse_args(int argc, char *argv[], int pass)
1070 struct cmdline_vparm *vparm;
1075 enum valuetype type;
1078 for (i = 1; i < argc; i++) {
1079 if (cmdargs.nr_vparm == MAX_VPARM) {
1080 prerror("Too many value parameters.\n");
1084 if (arg_match(argv, &i, "--version", "-v", NULL)) {
1087 } else if (arg_match(argv, &i, "--help", "-h", NULL)) {
1089 } else if (arg_match(argv, &i, "--input", "-i", ¶m)) {
1090 cmdargs.infile = param;
1091 } else if (arg_match(argv, &i, "--output", "-o", ¶m)) {
1092 cmdargs.outfile = param;
1093 } else if (arg_match(argv, &i, "--verbose", "-V", NULL)) {
1094 cmdargs.verbose = 1;
1095 } else if (arg_match(argv, &i, "--force", "-n", NULL)) {
1097 } else if (arg_match(argv, &i, "--binmode", "-b", NULL)) {
1098 cmdargs.bin_mode = 1;
1099 } else if (pass == 2 && arg_match(argv, &i, "--rawset", "-s", ¶m)) {
1100 vparm = &(cmdargs.vparm[cmdargs.nr_vparm++]);
1101 err = parse_rawset(param, vparm);
1104 } else if (pass == 2 && arg_match(argv, &i, "--rawget", "-g", ¶m)) {
1105 vparm = &(cmdargs.vparm[cmdargs.nr_vparm++]);
1106 err = parse_rawget(param, vparm);
1110 } else if (pass == 2 && arg_match(argv, &i, "--print-all", "-P", NULL)) {
1111 err = generate_printall();
1115 } else if (pass == 2) {
1117 if (arg[0] != '-' || arg[1] != '-')
1118 goto out_usage; /* all must start with "--" */
1119 if (locate_item_by_desc(BIT(sprom_rev), &type, &length, arg + 2))
1121 arg_match(argv, &i, arg, NULL, ¶m);
1122 vparm = &(cmdargs.vparm[cmdargs.nr_vparm++]);
1124 vparm->bits = length;
1125 err = parse_value(param, vparm, arg);
1129 err = parse_mac(param, vparm, arg);
1134 err = parse_ccode(param, vparm, arg);
1142 if (pass == 2 && cmdargs.nr_vparm == 0) {
1143 prerror("No Value parameter given. See --help.\n");
1149 print_usage(argc, argv);
1155 int main(int argc, char **argv)
1159 uint8_t sprom[SPROM4_SIZE + 10];
1160 char *buffer = NULL;
1161 size_t buffer_size = 0;
1163 /* Some arguments require that the revision of the sprom be known,
1164 * but that is not known until the sprom data are read. This difficulty
1165 * is handled by making two passes through the argument list. The first
1166 * only process those arguments that do not depend on sprom revision.
1168 * Do the first pass through arguments
1170 err = parse_args(argc, argv, 1);
1177 prinfo("\nReading input from \"%s\"...\n",
1178 cmdargs.infile ? cmdargs.infile : "stdin");
1180 err = open_infile(&fd);
1183 err = read_infile(fd, &buffer, &buffer_size);
1187 err = parse_input(sprom, buffer, buffer_size);
1191 err = validate_input(sprom);
1195 /* do second pass through argument list */
1196 err = parse_args(argc, argv, 2);
1202 err = display_sprom(sprom);
1205 err = modify_sprom(sprom);
1209 err = open_outfile(&fd);
1212 err = write_output(fd, sprom);
1216 prinfo("SPROM modified.\n");
1218 prdata("The input file is data from a revision %d SPROM.\n", sprom_rev);