The commands in src/cmd/* now return URJ_STATUS_OK, URJ_STATUS_FAIL (or

URJ_STATUS_MUST_QUIT), in accordance with the rest of the library.
The caller of a command must decide how to handle an error (e.g. by printing
its detail message).
print routines in the library (e.g. bus) are equipped with a urj_log_level_t
parameter to control their verbosity.



git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1588 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Rutger Hofman 16 years ago
parent d0aa877eb0
commit 0c44282a7f

@ -1,3 +1,13 @@
2009-05-12 Rutger Hofman <rfhh>
* src/cmd/*.c, many more files: have the commands in src/cmd/ return
URJ_STATUS_OK on success, URJ_STATUS_FAIL on error, URJ_STATUS_MUST_QUIT
at a 'quit' command. The command implementations themselves do not print
on error; that is left to the caller, i.e. the application or a file
parser.
Library commands that produce output (print routines) are equipped with
a urj_log_level_t parameter to control their verbosity.
2009-05-11 Arnim Laeuger <arniml>
* src/bus/ejtag_dma.c (ejtag_dma_bus_init): invert abort condition for break

@ -41,13 +41,22 @@ typedef struct
bsdl.debug = 0; \
} while (0)
/** @return
// @@@@ RFHH ToDo: let urj_bsdl_read_file also return URJ_STATUS_...
/**
* @return
* < 0 : Error occured, parse/syntax problems or out of memory
* = 0 : No errors, idcode not checked or mismatching
* > 0 : No errors, idcode checked and matched
*/
int urj_bsdl_read_file (urj_chain_t *, const char *, int, const char *);
void urj_bsdl_set_path (urj_chain_t *, const char *);
// @@@@ RFHH ToDo: let urj_bsdl_scan_files also return URJ_STATUS_...
/**
* @return
* < 0 : Error occured, parse/syntax problems or out of memory
* = 0 : No errors, idcode not checked or mismatching
* > 0 : No errors, idcode checked and matched
*/
int urj_bsdl_scan_files (urj_chain_t *, const char *, int);
#endif /* URJ_BSDL_BSDL_H */

@ -55,7 +55,7 @@ struct urj_bus_driver
const urj_bus_driver_t *driver,
char *cmd_params[]);
void (*free_bus) (urj_bus_t *bus);
void (*printinfo) (urj_bus_t *bus);
void (*printinfo) (urj_log_level_t ll, urj_bus_t *bus);
void (*prepare) (urj_bus_t *bus);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
int (*area) (urj_bus_t *bus, uint32_t adr, urj_bus_area_t *area);
@ -76,7 +76,7 @@ struct urj_bus
const urj_bus_driver_t *driver;
};
#define URJ_BUS_PRINTINFO(bus) (bus)->driver->printinfo(bus)
#define URJ_BUS_PRINTINFO(ll, bus) (bus)->driver->printinfo(ll, bus)
#define URJ_BUS_PREPARE(bus) (bus)->driver->prepare(bus)
#define URJ_BUS_AREA(bus,adr,a) (bus)->driver->area(bus,adr,a)
#define URJ_BUS_READ_START(bus,adr) (bus)->driver->read_start(bus,adr)

@ -150,13 +150,13 @@ int urj_tap_cable_get_tdo (urj_cable_t *cable);
int urj_tap_cable_get_tdo_late (urj_cable_t *cable);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure */
int urj_tap_cable_defer_get_tdo (urj_cable_t *cable);
/** @return @see (*set_signal)() */
/** @return 0 or 1 on success; -1 on failure */
int urj_tap_cable_set_signal (urj_cable_t *cable, int mask, int val);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure */
int urj_tap_cable_defer_set_signal (urj_cable_t *cable, int mask, int val);
/** @return @see (*get_signal)() */
/** @return 0 or 1 on success; -1 on failure */
int urj_tap_cable_get_signal (urj_cable_t *cable, urj_pod_sigsel_t sig);
/** @return @see (*get_signal)() */
/** @return 0 or 1 on success; -1 on failure */
int urj_tap_cable_get_signal_late (urj_cable_t *cable, urj_pod_sigsel_t sig);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure */
int urj_tap_cable_defer_get_signal (urj_cable_t *cable, urj_pod_sigsel_t sig);

@ -71,7 +71,9 @@ int urj_tap_chain_shift_data_registers_mode (urj_chain_t *chain,
int capture_output, int capture,
int chain_exit);
void urj_tap_chain_flush (urj_chain_t *chain);
/** @return 0 or 1 on success; -1 on failure */
int urj_tap_chain_set_pod_signal (urj_chain_t *chain, int mask, int val);
/** @return 0 or 1 on success; -1 on failure */
int urj_tap_chain_get_pod_signal (urj_chain_t *chain, urj_pod_sigsel_t sig);
/**
* Check whether a chain has an active part

@ -37,24 +37,28 @@
#include "types.h"
/**
* @return:
* 1 on unrecognized command
* otherwise: result from command implementation
* 1 success or library function error
* 0
* -1 command syntax error: wrong number of arguments,
* illegal arguments
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error. Consult
* urj_error for error details. Syntax errors in the input params are
* handled in the same way, urj_error is set to #URJ_ERROR_SYNTAX.
*/
int urj_cmd_run (urj_chain_t *chain, char *params[]);
/**
* @return
* malloc'ed value. The caller is responsible for freeing it.
* Search through registered commands
*
* @param text match commands whose prefix equals <code>text</code>. Rotates
* through the registered commands. The prefix length is set when
* the rotating state is reset.
* @@@@ RFHH that is weird behaviour. Why not do the prefix length as strlen(text)?
* @param state if 0, reset the rotating state to start from the beginning
*
* @return malloc'ed value. The caller is responsible for freeing it.
* NULL for malloc failure or end of command list.
*/
char *urj_cmd_find_next (const char *text, int state);
/* @@@@ RFHH candidate to become local in src/cmd/: */
/* @@@@ RFHH candidate to become local in src/cmd/ after cable refactor */
int urj_cmd_params (char *params[]);
/* @@@@ RFHH candidate to become local in src/cmd/: */
/* @@@@ RFHH candidate to become local in src/cmd/ after cable refactor */
int urj_cmd_get_number (const char *s, unsigned int *i);
#endif /* URJ_CMD_H */

