# HG changeset patch # User Mychaela Falconia # Date 1583884918 0 # Node ID 752aef91cc959b2db5ddf9bbaab97b658a12220d # Parent 7de96d468c47c34c394805c89331747ba937c056 fc-loadtool batch mode extended to support single commands diff -r 7de96d468c47 -r 752aef91cc95 loadtools/ltmain.c --- 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 #include #include +#include +#include #include #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);