annotate loadtools/ltdump.c @ 641:b4070292640a

fc-loadtool: dump facility changed to use BINDUMP
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 01 Mar 2020 20:06:21 +0000
parents 5385aca4d813
children 141372e0d28f
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 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>
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
7 #include <sys/time.h>
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
8 #include <sys/errno.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <time.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
16 extern int errno;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
18 extern int target_fd;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
19 extern uint32_t crc32_table[];
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static char dumpsrec_s0_line[] = "S007000044554D50C2\n";
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static char dumpsrec_s7_line[] = "S70500000000FA\n";
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
24 collect_binblock_from_target(buf, expect_len, timeout)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
25 u_char *buf;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
26 unsigned expect_len;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
28 fd_set fds;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
29 struct timeval tv;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
30 unsigned rcvd;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
31 int cc;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
33 for (rcvd = 0; rcvd < expect_len; ) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
34 FD_ZERO(&fds);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
35 FD_SET(target_fd, &fds);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
36 tv.tv_sec = timeout;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
37 tv.tv_usec = 0;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
38 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
39 if (cc < 0) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
40 if (errno == EINTR)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
41 continue;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
42 perror("select");
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
43 return(-1);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
44 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
45 if (cc < 1) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr,
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
47 "error: timeout waiting for binary block\n");
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
48 return(-1);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
49 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
50 cc = read(target_fd, buf + rcvd, expect_len - rcvd);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
51 if (cc <= 0) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
52 perror("read after successful select");
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
55 rcvd += cc;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
57 return(0);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
58 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
59
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
60 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
61 u_char *buf;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
62 uint32_t addr;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
63 unsigned blklen;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
64 FILE *outfile;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
65 {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
66 unsigned remain, reclen, n;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
67 u_char binrec[38], accum;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
68
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
69 for (remain = blklen; remain; remain -= reclen) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
70 reclen = 32;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
71 if (remain < reclen)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
72 reclen = remain;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
73 binrec[0] = reclen + 5;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
74 binrec[1] = addr >> 24;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
75 binrec[2] = addr >> 16;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
76 binrec[3] = addr >> 8;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
77 binrec[4] = addr;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
78 bcopy(buf, binrec + 5, reclen);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
79 accum = 0;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
80 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
81 accum += binrec[n];
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
82 binrec[n] = ~accum;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
83 putc('S', outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
84 putc('3', outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
85 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
86 fprintf(outfile, "%02X", binrec[n]);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
87 putc('\n', outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
88 buf += reclen;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
89 addr += reclen;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 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
94 u_long start_addr, area_len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 char *filename;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 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
98 FILE *dump_outfile;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
99 uint32_t dump_nextaddr, dump_crcaccum;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
100 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
101 unsigned blklen, n;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 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
103 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
104 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
105 unsigned duration, mm, ss;
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
106 int rc;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 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
109 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
110 if (rc)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
111 return(rc);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 printf("got %08lX\n", target_crc_init);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 dump_outfile = fopen(filename, "w");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 if (!dump_outfile) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 perror(filename);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 dump_nextaddr = start_addr;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 dump_crcaccum = 0xFFFFFFFF;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 dump_total_len = area_len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 dump_progress_len = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 printf("Requesting memory dump...\n");
610
98474043ecdd fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
124 time(&dump_initial_time);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 sprintf(target_arg1, "%lx", start_addr);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 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
127 target_argv[0] = "BINDUMP";
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 target_argv[1] = target_arg1;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 target_argv[2] = target_arg2;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 target_argv[3] = 0;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 tpinterf_make_cmd(target_argv);
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
132 rc = tpinterf_send_cmd();
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
133 if (rc < 0) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 fclose(dump_outfile);
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
135 return(rc);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
137 expect_blkhdr[0] = 0x55;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
138 expect_blkhdr[1] = 0xAA;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
139 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
140 blklen = 8192;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
141 if (dump_remain < blklen)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
142 blklen = dump_remain;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
143 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
144 if (rc < 0) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
145 fclose(dump_outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
146 return(rc);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
147 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
148 expect_blkhdr[2] = dump_nextaddr >> 24;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
149 expect_blkhdr[3] = dump_nextaddr >> 16;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
150 expect_blkhdr[4] = dump_nextaddr >> 8;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
151 expect_blkhdr[5] = dump_nextaddr;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
152 expect_blkhdr[6] = blklen >> 8;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
153 expect_blkhdr[7] = blklen;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
154 if (bcmp(recvbuf, expect_blkhdr, 8)) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
155 fprintf(stderr,
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
156 "error: expected block header mismatch\n");
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
157 fclose(dump_outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
158 return(rc);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
159 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
160 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
161 if (rc < 0) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
162 fclose(dump_outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
163 return(rc);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
164 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
165 /* save the bits */
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
166 if (fmt_srec) {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
167 if (!dump_progress_len)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
168 fputs(dumpsrec_s0_line, dump_outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
169 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
170 dump_outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
171 } else
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
172 fwrite(recvbuf, 1, blklen, dump_outfile);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
173 /* update running CRC */
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
174 for (n = 0; n < blklen; n++)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
175 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
176 recvbuf[n]] ^
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
177 (dump_crcaccum >> 8);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
178 /* progress indication */
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
179 dump_progress_len += blklen;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
180 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
181 time(&curtime);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
182 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
183 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
184 (u_long) dump_progress_len,
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
185 (u_long) dump_total_len, n);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
186 fflush(stdout);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
187 }
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
188 dump_nextaddr += blklen;
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
189 dump_last_time = curtime;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 putchar('\n'); /* after last progress line */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 /* sanity checks */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 if (dump_nextaddr != start_addr + area_len) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 fclose(dump_outfile);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 fprintf(stderr,
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 "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
197 return(-1);
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 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
200 fclose(dump_outfile);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 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
202 (u_long) dump_crcaccum);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 if (fmt_srec)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 fputs(dumpsrec_s7_line, dump_outfile);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 fclose(dump_outfile);
641
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
208
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
209 /* collect '=' at the end */
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
210 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
211 if (rc < 0)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
212 return(rc);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
213 time(&dump_last_time);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
214 if (recvbuf[0] != '=') {
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
215 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
216 return(-1);
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
217 }
610
98474043ecdd fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
218 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
219 mm = duration / 60;
98474043ecdd fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
220 ss = duration - mm * 60;
98474043ecdd fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
221 printf("Dump stream received in %um%us\n", mm, ss);
98474043ecdd fc-loadtool dump2file operations: added Rx time reporting
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
222
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 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
224 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
225 if (rc)
b4070292640a fc-loadtool: dump facility changed to use BINDUMP
Mychaela Falconia <falcon@freecalypso.org>
parents: 640
diff changeset
226 return(rc);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 if (target_crc_fin == target_crc_init) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 printf("match, dump successful\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 } else {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 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
232 target_crc_fin);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 cmd_dump2bin(argc, argv)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 char **argv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 u_long area_base, area_len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 char *strtoul_endp;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 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
244 if (*strtoul_endp) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 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
246 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 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
249 if (*strtoul_endp)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 goto inv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 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
252 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 cmd_dump2srec(argc, argv)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 char **argv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 u_long area_base, area_len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 char *strtoul_endp;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 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
261 if (*strtoul_endp) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 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
263 return(-1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 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
266 if (*strtoul_endp)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 goto inv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 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
269 }