@ -35,7 +35,6 @@ typedef enum urj_error {
URJ_ERROR_ALREADY,
URJ_ERROR_OUT_OF_MEMORY,
URJ_ERROR_NO_CHAIN,
URJ_ERROR_NO_ACTIVE_PART,
URJ_ERROR_NO_ACTIVE_INSTRUCTION,
URJ_ERROR_NO_DATA_REGISTER,
URJ_ERROR_INVALID,
@ -49,6 +48,8 @@ typedef enum urj_error {
URJ_ERROR_IO, /**< I/O error from OS */
URJ_ERROR_BUS,
URJ_ERROR_FLASH,
URJ_ERROR_FLASH_DETECT,
URJ_ERROR_FLASH_PROGRAM,
@ -64,6 +65,7 @@ typedef enum urj_error {
*/
typedef struct urj_error_state {
urj_error_t errnum; /**< error number */
int sys_errno; /**< errno if URJ_ERROR_IO */
const char *file; /**< file where error is set */
const char *function; /**< function --,,-- */
int line; /**< line no --,,-- */
@ -101,6 +103,38 @@ extern const char *urj_error_string (urj_error_t error);
} \
} while (0)
#define urj_error_msg_append(...) \
do { \
if (urj_error_state.errnum == URJ_ERROR_OK) \
snprintf (urj_error_state.msg, sizeof urj_error_state.msg, \
__VA_ARGS__); \
else \
snprintf (urj_error_state.msg + strlen(urj_error_state.msg), \
sizeof urj_error_state.msg \
- strlen(urj_error_state.msg), \
__VA_ARGS__); \
} while (0)
/**
* Set I/O error state: do as urj_error_set, but also store errno in
* #urj_error_state and then reset errno.
*
* @param e urj_error_t value
* @param ... consists of a printf argument set. It needs to start with a
* const char *fmt, followed by arguments used by fmt.
*/
#define urj_error_IO_set(e, ...) \
do { \
urj_error_set (e, __VA_ARGS__); \
urj_error_state.sys_errno = errno; \
errno = 0; \
} while (0)
/**
* The error number
*/
urj_error_t urj_error_get (void);
/**
* Reset the error state.
*/

@ -38,7 +38,6 @@
#include <stdint.h>
#include "types.h"
#include "log.h"
typedef struct urj_flash_cfi_array urj_flash_cfi_array_t;

@ -25,19 +25,7 @@
#include <stdarg.h>
/**
* Log levels
*/
typedef enum urj_log_level {
URJ_LOG_LEVEL_ALL, /**< every single bit as it is transmitted */
URJ_LOG_LEVEL_COMM, /**< low level communication details */
URJ_LOG_LEVEL_DEBUG, /**< more details of interest for developers */
URJ_LOG_LEVEL_DETAIL, /**< verbose output */
URJ_LOG_LEVEL_NORMAL, /**< just noteworthy info */
URJ_LOG_LEVEL_WARNING, /**< unmissable warnings */
URJ_LOG_LEVEL_ERROR, /**< only fatal errors */
URJ_LOG_LEVEL_SILENT, /**< suppress logging output */
} urj_log_level_t;
#include "types.h"
/**
* Log state.

@ -59,7 +59,9 @@ struct urj_parport
int urj_tap_parport_open (urj_parport_t *port);
int urj_tap_parport_close (urj_parport_t *port);
int urj_tap_parport_set_data (urj_parport_t *port, uint8_t data);
/** @return data on success; -1 on error */
int urj_tap_parport_get_data (urj_parport_t *port);
/** @return status on success; -1 on error */
int urj_tap_parport_get_status (urj_parport_t *port);
int urj_tap_parport_set_control (urj_parport_t *port, uint8_t data);

@ -30,17 +30,27 @@
#include "types.h"
/**
* @return -1 on error; see urj_parse_line() otherwise
* @return
* URJ_STATUS_OK on success
* URJ_STATUS_ERROR on error
* URJ_STATUS_QUIT on quit command
*/
int urj_parse_file (urj_chain_t *chain, const char *filename);
int urj_parse_line (urj_chain_t *chain, char *line);
/**
* @return URJ_STATUS_FAIL on error; urj_cmd_run() otherwise
* @return
* URJ_STATUS_OK on success
* URJ_STATUS_ERROR on error
* URJ_STATUS_QUIT on quit command
*/
int urj_parse_line (urj_chain_t *chain, char *line);
int urj_parse_stream (urj_log_level_t ll, urj_chain_t *chain, FILE *f);
/**
* @return see urj_parse_line()
* @return
* URJ_STATUS_OK on success
* URJ_STATUS_ERROR on error
* URJ_STATUS_QUIT on quit command
*/
int urj_parse_stream (urj_chain_t *chain, FILE *f);
int urj_parse_file (urj_log_level_t ll, urj_chain_t *chain,
const char *filename);
/**
* Include a file. Autodetects whether it is a bsdl file or a UrJTAG command

@ -66,9 +66,9 @@ void urj_part_set_instruction (urj_part_t *p, const char *iname);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
int urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, int val);
/** @return -1 on error; signal number >= 0 for success */
int urj_part_get_signal (urj_part_t *p, urj_part_signal_t *s);
int urj_part_get_signal (urj_part_t *p, const urj_part_signal_t *s);
/* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
int urj_part_print (urj_part_t *p);
int urj_part_print (urj_log_level_t ll, urj_part_t *p);
/**
* Set the length of the instructions of a part
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error
@ -104,6 +104,6 @@ int urj_part_parts_add_part (urj_parts_t *ps, urj_part_t *p);
/* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
int urj_part_parts_set_instruction (urj_parts_t *ps, const char *iname);
/* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */
int urj_part_parts_print (urj_parts_t *ps);
int urj_part_parts_print (urj_log_level_t ll, urj_parts_t *ps);
#endif /* URJ_PART_H */

@ -41,8 +41,22 @@ typedef struct urj_data_register urj_data_register_t;
typedef struct urj_bsbit urj_bsbit_t;
typedef struct urj_tap_register urj_tap_register_t;
/**
* Log levels
*/
typedef enum urj_log_level {
URJ_LOG_LEVEL_ALL, /**< every single bit as it is transmitted */
URJ_LOG_LEVEL_COMM, /**< low level communication details */
URJ_LOG_LEVEL_DEBUG, /**< more details of interest for developers */
URJ_LOG_LEVEL_DETAIL, /**< verbose output */
URJ_LOG_LEVEL_NORMAL, /**< just noteworthy info */
URJ_LOG_LEVEL_WARNING, /**< unmissable warnings */
URJ_LOG_LEVEL_ERROR, /**< only fatal errors */
URJ_LOG_LEVEL_SILENT, /**< suppress logging output */
} urj_log_level_t;
#define URJ_STATUS_OK 0
#define URJ_STATUS_FAIL 1
#define URJ_STATUS_SYNTAX_ERROR (-1)
#define URJ_STATUS_MUST_QUIT (-2)
#endif /* URJ_URJ_TYPES_H */

@ -157,6 +157,8 @@ jtag_save_history (void)
#endif /* HAVE_READLINE */
/** @return URJ_STATUS_QUIT on quit command, URJ_STATUS_OK on success,
* URJ_STATUS_ERROR on error */
static int
jtag_readline_multiple_commands_support (urj_chain_t *chain, char *line) /* multiple commands should be separated with '::' */
{
@ -181,11 +183,16 @@ jtag_readline_multiple_commands_support (urj_chain_t *chain, char *line)
}
r = urj_parse_line (chain, line);
if (r == URJ_STATUS_FAIL)
{
urj_log (URJ_LOG_LEVEL_NORMAL, "Error: %s\n", urj_error_describe());
urj_error_reset ();
}
urj_tap_chain_flush (chain);
}
while (nextcmd && r);
while (nextcmd && r != URJ_STATUS_MUST_QUIT);
return r;
}
@ -200,7 +207,8 @@ jtag_readline_loop (urj_chain_t *chain, const char *prompt)
#endif
/* Iterate */
while (jtag_readline_multiple_commands_support (chain, line))
while (jtag_readline_multiple_commands_support (chain, line)
!= URJ_STATUS_MUST_QUIT)
{
free (line);
@ -245,7 +253,8 @@ jtag_readline_loop (urj_chain_t *chain, const char *prompt)
line[0] = 0;
do
{
if (!jtag_readline_multiple_commands_support (chain, line))
if (jtag_readline_multiple_commands_support (chain, line)
== URJ_STATUS_MUST_QUIT)
break;
printf ("%s", prompt);
fflush (stdout);
@ -274,7 +283,7 @@ jtag_parse_rc (urj_chain_t *chain)
strcat (file, "/");
strcat (file, RCFILE);
go = urj_parse_file (chain, file);
go = urj_parse_file (URJ_LOG_LEVEL_DETAIL, chain, file);
free (file);
@ -298,7 +307,7 @@ cleanup (urj_chain_t *chain)
int
main (int argc, char *const argv[])
{
int go = 0;
int go = 1;
int i;
int c;
int norc = 0;
@ -307,7 +316,7 @@ main (int argc, char *const argv[])
int quiet = 0;
urj_chain_t *chain = NULL;
urj_set_argv0(argv[0]);
urj_set_argv0 (argv[0]);
if (geteuid () == 0 && getuid () != 0)
{
@ -428,7 +437,7 @@ main (int argc, char *const argv[])
return -1;
}
go = urj_parse_file (chain, argv[i]);
go = urj_parse_file (URJ_LOG_LEVEL_NORMAL, chain, argv[i]);
cleanup (chain);
if (go < 0)
{
@ -450,7 +459,7 @@ main (int argc, char *const argv[])
printf (_("Out of memory\n"));
return -1;
}
urj_parse_stream (chain, stdin);
urj_parse_stream (URJ_LOG_LEVEL_NORMAL, chain, stdin);
cleanup (chain);
@ -485,7 +494,19 @@ main (int argc, char *const argv[])
jtag_create_jtagdir ();
/* Parse and execute the RC file */
go = norc ? 1 : jtag_parse_rc (chain);
if (!norc)
{
if (jtag_parse_rc (chain) == URJ_STATUS_FAIL)
{
if (urj_error_get() != URJ_ERROR_IO)
{
urj_log (URJ_LOG_LEVEL_NORMAL, "Error: %s\n",
urj_error_describe());
go = 0;
}
urj_error_reset();
}
}
#ifdef HAVE_LIBREADLINE
#ifdef HAVE_READLINE_COMPLETION

@ -124,14 +124,14 @@ au1500_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
au1500_bus_printinfo (urj_bus_t *bus)
au1500_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("AU1500 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("AU1500 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -568,7 +568,7 @@ avr32_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
avr32_bus_printinfo (urj_bus_t *bus)
avr32_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
@ -576,7 +576,7 @@ avr32_bus_printinfo (urj_bus_t *bus)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("AVR32 multi-mode bus driver (JTAG part No. %d)\n"), i);
urj_log (ll, _("AVR32 multi-mode bus driver (JTAG part No. %d)\n"), i);
}
/**

@ -116,15 +116,14 @@ bcm1250_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
bcm1250_bus_printinfo (urj_bus_t *bus)
bcm1250_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Broadcom BCM1250 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Broadcom BCM1250 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -140,15 +140,14 @@ bf533_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
bf533_ezkit_bus_printinfo (urj_bus_t *bus)
bf533_ezkit_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Blackfin BF533 EZKit compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Blackfin BF533 EZKit compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -142,15 +142,14 @@ bf533_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
bf533_stamp_bus_printinfo (urj_bus_t *bus)
bf533_stamp_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Blackfin BF533 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Blackfin BF533 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -314,14 +314,14 @@ bf537_stamp_bus_write (urj_bus_t *bus, uint32_t adr, uint32_t data)
*
*/
static void
bf537_stamp_bus_printinfo (urj_bus_t *bus)
bf537_stamp_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("%s (JTAG part No. %d)\n"), bus->driver->description, i);
urj_log (ll, _("%s (JTAG part No. %d)\n"), bus->driver->description, i);
}
#define BF537_STAMP_BUS_FUNCTIONS \

@ -141,15 +141,14 @@ bf548_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
bf548_ezkit_bus_printinfo (urj_bus_t *bus)
bf548_ezkit_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Blackfin BF548 EZ-KIT compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Blackfin BF548 EZ-KIT compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -146,15 +146,14 @@ bf561_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
bf561_ezkit_bus_printinfo (urj_bus_t *bus)
bf561_ezkit_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Blackfin BF561 EZ-KIT compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Blackfin BF561 EZ-KIT compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -140,15 +140,15 @@ flashbscoach_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
flashbscoach_bus_printinfo (urj_bus_t *bus)
flashbscoach_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Goepel electronic Boundary Scan Coach compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll,
_("Goepel electronic Boundary Scan Coach compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -144,14 +144,14 @@ ejtag_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
ejtag_bus_printinfo (urj_bus_t *bus)
ejtag_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("EJTAG compatible bus driver via PrAcc (JTAG part No. %d)\n"),
urj_log (ll, _("EJTAG compatible bus driver via PrAcc (JTAG part No. %d)\n"),
i);
}

@ -117,14 +117,14 @@ ejtag_dma_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
ejtag_dma_bus_printinfo (urj_bus_t *bus)
ejtag_dma_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("EJTAG compatible bus driver via DMA (JTAG part No. %d)\n"), i);
urj_log (ll, _("EJTAG compatible bus driver via DMA (JTAG part No. %d)\n"), i);
}
/**

@ -502,14 +502,14 @@ fjmem_bus_free (urj_bus_t *bus)
*
*/
static void
fjmem_bus_printinfo (urj_bus_t *bus)
fjmem_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("fjmem FPGA bus driver via USER register (JTAG part No. %d)\n"),
urj_log (ll, _("fjmem FPGA bus driver via USER register (JTAG part No. %d)\n"),
i);
}

@ -122,14 +122,14 @@ h7202_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
h7202_bus_printinfo (urj_bus_t *bus)
h7202_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf ("H7202 compatible bus driver via BSR (JTAG part No. %d)\n", i);
urj_log (ll, "H7202 compatible bus driver via BSR (JTAG part No. %d)\n", i);
}
/**

@ -118,15 +118,14 @@ ixp425_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
ixp425_bus_printinfo (urj_bus_t *bus)
ixp425_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Intel IXP425 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Intel IXP425 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -345,15 +345,14 @@ jopcyc_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
jopcyc_bus_printinfo (urj_bus_t *bus)
jopcyc_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("JOP.design Cyclone Board compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("JOP.design Cyclone Board compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -140,15 +140,14 @@ lh7a400_bus_new (urj_chain_t *chain, const const urj_bus_driver_t *driver,
*
*/
static void
lh7a400_bus_printinfo (urj_bus_t *bus)
lh7a400_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Sharp LH7A400 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Sharp LH7A400 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -146,15 +146,14 @@ mpc5200_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
mpc5200_bus_printinfo (urj_bus_t *bus)
mpc5200_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Freescale MPC5200 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Freescale MPC5200 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -247,15 +247,14 @@ mpc824x_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
mpc824x_bus_printinfo (urj_bus_t *bus)
mpc824x_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Motorola MPC824x compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Motorola MPC824x compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -112,15 +112,14 @@ ppc405ep_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
ppc405ep_bus_printinfo (urj_bus_t *bus)
ppc405ep_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("IBM PowerPC 405EP compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("IBM PowerPC 405EP compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -114,15 +114,14 @@ ppc440gx_ebc8_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
ppc440gx_ebc8_bus_printinfo (urj_bus_t *bus)
ppc440gx_ebc8_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("IBM PowerPC 440GX 8-bit compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("IBM PowerPC 440GX 8-bit compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -325,15 +325,14 @@ prototype_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
prototype_bus_printinfo (urj_bus_t *bus)
prototype_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Configurable prototype bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Configurable prototype bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -250,14 +250,14 @@ pxa2xx_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
pxa2xx_bus_printinfo (urj_bus_t *bus)
pxa2xx_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("%s (JTAG part No. %d)\n"), bus->driver->description, i);
urj_log (ll, _("%s (JTAG part No. %d)\n"), bus->driver->description, i);
}
/**
@ -285,24 +285,21 @@ pxa2xx_bus_init (urj_bus_t *bus)
if (PROC == PROC_PXA25x)
{
const urj_part_signal_t *bs_2 = urj_part_find_signal (p, "BOOT_SEL[2]");
const urj_part_signal_t *bs_1 = urj_part_find_signal (p, "BOOT_SEL[1]");
const urj_part_signal_t *bs_0 = urj_part_find_signal (p, "BOOT_SEL[0]");
BOOT_DEF = BOOT_DEF_PKG_TYPE |
BOOT_DEF_BOOT_SEL (urj_part_get_signal
(p,
urj_part_find_signal (p,
"BOOT_SEL[2]")) << 2 |
urj_part_get_signal (p,
urj_part_find_signal (p,
"BOOT_SEL[1]"))
<< 1 | urj_part_get_signal (p,
urj_part_find_signal
(p,
"BOOT_SEL[0]")));
BOOT_DEF_BOOT_SEL (urj_part_get_signal (p, bs_2) << 2
| urj_part_get_signal (p, bs_1) << 1
| urj_part_get_signal (p, bs_0));
}
else if (PROC == PROC_PXA27x)
{
const urj_part_signal_t *bs = urj_part_find_signal (p, "BOOT_SEL");
BOOT_DEF = BOOT_DEF_PKG_TYPE |
BOOT_DEF_BOOT_SEL (urj_part_get_signal
(p, urj_part_find_signal (p, "BOOT_SEL")));
BOOT_DEF_BOOT_SEL (urj_part_get_signal (p, bs));
}
else
printf ("BUG in the code, file %s, line %d.\n", __FILE__, __LINE__);

@ -182,15 +182,14 @@ s3c4510_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
s3c4510_bus_printinfo (urj_bus_t *bus)
s3c4510_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Samsung S3C4510B compatibile bus driver via BSR (JTAG part No. %d) RCS0=%ubit\n"),
urj_log (ll, _("Samsung S3C4510B compatibile bus driver via BSR (JTAG part No. %d) RCS0=%ubit\n"),
i, dbus_width);
}
@ -236,12 +235,10 @@ s3c4510_bus_area (urj_bus_t *bus, uint32_t adr, urj_bus_area_t *area)
area->length = UINT64_C (0x100000000);
// endian = urj_part_get_signal( bus->part, urj_part_find_signal( bus->part, "LITTLE" ));
b0size0 =
urj_part_get_signal (bus->part,
urj_part_find_signal (bus->part, "B0SIZE0"));
b0size1 =
urj_part_get_signal (bus->part,
urj_part_find_signal (bus->part, "B0SIZE1"));
b0size0 = urj_part_get_signal (bus->part,
urj_part_find_signal (bus->part, "B0SIZE0"));
b0size1 = urj_part_get_signal (bus->part,
urj_part_find_signal (bus->part, "B0SIZE1"));
switch ((b0size1 << 1) | b0size0)
{

@ -125,15 +125,14 @@ sa1110_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
sa1110_bus_printinfo (urj_bus_t *bus)
sa1110_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Intel SA-1110 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Intel SA-1110 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -136,15 +136,14 @@ sh7727_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
sh7727_bus_printinfo (urj_bus_t *bus)
sh7727_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Hitachi SH7727 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Hitachi SH7727 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -134,15 +134,14 @@ sh7750r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
sh7750r_bus_printinfo (urj_bus_t *bus)
sh7750r_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Hitachi SH7750R compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Hitachi SH7750R compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -128,15 +128,14 @@ sh7751r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
sh7751r_bus_printinfo (urj_bus_t *bus)
sh7751r_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Hitachi SH7751R compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Hitachi SH7751R compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -122,15 +122,14 @@ sharc_21065L_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
sharc_21065L_bus_printinfo (urj_bus_t *bus)
sharc_21065L_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Analog Device's SHARC 21065L compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Analog Device's SHARC 21065L compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -170,14 +170,14 @@ slsup3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
slsup3_bus_printinfo (urj_bus_t *bus)
slsup3_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_("SLS UP3 bus driver via BSR (JTAG part No. %d)\n"), i);
urj_log (ll, _("SLS UP3 bus driver via BSR (JTAG part No. %d)\n"), i);
}
/**

@ -138,15 +138,14 @@ tx4925_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
tx4925_bus_printinfo (urj_bus_t *bus)
tx4925_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Toshiba TX4925 compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Toshiba TX4925 compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -420,15 +420,14 @@ zefant_xs3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
*
*/
static void
zefant_xs3_bus_printinfo (urj_bus_t *bus)
zefant_xs3_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus)
{
int i;
for (i = 0; i < bus->chain->parts->len; i++)
if (bus->part == bus->chain->parts->parts[i])
break;
printf (_
("Simple Solutions Zefant-XS3 Board compatible bus driver via BSR (JTAG part No. %d)\n"),
urj_log (ll, _("Simple Solutions Zefant-XS3 Board compatible bus driver via BSR (JTAG part No. %d)\n"),
i);
}

@ -43,6 +43,8 @@ typedef struct
char *name;
char *desc;
void (*help) (void);
/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error, both
* syntax and library errors */
int (*run) (urj_chain_t *chain, char *params[]);
} urj_cmd_t;
@ -93,6 +95,11 @@ extern const urj_cmd_t urj_cmd_debug;
extern const urj_cmd_t *urj_cmds[];
/**
* Tests if chain has a cable pointer
*
* @return URJ_STATUS_OK if success; URJ_STATUS_FAIL on error or failure
*/
int urj_cmd_test_cable (urj_chain_t *chain);
#endif /* URJ_CMD_H */

