diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 508d6840..6be57062 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,13 @@ +2009-05-12 Rutger Hofman + + * 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 * src/bus/ejtag_dma.c (ejtag_dma_bus_init): invert abort condition for break diff --git a/urjtag/include/urjtag/bsdl.h b/urjtag/include/urjtag/bsdl.h index 289b71fa..101e2577 100644 --- a/urjtag/include/urjtag/bsdl.h +++ b/urjtag/include/urjtag/bsdl.h @@ -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 */ diff --git a/urjtag/include/urjtag/bus_driver.h b/urjtag/include/urjtag/bus_driver.h index 242ef58e..acb6e647 100644 --- a/urjtag/include/urjtag/bus_driver.h +++ b/urjtag/include/urjtag/bus_driver.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) diff --git a/urjtag/include/urjtag/cable.h b/urjtag/include/urjtag/cable.h index d3344015..6dd0830e 100644 --- a/urjtag/include/urjtag/cable.h +++ b/urjtag/include/urjtag/cable.h @@ -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); diff --git a/urjtag/include/urjtag/chain.h b/urjtag/include/urjtag/chain.h index d7658454..9ad81730 100644 --- a/urjtag/include/urjtag/chain.h +++ b/urjtag/include/urjtag/chain.h @@ -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 diff --git a/urjtag/include/urjtag/cmd.h b/urjtag/include/urjtag/cmd.h index a81d36ca..7b1c3c36 100644 --- a/urjtag/include/urjtag/cmd.h +++ b/urjtag/include/urjtag/cmd.h @@ -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 text. 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 */ diff --git a/urjtag/include/urjtag/error.h b/urjtag/include/urjtag/error.h index f9bcee45..8b0b8b5b 100644 --- a/urjtag/include/urjtag/error.h +++ b/urjtag/include/urjtag/error.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. */ diff --git a/urjtag/include/urjtag/flash.h b/urjtag/include/urjtag/flash.h index 663727a1..d50a06b9 100644 --- a/urjtag/include/urjtag/flash.h +++ b/urjtag/include/urjtag/flash.h @@ -38,7 +38,6 @@ #include #include "types.h" -#include "log.h" typedef struct urj_flash_cfi_array urj_flash_cfi_array_t; diff --git a/urjtag/include/urjtag/log.h b/urjtag/include/urjtag/log.h index 9e47cdd1..5cd2d55c 100644 --- a/urjtag/include/urjtag/log.h +++ b/urjtag/include/urjtag/log.h @@ -25,19 +25,7 @@ #include -/** - * 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. diff --git a/urjtag/include/urjtag/parport.h b/urjtag/include/urjtag/parport.h index c9cd05ad..18e019c7 100644 --- a/urjtag/include/urjtag/parport.h +++ b/urjtag/include/urjtag/parport.h @@ -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); diff --git a/urjtag/include/urjtag/parse.h b/urjtag/include/urjtag/parse.h index c2b4abb3..7acb51c3 100644 --- a/urjtag/include/urjtag/parse.h +++ b/urjtag/include/urjtag/parse.h @@ -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 diff --git a/urjtag/include/urjtag/part.h b/urjtag/include/urjtag/part.h index 353b87b8..bb4aa328 100644 --- a/urjtag/include/urjtag/part.h +++ b/urjtag/include/urjtag/part.h @@ -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 */ diff --git a/urjtag/include/urjtag/types.h b/urjtag/include/urjtag/types.h index 425c2ba2..cd177fde 100644 --- a/urjtag/include/urjtag/types.h +++ b/urjtag/include/urjtag/types.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 */ diff --git a/urjtag/src/apps/jtag/jtag.c b/urjtag/src/apps/jtag/jtag.c index 7d78ad9c..f9f0073f 100644 --- a/urjtag/src/apps/jtag/jtag.c +++ b/urjtag/src/apps/jtag/jtag.c @@ -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 diff --git a/urjtag/src/bus/au1500.c b/urjtag/src/bus/au1500.c index 9b56dbe7..f6678c66 100644 --- a/urjtag/src/bus/au1500.c +++ b/urjtag/src/bus/au1500.c @@ -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); } diff --git a/urjtag/src/bus/avr32.c b/urjtag/src/bus/avr32.c index 8142e6d8..53024085 100644 --- a/urjtag/src/bus/avr32.c +++ b/urjtag/src/bus/avr32.c @@ -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); } /** diff --git a/urjtag/src/bus/bcm1250.c b/urjtag/src/bus/bcm1250.c index a101d0e7..a4a7d7e4 100644 --- a/urjtag/src/bus/bcm1250.c +++ b/urjtag/src/bus/bcm1250.c @@ -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); } diff --git a/urjtag/src/bus/bf533_ezkit.c b/urjtag/src/bus/bf533_ezkit.c index e2f59a6e..3cf31c6c 100644 --- a/urjtag/src/bus/bf533_ezkit.c +++ b/urjtag/src/bus/bf533_ezkit.c @@ -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); } diff --git a/urjtag/src/bus/bf533_stamp.c b/urjtag/src/bus/bf533_stamp.c index 13b663f1..fab57c48 100644 --- a/urjtag/src/bus/bf533_stamp.c +++ b/urjtag/src/bus/bf533_stamp.c @@ -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); } diff --git a/urjtag/src/bus/bf537_stamp.c b/urjtag/src/bus/bf537_stamp.c index 80007f12..3ec603f5 100644 --- a/urjtag/src/bus/bf537_stamp.c +++ b/urjtag/src/bus/bf537_stamp.c @@ -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 \ diff --git a/urjtag/src/bus/bf548_ezkit.c b/urjtag/src/bus/bf548_ezkit.c index fb3d2570..8e4c3540 100644 --- a/urjtag/src/bus/bf548_ezkit.c +++ b/urjtag/src/bus/bf548_ezkit.c @@ -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); } diff --git a/urjtag/src/bus/bf561_ezkit.c b/urjtag/src/bus/bf561_ezkit.c index 803bc24f..e80b1c59 100644 --- a/urjtag/src/bus/bf561_ezkit.c +++ b/urjtag/src/bus/bf561_ezkit.c @@ -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); } diff --git a/urjtag/src/bus/bscoach.c b/urjtag/src/bus/bscoach.c index 0e49b6cc..0dbd18c4 100644 --- a/urjtag/src/bus/bscoach.c +++ b/urjtag/src/bus/bscoach.c @@ -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); } diff --git a/urjtag/src/bus/ejtag.c b/urjtag/src/bus/ejtag.c index 6741cc4c..cc260f22 100644 --- a/urjtag/src/bus/ejtag.c +++ b/urjtag/src/bus/ejtag.c @@ -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); } diff --git a/urjtag/src/bus/ejtag_dma.c b/urjtag/src/bus/ejtag_dma.c index 38de382a..6dc11355 100644 --- a/urjtag/src/bus/ejtag_dma.c +++ b/urjtag/src/bus/ejtag_dma.c @@ -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); } /** diff --git a/urjtag/src/bus/fjmem.c b/urjtag/src/bus/fjmem.c index 53e6ccb8..dca5bdda 100644 --- a/urjtag/src/bus/fjmem.c +++ b/urjtag/src/bus/fjmem.c @@ -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); } diff --git a/urjtag/src/bus/h7202.c b/urjtag/src/bus/h7202.c index 37ccc9a5..95606d4a 100644 --- a/urjtag/src/bus/h7202.c +++ b/urjtag/src/bus/h7202.c @@ -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); } /** diff --git a/urjtag/src/bus/ixp425.c b/urjtag/src/bus/ixp425.c index e9287474..957f98c8 100644 --- a/urjtag/src/bus/ixp425.c +++ b/urjtag/src/bus/ixp425.c @@ -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); } diff --git a/urjtag/src/bus/jopcyc.c b/urjtag/src/bus/jopcyc.c index e64f653f..f4302ca7 100644 --- a/urjtag/src/bus/jopcyc.c +++ b/urjtag/src/bus/jopcyc.c @@ -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); } diff --git a/urjtag/src/bus/lh7a400.c b/urjtag/src/bus/lh7a400.c index 56c6e0ae..17f7fa68 100644 --- a/urjtag/src/bus/lh7a400.c +++ b/urjtag/src/bus/lh7a400.c @@ -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); } diff --git a/urjtag/src/bus/mpc5200.c b/urjtag/src/bus/mpc5200.c index 8424aeb7..bb804460 100644 --- a/urjtag/src/bus/mpc5200.c +++ b/urjtag/src/bus/mpc5200.c @@ -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); } diff --git a/urjtag/src/bus/mpc824x.c b/urjtag/src/bus/mpc824x.c index 6da9d350..0994d8fe 100644 --- a/urjtag/src/bus/mpc824x.c +++ b/urjtag/src/bus/mpc824x.c @@ -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); } diff --git a/urjtag/src/bus/ppc405ep.c b/urjtag/src/bus/ppc405ep.c index 88100a3a..448a3651 100644 --- a/urjtag/src/bus/ppc405ep.c +++ b/urjtag/src/bus/ppc405ep.c @@ -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); } diff --git a/urjtag/src/bus/ppc440gx_ebc8.c b/urjtag/src/bus/ppc440gx_ebc8.c index dabd6f5d..61dcb8e4 100644 --- a/urjtag/src/bus/ppc440gx_ebc8.c +++ b/urjtag/src/bus/ppc440gx_ebc8.c @@ -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); } diff --git a/urjtag/src/bus/prototype.c b/urjtag/src/bus/prototype.c index 6c2f624e..c843ac1d 100644 --- a/urjtag/src/bus/prototype.c +++ b/urjtag/src/bus/prototype.c @@ -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); } diff --git a/urjtag/src/bus/pxa2x0.c b/urjtag/src/bus/pxa2x0.c index 014fb8e3..442985c7 100644 --- a/urjtag/src/bus/pxa2x0.c +++ b/urjtag/src/bus/pxa2x0.c @@ -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__); diff --git a/urjtag/src/bus/s3c4510x.c b/urjtag/src/bus/s3c4510x.c index 4f88dfae..76bb7c92 100644 --- a/urjtag/src/bus/s3c4510x.c +++ b/urjtag/src/bus/s3c4510x.c @@ -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) { diff --git a/urjtag/src/bus/sa1110.c b/urjtag/src/bus/sa1110.c index 6dac6217..7d79b156 100644 --- a/urjtag/src/bus/sa1110.c +++ b/urjtag/src/bus/sa1110.c @@ -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); } diff --git a/urjtag/src/bus/sh7727.c b/urjtag/src/bus/sh7727.c index 57d3b330..3df4bc4b 100644 --- a/urjtag/src/bus/sh7727.c +++ b/urjtag/src/bus/sh7727.c @@ -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); } diff --git a/urjtag/src/bus/sh7750r.c b/urjtag/src/bus/sh7750r.c index 813b596d..fea0d967 100644 --- a/urjtag/src/bus/sh7750r.c +++ b/urjtag/src/bus/sh7750r.c @@ -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); } diff --git a/urjtag/src/bus/sh7751r.c b/urjtag/src/bus/sh7751r.c index 7a97f576..a89244ff 100644 --- a/urjtag/src/bus/sh7751r.c +++ b/urjtag/src/bus/sh7751r.c @@ -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); } diff --git a/urjtag/src/bus/sharc21065l.c b/urjtag/src/bus/sharc21065l.c index 02ef6c92..349c3704 100644 --- a/urjtag/src/bus/sharc21065l.c +++ b/urjtag/src/bus/sharc21065l.c @@ -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); } diff --git a/urjtag/src/bus/slsup3.c b/urjtag/src/bus/slsup3.c index edb6cd61..a749b050 100644 --- a/urjtag/src/bus/slsup3.c +++ b/urjtag/src/bus/slsup3.c @@ -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); } /** diff --git a/urjtag/src/bus/tx4925.c b/urjtag/src/bus/tx4925.c index 650da41e..7c9a91b7 100644 --- a/urjtag/src/bus/tx4925.c +++ b/urjtag/src/bus/tx4925.c @@ -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); } diff --git a/urjtag/src/bus/zefant-xs3.c b/urjtag/src/bus/zefant-xs3.c index fa9b9ceb..5d2d1849 100644 --- a/urjtag/src/bus/zefant-xs3.c +++ b/urjtag/src/bus/zefant-xs3.c @@ -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); } diff --git a/urjtag/src/cmd/cmd.h b/urjtag/src/cmd/cmd.h index a6968a99..bce74430 100644 --- a/urjtag/src/cmd/cmd.h +++ b/urjtag/src/cmd/cmd.h @@ -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 */ diff --git a/urjtag/src/cmd/cmd_addpart.c b/urjtag/src/cmd/cmd_addpart.c index 26ad8499..bb8669c6 100644 --- a/urjtag/src/cmd/cmd_addpart.c +++ b/urjtag/src/cmd/cmd_addpart.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/urjtag/src/cmd/cmd_bit.c b/urjtag/src/cmd/cmd_bit.c index 6295cea8..2e22874b 100644 --- a/urjtag/src/cmd/cmd_bit.c +++ b/urjtag/src/cmd/cmd_bit.c @@ -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 diff --git a/urjtag/src/cmd/cmd_bsdl.c b/urjtag/src/cmd/cmd_bsdl.c index ccac8f38..39a1565f 100644 --- a/urjtag/src/cmd/cmd_bsdl.c +++ b/urjtag/src/cmd/cmd_bsdl.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/urjtag/src/cmd/cmd_bus.c b/urjtag/src/cmd/cmd_bus.c index 1ade97b3..f31e4f17 100644 --- a/urjtag/src/cmd/cmd_bus.c +++ b/urjtag/src/cmd/cmd_bus.c @@ -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 diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index cd8e84ba..008f144c 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_cmd.c b/urjtag/src/cmd/cmd_cmd.c index 0b8e676a..8ab7d808 100644 --- a/urjtag/src/cmd/cmd_cmd.c +++ b/urjtag/src/cmd/cmd_cmd.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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; } diff --git a/urjtag/src/cmd/cmd_debug.c b/urjtag/src/cmd/cmd_debug.c index ada1b2a0..c85ed922 100644 --- a/urjtag/src/cmd/cmd_debug.c +++ b/urjtag/src/cmd/cmd_debug.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_detect.c b/urjtag/src/cmd/cmd_detect.c index 006f30ae..e606a67f 100644 --- a/urjtag/src/cmd/cmd_detect.c +++ b/urjtag/src/cmd/cmd_detect.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_detectflash.c b/urjtag/src/cmd/cmd_detectflash.c index 770c735a..1bd10afd 100644 --- a/urjtag/src/cmd/cmd_detectflash.c +++ b/urjtag/src/cmd/cmd_detectflash.c @@ -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 diff --git a/urjtag/src/cmd/cmd_discovery.c b/urjtag/src/cmd/cmd_discovery.c index b3599995..663497bf 100644 --- a/urjtag/src/cmd/cmd_discovery.c +++ b/urjtag/src/cmd/cmd_discovery.c @@ -26,6 +26,7 @@ #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_dr.c b/urjtag/src/cmd/cmd_dr.c index 3f714db2..e4346a93 100644 --- a/urjtag/src/cmd/cmd_dr.c +++ b/urjtag/src/cmd/cmd_dr.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_endian.c b/urjtag/src/cmd/cmd_endian.c index 3c15040f..389a18af 100644 --- a/urjtag/src/cmd/cmd_endian.c +++ b/urjtag/src/cmd/cmd_endian.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_eraseflash.c b/urjtag/src/cmd/cmd_eraseflash.c index 62e54b3e..3bf825f7 100644 --- a/urjtag/src/cmd/cmd_eraseflash.c +++ b/urjtag/src/cmd/cmd_eraseflash.c @@ -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 diff --git a/urjtag/src/cmd/cmd_flashmem.c b/urjtag/src/cmd/cmd_flashmem.c index 5dd48b68..555332ac 100644 --- a/urjtag/src/cmd/cmd_flashmem.c +++ b/urjtag/src/cmd/cmd_flashmem.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_frequency.c b/urjtag/src/cmd/cmd_frequency.c index 2b87cf5e..b6d5f8bb 100644 --- a/urjtag/src/cmd/cmd_frequency.c +++ b/urjtag/src/cmd/cmd_frequency.c @@ -26,6 +26,7 @@ #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_get.c b/urjtag/src/cmd/cmd_get.c index d7cc300e..488087d6 100644 --- a/urjtag/src/cmd/cmd_get.c +++ b/urjtag/src/cmd/cmd_get.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -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"), diff --git a/urjtag/src/cmd/cmd_help.c b/urjtag/src/cmd/cmd_help.c index 69ea44e3..71aa17f0 100644 --- a/urjtag/src/cmd/cmd_help.c +++ b/urjtag/src/cmd/cmd_help.c @@ -27,6 +27,7 @@ #include #include +#include #include #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 diff --git a/urjtag/src/cmd/cmd_idcode.c b/urjtag/src/cmd/cmd_idcode.c index 64c17d25..0d855ed3 100644 --- a/urjtag/src/cmd/cmd_idcode.c +++ b/urjtag/src/cmd/cmd_idcode.c @@ -25,6 +25,7 @@ #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_include.c b/urjtag/src/cmd/cmd_include.c index 4e311128..7a91ef87 100644 --- a/urjtag/src/cmd/cmd_include.c +++ b/urjtag/src/cmd/cmd_include.c @@ -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 diff --git a/urjtag/src/cmd/cmd_initbus.c b/urjtag/src/cmd/cmd_initbus.c index 6c072c92..98293cdc 100644 --- a/urjtag/src/cmd/cmd_initbus.c +++ b/urjtag/src/cmd/cmd_initbus.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_instruction.c b/urjtag/src/cmd/cmd_instruction.c index 8c1b82d1..712dff7a 100644 --- a/urjtag/src/cmd/cmd_instruction.c +++ b/urjtag/src/cmd/cmd_instruction.c @@ -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 diff --git a/urjtag/src/cmd/cmd_part.c b/urjtag/src/cmd/cmd_part.c index 2796d184..f8bf8d91 100644 --- a/urjtag/src/cmd/cmd_part.c +++ b/urjtag/src/cmd/cmd_part.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -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"); diff --git a/urjtag/src/cmd/cmd_peekpoke.c b/urjtag/src/cmd/cmd_peekpoke.c index 7233fc73..b1b05fd4 100644 --- a/urjtag/src/cmd/cmd_peekpoke.c +++ b/urjtag/src/cmd/cmd_peekpoke.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_pod.c b/urjtag/src/cmd/cmd_pod.c index e81267bf..387b1871 100644 --- a/urjtag/src/cmd/cmd_pod.c +++ b/urjtag/src/cmd/cmd_pod.c @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_print.c b/urjtag/src/cmd/cmd_print.c index 8563cdd9..79bc4784 100644 --- a/urjtag/src/cmd/cmd_print.c +++ b/urjtag/src/cmd/cmd_print.c @@ -38,6 +38,7 @@ typedef char wchar_t; # define wcslen(str) strlen(str) #endif +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_quit.c b/urjtag/src/cmd/cmd_quit.c index dc7ab24a..db18a68b 100644 --- a/urjtag/src/cmd/cmd_quit.c +++ b/urjtag/src/cmd/cmd_quit.c @@ -26,6 +26,7 @@ #include +#include #include #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 diff --git a/urjtag/src/cmd/cmd_readmem.c b/urjtag/src/cmd/cmd_readmem.c index b92dda31..2c666951 100644 --- a/urjtag/src/cmd/cmd_readmem.c +++ b/urjtag/src/cmd/cmd_readmem.c @@ -26,7 +26,10 @@ #include #include +#include +#include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_register.c b/urjtag/src/cmd/cmd_register.c index a6f1f523..003c225c 100644 --- a/urjtag/src/cmd/cmd_register.c +++ b/urjtag/src/cmd/cmd_register.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_reset.c b/urjtag/src/cmd/cmd_reset.c index 0fb6cc8d..a72c1635 100644 --- a/urjtag/src/cmd/cmd_reset.c +++ b/urjtag/src/cmd/cmd_reset.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_salias.c b/urjtag/src/cmd/cmd_salias.c index f0554291..7c2a24e3 100644 --- a/urjtag/src/cmd/cmd_salias.c +++ b/urjtag/src/cmd/cmd_salias.c @@ -28,11 +28,12 @@ #include #include -#include "urjtag/chain.h" -#include "urjtag/part.h" -#include "urjtag/bssignal.h" +#include +#include +#include +#include -#include "urjtag/cmd.h" +#include #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 diff --git a/urjtag/src/cmd/cmd_scan.c b/urjtag/src/cmd/cmd_scan.c index 65492697..1d7ac94a 100644 --- a/urjtag/src/cmd/cmd_scan.c +++ b/urjtag/src/cmd/cmd_scan.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_set.c b/urjtag/src/cmd/cmd_set.c index e4336ba3..561ce4af 100644 --- a/urjtag/src/cmd/cmd_set.c +++ b/urjtag/src/cmd/cmd_set.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_shell.c b/urjtag/src/cmd/cmd_shell.c index 9ebb721c..795a9158 100644 --- a/urjtag/src/cmd/cmd_shell.c +++ b/urjtag/src/cmd/cmd_shell.c @@ -31,6 +31,7 @@ #include #include +#include #include #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 diff --git a/urjtag/src/cmd/cmd_shift.c b/urjtag/src/cmd/cmd_shift.c index 2e278347..fc78773d 100644 --- a/urjtag/src/cmd/cmd_shift.c +++ b/urjtag/src/cmd/cmd_shift.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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 diff --git a/urjtag/src/cmd/cmd_signal.c b/urjtag/src/cmd/cmd_signal.c index 16327489..d0667b94 100644 --- a/urjtag/src/cmd/cmd_signal.c +++ b/urjtag/src/cmd/cmd_signal.c @@ -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 diff --git a/urjtag/src/cmd/cmd_svf.c b/urjtag/src/cmd/cmd_svf.c index 1d16730e..8c1b51eb 100644 --- a/urjtag/src/cmd/cmd_svf.c +++ b/urjtag/src/cmd/cmd_svf.c @@ -29,7 +29,9 @@ #include #include #include +#include +#include #include #include @@ -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; diff --git a/urjtag/src/cmd/cmd_test.c b/urjtag/src/cmd/cmd_test.c index 9b966d44..bc6ee703 100644 --- a/urjtag/src/cmd/cmd_test.c +++ b/urjtag/src/cmd/cmd_test.c @@ -29,6 +29,7 @@ #include //#include +#include #include #include #include @@ -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 (_("%s = %d\n"), params[2], data); - return -99; - } + urj_error_set (URJ_ERROR_ILLEGAL_STATE, + _("%s = %d"), params[2], data); + return URJ_STATUS_FAIL; } - return 1; + + return URJ_STATUS_OK; } static void diff --git a/urjtag/src/cmd/cmd_usleep.c b/urjtag/src/cmd/cmd_usleep.c index 1a5be2c7..e0c5034a 100644 --- a/urjtag/src/cmd/cmd_usleep.c +++ b/urjtag/src/cmd/cmd_usleep.c @@ -29,6 +29,7 @@ #include #include +#include #include #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 diff --git a/urjtag/src/cmd/cmd_writemem.c b/urjtag/src/cmd/cmd_writemem.c index 5c6920e7..12dc1007 100644 --- a/urjtag/src/cmd/cmd_writemem.c +++ b/urjtag/src/cmd/cmd_writemem.c @@ -24,7 +24,10 @@ #include #include +#include +#include +#include #include #include @@ -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 diff --git a/urjtag/src/global/parse.c b/urjtag/src/global/parse.c index 92e8bf8c..e1c77bc4 100644 --- a/urjtag/src/global/parse.c +++ b/urjtag/src/global/parse.c @@ -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); diff --git a/urjtag/src/global/urjtag.c b/urjtag/src/global/urjtag.c index ff8a16a3..b0d512bf 100644 --- a/urjtag/src/global/urjtag.c +++ b/urjtag/src/global/urjtag.c @@ -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; +} diff --git a/urjtag/src/part/part.c b/urjtag/src/part/part.c index 79789b5e..921ae9f0 100644 --- a/urjtag/src/part/part.c +++ b/urjtag/src/part/part.c @@ -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; diff --git a/urjtag/src/svf/svf.c b/urjtag/src/svf/svf.c index aec8ccb2..1a14bd13 100644 --- a/urjtag/src/svf/svf.c +++ b/urjtag/src/svf/svf.c @@ -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"))) diff --git a/urjtag/src/tap/chain.c b/urjtag/src/tap/chain.c index d2847f41..96b7ae89 100644 --- a/urjtag/src/tap/chain.c +++ b/urjtag/src/tap/chain.c @@ -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; } diff --git a/urjtag/src/tap/detect.c b/urjtag/src/tap/detect.c index e81c1a67..493ecf5d 100644 --- a/urjtag/src/tap/detect.c +++ b/urjtag/src/tap/detect.c @@ -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)