Beispiel #1
0
static int
cmd_debug_run (urj_chain_t *chain, char *params[])
{
    switch (urj_cmd_params (params)) {

    /* display current log level */
    case 1:
        urj_log (URJ_LOG_LEVEL_NORMAL, _("Current log level is '%s'\n"),
                 urj_log_level_string (urj_log_state.level));
        return URJ_STATUS_OK;

    /* set log level */
    case 2:
    {
        urj_log_level_t new_level = urj_string_log_level (params[1]);
        if (new_level == -1)
        {
            urj_error_set (URJ_ERROR_SYNTAX, "unknown log level '%s'", params[1]);
            return URJ_STATUS_FAIL;
        }
        urj_log_state.level = new_level;

        return URJ_STATUS_OK;
    }

    /* fail! */
    default:
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }
}
Beispiel #2
0
static int
cmd_eraseflash_run (urj_chain_t *chain, char *params[])
{
    long unsigned adr = 0;
    long unsigned number = 0;

    if (urj_cmd_params (params) != 3)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be %d, not %d",
                       params[0], 3, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;
    if (!urj_bus)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus driver missing"));
        return URJ_STATUS_FAIL;
    }
    if (urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;
    if (urj_cmd_get_number (params[2], &number) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    return urj_flasherase (urj_bus, adr, number);
}
Beispiel #3
0
static int
cmd_shift_run (urj_chain_t *chain, char *params[])
{
    if (urj_cmd_params (params) != 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    if (strcasecmp (params[1], "ir") == 0)
    {
        /* @@@@ RFHH check result */
        urj_tap_chain_shift_instructions (chain);
        return URJ_STATUS_OK;
    }
    if (strcasecmp (params[1], "dr") == 0)
    {
        /* @@@@ RFHH check result */
        urj_tap_chain_shift_data_registers (chain, 1);
        return URJ_STATUS_OK;
    }

    urj_error_set (URJ_ERROR_SYNTAX,
                   "%s parameter 2 must be 'ir' or 'dr', not '%s'",
                   params[0], params[1]);
    return URJ_STATUS_FAIL;
}
Beispiel #4
0
static int
cmd_endian_run (urj_chain_t *chain, char *params[])
{
    urj_endian_t new_endian;

    if (urj_cmd_params (params) > 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be <= %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (!params[1])
    {
        urj_log (URJ_LOG_LEVEL_NORMAL, _("Endianess for external files: %s\n"),
                 urj_endian_to_string (urj_get_file_endian ()));
        return URJ_STATUS_OK;
    }

    new_endian = urj_endian_from_string (params[1]);
    if (new_endian != URJ_ENDIAN_UNKNOWN)
    {
        urj_set_file_endian (new_endian);
        return URJ_STATUS_OK;
    }

    urj_error_set (URJ_ERROR_SYNTAX,
                   _("endianness must be 'little' or 'big', not '%s'"),
                   params[1]);
    return URJ_STATUS_FAIL;
}
Beispiel #5
0
static int
cmd_initbus_run (urj_chain_t *chain, char *params[])
{
    if (urj_cmd_params (params) < 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be >= %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    return urj_bus_init (chain, params[1], &params[2]);
}
Beispiel #6
0
static int
cmd_initbus_run (urj_chain_t *chain, char *params[])
{
    int drv, i;
    const urj_param_t **bus_params;

    if (urj_cmd_params (params) < 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be >= %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    if (urj_tap_chain_active_part (chain) == NULL)
        return URJ_STATUS_FAIL;

    for (drv = 0; urj_bus_drivers[drv] != NULL; drv++)
        if (strcasecmp (urj_bus_drivers[drv]->name, params[1]) == 0)
            break;

    if (urj_bus_drivers[drv] == NULL)
    {
        urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown bus: %s"), params[1]);
        return URJ_STATUS_FAIL;
    }

    urj_param_init (&bus_params);
    for (i = 2; params[i] != NULL; i++)
        if (urj_param_push (&urj_bus_param_list, &bus_params,
                            params[i]) != URJ_STATUS_OK)
        {
            urj_param_clear (&bus_params);
            return URJ_STATUS_FAIL;
        }

    if (urj_bus_init_bus(chain, urj_bus_drivers[drv], bus_params) == NULL)
    {
        urj_param_clear (&bus_params);
        return URJ_STATUS_FAIL;
    }

    urj_param_clear (&bus_params);

    return URJ_STATUS_OK;
}
Beispiel #7
0
static int
cmd_tapmux_run (urj_chain_t *chain, char *params[])
{
  int i,j;
  if ((i = urj_cmd_params (params)) < 2)
    {
      urj_error_set (URJ_ERROR_SYNTAX,
		     "%s: #parameters should be >= %d, not %d",
		     params[0], 2, urj_cmd_params (params));
      return URJ_STATUS_FAIL;
    }

  if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
    return URJ_STATUS_FAIL;

  tmc_init();
  hudi_init();

  for(j = 1; j < i; j++) {
    if (strncasecmp(params[j], "bypass", 6) == 0) {
      if ((j+1) == i)
	urj_error_set (URJ_ERROR_SYNTAX, "missing channel number for bypass");
      tmc_current_channel = atoi(params[++j]);
      tmc_reset_and_bypass(chain, tmc_current_channel);
      return URJ_STATUS_OK;
    } else if (strncasecmp(params[j], "printids", 8) == 0) {
      tmc_print_ids(chain, tmc_current_channel);
      return URJ_STATUS_OK;
    } else if (strncasecmp(params[j], "stdi", 4) == 0) {
      if ((j+1) == i)
	urj_error_set (URJ_ERROR_SYNTAX, "missing subcommand for stdi");
      j++;
      return stdi_subcommand(chain,j,i,params);
    } else if (strncasecmp(params[j], "dsu", 3) == 0) {
      if ((j+1) == i)
	urj_error_set (URJ_ERROR_SYNTAX, "missing subcommand for dsu");
      j++;
      return dsu_subcommand(chain,j,i,params);
    } else {
      urj_error_set (URJ_ERROR_SYNTAX, "illegal subcommand '%s'", params[j]);
      return URJ_STATUS_FAIL;
    }
  }
    
  //  hudi_free();
  //  tmc_free();

  return URJ_STATUS_FAIL;
}
Beispiel #8
0
static int
cmd_flashmem_run (urj_chain_t *chain, char *params[])
{
    int msbin;
    int noverify = 0;
    long unsigned adr = 0;
    FILE *f;
    int paramc = urj_cmd_params (params);
    int r;

    if (paramc < 3)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be >= %d, not %d",
                       params[0], 3, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (!urj_bus)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus driver missing"));
        return URJ_STATUS_FAIL;
    }

    msbin = strcasecmp ("msbin", params[1]) == 0;
    if (!msbin && urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    if (paramc > 3)
        noverify = strcasecmp ("noverify", params[3]) == 0;
    else
        noverify = 0;

    f = fopen (params[2], "rb");
    if (!f)
    {
        urj_error_IO_set (_("Unable to open file `%s'"), params[2]);
        return URJ_STATUS_FAIL;
    }

    if (msbin)
        r = urj_flashmsbin (urj_bus, f, noverify);
    else
        r = urj_flashmem (urj_bus, f, adr, noverify);

    fclose (f);

    return r;
}
Beispiel #9
0
static int
cmd_discovery_run (urj_chain_t *chain, char *params[])
{
    if (urj_cmd_params (params) != 1)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be %d, not %d",
                       params[0], 1, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    return urj_tap_discovery (chain);
}
Beispiel #10
0
static int
cmd_get_run (urj_chain_t *chain, char *params[])
{
    int data;
    urj_part_signal_t *s;
    urj_part_t *part;

    if (urj_cmd_params (params) != 3)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be %d, not %d",
                       params[0], 3, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (strcasecmp (params[1], "signal") != 0)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "params[1] must be 'signal', not '%s'", params[1]);
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    part = urj_tap_chain_active_part (chain);
    if (part == NULL)
        return URJ_STATUS_FAIL;

    s = urj_part_find_signal (part, params[2]);
    if (!s)
    {
        urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"),
                       params[2]);
        return URJ_STATUS_FAIL;
    }
    data = urj_part_get_signal (part, s);
    if (data == -1)
        return URJ_STATUS_FAIL;

    urj_log (URJ_LOG_LEVEL_NORMAL, _("%s = %d\n"), params[2], data);

    return URJ_STATUS_OK;
}
Beispiel #11
0
static int
cmd_salias_run (urj_chain_t *chain, char *params[])
{
    urj_part_t *part;
    urj_part_signal_t *s;
    urj_part_salias_t *sa;

    if (urj_cmd_params (params) != 3)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be %d, not %d",
                       params[0], 3, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    part = urj_tap_chain_active_part (chain);
    if (part == NULL)
        return URJ_STATUS_FAIL;

    if (urj_part_find_signal (part, params[1]) != NULL)
    {
        return URJ_STATUS_FAIL;
    }

    s = urj_part_find_signal (part, params[2]);
    if (s == NULL)
    {
        urj_error_set (URJ_ERROR_NOTFOUND, _("Signal '%s' not found"),
                       params[2]);
        return URJ_STATUS_FAIL;
    }

    sa = urj_part_salias_alloc (params[1], s);
    if (!sa)
        return URJ_STATUS_FAIL;

    sa->next = part->saliases;
    part->saliases = sa;

    return URJ_STATUS_OK;
}
Beispiel #12
0
static int
cmd_stapl_run (urj_chain_t *chain, char *params[])
{
    int num_params;
    int result = URJ_STATUS_OK;

    num_params = urj_cmd_params (params);
    if (num_params <= 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be = %d, not %d",
                       params[0], 3, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    result = urj_stapl_run (chain, params[1], params[2]);

    return result;
}
Beispiel #13
0
static int
cmd_help_run (urj_chain_t *chain, char *params[])
{
    int i;

    if (urj_cmd_params (params) > 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be <= %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    /* short description generation */
    if (urj_cmd_params (params) == 1)
    {
        urj_log (URJ_LOG_LEVEL_NORMAL, _("Command list:\n\n"));
        urj_cmd_show_list (urj_cmds);
        urj_log (URJ_LOG_LEVEL_NORMAL,
                 _("\nType \"help COMMAND\" for details about a particular command.\n"));
        return URJ_STATUS_OK;
    }

    /* search and print help for a particular command */
    for (i = 0; urj_cmds[i]; i++)
        if (strcasecmp (urj_cmds[i]->name, params[1]) == 0)
        {
            if (urj_cmds[i]->help)
                urj_cmds[i]->help ();
            return URJ_STATUS_OK;
        }

    urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: unknown command\n"), params[1]);

    return URJ_STATUS_OK;
}
Beispiel #14
0
static int
cmd_dr_run (urj_chain_t *chain, char *params[])
{
    int dir = 1;
    urj_part_t *part;
    urj_tap_register_t *r;
    urj_data_register_t *dr;
    urj_part_instruction_t *active_ir;

    if (urj_cmd_params (params) < 1 || urj_cmd_params (params) > 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be >= 1 and <= 2, not %d",
                       params[0], urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    part = urj_tap_chain_active_part (chain);
    if (part == NULL)
        return URJ_STATUS_FAIL;

    active_ir = part->active_instruction;
    if (active_ir == NULL)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE,
                       _("%s: part without active instruction"), "dr");
        return URJ_STATUS_FAIL;
    }
    dr = active_ir->data_register;
    if (dr == NULL)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE,
                       _("%s: instruction without active data register"), "dr");
        return URJ_STATUS_FAIL;
    }

    if (params[1])
    {
        if (strcasecmp (params[1], "in") == 0)
            dir = 0;
        else if (strcasecmp (params[1], "out") == 0)
            dir = 1;
        else
        {
            int ret = urj_tap_register_set_string (dr->in, params[1]);
            if (ret != URJ_STATUS_OK)
                return ret;
            dir = 0;
        }
    }

    if (dir)
        r = dr->out;
    else
        r = dr->in;
    urj_log (URJ_LOG_LEVEL_NORMAL, "%s (0x%0*" PRIX64 ")\n",
             urj_tap_register_get_string (r), r->len / 4,
             urj_tap_register_get_value (r));

    return URJ_STATUS_OK;
}
Beispiel #15
0
static int
cmd_set_run (urj_chain_t *chain, char *params[])
{
    int dir;
    long unsigned data = 0;
    urj_part_signal_t *s;
    urj_part_t *part;

    if (urj_cmd_params (params) < 4 || urj_cmd_params (params) > 5)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be 4 or 5, not %d",
                       params[0], urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (strcasecmp (params[1], "signal") != 0)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: second parameter must be '%s'",
                       params[0], params[1]);
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    part = urj_tap_chain_active_part (chain);
    if (part == NULL)
        return URJ_STATUS_FAIL;

    /* direction */
    if (strcasecmp (params[3], "in") != 0
        && strcasecmp (params[3], "out") != 0)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: DIR parameter must be 'in' or 'out', not '%s'",
                       params[0], params[3]);
        return URJ_STATUS_FAIL;
    }

    dir = (strcasecmp (params[3], "in") == 0) ? 0 : 1;

    if (dir)
    {
        if (urj_cmd_get_number (params[4], &data) != URJ_STATUS_OK)
            return URJ_STATUS_FAIL;
        if (data > 1)
        {
            urj_error_set (URJ_ERROR_SYNTAX,
                           "%s: DATA parameter must be '0' or '1', not '%s'",
                           params[0], params[4]);
            return URJ_STATUS_FAIL;
        }
    }

    s = urj_part_find_signal (part, params[2]);
    if (!s)
    {
        urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"),
                       params[2]);
        return URJ_STATUS_FAIL;
    }

    return urj_part_set_signal (part, s, dir, data);
}
Beispiel #16
0
static int
cmd_print_run (urj_chain_t *chain, char *params[])
{
#define FORMAT_LENGTH   128
    char format[FORMAT_LENGTH];
#if HAVE_SWPRINTF
    wchar_t wformat[FORMAT_LENGTH];
#endif /* HAVE_SWPRINTF */
    wchar_t wheader[FORMAT_LENGTH];
    char header[FORMAT_LENGTH];
    int i;
    int noheader = 0;

    if (urj_cmd_params (params) > 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "%s: #parameters should be <= %d, not %d",
                       params[0], 2, urj_cmd_params (params));
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    if (!chain->parts)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE, "Run \"detect\" first");
        return URJ_STATUS_FAIL;
    }

    if (urj_cmd_params (params) == 2)
    {
        if (strcasecmp (params[1], "bus") == 0)
            noheader = 1;

        if (strcasecmp (params[1], "signals") == 0)
        {

            urj_log (URJ_LOG_LEVEL_NORMAL, "Signals:\n");
            urj_part_t *part;
            urj_part_signal_t *s;
            part = chain->parts->parts[chain->active_part];
            for (s = part->signals; s != NULL; s = s->next)
            {
                urj_part_salias_t *sa;
                if (s->pin)
                    urj_log (URJ_LOG_LEVEL_NORMAL, "%s %s", s->name, s->pin);
                else
                    urj_log (URJ_LOG_LEVEL_NORMAL, "%s", s->name);
                if (s->input)
                    urj_log (URJ_LOG_LEVEL_NORMAL, "\tinput=%s",
                             s->input->name);
                if (s->output)
                    urj_log (URJ_LOG_LEVEL_NORMAL, "\toutput=%s",
                             s->output->name);

                for (sa = part->saliases; sa != NULL; sa = sa->next)
                {
                    if (s == sa->signal)
                        urj_log (URJ_LOG_LEVEL_NORMAL, "\tsalias=%s", sa->name);
                }
                urj_log (URJ_LOG_LEVEL_NORMAL, "\n");
            }
            return URJ_STATUS_OK;
        }

        if (strcasecmp (params[1], "instructions") == 0)
        {
            urj_part_t *part;
            urj_part_instruction_t *inst;

            snprintf (format, sizeof format, _(" Active %%-%ds %%-%ds\n"),
                      URJ_INSTRUCTION_MAXLEN_INSTRUCTION,
                      URJ_DATA_REGISTER_MAXLEN);
#if HAVE_SWPRINTF
            if (mbstowcs (wformat, format, sizeof format) == -1)
                // @@@@ RFHH throw urj_error?
                printf (_("(%d) String conversion failed!\n"), __LINE__);
            swprintf (wheader, sizeof format, wformat, _("Instruction"), _("Register"));
            if (wcstombs (header, wheader, sizeof format) == -1)
                // @@@@ RFHH throw urj_error?
                printf (_("(%d) String conversion failed!\n"), __LINE__);
#else /* HAVE_SWPRINTF */
            snprintf (header, sizeof format, format, _("Instruction"), _("Register"));
            if (mbstowcs (wheader, header, sizeof format) == -1)
                // @@@@ RFHH throw urj_error?
                printf (_("(%d) String conversion failed!\n"), __LINE__);
#endif /* HAVE_SWPRINTF */
            urj_log (URJ_LOG_LEVEL_NORMAL, "%s", header);

            for (i = 0; i < wcslen (wheader); i++)
                urj_log (URJ_LOG_LEVEL_NORMAL, "%c", '-');
            urj_log (URJ_LOG_LEVEL_NORMAL, "%c", '\n');

            snprintf (format, sizeof format, _("   %%c    %%-%ds %%-%ds\n"),
                      URJ_INSTRUCTION_MAXLEN_INSTRUCTION,
                      URJ_DATA_REGISTER_MAXLEN);

            part = chain->parts->parts[chain->active_part];
            for (inst = part->instructions; inst != NULL; inst = inst->next)
            {
                urj_log (URJ_LOG_LEVEL_NORMAL, format,
                         (inst == part->active_instruction) ? 'X' : ' ',
                         inst->name, inst->data_register->name);
            }
            return URJ_STATUS_OK;
        }
    }

    if (noheader == 0)
    {
        snprintf (format, sizeof format,
                  _(" No. %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds\n"),
                  URJ_PART_MANUFACTURER_MAXLEN, URJ_PART_PART_MAXLEN,
                  URJ_PART_STEPPING_MAXLEN,
                  URJ_INSTRUCTION_MAXLEN_INSTRUCTION,
                  URJ_DATA_REGISTER_MAXLEN);
#if HAVE_SWPRINTF
        if (mbstowcs (wformat, format, sizeof format) == -1)
            // @@@@ RFHH throw urj_error?
            printf (_("(%d) String conversion failed!\n"), __LINE__);
        swprintf (wheader, sizeof format, wformat, _("Manufacturer"), _("Part"),
                  _("Stepping"), _("Instruction"), _("Register"));
        if (wcstombs (header, wheader, sizeof format) == -1)
            // @@@@ RFHH throw urj_error?
            printf (_("(%d) String conversion failed!\n"), __LINE__);
#else /* HAVE_SWPRINTF */
        snprintf (header, sizeof format, format, _("Manufacturer"), _("Part"),
                  _("Stepping"), _("Instruction"), _("Register"));
        if (mbstowcs (wheader, header, sizeof format) == -1)
            // @@@@ RFHH throw urj_error?
            printf (_("(%d) String conversion failed!\n"), __LINE__);
#endif /* HAVE_SWPRINTF */
        urj_log (URJ_LOG_LEVEL_NORMAL, "%s", header);

        for (i = 0; i < wcslen (wheader); i++)
            urj_log (URJ_LOG_LEVEL_NORMAL, "%c", '-');
        urj_log (URJ_LOG_LEVEL_NORMAL, "%c", '\n');
    }

    if (urj_cmd_params (params) == 1)
    {
        int r = URJ_STATUS_OK;

        if (chain->parts->len > chain->active_part)
        {
            if (chain->parts->parts[chain->active_part]->alias)
                urj_log (URJ_LOG_LEVEL_NORMAL, _(" %3d %s "),
                         chain->active_part,
                         chain->parts->parts[chain->active_part]->alias);
            else
                urj_log (URJ_LOG_LEVEL_NORMAL, _(" %3d "), chain->active_part);

            urj_part_print (URJ_LOG_LEVEL_NORMAL,
                            chain->parts->parts[chain->active_part]);
        }
        if (urj_bus != NULL)
        {
            int i;
            uint64_t a;
            urj_bus_area_t area;

            for (i = 0; i < urj_buses.len; i++)
                if (urj_buses.buses[i] == urj_bus)
                    break;
            urj_log (URJ_LOG_LEVEL_NORMAL, _("\nActive bus:\n*%d: "), i);
            URJ_BUS_PRINTINFO (URJ_LOG_LEVEL_NORMAL, urj_bus);

            for (a = 0; a < UINT64_C (0x100000000);
                 a = area.start + area.length)
            {
                r = URJ_BUS_AREA (urj_bus, a, &area);
                if (r != URJ_STATUS_OK)
                {
                    urj_log (URJ_LOG_LEVEL_NORMAL,
                             _("Error in bus area discovery at 0x%08llX\n"),
                             (long long unsigned int) a);
                    break;
                }
                if (area.width != 0)
                {
                    if (area.description != NULL)
                        urj_log (URJ_LOG_LEVEL_NORMAL,
                                 _("\tstart: 0x%08lX, length: 0x%08llX, data width: %d bit, (%s)\n"),
                                 (long unsigned) area.start,
                                 (long long unsigned int) area.length,
                                 area.width, _(area.description));
                    else
                        urj_log (URJ_LOG_LEVEL_NORMAL,
                                 _("\tstart: 0x%08lX, length: 0x%08llX, data width: %d bit\n"),
                                 (long unsigned) area.start,
                                 (long long unsigned int) area.length,
                                 area.width);
                }
            }
        }

        return r;
    }

    if (strcasecmp (params[1], "chain") == 0)
    {
        urj_part_parts_print (URJ_LOG_LEVEL_NORMAL, chain->parts);
        return URJ_STATUS_OK;
    }

    for (i = 0; i < urj_buses.len; i++)
    {
        if (urj_buses.buses[i] == urj_bus)
            urj_log (URJ_LOG_LEVEL_NORMAL, _("*%d: "), i);
        else
            urj_log (URJ_LOG_LEVEL_NORMAL, _("%d: "), i);
        URJ_BUS_PRINTINFO (URJ_LOG_LEVEL_NORMAL, urj_buses.buses[i]);
    }

    return URJ_STATUS_OK;
}
Beispiel #17
0
static int
cmd_bfin_run (urj_chain_t *chain, char *params[])
{
    int num_params;

    num_params = urj_cmd_params (params);

    if (num_params < 2)
    {
        urj_error_set (URJ_ERROR_SYNTAX,
                       "#parameters should be >= 2, not %d",
                       num_params);
        return URJ_STATUS_FAIL;
    }

    /* The remaining commands require cable or parts.  */

    if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    if (!chain->parts)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE, "no parts, Run '%s' first",
                       "detect");
        return URJ_STATUS_FAIL;
    }

    if (chain->active_part >= chain->parts->len)
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE, "no active part");
        return URJ_STATUS_FAIL;
    }

    if (!part_is_bfin (chain, chain->active_part))
    {
        urj_error_set (URJ_ERROR_ILLEGAL_STATE, "not a Blackfin part");
        return URJ_STATUS_FAIL;
    }

    assert (chain->active_part >= 0 && chain->active_part < chain->parts->len);

    if (strcmp (params[1], "emulation") == 0)
    {
        if (num_params != 3)
        {
            urj_error_set (URJ_ERROR_BFIN,
                           "'bfin emulation' requires 1 parameter, not %d",
                           num_params - 2);
            return URJ_STATUS_FAIL;
        }

        if (strcmp (params[2], "enable") == 0)
        {
            part_emulation_enable (chain, chain->active_part);
        }
        else if (strcmp (params[2], "trigger") == 0)
        {
            part_emulation_trigger (chain, chain->active_part);
        }
        else if (strcmp (params[2], "enter") == 0)
        {
            part_emulation_enable (chain, chain->active_part);
            part_emulation_trigger (chain, chain->active_part);
        }
        else if (strcmp (params[2], "return") == 0)
        {
            part_emulation_return (chain, chain->active_part);
        }
        else if (strcmp (params[2], "disable") == 0)
        {
            part_emulation_disable (chain, chain->active_part);
        }
        else if (strcmp (params[2], "exit") == 0)
        {
            part_emulation_return (chain, chain->active_part);
            part_emulation_disable (chain, chain->active_part);
        }
        else if (strcmp (params[2], "status") == 0)
        {
            uint16_t dbgstat, excause;
            const char *str_excause;
            urj_part_t *part;

            part_dbgstat_get (chain, chain->active_part);
            part = chain->parts->parts[chain->active_part];
            dbgstat = BFIN_PART_DBGSTAT (part);
            excause = part_dbgstat_emucause (chain, chain->active_part);

            switch (excause)
            {
                case 0x0: str_excause = "EMUEXCPT was executed"; break;
                case 0x1: str_excause = "EMUIN pin was asserted"; break;
                case 0x2: str_excause = "Watchpoint event occurred"; break;
                case 0x4: str_excause = "Performance Monitor 0 overflowed"; break;
                case 0x5: str_excause = "Performance Monitor 1 overflowed"; break;
                case 0x8: str_excause = "Emulation single step"; break;
                default:  str_excause = "Reserved??"; break;
            }

            urj_log (URJ_LOG_LEVEL_NORMAL, "Core [%d] DBGSTAT = 0x%"PRIx16"\n",
                     chain->active_part, dbgstat);

            urj_log (URJ_LOG_LEVEL_NORMAL,
                     "\tEMUDOF     = %u\n"
                     "\tEMUDIF     = %u\n"
                     "\tEMUDOOVF   = %u\n"
                     "\tEMUDIOVF   = %u\n"
                     "\tEMUREADY   = %u\n"
                     "\tEMUACK     = %u\n"
                     "\tEMUCAUSE   = 0x%x (%s)\n"
                     "\tBIST_DONE  = %u\n"
                     "\tLPDEC0     = %u\n"
                     "\tIN_RESET   = %u\n"
                     "\tIDLE       = %u\n"
                     "\tCORE_FAULT = %u\n"
                     "\tLPDEC1     = %u\n",
                     part_dbgstat_is_emudof (chain, chain->active_part),
                     part_dbgstat_is_emudif (chain, chain->active_part),
                     part_dbgstat_is_emudoovf (chain, chain->active_part),
                     part_dbgstat_is_emudiovf (chain, chain->active_part),
                     part_dbgstat_is_emuready (chain, chain->active_part),
                     part_dbgstat_is_emuack (chain, chain->active_part),
                     excause, str_excause,
                     part_dbgstat_is_bist_done (chain, chain->active_part),
                     part_dbgstat_is_lpdec0 (chain, chain->active_part),
                     part_dbgstat_is_in_reset (chain, chain->active_part),
                     part_dbgstat_is_idle (chain, chain->active_part),
                     part_dbgstat_is_core_fault (chain, chain->active_part),
                     part_dbgstat_is_lpdec1 (chain, chain->active_part));
        }
        else if (strcmp (params[2], "singlestep") == 0)
        {
            part_dbgstat_get (chain, chain->active_part);

            if (!part_dbgstat_is_emuready (chain, chain->active_part))
            {
                urj_error_set (URJ_ERROR_BFIN, "Run '%s' first",
                               "bfin emulation enter");
                return URJ_STATUS_FAIL;
            }

            /* TODO  Allow an argument to specify how many single steps.  */

            part_scan_select (chain, chain->active_part, DBGCTL_SCAN);
            part_dbgctl_bit_set_esstep (chain, chain->active_part);
            urj_tap_chain_shift_data_registers_mode (chain, 0, 1, URJ_CHAIN_EXITMODE_UPDATE);
            part_emuir_set (chain, chain->active_part, INSN_RTE, URJ_CHAIN_EXITMODE_IDLE);
            part_scan_select (chain, chain->active_part, DBGCTL_SCAN);
            part_dbgctl_bit_clear_esstep (chain, chain->active_part);
            urj_tap_chain_shift_data_registers_mode (chain, 0, 1, URJ_CHAIN_EXITMODE_UPDATE);
        }
        else
        {
            urj_error_set (URJ_ERROR_BFIN,
                           "unknown emulation subcommand '%s'", params[2]);
            return URJ_STATUS_FAIL;
        }

        return URJ_STATUS_OK;
    }
    else if (strcmp (params[1], "execute") == 0)
    {
        int execute_ret = URJ_STATUS_FAIL;

        part_dbgstat_get (chain, chain->active_part);

        if (!part_dbgstat_is_emuready (chain, chain->active_part))
        {
            urj_error_set (URJ_ERROR_BFIN, "Run '%s' first",
                           "bfin emulation enter");
            return URJ_STATUS_FAIL;
        }

        if (num_params > 2)
        {
            int i;
            struct bfin_insn *insns = NULL;
            struct bfin_insn **last = &insns;
            char tmp[8];
            char *tmpfile = NULL;

            for (i = 2; i < num_params; i++)
            {
                if (params[i][0] == '[' && params[i][1] == '0')
                {
                    uint64_t n;

                    if (sscanf (params[i], "[0%[xX]%"PRIx64"]", tmp, &n) != 2)
                        goto execute_cleanup;

                    *last = (struct bfin_insn *) malloc (sizeof (struct bfin_insn));
                    if (*last == NULL)
                        goto execute_cleanup;

                    (*last)->i = n;
                    (*last)->type = BFIN_INSN_SET_EMUDAT;
                    (*last)->next = NULL;
                    last = &((*last)->next);
                }
                else if (params[i][0] == '0')
                {
                    uint64_t n;

                    if (sscanf (params[i], "0%[xX]%"PRIx64, tmp, &n) != 2)
                        goto execute_cleanup;

                    *last = (struct bfin_insn *) malloc (sizeof (struct bfin_insn));
                    if (*last == NULL)
                        goto execute_cleanup;

                    (*last)->i = n;
                    (*last)->type = BFIN_INSN_NORMAL;
                    (*last)->next = NULL;
                    last = &((*last)->next);
                }
                else
                {
#ifndef HAVE_SYS_WAIT_H
                    urj_error_set (URJ_ERROR_BFIN,
                                   "Sorry, dynamic code not available for your platform");
                    goto execute_cleanup;
#else
                    unsigned char raw_insn[4];
                    char *tmp_buf;
                    char *tuples[] = {"uclinux", "linux-uclibc", "elf"};
                    size_t t;
                    FILE *fp;

                    /* 1024 should be plenty.  */
                    char insns_string[1024];
                    char *p = insns_string;

                    for (; i < num_params; i++)
                    {
                        p += snprintf (p, sizeof (insns_string) - (p - insns_string),
                                       "%s ", params[i]);
                        if (params[i][strlen (params[i]) - 1] == '"')
                            break;
                        if (params[i][strlen (params[i]) - 1] == ';')
                            break;
                    }
                    if (i == num_params)
                    {
                        urj_error_set (URJ_ERROR_BFIN,
                                       "unbalanced double quotes");
                        goto execute_cleanup;
                    }

                    /* p points past the '\0'. p - 1 points to the ending '\0'.
                       p - 2 points to the last double quote.  */
                    *(p - 2) = ';';
                    if (insns_string[0] == '"')
                        insns_string[0] = ' ';

                    /* HRM states that branches and hardware loop setup results
                       in undefined behavior.  Should check opcode instead?  */
                    if (strcasestr(insns_string, "jump") ||
                        strcasestr(insns_string, "call") ||
                        strcasestr(insns_string, "lsetup"))
                        urj_warning (_("jump/call/lsetup insns may not work in emulation\n"));

                    /* get a temporary file to work with -- a little racy */
                    if (!tmpfile)
                    {
                        tmpfile = tmpnam (NULL);
                        if (!tmpfile)
                            goto execute_cleanup;
                        tmpfile = strdup (tmpfile);
                        if (!tmpfile)
                            goto execute_cleanup;
                    }

                    /* try to find a toolchain in $PATH */
                    for (t = 0; t < ARRAY_SIZE(tuples); ++t)
                    {
                        int ret;

                        /* TODO  Pass -mcpu= to gas.  */
                        ret = asprintf (&tmp_buf,
                                        "bfin-%3$s-as --version >/dev/null 2>&1 || exit $?;"
                                        "echo '%1$s' | bfin-%3$s-as - -o \"%2$s\""
                                        " && bfin-%3$s-objcopy -O binary \"%2$s\"",
                                        insns_string, tmpfile, tuples[t]);
                        if (ret == -1)
                        {
                            urj_error_set (URJ_ERROR_OUT_OF_MEMORY, _("asprintf() failed"));
                            goto execute_cleanup;
                        }
                        ret = system (tmp_buf);
                        free (tmp_buf);
                        if (WIFEXITED(ret))
                        {
                            if (WEXITSTATUS(ret) == 0)
                                break;
                            /* 127 -> not found in $PATH */
                            else if (WEXITSTATUS(ret) == 127)
                                continue;
                            else
                            {
                                urj_error_set (URJ_ERROR_BFIN, "GAS failed parsing: %s",
                                               insns_string);
                                goto execute_cleanup;
                            }
                        }
                    }
                    if (t == ARRAY_SIZE(tuples))
                    {
                        urj_error_set (URJ_ERROR_BFIN,
                                       "unable to find Blackfin toolchain in $PATH\n");
                        goto execute_cleanup;
                    }

                    /* Read the binary blob from the toolchain */
                    fp = fopen (tmpfile, FOPEN_R);
                    if (fp == NULL)
                        goto execute_cleanup;

                    /* Figure out how many instructions there are */
                    t = 0;
                    p = insns_string;
                    while ((p = strchr(p, ';')) != NULL)
                    {
                        ++t;
                        ++p;
                    }

                    while (t-- && fread (raw_insn, 1, 2, fp) == 2)
                    {
                        uint16_t iw = raw_insn[0] | (raw_insn[1] << 8);
                        uint64_t n = iw;
                        int is_multiinsn = INSN_IS_MULTI (raw_insn[1]);

                        if ((iw & 0xf000) >= 0xc000)
                        {
                            if (fread (raw_insn, 1, 2, fp) != 2)
                                goto execute_cleanup;

                            iw = raw_insn[0] | (raw_insn[1] << 8);
                            n = (n << 16) | iw;
                        }

                        if (is_multiinsn)
                        {
                            if (fread (raw_insn, 1, 4, fp) != 4)
                                goto execute_cleanup;

                            n = (n << 32)
                                | ((uint64_t)raw_insn[0] << 16)
                                | ((uint64_t)raw_insn[1] << 24)
                                | raw_insn[2] | (raw_insn[3] << 8);
                        }

                        *last = (struct bfin_insn *) malloc (sizeof (struct bfin_insn));
                        if (*last == NULL)
                            goto execute_cleanup;

                        (*last)->i = n;
                        (*last)->type = BFIN_INSN_NORMAL;
                        (*last)->next = NULL;
                        last = &((*last)->next);
                    }

                    fclose (fp);
#endif
                }
            }

            part_execute_instructions (chain, chain->active_part, insns);
            execute_ret = URJ_STATUS_OK;

          execute_cleanup:
            if (tmpfile)
            {
                unlink (tmpfile);
                free (tmpfile);
            }
            while (insns)
            {
                struct bfin_insn *tmp = insns->next;
                free (insns);
                insns = tmp;
            }
        }

        if (execute_ret == URJ_STATUS_OK)
        {
            uint64_t emudat;

            emudat = part_emudat_get (chain, chain->active_part, URJ_CHAIN_EXITMODE_UPDATE);
            urj_log (URJ_LOG_LEVEL_NORMAL, "EMUDAT = 0x%"PRIx64"\n", emudat);

            part_dbgstat_get (chain, chain->active_part);
            if (part_dbgstat_is_core_fault (chain, chain->active_part))
                urj_warning (_("core fault detected\n"));
        }

        return execute_ret;
    }
    else if (strcmp (params[1], "reset") == 0)
    {
        int reset_what = 0;

        part_dbgstat_get (chain, chain->active_part);

        if (!part_dbgstat_is_emuready (chain, chain->active_part))
        {
            urj_error_set (URJ_ERROR_BFIN, "Run '%s' first",
                           "bfin emulation enter");
            return URJ_STATUS_FAIL;
        }

        if (num_params == 3)
        {
            if (!strcmp (params[2], "core"))
                reset_what |= 0x1;
            else if (!strcmp (params[2], "system"))
                reset_what |= 0x2;
            else
            {
                urj_error_set (URJ_ERROR_BFIN, "bad parameter '%s'", params[2]);
                return URJ_STATUS_FAIL;
            }
        }
        else if (num_params == 2)
            reset_what = 0x1 | 0x2;
        else
        {
            urj_error_set (URJ_ERROR_BFIN,
                           "'bfin emulation' requires 0 or 1 parameter, not %d",
                           num_params - 2);
            return URJ_STATUS_FAIL;
        }

        urj_log (URJ_LOG_LEVEL_NORMAL,
                 _("%s: reseting processor ... "), "bfin");
        fflush (stdout);
        if (reset_what == 0x3)
            software_reset (chain, chain->active_part);
        else if (reset_what & 0x1)
            bfin_core_reset (chain, chain->active_part);
        else if (reset_what & 0x2)
            chain_system_reset (chain);
        urj_log (URJ_LOG_LEVEL_NORMAL, _("OK\n"));

        return URJ_STATUS_OK;
    }
    else
    {
        urj_error_set (URJ_ERROR_BFIN,
                       "unknown command '%s'", params[1]);
        return URJ_STATUS_FAIL;
    }

    return URJ_STATUS_OK;
}
Beispiel #18
0
int
urj_tap_chain_connect (urj_chain_t *chain, const char *drivername, char *params[])
{
    urj_cable_t *cable;
    int j, paramc;
    const urj_param_t **cable_params;
    const urj_cable_driver_t *driver;

    urj_cable_parport_devtype_t devtype;
    const char *devname;
    int param_start;

    param_start = 0;
    paramc = urj_cmd_params (params);

    driver = urj_tap_cable_find (drivername);
    if (!driver)
    {
        urj_error_set (URJ_ERROR_INVALID,
                       "unknown cable driver '%s'", drivername);
        return URJ_STATUS_FAIL;
    }

    if (driver->device_type == URJ_CABLE_DEVICE_PARPORT)
    {
        if (paramc < 2)
        {
            urj_error_set (URJ_ERROR_SYNTAX,
                           "parallel cable requires >= 4 parameters, got %d", paramc);
            return URJ_STATUS_FAIL;
        }
        for (j = 0; j < URJ_CABLE_PARPORT_N_DEVS; j++)
            if (strcasecmp (params[0],
                            urj_cable_parport_devtype_string (j)) == 0)
                break;
        if (j == URJ_CABLE_PARPORT_N_DEVS)
        {
            urj_error_set (URJ_ERROR_INVALID,
                           "unknown parallel port device type '%s'",
                           params[0]);
            return URJ_STATUS_FAIL;
        }

        devtype = j;
        devname = params[1];
        param_start = 2;
    }
    else
    {
        /* Silence gcc uninitialized warnings */
        devtype = -1;
        devname = NULL;
    }

    if (urj_param_init_list (&cable_params, &params[param_start],
                             &urj_cable_param_list) != URJ_STATUS_OK)
        return URJ_STATUS_FAIL;

    switch (driver->device_type)
    {
    case URJ_CABLE_DEVICE_PARPORT:
        cable = urj_tap_cable_parport_connect (chain, driver, devtype, devname,
                                               cable_params);
        break;
    case URJ_CABLE_DEVICE_USB:
        cable = urj_tap_cable_usb_connect (chain, driver, cable_params);
        break;
    case URJ_CABLE_DEVICE_OTHER:
        cable = urj_tap_cable_other_connect (chain, driver, cable_params);
        break;
    default:
        cable = NULL;
        break;
    }

    urj_param_clear (&cable_params);

    if (cable == NULL)
        return URJ_STATUS_FAIL;

    chain->cable->chain = chain;
    return URJ_STATUS_OK;
}