@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/tap.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
@ -39,32 +40,39 @@ cmd_addpart_run (urj_chain_t *chain, char *params[])
unsigned int len;
if (urj_cmd_params (params) != 2)
return -1;
{
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_get_number (params[1], &len))
return -1;
if (urj_cmd_get_number (params[1], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (!urj_cmd_test_cable (chain))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
// @@@@ RFHH check result
urj_tap_manual_add (chain, len);
if (urj_tap_manual_add (chain, len) == -1)
return URJ_STATUS_FAIL;
// @@@@ RFHH this cannot be
if (chain->parts == NULL)
return 1;
return URJ_STATUS_FAIL;
// @@@@ RFHH this cannot be
if (chain->parts->len == 0)
{
urj_part_parts_free (chain->parts);
chain->parts = NULL;
return URJ_STATUS_FAIL;
}
/* @@@@ RFHH check result */
urj_part_parts_set_instruction (chain->parts, "BYPASS");
/* @@@@ RFHH check result */
urj_tap_chain_shift_instructions (chain);
return 1;
return URJ_STATUS_OK;
}

@ -67,38 +67,36 @@ cmd_bit_run (urj_chain_t *chain, char *params[])
if ((parameters != 5) && (parameters != 8))
{
printf (_("%s: invalid number of parameters (%d) for command '%s'\n"),
"bit", parameters, command);
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #params should be 5 or 8, not %d",
"bus", parameters);
return URJ_STATUS_FAIL;
}
if (!urj_cmd_test_cable (chain))
{
printf (_("%s: cable test failed for command '%s'\n"), "bit",
command);
return 1;
}
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
{
return 1;
}
return URJ_STATUS_FAIL;
/* bit number */
if (urj_cmd_get_number (params[1], &bit))
if (urj_cmd_get_number (params[1], &bit) != URJ_STATUS_OK)
{
printf (_("%s: unable to get boundary bit number for command '%s'\n"),
"bit", command);
return -1;
// error state already set
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%s: unable to get boundary bit number for command '%s'"),
"bus", command);
return URJ_STATUS_FAIL;
}
/* bit type */
if (strlen (params[2]) != 1)
{
printf (_("%s: invalid bit type length for command '%s'\n"), "bit",
command);
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
_("%s: invalid bit type length for command '%s'"),
"bus", command);
return URJ_STATUS_FAIL;
}
switch (params[2][0])
{
@ -123,16 +121,19 @@ cmd_bit_run (urj_chain_t *chain, char *params[])
type = URJ_BSBIT_INTERNAL;
break;
default:
printf (_("%s: invalid bit type for command '%s'\n"), "bit", command);
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
_("%s: invalid bit type for command '%s'"),
"bus", command);
return URJ_STATUS_FAIL;
}
/* default (safe) value */
if (strlen (params[3]) != 1)
{
printf (_("%s: invalid default value length for command '%s'\n"),
"bit", command);
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
_("%s: invalid default value length for command '%s'"),
"bus", command);
return URJ_STATUS_FAIL;
}
switch (params[3][0])
{
@ -144,58 +145,52 @@ cmd_bit_run (urj_chain_t *chain, char *params[])
safe = URJ_BSBIT_DONTCARE;
break;
default:
printf (_("%s: invalid default value for command '%s'\n"),
"bit", command);
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
_("%s: invalid default value '%s' for command '%s'"),
"bus", params[3], command);
return URJ_STATUS_FAIL;
}
if (urj_cmd_params (params) == 5)
// without control bit
return urj_part_bsbit_alloc (part, bit, params[4], type, safe);
/* with control bit */
int control_value;
int control_state;
/* control bit number */
if (urj_cmd_get_number (params[5], &control) != URJ_STATUS_OK)
{
urj_log (URJ_LOG_LEVEL_NORMAL,
_("%s: unable to get control bit number for command '%s'"),
"bit", command);
return URJ_STATUS_FAIL;
}
/* control value */
if (strlen (params[6]) != 1)
{
urj_error_set (URJ_ERROR_SYNTAX,
_("%s: invalid control value length for command '%s'"),
"bit", command);
return URJ_STATUS_FAIL;
}
control_value = (params[6][0] == '1');
/* test for control bit */
if (urj_cmd_params (params) == 5) {
if (urj_part_bsbit_alloc (part, bit, params[4], type,
safe) != URJ_STATUS_OK)
{
printf ("in command '%s'\n", command);
urj_error_reset();
return 1;
}
} else {
int control_value;
int control_state;
/* control bit number */
if (urj_cmd_get_number (params[5], &control))
{
printf (_("%s: unable to get control bit number for command '%s'\n"),
"bit", command);
return -1;
}
/* control value */
if (strlen (params[6]) != 1)
{
printf (_("%s: invalid control value length for command '%s'\n"),
"bit", command);
return -1;
}
control_value = (params[6][0] == '1');
/* control state */
if (strcasecmp (params[7], "Z"))
return -1;
control_state = URJ_BSBIT_STATE_Z;
if (urj_part_bsbit_alloc_control (part, bit, params[4], type, safe,
control, control_value,
control_state) != URJ_STATUS_OK)
{
printf ("in command '%s'\n", command);
urj_error_reset();
return 1;
}
/* control state */
if (strcasecmp (params[7], "Z"))
{
urj_error_set (URJ_ERROR_SYNTAX, "control state '%s' must be 'Z'",
params[7]);
return URJ_STATUS_FAIL;
}
return 1;
control_state = URJ_BSBIT_STATE_Z;
return urj_part_bsbit_alloc_control (part, bit, params[4], type, safe,
control, control_value,
control_state);
}
static void

@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/bsdl.h>
#include <urjtag/chain.h>
#include <urjtag/cmd.h>
@ -41,68 +42,71 @@ cmd_bsdl_run (urj_chain_t *chain, char *params[])
urj_bsdl_globs_t *globs = &(chain->bsdl);
num_params = urj_cmd_params (params);
if (num_params >= 2)
if (num_params < 2 || num_params > 3)
{
if (strcmp (params[1], "test") == 0)
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be %d or %d, not %d",
params[0], 2, 3, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
if (strcmp (params[1], "test") == 0)
{
int debug_save;
debug_save = globs->debug;
globs->debug = 1;
if (num_params == 3)
{
result = urj_bsdl_read_file (chain, params[2], URJ_BSDL_MODE_TEST,
NULL) >= 0 ? 1 : -1;
}
else if (num_params == 2)
{
int debug_save;
urj_bsdl_scan_files (chain, NULL, URJ_BSDL_MODE_TEST);
result = 1;
}
globs->debug = debug_save;
}
debug_save = globs->debug;
globs->debug = 1;
if (num_params == 3)
{
result =
urj_bsdl_read_file (chain, params[2], URJ_BSDL_MODE_TEST,
NULL) >= 0 ? 1 : -1;
}
else if (num_params == 2)
{
urj_bsdl_scan_files (chain, NULL, URJ_BSDL_MODE_TEST);
result = 1;
}
globs->debug = debug_save;
if (strcmp (params[1], "dump") == 0)
{
if (num_params == 3)
{
result = urj_bsdl_read_file (chain, params[2], URJ_BSDL_MODE_DUMP,
NULL) >= 0 ? 1 : -1;
}
else if (num_params == 2)
{
urj_bsdl_scan_files (chain, NULL, URJ_BSDL_MODE_DUMP);
result = 1;
}
}
if (strcmp (params[1], "dump") == 0)
if (num_params == 3)
{
if (strcmp (params[1], "path") == 0)
{
if (num_params == 3)
{
result =
urj_bsdl_read_file (chain, params[2], URJ_BSDL_MODE_DUMP,
NULL) >= 0 ? 1 : -1;
}
else if (num_params == 2)
{
urj_bsdl_scan_files (chain, NULL, URJ_BSDL_MODE_DUMP);
result = 1;
}
urj_bsdl_set_path (chain, params[2]);
result = 1;
}
if (num_params == 3)
if (strcmp (params[1], "debug") == 0)
{
if (strcmp (params[1], "path") == 0)
if (strcmp (params[2], "on") == 0)
{
urj_bsdl_set_path (chain, params[2]);
globs->debug = 1;
result = 1;
}
if (strcmp (params[1], "debug") == 0)
if (strcmp (params[2], "off") == 0)
{
if (strcmp (params[2], "on") == 0)
{
globs->debug = 1;
result = 1;
}
if (strcmp (params[2], "off") == 0)
{
globs->debug = 0;
result = 1;
}
globs->debug = 0;
result = 1;
}
}
}
return result;
return (result >= 0) ? URJ_STATUS_OK : URJ_STATUS_FAIL;
}

