changeset 686:752aef91cc95

fc-loadtool batch mode extended to support single commands
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 11 Mar 2020 00:01:58 +0000
parents 7de96d468c47
children d2e4a2274497
files loadtools/ltmain.c
diffstat 1 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/ltmain.c	Tue Mar 10 07:38:15 2020 +0000
+++ b/loadtools/ltmain.c	Wed Mar 11 00:01:58 2020 +0000
@@ -6,6 +6,8 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <strings.h>
 #include <unistd.h>
 #include "srecreader.h"
 
@@ -27,6 +29,7 @@
 	extern int optind;
 	int c;
 	char command[512];
+	char *batch_script;
 
 	while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:r:t:")) != EOF)
 		switch (c) {
@@ -71,14 +74,36 @@
 		case '?':
 		default:
 usage:			fprintf(stderr,
-		"usage: fc-loadtool [options] ttyport [command-script]\n");
+		"usage: fc-loadtool [options] ttyport [batch command]\n");
 			exit(1);
 		}
-	if (argc - optind < 1 || argc - optind > 2)
+	if (argc - optind < 1)
 		goto usage;
 	target_ttydev = argv[optind];
 	if (!iramimage.filename)
 		iramimage.filename = default_loadagent_image;
+	if (argc - optind > 1) {
+		if (reattach) {
+			fprintf(stderr,
+			"error: -r option and batch mode are incompatible\n");
+			exit(1);
+		}
+		if (argc - optind == 2)
+			batch_script = argv[optind+1];
+		else if (!strcmp(argv[optind+1], "exec")) {
+			if (argc - optind == 3)
+				batch_script = argv[optind+2];
+			else
+				goto invalid_batch;
+		} else if (!strcmp(argv[optind+1], "flash") ||
+			   !strcmp(argv[optind+1], "flash2"))
+			batch_script = 0;
+		else {
+invalid_batch:		fprintf(stderr,
+				"error: non-understood batch mode command\n");
+			exit(1);
+		}
+	}
 
 	open_serial_port(target_ttydev);
 	if (reattach)
@@ -104,8 +129,15 @@
 				if (c)
 					exit(1);
 			}
-			printf("Executing command script %s\n", argv[optind+1]);
-			c = loadtool_exec_script(argv[optind+1], 0);
+			if (batch_script) {
+				printf("Executing command script %s\n",
+					batch_script);
+				c = loadtool_exec_script(batch_script, 0);
+			} else {
+				printf("Executing batch command\n");
+				c = cmd_flash(argc - optind - 1,
+					      argv + optind + 1);
+			}
 			if (c)
 				exit(1);
 			default_exit(0);