1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <common.h>
26#include <altera.h>
27
28int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
29 int isSerial, int isSecure);
30int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize);
31
32
33
34int StratixII_load (Altera_desc * desc, void *buf, size_t bsize)
35{
36 int ret_val = FPGA_FAIL;
37
38 switch (desc->iface) {
39 case passive_serial:
40 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 1, 0);
41 break;
42 case fast_passive_parallel:
43 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 0);
44 break;
45 case fast_passive_parallel_security:
46 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 1);
47 break;
48
49
50 default:
51 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
52 desc->iface);
53 }
54 return ret_val;
55}
56
57int StratixII_dump (Altera_desc * desc, void *buf, size_t bsize)
58{
59 int ret_val = FPGA_FAIL;
60
61 switch (desc->iface) {
62 case passive_serial:
63 case fast_passive_parallel:
64 case fast_passive_parallel_security:
65 ret_val = StratixII_ps_fpp_dump (desc, buf, bsize);
66 break;
67
68 default:
69 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
70 desc->iface);
71 }
72 return ret_val;
73}
74
75int StratixII_info (Altera_desc * desc)
76{
77 return FPGA_SUCCESS;
78}
79
80int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize)
81{
82 printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
83 return FPGA_FAIL;
84}
85
86int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
87 int isSerial, int isSecure)
88{
89 altera_board_specific_func *fns;
90 int cookie;
91 int ret_val = FPGA_FAIL;
92 int bytecount;
93 char *buff = buf;
94 int i;
95
96 if (!desc) {
97 printf ("%s(%d) Altera_desc missing\n", __FUNCTION__, __LINE__);
98 return FPGA_FAIL;
99 }
100 if (!buff) {
101 printf ("%s(%d) buffer is missing\n", __FUNCTION__, __LINE__);
102 return FPGA_FAIL;
103 }
104 if (!bsize) {
105 printf ("%s(%d) size is zero\n", __FUNCTION__, __LINE__);
106 return FPGA_FAIL;
107 }
108 if (!desc->iface_fns) {
109 printf
110 ("%s(%d) Altera_desc function interface table is missing\n",
111 __FUNCTION__, __LINE__);
112 return FPGA_FAIL;
113 }
114 fns = (altera_board_specific_func *) (desc->iface_fns);
115 cookie = desc->cookie;
116
117 if (!
118 (fns->config && fns->status && fns->done && fns->data
119 && fns->abort)) {
120 printf
121 ("%s(%d) Missing some function in the function interface table\n",
122 __FUNCTION__, __LINE__);
123 return FPGA_FAIL;
124 }
125
126
127 if (fns->pre) {
128 if ((ret_val = fns->pre (cookie)) < 0) {
129 return ret_val;
130 }
131 }
132
133
134
135
136 fns->config (0, 1, cookie);
137 udelay (5);
138 fns->config (1, 1, cookie);
139 udelay (100);
140
141
142 bytecount = 0;
143 fns->clk (0, 1, cookie);
144
145 printf ("loading to fpga ");
146 while (bytecount < bsize) {
147
148 if (fns->status (cookie) != 1) {
149 printf
150 ("\n%s(%d) Stratix failed (byte transfered till failure 0x%x)\n",
151 __FUNCTION__, __LINE__, bytecount);
152 fns->abort (cookie);
153 return FPGA_FAIL;
154 }
155 if (isSerial) {
156 int i;
157 uint8_t data = buff[bytecount++];
158 for (i = 0; i < 8; i++) {
159
160 fns->data ((data >> i) & 1, 1, cookie);
161
162
163 fns->clk (1, 1, cookie);
164 fns->clk (0, 1, cookie);
165 }
166 } else {
167
168 fns->data (buff[bytecount++], 1, cookie);
169
170
171 fns->clk (1, 1, cookie);
172 fns->clk (0, 1, cookie);
173
174
175 for (i = 0; isSecure && i < 3; i++) {
176 fns->clk (1, 1, cookie);
177 fns->clk (0, 1, cookie);
178 }
179 }
180
181
182 if ((bytecount % (bsize / 100)) == 0) {
183 printf ("\b\b\b%02d\%", bytecount * 100 / bsize);
184 }
185 }
186
187
188 fns->clk (1, 1, cookie);
189 udelay (100);
190 if (!fns->done (cookie)) {
191 printf (" error!.\n");
192 fns->abort (cookie);
193 return FPGA_FAIL;
194 } else {
195 printf ("\b\b\b done.\n");
196 }
197
198
199 if (fns->post) {
200 if ((ret_val = fns->post (cookie)) < 0) {
201 fns->abort (cookie);
202 return ret_val;
203 }
204 }
205
206 return FPGA_SUCCESS;
207}
208