FreeCalypso > hg > freecalypso-sw
annotate loadtools/flprogbin.c @ 959:21be17067eb2
c139explore: dump command added
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Wed, 04 Nov 2015 20:54:23 +0000 |
parents | fb3f04a62f71 |
children |
rev | line source |
---|---|
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
2 * This module implements the flash program-bin command: |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * programming flash using a binary file as the data source. |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/types.h> |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <sys/stat.h> |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdio.h> |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdint.h> |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
11 #include <time.h> |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "flash.h" |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 extern struct flash_bank_info flash_bank_info[2]; |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
15 extern uint32_t crc32_table[]; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 flashcmd_progbin(argc, argv, bank) |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 char **argv; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 struct flash_bank_info *bi; |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
21 u_long flashoff, fileoff, len, origlen, bytesdone; |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
22 u_long crc_base_addr, crc_from_target; |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
23 uint32_t crcaccum; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 char *strtoul_endp; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 FILE *binf; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 struct stat filestat; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 char *targv[4], shortarg[10], longarg[513]; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 u_char databuf[256]; |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
29 int reclen, cc, i; |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
30 time_t curtime, last_time; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (argc < 4 || argc > 6) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 inv: fprintf(stderr, |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 "usage: %s %s flash-offset binfile [file-offset [length]]\n", |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 argv[0], argv[1]); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 flashoff = strtoul(argv[2], &strtoul_endp, 16); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (*strtoul_endp) |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 goto inv; |
400
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
41 if (flash_get_cfi(bank) < 0) |
f027c6fbe37e
fc-loadtool flash: first round of refactoring for CFI
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
205
diff
changeset
|
42 return(-1); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 bi = flash_bank_info + bank; |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
44 if (flashoff >= bi->geom->total_size) { |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 fprintf(stderr, |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 "error: specified flash offset exceeds bank size (0x%lx)\n", |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
47 (u_long) bi->geom->total_size); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 if (flashoff & 1) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 fprintf(stderr, "error: flash offset must be even\n"); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 binf = fopen(argv[3], "r"); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 if (!binf) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 perror(argv[3]); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 fstat(fileno(binf), &filestat); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 if (!S_ISREG(filestat.st_mode)) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 fprintf(stderr, "%s is not a regular file\n", argv[3]); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 if (argc > 4) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 fileoff = strtoul(argv[4], &strtoul_endp, 16); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (*strtoul_endp) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 goto inv; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 if (fileoff > filestat.st_size) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 fprintf(stderr, |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 "error: specified file offset exceeds file length\n"); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 } else |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 fileoff = 0; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (argc > 5) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 len = strtoul(argv[5], &strtoul_endp, 16); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 if (*strtoul_endp) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 goto inv; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 if (len > filestat.st_size - fileoff) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 fprintf(stderr, |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 "error: specified file offset+length exceed file length\n"); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 } else |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 len = filestat.st_size - fileoff; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 if (!len) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 printf("Length is zero - nothing to do!\n"); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 return(0); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 } |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
98 if (len > bi->geom->total_size - flashoff) { |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 fprintf(stderr, |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 "error: specified flash offset+length exceed bank size (0x%lx)\n", |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
101 (u_long) bi->geom->total_size); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 if (len & 1) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 fprintf(stderr, "error: program length must be even\n"); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 /* finally done with the arg parsing etc, can get to work now */ |
205
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
112 if (flash_id_check(bank, 0) < 0) { |
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
113 fclose(binf); |
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
114 return(-1); |
cd12d1049f91
fc-loadtool: flash ID check moved into flash info, added to erase and program
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
95
diff
changeset
|
115 } |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
116 crc_base_addr = bi->base_addr + flashoff; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 sprintf(shortarg, "%lx", (u_long) bi->base_addr); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
118 targv[0] = bi->ops->loadagent_setbase_cmd; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 targv[1] = shortarg; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 targv[2] = 0; |
66
98f855e58c9f
fc-loadtool flash program-bin command: forgot to print progress dots
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
65
diff
changeset
|
121 printf("Setting flash base address: %s %s\n", targv[0], targv[1]); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 tpinterf_make_cmd(targv); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 if (tpinterf_send_cmd() < 0) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 cc = tpinterf_pass_output(1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 if (cc) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 return(cc); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 } |
410
81d387690063
Intel flash: clear SR before programming
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
132 if (bi->ops->prep_for_program(bi) < 0) { |
81d387690063
Intel flash: clear SR before programming
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
133 fclose(binf); |
81d387690063
Intel flash: clear SR before programming
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
134 return(-1); |
81d387690063
Intel flash: clear SR before programming
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
405
diff
changeset
|
135 } |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 fseek(binf, fileoff, SEEK_SET); |
405
a212b4968b29
fc-loadtool flash: another refactoring: geometry vs. command set
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
400
diff
changeset
|
137 targv[0] = bi->ops->loadagent_program_cmd; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 targv[1] = shortarg; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 targv[2] = longarg; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 targv[3] = 0; |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
141 printf("Programming flash: %lu (0x%lx) bytes\n", len, len); |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
142 origlen = len; |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
143 bytesdone = 0; |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
144 last_time = 0; |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
145 crcaccum = 0xFFFFFFFF; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 while (len) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 if (len >= 256) |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 reclen = 256; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 else |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 reclen = len; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 cc = fread(databuf, 1, reclen, binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 if (cc != reclen) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 fprintf(stderr, "error reading from %s\n", argv[3]); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 } |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
157 for (i = 0; i < reclen; i++) /* update running CRC */ |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
158 crcaccum = crc32_table[crcaccum & 0xFF ^ databuf[i]] |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
159 ^ (crcaccum >> 8); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 sprintf(shortarg, "%lx", flashoff); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 build_flashw_hex_string(databuf, longarg, reclen >> 1, 0); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 tpinterf_make_cmd(targv); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 if (tpinterf_send_cmd() < 0) { |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 fclose(binf); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 return(-1); |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 } |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
167 i = tpinterf_pass_output(8); /* 8 s timeout */ |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
168 if (i) { |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 fclose(binf); |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
170 return(i); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 } |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 flashoff += reclen; |
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 len -= reclen; |
95
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
174 bytesdone += reclen; |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
175 cc = bytesdone * 100 / origlen; |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
176 time(&curtime); |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
177 if (curtime != last_time || cc == 100) { |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
178 printf("\r0x%lx bytes programmed (%i%%)", |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
179 bytesdone, cc); |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
180 fflush(stdout); |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
181 } |
336f5cc96810
fc-loadtool flash program-bin: smarter progress indication
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
66
diff
changeset
|
182 last_time = curtime; |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 } |
66
98f855e58c9f
fc-loadtool flash program-bin command: forgot to print progress dots
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
65
diff
changeset
|
184 putchar('\n'); |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 fclose(binf); |
922
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
186 |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
187 /* reset flash to read mode */ |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
188 if (bi->ops->reset_cmd(bi) < 0) |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
189 return(-1); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
190 printf("Verifying CRC-32 of programmed flash area\n"); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
191 if (crc32_on_target(crc_base_addr, origlen, &crc_from_target) < 0) |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
192 return(-1); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
193 if (crc_from_target == crcaccum) { |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
194 printf("match (%08lX)\n", crc_from_target); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
195 return(0); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
196 } else { |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
197 fprintf(stderr, "error: CRC mismatch!\n"); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
198 return(-1); |
fb3f04a62f71
fc-loadtool: flash program-bin now performs a CRC-32 verification
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
410
diff
changeset
|
199 } |
65
a7da6648a7f8
fc-loadtool: flash program-bin command implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 } |