fpgad.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * (C) Copyright 2013
  3. * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
  4. *
  5. * based on cmd_mem.c
  6. * (C) Copyright 2000
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <console.h>
  14. #include <gdsys_fpga.h>
  15. static uint dp_last_fpga;
  16. static uint dp_last_addr;
  17. static uint dp_last_length = 0x40;
  18. /*
  19. * FPGA Memory Display
  20. *
  21. * Syntax:
  22. * fpgad {fpga} {addr} {len}
  23. */
  24. #define DISP_LINE_LEN 16
  25. int do_fpga_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  26. {
  27. unsigned int k;
  28. unsigned int fpga;
  29. ulong addr, length;
  30. int rc = 0;
  31. u16 linebuf[DISP_LINE_LEN/sizeof(u16)];
  32. ulong nbytes;
  33. /*
  34. * We use the last specified parameters, unless new ones are
  35. * entered.
  36. */
  37. fpga = dp_last_fpga;
  38. addr = dp_last_addr;
  39. length = dp_last_length;
  40. if (argc < 3)
  41. return CMD_RET_USAGE;
  42. if ((flag & CMD_FLAG_REPEAT) == 0) {
  43. /*
  44. * FPGA is specified since argc > 2
  45. */
  46. fpga = simple_strtoul(argv[1], NULL, 16);
  47. /*
  48. * Address is specified since argc > 2
  49. */
  50. addr = simple_strtoul(argv[2], NULL, 16);
  51. /*
  52. * If another parameter, it is the length to display.
  53. * Length is the number of objects, not number of bytes.
  54. */
  55. if (argc > 3)
  56. length = simple_strtoul(argv[3], NULL, 16);
  57. }
  58. nbytes = length * sizeof(u16);
  59. do {
  60. ulong linebytes = (nbytes > DISP_LINE_LEN) ?
  61. DISP_LINE_LEN : nbytes;
  62. for (k = 0; k < linebytes / sizeof(u16); ++k)
  63. fpga_get_reg(fpga,
  64. (u16 *)fpga_ptr[fpga] + addr
  65. / sizeof(u16) + k,
  66. addr + k * sizeof(u16),
  67. &linebuf[k]);
  68. print_buffer(addr, (void *)linebuf, sizeof(u16),
  69. linebytes / sizeof(u16),
  70. DISP_LINE_LEN / sizeof(u16));
  71. nbytes -= linebytes;
  72. addr += linebytes;
  73. if (ctrlc()) {
  74. rc = 1;
  75. break;
  76. }
  77. } while (nbytes > 0);
  78. dp_last_fpga = fpga;
  79. dp_last_addr = addr;
  80. dp_last_length = length;
  81. return rc;
  82. }
  83. U_BOOT_CMD(
  84. fpgad, 4, 1, do_fpga_md,
  85. "fpga register display",
  86. "fpga address [# of objects]"
  87. );