summaryrefslogtreecommitdiff
path: root/gpsflash.c
blob: 0defe531fbea17e6d725011b4db700d82f6a9c11 (plain)
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
/* $Id$ */
/*
 * This is the GPS-type-independent part of the gpsflash program.
 *
 */
/*
 * Copyright (c) 2005-2007 Chris Kuethe <chris.kuethe@gmail.com>
 * Copyright (c) 2005-2007 Eric S. Raymond <esr@thyrsus.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include <stdarg.h>
#include <string.h>
#ifndef S_SPLINT_S
#include <unistd.h>
#endif /* S_SOLINT_S */
#include "gpsd_config.h"
#include "gpsd.h"
#include "gpsflash.h"

/* block size when writing to the serial port. related to FIFO size */
#define WRBLK 128

static char *progname;
static int verbosity = 0;

static bool srec_check(const char *data);

void gpsd_report(int errlevel, const char *fmt, ... )
/* assemble command in printf(3) style, use stderr or syslog */
{
    if (errlevel <= verbosity) {
	char buf[BUFSIZ];
	va_list ap;

	(void)strlcpy(buf, progname, BUFSIZ);
	(void)strlcat(buf, ": ", BUFSIZ);
	va_start(ap, fmt) ;
	(void)vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
	va_end(ap);
	(void)fputs(buf, stdout);
    }
}

static void
usage(void){
    fprintf(stderr, "Usage: %s [-v d] [-n] [-l <loader_file>] -f <firmware_file> {<tty>}\n", progname);
}

int
serialSpeed(int pfd, struct termios *term, int speed){
	int rv;
	int r = 0;

	switch(speed){
#ifdef B115200
	case 115200:
		speed = B115200;
		break;
#endif
#ifdef B57600
	case 57600:
		speed = B57600;
		break;
#endif
	case 38400:
		speed = B38400;
		break;
#ifdef B28800
	case 28800:
		speed = B28800;
		break;
#endif
	case 19200:
		speed = B19200;
		break;
#ifdef B14400
	case 14400:
		speed = B14400;
		break;
#endif
	case 9600:
		speed = B9600;
		break;
	case 4800:
		speed = B9600;
		break;
	default:
		errno = EINVAL;
		return -1;
	}

	/* set UART speed */
	(int)tcgetattr(pfd, term);
	/*@ ignore @*/
	cfsetispeed(term, speed);
	cfsetospeed(term, speed);
	/*@ end @*/
	while (((rv = tcsetattr(pfd, TCSAFLUSH, term)) == -1) && \
	    (errno == EINTR) && (r < 3)) {
		/* retry up to 3 times on EINTR */
		(void)usleep(1000);
		r++;
	}

	if(rv == -1)
		return -1;
	else
		return 0;
}


int
serialConfig(int pfd, struct termios *term, int speed){
	int rv;
	int r = 0;

	/* get the current terminal settings */
	(void)tcgetattr(pfd, term);
	/* set the port into "raw" mode. */
	/*@i@*/cfmakeraw(term);
	term->c_lflag &=~ (ICANON);
	/* Enable serial I/O, ignore modem lines */
	term->c_cflag |= (CLOCAL | CREAD);
	/* No output postprocessing */
	term->c_oflag &=~ (OPOST);
	/* 8 data bits */
	term->c_cflag |= CS8;
	term->c_iflag &=~ (ISTRIP);
	/* No parity */
	term->c_iflag &=~ (INPCK);
	term->c_cflag &=~ (PARENB | PARODD);
	/* 1 Stop bit */
	term->c_cflag &=~ (CSIZE | CSTOPB);
	/* No flow control */
	term->c_iflag &=~ (IXON | IXOFF);
#if defined(CCTS_OFLOW) && defined(CRTS_IFLOW) && defined(MDMBUF)
	term->c_oflag &=~ (CCTS_OFLOW | CRTS_IFLOW | MDMBUF);
#endif
#if defined(CRTSCTS)
	term->c_oflag &=~ (CRTSCTS);
#endif

	/* we'd like to read back at least 2 characters in .2sec */
	/*@i@*/term->c_cc[VMIN] = 2;
	/*@i@*/term->c_cc[VTIME] = 2;

	/* apply all the funky control settings */
	while (((rv = tcsetattr(pfd, TCSAFLUSH, term)) == -1) && \
	    (errno == EINTR) && (r < 3)) {
		/* retry up to 3 times on EINTR */
		(void)usleep(1000);
		r++;
	}

	if(rv == -1)
		return -1;
	
	/* and if that all worked, try change the UART speed */
	return serialSpeed(pfd, term, speed);
}

