changeset 683:ecea01f65146

loadtools: implemented -t option for boot ROM wait timeout
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 10 Mar 2020 07:05:32 +0000
parents a7496a1e0df7
children 7674abe34c25
files loadtools/bpmain.c loadtools/clmain.c loadtools/ltmain.c loadtools/romdump.c loadtools/romload.c loadtools/sertool.c
diffstat 6 files changed, 43 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/bpmain.c	Tue Mar 10 04:10:05 2020 +0000
+++ b/loadtools/bpmain.c	Tue Mar 10 07:05:32 2020 +0000
@@ -27,7 +27,7 @@
 	int c;
 	char command[512];
 
-	while ((c = getopt(argc, argv, "a:b:c:C:h:H:i:P:r:")) != EOF)
+	while ((c = getopt(argc, argv, "a:b:c:C:h:H:i:P:r:t:")) != EOF)
 		switch (c) {
 		case 'a':
 			iramimage.filename = optarg;
@@ -59,6 +59,9 @@
 			if (!reattach)
 				exit(1);	/* error msg already printed */
 			continue;
+		case 't':
+			set_romload_timeout(optarg);
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
--- a/loadtools/clmain.c	Tue Mar 10 04:10:05 2020 +0000
+++ b/loadtools/clmain.c	Tue Mar 10 07:05:32 2020 +0000
@@ -37,7 +37,7 @@
 	int c;
 	struct baudrate *br;
 
-	while ((c = getopt(argc, argv, "+a:b:B:c:C:h:H:i:jP:r:")) != EOF)
+	while ((c = getopt(argc, argv, "+a:b:B:c:C:h:H:i:jP:r:t:")) != EOF)
 		switch (c) {
 		case 'a':
 			iramimage.filename = optarg;
@@ -79,6 +79,9 @@
 				exit(1);	/* error msg already printed */
 			xram_run_baudrate = br;
 			continue;
+		case 't':
+			set_romload_timeout(optarg);
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
--- a/loadtools/ltmain.c	Tue Mar 10 04:10:05 2020 +0000
+++ b/loadtools/ltmain.c	Tue Mar 10 07:05:32 2020 +0000
@@ -28,7 +28,7 @@
 	int c;
 	char command[512];
 
-	while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:r:")) != EOF)
+	while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:r:t:")) != EOF)
 		switch (c) {
 		case 'a':
 			iramimage.filename = optarg;
@@ -65,6 +65,9 @@
 			if (!reattach)
 				exit(1);	/* error msg already printed */
 			continue;
+		case 't':
+			set_romload_timeout(optarg);
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
--- a/loadtools/romdump.c	Tue Mar 10 04:10:05 2020 +0000
+++ b/loadtools/romdump.c	Tue Mar 10 07:05:32 2020 +0000
@@ -44,7 +44,7 @@
 	struct baudrate *br;
 	char *targv[2];
 
-	while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:")) != EOF)
+	while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:t:")) != EOF)
 		switch (c) {
 		case 'a':
 			iramimage.filename = optarg;
@@ -77,6 +77,9 @@
 			if (find_bootctrl_entry(optarg) < 0)
 				exit(1);	/* error msg already printed */
 			continue;
+		case 't':
+			set_romload_timeout(optarg);
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
--- a/loadtools/romload.c	Tue Mar 10 04:10:05 2020 +0000
+++ b/loadtools/romload.c	Tue Mar 10 07:05:32 2020 +0000
@@ -28,6 +28,7 @@
 struct baudrate *romload_baud_rate = baud_rate_table;	/* 1st entry default */
 
 static int beacon_interval = 13;	/* in milliseconds */
+static int beacon_timeout;		/* ditto */
 
 static u_char beacon_cmd[2] = {'<', 'i'};
 
@@ -81,6 +82,16 @@
 
 /*
  * The following function should be called by command line option
+ * parsers upon encountering the -t option.
+ */
+set_romload_timeout(arg)
+	char *arg;
+{
+	beacon_timeout = atoi(arg);
+}
+
+/*
+ * The following function should be called by command line option
  * parsers upon encountering the -b option.
  */
 set_romload_baudrate(arg)
@@ -151,11 +162,20 @@
 static
 send_beacons()
 {
+	int time_accum;
+
 	printf("Sending beacons to %s\n", target_ttydev);
-	do
+	for (time_accum = 0; ; ) {
 		write(target_fd, beacon_cmd, sizeof beacon_cmd);
-	while (expect_response(beacon_interval) != 'i');
-	return 0;
+		if (expect_response(beacon_interval) == 'i')
+			return 0;
+		time_accum += beacon_interval;
+		if (beacon_timeout && time_accum >= beacon_timeout) {
+			fprintf(stderr,
+				"Timeout waiting for boot ROM response\n");
+			exit(1);
+		}
+	}
 }
 
 static int
--- a/loadtools/sertool.c	Tue Mar 10 04:10:05 2020 +0000
+++ b/loadtools/sertool.c	Tue Mar 10 07:05:32 2020 +0000
@@ -26,7 +26,7 @@
 	extern int optind;
 	int c;
 
-	while ((c = getopt(argc, argv, "b:c:C:h:H:i:P:")) != EOF)
+	while ((c = getopt(argc, argv, "b:c:C:h:H:i:P:t:")) != EOF)
 		switch (c) {
 		case 'b':
 			set_romload_baudrate(optarg);
@@ -50,6 +50,9 @@
 			if (find_bootctrl_entry(optarg) < 0)
 				exit(1);	/* error msg already printed */
 			continue;
+		case 't':
+			set_romload_timeout(optarg);
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,