FreeCalypso > hg > freecalypso-sw
annotate loadtools/ltdispatch.c @ 941:6b0b2f6dbb20
gsm-fw/services/ffs/drv.c: AMD multi-bank flash driver fixed for Pirelli
and future FreeCalypso hardware
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 01 Nov 2015 00:07:09 +0000 |
parents | 8891c3d0c68a |
children |
rev | line source |
---|---|
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the command dispatch for fc-loadtool |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <ctype.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <string.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <strings.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdlib.h> |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
52
b015036286f3
fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
36
diff
changeset
|
11 extern int cmd_baud(); |
35
05af070c4b60
loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
12 extern int cmd_crc32(); |
70
e2698daf40d1
dieid implemented in fc-loadtool as well
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
65
diff
changeset
|
13 extern int cmd_dieid(); |
36
65111e6eee9e
loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
14 extern int cmd_dump2bin(); |
65111e6eee9e
loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
15 extern int cmd_dump2srec(); |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
16 extern int cmd_exec(); |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
22
diff
changeset
|
17 extern int cmd_exit(); |
58
1f9302b6f342
fc-loadtool: started flash/flash2 command implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
57
diff
changeset
|
18 extern int cmd_flash(); |
105
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
19 extern int cmd_help(); |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 extern int loadtool_cmd_passthru(); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 static struct cmdtab { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 char *cmd; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 int minargs; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 int maxargs; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 int (*func)(); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 } cmdtab[] = { |
395
8891c3d0c68a
fc-loadtool: pass abb[rw] commands through to loadagent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
105
diff
changeset
|
28 {"abbr", 2, 2, loadtool_cmd_passthru}, |
8891c3d0c68a
fc-loadtool: pass abb[rw] commands through to loadagent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
105
diff
changeset
|
29 {"abbw", 3, 3, loadtool_cmd_passthru}, |
52
b015036286f3
fc-loadtool: fast-baud communication with loadagent implemented, works!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
36
diff
changeset
|
30 {"baud", 0, 1, cmd_baud}, |
35
05af070c4b60
loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
29
diff
changeset
|
31 {"crc32", 2, 2, cmd_crc32}, |
71
0c1480317c18
dieid via fc-loadtool: added ability to save to a file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
70
diff
changeset
|
32 {"dieid", 0, 1, cmd_dieid}, |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 {"dump", 2, 2, loadtool_cmd_passthru}, |
36
65111e6eee9e
loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
34 {"dump2bin", 3, 3, cmd_dump2bin}, |
65111e6eee9e
loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
35
diff
changeset
|
35 {"dump2srec", 3, 3, cmd_dump2srec}, |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
36 {"exec", 1, 1, cmd_exec}, |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
22
diff
changeset
|
37 {"exit", 0, 1, cmd_exit}, |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
38 {"flash", 1, 5, cmd_flash}, |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
58
diff
changeset
|
39 {"flash2", 1, 5, cmd_flash}, |
105
02cb0206aa47
fc-loadtool help implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
71
diff
changeset
|
40 {"help", 0, 2, cmd_help}, |
27
ae6294b8a015
loadtool: exit jump0 implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
22
diff
changeset
|
41 {"quit", 0, 1, cmd_exit}, |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 {"r8", 1, 1, loadtool_cmd_passthru}, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 {"r16", 1, 1, loadtool_cmd_passthru}, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 {"r32", 1, 1, loadtool_cmd_passthru}, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 {"w8", 2, 2, loadtool_cmd_passthru}, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 {"w16", 2, 2, loadtool_cmd_passthru}, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 {"w32", 2, 2, loadtool_cmd_passthru}, |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 {0, 0, 0, 0} |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 }; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
51 loadtool_dispatch_cmd(cmd, is_script) |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
52 char *cmd; |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 char *argv[10]; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 char *cp, **ap; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 struct cmdtab *tp; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
58 for (cp = cmd; isspace(*cp); cp++) |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 ; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 if (!*cp || *cp == '#') |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 return(0); |
29
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
62 if (is_script) |
dacf45e3d20f
loadtool: scripting functionality implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
27
diff
changeset
|
63 printf("Script command: %s\n", cp); |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 argv[0] = cp; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 while (*cp && !isspace(*cp)) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 cp++; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (*cp) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 *cp++ = '\0'; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 for (tp = cmdtab; tp->cmd; tp++) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 if (!strcmp(tp->cmd, argv[0])) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 break; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 if (!tp->func) { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 fprintf(stderr, "error: no such command\n"); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 return(-1); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 } |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 for (ap = argv + 1; ; ) { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 while (isspace(*cp)) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 cp++; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (!*cp || *cp == '#') |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 break; |
57
10996c267de4
loadtools old buglet: off by 1 error in the max-arguments logic in cmd parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
52
diff
changeset
|
81 if (ap - argv - 1 >= tp->maxargs) { |
22
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 fprintf(stderr, "error: too many arguments\n"); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 return(-1); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 } |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 *ap++ = cp; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 while (*cp && !isspace(*cp)) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 cp++; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 if (*cp) |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 *cp++ = '\0'; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 if (ap - argv - 1 < tp->minargs) { |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 fprintf(stderr, "error: too few arguments\n"); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 return(-1); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 } |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 *ap = 0; |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 return tp->func(ap - argv, argv); |
e658a84b37df
loadtool coming along
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 } |