@ -41,26 +41,27 @@ cmd_bus_run (urj_chain_t *chain, char *params[])
unsigned int n;
if (urj_cmd_params (params) != 2)
return -1;
if (!urj_cmd_test_cable (chain))
return 1;
if (!chain->parts)
{
printf (_("Run \"detect\" first.\n"));
return 1;
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_get_number (params[1], &n))
return -1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (urj_bus_buses_set (n) != URJ_STATUS_OK)
if (!chain->parts)
{
urj_error_reset();
urj_error_set (URJ_ERROR_ILLEGAL_STATE, "no parts. Run '%s' first",
"detect");
return URJ_STATUS_FAIL;
}
return 1;
if (urj_cmd_get_number (params[1], &n) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
return urj_bus_buses_set (n);
}
static void

@ -28,6 +28,7 @@
#include <string.h>
#include <stdlib.h>
#include <urjtag/error.h>
#include <urjtag/parport.h>
#include <urjtag/tap.h>
#include <urjtag/cable.h>
@ -47,7 +48,12 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
/* we need at least one parameter for 'cable' command */
if (paramc < 2)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be >= %d, not %d",
params[0], 2, paramc);
return URJ_STATUS_FAIL;
}
/* maybe old syntax was used? search connection type driver */
for (i = 0; urj_tap_parport_drivers[i]; i++)
@ -57,8 +63,7 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
if (urj_tap_parport_drivers[i] != 0)
{
/* Old syntax was used. Swap params. */
printf (_
("Note: the 'cable' command syntax changed, please read the help text\n"));
urj_warning ("Note: the 'cable' command syntax changed, please read the help text\n");
if (paramc >= 4)
{
char *tmparam;
@ -68,7 +73,12 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
params[1] = tmparam;
}
else
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"old syntax requires >= %d params, not %d",
4, paramc);
return URJ_STATUS_FAIL;
}
}
/* search cable driver list */
@ -77,8 +87,9 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
break;
if (!urj_tap_cable_drivers[i])
{
printf (_("Unknown cable type: %s\n"), params[1]);
return 1;
urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown cable type: '%s'"),
params[1]);
return URJ_STATUS_FAIL;
}
if (paramc >= 3)
@ -86,7 +97,7 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
if (strcasecmp (params[2], "help") == 0)
{
urj_tap_cable_drivers[i]->help (urj_tap_cable_drivers[i]->name);
return 1;
return URJ_STATUS_OK;
}
}
@ -101,32 +112,31 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
cable = calloc (1, sizeof (urj_cable_t));
if (!cable)
{
printf (_("%s(%d) calloc failed!\n"), __FILE__, __LINE__);
return 1;
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails",
1, sizeof (urj_cable_t));
return URJ_STATUS_FAIL;
}
cable->driver = urj_tap_cable_drivers[i];
if (cable->driver->connect (++params, cable))
{
printf (_("Error: Cable connection failed!\n"));
free (cable);
return 1;
return URJ_STATUS_FAIL;
}
chain->cable = cable;
if (urj_tap_cable_init (chain->cable))
{
printf (_("Error: Cable initialization failed!\n"));
urj_tap_chain_disconnect (chain);
return 1;
return URJ_STATUS_FAIL;
}
urj_tap_chain_set_trst (chain, 0);
urj_tap_chain_set_trst (chain, 1);
urj_tap_reset (chain);
return 1;
return URJ_STATUS_OK;
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/cmd.h>
@ -106,12 +107,12 @@ int
urj_cmd_test_cable (urj_chain_t *chain)
{
if (chain->cable)
return 1;
return URJ_STATUS_OK;
printf (_
("Error: Cable not configured. Please use '%s' command first!\n"),
"cable");
return 0;
urj_error_set (URJ_ERROR_ILLEGAL_STATE,
"Cable not configured. Please use '%s' command first!",
"cable");
return URJ_STATUS_FAIL;
}
/* Remainder copied from libbrux/cmd/cmd.c */
@ -123,7 +124,7 @@ urj_cmd_run (urj_chain_t *chain, char *params[])
size_t len;
if (!params[0])
return 1;
return URJ_STATUS_OK;
pidx = -1;
len = strlen (params[0]);
@ -132,13 +133,8 @@ urj_cmd_run (urj_chain_t *chain, char *params[])
{
if (strcasecmp (urj_cmds[i]->name, params[0]) == 0)
{
int r;
run_cmd:
r = urj_cmds[i]->run (chain, params);
if (r < 0)
printf (_("%s: syntax error!\n"), params[0]);
return r;
return urj_cmds[i]->run (chain, params);
}
else if (strncasecmp (urj_cmds[i]->name, params[0], len) == 0)
{
@ -152,17 +148,17 @@ urj_cmd_run (urj_chain_t *chain, char *params[])
switch (pidx)
{
case -2:
printf (_("%s: Ambiguous command\n"), params[0]);
urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: Ambiguous command\n"), params[0]);
break;
case -1:
printf (_("%s: unknown command\n"), params[0]);
urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: unknown command\n"), params[0]);
break;
default:
i = pidx;
goto run_cmd;
}
return 1;
return URJ_STATUS_OK;
}
int
@ -184,19 +180,24 @@ urj_cmd_get_number (const char *s, unsigned int *i)
size_t l;
if (!s || !i)
return -1;
{
urj_error_set (URJ_ERROR_INVALID, "NULL string or int pointer");
return URJ_STATUS_FAIL;
}
l = strlen (s);
n = -1;
r = sscanf (s, "0x%x%n", i, &n);
if (r == 1 && n == l)
return 0;
return URJ_STATUS_OK;
n = -1;
r = sscanf (s, "%u%n", i, &n);
if (r == 1 && n == l)
return 0;
return URJ_STATUS_OK;
urj_error_set (URJ_ERROR_SYNTAX, "not a number: '%s'", s);
return -1;
return URJ_STATUS_FAIL;
}

@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/jtag.h>
#include <urjtag/cmd.h>
@ -39,14 +40,23 @@ cmd_debug_run (urj_chain_t *chain, char *params[])
{
unsigned int i;
// @@@@ RFHH change this to control the urj_log level
// @@@@ RFHH urj_debug_mode isn't used anyway
if (urj_cmd_params (params) != 2)
return -1;
{
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_get_number (params[1], &i))
return -1;
if (urj_cmd_get_number (params[1], &i) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
urj_debug_mode = i;
return 1;
return URJ_STATUS_OK;
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/tap.h>
#include <urjtag/error.h>
@ -38,18 +39,20 @@ static int
cmd_detect_run (urj_chain_t *chain, char *params[])
{
if (urj_cmd_params (params) != 1)
return -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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (urj_tap_detect (chain) != URJ_STATUS_OK)
{
urj_error_reset();
return 1;
}
return URJ_STATUS_FAIL;
return 1;
return URJ_STATUS_OK;
}
static void

@ -40,24 +40,23 @@ cmd_detectflash_run (urj_chain_t *chain, char *params[])
uint32_t adr;
if (urj_cmd_params (params) != 2)
return -1;
if (!urj_bus)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
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_get_number (params[1], &adr))
return -1;
if (urj_flash_detectflash (URJ_LOG_LEVEL_NORMAL, urj_bus, adr) != URJ_STATUS_OK)
if (!urj_bus)
{
printf("detect flash error: %s\n", urj_error_describe());
urj_error_reset();
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus missing"));
return URJ_STATUS_FAIL;
}
return 1;
if (urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
return urj_flash_detectflash (URJ_LOG_LEVEL_NORMAL, urj_bus, adr);
}
static void

@ -26,6 +26,7 @@
#include <stdio.h>
#include <urjtag/error.h>
#include <urjtag/tap.h>
#include <urjtag/cmd.h>
@ -36,14 +37,17 @@ static int
cmd_discovery_run (urj_chain_t *chain, char *params[])
{
if (urj_cmd_params (params) != 1)
return -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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
urj_tap_discovery (chain);
return 1;
return urj_tap_discovery (chain);
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/part_instruction.h>
@ -47,26 +48,33 @@ cmd_dr_run (urj_chain_t *chain, char *params[])
urj_part_instruction_t *active_ir;
if (urj_cmd_params (params) < 1 || urj_cmd_params (params) > 2)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
active_ir = part->active_instruction;
if (active_ir == NULL)
{
printf (_("%s: part without active instruction\n"), "dr");
return 1;
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)
{
printf (_("%s: part without active data register\n"), "dr");
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE,
_("%s: part without active data register"), "dr");
return URJ_STATUS_FAIL;
}
if (params[1])
@ -80,14 +88,19 @@ cmd_dr_run (urj_chain_t *chain, char *params[])
unsigned int bit;
if (strspn (params[1], "01") != strlen (params[1]))
{
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
"bit patterns should be 0s and 1s, not '%s'",
params[1]);
return URJ_STATUS_FAIL;
}
r = dr->in;
if (r->len != strlen (params[1]))
{
printf (_("%s: register length mismatch\n"), "dr");
return 1;
urj_error_set (URJ_ERROR_OUT_OF_BOUNDS,
_("%s: register length %d mismatch: %d"),
"dr", r->len, strlen (params[1]));
return URJ_STATUS_FAIL;
}
for (bit = 0; params[1][bit]; bit++)
{
@ -102,9 +115,9 @@ cmd_dr_run (urj_chain_t *chain, char *params[])
r = dr->out;
else
r = dr->in;
printf (_("%s\n"), urj_tap_register_get_string (r));
urj_log (URJ_LOG_LEVEL_NORMAL, _("%s\n"), urj_tap_register_get_string (r));
return 1;
return URJ_STATUS_OK;
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/jtag.h>
#include <urjtag/cmd.h>
@ -37,29 +38,38 @@ static int
cmd_endian_run (urj_chain_t *chain, char *params[])
{
if (urj_cmd_params (params) > 2)
return -1;
{
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])
{
if (urj_big_endian)
printf (_("Endianess for external files: big\n"));
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Endianess for external files: big\n"));
else
printf (_("Endianess for external files: little\n"));
return 1;
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Endianess for external files: little\n"));
return URJ_STATUS_OK;
}
if (strcasecmp (params[1], "little") == 0)
{
urj_big_endian = 0;
return 1;
return URJ_STATUS_OK;
}
if (strcasecmp (params[1], "big") == 0)
{
urj_big_endian = 1;
return 1;
return URJ_STATUS_OK;
}
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
"endianness must be 'little' or 'big', not '%s'", params[1]);
return URJ_STATUS_FAIL;
}
static void

@ -43,25 +43,26 @@ cmd_eraseflash_run (urj_chain_t *chain, char *params[])
unsigned int number = 0;
if (urj_cmd_params (params) != 3)
return -1;
if (!urj_cmd_test_cable (chain))
return 1;
if (!urj_bus)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
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_get_number (params[1], &adr))
return -1;
if (urj_cmd_get_number (params[2], &number))
return -1;
if (urj_flasherase (urj_bus, adr, number) != URJ_STATUS_OK)
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (!urj_bus)
{
printf ("error: %s\n", urj_error_describe());
urj_error_reset();
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 1;
return urj_flasherase (urj_bus, adr, number);
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <urjtag/error.h>
#include <urjtag/bus.h>
@ -44,19 +45,25 @@ cmd_flashmem_run (urj_chain_t *chain, char *params[])
uint32_t adr = 0;
FILE *f;
int paramc = urj_cmd_params (params);
int r;
if (paramc < 3)
return -1;
{
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)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
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))
return -1;
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;
@ -66,28 +73,20 @@ cmd_flashmem_run (urj_chain_t *chain, char *params[])
f = fopen (params[2], "rb");
if (!f)
{
printf (_("Unable to open file `%s'!\n"), params[2]);
return 1;
urj_error_set (URJ_ERROR_IO, _("Unable to open file `%s': %s"),
params[2], strerror (errno));
errno = 0;
return URJ_STATUS_FAIL;
}
if (msbin)
{
if (urj_flashmsbin (urj_bus, f, noverify) != URJ_STATUS_OK)
{
printf ("error: %s\n", urj_error_describe());
urj_error_reset();
}
}
r = urj_flashmsbin (urj_bus, f, noverify);
else
{
if (urj_flashmem (urj_bus, f, adr, noverify) != URJ_STATUS_OK)
{
printf ("error: %s\n", urj_error_describe());
urj_error_reset();
}
}
r = urj_flashmem (urj_bus, f, adr, noverify);
fclose (f);
return 1;
return r;
}
static void