int
binary_send(int pfd, char *data UNUSED , size_t ls){
	unsigned char *msg;
	size_t nbr, nbs, nbx;
	ssize_t r;
	static int count;
	double start = timestamp();

	/*@ -compdef @*/
	if((msg = malloc(ls+10)) == NULL){
		return -1; /* oops. bail out */
	}

	fprintf(stderr, "gpsflash: transferring binary... \010");
	count = 0;

	nbr = ls+10; nbs = WRBLK ; nbx = 0;
	while(nbr){
		if(nbr > WRBLK )
			nbs = WRBLK ;
		else
			nbs = nbr;

r0:		if((r = write(pfd, msg+nbx, nbs)) == -1){
			if (errno == EAGAIN){ /* retry */
				(void)tcdrain(pfd); /* wait a moment */
				errno = 0; /* clear errno */
				nbr -= r; /* number bytes remaining */
				nbx += r; /* number bytes sent */
				goto r0;
			} else {
			        (void)free(msg);
				return -1; /* oops. bail out */
			}
		}
		nbr -= r;
		nbx += r;

		(void)fputc("-/|\\"[count % 4], stderr);
		(void)fputc('\010', stderr);
		(void)fflush(stdout);
	}
	/*@ +compdef @*/

	(void)fprintf(stderr, "...done (%2.2f sec).\n", timestamp()-start);

	(void)free(msg);
	return 0;
}


int
srecord_send(int pfd, char *data, size_t len){
	int r, i;
	size_t tl;
	char sendbuf[85], recvbuf[8];
	static int count;
	double start = timestamp();

	/* srecord loading is interactive. send line, get reply */
	/* when sending S-records, check for SA/S5 or SE */

	fprintf(stderr, "gpsflash: transferring S-records... \010");
	count = 0;

	memset(recvbuf, 0, 8);
	i = 0;

	while(strlen(data)){
		/* grab a line of firmware, ignore line endings */
		if ((r = (int)strlen(data))){
			memset(sendbuf,0,85);
			if((r = sscanf(data, "%80s", sendbuf)) == EOF)
				return 0;

			tl = strlen(sendbuf);
			if ((tl < 1) || (tl > 80))
				return -1;

			data += tl;
			len -= tl;

			while((data[0] != 'S') && (data[0] != '\0'))
				data++;

			sendbuf[tl] = '\r';
			sendbuf[tl+1] = '\n';
			tl += 2;

			if ((++i % 1000) == 0)
				printf ("%6d\n", i);

			(void)tcflush(pfd, TCIFLUSH);
			if((r = (int)write(pfd, sendbuf, tl+2)) != (int)tl+2)
				return -1; /* oops. bail out */

			(void)tcdrain(pfd);
			if((r = (int)read(pfd, recvbuf, 7)) == -1)
				return -1; /* oops. bail out */

			if (!((recvbuf[0] == 'S') && ((recvbuf[1] == 'A') || (recvbuf[1] == '5'))))
				return -1; /* oops. bail out */
		}

		(void)fputc("-/|\\"[count % 4], stderr);
		(void)fputc('\010', stderr);
		(void)fflush(stdout);
	}

	(void)fprintf(stderr, "...done (%2.2f sec).\n", timestamp()-start);
	return 0;
}

bool
expect(int pfd, const char *str, size_t len, time_t timeout)
/* keep reading till we see a specified expect string or time out */
{
    size_t got = 0;
    char ch;
    double start = timestamp();

    gpsd_report(LOG_PROG, "expect(%s, %d)\n",
		gpsd_hexdump((char *)str, len),
		(int)timeout);

    for (;;) {
	if (read(pfd, &ch, 1) != 1)
	    return false;		/* I/O failed */
	gpsd_report(LOG_RAW, "I see %zd: %02x\n", got, (unsigned)(ch & 0xff));
	if (timestamp() - start > (double)timeout)
	    return false;		/* we're timed out */
	else if (got == len)
	    return true;		/* we're done */
	else if (ch == str[got])
	    got++;			/* match continues */
	else
	    got = 0;			/* match fails, retry */
    }
}


