blob: 6370cafb23c27a3c2f8b3e4faf21837dde516c12 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekd5dae852013-04-22 15:43:02 +02002/*
3 * (C) Copyright 2012-2013, Xilinx, Michal Simek
4 *
5 * (C) Copyright 2012
6 * Joe Hershberger <joe.hershberger@ni.com>
Michal Simekd5dae852013-04-22 15:43:02 +02007 */
8
9#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -070010#include <console.h>
Simon Glass9edefc22019-11-14 12:57:37 -070011#include <cpu_func.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <asm/cache.h>
Michal Simekd5dae852013-04-22 15:43:02 +020013#include <asm/io.h>
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +053014#include <fs.h>
Michal Simekd5dae852013-04-22 15:43:02 +020015#include <zynqpl.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040016#include <linux/sizes.h>
Michal Simekd5dae852013-04-22 15:43:02 +020017#include <asm/arch/hardware.h>
18#include <asm/arch/sys_proto.h>
19
20#define DEVCFG_CTRL_PCFG_PROG_B 0x40000000
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +053021#define DEVCFG_CTRL_PCFG_AES_EFUSE_MASK 0x00001000
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +053022#define DEVCFG_CTRL_PCAP_RATE_EN_MASK 0x02000000
Michal Simekd5dae852013-04-22 15:43:02 +020023#define DEVCFG_ISR_FATAL_ERROR_MASK 0x00740040
24#define DEVCFG_ISR_ERROR_FLAGS_MASK 0x00340840
25#define DEVCFG_ISR_RX_FIFO_OV 0x00040000
26#define DEVCFG_ISR_DMA_DONE 0x00002000
27#define DEVCFG_ISR_PCFG_DONE 0x00000004
28#define DEVCFG_STATUS_DMA_CMD_Q_F 0x80000000
29#define DEVCFG_STATUS_DMA_CMD_Q_E 0x40000000
30#define DEVCFG_STATUS_DMA_DONE_CNT_MASK 0x30000000
31#define DEVCFG_STATUS_PCFG_INIT 0x00000010
Soren Brinkmann5f932272013-06-14 17:43:24 -070032#define DEVCFG_MCTRL_PCAP_LPBK 0x00000010
Michal Simekd5dae852013-04-22 15:43:02 +020033#define DEVCFG_MCTRL_RFIFO_FLUSH 0x00000002
34#define DEVCFG_MCTRL_WFIFO_FLUSH 0x00000001
35
36#ifndef CONFIG_SYS_FPGA_WAIT
37#define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
38#endif
39
40#ifndef CONFIG_SYS_FPGA_PROG_TIME
Michal Simekfd2b10b2013-06-17 13:54:07 +020041#define CONFIG_SYS_FPGA_PROG_TIME (CONFIG_SYS_HZ * 4) /* 4 s */
Michal Simekd5dae852013-04-22 15:43:02 +020042#endif
43
Michal Simekd5dae852013-04-22 15:43:02 +020044#define DUMMY_WORD 0xffffffff
45
46/* Xilinx binary format header */
47static const u32 bin_format[] = {
48 DUMMY_WORD, /* Dummy words */
49 DUMMY_WORD,
50 DUMMY_WORD,
51 DUMMY_WORD,
52 DUMMY_WORD,
53 DUMMY_WORD,
54 DUMMY_WORD,
55 DUMMY_WORD,
56 0x000000bb, /* Sync word */
57 0x11220044, /* Sync word */
58 DUMMY_WORD,
59 DUMMY_WORD,
60 0xaa995566, /* Sync word */
61};
62
63#define SWAP_NO 1
64#define SWAP_DONE 2
65
66/*
67 * Load the whole word from unaligned buffer
68 * Keep in your mind that it is byte loading on little-endian system
69 */
70static u32 load_word(const void *buf, u32 swap)
71{
72 u32 word = 0;
73 u8 *bitc = (u8 *)buf;
74 int p;
75
76 if (swap == SWAP_NO) {
77 for (p = 0; p < 4; p++) {
78 word <<= 8;
79 word |= bitc[p];
80 }
81 } else {
82 for (p = 3; p >= 0; p--) {
83 word <<= 8;
84 word |= bitc[p];
85 }
86 }
87
88 return word;
89}
90
91static u32 check_header(const void *buf)
92{
93 u32 i, pattern;
94 int swap = SWAP_NO;
95 u32 *test = (u32 *)buf;
96
97 debug("%s: Let's check bitstream header\n", __func__);
98
99 /* Checking that passing bin is not a bitstream */
100 for (i = 0; i < ARRAY_SIZE(bin_format); i++) {
101 pattern = load_word(&test[i], swap);
102
103 /*
104 * Bitstreams in binary format are swapped
105 * compare to regular bistream.
106 * Do not swap dummy word but if swap is done assume
107 * that parsing buffer is binary format
108 */
109 if ((__swab32(pattern) != DUMMY_WORD) &&
110 (__swab32(pattern) == bin_format[i])) {
111 pattern = __swab32(pattern);
112 swap = SWAP_DONE;
113 debug("%s: data swapped - let's swap\n", __func__);
114 }
115
116 debug("%s: %d/%x: pattern %x/%x bin_format\n", __func__, i,
117 (u32)&test[i], pattern, bin_format[i]);
118 if (pattern != bin_format[i]) {
119 debug("%s: Bitstream is not recognized\n", __func__);
120 return 0;
121 }
122 }
123 debug("%s: Found bitstream header at %x %s swapinng\n", __func__,
124 (u32)buf, swap == SWAP_NO ? "without" : "with");
125
126 return swap;
127}
128
129static void *check_data(u8 *buf, size_t bsize, u32 *swap)
130{
131 u32 word, p = 0; /* possition */
132
133 /* Because buf doesn't need to be aligned let's read it by chars */
134 for (p = 0; p < bsize; p++) {
135 word = load_word(&buf[p], SWAP_NO);
136 debug("%s: word %x %x/%x\n", __func__, word, p, (u32)&buf[p]);
137
138 /* Find the first bitstream dummy word */
139 if (word == DUMMY_WORD) {
140 debug("%s: Found dummy word at position %x/%x\n",
141 __func__, p, (u32)&buf[p]);
142 *swap = check_header(&buf[p]);
143 if (*swap) {
144 /* FIXME add full bitstream checking here */
145 return &buf[p];
146 }
147 }
148 /* Loop can be huge - support CTRL + C */
149 if (ctrlc())
Michal Simek42a74a02014-04-25 13:51:58 +0200150 return NULL;
Michal Simekd5dae852013-04-22 15:43:02 +0200151 }
Michal Simek42a74a02014-04-25 13:51:58 +0200152 return NULL;
Michal Simekd5dae852013-04-22 15:43:02 +0200153}
154
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530155static int zynq_dma_transfer(u32 srcbuf, u32 srclen, u32 dstbuf, u32 dstlen)
Michal Simekd5dae852013-04-22 15:43:02 +0200156{
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530157 unsigned long ts;
158 u32 isr_status;
Michal Simekd5dae852013-04-22 15:43:02 +0200159
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530160 /* Set up the transfer */
161 writel((u32)srcbuf, &devcfg_base->dma_src_addr);
162 writel(dstbuf, &devcfg_base->dma_dst_addr);
163 writel(srclen, &devcfg_base->dma_src_len);
164 writel(dstlen, &devcfg_base->dma_dst_len);
Michal Simekd5dae852013-04-22 15:43:02 +0200165
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530166 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200167
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530168 /* Polling the PCAP_INIT status for Set */
169 ts = get_timer(0);
170 while (!(isr_status & DEVCFG_ISR_DMA_DONE)) {
171 if (isr_status & DEVCFG_ISR_ERROR_FLAGS_MASK) {
172 debug("%s: Error: isr = 0x%08X\n", __func__,
173 isr_status);
174 debug("%s: Write count = 0x%08X\n", __func__,
175 readl(&devcfg_base->write_count));
176 debug("%s: Read count = 0x%08X\n", __func__,
177 readl(&devcfg_base->read_count));
Michal Simekd5dae852013-04-22 15:43:02 +0200178
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530179 return FPGA_FAIL;
Novasys Ingenieriec83a35f2013-11-27 09:03:01 +0100180 }
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530181 if (get_timer(ts) > CONFIG_SYS_FPGA_PROG_TIME) {
182 printf("%s: Timeout wait for DMA to complete\n",
183 __func__);
184 return FPGA_FAIL;
185 }
186 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200187 }
188
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530189 debug("%s: DMA transfer is done\n", __func__);
190
191 /* Clear out the DMA status */
192 writel(DEVCFG_ISR_DMA_DONE, &devcfg_base->int_sts);
193
194 return FPGA_SUCCESS;
195}
196
Michal Simek5b815c92014-05-02 14:15:27 +0200197static int zynq_dma_xfer_init(bitstream_type bstype)
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530198{
199 u32 status, control, isr_status;
200 unsigned long ts;
201
Soren Brinkmann5f932272013-06-14 17:43:24 -0700202 /* Clear loopback bit */
203 clrbits_le32(&devcfg_base->mctrl, DEVCFG_MCTRL_PCAP_LPBK);
204
Michal Simek5b815c92014-05-02 14:15:27 +0200205 if (bstype != BIT_PARTIAL) {
Michal Simekd5dae852013-04-22 15:43:02 +0200206 zynq_slcr_devcfg_disable();
207
208 /* Setting PCFG_PROG_B signal to high */
209 control = readl(&devcfg_base->ctrl);
210 writel(control | DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +0530211
212 /*
213 * Delay is required if AES efuse is selected as
214 * key source.
215 */
216 if (control & DEVCFG_CTRL_PCFG_AES_EFUSE_MASK)
217 mdelay(5);
218
Michal Simekd5dae852013-04-22 15:43:02 +0200219 /* Setting PCFG_PROG_B signal to low */
220 writel(control & ~DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
221
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +0530222 /*
223 * Delay is required if AES efuse is selected as
224 * key source.
225 */
226 if (control & DEVCFG_CTRL_PCFG_AES_EFUSE_MASK)
227 mdelay(5);
228
Michal Simekd5dae852013-04-22 15:43:02 +0200229 /* Polling the PCAP_INIT status for Reset */
230 ts = get_timer(0);
231 while (readl(&devcfg_base->status) & DEVCFG_STATUS_PCFG_INIT) {
232 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
233 printf("%s: Timeout wait for INIT to clear\n",
234 __func__);
235 return FPGA_FAIL;
236 }
237 }
238
239 /* Setting PCFG_PROG_B signal to high */
240 writel(control | DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
241
242 /* Polling the PCAP_INIT status for Set */
243 ts = get_timer(0);
244 while (!(readl(&devcfg_base->status) &
245 DEVCFG_STATUS_PCFG_INIT)) {
246 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
247 printf("%s: Timeout wait for INIT to set\n",
248 __func__);
249 return FPGA_FAIL;
250 }
251 }
252 }
253
254 isr_status = readl(&devcfg_base->int_sts);
255
256 /* Clear it all, so if Boot ROM comes back, it can proceed */
257 writel(0xFFFFFFFF, &devcfg_base->int_sts);
258
259 if (isr_status & DEVCFG_ISR_FATAL_ERROR_MASK) {
260 debug("%s: Fatal errors in PCAP 0x%X\n", __func__, isr_status);
261
262 /* If RX FIFO overflow, need to flush RX FIFO first */
263 if (isr_status & DEVCFG_ISR_RX_FIFO_OV) {
264 writel(DEVCFG_MCTRL_RFIFO_FLUSH, &devcfg_base->mctrl);
265 writel(0xFFFFFFFF, &devcfg_base->int_sts);
266 }
267 return FPGA_FAIL;
268 }
269
270 status = readl(&devcfg_base->status);
271
272 debug("%s: Status = 0x%08X\n", __func__, status);
273
274 if (status & DEVCFG_STATUS_DMA_CMD_Q_F) {
275 debug("%s: Error: device busy\n", __func__);
276 return FPGA_FAIL;
277 }
278
279 debug("%s: Device ready\n", __func__);
280
281 if (!(status & DEVCFG_STATUS_DMA_CMD_Q_E)) {
282 if (!(readl(&devcfg_base->int_sts) & DEVCFG_ISR_DMA_DONE)) {
283 /* Error state, transfer cannot occur */
284 debug("%s: ISR indicates error\n", __func__);
285 return FPGA_FAIL;
286 } else {
287 /* Clear out the status */
288 writel(DEVCFG_ISR_DMA_DONE, &devcfg_base->int_sts);
289 }
290 }
291
292 if (status & DEVCFG_STATUS_DMA_DONE_CNT_MASK) {
293 /* Clear the count of completed DMA transfers */
294 writel(DEVCFG_STATUS_DMA_DONE_CNT_MASK, &devcfg_base->status);
295 }
296
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530297 return FPGA_SUCCESS;
298}
299
300static u32 *zynq_align_dma_buffer(u32 *buf, u32 len, u32 swap)
301{
302 u32 *new_buf;
303 u32 i;
304
305 if ((u32)buf != ALIGN((u32)buf, ARCH_DMA_MINALIGN)) {
306 new_buf = (u32 *)ALIGN((u32)buf, ARCH_DMA_MINALIGN);
307
308 /*
309 * This might be dangerous but permits to flash if
310 * ARCH_DMA_MINALIGN is greater than header size
311 */
312 if (new_buf > buf) {
313 debug("%s: Aligned buffer is after buffer start\n",
314 __func__);
315 new_buf -= ARCH_DMA_MINALIGN;
316 }
317 printf("%s: Align buffer at %x to %x(swap %d)\n", __func__,
318 (u32)buf, (u32)new_buf, swap);
319
320 for (i = 0; i < (len/4); i++)
321 new_buf[i] = load_word(&buf[i], swap);
322
323 buf = new_buf;
324 } else if (swap != SWAP_DONE) {
325 /* For bitstream which are aligned */
326 u32 *new_buf = (u32 *)buf;
327
328 printf("%s: Bitstream is not swapped(%d) - swap it\n", __func__,
329 swap);
330
331 for (i = 0; i < (len/4); i++)
332 new_buf[i] = load_word(&buf[i], swap);
333 }
334
335 return buf;
336}
337
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530338static int zynq_validate_bitstream(xilinx_desc *desc, const void *buf,
339 size_t bsize, u32 blocksize, u32 *swap,
Michal Simek5b815c92014-05-02 14:15:27 +0200340 bitstream_type *bstype)
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530341{
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530342 u32 *buf_start;
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530343 u32 diff;
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530344
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530345 buf_start = check_data((u8 *)buf, blocksize, swap);
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530346
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530347 if (!buf_start)
348 return FPGA_FAIL;
349
350 /* Check if data is postpone from start */
351 diff = (u32)buf_start - (u32)buf;
352 if (diff) {
353 printf("%s: Bitstream is not validated yet (diff %x)\n",
354 __func__, diff);
355 return FPGA_FAIL;
356 }
357
358 if ((u32)buf < SZ_1M) {
359 printf("%s: Bitstream has to be placed up to 1MB (%x)\n",
360 __func__, (u32)buf);
361 return FPGA_FAIL;
362 }
363
Michal Simek5b815c92014-05-02 14:15:27 +0200364 if (zynq_dma_xfer_init(*bstype))
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530365 return FPGA_FAIL;
366
367 return 0;
368}
369
Michal Simek7a78bd22014-05-02 14:09:30 +0200370static int zynq_load(xilinx_desc *desc, const void *buf, size_t bsize,
371 bitstream_type bstype)
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530372{
373 unsigned long ts; /* Timestamp */
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530374 u32 isr_status, swap;
375
376 /*
377 * send bsize inplace of blocksize as it was not a bitstream
378 * in chunks
379 */
380 if (zynq_validate_bitstream(desc, buf, bsize, bsize, &swap,
Michal Simek5b815c92014-05-02 14:15:27 +0200381 &bstype))
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530382 return FPGA_FAIL;
383
384 buf = zynq_align_dma_buffer((u32 *)buf, bsize, swap);
385
Michal Simekd5dae852013-04-22 15:43:02 +0200386 debug("%s: Source = 0x%08X\n", __func__, (u32)buf);
387 debug("%s: Size = %zu\n", __func__, bsize);
388
Jagannadha Sutradharudu Tekiec4b73f2013-09-20 18:39:47 +0530389 /* flush(clean & invalidate) d-cache range buf */
390 flush_dcache_range((u32)buf, (u32)buf +
391 roundup(bsize, ARCH_DMA_MINALIGN));
392
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530393 if (zynq_dma_transfer((u32)buf | 1, bsize >> 2, 0xffffffff, 0))
394 return FPGA_FAIL;
Michal Simekd5dae852013-04-22 15:43:02 +0200395
396 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200397 /* Check FPGA configuration completion */
398 ts = get_timer(0);
399 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
400 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
401 printf("%s: Timeout wait for FPGA to config\n",
402 __func__);
403 return FPGA_FAIL;
404 }
405 isr_status = readl(&devcfg_base->int_sts);
406 }
407
408 debug("%s: FPGA config done\n", __func__);
409
Michal Simek5b815c92014-05-02 14:15:27 +0200410 if (bstype != BIT_PARTIAL)
Michal Simekd5dae852013-04-22 15:43:02 +0200411 zynq_slcr_devcfg_enable();
412
Siva Durga Prasad Paladugu31f7ce72019-03-23 16:01:36 +0530413 puts("INFO:post config was not run, please run manually if needed\n");
414
Michal Simekd5dae852013-04-22 15:43:02 +0200415 return FPGA_SUCCESS;
416}
417
Luis Aranedad600c4f2018-07-19 03:10:17 -0400418#if defined(CONFIG_CMD_FPGA_LOADFS) && !defined(CONFIG_SPL_BUILD)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530419static int zynq_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
420 fpga_fs_info *fsinfo)
421{
422 unsigned long ts; /* Timestamp */
423 u32 isr_status, swap;
424 u32 partialbit = 0;
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800425 loff_t blocksize, actread;
426 loff_t pos = 0;
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530427 int fstype;
Tien Fong Chee3003c442019-02-15 15:57:07 +0800428 char *interface, *dev_part;
429 const char *filename;
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530430
431 blocksize = fsinfo->blocksize;
432 interface = fsinfo->interface;
433 dev_part = fsinfo->dev_part;
434 filename = fsinfo->filename;
435 fstype = fsinfo->fstype;
436
437 if (fs_set_blk_dev(interface, dev_part, fstype))
438 return FPGA_FAIL;
439
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800440 if (fs_read(filename, (u32) buf, pos, blocksize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530441 return FPGA_FAIL;
442
443 if (zynq_validate_bitstream(desc, buf, bsize, blocksize, &swap,
444 &partialbit))
445 return FPGA_FAIL;
446
447 dcache_disable();
448
449 do {
450 buf = zynq_align_dma_buffer((u32 *)buf, blocksize, swap);
451
452 if (zynq_dma_transfer((u32)buf | 1, blocksize >> 2,
453 0xffffffff, 0))
454 return FPGA_FAIL;
455
456 bsize -= blocksize;
457 pos += blocksize;
458
459 if (fs_set_blk_dev(interface, dev_part, fstype))
460 return FPGA_FAIL;
461
462 if (bsize > blocksize) {
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800463 if (fs_read(filename, (u32) buf, pos, blocksize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530464 return FPGA_FAIL;
465 } else {
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800466 if (fs_read(filename, (u32) buf, pos, bsize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530467 return FPGA_FAIL;
468 }
469 } while (bsize > blocksize);
470
471 buf = zynq_align_dma_buffer((u32 *)buf, blocksize, swap);
472
473 if (zynq_dma_transfer((u32)buf | 1, bsize >> 2, 0xffffffff, 0))
474 return FPGA_FAIL;
475
476 dcache_enable();
477
478 isr_status = readl(&devcfg_base->int_sts);
479
480 /* Check FPGA configuration completion */
481 ts = get_timer(0);
482 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
483 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
484 printf("%s: Timeout wait for FPGA to config\n",
485 __func__);
486 return FPGA_FAIL;
487 }
488 isr_status = readl(&devcfg_base->int_sts);
489 }
490
491 debug("%s: FPGA config done\n", __func__);
492
493 if (!partialbit)
494 zynq_slcr_devcfg_enable();
495
496 return FPGA_SUCCESS;
497}
498#endif
499
Michal Simek14cfc4f2014-03-13 13:07:57 +0100500struct xilinx_fpga_op zynq_op = {
501 .load = zynq_load,
Luis Aranedad600c4f2018-07-19 03:10:17 -0400502#if defined(CONFIG_CMD_FPGA_LOADFS) && !defined(CONFIG_SPL_BUILD)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530503 .loadfs = zynq_loadfs,
504#endif
Michal Simek14cfc4f2014-03-13 13:07:57 +0100505};
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530506
507#ifdef CONFIG_CMD_ZYNQ_AES
508/*
509 * Load the encrypted image from src addr and decrypt the image and
510 * place it back the decrypted image into dstaddr.
511 */
512int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen)
513{
514 if (srcaddr < SZ_1M || dstaddr < SZ_1M) {
515 printf("%s: src and dst addr should be > 1M\n",
516 __func__);
517 return FPGA_FAIL;
518 }
519
520 if (zynq_dma_xfer_init(BIT_NONE)) {
521 printf("%s: zynq_dma_xfer_init FAIL\n", __func__);
522 return FPGA_FAIL;
523 }
524
525 writel((readl(&devcfg_base->ctrl) | DEVCFG_CTRL_PCAP_RATE_EN_MASK),
526 &devcfg_base->ctrl);
527
528 debug("%s: Source = 0x%08X\n", __func__, (u32)srcaddr);
529 debug("%s: Size = %zu\n", __func__, srclen);
530
531 /* flush(clean & invalidate) d-cache range buf */
532 flush_dcache_range((u32)srcaddr, (u32)srcaddr +
533 roundup(srclen << 2, ARCH_DMA_MINALIGN));
534 /*
535 * Flush destination address range only if image is not
536 * bitstream.
537 */
538 flush_dcache_range((u32)dstaddr, (u32)dstaddr +
539 roundup(dstlen << 2, ARCH_DMA_MINALIGN));
540
541 if (zynq_dma_transfer(srcaddr | 1, srclen, dstaddr | 1, dstlen))
542 return FPGA_FAIL;
543
544 writel((readl(&devcfg_base->ctrl) & ~DEVCFG_CTRL_PCAP_RATE_EN_MASK),
545 &devcfg_base->ctrl);
546
547 return FPGA_SUCCESS;
548}
549#endif