FreeCalypso > hg > freecalypso-tools
annotate loadtools/flashops.c @ 981:f21798eb13cf
fc-loadtool: implement flash ppb-* commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 02 Dec 2023 05:46:00 +0000 |
parents | 44cdfc4fed4c |
children |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements those flash operations which are dependent |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * on the AMD vs. Intel command set style. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <time.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "flash.h" |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 /* common stub functions */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 noop() |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static |
506
0dd2c87c1b63
fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
325
diff
changeset
|
22 amd_invalid() |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fprintf(stderr, |
506
0dd2c87c1b63
fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
325
diff
changeset
|
25 "This operation is not applicable to AMD-style flash\n"); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 /* AMD flash functions */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 amd_reset_cmd(bi) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (do_w16(bi->base_addr + 0xAAA, 0xF0)) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 "unexpected response to w16 when resetting flash to read mode!\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 amd_sector_erase(bi, sp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 struct sector_info *sp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 int stat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 uint16_t flstat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 time_t start_time, curtime; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0xAA); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (stat) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 bad_w16: fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 "unexpected response to w16 in erase cmd sequence - aborting\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 stat = do_w16(bi->base_addr + sp->start + 0x554, 0x55); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0x80); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0xAA); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 stat = do_w16(bi->base_addr + sp->start + 0x554, 0x55); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 stat = do_w16(bi->base_addr + sp->start + 0xAAA, 0x30); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 start_time = time(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 for (;;) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 stat = do_r16(bi->base_addr + sp->start, &flstat); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return(stat); /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (flstat == 0xFFFF) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 curtime = time(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (curtime >= start_time + 20) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 fprintf(stderr, "erase timeout, aborting\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 struct flash_cmdset flash_cmdset_amd = { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 .cmdset_name = "AMD", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 .reset_cmd = amd_reset_cmd, |
506
0dd2c87c1b63
fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
325
diff
changeset
|
89 .status_cmd = amd_invalid, |
0dd2c87c1b63
fc-loadtool flash support overhaul
Mychaela Falconia <falcon@freecalypso.org>
parents:
325
diff
changeset
|
90 .unlock_sector = amd_invalid, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 .erase_sector = amd_sector_erase, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 .prep_for_program = noop, |
711
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
93 .read_prot_reg = amd_invalid, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 .loadagent_setbase_cmd = "AMFB", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 .loadagent_program_cmd = "AMFW", |
664
77a0001d8849
fc-loadtool: prep for binary flash programming
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
96 .loadagent_binmode_cmd = "AMFWB", |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 .needs_unlock = 0, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 }; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 /* Intel flash functions */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 intel_reset_cmd(bi) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (do_w16(bi->base_addr, 0xFF)) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 "unexpected response to w16 when resetting flash to read mode!\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
325
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
113 intel_w30_reset_cmd(bi) |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
114 struct flash_bank_info *bi; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
115 { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
116 uint32_t part; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
117 |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
118 for (part = 0; part < bi->geom->total_size; part += 0x80000) { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
119 if (do_w16(bi->base_addr + part, 0xFF)) { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
120 fprintf(stderr, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
121 "unexpected response to w16 when resetting flash to read mode!\n"); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
122 return(-1); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
123 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
124 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
125 return(0); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
126 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
127 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 intel_status_cmd(bi) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 int stat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 uint16_t sr; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 /* issue Read SR command */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 stat = do_w16(bi->base_addr, 0x70); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (stat) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 "unexpected response to w16 for Read SR command\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 stat = do_r16(bi->base_addr, &sr); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 return(stat); /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 sr &= 0xFF; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 printf("Status Register: %02X\n", sr); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 |
325
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
149 intel_w30_status_cmd(bi) |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
150 struct flash_bank_info *bi; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
151 { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
152 uint32_t part; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
153 int stat; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
154 uint16_t sr; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
155 |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
156 for (part = 0; part < bi->geom->total_size; part += 0x80000) { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
157 /* issue Read SR command */ |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
158 stat = do_w16(bi->base_addr + part, 0x70); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
159 if (stat) { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
160 fprintf(stderr, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
161 "unexpected response to w16 for Read SR command\n"); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
162 return(-1); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
163 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
164 stat = do_r16(bi->base_addr + part, &sr); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
165 if (stat) |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
166 return(stat); /* error msg already printed */ |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
167 sr &= 0xFF; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
168 printf("Status Register for partition %08lX: %02X\n", |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
169 (u_long) part, sr); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
170 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
171 return(0); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
172 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
173 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 intel_sector_unlock(bi, sp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 struct sector_info *sp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 int stat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 stat = do_w16(bi->base_addr + sp->start, 0x60); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 if (stat) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 bad_w16: fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 "unexpected response to w16 in block unlock cmd sequence - aborting\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 stat = do_w16(bi->base_addr + sp->start, 0xD0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 intel_sector_erase(bi, sp) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 struct sector_info *sp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 int stat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 uint16_t flstat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 time_t start_time, curtime; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 stat = intel_sector_unlock(bi, sp); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 return(stat); /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 /* clear SR */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 stat = do_w16(bi->base_addr + sp->start, 0x50); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 if (stat) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 bad_w16: fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 "unexpected response to w16 in erase cmd sequence - aborting\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 /* send the actual block erase command */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 stat = do_w16(bi->base_addr + sp->start, 0x20); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 stat = do_w16(bi->base_addr + sp->start, 0xD0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 goto bad_w16; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 /* wait for completion */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 start_time = time(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 for (;;) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 stat = do_r16(bi->base_addr + sp->start, &flstat); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 return(stat); /* error msg already printed */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 if (flstat & 0x80) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 curtime = time(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 if (curtime >= start_time + 20) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 fprintf(stderr, "erase timeout, aborting\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 if (flstat & 0x20) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 fprintf(stderr, "block erase failed!\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 } else |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 intel_clear_sr(bi) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 struct flash_bank_info *bi; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 printf("Clearing Intel flash SR\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 if (do_w16(bi->base_addr, 0x50)) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 "unexpected response to w16 for Clear SR command\n"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 |
325
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
250 intel_w30_clear_sr(bi) |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
251 struct flash_bank_info *bi; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
252 { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
253 uint32_t part; |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
254 |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
255 printf("Clearing Intel flash SR\n"); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
256 for (part = 0; part < bi->geom->total_size; part += 0x80000) { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
257 if (do_w16(bi->base_addr + part, 0x50)) { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
258 fprintf(stderr, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
259 "unexpected response to w16 for Clear SR command\n"); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
260 return(-1); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
261 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
262 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
263 return(0); |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
264 } |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
265 |
711
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
266 intel_read_prot_reg(bi, data) |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
267 struct flash_bank_info *bi; |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
268 uint16_t *data; |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
269 { |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
270 int stat, i; |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
271 |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
272 if (do_w16(bi->base_addr, 0x90)) { |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
273 fprintf(stderr, |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
274 "unexpected response to w16 for Read ID command\n"); |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
275 return(-1); |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
276 } |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
277 for (i = 0; i < 9; i++) { |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
278 stat = do_r16(bi->base_addr + 0x100 + i * 2, data + i); |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
279 if (stat) |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
280 return(stat); /* error msg already printed */ |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
281 } |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
282 return(0); |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
283 } |
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
284 |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 struct flash_cmdset flash_cmdset_intel = { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 .cmdset_name = "Intel", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 .reset_cmd = intel_reset_cmd, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 .status_cmd = intel_status_cmd, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 .unlock_sector = intel_sector_unlock, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 .erase_sector = intel_sector_erase, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 .prep_for_program = intel_clear_sr, |
711
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
292 .read_prot_reg = intel_read_prot_reg, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 .loadagent_setbase_cmd = "INFB", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 .loadagent_program_cmd = "INFW", |
664
77a0001d8849
fc-loadtool: prep for binary flash programming
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
295 .loadagent_binmode_cmd = "INFWB", |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 .needs_unlock = 1, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 }; |
325
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
298 |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
299 struct flash_cmdset flash_cmdset_intel_w30 = { |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
300 .cmdset_name = "Intel", |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
301 .reset_cmd = intel_w30_reset_cmd, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
302 .status_cmd = intel_w30_status_cmd, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
303 .unlock_sector = intel_sector_unlock, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
304 .erase_sector = intel_sector_erase, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
305 .prep_for_program = intel_w30_clear_sr, |
711
44cdfc4fed4c
fc-loadtool: flash prot-reg command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
664
diff
changeset
|
306 .read_prot_reg = intel_read_prot_reg, |
325
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
307 .loadagent_setbase_cmd = "INFB", |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
308 .loadagent_program_cmd = "INFW", |
664
77a0001d8849
fc-loadtool: prep for binary flash programming
Mychaela Falconia <falcon@freecalypso.org>
parents:
506
diff
changeset
|
309 .loadagent_binmode_cmd = "INFWB", |
325
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
310 .needs_unlock = 1, |
545e1718f5fb
fc-loadtool: support for 28F640W30B flash chip with partition quirks
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
311 }; |