diff loadtools/romload.c @ 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 46d7ed4ee634
children
line wrap: on
line diff
--- 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