You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
4.0 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #define OPENOCD_VERSION "Open On-Chip Debugger (2006-11-22 14:00 CEST)"
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif
  24. #include "log.h"
  25. #include "types.h"
  26. #include "jtag.h"
  27. #include "configuration.h"
  28. #include "interpreter.h"
  29. #include "xsvf.h"
  30. #include "target.h"
  31. #include "flash.h"
  32. #include "pld.h"
  33. #include "command.h"
  34. #include "server.h"
  35. #include "telnet_server.h"
  36. #include "gdb_server.h"
  37. #include <sys/time.h>
  38. #include <sys/types.h>
  39. #include <strings.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <unistd.h>
  44. #include <errno.h>
  45. /* Give TELNET a way to find out what version this is */
  46. int handle_version_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  47. {
  48. command_print(cmd_ctx, OPENOCD_VERSION);
  49. return ERROR_OK;
  50. }
  51. int main(int argc, char *argv[])
  52. {
  53. /* initialize commandline interface */
  54. command_context_t *cmd_ctx, *cfg_cmd_ctx;
  55. cmd_ctx = command_init();
  56. register_command(cmd_ctx, NULL, "version", handle_version_command,
  57. COMMAND_EXEC, "show OpenOCD version");
  58. /* register subsystem commands */
  59. server_register_commands(cmd_ctx);
  60. telnet_register_commands(cmd_ctx);
  61. gdb_register_commands(cmd_ctx);
  62. log_register_commands(cmd_ctx);
  63. jtag_register_commands(cmd_ctx);
  64. interpreter_register_commands(cmd_ctx);
  65. xsvf_register_commands(cmd_ctx);
  66. target_register_commands(cmd_ctx);
  67. flash_register_commands(cmd_ctx);
  68. pld_register_commands(cmd_ctx);
  69. if (log_init(cmd_ctx) != ERROR_OK)
  70. return EXIT_FAILURE;
  71. DEBUG("log init complete");
  72. INFO( OPENOCD_VERSION );
  73. cfg_cmd_ctx = copy_command_context(cmd_ctx);
  74. cfg_cmd_ctx->mode = COMMAND_CONFIG;
  75. command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL);
  76. if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
  77. return EXIT_FAILURE;
  78. if (parse_config_file(cfg_cmd_ctx) != ERROR_OK)
  79. return EXIT_FAILURE;
  80. command_done(cfg_cmd_ctx);
  81. command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
  82. if (jtag_init(cmd_ctx) != ERROR_OK)
  83. return EXIT_FAILURE;
  84. DEBUG("jtag init complete");
  85. if (target_init(cmd_ctx) != ERROR_OK)
  86. return EXIT_FAILURE;
  87. DEBUG("target init complete");
  88. if (flash_init(cmd_ctx) != ERROR_OK)
  89. return EXIT_FAILURE;
  90. DEBUG("flash init complete");
  91. if (pld_init(cmd_ctx) != ERROR_OK)
  92. return EXIT_FAILURE;
  93. DEBUG("pld init complete");
  94. /* initialize tcp server */
  95. server_init();
  96. /* initialize telnet subsystem */
  97. telnet_init("Open On-Chip Debugger");
  98. gdb_init();
  99. /* handle network connections */
  100. server_loop(cmd_ctx);
  101. /* shut server down */
  102. server_quit();
  103. /* free commandline interface */
  104. command_done(cmd_ctx);
  105. return EXIT_SUCCESS;
  106. }