annotate loadtools/ltmisc.c @ 659:761e8b0c65b0

loadagent: first step in implementation of binary flash programming
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 03 Mar 2020 17:55:20 +0000
parents dfe6ba3611cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module is a place to implement little miscellaneous fc-loadtool
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * commands which don't belong anywhere else.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
646
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
7 #include <sys/time.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
640
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
10 #include <stdlib.h>
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
11
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
12 cmd_crc32(argc, argv)
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
13 char **argv;
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
14 {
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
15 u_long area_base, area_len;
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
16 char *strtoul_endp;
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
17 u_long crc_result;
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
18 int stat;
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
19
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
20 area_base = strtoul(argv[1], &strtoul_endp, 16);
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
21 if (*strtoul_endp) {
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
22 inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n");
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
23 return(-1);
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
24 }
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
25 area_len = strtoul(argv[2], &strtoul_endp, 16);
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
26 if (*strtoul_endp)
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
27 goto inv;
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
28 stat = crc32_on_target(area_base, area_len, &crc_result);
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
29 if (stat == 0)
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
30 printf("%08lX\n", crc_result);
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
31 return(stat);
5385aca4d813 fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
32 }
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 cmd_dieid(argc, argv)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 char **argv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 static uint32_t addrs[4] = {0xFFFEF010, 0xFFFEF012, 0xFFFEF014,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 0xFFFEF016};
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 uint16_t data[4];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 int i, stat;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 FILE *of;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (i = 0; i < 4; i++) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 stat = do_r16(addrs[i], data + i);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (stat)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(stat);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 printf("%08lX: %04X\n", (u_long)addrs[i], (int)data[i]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (argc < 2)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 of = fopen(argv[1], "w");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!of) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 perror(argv[1]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 for (i = 0; i < 4; i++)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 fprintf(of, "%08lX: %04X\n", (u_long)addrs[i], (int)data[i]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fclose(of);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 printf("Saved to %s\n", argv[1]);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
646
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
62
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
63 cmd_timeout_cal(argc, argv)
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
64 char **argv;
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
65 {
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
66 char *targv[3];
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
67 struct timeval time1, time2, diff;
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
68 int rc;
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
69
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
70 targv[0] = "sertimeout";
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
71 targv[1] = argv[1];
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
72 targv[2] = 0;
647
dfe6ba3611cd loadtool timeout-cal command: stupid bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 646
diff changeset
73 if (tpinterf_make_cmd(targv) < 0) {
646
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
74 fprintf(stderr, "error: unable to form target command\n");
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
75 return(-1);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
76 }
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
77 if (tpinterf_send_cmd() < 0)
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
78 return(-1);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
79 gettimeofday(&time1, 0);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
80 rc = tpinterf_pass_output(60);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
81 gettimeofday(&time2, 0);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
82 if (rc)
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
83 return(rc);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
84 timersub(&time2, &time1, &diff);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
85 printf("%u.%06u s\n", (unsigned) diff.tv_sec, (unsigned) diff.tv_usec);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
86 return(0);
0d199c6a6ea4 fc-loadtool: timeout-cal internal developer command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
87 }