comparison loadtools/ltdump.c @ 640:5385aca4d813

fc-loadtool module refactoring: CRC-32 functions split out
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 01 Mar 2020 18:54:29 +0000
parents 98474043ecdd
children b4070292640a
comparison
equal deleted inserted replaced
639:963d15a808eb 640:5385aca4d813
10 #include <strings.h> 10 #include <strings.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <time.h> 12 #include <time.h>
13 13
14 extern uint32_t crc32_table[]; 14 extern uint32_t crc32_table[];
15 extern char target_response_line[];
16
17 crc32_on_target(area_base, area_len, retptr)
18 u_long area_base, area_len, *retptr;
19 {
20 char arg1[10], arg2[10], *argv[4];
21 int stat;
22 char *strtoul_endp;
23
24 sprintf(arg1, "%lx", area_base);
25 sprintf(arg2, "%lx", area_len);
26 argv[0] = "crc32";
27 argv[1] = arg1;
28 argv[2] = arg2;
29 argv[3] = 0;
30 tpinterf_make_cmd(argv);
31 if (tpinterf_send_cmd() < 0)
32 return(-1);
33 stat = tpinterf_capture_output_oneline(10); /* 10 s timeout */
34 if (stat != 1) {
35 errout: fprintf(stderr, "error: malformed response to crc32 command\n");
36 return(-1);
37 }
38 if (strlen(target_response_line) != 8)
39 goto errout;
40 *retptr = strtoul(target_response_line, &strtoul_endp, 16);
41 if (strtoul_endp != target_response_line + 8)
42 goto errout;
43 return(0);
44 }
45
46 cmd_crc32(argc, argv)
47 char **argv;
48 {
49 u_long area_base, area_len;
50 char *strtoul_endp;
51 u_long crc_result;
52 int stat;
53
54 area_base = strtoul(argv[1], &strtoul_endp, 16);
55 if (*strtoul_endp) {
56 inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n");
57 return(-1);
58 }
59 area_len = strtoul(argv[2], &strtoul_endp, 16);
60 if (*strtoul_endp)
61 goto inv;
62 stat = crc32_on_target(area_base, area_len, &crc_result);
63 if (stat == 0)
64 printf("%08lX\n", crc_result);
65 return(stat);
66 }
67
68 /* the actual dump facility */
69 15
70 static FILE *dump_outfile; 16 static FILE *dump_outfile;
71 static int dump_save_srec; 17 static int dump_save_srec;
72 static uint32_t dump_nextaddr, dump_crcaccum; 18 static uint32_t dump_nextaddr, dump_crcaccum;
73 static uint32_t dump_total_len, dump_progress_len; 19 static uint32_t dump_total_len, dump_progress_len;