#if defined(SIRF_ENABLE) && defined(BINARY_ENABLE)
/* add new types by adding pointers to their driver blocks to this list */
/*@ -nullassign @*/
static struct flashloader_t *types[] = {&sirf_type, NULL};
/*@ +nullassign @*/
#else
/* add new types by adding pointers to their driver blocks to this list */
/*@ -nullassign @*/
static struct flashloader_t *types[] = {NULL, NULL};
/*@ +nullassign @*/
#endif

int
main(int argc, char **argv){

	int ch;
	int lfd, ffd, pfd;
	size_t ls,  fs;
	bool fflag = false, lflag = false, nflag = false;
	struct stat sb;
	struct flashloader_t *gpstype, **gp;
	char *fname = NULL;
	char *lname = NULL;
	char *port = NULL;
	char *warning;
	struct termios term;
	sigset_t sigset;
	char *firmware = NULL;
	char *loader = NULL;
	char *version = NULL;

	progname = argv[0];

	while ((ch = getopt(argc, argv, "f:l:nVv:")) != -1)
		switch (ch) {
		case 'f':
			fname = optarg;
			fflag = true;
			break;
		case 'l':
			lname = optarg;
			lflag = true;
			break;
		case 'n':
			nflag = true;
			break;
		case 'v':
			verbosity = atoi(optarg);
			break;
		case 'V':
			(void)fprintf(stderr, "SVN ID: $Id$ \n");
			exit(0);
		default:
			usage();
			exit(0);
			/* NOTREACHED */
		}

	argc -= optind;
	argv += optind;

	/* there is exactly one required argument, a tty device */
	if (argc == 1) 
	    port = argv[0];
	else {
	    usage();
	    exit(0);
	}

	if (!nflag && 
	    (((warning = getenv("I_READ_THE_WARNING")) == NULL) ||
	     (strcmp(warning, "why oh why didn't i take the blue pill")!=0))){
	    printf("\nThis program rewrites your receiver's flash ROM.\n");
	    printf("If done improperly this will permanently ruin your\n");
	    printf("receiver. We insist you read the gpsflash manpage\n");
	    printf("before you break something.\n\n");
	    nflag = true;
	}

	if (!nflag) {
	    /* make sure we have meaningful flags */
	    if (!fflag || fname == NULL) {
		usage();
		return 1;
	    }
	}

	/* Open the serial port, blocking is OK */
	if((pfd = open(port, O_RDWR | O_NOCTTY , 0600)) == -1) {
		gpsd_report(LOG_ERROR, "open(%s)\n", port);
		return 1;
	}

	/* try to get an identification string out of the firmware */
	gpstype = NULL;
	for (gp = types; *gp; gp++) {
	    gpstype = *gp;
	    gpsd_report(LOG_PROG, "probing for %s\n", gpstype->name);
	    if (gpstype->probe(pfd, &version) == 0)
		break;
	}
	if (gpstype == NULL || version == NULL) {
	    gpsd_report(LOG_ERROR, "not a known GPS type\n");
	    return 1;
	}

	/* OK, we have a known type */
	gpsd_report(LOG_SHOUT, "GPS is %s, version '%s'.\n", gpstype->name, version);
	if (lname == NULL)
	    lname = (char *)gpstype->flashloader;

	if (nflag) {
	    gpsd_report(LOG_PROG, "probe finished.\n");
	    return 0;
	}

	/* there may be a type-specific setup method */
	memset(&term, 0, sizeof(term));
	if(gpstype->port_setup(pfd, &term) == -1) {
		gpsd_report(LOG_ERROR, "port_setup()\n");
		return 1;
	}

	gpsd_report(LOG_PROG, "port set up...\n");

	/* Open the loader file */
	if((lfd = open(lname, O_RDONLY, 0444)) == -1) {
	    gpsd_report(LOG_ERROR, "open(%s)\n", lname);
	    return 1;
	}

	/* fstat() its file descriptor. Need the size, and avoid races */
	if(fstat(lfd, &sb) == -1) {
	    gpsd_report(LOG_ERROR, "fstat(%s)\n", lname);
	    return 1;
	}

	/* minimal sanity check on loader size. also prevents bad malloc() */
	ls = (size_t)sb.st_size;
	if ((ls < gpstype->min_loader_size)||(ls > gpstype->max_loader_size)){
	    gpsd_report(LOG_ERROR, "preposterous loader size: %zd\n", ls);
	    return 1;
	}

	gpsd_report(LOG_PROG, "passed sanity checks...\n");

	/* malloc a loader buffer */
	if ((loader = malloc(ls)) == NULL) {
	    gpsd_report(LOG_ERROR, "malloc(%zd)\n", ls);
	    return 1;
	}

	if (read(lfd, loader, ls) != (ssize_t)ls) {
	    (void)free(loader);
	    gpsd_report(LOG_ERROR, "read(%zd)\n", ls);
	    return 1;
	}

	/* don't care if close fails - kernel will force close on exit() */
	(void)close(lfd);

	gpsd_report(LOG_PROG, "loader read in...\n");

	/* Open the firmware image file */
	/*@ -nullpass @*/
	if((ffd = open(fname, O_RDONLY, 0444)) == -1) {
	    (void)free(loader);
	    gpsd_report(LOG_ERROR, "open(%s)]n", fname);
	    return 1;
	}
	if(fstat(ffd, &sb) == -1) {
	    (void)free(loader);
	    gpsd_report(LOG_ERROR, "fstat(%s)\n", fname);
	    return 1;
	}

	/* minimal sanity check on firmware size. also prevents bad malloc() */
	fs = (size_t)sb.st_size;
	if ((fs < gpstype->min_firmware_size) || (fs > gpstype->max_firmware_size)){
	    (void)free(loader);
	    gpsd_report(LOG_ERROR, "preposterous firmware size: %zd\n", fs);
	    return 1;
	}

	/* malloc an image buffer */
	if ((firmware = malloc(fs+1)) == NULL) {
	    (void)free(loader);
	    gpsd_report(LOG_ERROR, "malloc(%zd)\n", fs);
	    return 1;
	}

	/* get the firmware */
	if (read(ffd, firmware, fs) != (ssize_t)fs) {
	    (void)free(loader);
	    (void)free(firmware);
	    gpsd_report(LOG_ERROR, "read(%zd)\n", fs);
	    return 1;
	}

	firmware[fs] = '\0';

	/* don't care if close fails - kernel will force close on exit() */
	(void)close(ffd);

	gpsd_report(LOG_PROG, "firmware read in...\n");

	/* did we just read some S-records? */
	if (!((firmware[0] == 'S') && ((firmware[1] >= '0') && (firmware[1] <= '9')))){ /* srec? */
	    (void)free(loader);
	    (void)free(firmware);
	    gpsd_report(LOG_ERROR, "%s: not an S-record file\n", fname);
	    return 1;
	}

	if(gpstype->version_check(pfd, version, loader, ls, firmware, fs)==-1){
		(void)free(loader);
		(void)free(firmware);
		gpsd_report(LOG_ERROR, "version_check()\n");
		return 1;
	}

	/*
	 * dlgps2.bin starts flashing when it sees valid srecords.
	 * validate the entire image before we flash. shooting self
	 * in foot is bad, mmmkay?
	 */
	gpsd_report(LOG_PROG, "validating firmware\n");
	if (srec_check(firmware)){
	    (void)free(loader);
	    (void)free(firmware);
	    gpsd_report(LOG_ERROR, "%s: corrupted firmware image\n", fname);
	    return 1;
	}
	/*@ +nullpass @*/
	gpsd_report(LOG_PROG, "firmware validated\n");

	gpsd_report(LOG_PROG, "version checked...\n");

	gpsd_report(LOG_PROG, "blocking signals...\n");

	/* once we get here, we are uninterruptable. handle signals */
	(void)sigemptyset(&sigset);
	(void)sigaddset(&sigset, SIGINT);
	(void)sigaddset(&sigset, SIGHUP);
	(void)sigaddset(&sigset, SIGQUIT);
	(void)sigaddset(&sigset, SIGTSTP);
	(void)sigaddset(&sigset, SIGSTOP);
	(void)sigaddset(&sigset, SIGKILL);

	if(sigprocmask(SIG_BLOCK, &sigset, NULL) == -1) {
		(void)free(loader);
		(void)free(firmware);
		gpsd_report(LOG_ERROR,"sigprocmask\n");
		return 1;
	}

	/* send the command to begin the update */
	if(gpstype->stage1_command!=NULL && (gpstype->stage1_command(pfd) == -1)) {
		(void)free(loader);
		(void)free(firmware);
		gpsd_report(LOG_ERROR, "Stage 1 update command\n");
		return 1;
	}

	gpsd_report(LOG_PROG, "sending loader...\n");

	/* send the bootstrap/flash programmer */
	if(gpstype->loader_send(pfd, &term, loader, ls) == -1) {
		(void)free(loader);
		(void)free(firmware);
		gpsd_report(LOG_ERROR, "Loader send\n");
		return 1;
	}
	(void)free(loader);

	gpsd_report(LOG_PROG, "initializing firmware load...\n");

	/* send any command needed to demarcate the two loads */
	if(gpstype->stage2_command!=NULL && (gpstype->stage2_command(pfd) == -1)) {
	    (void)free(firmware);
	    gpsd_report(LOG_ERROR, "Stage 2 update command\n");
	    return 1;
	}

	gpsd_report(LOG_PROG, "performing firmware load...\n");

	/* and now, poke the actual firmware over */
	if(gpstype->firmware_send(pfd, firmware, fs) == -1) {
	    (void)free(firmware);
	    gpsd_report(LOG_ERROR, "Firmware send\n");
	    return 1;
	}
	(void)free(firmware);

	gpsd_report(LOG_PROG, "finishing firmware load...\n");

	/* send any command needed to finish the firmware load */
	if(gpstype->stage3_command!=NULL && (gpstype->stage3_command(pfd) == -1)) {
	    gpsd_report(LOG_ERROR, "Stage 3 update command\n");
	    return 1;
	}

	gpsd_report(LOG_PROG, "unblocking signals...\n");

	if(sigprocmask(SIG_UNBLOCK, &sigset, NULL) == -1) {
		gpsd_report(LOG_ERROR,"sigprocmask\n");
		return 1;
	}

	/* type-defined wrapup, take our tty to GPS's post-flash settings */
	if(gpstype->port_wrapup(pfd, &term) == -1) {
		gpsd_report(LOG_ERROR, "port_wrapup()\n");
		return 1;
	}

	gpsd_report(LOG_PROG, "finished.\n");

	/* return() from main(), to take advantage of SSP compilers */
	return 0;
}