@ -26,6 +26,7 @@
#include <stdio.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/cable.h>
@ -38,26 +39,31 @@ cmd_frequency_run (urj_chain_t *chain, char *params[])
{
unsigned int freq;
if (!urj_cmd_test_cable (chain))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
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_params (params) == 1)
{
printf (_("Current TCK frequency is %u Hz\n"),
urj_log (URJ_LOG_LEVEL_NORMAL, _("Current TCK frequency is %u Hz\n"),
urj_tap_cable_get_frequency (chain->cable));
return 1;
return URJ_STATUS_OK;
}
if (urj_cmd_params (params) != 2)
return -1;
if (urj_cmd_get_number (params[1], &freq))
return -1;
if (urj_cmd_get_number (params[1], &freq) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
printf (_("Setting TCK frequency to %u Hz\n"), freq);
urj_log (URJ_LOG_LEVEL_NORMAL, _("Setting TCK frequency to %u Hz\n"), freq);
urj_tap_cable_set_frequency (chain->cable, freq);
return 1;
return URJ_STATUS_OK;
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/part.h>
#include <urjtag/chain.h>
#include <urjtag/bssignal.h>
@ -43,35 +44,47 @@ cmd_get_run (urj_chain_t *chain, char *params[])
urj_part_t *part;
if (urj_cmd_params (params) != 3)
return -1;
{
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)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
s = urj_part_find_signal (part, params[2]);
if (!s)
{
printf (_("signal '%s' not found\n"), params[2]);
return 1;
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)
printf (_("%s = %d\n"), params[2], data);
if (data == -1)
return URJ_STATUS_FAIL;
urj_log (URJ_LOG_LEVEL_NORMAL, _("%s = %d\n"), params[2], data);
return 1;
return URJ_STATUS_OK;
}
static void
cmd_get_help (void)
{
printf (_("Usage: %s SIGNAL\n"
printf (_("Usage: %s signal SIGNAL\n"
"Get signal state from output BSR (Boundary Scan Register).\n"
"\n"
"SIGNAL signal name (from JTAG declaration file)\n"),

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/cmd.h>
#include "cmd.h"
@ -36,34 +37,39 @@ 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 (!params[1])
if (urj_cmd_params (params) == 1)
{
printf (_("Command list:\n\n"));
urj_log (URJ_LOG_LEVEL_NORMAL, _("Command list:\n\n"));
for (i = 0; urj_cmds[i]; i++)
printf (_("%-13s %s\n"), urj_cmds[i]->name,
urj_cmds[i]->desc ? _(urj_cmds[i]->desc) :
_("(no description available)"));
printf (_
("\nType \"help COMMAND\" for details about a particular command.\n"));
return 1;
urj_log (URJ_LOG_LEVEL_NORMAL, _("%-13s %s\n"), urj_cmds[i]->name,
urj_cmds[i]->desc ? _(urj_cmds[i]->desc) :
_("(no description available)"));
urj_log (URJ_LOG_LEVEL_NORMAL,
_("\nType \"help COMMAND\" for details about a particular command.\n"));
return URJ_STATUS_OK;
}
if (params[2])
return -1;
/* 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 1;
return URJ_STATUS_OK;
}
printf (_("%s: unknown command\n"), params[1]);
urj_log (URJ_LOG_LEVEL_NORMAL, _("%s: unknown command\n"), params[1]);
return 1;
return URJ_STATUS_OK;
}
static void

@ -25,6 +25,7 @@
#include <stdio.h>
#include <urjtag/error.h>
#include <urjtag/tap.h>
#include <urjtag/cmd.h>
@ -36,24 +37,23 @@ cmd_idcode_run (urj_chain_t *chain, char *params[])
{
unsigned int bytes = 0;
if (urj_cmd_params (params) == 1)
if (urj_cmd_params (params) > 2)
{
bytes = 0;
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be <= %d, not %d",
params[0], 2, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
else if (urj_cmd_params (params) > 2)
return -1;
if (urj_cmd_params (params) == 2)
if (urj_cmd_get_number (params[1], &bytes) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
else if (urj_cmd_get_number (params[1], &bytes))
return -1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (!urj_cmd_test_cable (chain))
return 1;
printf (_("Reading %d bytes if idcode\n"), bytes);
// @@@@ RFHH check return value
urj_tap_idcode (chain, bytes);
return 1;
urj_log (URJ_LOG_LEVEL_NORMAL, _("Reading %d bytes of idcode\n"), bytes);
return urj_tap_idcode (chain, bytes);
}
static void

@ -43,37 +43,36 @@ cmd_include_or_script_run (urj_chain_t *chain, int is_include, char *params[])
{
int i;
unsigned int j = 1;
int r = URJ_STATUS_OK;
if (urj_cmd_params (params) < 2)
return -1;
{
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 (!is_include)
{
printf (_("Please use the 'include' command instead of 'script'\n"));
urj_warning (_("Please use the 'include' command instead of 'script'\n"));
}
if (urj_cmd_params (params) > 2)
{
/* loop n times option */
if (urj_cmd_get_number (params[2], &j))
{
printf (_("%s: unable to get number from '%s'\n"),
"include/script", params[2]);
return -1;
}
if (urj_cmd_get_number (params[2], &j) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
}
for (i = 0; i < j; i++)
{
if (urj_parse_include (chain, params[1], ! is_include) != URJ_STATUS_OK)
{
printf ("error: %s\n", urj_error_describe ());
urj_error_reset ();
r = urj_parse_include (chain, params[1], ! is_include);
if (r != URJ_STATUS_OK)
break;
}
}
return 1;
return r;
}
static void

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/bus.h>
@ -41,13 +42,18 @@ cmd_initbus_run (urj_chain_t *chain, char *params[])
int i;
if (urj_cmd_params (params) < 2)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (urj_tap_chain_active_part (chain) == NULL)
return 1;
return URJ_STATUS_FAIL;
for (i = 0; urj_bus_drivers[i] != NULL; i++)
{
@ -58,27 +64,29 @@ cmd_initbus_run (urj_chain_t *chain, char *params[])
params);
if (abus == NULL)
{
printf (_("bus alloc/attach failed!\n"));
return 1;
// @@@@ RFHH need to sanitize the bus module
urj_error_set (URJ_ERROR_BUS, _("bus alloc/attach failed"));
return URJ_STATUS_FAIL;
}
urj_bus_buses_add (abus);
// @@@@ RFHH need to bail out on error ?
if (URJ_BUS_INIT (abus) != URJ_STATUS_OK)
printf (_("bus initialization failed!\n"));
for (i = 0; i < urj_buses.len; i++)
if (urj_buses.buses[i] == urj_bus)
break;
// @@@@ RFHH no need to handle the case of bus not found ?
if (i != urj_buses.len - 1)
printf (_("Initialized bus %d, active bus %d\n"),
urj_buses.len - 1, i);
return 1;
return URJ_STATUS_OK;
}
}
printf (_("Unknown bus: %s\n"), params[1]);
return 1;
urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown bus: %s"), params[1]);
return URJ_STATUS_FAIL;
}
static void

@ -40,55 +40,58 @@ static int
cmd_instruction_run (urj_chain_t *chain, char *params[])
{
urj_part_t *part;
unsigned int len;
urj_part_instruction_t *i;
if (!urj_cmd_test_cable (chain))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
if (urj_cmd_params (params) == 2)
switch (urj_cmd_params (params))
{
case 2:
urj_part_set_instruction (part, params[1]);
if (part->active_instruction == NULL)
printf (_("%s: unknown instruction '%s'\n"), "instruction",
params[1]);
return 1;
}
if (urj_cmd_params (params) == 3)
{
unsigned int len;
{
urj_error_set (URJ_ERROR_INVALID,
_("%s: unknown instruction '%s'"),
"instruction", params[1]);
return URJ_STATUS_FAIL;
}
return URJ_STATUS_OK;
case 3:
if (strcasecmp (params[1], "length") != 0)
return -1;
if (urj_cmd_get_number (params[2], &len))
return -1;
if (urj_part_instruction_length_set (part, len) != URJ_STATUS_OK)
{
urj_error_reset();
urj_error_set (URJ_ERROR_SYNTAX,
"param 1 of 3 must be 'length', not '%s'",
params[1]);
return URJ_STATUS_FAIL;
}
return 1;
}
if (urj_cmd_params (params) == 4)
{
urj_part_instruction_t *i;
if (urj_cmd_get_number (params[2], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
return urj_part_instruction_length_set (part, len);
case 4:
i = urj_part_instruction_define (part, params[1], params[2], params[3]);
if (!i)
{
urj_error_reset();
return 1;
}
return URJ_STATUS_FAIL;
return URJ_STATUS_OK;
return 1;
default:
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be 2, 3, or 4, not %d",
params[0], urj_cmd_params (params));
break;
}
return -1;
return URJ_STATUS_FAIL;
}
static void

@ -28,6 +28,7 @@
#include <string.h>
#include <stdlib.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
@ -40,6 +41,14 @@ cmd_part_run (urj_chain_t *chain, char *params[])
{
unsigned int n;
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;
}
/* part alias U1 (3 params) */
if (urj_cmd_params (params) == 3)
{
@ -48,36 +57,39 @@ cmd_part_run (urj_chain_t *chain, char *params[])
urj_part_t *part = urj_tap_chain_active_part (chain);
if (part == NULL)
// retain error state
return 1;
return URJ_STATUS_FAIL;
part->alias = strdup (params[2]);
if (part->alias == NULL)
{
urj_error_set(URJ_ERROR_OUT_OF_MEMORY, "strdup(%s) fails",
params[2]);
return -1;
return URJ_STATUS_FAIL;
}
return 1;
return URJ_STATUS_OK;
}
}
if (urj_cmd_params (params) != 2)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be %d or %d, not %d",
params[0], 2, 3, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
if (!urj_cmd_test_cable (chain))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (!chain->parts)
{
printf (_("Run \"detect\" first.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, "Run \"detect\" first");
return URJ_STATUS_FAIL;
}
/* Search for alias too djf */
if (urj_cmd_get_number (params[1], &n))
if (urj_cmd_get_number (params[1], &n) != URJ_STATUS_OK)
{
/* Search all parts to check their aliases */
@ -91,25 +103,35 @@ cmd_part_run (urj_chain_t *chain, char *params[])
break;
}
if (i < chain->parts->len)
{
n = i;
}
else
return -1;
{
urj_error_set (URJ_ERROR_NOTFOUND, "part '%s'", params[1]);
return URJ_STATUS_FAIL;
}
}
if (n >= chain->parts->len)
{
printf (_("%s: invalid part number\n"), "part");
return 1;
urj_error_set (URJ_ERROR_INVALID,
_("%s: invalid part number %d, max %d"), "part",
n, chain->parts->len);
return URJ_STATUS_FAIL;
}
chain->active_part = n;
return 1;
return URJ_STATUS_OK;
}
static void
cmd_part_help (void)
{
// @@@@ RFHH this doesn't reflect input syntax:
// jtag> part PART
// jtag> part alias ALIAS
printf (_("Usage: %s PART\n"
"Change active part for current JTAG chain.\n"
"\n" "PART part number | alias\n"), "part");

@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdint.h>
#include <urjtag/error.h>
#include <urjtag/bus.h>
#include <urjtag/cmd.h>
@ -43,23 +44,28 @@ cmd_peek_run (urj_chain_t *chain, char *params[])
/* urj_bus_t *bus = part_get_active_bus(chain); */
if ((pars = urj_cmd_params (params)) < 2)
return -1;
{
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_bus)
{
printf (_("Error: Bus missing.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus missing"));
return URJ_STATUS_FAIL;
}
if (!urj_bus->driver)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus driver missing"));
return URJ_STATUS_FAIL;
}
do
{
if (urj_cmd_get_number (params[j], &adr))
return -1;
if (urj_cmd_get_number (params[j], &adr) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
URJ_BUS_PREPARE (urj_bus);
URJ_BUS_AREA (urj_bus, adr, &area);
@ -69,19 +75,22 @@ cmd_peek_run (urj_chain_t *chain, char *params[])
{
case 8:
val &= 0xff;
printf (_("URJ_BUS_READ(0x%08x) = 0x%02X (%i)\n"), adr, val, val);
urj_log (URJ_LOG_LEVEL_NORMAL,
_("URJ_BUS_READ(0x%08x) = 0x%02X (%i)\n"), adr, val, val);
break;
case 16:
val &= 0xffff;
printf (_("URJ_BUS_READ(0x%08x) = 0x%04X (%i)\n"), adr, val, val);
urj_log (URJ_LOG_LEVEL_NORMAL,
_("URJ_BUS_READ(0x%08x) = 0x%04X (%i)\n"), adr, val, val);
break;
default:
printf (_("URJ_BUS_READ(0x%08x) = 0x%08X (%i)\n"), adr, val, val);
urj_log (URJ_LOG_LEVEL_NORMAL,
_("URJ_BUS_READ(0x%08x) = 0x%08X (%i)\n"), adr, val, val);
}
}
while (++j != pars);
return 1;
return URJ_STATUS_OK;
}
static void
@ -112,32 +121,37 @@ cmd_poke_run (urj_chain_t *chain, char *params[])
int k = 1, pars = urj_cmd_params (params);
if (pars < 3 || !(pars & 1))
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be >= %d and odd-numbered, not %d",
params[0], 3, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
if (!urj_bus)
{
printf (_("Error: Bus missing.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus missing"));
return URJ_STATUS_FAIL;
}
if (!urj_bus->driver)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus driver missing"));
return URJ_STATUS_FAIL;
}
URJ_BUS_PREPARE (urj_bus);
while (k < pars)
{
if (urj_cmd_get_number (params[k], &adr)
if (urj_cmd_get_number (params[k], &adr) != URJ_STATUS_OK
|| urj_cmd_get_number (params[k + 1], &val))
return -1;
return URJ_STATUS_FAIL;
URJ_BUS_AREA (urj_bus, adr, &area);
URJ_BUS_WRITE (urj_bus, adr, val);
k += 2;
}
return 1;
return URJ_STATUS_OK;
}
static void

