FreeCalypso > hg > freecalypso-sw
annotate target-utils/libload/intelflash.c @ 912:f50c71442d50
etmsync: die ID read implemented
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Tue, 08 Sep 2015 08:18:42 +0000 |
parents | d7f409493eb6 |
children |
rev | line source |
---|---|
404
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the INFB and INFW commands for programming |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * Intel-style flash memories. The syntax and operation are exactly |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * the same as the AMD flash counterparts AMFB and AMFW. |
411
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
5 * |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
6 * The intel-rewrite-sector command (erase+program with a minimum of |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
7 * vulnerability for brickable-boot Compal phones) is implemented |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
8 * here as well. |
404
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 */ |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <sys/types.h> |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "types.h" |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 static u32 base_addr; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 void |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 cmd_INFB(argbulk) |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 char *argbulk; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 char *argv[2]; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 u_long addr; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 if (parse_args(argbulk, 1, 1, argv, 0) < 0) |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 if (parse_hexarg(argv[0], 8, &addr) < 0) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 printf("ERROR: argument must be a valid 32-bit hex address\n"); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 if (addr & 1) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 printf("ERROR: odd address\n"); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 base_addr = addr; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 void |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 cmd_INFW(argbulk) |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 char *argbulk; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 char *argv[3], *s; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 u_long offset; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 volatile u16 *flashptr; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 u32 datum; /* needs to be u32 for decode_hex_digits() */ |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 u16 stat; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 int i; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 if (parse_args(argbulk, 2, 2, argv, 0) < 0) |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 if (parse_hexarg(argv[0], 8, &offset) < 0) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 printf("ERROR: offset argument must a valid 32-bit hex value\n"); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 if (offset & 1) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 printf("ERROR: odd offset argument\n"); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 flashptr = (volatile u16 *)(base_addr + offset); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 for (s = argv[1]; *s; flashptr++, s += 4) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 if (decode_hex_digits(s, 4, &datum) < 0) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 printf("ERROR: bad INFW hex string argument\n"); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 *flashptr = 0x40; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 *flashptr = datum; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 for (i = 10000; i; i--) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 stat = *flashptr; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (stat & 0x80) |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 break; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 if (!i) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 printf("ERROR: flash write timeout at %08X\n", |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 (u_long) flashptr); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 if (stat & 0x10) { |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 printf("ERROR: program operation failed at %08X\n", |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 (u_long) flashptr); |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 return; |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 } |
7daea2476062
loadagent: Intel flash support added, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 } |
411
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
82 |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
83 void |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
84 cmd_intel_rewrite_sector(argbulk) |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
85 char *argbulk; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
86 { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
87 char *argv[4]; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
88 u_long srcaddr, dstaddr, len; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
89 const u16 *srcptr; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
90 volatile u16 *flashptr; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
91 u16 stat; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
92 |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
93 if (parse_args(argbulk, 3, 3, argv, 0) < 0) |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
94 return; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
95 if (parse_hexarg(argv[0], 8, &srcaddr) < 0) { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
96 invarg: printf("ERROR: invalid argument(s)\n"); |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
97 return; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
98 } |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
99 if (parse_hexarg(argv[1], 8, &dstaddr) < 0) |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
100 goto invarg; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
101 if (parse_hexarg(argv[2], 8, &len) < 0) |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
102 goto invarg; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
103 if (srcaddr & 1 || dstaddr & 1 || len & 1) { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
104 printf("ERROR: all 3 arguments must be even\n"); |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
105 return; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
106 } |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
107 srcptr = (const u16 *) srcaddr; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
108 flashptr = (volatile u16 *) dstaddr; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
109 /* unlock the flash sector first */ |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
110 *flashptr = 0x60; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
111 *flashptr = 0xD0; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
112 /* clear SR */ |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
113 *flashptr = 0x50; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
114 /* erase */ |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
115 *flashptr = 0x20; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
116 *flashptr = 0xD0; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
117 /* wait for erase completion */ |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
118 for (;;) { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
119 stat = *flashptr; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
120 if (stat & 0x80) |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
121 break; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
122 } |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
123 if (stat & 0x30) { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
124 printf("ERROR: erase operation failed!\n"); |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
125 return; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
126 } |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
127 /* now program the new content */ |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
128 for (; len; len -= 2) { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
129 *flashptr = 0x40; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
130 *flashptr = *srcptr++; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
131 for (;;) { |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
132 stat = *flashptr; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
133 if (stat & 0x80) |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
134 break; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
135 } |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
136 flashptr++; |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
137 } |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
138 printf("Operation complete, final SR: %02X\n", stat & 0xFF); |
d7f409493eb6
loadagent: intel-rewrite-sector implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
404
diff
changeset
|
139 } |