FreeCalypso > hg > freecalypso-tools
annotate loadtools/secondprog.c @ 700:db9a8e88e63f
target-utils lunadrv program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 May 2020 02:19:51 +0000 |
parents | 064d4eedb3a6 |
children |
rev | line source |
---|---|
204
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains the code for passing the serial channel to a |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * second program, used by fc-iram and fc-xram. |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <unistd.h> |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern char **passon_argv; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern int passon_argc; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 exec_2nd_prog() |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **execp_argv; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char **sp, **dp; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern int target_fd; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char desc_arg[16]; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 sprintf(desc_arg, "-d%d", target_fd); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 execp_argv = (char **) malloc(sizeof(char *) * (passon_argc + 2)); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!execp_argv) { |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 perror("malloc argv for execvp"); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 sp = passon_argv; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 dp = execp_argv; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 *dp++ = *sp++; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 *dp++ = desc_arg; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 while (*sp) |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *dp++ = *sp++; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 *dp = NULL; |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 execvp(execp_argv[0], execp_argv); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, "Unable to execvp %s\n", passon_argv[0]); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 exit(1); |
064d4eedb3a6
loadtools: second program invokation support added to fc-iram like in fc-xram
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |