cmd_fpga.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * (C) Copyright 2000, 2001
  3. * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. /*
  25. * FPGA support
  26. */
  27. #include <common.h>
  28. #include <command.h>
  29. #include <cmd_bsp.h>
  30. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  31. #include <net.h>
  32. #endif
  33. #include <fpga.h>
  34. #if 0
  35. #define FPGA_DEBUG
  36. #endif
  37. #ifdef FPGA_DEBUG
  38. #define PRINTF(fmt,args...) printf (fmt ,##args)
  39. #else
  40. #define PRINTF(fmt,args...)
  41. #endif
  42. #if defined (CONFIG_FPGA) && ( CONFIG_COMMANDS & CFG_CMD_FPGA )
  43. /* Local functions */
  44. static void fpga_usage ( cmd_tbl_t *cmdtp );
  45. static int fpga_get_op( char *opstr );
  46. /* Local defines */
  47. #define FPGA_NONE -1
  48. #define FPGA_INFO 0
  49. #define FPGA_LOAD 1
  50. #define FPGA_DUMP 3
  51. /* ------------------------------------------------------------------------- */
  52. /* command form:
  53. * fpga <op> <device number> <data addr> <datasize>
  54. * where op is 'load', 'dump', or 'info'
  55. * If there is no device number field, the fpga environment variable is used.
  56. * If there is no data addr field, the fpgadata environment variable is used.
  57. * The info command requires no data address field.
  58. */
  59. int
  60. do_fpga (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  61. {
  62. int op, dev = FPGA_INVALID_DEVICE;
  63. size_t data_size = 0;
  64. void *fpga_data = NULL;
  65. char *devstr = getenv("fpga");
  66. char *datastr = getenv("fpgadata");
  67. if ( devstr ) dev = (int)simple_strtoul( devstr, NULL, 16 );
  68. if ( datastr ) fpga_data = (void *)simple_strtoul( datastr, NULL, 16 );
  69. switch ( argc )
  70. {
  71. case 5: /* fpga <op> <dev> <data> <datasize> */
  72. data_size = simple_strtoul( argv[4], NULL, 16 );
  73. case 4: /* fpga <op> <dev> <data> */
  74. fpga_data = (void *)simple_strtoul( argv[3], NULL, 16 );
  75. PRINTF(__FUNCTION__": fpga_data = 0x%x\n", (uint)fpga_data );
  76. case 3: /* fpga <op> <dev | data addr> */
  77. dev = (int)simple_strtoul( argv[2], NULL, 16 );
  78. PRINTF(__FUNCTION__": device = %d\n", dev );
  79. /* FIXME - this is a really weak test */
  80. if (( argc == 3 ) && ( dev > fpga_count() )) { /* must be buffer ptr */
  81. PRINTF(__FUNCTION__": Assuming buffer pointer in arg 3\n");
  82. fpga_data = (void *)dev;
  83. PRINTF(__FUNCTION__": fpga_data = 0x%x\n", (uint)fpga_data );
  84. dev = FPGA_INVALID_DEVICE; /* reset device num */
  85. }
  86. case 2: /* fpga <op> */
  87. op = (int)fpga_get_op( argv[1] );
  88. break;
  89. default:
  90. PRINTF(__FUNCTION__": Too many or too few args (%d)\n", argc );
  91. op = FPGA_NONE; /* force usage display */
  92. break;
  93. }
  94. switch ( op ) {
  95. case FPGA_NONE:
  96. fpga_usage( cmdtp );
  97. break;
  98. case FPGA_INFO:
  99. fpga_info( dev );
  100. break;
  101. case FPGA_LOAD:
  102. fpga_load( dev, fpga_data, data_size );
  103. break;
  104. case FPGA_DUMP:
  105. fpga_dump( dev, fpga_data, data_size );
  106. break;
  107. default:
  108. printf( "Unknown operation.\n" );
  109. fpga_usage( cmdtp );
  110. break;
  111. }
  112. return 0;
  113. }
  114. static void fpga_usage ( cmd_tbl_t *cmdtp )
  115. {
  116. printf( "Usage:\n%s\n", cmdtp->usage );
  117. }
  118. /*
  119. * Map op to supported operations. We don't use a table since we
  120. * would just have to relocate it from flash anyway.
  121. */
  122. static int fpga_get_op( char *opstr )
  123. {
  124. int op = FPGA_NONE;
  125. if (!strcmp ("info", opstr)) {
  126. op = FPGA_INFO;
  127. }
  128. else if (!strcmp ("load", opstr)) {
  129. op = FPGA_LOAD;
  130. }
  131. else if (!strcmp ("dump", opstr)) {
  132. op = FPGA_DUMP;
  133. }
  134. if ( op == FPGA_NONE ) {
  135. printf ("Unknown fpga operation \"%s\"\n", opstr);
  136. }
  137. return op;
  138. }
  139. cmd_tbl_t U_BOOT_CMD(FPGA) = MK_CMD_ENTRY(
  140. "fpga", 6, 1, do_fpga,
  141. "fpga - loadable FPGA image support\n",
  142. "fpga [operation type] [device number] [image address] [image size]\n"
  143. "fpga operations:\n"
  144. "\tinfo\tlist known device information.\n"
  145. "\tload\tLoad device from memory buffer.\n"
  146. "\tdump\tLoad device to memory buffer.\n"
  147. );
  148. #endif /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */