comparison loadtools/clmain.c @ 135:e4257294102b

fc-xram: execvp of secondary program implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 03 Nov 2013 00:14:40 +0000
parents ccc5161848c7
children 837ba1b47478
comparison
equal deleted inserted replaced
134:e0d56e9be8a2 135:e4257294102b
24 extern struct baudrate *find_baudrate_by_name(); 24 extern struct baudrate *find_baudrate_by_name();
25 25
26 struct baudrate *xram_load_baudrate; 26 struct baudrate *xram_load_baudrate;
27 struct baudrate *xram_run_baudrate = baud_rate_table; /* 1st entry default */ 27 struct baudrate *xram_run_baudrate = baud_rate_table; /* 1st entry default */
28 28
29 char **passon_argv;
30 int passon_argc;
31
29 main(argc, argv) 32 main(argc, argv)
30 char **argv; 33 char **argv;
31 { 34 {
32 extern char *optarg; 35 extern char *optarg;
33 extern int optind; 36 extern int optind;
34 int c; 37 int c;
35 struct baudrate *br; 38 struct baudrate *br;
36 39
37 while ((c = getopt(argc, argv, "a:b:B:h:H:i:n")) != EOF) 40 while ((c = getopt(argc, argv, "+a:b:B:h:H:i:nr:")) != EOF)
38 switch (c) { 41 switch (c) {
39 case 'a': 42 case 'a':
40 iramimage.filename = optarg; 43 iramimage.filename = optarg;
41 continue; 44 continue;
42 case 'b': 45 case 'b':
58 set_beacon_interval(optarg); 61 set_beacon_interval(optarg);
59 continue; 62 continue;
60 case 'n': 63 case 'n':
61 gta_modem_poweron = 0; 64 gta_modem_poweron = 0;
62 continue; 65 continue;
66 case 'r':
67 br = find_baudrate_by_name(optarg);
68 if (!br)
69 exit(1); /* error msg already printed */
70 xram_run_baudrate = br;
71 continue;
63 case '?': 72 case '?':
64 default: 73 default:
65 usage: fprintf(stderr, 74 usage: fprintf(stderr,
66 "usage: fc-xram [options] ttyport xramimage.srec [runbaud]\n"); 75 "usage: fc-xram [options] ttyport xramimage.srec [2ndprog]\n");
67 exit(1); 76 exit(1);
68 } 77 }
69 if (argc - optind < 2) 78 if (argc - optind < 2)
70 goto usage; 79 goto usage;
71 target_ttydev = argv[optind]; 80 target_ttydev = argv[optind];
72 xramimage.filename = argv[optind+1]; 81 xramimage.filename = argv[optind+1];
73 if (!iramimage.filename) 82 if (!iramimage.filename)
74 iramimage.filename = default_loadagent_image; 83 iramimage.filename = default_loadagent_image;
75 if (argc - optind >= 3) { 84 if (argc - optind >= 3) {
76 if (argc - optind > 3) 85 passon_argv = argv + optind + 2;
77 goto usage; 86 passon_argc = argc - optind - 2;
78 br = find_baudrate_by_name(argv[optind+2]);
79 if (!br)
80 exit(1); /* error msg already printed */
81 xram_run_baudrate = br;
82 } 87 }
83 88
84 open_target_serial(); 89 open_target_serial();
85 perform_romload(); 90 perform_romload();
86 /* loadagent should be running now */ 91 /* loadagent should be running now */
97 if (c) 102 if (c)
98 exit(1); 103 exit(1);
99 } 104 }
100 printf("Sending XRAM image to loadagent\n"); 105 printf("Sending XRAM image to loadagent\n");
101 perform_chain_load(); 106 perform_chain_load();
107 if (passon_argv)
108 exec_2nd_prog();
102 tty_passthru(); 109 tty_passthru();
103 exit(0); 110 exit(0);
104 } 111 }
112
113 exec_2nd_prog()
114 {
115 char **execp_argv;
116 char **sp, **dp;
117 extern int target_fd;
118 char desc_arg[16];
119
120 sprintf(desc_arg, "-d%d", target_fd);
121 execp_argv = (char **) malloc(sizeof(char *) * (passon_argc + 2));
122 if (!execp_argv) {
123 perror("malloc argv for execvp");
124 exit(1);
125 }
126 sp = passon_argv;
127 dp = execp_argv;
128 *dp++ = *sp++;
129 *dp++ = desc_arg;
130 while (*sp)
131 *dp++ = *sp++;
132 *dp = NULL;
133 execvp(execp_argv[0], execp_argv);
134 fprintf(stderr, "Unable to execvp %s\n", passon_argv[0]);
135 exit(1);
136 }