annotate loadtools/ltdump.c @ 55:278052b6afda

loadtools: started laying the foundation for flash support
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Jun 2013 20:13:59 +0000
parents 65111e6eee9e
children 1f035187e98f
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>
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
13 extern uint32_t crc32_table[];
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern char target_response_line[];
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 crc32_on_target(area_base, area_len, retptr)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 u_long area_base, area_len, *retptr;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 char arg1[10], arg2[10], *argv[4];
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 int stat;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 char *strtoul_endp;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 sprintf(arg1, "%lx", area_base);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 sprintf(arg2, "%lx", area_len);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 argv[0] = "crc32";
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 argv[1] = arg1;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 argv[2] = arg2;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 argv[3] = 0;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 tpinterf_make_cmd(argv);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (tpinterf_send_cmd() < 0)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return(-1);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 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
33 if (stat != 1) {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 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
35 return(-1);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 if (strlen(target_response_line) != 8)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 goto errout;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 *retptr = strtoul(target_response_line, &strtoul_endp, 16);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 if (strtoul_endp != target_response_line + 8)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 goto errout;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 return(0);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
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 cmd_crc32(argc, argv)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 char **argv;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 u_long area_base, area_len;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 char *strtoul_endp;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 u_long crc_result;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 int stat;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 area_base = strtoul(argv[1], &strtoul_endp, 16);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 if (*strtoul_endp) {
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 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
56 return(-1);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 area_len = strtoul(argv[2], &strtoul_endp, 16);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (*strtoul_endp)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 goto inv;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 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
62 if (stat == 0)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 printf("%08lX\n", crc_result);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 return(stat);
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
67 /* the actual dump facility */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
68
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
69 static FILE *dump_outfile;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
70 static int dump_save_srec;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
71 static uint32_t dump_nextaddr, dump_crcaccum;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
72 static u_char dump_binrec[0x86];
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
73
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
74 static
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
75 dump_receiver(line)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
76 char *line;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
77 {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
78 int i, b;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
79 u_char sr_cksum;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
80 uint32_t addr_from_srec;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
81
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
82 if (strncmp(line, "S385", 4)) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
83 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
84 "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
85 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
86 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
87 for (i = 0; i < 0x86; i++) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
88 b = decode_hex_byte(line + i*2 + 2);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
89 if (b < 0) {
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 "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
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 dump_binrec[i] = b;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
95 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
96 sr_cksum = 0;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
97 for (i = 0; i < 0x86; i++)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
98 sr_cksum += dump_binrec[i];
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
99 if (sr_cksum != 0xFF) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
100 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
101 return(-1);
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 /* 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
104 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
105 ((uint32_t) dump_binrec[2] << 16) |
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
106 ((uint32_t) dump_binrec[3] << 8) |
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
107 (uint32_t) dump_binrec[4];
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
108 if (addr_from_srec != dump_nextaddr) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
109 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
110 "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
111 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
112 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
113 /* all checks passed - save it */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
114 if (dump_save_srec)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
115 fprintf(dump_outfile, "%s\n", line);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
116 else
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
117 fwrite(dump_binrec + 5, 1, 0x80, dump_outfile);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
118 /* update running CRC */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
119 for (i = 0; i < 0x80; i++)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
120 dump_crcaccum = crc32_table[dump_crcaccum & 0xFF ^
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
121 dump_binrec[i+5]] ^
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
122 (dump_crcaccum >> 8);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
123 /* progress indication */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
124 putchar('.');
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
125 fflush(stdout);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
126 dump_nextaddr += 0x80;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
127 return(1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
128 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
129
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
130 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
131 u_long start_addr, area_len;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
132 char *filename;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
133 {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
134 u_long target_crc_init, target_crc_fin;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
135 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
136 int stat;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
137
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
138 if (start_addr & 0x7F || area_len & 0x7F) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
139 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
140 "error: implementation limit: 128-byte alignment required\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
141 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
142 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
143 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
144 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
145 if (stat)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
146 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
147 printf("got %08lX\n", target_crc_init);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
148 dump_outfile = fopen(filename, "w");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
149 if (!dump_outfile) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
150 perror(filename);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
151 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
152 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
153 dump_save_srec = fmt_srec;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
154 dump_nextaddr = start_addr;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
155 dump_crcaccum = 0xFFFFFFFF;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
156
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
157 printf("Requesting memory dump...\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
158 sprintf(target_arg1, "%lx", start_addr);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
159 sprintf(target_arg2, "%lx", area_len);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
160 target_argv[0] = "DUMP";
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
161 target_argv[1] = target_arg1;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
162 target_argv[2] = target_arg2;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
163 target_argv[3] = 0;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
164 tpinterf_make_cmd(target_argv);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
165 stat = tpinterf_send_cmd();
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
166 if (stat < 0) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
167 fclose(dump_outfile);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
168 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
169 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
170 stat = tpinterf_capture_output(2, dump_receiver);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
171 fclose(dump_outfile);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
172 if (stat < 0)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
173 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
174 putchar('\n'); /* after lots of dots */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
175
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
176 /* sanity checks */
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
177 if (dump_nextaddr != start_addr + area_len) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
178 fprintf(stderr,
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
179 "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
180 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
181 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
182 if (dump_crcaccum != (uint32_t) target_crc_init) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
183 fprintf(stderr, "error: CRC mismatch (computed %lX)\n",
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
184 (u_long) dump_crcaccum);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
185 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
186 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
187 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
188 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
189 if (stat)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
190 return(stat);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
191 if (target_crc_fin == target_crc_init) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
192 printf("match, dump successful\n");
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
193 return(0);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
194 } else {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
195 fprintf(stderr, "mismatch: got %lX this time\n",
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
196 target_crc_fin);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
197 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
198 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
199 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
200
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 cmd_dump2bin(argc, argv)
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 char **argv;
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 {
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
204 u_long area_base, area_len;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
205 char *strtoul_endp;
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
207 area_base = strtoul(argv[1], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
208 if (*strtoul_endp) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
209 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
210 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
211 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
212 area_len = strtoul(argv[2], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
213 if (*strtoul_endp)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
214 goto inv;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
215 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
216 }
35
05af070c4b60 loadtool: preparations for dump2bin and dump2srec
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217
36
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
218 cmd_dump2srec(argc, argv)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
219 char **argv;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
220 {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
221 u_long area_base, area_len;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
222 char *strtoul_endp;
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 area_base = strtoul(argv[1], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
225 if (*strtoul_endp) {
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
226 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
227 return(-1);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
228 }
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
229 area_len = strtoul(argv[2], &strtoul_endp, 16);
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
230 if (*strtoul_endp)
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
231 goto inv;
65111e6eee9e loadtool: dump2bin and dump2srec implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 35
diff changeset
232 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
233 }