@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/pod.h>
@ -45,18 +46,30 @@ cmd_pod_run (urj_chain_t *chain, char *params[])
int val = 0;
if ((i = urj_cmd_params (params)) < 2)
return -1;
{
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))
return -1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
for (j = 1; j < i; j++)
{
char *eq = strrchr (params[j], '=');
if (!eq)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"parameter format should be 'SIGNAL=#', not '%s'",
params[j]);
return URJ_STATUS_FAIL;
}
urj_pod_sigsel_t it = URJ_POD_CS_NONE;
int n = strlen (params[j]);
if (n > 4 && (strncasecmp (params[j], "tck", 3) == 0))
it = URJ_POD_CS_TCK;
else if (n > 4 && (strncasecmp (params[j], "tms", 3) == 0))
@ -68,15 +81,21 @@ cmd_pod_run (urj_chain_t *chain, char *params[])
else if (n > 6 && (strncasecmp (params[j], "reset", 3) == 0))
it = URJ_POD_CS_RESET;
if (it == URJ_POD_CS_NONE)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX, "illegal signal name in '%s'",
params[j]);
return URJ_STATUS_FAIL;
}
mask |= it;
if (atoi (eq + 1) != 0)
val |= it;
}
urj_tap_chain_set_pod_signal (chain, mask, val);
if (urj_tap_chain_set_pod_signal (chain, mask, val) == -1)
return URJ_STATUS_FAIL;
return 1;
return URJ_STATUS_OK;
}
static void

@ -38,6 +38,7 @@ typedef char wchar_t;
# define wcslen(str) strlen(str)
#endif
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/bus.h>
@ -54,25 +55,31 @@ typedef char wchar_t;
static int
cmd_print_run (urj_chain_t *chain, char *params[])
{
char format[128];
#define FORMAT_LENGTH 128
char format[FORMAT_LENGTH];
#if HAVE_SWPRINTF
wchar_t wformat[128];
wchar_t wformat[FORMAT_LENGTH];
#endif /* HAVE_SWPRINTF */
wchar_t wheader[128];
char header[128];
wchar_t wheader[FORMAT_LENGTH];
char header[FORMAT_LENGTH];
int i;
int noheader = 0;
if (urj_cmd_params (params) > 2)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (!chain->parts)
{
printf (_("Run \"detect\" first.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, "Run \"detect\" first");
return URJ_STATUS_FAIL;
}
if (urj_cmd_params (params) == 2)
@ -83,7 +90,7 @@ cmd_print_run (urj_chain_t *chain, char *params[])
if (strcasecmp (params[1], "signals") == 0)
{
printf ("Signals:\n");
urj_log (URJ_LOG_LEVEL_NORMAL, "Signals:\n");
urj_part_t *part;
urj_part_signal_t *s;
part = chain->parts->parts[chain->active_part];
@ -91,22 +98,24 @@ cmd_print_run (urj_chain_t *chain, char *params[])
{
urj_part_salias_t *sa;
if (s->pin)
printf ("%s %s", s->name, s->pin);
urj_log (URJ_LOG_LEVEL_NORMAL, "%s %s", s->name, s->pin);
else
printf ("%s", s->name);
urj_log (URJ_LOG_LEVEL_NORMAL, "%s", s->name);
if (s->input)
printf ("\tinput=%s", s->input->name);
urj_log (URJ_LOG_LEVEL_NORMAL, "\tinput=%s",
s->input->name);
if (s->output)
printf ("\toutput=%s", s->output->name);
urj_log (URJ_LOG_LEVEL_NORMAL, "\toutput=%s",
s->output->name);
for (sa = part->saliases; sa != NULL; sa = sa->next)
{
if (s == sa->signal)
printf ("\tsalias=%s", sa->name);
urj_log (URJ_LOG_LEVEL_NORMAL, "\tsalias=%s", sa->name);
}
printf ("\n");
urj_log (URJ_LOG_LEVEL_NORMAL, "\n");
}
return (1);
return URJ_STATUS_OK;
}
if (strcasecmp (params[1], "instructions") == 0)
@ -114,79 +123,90 @@ cmd_print_run (urj_chain_t *chain, char *params[])
urj_part_t *part;
urj_part_instruction_t *inst;
snprintf (format, 128, _(" Active %%-%ds %%-%ds"),
snprintf (format, sizeof format, _(" Active %%-%ds %%-%ds\n"),
URJ_INSTRUCTION_MAXLEN_INSTRUCTION,
URJ_DATA_REGISTER_MAXLEN);
#if HAVE_SWPRINTF
if (mbstowcs (wformat, format, 128) == -1)
if (mbstowcs (wformat, format, sizeof format) == -1)
// @@@@ RFHH throw urj_error?
printf (_("(%d) String conversion failed!\n"), __LINE__);
swprintf (wheader, 128, wformat, _("Instruction"), _("Register"));
if (wcstombs (header, wheader, 128) == -1)
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, 128, format, _("Instruction"), _("Register"));
if (mbstowcs (wheader, header, 128) == -1)
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 */
puts (header);
urj_log (URJ_LOG_LEVEL_NORMAL, "%s", header);
for (i = 0; i < wcslen (wheader); i++)
putchar ('-');
putchar ('\n');
urj_log (URJ_LOG_LEVEL_NORMAL, "%c", '-');
urj_log (URJ_LOG_LEVEL_NORMAL, "%c", '\n');
snprintf (format, 128, _(" %%c %%-%ds %%-%ds\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)
{
printf (format,
inst == part->active_instruction
? 'X' : ' ', inst->name, inst->data_register->name);
urj_log (URJ_LOG_LEVEL_NORMAL, format,
(inst == part->active_instruction) ? 'X' : ' ',
inst->name, inst->data_register->name);
}
return (1);
return URJ_STATUS_OK;
}
}
if (noheader == 0)
{
snprintf (format, 128, _(" No. %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds"),
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, 128) == -1)
if (mbstowcs (wformat, format, sizeof format) == -1)
// @@@@ RFHH throw urj_error?
printf (_("(%d) String conversion failed!\n"), __LINE__);
swprintf (wheader, 128, wformat, _("Manufacturer"), _("Part"),
swprintf (wheader, sizeof format, wformat, _("Manufacturer"), _("Part"),
_("Stepping"), _("Instruction"), _("Register"));
if (wcstombs (header, wheader, 128) == -1)
if (wcstombs (header, wheader, sizeof format) == -1)
// @@@@ RFHH throw urj_error?
printf (_("(%d) String conversion failed!\n"), __LINE__);
#else /* HAVE_SWPRINTF */
snprintf (header, 128, format, _("Manufacturer"), _("Part"),
snprintf (header, sizeof format, format, _("Manufacturer"), _("Part"),
_("Stepping"), _("Instruction"), _("Register"));
if (mbstowcs (wheader, header, 128) == -1)
if (mbstowcs (wheader, header, sizeof format) == -1)
// @@@@ RFHH throw urj_error?
printf (_("(%d) String conversion failed!\n"), __LINE__);
#endif /* HAVE_SWPRINTF */
puts (header);
urj_log (URJ_LOG_LEVEL_NORMAL, "%s", header);
for (i = 0; i < wcslen (wheader); i++)
putchar ('-');
putchar ('\n');
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)
printf (_(" %3d %s "), chain->active_part,
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
printf (_(" %3d "), chain->active_part);
urj_log (URJ_LOG_LEVEL_NORMAL, _(" %3d "), chain->active_part);
urj_part_print (chain->parts->parts[chain->active_part]);
urj_part_print (URJ_LOG_LEVEL_NORMAL,
chain->parts->parts[chain->active_part]);
}
if (urj_bus != NULL)
{
@ -197,56 +217,57 @@ cmd_print_run (urj_chain_t *chain, char *params[])
for (i = 0; i < urj_buses.len; i++)
if (urj_buses.buses[i] == urj_bus)
break;
printf (_("\nActive bus:\n*%d: "), i);
URJ_BUS_PRINTINFO (urj_bus);
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)
{
if (URJ_BUS_AREA (urj_bus, a, &area) != URJ_STATUS_OK)
r = URJ_BUS_AREA (urj_bus, a, &area);
if (r != URJ_STATUS_OK)
{
printf (_
("Error in bus area discovery at 0x%08llX\n"),
(long long unsigned int) a);
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)
printf (_
("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit, (%s)\n"),
area.start,
(long long unsigned int) area.length,
area.width, _(area.description));
urj_log (URJ_LOG_LEVEL_NORMAL,
_("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit, (%s)\n"),
area.start,
(long long unsigned int) area.length,
area.width, _(area.description));
else
printf (_
("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit\n"),
area.start,
(long long unsigned int) area.length,
area.width);
urj_log (URJ_LOG_LEVEL_NORMAL,
_("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit\n"),
area.start,
(long long unsigned int) area.length,
area.width);
}
}
}
return 1;
return r;
}
if (strcasecmp (params[1], "chain") == 0)
{
urj_part_parts_print (chain->parts);
return 1;
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)
printf (_("*%d: "), i);
urj_log (URJ_LOG_LEVEL_NORMAL, _("*%d: "), i);
else
printf (_("%d: "), i);
URJ_BUS_PRINTINFO (urj_buses.buses[i]);
urj_log (URJ_LOG_LEVEL_NORMAL, _("%d: "), i);
URJ_BUS_PRINTINFO (URJ_LOG_LEVEL_NORMAL, urj_buses.buses[i]);
}
return 1;
return URJ_STATUS_OK;
}
static void

@ -26,6 +26,7 @@
#include <stdio.h>
#include <urjtag/error.h>
#include <urjtag/cmd.h>
#include "cmd.h"
@ -33,10 +34,15 @@
static int
cmd_quit_run (urj_chain_t *chain, char *params[])
{
if (params[1])
return -1;
return 0;
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;
}
return URJ_STATUS_MUST_QUIT;
}
static void

