OpenOCD
lattice.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2022 by Daniel Anselmi *
5  * danselmi@gmx.ch *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include "lattice.h"
13 #include <jtag/jtag.h>
14 #include "pld.h"
15 #include "lattice_bit.h"
16 #include "ecp2_3.h"
17 #include "ecp5.h"
18 #include "certus.h"
19 
20 #define PRELOAD 0x1C
21 #define USER1 0x32
22 #define USER2 0x38
23 
24 
26  uint32_t id;
29 };
30 
31 static const struct lattice_devices_elem lattice_devices[] = {
32  {0x01270043, 654, LATTICE_ECP2 /* ecp2-6e */},
33  {0x01271043, 643, LATTICE_ECP2 /* ecp2-12e */},
34  {0x01272043, 827, LATTICE_ECP2 /* ecp2-20e */},
35  {0x01274043, 1011, LATTICE_ECP2 /* ecp2-35e */},
36  {0x01273043, 1219, LATTICE_ECP2 /* ecp2-50e */},
37  {0x01275043, 654, LATTICE_ECP2 /* ecp2-70e */},
38  {0x01279043, 680, LATTICE_ECP2 /* ecp2m20e */},
39  {0x0127A043, 936, LATTICE_ECP2 /* ecp2m35e */},
40  {0x0127B043, 1056, LATTICE_ECP2 /* ecp2m50e */},
41  {0x0127C043, 1039, LATTICE_ECP2 /* ecp2m70e */},
42  {0x0127D043, 1311, LATTICE_ECP2 /* ecp2m100e */},
43  {0x01010043, 467, LATTICE_ECP3 /* ecp3 lae3-17ea & lfe3-17ea*/},
44  {0x01012043, 675, LATTICE_ECP3 /* ecp3 lae3-35ea & lfe3-35ea*/},
45  {0x01014043, 1077, LATTICE_ECP3 /* ecp3 lfe3-70ea & lfe3-70e & lfe3-95ea && lfe3-95e*/},
46  {0x01015043, 1326, LATTICE_ECP3 /* ecp3 lfe3-150e*/},
47  {0x21111043, 409, LATTICE_ECP5 /* "LAE5U-12F & LFE5U-12F" */},
48  {0x41111043, 409, LATTICE_ECP5 /* "LFE5U-25F" */},
49  {0x41112043, 510, LATTICE_ECP5 /* "LFE5U-45F" */},
50  {0x41113043, 750, LATTICE_ECP5 /* "LFE5U-85F" */},
51  {0x81111043, 409, LATTICE_ECP5 /* "LFE5UM5G-25F" */},
52  {0x81112043, 510, LATTICE_ECP5 /* "LFE5UM5G-45F" */},
53  {0x81113043, 750, LATTICE_ECP5 /* "LFE5UM5G-85F" */},
54  {0x01111043, 409, LATTICE_ECP5 /* "LAE5UM-25F" */},
55  {0x01112043, 510, LATTICE_ECP5 /* "LAE5UM-45F" */},
56  {0x01113043, 750, LATTICE_ECP5 /* "LAE5UM-85F" */},
57  {0x310f0043, 362, LATTICE_CERTUS /* LFD2NX-17 */},
58  {0x310f1043, 362, LATTICE_CERTUS /* LFD2NX-40 */},
59  {0x010f4043, 362, LATTICE_CERTUS /* LFCPNX-100 */},
60 };
61 
62 int lattice_set_instr(struct jtag_tap *tap, uint8_t new_instr, enum tap_state endstate)
63 {
64  struct scan_field field;
65  field.num_bits = tap->ir_length;
66  void *t = calloc(DIV_ROUND_UP(field.num_bits, 8), 1);
67  if (!t) {
68  LOG_ERROR("Out of memory");
69  return ERROR_FAIL;
70  }
71  field.out_value = t;
72  buf_set_u32(t, 0, field.num_bits, new_instr);
73  field.in_value = NULL;
74  jtag_add_ir_scan(tap, &field, endstate);
75  free(t);
76  return ERROR_OK;
77 }
78 
79 static int lattice_check_device_family(struct lattice_pld_device *lattice_device)
80 {
81  if (lattice_device->family != LATTICE_UNKNOWN && lattice_device->preload_length != 0)
82  return ERROR_OK;
83 
84  if (!lattice_device->tap || !lattice_device->tap->has_idcode)
85  return ERROR_FAIL;
86 
87  for (size_t i = 0; i < ARRAY_SIZE(lattice_devices); ++i) {
88  if (lattice_devices[i].id == lattice_device->tap->idcode) {
89  if (lattice_device->family == LATTICE_UNKNOWN)
90  lattice_device->family = lattice_devices[i].family;
91  if (lattice_device->preload_length == 0)
92  lattice_device->preload_length = lattice_devices[i].preload_length;
93  return ERROR_OK;
94  }
95  }
96  LOG_ERROR("Unknown id! Specify family and preload-length manually.");
97  return ERROR_FAIL;
98 }
99 
100 int lattice_read_u32_register(struct jtag_tap *tap, uint8_t cmd, uint32_t *in_val,
101  uint32_t out_val, bool do_idle)
102 {
103  struct scan_field field;
104  uint8_t buffer[4];
105 
106  int retval = lattice_set_instr(tap, cmd, TAP_IDLE);
107  if (retval != ERROR_OK)
108  return retval;
109  if (do_idle) {
111  jtag_add_sleep(1000);
112  }
113 
114  h_u32_to_le(buffer, out_val);
115  field.num_bits = 32;
116  field.out_value = buffer;
117  field.in_value = buffer;
118  jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
119  retval = jtag_execute_queue();
120  if (retval == ERROR_OK)
121  *in_val = le_to_h_u32(buffer);
122 
123  return retval;
124 }
125 
126 int lattice_read_u64_register(struct jtag_tap *tap, uint8_t cmd, uint64_t *in_val,
127  uint64_t out_val)
128 {
129  struct scan_field field;
130  uint8_t buffer[8];
131 
132  int retval = lattice_set_instr(tap, cmd, TAP_IDLE);
133  if (retval != ERROR_OK)
134  return retval;
135  h_u64_to_le(buffer, out_val);
136  field.num_bits = 64;
137  field.out_value = buffer;
138  field.in_value = buffer;
139  jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
140  retval = jtag_execute_queue();
141  if (retval == ERROR_OK)
142  *in_val = le_to_h_u64(buffer);
143 
144  return retval;
145 }
146 
147 int lattice_preload(struct lattice_pld_device *lattice_device)
148 {
149  struct scan_field field;
150  size_t sz_bytes = DIV_ROUND_UP(lattice_device->preload_length, 8);
151 
152  int retval = lattice_set_instr(lattice_device->tap, PRELOAD, TAP_IDLE);
153  if (retval != ERROR_OK)
154  return retval;
155  uint8_t *buffer = malloc(sz_bytes);
156  if (!buffer) {
157  LOG_ERROR("Out of memory");
158  return ERROR_FAIL;
159  }
160  memset(buffer, 0xff, sz_bytes);
161 
162  field.num_bits = lattice_device->preload_length;
163  field.out_value = buffer;
164  field.in_value = NULL;
165  jtag_add_dr_scan(lattice_device->tap, 1, &field, TAP_IDLE);
166  retval = jtag_execute_queue();
167  free(buffer);
168  return retval;
169 }
170 
171 static int lattice_read_usercode(struct lattice_pld_device *lattice_device, uint32_t *usercode, uint32_t out)
172 {
173  struct jtag_tap *tap = lattice_device->tap;
174  if (!tap)
175  return ERROR_FAIL;
176 
177  if (lattice_device->family == LATTICE_ECP2 || lattice_device->family == LATTICE_ECP3)
178  return lattice_ecp2_3_read_usercode(tap, usercode, out);
179  else if (lattice_device->family == LATTICE_ECP5)
180  return lattice_ecp5_read_usercode(tap, usercode, out);
181  else if (lattice_device->family == LATTICE_CERTUS)
182  return lattice_certus_read_usercode(tap, usercode, out);
183 
184  return ERROR_FAIL;
185 }
186 
187 int lattice_verify_usercode(struct lattice_pld_device *lattice_device, uint32_t out,
188  uint32_t expected, uint32_t mask)
189 {
190  uint32_t usercode;
191 
192  int retval = lattice_read_usercode(lattice_device, &usercode, out);
193  if (retval != ERROR_OK)
194  return retval;
195 
196  if ((usercode & mask) != expected) {
197  LOG_ERROR("verifying user code register failed got: 0x%08" PRIx32 " expected: 0x%08" PRIx32,
198  usercode & mask, expected);
199  return ERROR_FAIL;
200  }
201  return ERROR_OK;
202 }
203 
204 static int lattice_write_usercode(struct lattice_pld_device *lattice_device, uint32_t usercode)
205 {
206  if (lattice_device->family == LATTICE_ECP2 || lattice_device->family == LATTICE_ECP3)
207  return lattice_ecp2_3_write_usercode(lattice_device, usercode);
208  else if (lattice_device->family == LATTICE_ECP5)
209  return lattice_ecp5_write_usercode(lattice_device, usercode);
210  else if (lattice_device->family == LATTICE_CERTUS)
211  return lattice_certus_write_usercode(lattice_device, usercode);
212 
213  return ERROR_FAIL;
214 }
215 
216 static int lattice_read_status_u32(struct lattice_pld_device *lattice_device, uint32_t *status,
217  uint32_t out, bool do_idle)
218 {
219  if (!lattice_device->tap)
220  return ERROR_FAIL;
221 
222  if (lattice_device->family == LATTICE_ECP2 || lattice_device->family == LATTICE_ECP3)
223  return lattice_ecp2_3_read_status(lattice_device->tap, status, out, do_idle);
224  else if (lattice_device->family == LATTICE_ECP5)
225  return lattice_ecp5_read_status(lattice_device->tap, status, out, do_idle);
226 
227  return ERROR_FAIL;
228 }
229 static int lattice_read_status_u64(struct lattice_pld_device *lattice_device, uint64_t *status,
230  uint64_t out)
231 {
232  if (!lattice_device->tap)
233  return ERROR_FAIL;
234 
235  if (lattice_device->family == LATTICE_CERTUS)
236  return lattice_certus_read_status(lattice_device->tap, status, out);
237 
238  return ERROR_FAIL;
239 }
240 
241 int lattice_verify_status_register_u32(struct lattice_pld_device *lattice_device, uint32_t out,
242  uint32_t expected, uint32_t mask, bool do_idle)
243 {
244  uint32_t status;
245  int retval = lattice_read_status_u32(lattice_device, &status, out, do_idle);
246  if (retval != ERROR_OK)
247  return retval;
248 
249  if ((status & mask) != expected) {
250  LOG_ERROR("verifying status register failed got: 0x%08" PRIx32 " expected: 0x%08" PRIx32,
251  status & mask, expected);
252  return ERROR_FAIL;
253  }
254  return ERROR_OK;
255 }
256 
257 int lattice_verify_status_register_u64(struct lattice_pld_device *lattice_device, uint64_t out,
258  uint64_t expected, uint64_t mask)
259 {
260  uint64_t status;
261  int retval = lattice_read_status_u64(lattice_device, &status, out);
262  if (retval != ERROR_OK)
263  return retval;
264 
265  if ((status & mask) != expected) {
266  LOG_ERROR("verifying status register failed got: 0x%08" PRIx64 " expected: 0x%08" PRIx64,
267  status & mask, expected);
268  return ERROR_FAIL;
269  }
270  return ERROR_OK;
271 }
272 
273 static int lattice_load_command(struct pld_device *pld_device, const char *filename)
274 {
275  if (!pld_device)
276  return ERROR_FAIL;
277 
278  struct lattice_pld_device *lattice_device = pld_device->driver_priv;
279  if (!lattice_device || !lattice_device->tap)
280  return ERROR_FAIL;
281  struct jtag_tap *tap = lattice_device->tap;
282 
283  if (!tap || !tap->has_idcode)
284  return ERROR_FAIL;
285 
286  int retval = lattice_check_device_family(lattice_device);
287  if (retval != ERROR_OK)
288  return retval;
289 
290  struct lattice_bit_file bit_file;
291  retval = lattice_read_file(&bit_file, filename, lattice_device->family);
292  if (retval != ERROR_OK)
293  return retval;
294 
295  uint32_t id = tap->idcode;
296  retval = ERROR_FAIL;
297  switch (lattice_device->family) {
298  case LATTICE_ECP2:
299  retval = lattice_ecp2_load(lattice_device, &bit_file);
300  break;
301  case LATTICE_ECP3:
302  retval = lattice_ecp3_load(lattice_device, &bit_file);
303  break;
304  case LATTICE_ECP5:
305  case LATTICE_CERTUS:
306  if (bit_file.has_id && id != bit_file.idcode)
307  LOG_WARNING("Id on device (0x%8.8" PRIx32 ") and id in bit-stream (0x%8.8" PRIx32 ") don't match.",
308  id, bit_file.idcode);
309  if (lattice_device->family == LATTICE_ECP5)
310  retval = lattice_ecp5_load(lattice_device, &bit_file);
311  else
312  retval = lattice_certus_load(lattice_device, &bit_file);
313  break;
314  default:
315  LOG_ERROR("loading unknown device family");
316  break;
317  }
318  free(bit_file.raw_bit.data);
319  return retval;
320 }
321 
322 static int lattice_get_ipdbg_hub(int user_num, struct pld_device *pld_device, struct pld_ipdbg_hub *hub)
323 {
324  if (!pld_device)
325  return ERROR_FAIL;
326 
327  struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
328 
329  if (!pld_device_info || !pld_device_info->tap)
330  return ERROR_FAIL;
331 
332  hub->tap = pld_device_info->tap;
333 
334  if (user_num == 1) {
335  hub->user_ir_code = USER1;
336  } else if (user_num == 2) {
337  hub->user_ir_code = USER2;
338  } else {
339  LOG_ERROR("lattice devices only have user register 1 & 2");
340  return ERROR_FAIL;
341  }
342  return ERROR_OK;
343 }
344 
346 {
347  if (!pld_device)
348  return ERROR_FAIL;
349 
350  struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
351 
352  int retval = lattice_check_device_family(pld_device_info);
353  if (retval != ERROR_OK)
354  return retval;
355 
356  if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family == LATTICE_ECP3)
357  return lattice_ecp2_3_connect_spi_to_jtag(pld_device_info);
358  else if (pld_device_info->family == LATTICE_ECP5)
359  return lattice_ecp5_connect_spi_to_jtag(pld_device_info);
360  else if (pld_device_info->family == LATTICE_CERTUS)
361  return lattice_certus_connect_spi_to_jtag(pld_device_info);
362 
363  return ERROR_FAIL;
364 }
365 
367 {
368  if (!pld_device)
369  return ERROR_FAIL;
370 
371  struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
372 
373  int retval = lattice_check_device_family(pld_device_info);
374  if (retval != ERROR_OK)
375  return retval;
376 
377  if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family == LATTICE_ECP3)
378  return lattice_ecp2_3_disconnect_spi_from_jtag(pld_device_info);
379  else if (pld_device_info->family == LATTICE_ECP5)
380  return lattice_ecp5_disconnect_spi_from_jtag(pld_device_info);
381  else if (pld_device_info->family == LATTICE_CERTUS)
382  return lattice_certus_disconnect_spi_from_jtag(pld_device_info);
383 
384  return ERROR_FAIL;
385 }
386 
387 static int lattice_get_stuff_bits(struct pld_device *pld_device, unsigned int *facing_read_bits,
388  unsigned int *trailing_write_bits)
389 {
390  if (!pld_device)
391  return ERROR_FAIL;
392 
393  struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
394 
395  int retval = lattice_check_device_family(pld_device_info);
396  if (retval != ERROR_OK)
397  return retval;
398 
399  if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family == LATTICE_ECP3)
400  return lattice_ecp2_3_get_facing_read_bits(pld_device_info, facing_read_bits);
401  else if (pld_device_info->family == LATTICE_ECP5)
402  return lattice_ecp5_get_facing_read_bits(pld_device_info, facing_read_bits);
403  else if (pld_device_info->family == LATTICE_CERTUS)
404  return lattice_certus_get_facing_read_bits(pld_device_info, facing_read_bits);
405 
406  return ERROR_FAIL;
407 }
408 
409 static int lattice_has_jtagspi_instruction(struct pld_device *device, bool *has_instruction)
410 {
411  *has_instruction = true;
412  return ERROR_OK;
413 }
414 
415 PLD_CREATE_COMMAND_HANDLER(lattice_pld_create_command)
416 {
417  if (CMD_ARGC != 4 && CMD_ARGC != 6)
419 
420  if (!strcmp(CMD_ARGV[2], "-chain-position"))
421  LOG_WARNING("[%s] DEPRECATED! '-chain-position' will be removed in the future, use '-tap' instead",
422  CMD_ARGV[0]);
423  else if (strcmp(CMD_ARGV[2], "-tap") != 0)
425 
426  struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[3]);
427  if (!tap) {
428  command_print(CMD, "Tap: %s does not exist", CMD_ARGV[3]);
429  return ERROR_FAIL;
430  }
431 
432  /* id is not known yet -> postpone lattice_check_device_family() */
433  enum lattice_family_e family = LATTICE_UNKNOWN;
434  if (CMD_ARGC == 6) {
435  if (strcmp(CMD_ARGV[4], "-family") != 0)
437 
438  if (strcasecmp(CMD_ARGV[5], "ecp2") == 0) {
439  family = LATTICE_ECP2;
440  } else if (strcasecmp(CMD_ARGV[5], "ecp3") == 0) {
441  family = LATTICE_ECP3;
442  } else if (strcasecmp(CMD_ARGV[5], "ecp5") == 0) {
443  family = LATTICE_ECP5;
444  } else if (strcasecmp(CMD_ARGV[5], "certus") == 0) {
445  family = LATTICE_CERTUS;
446  } else {
447  command_print(CMD, "unknown family");
448  return ERROR_FAIL;
449  }
450  }
451 
452  struct lattice_pld_device *lattice_device = malloc(sizeof(struct lattice_pld_device));
453  if (!lattice_device) {
454  LOG_ERROR("Out of memory");
455  return ERROR_FAIL;
456  }
457 
458  lattice_device->tap = tap;
459  lattice_device->family = family;
460  lattice_device->preload_length = 0;
461 
462  pld->driver_priv = lattice_device;
463 
464  return ERROR_OK;
465 }
466 
467 COMMAND_HANDLER(lattice_read_usercode_register_command_handler)
468 {
469  uint32_t usercode;
470 
471  if (CMD_ARGC != 1)
473 
475  if (!device) {
476  command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
477  return ERROR_FAIL;
478  }
479 
480  struct lattice_pld_device *lattice_device = device->driver_priv;
481  if (!lattice_device)
482  return ERROR_FAIL;
483 
484  int retval = lattice_check_device_family(lattice_device);
485  if (retval != ERROR_OK)
486  return retval;
487 
488  retval = lattice_read_usercode(lattice_device, &usercode, 0x0);
489  if (retval == ERROR_OK)
490  command_print(CMD, "0x%8.8" PRIx32, usercode);
491 
492  return retval;
493 }
494 
495 COMMAND_HANDLER(lattice_set_preload_command_handler)
496 {
497  unsigned int preload_length;
498 
499  if (CMD_ARGC != 2)
501 
503  if (!device) {
504  command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
505  return ERROR_FAIL;
506  }
507 
508  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], preload_length);
509 
510  struct lattice_pld_device *lattice_device = device->driver_priv;
511 
512  if (!lattice_device)
513  return ERROR_FAIL;
514 
515  lattice_device->preload_length = preload_length;
516 
517  return ERROR_OK;
518 }
519 
520 COMMAND_HANDLER(lattice_write_usercode_register_command_handler)
521 {
522  uint32_t usercode;
523 
524  if (CMD_ARGC != 2)
526 
528  if (!device) {
529  command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
530  return ERROR_FAIL;
531  }
532 
533  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], usercode);
534 
535  struct lattice_pld_device *lattice_device = device->driver_priv;
536  if (!lattice_device)
537  return ERROR_FAIL;
538 
539  int retval = lattice_check_device_family(lattice_device);
540  if (retval != ERROR_OK)
541  return retval;
542 
543  return lattice_write_usercode(lattice_device, usercode);
544 }
545 
546 COMMAND_HANDLER(lattice_read_status_command_handler)
547 {
548  if (CMD_ARGC != 1)
550 
552  if (!device) {
553  command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
554  return ERROR_FAIL;
555  }
556 
557  struct lattice_pld_device *lattice_device = device->driver_priv;
558  if (!lattice_device)
559  return ERROR_FAIL;
560 
561  int retval = lattice_check_device_family(lattice_device);
562  if (retval != ERROR_OK)
563  return retval;
564 
565  if (lattice_device->family == LATTICE_CERTUS) {
566  uint64_t status;
567  retval = lattice_read_status_u64(lattice_device, &status, 0x0);
568  if (retval == ERROR_OK)
569  command_print(CMD, "0x%016" PRIx64, status);
570  } else {
571  uint32_t status;
572  const bool do_idle = lattice_device->family == LATTICE_ECP5;
573  retval = lattice_read_status_u32(lattice_device, &status, 0x0, do_idle);
574  if (retval == ERROR_OK)
575  command_print(CMD, "0x%8.8" PRIx32, status);
576  }
577 
578  return retval;
579 }
580 
581 COMMAND_HANDLER(lattice_refresh_command_handler)
582 {
583  if (CMD_ARGC != 1)
585 
587  if (!device) {
588  command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
589  return ERROR_FAIL;
590  }
591 
592  struct lattice_pld_device *lattice_device = device->driver_priv;
593  if (!lattice_device)
594  return ERROR_FAIL;
595 
596  int retval = lattice_check_device_family(lattice_device);
597  if (retval != ERROR_OK)
598  return retval;
599 
600  if (lattice_device->family == LATTICE_ECP2 || lattice_device->family == LATTICE_ECP3)
601  return lattice_ecp2_3_refresh(lattice_device);
602  else if (lattice_device->family == LATTICE_ECP5)
603  return lattice_ecp5_refresh(lattice_device);
604  else if (lattice_device->family == LATTICE_CERTUS)
605  return lattice_certus_refresh(lattice_device);
606 
607  return ERROR_FAIL;
608 }
609 
610 static const struct command_registration lattice_exec_command_handlers[] = {
611  {
612  .name = "read_status",
613  .mode = COMMAND_EXEC,
614  .handler = lattice_read_status_command_handler,
615  .help = "reading status register from FPGA",
616  .usage = "pld_name",
617  }, {
618  .name = "read_user",
619  .mode = COMMAND_EXEC,
620  .handler = lattice_read_usercode_register_command_handler,
621  .help = "reading usercode register from FPGA",
622  .usage = "pld_name",
623  }, {
624  .name = "write_user",
625  .mode = COMMAND_EXEC,
626  .handler = lattice_write_usercode_register_command_handler,
627  .help = "writing usercode register to FPGA",
628  .usage = "pld_name value",
629  }, {
630  .name = "set_preload",
631  .mode = COMMAND_ANY,
632  .handler = lattice_set_preload_command_handler,
633  .help = "set length for preload (device specific)",
634  .usage = "pld_name value",
635  }, {
636  .name = "refresh",
637  .mode = COMMAND_EXEC,
638  .handler = lattice_refresh_command_handler,
639  .help = "refresh from configuration memory",
640  .usage = "pld_name",
641  },
643 };
644 
645 static const struct command_registration lattice_command_handler[] = {
646  {
647  .name = "lattice",
648  .mode = COMMAND_ANY,
649  .help = "lattice specific commands",
650  .usage = "",
652  },
654 };
655 
656 struct pld_driver lattice_pld = {
657  .name = "lattice",
658  .commands = lattice_command_handler,
659  .pld_create_command = &lattice_pld_create_command,
660  .load = &lattice_load_command,
661  .get_ipdbg_hub = lattice_get_ipdbg_hub,
662  .has_jtagspi_instruction = lattice_has_jtagspi_instruction,
663  .connect_spi_to_jtag = lattice_connect_spi_to_jtag,
664  .disconnect_spi_from_jtag = lattice_disconnect_spi_from_jtag,
665  .get_stuff_bits = lattice_get_stuff_bits,
666 };
static const struct device_t * device
Definition: at91rm9200.c:94
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
int lattice_certus_load(struct lattice_pld_device *lattice_device, struct lattice_bit_file *bit_file)
Definition: certus.c:168
int lattice_certus_refresh(struct lattice_pld_device *lattice_device)
Definition: certus.c:309
int lattice_certus_write_usercode(struct lattice_pld_device *lattice_device, uint32_t usercode)
Definition: certus.c:30
int lattice_certus_get_facing_read_bits(struct lattice_pld_device *pld_device_info, unsigned int *facing_read_bits)
Definition: certus.c:299
int lattice_certus_read_usercode(struct jtag_tap *tap, uint32_t *usercode, uint32_t out)
Definition: certus.c:25
int lattice_certus_read_status(struct jtag_tap *tap, uint64_t *status, uint64_t out)
Definition: certus.c:20
int lattice_certus_connect_spi_to_jtag(struct lattice_pld_device *pld_device_info)
Definition: certus.c:236
int lattice_certus_disconnect_spi_from_jtag(struct lattice_pld_device *pld_device_info)
Definition: certus.c:282
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:389
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:146
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:161
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:405
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:156
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:445
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
int lattice_ecp2_3_read_status(struct jtag_tap *tap, uint32_t *status, uint32_t out, bool do_idle)
Definition: ecp2_3.c:32
int lattice_ecp2_3_disconnect_spi_from_jtag(struct lattice_pld_device *pld_device_info)
Definition: ecp2_3.c:282
int lattice_ecp2_3_read_usercode(struct jtag_tap *tap, uint32_t *usercode, uint32_t out)
Definition: ecp2_3.c:37
int lattice_ecp2_3_get_facing_read_bits(struct lattice_pld_device *pld_device_info, unsigned int *facing_read_bits)
Definition: ecp2_3.c:298
int lattice_ecp3_load(struct lattice_pld_device *lattice_device, struct lattice_bit_file *bit_file)
Definition: ecp2_3.c:212
int lattice_ecp2_3_write_usercode(struct lattice_pld_device *lattice_device, uint32_t usercode)
Definition: ecp2_3.c:42
int lattice_ecp2_3_refresh(struct lattice_pld_device *lattice_device)
Definition: ecp2_3.c:308
int lattice_ecp2_3_connect_spi_to_jtag(struct lattice_pld_device *pld_device_info)
Definition: ecp2_3.c:254
int lattice_ecp2_load(struct lattice_pld_device *lattice_device, struct lattice_bit_file *bit_file)
Definition: ecp2_3.c:172
int lattice_ecp5_refresh(struct lattice_pld_device *lattice_device)
Definition: ecp5.c:280
int lattice_ecp5_connect_spi_to_jtag(struct lattice_pld_device *pld_device_info)
Definition: ecp5.c:209
int lattice_ecp5_load(struct lattice_pld_device *lattice_device, struct lattice_bit_file *bit_file)
Definition: ecp5.c:162
int lattice_ecp5_disconnect_spi_from_jtag(struct lattice_pld_device *pld_device_info)
Definition: ecp5.c:253
int lattice_ecp5_write_usercode(struct lattice_pld_device *lattice_device, uint32_t usercode)
Definition: ecp5.c:35
int lattice_ecp5_read_usercode(struct jtag_tap *tap, uint32_t *usercode, uint32_t out)
Definition: ecp5.c:30
int lattice_ecp5_read_status(struct jtag_tap *tap, uint32_t *status, uint32_t out, bool do_idle)
Definition: ecp5.c:25
int lattice_ecp5_get_facing_read_bits(struct lattice_pld_device *pld_device_info, unsigned int *facing_read_bits)
Definition: ecp5.c:270
struct jtag_tap * jtag_tap_by_string(const char *s)
Definition: jtag/core.c:238
void jtag_add_runtest(unsigned int num_cycles, enum tap_state state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
Definition: jtag/core.c:581
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1033
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, enum tap_state state)
Generate a DR SCAN using the fields passed to the function.
Definition: jtag/core.c:438
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:866
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, enum tap_state state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
Definition: jtag/core.c:361
The JTAG interface can be implemented with a software or hardware fifo.
tap_state
Defines JTAG Test Access Port states.
Definition: jtag.h:37
@ TAP_IDLE
Definition: jtag.h:53
static const struct lattice_devices_elem lattice_devices[]
Definition: lattice.c:31
int lattice_verify_status_register_u32(struct lattice_pld_device *lattice_device, uint32_t out, uint32_t expected, uint32_t mask, bool do_idle)
Definition: lattice.c:241
#define USER1
Definition: lattice.c:21
static const struct command_registration lattice_command_handler[]
Definition: lattice.c:645
static int lattice_has_jtagspi_instruction(struct pld_device *device, bool *has_instruction)
Definition: lattice.c:409
int lattice_preload(struct lattice_pld_device *lattice_device)
Definition: lattice.c:147
struct pld_driver lattice_pld
Definition: lattice.c:656
static int lattice_get_stuff_bits(struct pld_device *pld_device, unsigned int *facing_read_bits, unsigned int *trailing_write_bits)
Definition: lattice.c:387
#define USER2
Definition: lattice.c:22
static int lattice_write_usercode(struct lattice_pld_device *lattice_device, uint32_t usercode)
Definition: lattice.c:204
static int lattice_disconnect_spi_from_jtag(struct pld_device *pld_device)
Definition: lattice.c:366
int lattice_read_u64_register(struct jtag_tap *tap, uint8_t cmd, uint64_t *in_val, uint64_t out_val)
Definition: lattice.c:126
static int lattice_read_status_u64(struct lattice_pld_device *lattice_device, uint64_t *status, uint64_t out)
Definition: lattice.c:229
static int lattice_read_usercode(struct lattice_pld_device *lattice_device, uint32_t *usercode, uint32_t out)
Definition: lattice.c:171
COMMAND_HANDLER(lattice_read_usercode_register_command_handler)
Definition: lattice.c:467
int lattice_read_u32_register(struct jtag_tap *tap, uint8_t cmd, uint32_t *in_val, uint32_t out_val, bool do_idle)
Definition: lattice.c:100
int lattice_verify_usercode(struct lattice_pld_device *lattice_device, uint32_t out, uint32_t expected, uint32_t mask)
Definition: lattice.c:187
static int lattice_check_device_family(struct lattice_pld_device *lattice_device)
Definition: lattice.c:79
static const struct command_registration lattice_exec_command_handlers[]
Definition: lattice.c:610
int lattice_set_instr(struct jtag_tap *tap, uint8_t new_instr, enum tap_state endstate)
Definition: lattice.c:62
#define PRELOAD
Definition: lattice.c:20
static int lattice_connect_spi_to_jtag(struct pld_device *pld_device)
Definition: lattice.c:345
static int lattice_read_status_u32(struct lattice_pld_device *lattice_device, uint32_t *status, uint32_t out, bool do_idle)
Definition: lattice.c:216
static int lattice_get_ipdbg_hub(int user_num, struct pld_device *pld_device, struct pld_ipdbg_hub *hub)
Definition: lattice.c:322
int lattice_verify_status_register_u64(struct lattice_pld_device *lattice_device, uint64_t out, uint64_t expected, uint64_t mask)
Definition: lattice.c:257
static int lattice_load_command(struct pld_device *pld_device, const char *filename)
Definition: lattice.c:273
PLD_CREATE_COMMAND_HANDLER(lattice_pld_create_command)
Definition: lattice.c:415
int lattice_read_file(struct lattice_bit_file *bit_file, const char *filename, enum lattice_family_e family)
Definition: lattice_bit.c:88
lattice_family_e
Definition: lattice_bit.h:23
@ LATTICE_UNKNOWN
Definition: lattice_bit.h:28
@ LATTICE_ECP5
Definition: lattice_bit.h:26
@ LATTICE_ECP3
Definition: lattice_bit.h:25
@ LATTICE_CERTUS
Definition: lattice_bit.h:27
@ LATTICE_ECP2
Definition: lattice_bit.h:24
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define ERROR_OK
Definition: log.h:182
uint8_t mask
Definition: parport.c:70
struct pld_device * get_pld_device_by_name_or_numstr(const char *str)
Definition: pld.c:56
const char * name
Definition: command.h:239
Definition: jtag.h:101
unsigned int ir_length
size of instruction register
Definition: jtag.h:110
uint8_t * expected
Capture-IR expected value.
Definition: jtag.h:112
bool has_idcode
not all devices have idcode, we'll discover this during chain examination
Definition: jtag.h:118
uint32_t idcode
device identification code
Definition: jtag.h:115
uint32_t idcode
Definition: lattice_bit.h:18
struct raw_bit_file raw_bit
Definition: lattice_bit.h:16
size_t preload_length
Definition: lattice.c:27
enum lattice_family_e family
Definition: lattice.c:28
struct jtag_tap * tap
Definition: lattice.h:18
enum lattice_family_e family
Definition: lattice.h:20
size_t preload_length
Definition: lattice.h:19
Definition: pld.h:48
void * driver_priv
Definition: pld.h:50
Definition: pld.h:31
const char * name
Definition: pld.h:32
unsigned int user_ir_code
Definition: pld.h:20
struct jtag_tap * tap
Definition: pld.h:19
uint8_t * data
Definition: raw_bit.h:16
This structure defines a single scan field in the scan.
Definition: jtag.h:87
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:93
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:91
unsigned int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
static uint64_t le_to_h_u64(const uint8_t *buf)
Definition: types.h:100
static void h_u32_to_le(uint8_t *buf, uint32_t val)
Definition: types.h:178
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
static void h_u64_to_le(uint8_t *buf, uint64_t val)
Definition: types.h:154
#define NULL
Definition: usb.h:16
uint8_t status[4]
Definition: vdebug.c:17
uint8_t cmd
Definition: vdebug.c:1