Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors

Showing 1 changed file with 54 additions and 26 deletions. Show diff stats Hide diff stats

  1. 80  tools/flterm.c
80  tools/flterm.c
@@ -329,13 +329,13 @@ static void gdb_process_packet(int infd, int outfd, int altfd)
329 329
 		fds.revents = 0;
330 330
 		if(poll(&fds, 1, 100) == 0) {
331 331
 			/* timeout */
332  
-			if (altfd != -1) {
  332
+			if(altfd != -1) {
333 333
 				write(altfd, gdbbuf, pos);
334 334
 			}
335 335
 			break;
336 336
 		}
337  
-		if (pos == GDBBUFLEN) {
338  
-			if (altfd != -1) {
  337
+		if(pos == GDBBUFLEN) {
  338
+			if(altfd != -1) {
339 339
 				write(altfd, gdbbuf, pos);
340 340
 			}
341 341
 			break;
@@ -344,26 +344,26 @@ static void gdb_process_packet(int infd, int outfd, int altfd)
344 344
 		gdbbuf[pos++] = c;
345 345
 		if(c == '#') {
346 346
 			seen_hash = 1;
347  
-		} else if (seen_hash == 0) {
  347
+		} else if(seen_hash == 0) {
348 348
 			runcksum += c;
349  
-		} else if (seen_hash == 1) {
  349
+		} else if(seen_hash == 1) {
350 350
 			recvcksum = hex(c) << 4;
351 351
 			seen_hash = 2;
352  
-		} else if (seen_hash == 2) {
  352
+		} else if(seen_hash == 2) {
353 353
 			recvcksum |= hex(c);
354 354
 			seen_hash = 3;
355 355
 		}
356 356
 
357  
-		if (seen_hash == 3) {
  357
+		if(seen_hash == 3) {
358 358
 			/* we're done */
359 359
 			runcksum %= 256;
360  
-			if (recvcksum == runcksum) {
361  
-				if (debug) {
  360
+			if(recvcksum == runcksum) {
  361
+				if(debug) {
362 362
 					fprintf(stderr, "[GDB %s]\n", gdbbuf);
363 363
 				}
364 364
 				write(outfd, gdbbuf, pos);
365 365
 			} else {
366  
-				if (altfd != -1) {
  366
+				if(altfd != -1) {
367 367
 					write(altfd, gdbbuf, pos);
368 368
 				}
369 369
 			}
@@ -377,10 +377,12 @@ static void do_terminal(char *serial_port,
377 377
 	int doublerate, int gdb_passthrough,
378 378
 	const char *kernel_image, unsigned int kernel_address,
379 379
 	const char *cmdline, unsigned int cmdline_address,
380  
-	const char *initrd_image, unsigned int initrd_address)
  380
+	const char *initrd_image, unsigned int initrd_address,
  381
+	char *log_path)
381 382
 {
382 383
 	int serialfd;
383 384
 	int gdbfd = -1;
  385
+	FILE *logfd = NULL;
384 386
 	struct termios my_termios;
385 387
 	char c;
386 388
 	int recognized;
@@ -389,6 +391,14 @@ static void do_terminal(char *serial_port,
389 391
 	int rsp_pending = 0;
390 392
 	
391 393
 	/* Open and configure the serial port */
  394
+	if(log_path != NULL) {
  395
+		logfd = fopen(log_path, "a+");
  396
+		if(logfd == NULL) {
  397
+			perror("Unable to open log file");
  398
+			return;
  399
+		}
  400
+	}
  401
+
392 402
 	serialfd = open(serial_port, O_RDWR|O_NOCTTY);
393 403
 	if(serialfd == -1) {
394 404
 		perror("Unable to open serial port");
@@ -421,7 +431,7 @@ static void do_terminal(char *serial_port,
421 431
 	recognized = 0;
422 432
 	flags = fcntl(serialfd, F_GETFL, 0);
423 433
 	while(1) {
424  
-		if (gdbfd == -1 && gdb_passthrough) {
  434
+		if(gdbfd == -1 && gdb_passthrough) {
425 435
 			gdbfd = open("/dev/ptmx", O_RDWR);
426 436
 			if(grantpt(gdbfd) != 0) {
427 437
 				perror("grantpt()");
@@ -449,22 +459,22 @@ static void do_terminal(char *serial_port,
449 459
 		fcntl(serialfd, F_SETFL, flags);
450 460
 
451 461
 		if(fds[0].revents & POLLIN) {
452  
-			if (read(0, &c, 1) <= 0) break;
  462
+			if(read(0, &c, 1) <= 0) break;
453 463
 			if(write(serialfd, &c, 1) <= 0) break;
454 464
 		}
455 465
 
456 466
 		if(fds[2].revents & POLLIN) {
457 467
 			rsp_pending = 1;
458  
-			if (read(gdbfd, &c, 1) <= 0) break;
459  
-			if (c == '\03') {
  468
+			if(read(gdbfd, &c, 1) <= 0) break;
  469
+			if(c == '\03') {
460 470
 				/* convert ETX to breaks */
461  
-				if (debug) {
  471
+				if(debug) {
462 472
 					fprintf(stderr, "[GDB BREAK]\n");
463 473
 				}
464 474
 				tcsendbreak(serialfd, 0);
465  
-			} else if (c == '$') {
  475
+			} else if(c == '$') {
466 476
 				gdb_process_packet(gdbfd, serialfd, -1);
467  
-			} else if (c == '+' || c == '-') {
  477
+			} else if(c == '+' || c == '-') {
468 478
 				write(serialfd, &c, 1);
469 479
 			} else {
470 480
 				fprintf(stderr, "Internal error (line %d)", __LINE__);
@@ -481,10 +491,14 @@ static void do_terminal(char *serial_port,
481 491
 
482 492
 		if(fds[1].revents & POLLIN) {
483 493
 			if(read(serialfd, &c, 1) <= 0) break;
  494
+
  495
+			fwrite(&c, sizeof(c), 1, logfd);
  496
+			fflush(logfd);
  497
+
484 498
 			if(gdbfd != -1 && rsp_pending && (c == '+' || c == '-')) {
485 499
 				rsp_pending = 0;
486 500
 				write(gdbfd, &c, 1);
487  
-			} else if (gdbfd != -1 && c == '$') {
  501
+			} else if(gdbfd != -1 && c == '$') {
488 502
 				gdb_process_packet(serialfd, gdbfd, 0);
489 503
 			} else {
490 504
 				/* write to terminal */
@@ -508,9 +522,9 @@ static void do_terminal(char *serial_port,
508 522
 	}
509 523
 	
510 524
 	close(serialfd);
511  
-	if(gdbfd != -1) {
512  
-		close(gdbfd);
513  
-	}
  525
+
  526
+	if(gdbfd != -1) close(gdbfd);
  527
+	if(logfd) fclose(logfd);
514 528
 }
515 529
 
516 530
 enum {
@@ -523,7 +537,8 @@ enum {
523 537
 	OPTION_CMDLINE,
524 538
 	OPTION_CMDLINEADR,
525 539
 	OPTION_INITRD,
526  
-	OPTION_INITRDADR
  540
+	OPTION_INITRDADR,
  541
+	OPTION_LOG
527 542
 };
528 543
 
529 544
 static const struct option options[] = {
@@ -578,13 +593,18 @@ static const struct option options[] = {
578 593
 		.val = OPTION_INITRDADR
579 594
 	},
580 595
 	{
  596
+		.name = "log",
  597
+		.has_arg = 1,
  598
+		.val = OPTION_LOG
  599
+	},
  600
+	{
581 601
 		.name = NULL
582 602
 	}
583 603
 };
584 604
 
585 605
 static void print_usage()
586 606
 {
587  
-	fprintf(stderr, "Serial boot program for Milkymist SoC - v. 2.0\n");
  607
+	fprintf(stderr, "Serial boot program for Milkymist SoC - v. 2.1\n");
588 608
 	fprintf(stderr, "Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq\n");
589 609
 	fprintf(stderr, "Copyright (C) 2011 Michael Walle\n");
590 610
 	fprintf(stderr, "Copyright (C) 2004 MontaVista Software, Inc\n\n");
@@ -597,7 +617,8 @@ static void print_usage()
597 617
 	fprintf(stderr, "              [--double-rate] [--gdb-passthrough] [--debug]\n");
598 618
 	fprintf(stderr, "              --kernel <kernel_image> [--kernel-adr <address>]\n");
599 619
 	fprintf(stderr, "              [--cmdline <cmdline> [--cmdline-adr <address>]]\n");
600  
-	fprintf(stderr, "              [--initrd <initrd_image> [--initrd-adr <address>]]\n\n");
  620
+	fprintf(stderr, "              [--initrd <initrd_image> [--initrd-adr <address>]]\n");
  621
+	fprintf(stderr, "              [--log <log_file>]\n\n");
601 622
 	printf("Default load addresses:\n");
602 623
 	fprintf(stderr, "  kernel:  0x%08x\n", DEFAULT_KERNELADR);
603 624
 	fprintf(stderr, "  cmdline: 0x%08x\n", DEFAULT_CMDLINEADR);
@@ -617,6 +638,7 @@ int main(int argc, char *argv[])
617 638
 	char *initrd_image;
618 639
 	unsigned int initrd_address;
619 640
 	char *endptr;
  641
+	char *log_path;
620 642
 	struct termios otty, ntty;
621 643
 	
622 644
 	/* Fetch command line arguments */
@@ -629,6 +651,7 @@ int main(int argc, char *argv[])
629 651
 	cmdline_address = DEFAULT_CMDLINEADR;
630 652
 	initrd_image = NULL;
631 653
 	initrd_address = DEFAULT_INITRDADR;
  654
+	log_path = NULL;
632 655
 	while((opt = getopt_long(argc, argv, "", options, NULL)) != -1) {
633 656
 		if(opt == '?') {
634 657
 			print_usage();
@@ -672,6 +695,10 @@ int main(int argc, char *argv[])
672 695
 				initrd_address = strtoul(optarg, &endptr, 0);
673 696
 				if(*endptr != 0) initrd_address = 0;
674 697
 				break;
  698
+			case OPTION_LOG:
  699
+				free(log_path);
  700
+				log_path = strdup(optarg);
  701
+				break;
675 702
 		}
676 703
 	}
677 704
 
@@ -693,7 +720,8 @@ int main(int argc, char *argv[])
693 720
 	do_terminal(serial_port, doublerate, gdb_passthrough,
694 721
 		kernel_image, kernel_address,
695 722
 		cmdline, cmdline_address,
696  
-		initrd_image, initrd_address);
  723
+		initrd_image, initrd_address,
  724
+		log_path);
697 725
 	
698 726
 	/* Restore stdin/out into their previous state */
699 727
 	tcsetattr(0, TCSANOW, &otty);

No commit comments for this range

Something went wrong with that request. Please try again.