annotate loadtools/ltdump.c @ 275:cedf09b6b5ac

started laying the foundation for fc-fsio host utility
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Feb 2014 20:27:15 +0000
parents b3ed63722eb5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the dump2bin and dump2srec functionality
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * of fc-loadtool.
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdint.h>
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <stdlib.h>
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
12 #include <time.h>
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
14 extern uint32_t crc32_table[];
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern char target_response_line[];
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 crc32_on_target(area_base, area_len, retptr)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 u_long area_base, area_len, *retptr;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 char arg1[10], arg2[10], *argv[4];
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 int stat;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 char *strtoul_endp;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 sprintf(arg1, "%lx", area_base);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 sprintf(arg2, "%lx", area_len);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 argv[0] = "crc32";
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 argv[1] = arg1;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 argv[2] = arg2;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 argv[3] = 0;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 tpinterf_make_cmd(argv);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 if (tpinterf_send_cmd() < 0)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 return(-1);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 stat = tpinterf_capture_output_oneline(10); /* 10 s timeout */
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 if (stat != 1) {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 errout: fprintf(stderr, "error: malformed response to crc32 command\n");
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 return(-1);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 if (strlen(target_response_line) != 8)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 goto errout;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 *retptr = strtoul(target_response_line, &strtoul_endp, 16);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 if (strtoul_endp != target_response_line + 8)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 goto errout;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 return(0);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 cmd_crc32(argc, argv)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 char **argv;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 u_long area_base, area_len;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 char *strtoul_endp;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 u_long crc_result;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 int stat;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 area_base = strtoul(argv[1], &strtoul_endp, 16);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (*strtoul_endp) {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n");
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 return(-1);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 area_len = strtoul(argv[2], &strtoul_endp, 16);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 if (*strtoul_endp)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 goto inv;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 stat = crc32_on_target(area_base, area_len, &crc_result);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 if (stat == 0)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 printf("%08lX\n", crc_result);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 return(stat);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
68 /* the actual dump facility */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
69
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
70 static FILE *dump_outfile;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
71 static int dump_save_srec;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
72 static uint32_t dump_nextaddr, dump_crcaccum;
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
73 static uint32_t dump_total_len, dump_progress_len;
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
74 static u_char dump_binrec[0x86];
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
75 static time_t dump_last_time;
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
76
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
77 static char dumpsrec_s0_line[] = "S007000044554D50C2\n";
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
78 static char dumpsrec_s7_line[] = "S70500000000FA\n";
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
79
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
80 static
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
81 dump_receiver(line)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
82 char *line;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
83 {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
84 int i, b;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
85 u_char sr_cksum;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
86 uint32_t addr_from_srec;
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
87 time_t curtime;
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
88
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
89 if (strncmp(line, "S385", 4)) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
90 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
91 "error: target response is not the expected S385...\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
92 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
93 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
94 for (i = 0; i < 0x86; i++) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
95 b = decode_hex_byte(line + i*2 + 2);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
96 if (b < 0) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
97 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
98 "data from target: S-record hex decode error\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
99 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
100 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
101 dump_binrec[i] = b;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
102 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
103 sr_cksum = 0;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
104 for (i = 0; i < 0x86; i++)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
105 sr_cksum += dump_binrec[i];
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
106 if (sr_cksum != 0xFF) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
107 fprintf(stderr, "data from target: bad S-record checksum\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
108 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
109 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
110 /* basic S-record format OK; now verify the address */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
111 addr_from_srec = ((uint32_t) dump_binrec[1] << 24) |
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
112 ((uint32_t) dump_binrec[2] << 16) |
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
113 ((uint32_t) dump_binrec[3] << 8) |
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
114 (uint32_t) dump_binrec[4];
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
115 if (addr_from_srec != dump_nextaddr) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
116 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
117 "error: S3 record from target has the wrong address\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
118 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
119 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
120 /* all checks passed - save it */
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
121 if (dump_save_srec) {
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
122 if (!dump_progress_len)
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
123 fputs(dumpsrec_s0_line, dump_outfile);
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
124 fprintf(dump_outfile, "%s\n", line);
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
125 } else
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
126 fwrite(dump_binrec + 5, 1, 0x80, dump_outfile);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
127 /* update running CRC */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
128 for (i = 0; i < 0x80; i++)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
129 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
130 dump_binrec[i+5]] ^
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
131 (dump_crcaccum >> 8);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
132 /* progress indication */
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
133 dump_progress_len += 0x80;
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
134 i = dump_progress_len * 100 / dump_total_len;
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
135 time(&curtime);
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
136 if (curtime != dump_last_time || i == 100) {
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
137 printf("\rRx %lu out of %lu bytes (%i%%)",
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
138 (u_long) dump_progress_len, (u_long) dump_total_len, i);
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
139 fflush(stdout);
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
140 }
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
141 dump_nextaddr += 0x80;
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
142 dump_last_time = curtime;
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
143 return(1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
144 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
145
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
146 loadtool_memdump(start_addr, area_len, filename, fmt_srec)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
147 u_long start_addr, area_len;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
148 char *filename;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
149 {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
150 u_long target_crc_init, target_crc_fin;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
151 char *target_argv[4], target_arg1[10], target_arg2[10];
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
152 int stat;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
153
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
154 if (start_addr & 0x7F || area_len & 0x7F) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
155 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
156 "error: implementation limit: 128-byte alignment required\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
157 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
158 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
159 printf("Requesting initial CRC-32 of the area from target...\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
160 stat = crc32_on_target(start_addr, area_len, &target_crc_init);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
161 if (stat)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
162 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
163 printf("got %08lX\n", target_crc_init);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
164 dump_outfile = fopen(filename, "w");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
165 if (!dump_outfile) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
166 perror(filename);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
167 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
168 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
169 dump_save_srec = fmt_srec;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
170 dump_nextaddr = start_addr;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
171 dump_crcaccum = 0xFFFFFFFF;
94
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
172 dump_total_len = area_len;
1f035187e98f fc-loadtool dump2{bin,srec}: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 36
diff changeset
173 dump_progress_len = 0;
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
174
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
175 printf("Requesting memory dump...\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
176 sprintf(target_arg1, "%lx", start_addr);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
177 sprintf(target_arg2, "%lx", area_len);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
178 target_argv[0] = "DUMP";
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
179 target_argv[1] = target_arg1;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
180 target_argv[2] = target_arg2;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
181 target_argv[3] = 0;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
182 tpinterf_make_cmd(target_argv);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
183 stat = tpinterf_send_cmd();
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
184 if (stat < 0) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
185 fclose(dump_outfile);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
186 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
187 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
188 stat = tpinterf_capture_output(2, dump_receiver);
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
189 if (stat < 0) {
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
190 fclose(dump_outfile);
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
191 return(stat);
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
192 }
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
193 putchar('\n'); /* after last progress line */
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
194
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
195 /* sanity checks */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
196 if (dump_nextaddr != start_addr + area_len) {
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
197 fclose(dump_outfile);
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
198 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
199 "error: received dump length does not match expected\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
200 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
201 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
202 if (dump_crcaccum != (uint32_t) target_crc_init) {
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
203 fclose(dump_outfile);
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
204 fprintf(stderr, "error: CRC mismatch (computed %lX)\n",
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
205 (u_long) dump_crcaccum);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
206 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
207 }
98
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
208 if (fmt_srec)
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
209 fputs(dumpsrec_s7_line, dump_outfile);
b3ed63722eb5 fc-loadtool dump2srec: decorate the SREC output file with S0 and S7 records
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 94
diff changeset
210 fclose(dump_outfile);
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
211 printf("Requesting another CRC-32 of the area from target...\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
212 stat = crc32_on_target(start_addr, area_len, &target_crc_fin);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
213 if (stat)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
214 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
215 if (target_crc_fin == target_crc_init) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
216 printf("match, dump successful\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
217 return(0);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
218 } else {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
219 fprintf(stderr, "mismatch: got %lX this time\n",
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
220 target_crc_fin);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
221 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
222 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
223 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
224
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 cmd_dump2bin(argc, argv)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 char **argv;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 {
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
228 u_long area_base, area_len;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
229 char *strtoul_endp;
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
231 area_base = strtoul(argv[1], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
232 if (*strtoul_endp) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
233 inv: fprintf(stderr, "usage: dump2bin hex-start hex-len outfile\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
234 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
235 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
236 area_len = strtoul(argv[2], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
237 if (*strtoul_endp)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
238 goto inv;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
239 return loadtool_memdump(area_base, area_len, argv[3], 0);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
240 }
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
242 cmd_dump2srec(argc, argv)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
243 char **argv;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
244 {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
245 u_long area_base, area_len;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
246 char *strtoul_endp;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
247
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
248 area_base = strtoul(argv[1], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
249 if (*strtoul_endp) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
250 inv: fprintf(stderr, "usage: dump2srec hex-start hex-len outfile\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
251 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
252 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
253 area_len = strtoul(argv[2], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
254 if (*strtoul_endp)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
255 goto inv;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
256 return loadtool_memdump(area_base, area_len, argv[3], 1);
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 }