FreeCalypso > hg > freecalypso-tools
annotate loadtools/lacrc32.c @ 1000:39a6090a052a
doc/How-flash-really-works: article written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Dec 2023 09:08:19 +0000 |
parents | 5385aca4d813 |
children |
rev | line source |
---|---|
640
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the function for getting a CRC-32 computation |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * from loadagent. |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern char target_response_line[]; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 crc32_on_target(area_base, area_len, retptr) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_long area_base, area_len, *retptr; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char arg1[10], arg2[10], *argv[4]; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int stat; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char *strtoul_endp; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 sprintf(arg1, "%lx", area_base); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 sprintf(arg2, "%lx", area_len); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 argv[0] = "crc32"; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 argv[1] = arg1; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 argv[2] = arg2; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 argv[3] = 0; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 tpinterf_make_cmd(argv); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (tpinterf_send_cmd() < 0) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(-1); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 stat = tpinterf_capture_output_oneline(10); /* 10 s timeout */ |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (stat != 1) { |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 errout: fprintf(stderr, "error: malformed response to crc32 command\n"); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(-1); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (strlen(target_response_line) != 8) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 goto errout; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 *retptr = strtoul(target_response_line, &strtoul_endp, 16); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (strtoul_endp != target_response_line + 8) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 goto errout; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(0); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |