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.
 
 
 
 
 
 

156 lines
4.5 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 " VERSION " (" PKGBLDDATE ") svn:" PKGBLDREV
  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 "nand.h"
  33. #include "pld.h"
  34. #include "command.h"
  35. #include "server.h"
  36. #include "telnet_server.h"
  37. #include "gdb_server.h"
  38. #include <sys/time.h>
  39. #include <sys/types.h>
  40. #include <strings.h>
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <unistd.h>
  45. #include <errno.h>
  46. /* Give TELNET a way to find out what version this is */
  47. int handle_version_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  48. {
  49. command_print(cmd_ctx, OPENOCD_VERSION);
  50. return ERROR_OK;
  51. }
  52. void exit_handler(void)
  53. {
  54. /* close JTAG interface */
  55. if (jtag && jtag->quit)
  56. jtag->quit();
  57. }
  58. int main(int argc, char *argv[])
  59. {
  60. /* initialize commandline interface */
  61. command_context_t *cmd_ctx, *cfg_cmd_ctx;
  62. cmd_ctx = command_init();
  63. register_command(cmd_ctx, NULL, "version", handle_version_command,
  64. COMMAND_EXEC, "show OpenOCD version");
  65. /* register subsystem commands */
  66. server_register_commands(cmd_ctx);
  67. telnet_register_commands(cmd_ctx);
  68. gdb_register_commands(cmd_ctx);
  69. log_register_commands(cmd_ctx);
  70. jtag_register_commands(cmd_ctx);
  71. interpreter_register_commands(cmd_ctx);
  72. xsvf_register_commands(cmd_ctx);
  73. target_register_commands(cmd_ctx);
  74. flash_register_commands(cmd_ctx);
  75. nand_register_commands(cmd_ctx);
  76. pld_register_commands(cmd_ctx);
  77. if (log_init(cmd_ctx) != ERROR_OK)
  78. return EXIT_FAILURE;
  79. LOG_DEBUG("log init complete");
  80. LOG_OUTPUT( OPENOCD_VERSION "\n" );
  81. LOG_OUTPUT( "$URL$\n");
  82. cfg_cmd_ctx = copy_command_context(cmd_ctx);
  83. cfg_cmd_ctx->mode = COMMAND_CONFIG;
  84. command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL);
  85. if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
  86. return EXIT_FAILURE;
  87. if (parse_config_file(cfg_cmd_ctx) != ERROR_OK)
  88. return EXIT_FAILURE;
  89. command_done(cfg_cmd_ctx);
  90. command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
  91. atexit(exit_handler);
  92. if (jtag_init(cmd_ctx) != ERROR_OK)
  93. return EXIT_FAILURE;
  94. LOG_DEBUG("jtag init complete");
  95. if (target_init(cmd_ctx) != ERROR_OK)
  96. return EXIT_FAILURE;
  97. LOG_DEBUG("target init complete");
  98. if (flash_init_drivers(cmd_ctx) != ERROR_OK)
  99. return EXIT_FAILURE;
  100. LOG_DEBUG("flash init complete");
  101. if (nand_init(cmd_ctx) != ERROR_OK)
  102. return EXIT_FAILURE;
  103. LOG_DEBUG("NAND init complete");
  104. if (pld_init(cmd_ctx) != ERROR_OK)
  105. return EXIT_FAILURE;
  106. LOG_DEBUG("pld init complete");
  107. /* initialize tcp server */
  108. server_init();
  109. /* initialize telnet subsystem */
  110. telnet_init("Open On-Chip Debugger");
  111. gdb_init();
  112. /* call any target resets */
  113. if (target_init_reset(cmd_ctx) != ERROR_OK)
  114. return EXIT_FAILURE;
  115. LOG_DEBUG("target init reset complete");
  116. /* handle network connections */
  117. server_loop(cmd_ctx);
  118. /* shut server down */
  119. server_quit();
  120. /* free commandline interface */
  121. command_done(cmd_ctx);
  122. return EXIT_SUCCESS;
  123. }