@ -26,7 +26,10 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <urjtag/error.h>
#include <urjtag/bus.h>
#include <urjtag/cmd.h>
@ -41,28 +44,35 @@ cmd_readmem_run (urj_chain_t *chain, char *params[])
FILE *f;
if (urj_cmd_params (params) != 4)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be %d, not %d",
params[0], 4, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
if (!urj_bus)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus missing"));
return URJ_STATUS_FAIL;
}
if (urj_cmd_get_number (params[1], &adr)
|| urj_cmd_get_number (params[2], &len))
return -1;
if (urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK
|| urj_cmd_get_number (params[2], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
f = fopen (params[3], "w");
if (!f)
{
printf (_("Unable to create file `%s'!\n"), params[3]);
return 1;
urj_error_set (URJ_ERROR_IO, _("Unable to create file `%s': %s"),
params[3], strerror(errno));
errno = 0;
return URJ_STATUS_FAIL;
}
urj_bus_readmem (urj_bus, f, adr, len);
fclose (f);
return 1;
return URJ_STATUS_OK;
}
static void

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/data_register.h>
@ -44,21 +45,24 @@ cmd_register_run (urj_chain_t *chain, char *params[])
unsigned int len;
if (urj_cmd_params (params) != 3)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
if (urj_cmd_get_number (params[2], &len))
return -1;
if (urj_cmd_get_number (params[2], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
(void) urj_part_data_register_define (part, params[1], len);
return 1;
return urj_part_data_register_define (part, params[1], len);
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/tap.h>
#include <urjtag/cmd.h>
@ -36,15 +37,18 @@
static int
cmd_reset_run (urj_chain_t *chain, char *params[])
{
if (urj_cmd_params (params) > 1)
return -1;
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
urj_tap_reset_bypass (chain);
return 1;
return urj_tap_reset_bypass (chain);
}
static void

@ -28,11 +28,12 @@
#include <stdlib.h>
#include <string.h>
#include "urjtag/chain.h"
#include "urjtag/part.h"
#include "urjtag/bssignal.h"
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/bssignal.h>
#include "urjtag/cmd.h"
#include <urjtag/cmd.h>
#include "cmd.h"
@ -44,39 +45,41 @@ cmd_salias_run (urj_chain_t *chain, char *params[])
urj_part_salias_t *sa;
if (urj_cmd_params (params) != 3)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
if (urj_part_find_signal (part, params[1]) != NULL)
{
printf (_("Signal '%s' already defined\n"), params[1]);
return 1;
return URJ_STATUS_FAIL;
}
s = urj_part_find_signal (part, params[2]);
if (s == NULL)
{
printf (_("Signal '%s' not found\n"), params[2]);
return 1;
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)
{
printf (_("out of memory\n"));
return 1;
}
return URJ_STATUS_FAIL;
sa->next = part->saliases;
part->saliases = sa;
return 1;
return URJ_STATUS_OK;
}
static void

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/tap_register.h>
@ -48,22 +49,27 @@ cmd_scan_run (urj_chain_t *chain, char *params[])
int i;
if ((i = urj_cmd_params (params)) < 1)
return -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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
/* search for Boundary Scan Register */
bsr = urj_part_find_data_register (part, "BSR");
if (!bsr)
{
printf (_("%s(%s:%d) Boundary Scan Register (BSR) not found\n"),
__FUNCTION__, __FILE__, __LINE__);
return 1;
urj_error_set (URJ_ERROR_NOTFOUND,
_("Boundary Scan Register (BSR) not found"));
return URJ_STATUS_FAIL;
}
if (urj_part_find_instruction (part, "SAMPLE"))
@ -76,54 +82,46 @@ cmd_scan_run (urj_chain_t *chain, char *params[])
}
else
{
printf (_("%s(%s:%d) Part can't SAMPLE\n"), __FUNCTION__, __FILE__,
__LINE__);
return 1;
urj_error_set (URJ_ERROR_UNSUPPORTED,_("Part can't SAMPLE"));
return URJ_STATUS_FAIL;
}
/* @@@@ RFHH check result */
urj_tap_chain_shift_instructions (chain);
obsr = urj_tap_register_alloc (bsr->out->len);
if (!obsr)
{
printf (_("Out of memory\n"));
return 1;
}
return URJ_STATUS_FAIL;
{
urj_part_signal_t *s;
urj_tap_register_init (obsr, urj_tap_register_get_string (bsr->out)); // copy
urj_tap_register_init (obsr, urj_tap_register_get_string (bsr->out)); // copy
/* @@@@ RFHH check result */
urj_tap_chain_shift_data_registers (chain, 1);
/* @@@@ RFHH check result */
urj_tap_chain_shift_data_registers (chain, 1);
for (s = part->signals; s; s = s->next)
urj_part_signal_t *s;
for (s = part->signals; s; s = s->next)
{
if (s->input != NULL)
{
if (s->input != NULL)
int old = obsr->data[s->input->bit];
int new = bsr->out->data[s->input->bit];
if (old != new)
{
int old = obsr->data[s->input->bit];
int new = bsr->out->data[s->input->bit];
if (old != new)
urj_part_salias_t *a;
urj_log (URJ_LOG_LEVEL_NORMAL, "%s", s->name);
for (a = part->saliases; a; a = a->next)
{
urj_part_salias_t *a;
printf ("%s", s->name);
for (a = part->saliases; a; a = a->next)
{
if (a->signal == s)
printf (",%s", a->name);
}
printf (_(": %d > %d\n"), old, new);
if (a->signal == s)
urj_log (URJ_LOG_LEVEL_NORMAL, ",%s", a->name);
}
urj_log (URJ_LOG_LEVEL_NORMAL, _(": %d > %d\n"), old, new);
}
}
}
urj_tap_register_free (obsr);
return 1;
return URJ_STATUS_OK;
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/part.h>
#include <urjtag/chain.h>
#include <urjtag/bssignal.h>
@ -44,42 +45,62 @@ cmd_set_run (urj_chain_t *chain, char *params[])
urj_part_t *part;
if (urj_cmd_params (params) < 4 || urj_cmd_params (params) > 5)
return -1;
{
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)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
/* direction */
if (strcasecmp (params[3], "in") != 0
&& strcasecmp (params[3], "out") != 0)
return -1;
{
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))
return -1;
if (urj_cmd_get_number (params[4], &data) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
if (data > 1)
return -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)
{
printf (_("signal '%s' not found\n"), params[2]);
return 1;
urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"),
params[2]);
return URJ_STATUS_FAIL;
}
urj_part_set_signal (part, s, dir, data);
return 1;
return urj_part_set_signal (part, s, dir, data);
}
static void

@ -31,6 +31,7 @@
#include <string.h>
#include <stdlib.h>
#include <urjtag/error.h>
#include <urjtag/cmd.h>
#include "cmd.h"
@ -42,7 +43,12 @@ cmd_shell_run (urj_chain_t *chain, char *params[])
char *shell_cmd;
if ((n = urj_cmd_params (params)) == 1)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be >= %d, not %d",
params[0], 2, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
/* I must apologize to everyone who knows what they are doing for
* the following. If you can pass a shell argument past strtok the
@ -59,8 +65,9 @@ cmd_shell_run (urj_chain_t *chain, char *params[])
shell_cmd = malloc (len);
if (shell_cmd == NULL)
{
printf (_("Out of memory\n"));
return -1;
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails",
(size_t) len);
return URJ_STATUS_FAIL;
}
strcpy (shell_cmd, params[1]);
@ -69,12 +76,12 @@ cmd_shell_run (urj_chain_t *chain, char *params[])
strcat (shell_cmd, " ");
strcat (shell_cmd, params[i]);
}
printf ("Executing '%s'\n", shell_cmd);
urj_log (URJ_LOG_LEVEL_NORMAL, "Executing '%s'\n", shell_cmd);
system (shell_cmd);
free (shell_cmd);
return 1;
return URJ_STATUS_OK;
}
static void

@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/cmd.h>
@ -37,25 +38,33 @@ static int
cmd_shift_run (urj_chain_t *chain, char *params[])
{
if (urj_cmd_params (params) != 2)
return -1;
{
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))
return 1;
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 1;
return URJ_STATUS_OK;
}
if (strcasecmp (params[1], "dr") == 0)
{
/* @@@@ RFHH check result */
urj_tap_chain_shift_data_registers (chain, 1);
return 1;
return URJ_STATUS_OK;
}
return -1;
urj_error_set (URJ_ERROR_SYNTAX,
"%s parameter 2 must be 'ir' or 'dr', not '%s'",
params[0], params[1]);
return URJ_STATUS_FAIL;
}
static void

@ -45,30 +45,34 @@ cmd_signal_run (urj_chain_t *chain, char *params[])
int i;
if ((i = urj_cmd_params (params)) < 2)
return -1;
{
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))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
if ((s = urj_part_find_signal (part, params[1])) != NULL)
{
if (i == 3)
{
printf ("Defining pin for signal %s\n", s->name);
urj_log (URJ_LOG_LEVEL_NORMAL, "Defining pin for signal %s\n",
s->name);
if (urj_part_signal_redefine_pin(chain, s,
params[2]) != URJ_STATUS_OK)
urj_error_reset();
return 1;
return urj_part_signal_redefine_pin(chain, s, params[2]);
}
else
{
printf (_("Signal '%s' already defined\n"), params[1]);
return 1;
urj_error_set (URJ_ERROR_ALREADY, _("Signal '%s' already defined"),
params[1]);
return URJ_STATUS_FAIL;
}
}
@ -81,11 +85,10 @@ cmd_signal_run (urj_chain_t *chain, char *params[])
s = urj_part_signal_define(chain, params[1]);
}
if (s == NULL) {
urj_error_reset();
return 1;
return URJ_STATUS_FAIL;
}
return 1;
return URJ_STATUS_OK;
}
static void

@ -29,7 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <urjtag/error.h>
#include <urjtag/log.h>
#include <urjtag/svf.h>
@ -41,43 +43,48 @@ static int
cmd_svf_run (urj_chain_t *chain, char *params[])
{
FILE *SVF_FILE;
int num_params, i, result = -1;
int num_params, i;
int stop = 0;
int print_progress = 0;
uint32_t ref_freq = 0;
urj_log_level_t old_log_level = urj_log_state.level;
int result;
num_params = urj_cmd_params (params);
if (num_params > 1)
if (num_params < 2)
{
for (i = 2; i < num_params; i++)
{
if (strcasecmp (params[i], "stop") == 0)
stop = 1;
else if (strcasecmp (params[i], "progress") == 0)
print_progress = 1;
else if (strncasecmp (params[i], "ref_freq=", 9) == 0)
ref_freq = strtol (params[i] + 9, NULL, 10);
else
return -1;
}
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be >= %d, not %d",
params[0], 2, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
for (i = 2; i < num_params; i++)
{
if (strcasecmp (params[i], "stop") == 0)
stop = 1;
else if (strcasecmp (params[i], "progress") == 0)
print_progress = 1;
else if (strncasecmp (params[i], "ref_freq=", 9) == 0)
ref_freq = strtol (params[i] + 9, NULL, 10);
if (print_progress)
urj_log_state.level = URJ_LOG_LEVEL_DETAIL;
if ((SVF_FILE = fopen (params[1], "r")) != NULL)
{
urj_svf_run (chain, SVF_FILE, stop, ref_freq);
result = 1;
if (urj_svf_run (chain, SVF_FILE, stop, ref_freq))
result = URJ_STATUS_OK;
else
result = URJ_STATUS_FAIL;
fclose (SVF_FILE);
}
else
{
printf (_("%s: cannot open file '%s' for reading\n"), "svf",
params[1]);
urj_error_set (URJ_ERROR_SYNTAX, "%s: unknown command '%s'",
params[0], params[i]);
result = URJ_STATUS_FAIL;
}
}
urj_log_state.level = old_log_level;

@ -29,6 +29,7 @@
#include <string.h>
//#include <stdlib.h>
#include <urjtag/error.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/bssignal.h>
@ -46,41 +47,54 @@ cmd_test_run (urj_chain_t *chain, char *params[])
urj_part_t *part;
if (urj_cmd_params (params) != 4)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be %d, not %d",
params[0], 4, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
if (strcasecmp (params[1], "signal") != 0)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: parameter[%d] should be '%s', not '%s'",
params[0], 1, "signal", params[1]);
return URJ_STATUS_FAIL;
}
if (!urj_cmd_test_cable (chain))
return 1;
if (urj_cmd_test_cable (chain) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
part = urj_tap_chain_active_part (chain);
if (part == NULL)
return 1;
return URJ_STATUS_FAIL;
s = urj_part_find_signal (part, params[2]);
if (!s)
{
printf (_("signal '%s' not found\n"), params[2]);
return 1;
urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"),
params[2]);
return URJ_STATUS_FAIL;
}
/* values 0,1,X since X is not a number, the following failure exits clean
* and doesnt test anything, as it should.
*/
if (urj_cmd_get_number (params[3], &i))
return 1;
if (urj_cmd_get_number (params[3], &i) != URJ_STATUS_OK)
return URJ_STATUS_OK;
data = urj_part_get_signal (part, s);
if (data != -1)
if (data == -1)
return URJ_STATUS_FAIL;
if (data != i)
{
if (data != i)
{
printf (_("<FAIL>%s = %d\n"), params[2], data);
return -99;
}
urj_error_set (URJ_ERROR_ILLEGAL_STATE,
_("<FAIL>%s = %d"), params[2], data);
return URJ_STATUS_FAIL;
}
return 1;
return URJ_STATUS_OK;
}
static void

