-
Notifications
You must be signed in to change notification settings - Fork 1
/
sms1xxx-firmware.c
262 lines (234 loc) · 8.85 KB
/
sms1xxx-firmware.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* SMS1XXX - Siano DVB-T USB driver for FreeBSD 8.0 and higher:
*
* Copyright (C) 2008-2014, Ganaël Laplanche, http://contribs.martymac.org
*
* This driver contains code taken from the FreeBSD dvbusb driver:
*
* Copyright (C) 2006-2007, Raaf
* Copyright (C) 2004-2006, Patrick Boettcher
*
* This driver contains code taken from the Linux siano driver:
*
* Siano Mobile Silicon, Inc.
* MDTV receiver kernel modules.
* Copyright (C) 2006-2009, Uri Shkolnik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* * * *
* Firmware management
* * * *
*/
/* firmware(9) stuff */
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/linker.h>
#include <sys/firmware.h>
/* le..toh(9) stuff */
#include <sys/endian.h>
#include "sms1xxx.h"
#include "sms1xxx-coreapi.h"
#include "sms1xxx-firmware.h"
#include "sms1xxx-usb.h"
#include "sms1xxx-endian.h"
static int sms1xxx_firmware_load_family1(struct sms1xxx_softc *,
const u8 *, u32);
static int sms1xxx_firmware_load_family2(struct sms1xxx_softc *,
const u8 *, u32);
static char *sms1xxx_firmwares
[((SMS1XXX_TYPE_MAX & SMS1XXX_TYPE_MASK) >> 16) + 1]
[DEVICE_MODE_MAX + 1] = {
/* STELLAR */
{ "stellar_dvbt.fw", /* DVBT */
"stellar_dvbh.fw", /* DVBH */
"stellar_dabtdmb.fw", /* DAB_TDMB */
"", /* DAB_TDMB_DABIP */
"stellar_dvbt.fw", /* DVBT_BDA */
"", /* DEVICE_MODE_ISDBT */
"", /* DEVICE_MODE_ISDBT_BDA */
"", /* DEVICE_MODE_CMMB */
"" }, /* DEVICE_MODE_RAW_TUNER */
/* NOVA_A */
{ "", /* DVBT */
"", /* DVBH */
"", /* DAB_TDMB */
"", /* DAB_TDMB_DABIP */
"", /* DVBT_BDA */
"", /* DEVICE_MODE_ISDBT */
"", /* DEVICE_MODE_ISDBT_BDA */
"", /* DEVICE_MODE_CMMB */
"" }, /* DEVICE_MODE_RAW_TUNER */
/* NOVA_B */
{ "novab0_dvbbda.fw", /* DVBT */
"novab0_dvbbda.fw", /* DVBH */
"novab0_tdmb.fw", /* DAB_TDMB */
"", /* DAB_TDMB_DABIP */
"novab0_dvbbda.fw", /* DVBT_BDA */
"novab0_isdbtbda.fw", /* DEVICE_MODE_ISDBT */
"novab0_isdbtbda.fw", /* DEVICE_MODE_ISDBT_BDA */
"", /* DEVICE_MODE_CMMB */
"" }, /* DEVICE_MODE_RAW_TUNER */
/* VEGA */
{ "", /* DVBT */
"", /* DVBH */
"", /* DAB_TDMB */
"", /* DAB_TDMB_DABIP */
"", /* DVBT_BDA */
"", /* DEVICE_MODE_ISDBT */
"", /* DEVICE_MODE_ISDBT_BDA */
"", /* DEVICE_MODE_CMMB */
"" }, /* DEVICE_MODE_RAW_TUNER */
};
/* Return a firmware name given type and mode
Return NULL if an invalid type/mode is specified or if no firmware found */
char *
sms1xxx_firmware_name(unsigned long type, int mode) {
/* Check type, mode, and firmware existence */
if (((type & SMS1XXX_TYPE_MASK)>=(SMS1XXX_TYPE_MIN & SMS1XXX_TYPE_MASK))
&& ((type & SMS1XXX_TYPE_MASK)<=(SMS1XXX_TYPE_MAX & SMS1XXX_TYPE_MASK))
&& (mode >= DEVICE_MODE_MIN)
&& (mode <= DEVICE_MODE_MAX)
&& (sms1xxx_firmwares[(type & SMS1XXX_TYPE_MASK) >> 16][mode][0])) {
return sms1xxx_firmwares[(type & SMS1XXX_TYPE_MASK) >> 16][mode] ;
}
return (NULL);
}
/* Load a firmware to the device using
the firmware(9) facility (family1 devices) */
static int
sms1xxx_firmware_load_family1(struct sms1xxx_softc *sc, const u8 *data,
u32 datasize)
{
if (sc->sc_dying)
return (ENXIO);
if ((data == NULL) || (datasize == 0))
return (EINVAL);
TRACE(TRACE_FIRMWARE, "data=%p, datasize=%d\n", data, datasize);
return sms1xxx_usb_rawwrite(sc, data, datasize);
}
/* Load a firmware to the device using
the firmware(9) facility (family2 devices) */
static int
sms1xxx_firmware_load_family2(struct sms1xxx_softc *sc, const u8 *data,
u32 datasize)
{
if (sc->sc_dying)
return (ENXIO);
if ((data == NULL) || (datasize == 0))
return (EINVAL);
TRACE(TRACE_FIRMWARE, "data=%p, datasize=%d\n", data, datasize);
const struct sms_firmware *firmware = (const struct sms_firmware *)data;
u32 mem_address = le32toh(firmware->start_address);
const u8 *payload = firmware->payload;
int err = 0;
if (sc->mode != DEVICE_MODE_NONE) {
/* send reload start command on warm devices */
err = sms1xxx_usb_reloadstart(sc);
if(err != 0) {
TRACE(TRACE_FIRMWARE, "reloadstart() failed, err=%d\n", err);
return (EIO);
}
mem_address = *(const u32*) &payload[20];
}
while(datasize && (err == 0)) {
/* Upload firmware using chunks <= SMS_MAX_PAYLOAD_SIZE */
int payload_size = min((int) datasize, SMS_MAX_PAYLOAD_SIZE);
struct sms_data_download Msg;
Msg.x_msg_header.msg_type = MSG_SMS_DATA_DOWNLOAD_REQ;
Msg.x_msg_header.msg_src_id = 0;
Msg.x_msg_header.msg_dst_id = HIF_TASK;
Msg.x_msg_header.msg_length =
(u16)(sizeof(struct sms_msg_hdr) + sizeof(u32) + payload_size);
Msg.x_msg_header.msg_flags = 0;
Msg.mem_addr = mem_address;
memcpy(Msg.payload, payload, payload_size);
TRACE(TRACE_FIRMWARE, "sending firmware chunk, size=%d, "
"remaining=%d\n", payload_size, datasize - payload_size);
sms1xxx_endian_handle_tx_message(&Msg);
/* XXX honour SMS_ROM_NO_RESPONSE and use sms1xxx_usb_write() ? */
err = sms1xxx_usb_write_and_wait(sc, (u8*)&Msg,
Msg.x_msg_header.msg_length, DLG_DATA_DOWNLOAD_DONE,
FRONTEND_TIMEOUT);
if(err == 0) {
payload += payload_size;
datasize -= payload_size;
mem_address += payload_size;
}
}
#ifdef SMS1XXX_DEBUG
if ((err != 0) || (datasize > 0))
TRACE(TRACE_FIRMWARE, "firmware upload error, err=%d, done=%zu, "
"remaining=%d\n", err, payload - firmware->payload, datasize);
#endif
if (err == 0) {
/* send reload exec command on warm devices */
if (sc->mode != DEVICE_MODE_NONE)
err = sms1xxx_usb_reloadexec(sc);
/* or software download trigger on cold ones */
else
err = sms1xxx_usb_swdtrigger(sc, firmware->start_address);
TRACE(TRACE_FIRMWARE, "trigger done, err=%d\n", err);
}
return (err);
}
/* Wrapper that loads a firmware to the device using
family1 or family2-specific functions */
int
sms1xxx_firmware_load(struct sms1xxx_softc *sc, int mode)
{
const struct firmware *fw;
char *fw_name;
int err = 0;
TRACE(TRACE_FIRMWARE, "sc=%p, mode=%d\n", sc, mode);
if (sc->sc_dying)
return (ENXIO);
fw_name = sms1xxx_firmware_name(sc->sc_type, mode);
if (fw_name == NULL) {
ERR("no firmware support for type 0x%lx, mode %d\n", sc->sc_type, mode);
return (EINVAL);
}
TRACE(TRACE_FIRMWARE, "uploading firmware %s\n", fw_name);
fw = firmware_get(fw_name);
if (fw) {
switch(sc->sc_type & SMS1XXX_FAMILY_MASK) {
case SMS1XXX_FAMILY1:
err = sms1xxx_firmware_load_family1(sc, fw->data, fw->datasize);
break;
case SMS1XXX_FAMILY2:
err = sms1xxx_firmware_load_family2(sc, fw->data, fw->datasize);
break;
default:
ERR("invalid device type 0x%lx\n",
sc->sc_type & SMS1XXX_FAMILY_MASK);
err = (EINVAL);
break;
}
firmware_put(fw, FIRMWARE_UNLOAD);
if (err == 0) {
sc->mode = DEVICE_MODE_NONE;
sc->device->requested_mode = mode;
sc->device->fw_loading = TRUE;
INFO("successfully uploaded firmware %s (%zd bytes)\n",
fw_name, fw->datasize);
}
else {
ERR("failed to upload firmware %s\n", fw_name);
}
}
else {
ERR("firmware %s not available (is module loaded ?)\n", fw_name);
err = (EINVAL);
}
return (err);
}