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.
 
 
 
 
 
 

137 lines
4.1 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2011 by Mathias Kuester *
  3. * Mathias Kuester <kesmtp@freenet.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. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. /* project specific includes */
  24. #include <jtag/interface.h>
  25. #include <transport/transport.h>
  26. #include <helper/time_support.h>
  27. static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi,
  28. struct jtag_tap *pTap)
  29. {
  30. jim_wide w;
  31. int e = Jim_GetOpt_Wide(goi, &w);
  32. if (e != JIM_OK) {
  33. Jim_SetResultFormatted(goi->interp, "option: %s bad parameter",
  34. n->name);
  35. return e;
  36. }
  37. unsigned expected_len = sizeof(uint32_t) * pTap->expected_ids_cnt;
  38. uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
  39. if (new_expected_ids == NULL) {
  40. Jim_SetResultFormatted(goi->interp, "no memory");
  41. return JIM_ERR;
  42. }
  43. memcpy(new_expected_ids, pTap->expected_ids, expected_len);
  44. new_expected_ids[pTap->expected_ids_cnt] = w;
  45. free(pTap->expected_ids);
  46. pTap->expected_ids = new_expected_ids;
  47. pTap->expected_ids_cnt++;
  48. return JIM_OK;
  49. }
  50. #define NTAP_OPT_EXPECTED_ID 0
  51. static int jim_stlink_newtap_cmd(Jim_GetOptInfo *goi)
  52. {
  53. struct jtag_tap *pTap;
  54. int x;
  55. int e;
  56. Jim_Nvp *n;
  57. char *cp;
  58. const Jim_Nvp opts[] = {
  59. {.name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID},
  60. {.name = NULL, .value = -1},
  61. };
  62. pTap = calloc(1, sizeof(struct jtag_tap));
  63. if (!pTap) {
  64. Jim_SetResultFormatted(goi->interp, "no memory");
  65. return JIM_ERR;
  66. }
  67. /*
  68. * we expect CHIP + TAP + OPTIONS
  69. * */
  70. if (goi->argc < 3) {
  71. Jim_SetResultFormatted(goi->interp,
  72. "Missing CHIP TAP OPTIONS ....");
  73. free(pTap);
  74. return JIM_ERR;
  75. }
  76. Jim_GetOpt_String(goi, &cp, NULL);
  77. pTap->chip = strdup(cp);
  78. Jim_GetOpt_String(goi, &cp, NULL);
  79. pTap->tapname = strdup(cp);
  80. /* name + dot + name + null */
  81. x = strlen(pTap->chip) + 1 + strlen(pTap->tapname) + 1;
  82. cp = malloc(x);
  83. sprintf(cp, "%s.%s", pTap->chip, pTap->tapname);
  84. pTap->dotted_name = cp;
  85. LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
  86. pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
  87. while (goi->argc) {
  88. e = Jim_GetOpt_Nvp(goi, opts, &n);
  89. if (e != JIM_OK) {
  90. Jim_GetOpt_NvpUnknown(goi, opts, 0);
  91. free((void *)pTap->dotted_name);
  92. free(pTap);
  93. return e;
  94. }
  95. LOG_DEBUG("Processing option: %s", n->name);
  96. switch (n->value) {
  97. case NTAP_OPT_EXPECTED_ID:
  98. e = jim_newtap_expected_id(n, goi, pTap);
  99. if (JIM_OK != e) {
  100. free((void *)pTap->dotted_name);
  101. free(pTap);
  102. return e;
  103. }
  104. break;
  105. } /* switch (n->value) */
  106. } /* while (goi->argc) */
  107. /* default is enabled-after-reset */
  108. pTap->enabled = !pTap->disabled_after_reset;
  109. jtag_tap_init(pTap);
  110. return JIM_OK;
  111. }
  112. int jim_stlink_newtap(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
  113. {
  114. Jim_GetOptInfo goi;
  115. Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
  116. return jim_stlink_newtap_cmd(&goi);
  117. }