@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/error.h>
#include <urjtag/cmd.h>
#include "cmd.h"
@ -39,14 +40,19 @@ cmd_usleep_run (urj_chain_t *chain, char *params[])
unsigned int usecs;
if (urj_cmd_params (params) != 2)
return -1;
{
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_get_number (params[1], &usecs))
return -1;
if (urj_cmd_get_number (params[1], &usecs) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
usleep (usecs);
return 1;
return URJ_STATUS_OK;
}
static void

@ -24,7 +24,10 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <urjtag/error.h>
#include <urjtag/bus.h>
#include <urjtag/cmd.h>
@ -39,28 +42,35 @@ cmd_writemem_run (urj_chain_t *chain, char *params[])
FILE *f;
if (urj_cmd_params (params) != 4)
return -1;
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be %d, not %d",
params[0], 4, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
if (!urj_bus)
{
printf (_("Error: Bus driver missing.\n"));
return 1;
urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus missing"));
return URJ_STATUS_FAIL;
}
if (urj_cmd_get_number (params[1], &adr)
|| urj_cmd_get_number (params[2], &len))
return -1;
if (urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK
|| urj_cmd_get_number (params[2], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
f = fopen (params[3], "r");
if (!f)
{
printf (_("Unable to open file `%s'!\n"), params[3]);
return 1;
urj_error_set (URJ_ERROR_IO, _("Unable to open file `%s': %s"),
params[3], strerror(errno));
errno = 0;
return URJ_STATUS_FAIL;
}
urj_bus_writemem (urj_bus, f, adr, len);
fclose (f);
return 1;
return URJ_STATUS_OK;
}
static void

@ -59,17 +59,14 @@ urj_parse_line (urj_chain_t *chain, char *line)
}
l = strlen (line);
if (l == 0)
{
urj_error_set (URJ_ERROR_INVALID, "zero-length line");
return 1;
}
return URJ_STATUS_OK;
/* allocate as many chars as in the input line; this will be enough in all cases */
sline = malloc (l + 1);
if (sline == NULL)
{
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%d) fails", l + 1);
return 1;
return URJ_STATUS_FAIL;
}
/* count and copy the tokens */
@ -99,8 +96,7 @@ urj_parse_line (urj_chain_t *chain, char *line)
if (tcnt == 0)
{
free (sline);
urj_error_set (URJ_ERROR_INVALID, "empty line");
return 1;
return URJ_STATUS_OK;
}
/* allocate the token pointer table */
@ -109,7 +105,7 @@ urj_parse_line (urj_chain_t *chain, char *line)
{
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails",
(tcnt + 1) * sizeof (char *));
return 1;
return URJ_STATUS_FAIL;
}
/* find the starting points for the tokens */
@ -132,7 +128,7 @@ urj_parse_line (urj_chain_t *chain, char *line)
int
urj_parse_stream (urj_chain_t *chain, FILE *f)
urj_parse_stream (urj_log_level_t ll, urj_chain_t *chain, FILE *f)
{
char inputline[MAXINPUTLINE + 1];
int go = 1, i, c, lnr, clip, found_comment;
@ -164,15 +160,20 @@ urj_parse_stream (urj_chain_t *chain, FILE *f)
urj_warning ("line %d exceeds %zd characters, clipped\n", lnr,
sizeof (inputline) - 1);
go = urj_parse_line (chain, inputline);
if (go == URJ_STATUS_FAIL)
{
urj_log (ll, "Error: %s; command '%s'\n", urj_error_describe(), inputline);
urj_error_reset ();
}
urj_tap_chain_flush (chain);
}
while (go && c != EOF);
while (go != URJ_STATUS_MUST_QUIT && c != EOF);
return go;
}
int
urj_parse_file (urj_chain_t *chain, const char *filename)
urj_parse_file (urj_log_level_t ll, urj_chain_t *chain, const char *filename)
{
FILE *f;
int go;
@ -180,13 +181,13 @@ urj_parse_file (urj_chain_t *chain, const char *filename)
f = fopen (filename, "r");
if (!f)
{
urj_error_set(URJ_ERROR_IO, "Cannot open file '%s' to parse: %s",
filename, strerror(errno));
urj_error_set (URJ_ERROR_IO, "Cannot open file '%s' to parse: %s",
filename, strerror(errno));
errno = 0;
return -1;
return URJ_STATUS_FAIL;
}
go = urj_parse_stream (chain, f);
go = urj_parse_stream (ll, chain, f);
fclose (f);
urj_log (URJ_LOG_LEVEL_DEBUG, "File Closed go=%d\n", go);
@ -223,7 +224,6 @@ urj_parse_include (urj_chain_t *chain, const char *filename, int ignore_path)
path = malloc (len = strlen (jtag_data_dir) + strlen (filename) + 2);
if (path == NULL)
{
printf (_("Out of memory\n"));
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", len);
return URJ_STATUS_FAIL;
}
@ -236,6 +236,7 @@ urj_parse_include (urj_chain_t *chain, const char *filename, int ignore_path)
/* perform a test read to check for BSDL syntax */
if (urj_bsdl_read_file (chain, filename, URJ_BSDL_MODE_INCLUDE1, NULL) >= 0)
{
// @@@@ RFHH ToDo: let urj_bsdl_read_file also return URJ_STATUS_...
/* it seems to be a proper BSDL file, so re-read and execute */
if (urj_bsdl_read_file (chain, filename, URJ_BSDL_MODE_INCLUDE2,
NULL) < 0)
@ -245,8 +246,7 @@ urj_parse_include (urj_chain_t *chain, const char *filename, int ignore_path)
else
#endif
{
if (urj_parse_file (chain, filename) == -1)
r = URJ_STATUS_FAIL;
r = urj_parse_file (URJ_LOG_LEVEL_NORMAL, chain, filename);
}
free (path);

@ -78,22 +78,16 @@ urj_log (urj_log_level_t level, const char *fmt, ...)
return r;
}
void
urj_error_reset (void)
urj_error_t
urj_error_get (void)
{
urj_error_state.errnum = URJ_ERROR_OK;
return urj_error_state.errnum;
}
const char *
urj_error_describe (void)
void
urj_error_reset (void)
{
static char msg[URJ_ERROR_MSG_LEN + 1024 + 256 + 20];
snprintf (msg, sizeof msg, "%s:%d %s(): %s", urj_error_state.file,
urj_error_state.line, urj_error_state.function,
urj_error_state.msg);
return msg;
urj_error_state.errnum = URJ_ERROR_OK;
}
const char *
@ -105,7 +99,6 @@ urj_error_string (urj_error_t err)
case URJ_ERROR_ALREADY: return "already defined";
case URJ_ERROR_OUT_OF_MEMORY: return "out of memory";
case URJ_ERROR_NO_CHAIN: return "no chain";
case URJ_ERROR_NO_ACTIVE_PART: return "no active part";
case URJ_ERROR_NO_ACTIVE_INSTRUCTION: return "no active instruction";
case URJ_ERROR_NO_DATA_REGISTER: return "no data register";
case URJ_ERROR_INVALID: return "invalid parameter";
@ -119,6 +112,8 @@ urj_error_string (urj_error_t err)
case URJ_ERROR_IO: return "I/O error from OS";
case URJ_ERROR_BUS: return "bus";
case URJ_ERROR_FLASH: return "flash";
case URJ_ERROR_FLASH_DETECT: return "flash detect";
case URJ_ERROR_FLASH_PROGRAM: return "flash program";
@ -128,3 +123,16 @@ urj_error_string (urj_error_t err)
return "UNDEFINED ERROR";
}
const char *
urj_error_describe (void)
{
static char msg[URJ_ERROR_MSG_LEN + 1024 + 256 + 20];
snprintf (msg, sizeof msg, "%s:%d %s() %s: %s",
urj_error_state.file, urj_error_state.line,
urj_error_state.function,
urj_error_string (urj_error_state.errnum), urj_error_state.msg);
return msg;
}

@ -255,7 +255,7 @@ urj_part_set_signal (urj_part_t *p, urj_part_signal_t *s, int out, int val)
}
int
urj_part_get_signal (urj_part_t *p, urj_part_signal_t *s)
urj_part_get_signal (urj_part_t *p, const urj_part_signal_t *s)
{
urj_data_register_t *bsr;
@ -285,7 +285,7 @@ urj_part_get_signal (urj_part_t *p, urj_part_signal_t *s)
}
int
urj_part_print (urj_part_t *p)
urj_part_print (urj_log_level_t ll, urj_part_t *p)
{
const char *instruction = NULL;
const char *dr = NULL;
@ -312,8 +312,8 @@ urj_part_print (urj_part_t *p)
instruction = _("(none)");
if (dr == NULL)
dr = _("(none)");
urj_log (URJ_LOG_LEVEL_NORMAL, format, p->manufacturer, p->part,
p->stepping, instruction, dr);
urj_log (ll, format, p->manufacturer, p->part, p->stepping, instruction,
dr);
return URJ_STATUS_OK;
}
@ -452,7 +452,7 @@ urj_part_parts_set_instruction (urj_parts_t *ps, const char *iname)
}
int
urj_part_parts_print (urj_parts_t *ps)
urj_part_parts_print (urj_log_level_t ll, urj_parts_t *ps)
{
int i;
@ -469,8 +469,8 @@ urj_part_parts_print (urj_parts_t *ps)
if (!p)
continue;
urj_log (URJ_LOG_LEVEL_NORMAL, _(" %3d "), i);
urj_part_print (p);
urj_log (ll, _(" %3d "), i);
urj_part_print (ll, p);
}
return URJ_STATUS_OK;

@ -1156,11 +1156,13 @@ urj_svf_run (urj_chain_t *chain, FILE *SVF_FILE, int stop_on_mismatch,
}
if (chain->parts == NULL)
{
urj_error_set (URJ_ERROR_NO_ACTIVE_PART,
urj_error_set (URJ_ERROR_NOTFOUND,
_("%s: chain without any parts\n"), "svf");
return 0;
}
priv.part = chain->parts->parts[chain->active_part];
// @@@@ RFHH is priv.part allowed to be NULL? if not, we should use
// urj_tap_chain_active_part()
/* setup register SDR if not already existing */
if (!(priv.dr = urj_part_find_data_register (priv.part, "SDR")))

@ -318,14 +318,14 @@ urj_tap_chain_active_part (urj_chain_t *chain)
if (!chain->parts)
{
urj_error_set (URJ_ERROR_NO_ACTIVE_PART,
_("Run \"detect\" first.\n"));
urj_error_set (URJ_ERROR_NOTFOUND, _("Run \"detect\" first"));
return NULL;
}
if (chain->active_part >= chain->parts->len)
{
urj_error_set (URJ_ERROR_NO_ACTIVE_PART,
_("%s: no active part\n"), "signal");
urj_error_set (URJ_ERROR_ILLEGAL_STATE,
_("active part no %d exceeds chain length %d"),
chain->active_part, chain->parts->len);
return NULL;
}

@ -505,7 +505,7 @@ urj_tap_detect (urj_chain_t *chain)
urj_bus_buses_free ();
urj_part_parts_free (chain->parts);
chain->parts = NULL;
if (urj_tap_detect_parts (chain, urj_get_data_dir ()) != URJ_STATUS_OK)
if (urj_tap_detect_parts (chain, urj_get_data_dir ()) == -1)
// retain error state
return URJ_STATUS_FAIL;
if (!chain->parts)

Loading…
Cancel
Save