static bool
srec_check(const char *data){
	int i, l, n, x, y, z;
	char buf[85];

	l = 0;
	while(strlen(data)){
		/* grab a line of firmware, ignore line endings */
		memset(buf,0,85);
		l++;
		if(sscanf(data, "%80s", buf) == EOF){
			gpsd_report(LOG_ERROR, "line %d read failed\n", l);
			return true;
		}

		n = (int)strlen(buf);
		if ((n < 1) || (n > 80)){
			gpsd_report(LOG_ERROR, "firmware line %d invalid length %d\n", l, n);
			return true;
		}

		/* advance to the next srecord */
		data += n;
		while((data[0] != 'S') && (data[0] != '\0'))
			data++;

		if (buf[0] != 'S'){
			gpsd_report(LOG_INF, "%s\n", buf);
			gpsd_report(LOG_ERROR, "firmware line %d doesn't begin with 'S'.\n", l);
			return true;
		}

		x = hex2bin(buf+2);
		y = (n - 4)/2;
		if (x != y){
			gpsd_report(LOG_INF, "buf: '%s'\n", buf);
			gpsd_report(LOG_ERROR, "firmware line %d length error: %d != %d\n", l, x, y);
			return true;
		}

		x = hex2bin(buf+n-2);
		y = 0;
		for(i = 2; i < n-2; i+=2){
			z = hex2bin(buf+i);
			y += z;
		}
		y &= 0xff; y ^= 0xff;
		if (x != y){
			gpsd_report(LOG_INF, "buf: '%s'\n", buf);
			gpsd_report(LOG_ERROR, "firmware line %d checksum error: %x != %x\n", l, x, y);
			return true;
		}
	}
	return false;
}