comparison loadtools/ltdump.c @ 35:05af070c4b60

loadtool: preparations for dump2bin and dump2srec
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 05 May 2013 02:24:56 +0000
parents
children 65111e6eee9e
comparison
equal deleted inserted replaced
34:2c6b2a74ac7c 35:05af070c4b60
1 /*
2 * This module implements the dump2bin and dump2srec functionality
3 * of fc-loadtool.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h>
12
13 extern char target_response_line[];
14
15 crc32_on_target(area_base, area_len, retptr)
16 u_long area_base, area_len, *retptr;
17 {
18 char arg1[10], arg2[10], *argv[4];
19 int stat;
20 char *strtoul_endp;
21
22 sprintf(arg1, "%lx", area_base);
23 sprintf(arg2, "%lx", area_len);
24 argv[0] = "crc32";
25 argv[1] = arg1;
26 argv[2] = arg2;
27 argv[3] = 0;
28 tpinterf_make_cmd(argv);
29 if (tpinterf_send_cmd() < 0)
30 return(-1);
31 stat = tpinterf_capture_output_oneline(10); /* 10 s timeout */
32 if (stat != 1) {
33 errout: fprintf(stderr, "error: malformed response to crc32 command\n");
34 return(-1);
35 }
36 if (strlen(target_response_line) != 8)
37 goto errout;
38 *retptr = strtoul(target_response_line, &strtoul_endp, 16);
39 if (strtoul_endp != target_response_line + 8)
40 goto errout;
41 return(0);
42 }
43
44 cmd_crc32(argc, argv)
45 char **argv;
46 {
47 u_long area_base, area_len;
48 char *strtoul_endp;
49 u_long crc_result;
50 int stat;
51
52 area_base = strtoul(argv[1], &strtoul_endp, 16);
53 if (*strtoul_endp) {
54 inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n");
55 return(-1);
56 }
57 area_len = strtoul(argv[2], &strtoul_endp, 16);
58 if (*strtoul_endp)
59 goto inv;
60 stat = crc32_on_target(area_base, area_len, &crc_result);
61 if (stat == 0)
62 printf("%08lX\n", crc_result);
63 return(stat);
64 }
65
66 cmd_dump2bin(argc, argv)
67 char **argv;
68 {
69
70
71 }