FreeCalypso > hg > freecalypso-tools
annotate loadtools/ltdump.c @ 845:aec320fe2653
fc-tmsync: new madc command reads all 8 MADC channels
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 31 Jul 2021 22:23:05 +0000 |
parents | 185c9bf208d3 |
children |
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 implements the dump2bin and dump2srec functionality |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * of fc-loadtool. |
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> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <time.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
14 extern uint32_t crc32_table[]; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static char dumpsrec_s0_line[] = "S007000044554D50C2\n"; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static char dumpsrec_s7_line[] = "S70500000000FA\n"; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
19 write_block_in_srec(buf, addr, blklen, outfile) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
20 u_char *buf; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
21 uint32_t addr; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
22 unsigned blklen; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
23 FILE *outfile; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
24 { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
25 unsigned remain, reclen, n; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
26 u_char binrec[38], accum; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
27 |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
28 for (remain = blklen; remain; remain -= reclen) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
29 reclen = 32; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
30 if (remain < reclen) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
31 reclen = remain; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
32 binrec[0] = reclen + 5; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
33 binrec[1] = addr >> 24; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
34 binrec[2] = addr >> 16; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
35 binrec[3] = addr >> 8; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
36 binrec[4] = addr; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
37 bcopy(buf, binrec + 5, reclen); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
38 accum = 0; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
39 for (n = 0; n < reclen + 5; n++) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
40 accum += binrec[n]; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
41 binrec[n] = ~accum; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
42 putc('S', outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
43 putc('3', outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
44 for (n = 0; n < reclen + 6; n++) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
45 fprintf(outfile, "%02X", binrec[n]); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
46 putc('\n', outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
47 buf += reclen; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
48 addr += reclen; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 loadtool_memdump(start_addr, area_len, filename, fmt_srec) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 u_long start_addr, area_len; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 char *filename; |
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 u_long target_crc_init, target_crc_fin; |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
57 FILE *dump_outfile; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
58 uint32_t dump_nextaddr, dump_crcaccum; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
59 uint32_t dump_total_len, dump_progress_len, dump_remain; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
60 unsigned blklen, n; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 char *target_argv[4], target_arg1[10], target_arg2[10]; |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
62 u_char recvbuf[8192], expect_blkhdr[8]; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
63 time_t dump_initial_time, dump_last_time, curtime; |
610
98474043ecdd
fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
64 unsigned duration, mm, ss; |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
65 int rc; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 printf("Requesting initial CRC-32 of the area from target...\n"); |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
68 rc = crc32_on_target(start_addr, area_len, &target_crc_init); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
69 if (rc) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
70 return(rc); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 printf("got %08lX\n", target_crc_init); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 dump_outfile = fopen(filename, "w"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (!dump_outfile) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 perror(filename); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 dump_nextaddr = start_addr; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 dump_crcaccum = 0xFFFFFFFF; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 dump_total_len = area_len; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 dump_progress_len = 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 printf("Requesting memory dump...\n"); |
610
98474043ecdd
fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
83 time(&dump_initial_time); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 sprintf(target_arg1, "%lx", start_addr); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 sprintf(target_arg2, "%lx", area_len); |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
86 target_argv[0] = "BINDUMP"; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 target_argv[1] = target_arg1; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 target_argv[2] = target_arg2; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 target_argv[3] = 0; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 tpinterf_make_cmd(target_argv); |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
91 rc = tpinterf_send_cmd(); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
92 if (rc < 0) { |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 fclose(dump_outfile); |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
94 return(rc); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
96 expect_blkhdr[0] = 0x55; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
97 expect_blkhdr[1] = 0xAA; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
98 for (dump_remain = dump_total_len; dump_remain; dump_remain -= blklen) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
99 blklen = 8192; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
100 if (dump_remain < blklen) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
101 blklen = dump_remain; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
102 rc = collect_binblock_from_target(recvbuf, 8, 2); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
103 if (rc < 0) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
104 fclose(dump_outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
105 return(rc); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
106 } |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
107 expect_blkhdr[2] = dump_nextaddr >> 24; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
108 expect_blkhdr[3] = dump_nextaddr >> 16; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
109 expect_blkhdr[4] = dump_nextaddr >> 8; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
110 expect_blkhdr[5] = dump_nextaddr; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
111 expect_blkhdr[6] = blklen >> 8; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
112 expect_blkhdr[7] = blklen; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
113 if (bcmp(recvbuf, expect_blkhdr, 8)) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
114 fprintf(stderr, |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
115 "error: expected block header mismatch\n"); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
116 fclose(dump_outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
117 return(rc); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
118 } |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
119 rc = collect_binblock_from_target(recvbuf, blklen, 2); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
120 if (rc < 0) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
121 fclose(dump_outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
122 return(rc); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
123 } |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
124 /* save the bits */ |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
125 if (fmt_srec) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
126 if (!dump_progress_len) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
127 fputs(dumpsrec_s0_line, dump_outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
128 write_block_in_srec(recvbuf, dump_nextaddr, blklen, |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
129 dump_outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
130 } else |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
131 fwrite(recvbuf, 1, blklen, dump_outfile); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
132 /* update running CRC */ |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
133 for (n = 0; n < blklen; n++) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
134 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^ |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
135 recvbuf[n]] ^ |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
136 (dump_crcaccum >> 8); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
137 /* progress indication */ |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
138 dump_progress_len += blklen; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
139 n = dump_progress_len * 100 / dump_total_len; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
140 time(&curtime); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
141 if (curtime != dump_last_time || n == 100) { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
142 printf("\rRx %lu out of %lu bytes (%u%%)", |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
143 (u_long) dump_progress_len, |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
144 (u_long) dump_total_len, n); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
145 fflush(stdout); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
146 } |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
147 dump_nextaddr += blklen; |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
148 dump_last_time = curtime; |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 putchar('\n'); /* after last progress line */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 /* sanity checks */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (dump_nextaddr != start_addr + area_len) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 fclose(dump_outfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 "error: received dump length does not match expected\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 if (dump_crcaccum != (uint32_t) target_crc_init) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 fclose(dump_outfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 fprintf(stderr, "error: CRC mismatch (computed %lX)\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 (u_long) dump_crcaccum); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 if (fmt_srec) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 fputs(dumpsrec_s7_line, dump_outfile); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 fclose(dump_outfile); |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
167 |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
168 /* collect '=' at the end */ |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
169 rc = collect_binblock_from_target(recvbuf, 1, 1); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
170 if (rc < 0) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
171 return(rc); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
172 time(&dump_last_time); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
173 if (recvbuf[0] != '=') { |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
174 fprintf(stderr, "error: \'=\' not received at the end\n"); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
175 return(-1); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
176 } |
610
98474043ecdd
fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
177 duration = dump_last_time - dump_initial_time; |
98474043ecdd
fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
178 mm = duration / 60; |
98474043ecdd
fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
179 ss = duration - mm * 60; |
692
185c9bf208d3
loadtools operation time reporting: two digits for seconds
Mychaela Falconia <falcon@freecalypso.org>
parents:
649
diff
changeset
|
180 printf("Dump stream received in %um%02us\n", mm, ss); |
610
98474043ecdd
fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
181 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 printf("Requesting another CRC-32 of the area from target...\n"); |
641
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
183 rc = crc32_on_target(start_addr, area_len, &target_crc_fin); |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
184 if (rc) |
b4070292640a
fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents:
640
diff
changeset
|
185 return(rc); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 if (target_crc_fin == target_crc_init) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 printf("match, dump successful\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 } else { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 fprintf(stderr, "mismatch: got %lX this time\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 target_crc_fin); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 cmd_dump2bin(argc, argv) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 char **argv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 u_long area_base, area_len; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 char *strtoul_endp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 area_base = strtoul(argv[1], &strtoul_endp, 16); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 if (*strtoul_endp) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 inv: fprintf(stderr, "usage: dump2bin hex-start hex-len outfile\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 area_len = strtoul(argv[2], &strtoul_endp, 16); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 if (*strtoul_endp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 goto inv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 return loadtool_memdump(area_base, area_len, argv[3], 0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 cmd_dump2srec(argc, argv) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 char **argv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 u_long area_base, area_len; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 char *strtoul_endp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 area_base = strtoul(argv[1], &strtoul_endp, 16); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 if (*strtoul_endp) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 inv: fprintf(stderr, "usage: dump2srec hex-start hex-len outfile\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 area_len = strtoul(argv[2], &strtoul_endp, 16); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 if (*strtoul_endp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 goto inv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 return loadtool_memdump(area_base, area_len, argv[3], 1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 } |