comparison loadtools/ltmain.c @ 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 ecea01f65146
children
comparison
equal deleted inserted replaced
685:7de96d468c47 686:752aef91cc95
4 4
5 #include <sys/types.h> 5 #include <sys/types.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
9 #include <unistd.h> 11 #include <unistd.h>
10 #include "srecreader.h" 12 #include "srecreader.h"
11 13
12 char *target_ttydev; 14 char *target_ttydev;
13 15
25 { 27 {
26 extern char *optarg; 28 extern char *optarg;
27 extern int optind; 29 extern int optind;
28 int c; 30 int c;
29 char command[512]; 31 char command[512];
32 char *batch_script;
30 33
31 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:r:t:")) != EOF) 34 while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:r:t:")) != EOF)
32 switch (c) { 35 switch (c) {
33 case 'a': 36 case 'a':
34 iramimage.filename = optarg; 37 iramimage.filename = optarg;
69 set_romload_timeout(optarg); 72 set_romload_timeout(optarg);
70 continue; 73 continue;
71 case '?': 74 case '?':
72 default: 75 default:
73 usage: fprintf(stderr, 76 usage: fprintf(stderr,
74 "usage: fc-loadtool [options] ttyport [command-script]\n"); 77 "usage: fc-loadtool [options] ttyport [batch command]\n");
75 exit(1); 78 exit(1);
76 } 79 }
77 if (argc - optind < 1 || argc - optind > 2) 80 if (argc - optind < 1)
78 goto usage; 81 goto usage;
79 target_ttydev = argv[optind]; 82 target_ttydev = argv[optind];
80 if (!iramimage.filename) 83 if (!iramimage.filename)
81 iramimage.filename = default_loadagent_image; 84 iramimage.filename = default_loadagent_image;
85 if (argc - optind > 1) {
86 if (reattach) {
87 fprintf(stderr,
88 "error: -r option and batch mode are incompatible\n");
89 exit(1);
90 }
91 if (argc - optind == 2)
92 batch_script = argv[optind+1];
93 else if (!strcmp(argv[optind+1], "exec")) {
94 if (argc - optind == 3)
95 batch_script = argv[optind+2];
96 else
97 goto invalid_batch;
98 } else if (!strcmp(argv[optind+1], "flash") ||
99 !strcmp(argv[optind+1], "flash2"))
100 batch_script = 0;
101 else {
102 invalid_batch: fprintf(stderr,
103 "error: non-understood batch mode command\n");
104 exit(1);
105 }
106 }
82 107
83 open_serial_port(target_ttydev); 108 open_serial_port(target_ttydev);
84 if (reattach) 109 if (reattach)
85 set_serial_baudrate(reattach); 110 set_serial_baudrate(reattach);
86 else { 111 else {
102 if (batch_baud) { 127 if (batch_baud) {
103 c = loadagent_switch_baud(batch_baud); 128 c = loadagent_switch_baud(batch_baud);
104 if (c) 129 if (c)
105 exit(1); 130 exit(1);
106 } 131 }
107 printf("Executing command script %s\n", argv[optind+1]); 132 if (batch_script) {
108 c = loadtool_exec_script(argv[optind+1], 0); 133 printf("Executing command script %s\n",
134 batch_script);
135 c = loadtool_exec_script(batch_script, 0);
136 } else {
137 printf("Executing batch command\n");
138 c = cmd_flash(argc - optind - 1,
139 argv + optind + 1);
140 }
109 if (c) 141 if (c)
110 exit(1); 142 exit(1);
111 default_exit(0); 143 default_exit(0);
112 } 144 }
113 } 145 }