annotate loadtools/flcmplboot.c @ 689:8b1121359341

cc_cfk.c compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 30 Sep 2014 01:20:27 +0000
parents c2e14cc15c23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
412
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the implementation of the flash erase-program-boot
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * hack for brickable Compal phones.
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
7 #include <sys/stat.h>
412
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <ctype.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdio.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdint.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <string.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <strings.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <stdlib.h>
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "flash.h"
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
16 extern struct flash_bank_info flash_bank_info[2];
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
17 extern struct flash_cmdset flash_cmdset_intel;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
18
416
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
19 extern uint32_t crc32_table[];
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
20
412
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 static int hack_enabled;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 static uint32_t boot_sector_size;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 static uint32_t ram_buffer_addr;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 /* called from hwparam.c config file parser */
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 void
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 set_boot_reflash_hack(arg, filename_for_errs, lineno_for_errs)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 char *arg;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 char *filename_for_errs;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 int lineno_for_errs;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 char *cp, *np, *ep;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 if (hack_enabled) {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 "%s line %d: duplicate boot-reflash-hack setting\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 for (cp = arg; isspace(*cp); cp++)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 ;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 if (!*cp || *cp == '#') {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 too_few_arg: fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 "%s line %d: boot-reflash-hack setting: too few arguments\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 for (np = cp; *cp && !isspace(*cp); cp++)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 ;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 if (!*cp)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 goto too_few_arg;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 *cp++ = '\0';
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 ram_buffer_addr = strtoul(np, &ep, 16);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 if (*ep) {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 invhex: fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 "%s line %d: syntax error (hex arguments expected)\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 while (isspace(*cp))
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 cp++;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 if (!*cp || *cp == '#')
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 goto too_few_arg;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 for (np = cp; *cp && !isspace(*cp); cp++)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 ;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (*cp)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 *cp++ = '\0';
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 boot_sector_size = strtoul(np, &ep, 16);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (*ep)
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 goto invhex;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 while (isspace(*cp))
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 cp++;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (*cp && *cp != '#') {
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 fprintf(stderr,
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 "%s line %d: boot-reflash-hack setting: too many arguments\n",
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 filename_for_errs, lineno_for_errs);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 exit(1);
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 hack_enabled = 1;
bf49e348576b fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 }
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
81
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
82 static void
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
83 make_s3_record(buf, dest_addr, datalen)
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
84 u_char *buf;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
85 uint32_t dest_addr;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
86 {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
87 int totlen, i;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
88 u_char accum;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
89
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
90 buf[0] = totlen = datalen + 5;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
91 buf[1] = dest_addr >> 24;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
92 buf[2] = dest_addr >> 16;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
93 buf[3] = dest_addr >> 8;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
94 buf[4] = dest_addr;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
95 accum = 0;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
96 for (i = 0; i < totlen; i++)
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
97 accum += buf[i];
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
98 buf[i] = ~accum;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
99 }
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
100
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
101 static void
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
102 make_ml_arg(rec, buf)
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
103 u_char *rec;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
104 char *buf;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
105 {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
106 register int i, len;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
107 register char *s;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
108
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
109 len = rec[0] + 1;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
110 s = buf;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
111 for (i = 0; i < len; i++) {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
112 sprintf(s, "%02X", rec[i]);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
113 s += 2;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
114 }
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
115 *s = '\0';
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
116 }
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
117
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
118 flashcmd_erase_program_boot(argc, argv)
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
119 char **argv;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
120 {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
121 FILE *binf;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
122 struct stat filestat;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
123 size_t len;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
124 char *strtoul_endp;
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
125 char *targv[5], longarg[513];
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
126 char shortarg1[9], shortarg2[9], shortarg3[9];
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
127 u_char databuf[256];
416
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
128 int reclen, cc, i;
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
129 uint32_t ramaddr, remlen, crcaccum;
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
130 u_long crc_from_target;
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
131
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
132 if (!hack_enabled) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
133 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
134 "Operation not applicable to this target device\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
135 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
136 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
137 if (argc < 3 || argc > 4) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
138 inv: fprintf(stderr, "usage: %s %s binfile [length]\n",
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
139 argv[0], argv[1]);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
140 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
141 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
142 if (flash_get_cfi(0) < 0)
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
143 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
144 if (flash_bank_info[0].geom->regions[0].sector_size
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
145 != boot_sector_size) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
146 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
147 "error: detected flash boot sector size differs from config\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
148 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
149 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
150 if (flash_bank_info[0].ops != &flash_cmdset_intel) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
151 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
152 "error: operation implemented for Intel flash only\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
153 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
154 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
155
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
156 binf = fopen(argv[2], "r");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
157 if (!binf) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
158 perror(argv[2]);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
159 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
160 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
161 fstat(fileno(binf), &filestat);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
162 if (!S_ISREG(filestat.st_mode)) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
163 fprintf(stderr, "%s is not a regular file\n", argv[2]);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
164 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
165 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
166 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
167 if (argc > 3) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
168 len = strtoul(argv[3], &strtoul_endp, 16);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
169 if (*strtoul_endp) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
170 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
171 goto inv;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
172 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
173 if (len > filestat.st_size) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
174 fprintf(stderr,
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
175 "error: specified length exceeds file length\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
176 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
177 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
178 }
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
179 } else
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
180 len = filestat.st_size;
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
181 if (len > boot_sector_size) {
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
182 fprintf(stderr, "error: length exceeds boot sector size\n");
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
183 fclose(binf);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
184 return(-1);
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
185 }
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
186 if (len & 1) {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
187 fprintf(stderr, "error: length must be even\n");
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
188 fclose(binf);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
189 return(-1);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
190 }
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
191
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
192 printf("Loading new boot code into target RAM at %lx\n",
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
193 (u_long) ram_buffer_addr);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
194 targv[0] = "ML";
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
195 targv[1] = longarg;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
196 targv[2] = 0;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
197 ramaddr = ram_buffer_addr;
416
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
198 crcaccum = 0xFFFFFFFF;
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
199 for (remlen = len; remlen; remlen -= reclen) {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
200 if (remlen >= 250)
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
201 reclen = 250;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
202 else
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
203 reclen = remlen;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
204 cc = fread(databuf + 5, 1, reclen, binf);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
205 if (cc != reclen) {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
206 fclose(binf);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
207 fprintf(stderr, "error reading from %s\n", argv[2]);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
208 return(-1);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
209 }
416
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
210 for (i = 0; i < reclen; i++) /* update running CRC */
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
211 crcaccum = crc32_table[crcaccum & 0xFF ^ databuf[i+5]]
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
212 ^ (crcaccum >> 8);
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
213 make_s3_record(databuf, ramaddr, reclen);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
214 make_ml_arg(databuf, longarg);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
215 tpinterf_make_cmd(targv);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
216 if (tpinterf_send_cmd() < 0) {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
217 fclose(binf);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
218 return(-1);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
219 }
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
220 cc = tpinterf_pass_output(1);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
221 if (cc) {
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
222 fclose(binf);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
223 return(cc);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
224 }
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
225 ramaddr += reclen;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
226 putchar('.');
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
227 fflush(stdout);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
228 }
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
229 putchar('\n');
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
230 fclose(binf);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
231
416
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
232 printf("Verifying CRC-32 in target RAM\n");
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
233 if (crc32_on_target((u_long) ram_buffer_addr, (u_long) len,
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
234 &crc_from_target) < 0)
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
235 return(-1);
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
236 if (crc_from_target == crcaccum)
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
237 printf("match (%08lX)\n", crc_from_target);
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
238 else {
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
239 fprintf(stderr, "error: CRC mismatch!\n");
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
240 return(-1);
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
241 }
c2e14cc15c23 flash erase-program-boot: implemented CRC check before flashing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 415
diff changeset
242
415
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
243 printf("Commanding flash erase+program operation on the target\n");
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
244 sprintf(shortarg1, "%lx", (u_long) ram_buffer_addr);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
245 sprintf(shortarg2, "%lx", (u_long) flash_bank_info[0].base_addr);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
246 sprintf(shortarg3, "%lx", (u_long) len);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
247 targv[0] = "intel-rewrite-sector";
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
248 targv[1] = shortarg1;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
249 targv[2] = shortarg2;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
250 targv[3] = shortarg3;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
251 targv[4] = 0;
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
252 tpinterf_make_cmd(targv);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
253 if (tpinterf_send_cmd() < 0)
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
254 return(-1);
b2487cfd68fd fc-loadtool: flash erase-program-boot implementation complete
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 414
diff changeset
255 return tpinterf_pass_output(20); /* 20 s timeout */
414
a2df77833c21 fc-loadtool: started implementing flash erase-program-boot command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 412
diff changeset
256 }