From ebb0861971272464f64f3483eb997caa7493458b Mon Sep 17 00:00:00 2001 From: Rutger Hofman Date: Thu, 28 May 2009 11:15:58 +0000 Subject: [PATCH] - rename src/global/urjtag.c to src/global/log-error.c - introduce data structure for key/value pairs - have an API call initbus() that uses key/value pairs to pass in options - have API calls urj_tap_cable_parport_connect(), urj_tap_cable_usb_connect(), urj_tap_cable_other_connect(); have a tagged union in the cable driver that offers driver-specific connect() calls. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1636 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 15 + urjtag/include/urjtag/Makefile.am | 3 +- urjtag/include/urjtag/bus.h | 6 +- urjtag/include/urjtag/bus_driver.h | 48 ++- urjtag/include/urjtag/cable.h | 60 +++- urjtag/include/urjtag/params.h | 126 ++++++++ urjtag/include/urjtag/parport.h | 16 +- urjtag/include/urjtag/usbconn.h | 13 +- urjtag/po/POTFILES.in | 4 +- urjtag/src/bus/au1500.c | 24 +- urjtag/src/bus/avr32.c | 107 ++++--- urjtag/src/bus/bcm1250.c | 27 +- urjtag/src/bus/bf533_ezkit.c | 27 +- urjtag/src/bus/bf533_stamp.c | 27 +- urjtag/src/bus/bf537_stamp.c | 27 +- urjtag/src/bus/bf548_ezkit.c | 27 +- urjtag/src/bus/bf561_ezkit.c | 27 +- urjtag/src/bus/bscoach.c | 30 +- urjtag/src/bus/buses.c | 126 +++++++- urjtag/src/bus/ejtag.c | 27 +- urjtag/src/bus/ejtag_dma.c | 23 +- urjtag/src/bus/fjmem.c | 122 +++---- urjtag/src/bus/generic_bus.c | 31 ++ urjtag/src/bus/generic_bus.h | 5 + urjtag/src/bus/h7202.c | 27 +- urjtag/src/bus/ixp425.c | 27 +- urjtag/src/bus/ixp435.c | 27 +- urjtag/src/bus/jopcyc.c | 27 +- urjtag/src/bus/lh7a400.c | 27 +- urjtag/src/bus/mpc5200.c | 46 ++- urjtag/src/bus/mpc824x.c | 126 +++----- urjtag/src/bus/ppc405ep.c | 27 +- urjtag/src/bus/ppc440gx_ebc8.c | 27 +- urjtag/src/bus/prototype.c | 193 +++++------ urjtag/src/bus/pxa2x0.c | 32 +- urjtag/src/bus/s3c4510x.c | 26 +- urjtag/src/bus/sa1110.c | 27 +- urjtag/src/bus/sh7727.c | 27 +- urjtag/src/bus/sh7750r.c | 26 +- urjtag/src/bus/sh7751r.c | 28 +- urjtag/src/bus/sharc21065l.c | 27 +- urjtag/src/bus/slsup3.c | 27 +- urjtag/src/bus/tx4925.c | 27 +- urjtag/src/bus/zefant-xs3.c | 27 +- urjtag/src/cmd/cmd_cable.c | 92 +++--- urjtag/src/cmd/cmd_initbus.c | 50 ++- urjtag/src/cmd/cmd_signal.c | 14 +- urjtag/src/global/Makefile.am | 5 +- urjtag/src/global/{urjtag.c => log-error.c} | 0 urjtag/src/global/params.c | 337 ++++++++++++++++++++ urjtag/src/tap/cable.c | 128 ++++++++ urjtag/src/tap/cable/arcom.c | 3 +- urjtag/src/tap/cable/byteblaster.c | 3 +- urjtag/src/tap/cable/dlc5.c | 3 +- urjtag/src/tap/cable/ea253.c | 3 +- urjtag/src/tap/cable/ei012.c | 3 +- urjtag/src/tap/cable/ft2232.c | 34 +- urjtag/src/tap/cable/generic.c | 1 + urjtag/src/tap/cable/generic_parport.c | 18 +- urjtag/src/tap/cable/generic_parport.h | 6 +- urjtag/src/tap/cable/generic_usbconn.c | 54 ++-- urjtag/src/tap/cable/generic_usbconn.h | 10 +- urjtag/src/tap/cable/jim.c | 2 +- urjtag/src/tap/cable/jlink.c | 3 +- urjtag/src/tap/cable/keithkoep.c | 3 +- urjtag/src/tap/cable/lattice.c | 3 +- urjtag/src/tap/cable/mpcbdm.c | 3 +- urjtag/src/tap/cable/triton.c | 3 +- urjtag/src/tap/cable/ts7800.c | 5 +- urjtag/src/tap/cable/usbblaster.c | 7 +- urjtag/src/tap/cable/vision_ep9307.c | 5 +- urjtag/src/tap/cable/wiggler.c | 40 ++- urjtag/src/tap/cable/wiggler2.c | 3 +- urjtag/src/tap/cable/xpc.c | 6 +- urjtag/src/tap/parport.c | 14 + urjtag/src/tap/parport/direct.c | 12 +- urjtag/src/tap/parport/ppdev.c | 18 +- urjtag/src/tap/parport/ppi.c | 19 +- urjtag/src/tap/usbconn/libftd2xx.c | 10 +- urjtag/src/tap/usbconn/libftdi.c | 10 +- urjtag/src/tap/usbconn/libusb.c | 6 +- 81 files changed, 1572 insertions(+), 1140 deletions(-) create mode 100644 urjtag/include/urjtag/params.h rename urjtag/src/global/{urjtag.c => log-error.c} (100%) create mode 100644 urjtag/src/global/params.c diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index aca0afb2..40c1fea7 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,18 @@ +2009-05-28 Rutger Hofman + + * src/global/urjtag.c, src/global/Makefile.am: rename urjtag.c to + src/global/log-error.c + * src/global/params.c, src/global/Makefile.am, include/urjtag/params.h, + include/urjtag/Makefile.am: data structure for key/value pairs + * src/bus/*, include/urjtag/bus_driver.h, include/urjtag/bus.h, + src/cmd/cmd_initbus.c: have an API call initbus() that uses key/value + pairs to pass in options + * src/tap/cable.c, src/tap/parport.c, src/tap/usbconn.c, src/tap/cable/*, + src/tap/parport/*, src/tap/usbconn/*, include/urjtag/cable.h: have API + calls urj_tap_cable_parport_connect(), urj_tap_cable_usb_connect(), + urj_tap_cable_other_connect(); have a tagged union in the cable driver + that offers driver-specific connect() calls. + 2009-05-28 Mike Frysinger * configure.ac: improve svn rev look up by ignoring errors, unifying diff --git a/urjtag/include/urjtag/Makefile.am b/urjtag/include/urjtag/Makefile.am index 1f726fba..a074622d 100644 --- a/urjtag/include/urjtag/Makefile.am +++ b/urjtag/include/urjtag/Makefile.am @@ -42,9 +42,10 @@ pkginclude_HEADERS = \ jim.h \ jtag.h \ log.h \ - part_instruction.h \ + params.h \ parport.h \ part.h \ + part_instruction.h \ pod.h \ tap_register.h \ tap_state.h \ diff --git a/urjtag/include/urjtag/bus.h b/urjtag/include/urjtag/bus.h index abb581a3..fbcad01c 100644 --- a/urjtag/include/urjtag/bus.h +++ b/urjtag/include/urjtag/bus.h @@ -49,10 +49,8 @@ extern urj_buses_t urj_buses; extern const urj_bus_driver_t *urj_bus_drivers[]; void urj_bus_buses_free (void); -/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */ -void urj_bus_buses_add (urj_bus_t *abus); -/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */ -void urj_bus_buses_delete (urj_bus_t *abus); +int urj_bus_buses_add (urj_bus_t *abus); +int urj_bus_buses_delete (urj_bus_t *abus); /** set active bus * @param n choose n'th bus in #urj_buses as the active bus diff --git a/urjtag/include/urjtag/bus_driver.h b/urjtag/include/urjtag/bus_driver.h index 883e8adb..e143e8fd 100644 --- a/urjtag/include/urjtag/bus_driver.h +++ b/urjtag/include/urjtag/bus_driver.h @@ -38,6 +38,7 @@ #include #include "types.h" +#include "params.h" typedef struct { @@ -48,13 +49,47 @@ typedef struct } urj_bus_area_t; +typedef enum URJ_BUS_PARAM_KEY +{ + URJ_BUS_PARAM_KEY_MUX, // bool mpc5200 + // avr32: mode = OCD | HSBC | HSBU | x8 | x16 | x32 avr32 + URJ_BUS_PARAM_KEY_OCD, // bool avr32 + URJ_BUS_PARAM_KEY_HSBC, // bool avr32 + URJ_BUS_PARAM_KEY_HSBU, // bool avr32 + URJ_BUS_PARAM_KEY_X8, // bool avr32 + URJ_BUS_PARAM_KEY_X16, // bool avr32 + URJ_BUS_PARAM_KEY_X32, // bool avr32 + URJ_BUS_PARAM_KEY_WIDTH, // 0=auto 8 16 32 64 + // aliased as x8 x16 x32 bool avr32 + // 8 32 64 mpc824 + // aliased as AMODE prototype + URJ_BUS_PARAM_KEY_OPCODE, // string fjmem + URJ_BUS_PARAM_KEY_LEN, // ulong fjmem + URJ_BUS_PARAM_KEY_AMODE, // alias for WIDTH: 0=auto 8 16 32 prototype + URJ_BUS_PARAM_KEY_ALSB, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_AMSB, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_DLSB, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_DMSB, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_CS, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_NCS, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_OE, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_NOE, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_WE, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_NWE, // string (= signal name) prototype + URJ_BUS_PARAM_KEY_REVBITS, // bool mpc824 + URJ_BUS_PARAM_KEY_HELP, // bool mpc824 + URJ_BUS_PARAM_KEY_DBGaDDR, // bool mpc824 + URJ_BUS_PARAM_KEY_DBGdATA, // bool mpc824 +} +urj_bus_param_key_t; + struct urj_bus_driver { const char *name; const char *description; urj_bus_t *(*new_bus) (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]); + const urj_param_t *cmd_params[]); void (*free_bus) (urj_bus_t *bus); void (*printinfo) (urj_log_level_t ll, urj_bus_t *bus); void (*prepare) (urj_bus_t *bus); @@ -82,6 +117,7 @@ struct urj_bus const urj_bus_driver_t *driver; }; + #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) @@ -93,4 +129,14 @@ struct urj_bus #define URJ_BUS_FREE(bus) (bus)->driver->free_bus(bus) #define URJ_BUS_INIT(bus) (bus)->driver->init(bus) +/** + * API function to init a bus + */ +urj_bus_t *urj_bus_init_bus (urj_chain_t *chain, + const urj_bus_driver_t *bus_driver, + const urj_param_t *param[]); + +/** The list of recognized parameters */ +extern const urj_param_list_t urj_bus_param_list; + #endif /* URJ_BUS_DRIVER_BRUX_BUS_H */ diff --git a/urjtag/include/urjtag/cable.h b/urjtag/include/urjtag/cable.h index ad73e39d..982a5f02 100644 --- a/urjtag/include/urjtag/cable.h +++ b/urjtag/include/urjtag/cable.h @@ -29,7 +29,9 @@ #include #include "types.h" +#include "params.h" +#include "parport.h" #include "pod.h" typedef struct urj_cable_driver urj_cable_driver_t; @@ -42,12 +44,37 @@ typedef enum urj_cable_flush_amount } urj_cable_flush_amount_t; +typedef enum URJ_CABLE_DEVICE_TYPE +{ + URJ_CABLE_DEVICE_PARPORT, + URJ_CABLE_DEVICE_USB, + URJ_CABLE_DEVICE_OTHER, +} +urj_cable_device_type_t; + +typedef enum URJ_CABLE_PARAM_KEY +{ + URJ_CABLE_PARAM_KEY_PID, // lu generic_usbconn + URJ_CABLE_PARAM_KEY_VID, // lu generic_usbconn + URJ_CABLE_PARAM_KEY_DESC, // string generic_usbconn + URJ_CABLE_PARAM_KEY_DRIVER, // string generic_usbconn + URJ_CABLE_PARAM_KEY_BITMAP, // string wiggler +} +urj_cable_param_key_t; + struct urj_cable_driver { const char *name; const char *description; + /** tag for the following union */ + urj_cable_device_type_t device_type; /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure */ - int (*connect) (char *params[], urj_cable_t *cable); + union { + int (*parport) (urj_cable_t *cable, urj_cable_parport_devtype_t devtype, + const char *devname, const urj_param_t *params[]); + int (*usb) (urj_cable_t *cable, const urj_param_t *params[]); + int (*other) (urj_cable_t *cable, const urj_param_t *params[]); + } connect; void (*disconnect) (urj_cable_t *cable); void (*cable_free) (urj_cable_t *cable); /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure */ @@ -127,6 +154,7 @@ struct urj_cable { urj_usbconn_t *usb; urj_parport_t *port; + void *other; } link; void *params; urj_chain_t *chain; @@ -180,6 +208,36 @@ int urj_tap_cable_add_queue_item (urj_cable_t *cable, int urj_tap_cable_get_queue_item (urj_cable_t *cable, urj_cable_queue_info_t *q); +/** + * API function to connect to a parport cable + * + * @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure + */ +urj_cable_t *urj_tap_cable_parport_connect (urj_chain_t *chain, + urj_cable_driver_t *driver, + urj_cable_parport_devtype_t devtype, + const char *devname, + const urj_param_t *params[]); +/** + * API function to connect to a USB cable + * + * @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure + */ +urj_cable_t *urj_tap_cable_usb_connect (urj_chain_t *chain, + urj_cable_driver_t *driver, + const urj_param_t *params[]); +/** + * API function to connect to a type-other cable + * + * @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure + */ +urj_cable_t *urj_tap_cable_other_connect (urj_chain_t *chain, + urj_cable_driver_t *driver, + const urj_param_t *params[]); + extern urj_cable_driver_t *urj_tap_cable_drivers[]; +/** The list of recognized parameters */ +extern const urj_param_list_t urj_cable_param_list; + #endif /* URJ_CABLE_H */ diff --git a/urjtag/include/urjtag/params.h b/urjtag/include/urjtag/params.h new file mode 100644 index 00000000..712fa5d8 --- /dev/null +++ b/urjtag/include/urjtag/params.h @@ -0,0 +1,126 @@ +/* + * $Id: params.h 1606 2009-05-19 15:06:20Z rfhh $ + * + * Parameter list, in the vein of X parameter passing + * Copyright (C) 2009 VU Amsterdam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the ETC s.r.o. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Written by Rutger Hofman , 2009 + * + */ + +#ifndef URJ_PARAMS_H +#define URJ_PARAMS_H + +#include + +#include "types.h" + +/** + * Supported parameter types + */ +typedef enum URJ_PARAM_TYPE_T +{ + URJ_PARAM_TYPE_LU, + URJ_PARAM_TYPE_STRING, + URJ_PARAM_TYPE_BOOL, +} +urj_param_type_t; + +/** + * Parameter as assembled for passing to parameter-taking functions + */ +typedef struct URJ_PARAM +{ + urj_param_type_t type; + int key; + union { + long unsigned lu; + const char *string; + int enabled; /**< bool */ + } value; +} +urj_param_t; + +/** + * Description of a parameter, as recognized by a module + */ +typedef struct URJ_PARAM_DESCR +{ + int key; /**< key */ + urj_param_type_t type; /**< type */ + const char *string; /**< human-friendly form */ +} +urj_param_descr_t; + +/** + * Type for a module to export its recognized parameters + */ +typedef struct URJ_PARAM_LIST +{ + urj_param_descr_t *list; + size_t n; +} +urj_param_list_t; + +/** Initialise a parameter assembly line */ +int urj_param_init (const urj_param_t ***bp); +/** Clear the parameter assembly line */ +int urj_param_clear (const urj_param_t ***bp); + +/** + * toString function for #urj_param_t. Is not reentrant. May return a + * pointer to a static string. + */ +const char *urj_param_string(const urj_param_list_t *params, + const urj_param_t *p); + +/** + * Append a string-type argument to the current #urj_param_t assembly line. + * Copies the pointer value, does no strdup(val). + */ +int urj_param_push_string (const urj_param_t ***bp, int key, const char *val); +/** + * Append a ulong-type argument to the current #urj_param_t assembly line. + */ +int urj_param_push_lu (const urj_param_t ***bp, int key, long unsigned val); +/** + * Append a bool-type argument to the current #urj_param_t assembly line. + */ +int urj_param_push_bool (const urj_param_t ***bp, int key, int val); +/** + * Transform a string representation of a param "key=value" into a #urj_param_t + * representation, and append it to the current #urj_param_t assembly line. + */ +int urj_param_push (const urj_param_list_t *params, const urj_param_t ***bp, + const char *p); +/** + * Utility function to count the number of items in a #urj_param_t assembly + * line + */ +size_t urj_param_num (const urj_param_t *params[]); + +#endif /* URJ_BUS_DRIVER_BRUX_BUS_H */ diff --git a/urjtag/include/urjtag/parport.h b/urjtag/include/urjtag/parport.h index ccd9dd73..eb9c29ce 100644 --- a/urjtag/include/urjtag/parport.h +++ b/urjtag/include/urjtag/parport.h @@ -29,11 +29,21 @@ #include #include "types.h" +#include "params.h" + +typedef enum URJ_CABLE_PARPORT_DEVTYPE +{ + URJ_CABLE_PARPORT_DEV_PARALLEL, + URJ_CABLE_PARPORT_DEV_PPDEV, + URJ_CABLE_PARPORT_DEV_PPI, + URJ_CABLE_PARPORT_N_DEVS, +} +urj_cable_parport_devtype_t; typedef struct { - const char *type; - urj_parport_t *(*connect) (const char **, int); + urj_cable_parport_devtype_t type; + urj_parport_t *(*connect) (const char *devname); void (*parport_free) (urj_parport_t *); /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */ int (*open) (urj_parport_t *); @@ -66,6 +76,8 @@ int urj_tap_parport_get_data (urj_parport_t *port); int urj_tap_parport_get_status (urj_parport_t *port); int urj_tap_parport_set_control (urj_parport_t *port, const unsigned char data); +const char *urj_cable_parport_devtype_string(urj_cable_parport_devtype_t dt); + extern urj_parport_driver_t *urj_tap_parport_drivers[]; #endif /* URJ_PARPORT_H */ diff --git a/urjtag/include/urjtag/usbconn.h b/urjtag/include/urjtag/usbconn.h index d346ec02..b6dfc2fb 100644 --- a/urjtag/include/urjtag/usbconn.h +++ b/urjtag/include/urjtag/usbconn.h @@ -29,12 +29,13 @@ #include #include "types.h" +#include "params.h" typedef struct { - char *name; - char *desc; - char *driver; + const char *name; + const char *desc; + const char *driver; int32_t vid; int32_t pid; } @@ -43,7 +44,8 @@ urj_usbconn_cable_t; typedef struct { const char *type; - urj_usbconn_t *(*connect) (const char **, int, urj_usbconn_cable_t *); + urj_usbconn_t *(*connect) (urj_usbconn_cable_t *cable, + const urj_param_t *params[]); void (*free) (urj_usbconn_t *); /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */ int (*open) (urj_usbconn_t *); @@ -63,7 +65,8 @@ struct urj_usbconn urj_cable_t *cable; }; -urj_usbconn_t *usbconn_connect (const char **, int, urj_usbconn_cable_t *); +urj_usbconn_t *usbconn_connect (urj_usbconn_cable_t *cable, + const urj_param_t *params[]); int usbconn_free (urj_usbconn_t *conn); int urj_tap_usbconn_open (urj_usbconn_t *conn); int urj_tap_usbconn_close (urj_usbconn_t *conn); diff --git a/urjtag/po/POTFILES.in b/urjtag/po/POTFILES.in index 09c927e2..c5019710 100644 --- a/urjtag/po/POTFILES.in +++ b/urjtag/po/POTFILES.in @@ -1,4 +1,5 @@ # $Id$ +src/apps/bsdl2jtag/bsdl2jtag.c src/apps/jtag/jtag.c src/bsdl/bsdl_bison.c src/bsdl/bsdl.c @@ -86,9 +87,10 @@ src/flash/flash.c src/flash/intel.c src/flash/jedec.c src/flash/jedec_exp.c -src/global/urjtag.c +src/global/log-error.c src/global/parse.c src/global/data_dir.c +src/global/params.c src/jim/intel_28f800b3.c src/jim/some_cpu.c src/jim/jim_tap.c diff --git a/urjtag/src/bus/au1500.c b/urjtag/src/bus/au1500.c index 91fb90f8..585015ef 100644 --- a/urjtag/src/bus/au1500.c +++ b/urjtag/src/bus/au1500.c @@ -62,7 +62,7 @@ typedef struct */ static urj_bus_t * au1500_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -70,26 +70,10 @@ au1500_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 32; i++) { diff --git a/urjtag/src/bus/avr32.c b/urjtag/src/bus/avr32.c index 63b2806a..9631dfec 100644 --- a/urjtag/src/bus/avr32.c +++ b/urjtag/src/bus/avr32.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ typedef struct #define BUS_MODE_x8 3 #define BUS_MODE_x16 4 #define BUS_MODE_x32 5 +#define BUS_MODE_ERROR UINT_MAX #define BP ((bus_params_t *) bus->params) #define SLAVE (BP->slave) @@ -491,49 +493,76 @@ check_instruction (urj_part_t *part, const char *instr) */ static urj_bus_t * avr32_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; - char *param; - unsigned int mode; - - part = chain->parts->parts[chain->active_part]; + unsigned int mode = BUS_MODE_ERROR; - param = cmd_params[2]; - if (!param) + if (cmd_params[0] == NULL) { urj_error_set (URJ_ERROR_SYNTAX, "no bus mode specified"); return NULL; } - if (!strcasecmp ("OCD", param)) + if (cmd_params[1] != NULL) { - mode = BUS_MODE_OCD; + urj_error_set (URJ_ERROR_SYNTAX, "invalid bus parameter: %s", + urj_param_string(&urj_bus_param_list, cmd_params[1])); + return NULL; } - else if (!strcasecmp ("HSBC", param)) + + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) + return NULL; + part = bus->part; + + switch (cmd_params[0]->key) { + case URJ_BUS_PARAM_KEY_OCD: + mode = BUS_MODE_OCD; + break; + case URJ_BUS_PARAM_KEY_HSBC: mode = BUS_MODE_HSBC; - } - else if (!strcasecmp ("HSBU", param)) - { + break; + case URJ_BUS_PARAM_KEY_HSBU: mode = BUS_MODE_HSBU; - } - else if (!strcasecmp ("x8", param)) - { + break; + case URJ_BUS_PARAM_KEY_X8: // see also: width=8 mode = BUS_MODE_x8; - } - else if (!strcasecmp ("x16", param)) - { + break; + case URJ_BUS_PARAM_KEY_X16: // see also: width=16 mode = BUS_MODE_x16; - } - else if (!strcasecmp ("x32", param)) - { + break; + case URJ_BUS_PARAM_KEY_X32: // see also: width=32 mode = BUS_MODE_x32; - } - else - { - urj_error_set (URJ_ERROR_SYNTAX, "invalid bus mode: %s", param); + break; + + // RFHH introduced 'width=8|16|32' as an alias for x8, x16, x32 + case URJ_BUS_PARAM_KEY_WIDTH: + switch (cmd_params[0]->value.lu) + { + case 8: + mode = BUS_MODE_x8; + break; + case 16: + mode = BUS_MODE_x16; + break; + case 32: + mode = BUS_MODE_x32; + break; + default: + urj_bus_generic_free (bus); + urj_error_set (URJ_ERROR_SYNTAX, "invalid bus width: %lu", + cmd_params[0]->value.lu); + return NULL; + } + break; + + default: + urj_bus_generic_free (bus); + urj_error_set (URJ_ERROR_SYNTAX, "invalid bus mode: %s", + urj_param_string(&urj_bus_param_list, cmd_params[0])); return NULL; } @@ -543,31 +572,23 @@ avr32_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, case BUS_MODE_HSBC: case BUS_MODE_HSBU: if (check_instruction (part, "MEMORY_WORD_ACCESS")) + { + urj_bus_generic_free (bus); return NULL; + } break; case BUS_MODE_x8: case BUS_MODE_x16: case BUS_MODE_x32: if (check_instruction (part, "NEXUS_ACCESS")) + { + urj_bus_generic_free (bus); return NULL; + } break; - } - - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + default: + urj_error_set (URJ_ERROR_INVALID, "need bus mode parameter"); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bcm1250.c b/urjtag/src/bus/bcm1250.c index d7024896..5d6d15e2 100644 --- a/urjtag/src/bus/bcm1250.c +++ b/urjtag/src/bus/bcm1250.c @@ -60,7 +60,7 @@ typedef struct */ static urj_bus_t * bcm1250_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -68,26 +68,10 @@ bcm1250_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 32; i++) { @@ -109,8 +93,7 @@ bcm1250_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bf533_ezkit.c b/urjtag/src/bus/bf533_ezkit.c index 0b572726..e014fc2a 100644 --- a/urjtag/src/bus/bf533_ezkit.c +++ b/urjtag/src/bus/bf533_ezkit.c @@ -68,7 +68,7 @@ typedef struct */ static urj_bus_t * bf533_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -76,26 +76,10 @@ bf533_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 4; i++) { @@ -133,8 +117,7 @@ bf533_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bf533_stamp.c b/urjtag/src/bus/bf533_stamp.c index 7e934e02..cb767e0d 100644 --- a/urjtag/src/bus/bf533_stamp.c +++ b/urjtag/src/bus/bf533_stamp.c @@ -70,7 +70,7 @@ typedef struct */ static urj_bus_t * bf533_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -78,26 +78,10 @@ bf533_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 2; i++) { @@ -139,8 +123,7 @@ bf533_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bf537_stamp.c b/urjtag/src/bus/bf537_stamp.c index 7f3b436b..cee009ea 100644 --- a/urjtag/src/bus/bf537_stamp.c +++ b/urjtag/src/bus/bf537_stamp.c @@ -68,7 +68,7 @@ typedef struct */ static urj_bus_t * bf537_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -76,26 +76,10 @@ bf537_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 4; i++) { @@ -133,8 +117,7 @@ bf537_stamp_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bf548_ezkit.c b/urjtag/src/bus/bf548_ezkit.c index 067a49cb..46c79737 100644 --- a/urjtag/src/bus/bf548_ezkit.c +++ b/urjtag/src/bus/bf548_ezkit.c @@ -63,7 +63,7 @@ typedef struct */ static urj_bus_t * bf548_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -71,26 +71,10 @@ bf548_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 4; i++) { @@ -134,8 +118,7 @@ bf548_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bf561_ezkit.c b/urjtag/src/bus/bf561_ezkit.c index cc212608..d468595f 100644 --- a/urjtag/src/bus/bf561_ezkit.c +++ b/urjtag/src/bus/bf561_ezkit.c @@ -68,7 +68,7 @@ typedef struct */ static urj_bus_t * bf561_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -76,26 +76,10 @@ bf561_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 4; i++) { @@ -139,8 +123,7 @@ bf561_ezkit_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/bscoach.c b/urjtag/src/bus/bscoach.c index 833c7870..1965375d 100644 --- a/urjtag/src/bus/bscoach.c +++ b/urjtag/src/bus/bscoach.c @@ -68,32 +68,17 @@ typedef struct */ static urj_bus_t * flashbscoach_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } + part = bus->part; - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; //OE & WE failed |= urj_bus_generic_attach_sig (part, &(OE_F), "PB02_00"); failed |= urj_bus_generic_attach_sig (part, &(WE_F), "PB02_08"); @@ -127,17 +112,12 @@ flashbscoach_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, failed |= urj_bus_generic_attach_sig (part, &(D[6]), "PB02_01"); failed |= urj_bus_generic_attach_sig (part, &(D[7]), "PB00_11"); - - - if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } - return bus; } diff --git a/urjtag/src/bus/buses.c b/urjtag/src/bus/buses.c index 099aab7b..10026c8e 100644 --- a/urjtag/src/bus/buses.c +++ b/urjtag/src/bus/buses.c @@ -26,9 +26,12 @@ #include #include +#include #include #include +#include +#include #include "buses.h" @@ -162,30 +165,34 @@ urj_bus_buses_free (void) urj_bus = NULL; } -void +int urj_bus_buses_add (urj_bus_t *abus) { urj_bus_t **b; if (abus == NULL) - /* @@@@ RFHH add status return */ - return; + { + urj_error_set (URJ_ERROR_INVALID, "abus == NULL"); + return URJ_STATUS_FAIL; + } b = realloc (urj_buses.buses, (urj_buses.len + 1) * sizeof (urj_bus_t *)); if (b == NULL) { - /* @@@@ RFHH add status return */ - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return; + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, _("realloc(%s,%zd) fails"), + "urj_buses.buses", + (urj_buses.len + 1) * sizeof (urj_bus_t *)); + return URJ_STATUS_FAIL; } urj_buses.buses = b; urj_buses.buses[urj_buses.len++] = abus; if (urj_bus == NULL) urj_bus = abus; + + return URJ_STATUS_OK; } -void +int urj_bus_buses_delete (urj_bus_t *abus) { int i; @@ -195,8 +202,10 @@ urj_bus_buses_delete (urj_bus_t *abus) if (abus == urj_buses.buses[i]) break; if (i >= urj_buses.len) - /* @@@@ RFHH add status return */ - return; + { + urj_error_set (URJ_ERROR_NOTFOUND, "abus not in global bus list"); + return URJ_STATUS_FAIL; + } while (i + 1 < urj_buses.len) { @@ -205,15 +214,24 @@ urj_bus_buses_delete (urj_bus_t *abus) } urj_buses.len--; b = realloc (urj_buses.buses, urj_buses.len * sizeof (urj_bus_t *)); - if ((b != NULL) || (urj_buses.len == 0)) - urj_buses.buses = b; + if (b == NULL && urj_buses.len > 0) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, _("realloc(%s,%zd) fails"), + "urj_buses.buses", urj_buses.len * sizeof (urj_bus_t *)); + return URJ_STATUS_FAIL; + } + urj_buses.buses = b; - if (urj_bus != abus) - /* @@@@ RFHH add status return */ - return; + if (urj_bus == abus) + { + if (urj_buses.len > 0) + urj_bus = urj_buses.buses[0]; + // @@@@ RFHH else: urj_bus is a dangling pointer? + else + urj_bus = NULL; + } - if (urj_buses.len > 0) - urj_bus = urj_buses.buses[0]; + return URJ_STATUS_OK; } int @@ -229,3 +247,77 @@ urj_bus_buses_set (int n) return URJ_STATUS_OK; } + +urj_bus_t * +urj_bus_init_bus (urj_chain_t *chain, const urj_bus_driver_t *bus_driver, + const urj_param_t *param[]) +{ + urj_bus_t *abus; + int i; + + if (urj_tap_chain_active_part (chain) == NULL) + return NULL; + + abus = bus_driver->new_bus (chain, bus_driver, param); + if (abus == NULL) + // retain error state + return NULL; + + if (urj_bus_buses_add (abus) != URJ_STATUS_OK) + { + // @@@@ RFHH I added this FREE() + bail out. Is that correct? + URJ_BUS_FREE(abus); + return NULL; + } + + if (URJ_BUS_INIT (abus) != URJ_STATUS_OK) + { + // @@@@ RFHH I added this FREE() + bail out. Is that correct? + URJ_BUS_FREE(abus); + return NULL; + } + + for (i = 0; i < urj_buses.len; i++) + if (urj_buses.buses[i] == urj_bus) + break; + if (i != urj_buses.len - 1) + urj_log (URJ_LOG_LEVEL_NORMAL, _("Initialized bus %d, active bus %d\n"), + urj_buses.len - 1, i); + + return abus; +} + +static urj_param_descr_t bus_param[] = +{ + { URJ_BUS_PARAM_KEY_MUX, URJ_PARAM_TYPE_BOOL, "MUX", }, + { URJ_BUS_PARAM_KEY_OCD, URJ_PARAM_TYPE_BOOL, "OCD", }, + { URJ_BUS_PARAM_KEY_HSBC, URJ_PARAM_TYPE_BOOL, "HSBC", }, + { URJ_BUS_PARAM_KEY_HSBU, URJ_PARAM_TYPE_BOOL, "HSBU", }, + { URJ_BUS_PARAM_KEY_X8, URJ_PARAM_TYPE_BOOL, "X8", }, + { URJ_BUS_PARAM_KEY_X16, URJ_PARAM_TYPE_BOOL, "X16", }, + { URJ_BUS_PARAM_KEY_X32, URJ_PARAM_TYPE_BOOL, "X32", }, + { URJ_BUS_PARAM_KEY_WIDTH, URJ_PARAM_TYPE_LU, "WIDTH", }, + { URJ_BUS_PARAM_KEY_AMODE, URJ_PARAM_TYPE_LU, "AMODE", }, + { URJ_BUS_PARAM_KEY_OPCODE, URJ_PARAM_TYPE_STRING, "OPCODE", }, + { URJ_BUS_PARAM_KEY_LEN, URJ_PARAM_TYPE_LU, "LEN", }, + { URJ_BUS_PARAM_KEY_ALSB, URJ_PARAM_TYPE_STRING, "ALSB", }, + { URJ_BUS_PARAM_KEY_AMSB, URJ_PARAM_TYPE_STRING, "AMSB", }, + { URJ_BUS_PARAM_KEY_DLSB, URJ_PARAM_TYPE_STRING, "DLSB", }, + { URJ_BUS_PARAM_KEY_DMSB, URJ_PARAM_TYPE_STRING, "DMSB", }, + { URJ_BUS_PARAM_KEY_CS, URJ_PARAM_TYPE_STRING, "CS", }, + { URJ_BUS_PARAM_KEY_NCS, URJ_PARAM_TYPE_STRING, "NCS", }, + { URJ_BUS_PARAM_KEY_OE, URJ_PARAM_TYPE_STRING, "OE", }, + { URJ_BUS_PARAM_KEY_NOE, URJ_PARAM_TYPE_STRING, "NOE", }, + { URJ_BUS_PARAM_KEY_WE, URJ_PARAM_TYPE_STRING, "WE", }, + { URJ_BUS_PARAM_KEY_NWE, URJ_PARAM_TYPE_STRING, "NWE", }, + { URJ_BUS_PARAM_KEY_REVBITS, URJ_PARAM_TYPE_BOOL, "REVBITS", }, + { URJ_BUS_PARAM_KEY_HELP, URJ_PARAM_TYPE_BOOL, "HELP", }, + { URJ_BUS_PARAM_KEY_DBGaDDR, URJ_PARAM_TYPE_BOOL, "DBGaDDR", }, + { URJ_BUS_PARAM_KEY_DBGdATA, URJ_PARAM_TYPE_BOOL, "DBGdATA", }, +}; + +const urj_param_list_t urj_bus_param_list = +{ + .list = bus_param, + .n = sizeof bus_param / sizeof bus_param[0], +}; diff --git a/urjtag/src/bus/ejtag.c b/urjtag/src/bus/ejtag.c index c59b6161..06bce05b 100644 --- a/urjtag/src/bus/ejtag.c +++ b/urjtag/src/bus/ejtag.c @@ -117,32 +117,9 @@ typedef struct */ static urj_bus_t * ejtag_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { - urj_bus_t *bus; - - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = chain->parts->parts[chain->active_part]; - - return bus; + return urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); } /** diff --git a/urjtag/src/bus/ejtag_dma.c b/urjtag/src/bus/ejtag_dma.c index f8ef66de..d81130c0 100644 --- a/urjtag/src/bus/ejtag_dma.c +++ b/urjtag/src/bus/ejtag_dma.c @@ -89,30 +89,13 @@ typedef struct */ static urj_bus_t * ejtag_dma_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = chain->parts->parts[chain->active_part]; return bus; } diff --git a/urjtag/src/bus/fjmem.c b/urjtag/src/bus/fjmem.c index 64decac2..c70161bd 100644 --- a/urjtag/src/bus/fjmem.c +++ b/urjtag/src/bus/fjmem.c @@ -84,7 +84,7 @@ typedef struct #define BLOCK_DESC ((bus_params_t *) bus->params)->block_desc static int -fjmem_detect_reg_len (urj_chain_t *chain, urj_part_t *part, char *opcode, +fjmem_detect_reg_len (urj_chain_t *chain, urj_part_t *part, const char *opcode, int len) { urj_data_register_t *dr; @@ -357,102 +357,72 @@ fjmem_query_blocks (urj_chain_t *chain, urj_part_t *part, urj_bus_t *bus) */ static urj_bus_t * fjmem_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *params[]) + const urj_param_t *params[]) { urj_bus_t *bus = NULL; int failed = 0; urj_part_t *part; - char *opcode = NULL; + const char *opcode = NULL; int fjmem_reg_len = 0; int idx; - part = chain->parts->parts[chain->active_part]; + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) + return NULL; + part = bus->part; /* parse parameters */ - for (idx = 2; idx < urj_cmd_params (params); idx++) + for (idx = 0; params[idx] != NULL; idx++) { - char *comma, *value; - - comma = strchr (params[idx], '='); - if (comma == NULL) - { - // @@@@ RFHH bail out? - urj_error_set (URJ_ERROR_SYNTAX, - _("Wrong parameter specification: %s"), params[idx]); - continue; - } - - /* set value and terminate parameter name string */ - value = comma + 1; - *comma = '\0'; - - if (strcasecmp (params[idx], "opcode") == 0) - opcode = value; - if (strcasecmp (params[idx], "len") == 0) + switch (params[idx]->key) { - long unsigned tmp; - urj_cmd_get_number (value, &tmp); - fjmem_reg_len = (int) tmp; + case URJ_BUS_PARAM_KEY_OPCODE: + opcode = params[idx]->value.string; + break; + case URJ_BUS_PARAM_KEY_LEN: + fjmem_reg_len = params[idx]->value.lu; + break; + default: + urj_bus_generic_free (bus); + urj_error_set (URJ_ERROR_SYNTAX, "unrecognized bus parameter '%s'", + urj_param_string(&urj_bus_param_list, params[idx])); + return NULL; } } - if (opcode) + if (opcode == NULL) { - block_desc_t *bd; + urj_bus_generic_free (bus); + urj_error_set (URJ_ERROR_SYNTAX, + _("Parameter for instruction opcode missing")); + return NULL; + } - fjmem_reg_len = - fjmem_detect_reg_len (chain, part, opcode, fjmem_reg_len); - if (fjmem_reg_len <= 0) - return NULL; + block_desc_t *bd; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } + fjmem_reg_len = fjmem_detect_reg_len (chain, part, opcode, fjmem_reg_len); + if (fjmem_reg_len <= 0) + return NULL; - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = chain->parts->parts[chain->active_part]; - FJMEM_REG = urj_part_find_data_register (bus->part, FJMEM_REG_NAME); - bd = &(BLOCK_DESC); - bd->blocks = NULL; - bd->reg_len = fjmem_reg_len; - bd->instr_pos = 0; - bd->block_pos = bd->instr_pos + 4; /* 3 bits for instruction field, 1 bit ack field */ + bus->chain = chain; + // @@@@ RFHH check result + FJMEM_REG = urj_part_find_data_register (part, FJMEM_REG_NAME); + bd = &(BLOCK_DESC); + bd->blocks = NULL; + bd->reg_len = fjmem_reg_len; + bd->instr_pos = 0; + bd->block_pos = bd->instr_pos + 4; /* 3 bits for instruction field, 1 bit ack field */ - if (fjmem_detect_fields (chain, part, bus) > 0) - { - if (fjmem_query_blocks (chain, part, bus) > 0) - { - } - else - failed |= 1; - } - else - failed |= 1; + if (fjmem_detect_fields (chain, part, bus) <= 0) + failed |= 1; + else if (fjmem_query_blocks (chain, part, bus) <= 0) + failed |= 1; - if (failed) - { - free (bus->params); - free (bus); - return NULL; - } + if (failed) + { + urj_bus_generic_free (bus); + return NULL; } - else - urj_error_set (URJ_ERROR_SYNTAX, - _("Parameter for instruction opcode missing")); return bus; } diff --git a/urjtag/src/bus/generic_bus.c b/urjtag/src/bus/generic_bus.c index 57657025..c04afd0b 100644 --- a/urjtag/src/bus/generic_bus.c +++ b/urjtag/src/bus/generic_bus.c @@ -46,6 +46,37 @@ urj_bus_generic_attach_sig (urj_part_t *part, urj_part_signal_t **sig, return URJ_STATUS_OK; } +urj_bus_t * +urj_bus_generic_new (urj_chain_t *chain, const urj_bus_driver_t *driver, + size_t param_size) +{ + urj_bus_t *bus; + + bus = calloc (1, sizeof (urj_bus_t)); + if (bus == NULL) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", + (size_t) 1, sizeof (urj_bus_t)); + return NULL; + } + + bus->driver = driver; + bus->params = calloc (1, param_size); + if (bus->params == NULL) + { + free (bus); + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", + (size_t) 1, param_size); + return NULL; + } + + bus->chain = chain; + // @@@@ RFHH shouldn't we verify chain->active_part etc? + bus->part = chain->parts->parts[chain->active_part]; + + return bus; +} + /** * bus->driver->(*free_bus) * diff --git a/urjtag/src/bus/generic_bus.h b/urjtag/src/bus/generic_bus.h index 704a0e3d..37faccbb 100644 --- a/urjtag/src/bus/generic_bus.h +++ b/urjtag/src/bus/generic_bus.h @@ -25,11 +25,16 @@ #ifndef URJ_BUS_GENERIC_BUS_H #define URJ_BUS_GENERIC_BUS_H +#include + #include int urj_bus_generic_attach_sig (urj_part_t *part, urj_part_signal_t **sig, char *id); +urj_bus_t *urj_bus_generic_new (urj_chain_t *chain, + const urj_bus_driver_t *driver, + size_t param_size); void urj_bus_generic_free (urj_bus_t *bus); int urj_bus_generic_no_init (urj_bus_t *bus); void urj_bus_generic_prepare_extest (urj_bus_t *bus); diff --git a/urjtag/src/bus/h7202.c b/urjtag/src/bus/h7202.c index 3db9fe20..99aa01c4 100644 --- a/urjtag/src/bus/h7202.c +++ b/urjtag/src/bus/h7202.c @@ -58,7 +58,7 @@ typedef struct */ static urj_bus_t * h7202_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -66,26 +66,10 @@ h7202_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 25; i++) { @@ -115,8 +99,7 @@ h7202_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/ixp425.c b/urjtag/src/bus/ixp425.c index a8afd00a..53a2b27a 100644 --- a/urjtag/src/bus/ixp425.c +++ b/urjtag/src/bus/ixp425.c @@ -58,7 +58,7 @@ typedef struct */ static urj_bus_t * ixp425_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -66,26 +66,10 @@ ixp425_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 8; i++) { @@ -111,8 +95,7 @@ ixp425_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/ixp435.c b/urjtag/src/bus/ixp435.c index f74864c7..da14da7e 100644 --- a/urjtag/src/bus/ixp435.c +++ b/urjtag/src/bus/ixp435.c @@ -58,7 +58,7 @@ typedef struct { */ static urj_bus_t * ixp435_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -66,26 +66,10 @@ ixp435_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 4; i++) { sprintf (buff, "ex_cs_n%d", i); @@ -107,8 +91,7 @@ ixp435_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, failed |= urj_bus_generic_attach_sig (part, &(EX_RD), "ex_rd_n"); if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/jopcyc.c b/urjtag/src/bus/jopcyc.c index 8c383f20..b27754b9 100644 --- a/urjtag/src/bus/jopcyc.c +++ b/urjtag/src/bus/jopcyc.c @@ -139,33 +139,17 @@ typedef struct */ static urj_bus_t * jopcyc_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; int failed = 0; component_t *comp; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; /* * Setup RAMA @@ -338,8 +322,7 @@ jopcyc_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/lh7a400.c b/urjtag/src/bus/lh7a400.c index 91def20f..7a5c4191 100644 --- a/urjtag/src/bus/lh7a400.c +++ b/urjtag/src/bus/lh7a400.c @@ -74,7 +74,7 @@ typedef struct */ static urj_bus_t * lh7a400_bus_new (urj_chain_t *chain, const const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -82,26 +82,10 @@ lh7a400_bus_new (urj_chain_t *chain, const const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < ADR_NUM; i++) { @@ -133,8 +117,7 @@ lh7a400_bus_new (urj_chain_t *chain, const const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/mpc5200.c b/urjtag/src/bus/mpc5200.c index 977482c3..895f699b 100644 --- a/urjtag/src/bus/mpc5200.c +++ b/urjtag/src/bus/mpc5200.c @@ -74,7 +74,7 @@ typedef struct */ static urj_bus_t * mpc5200_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; bus_params_t *bp; @@ -83,40 +83,35 @@ mpc5200_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = bp = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } + part = bus->part; + bp = bus->params; bp->lpc_num_ad = 24; bp->lpc_num_d = 8; - if (cmd_params[2] && !strncasecmp ("MUX", cmd_params[2], 3)) + for (i = 0; cmd_params[i] != NULL; i++) { - bp->lpc_num_ad = 25; - bp->lpc_num_d = 16; - bp->muxed = 1; + switch (cmd_params[i]->key) + { + case URJ_BUS_PARAM_KEY_MUX: + bp->lpc_num_ad = 25; + bp->lpc_num_d = 16; + bp->muxed = 1; + break; + default: + urj_bus_generic_free (bus); + urj_error_set (URJ_ERROR_SYNTAX, "unrecognised bus parameter '%s'", + urj_param_string(&urj_bus_param_list, cmd_params[i])); + return NULL; + } } urj_log (URJ_LOG_LEVEL_NORMAL, "%sMUXed %db address, %db data bus\n", (bp->muxed ? "" : "Non-"), bp->lpc_num_ad, bp->lpc_num_d); - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; - /* Get the signals */ for (i = 0; i < LPC_NUM_AD; i++) { @@ -140,8 +135,7 @@ mpc5200_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/mpc824x.c b/urjtag/src/bus/mpc824x.c index ee41a5b0..0d9b6e11 100644 --- a/urjtag/src/bus/mpc824x.c +++ b/urjtag/src/bus/mpc824x.c @@ -74,7 +74,7 @@ static char dbgData = 0; */ static urj_bus_t * mpc824x_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -84,72 +84,69 @@ mpc824x_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, urj_part_signal_t *s_nfoe; urj_part_signal_t *s_sdma1; - char param[16], value[16]; - char dfltWidth = 1; dbgAddr = 0; dbgData = 0; REVBITS = 0; - for (i = 2; cmd_params[i]; i++) + for (i = 0; cmd_params[i] != NULL; i++) { - if (strstr (cmd_params[i], "=")) + switch (cmd_params[i]->key) { - sscanf (cmd_params[i], "%[^=]%*c%s", param, value); - - if (!strcmp ("width", param)) + case URJ_BUS_PARAM_KEY_WIDTH: + switch (cmd_params[i]->value.lu) { - if (!strcmp ("8", value)) - { - BUS_WIDTH = 8; - dfltWidth = 0; - } - else if (!strcmp ("32", value)) - { - BUS_WIDTH = 32; - dfltWidth = 0; - } - else if (!strcmp ("64", value)) - { - // BUS_WIDTH = 64; // Needs to fix, look at setup_data() - BUS_WIDTH = 32; - urj_error_set (URJ_ERROR_UNSUPPORTED, - _(" Bus width 64 exists in mpc824x, but not supported by UrJTAG currently")); - dfltWidth = 1; - } - else - { - urj_error_set (URJ_ERROR_UNSUPPORTED, - _(" Only 8,32 and 64 bus width are supported for Banks 0 and 1")); - return NULL; - } - } - } - else - { - if (!strcmp ("revbits", cmd_params[i])) - REVBITS = 1; - - if (!strcmp ("help", cmd_params[i])) - { - urj_log (URJ_LOG_LEVEL_NORMAL, - _("Usage: initbus mpc824x [width=WIDTH] [revbits] [dbgAddr] [dbgData]\n\n" - " WIDTH data bus width - 8, 32, 64 (default 8)\n" - " revbits reverse bits in data bus (default - no)\n" - " dbgAddr display address bus state (default - no)\n" - " dbgData display data bus state (default - no)\n")); + case 8: + BUS_WIDTH = 8; + dfltWidth = 0; + break; + case 32: + BUS_WIDTH = 32; + dfltWidth = 0; + break; + case 64: + // BUS_WIDTH = 64; // Needs to fix, look at setup_data() + BUS_WIDTH = 32; + urj_error_set (URJ_ERROR_UNSUPPORTED, + _(" Bus width 64 exists in mpc824x, but not supported by UrJTAG currently")); + dfltWidth = 1; + break; + default: + urj_error_set (URJ_ERROR_UNSUPPORTED, + _(" Only 8,32 and 64 bus width are supported for Banks 0 and 1")); return NULL; } + break; - if (!strcmp ("dbgAddr", cmd_params[i])) - dbgAddr = 1; - + case URJ_BUS_PARAM_KEY_REVBITS: + REVBITS = 1; + break; - if (!strcmp ("dbgData", cmd_params[i])) - dbgData = 1; + // @@@@ RFHH ToDo: lift this from init_bus + case URJ_BUS_PARAM_KEY_HELP: + urj_log (URJ_LOG_LEVEL_NORMAL, + _("Usage: initbus mpc824x [width=WIDTH] [revbits] [dbgAddr] [dbgData]\n\n" + " WIDTH data bus width - 8, 32, 64 (default 8)\n" + " revbits reverse bits in data bus (default - no)\n" + " dbgAddr display address bus state (default - no)\n" + " dbgData display data bus state (default - no)\n")); + return NULL; + + // @@@@ RFHH ToDo: lift this from init_bus + case URJ_BUS_PARAM_KEY_DBGaDDR: + dbgAddr = 1; + break; + // @@@@ RFHH ToDo: lift this from init_bus + case URJ_BUS_PARAM_KEY_DBGdATA: + dbgData = 1; + break; + default: + urj_error_set (URJ_ERROR_SYNTAX, "unrecognised bus parameter '%s'", + urj_param_string(&urj_bus_param_list, cmd_params[i])); + return NULL; } } @@ -159,26 +156,10 @@ mpc824x_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, // REVBITS = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; s_nfoe = urj_part_find_signal (part, "nFOE"); s_sdma1 = urj_part_find_signal (part, "SDMA1"); @@ -241,8 +222,7 @@ mpc824x_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/ppc405ep.c b/urjtag/src/bus/ppc405ep.c index cf0fc9db..c2e5303c 100644 --- a/urjtag/src/bus/ppc405ep.c +++ b/urjtag/src/bus/ppc405ep.c @@ -58,7 +58,7 @@ typedef struct */ static urj_bus_t * ppc405ep_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -66,26 +66,10 @@ ppc405ep_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 6; i < 32; i++) { @@ -107,8 +91,7 @@ ppc405ep_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/ppc440gx_ebc8.c b/urjtag/src/bus/ppc440gx_ebc8.c index c8fe5334..24eed8db 100644 --- a/urjtag/src/bus/ppc440gx_ebc8.c +++ b/urjtag/src/bus/ppc440gx_ebc8.c @@ -58,7 +58,7 @@ typedef struct */ static urj_bus_t * ppc440gx_ebc8_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -66,26 +66,10 @@ ppc440gx_ebc8_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < PPC440GX_ADDR_LINES; i++) { @@ -107,8 +91,7 @@ ppc440gx_ebc8_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/prototype.c b/urjtag/src/bus/prototype.c index de3917c1..63102950 100644 --- a/urjtag/src/bus/prototype.c +++ b/urjtag/src/bus/prototype.c @@ -69,7 +69,7 @@ typedef struct #define ASHIFT ((bus_params_t *) bus->params)->ashift static void -prototype_bus_signal_parse (char *str, char *fmt, int *inst) +prototype_bus_signal_parse (const char *str, char *fmt, int *inst) { char pre[16], suf[16]; @@ -84,6 +84,7 @@ prototype_bus_signal_parse (char *str, char *fmt, int *inst) case 3: sprintf (fmt, "%s%s%s", pre, "%d", suf); } + // @@@@ RFHH what about failure? } /** @@ -92,113 +93,126 @@ prototype_bus_signal_parse (char *str, char *fmt, int *inst) */ static urj_bus_t * prototype_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_signal_t *sig; - char buff[16], fmt[16], afmt[16], dfmt[16], param[16], value[16]; + char buff[16], fmt[16], afmt[16], dfmt[16]; int i, j, inst, max, min; int failed = 0; int ashift = -1; + const char *value; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->chain = chain; - bus->part = chain->parts->parts[chain->active_part]; CS = OE = WE = NULL; ALSBI = AMSBI = DLSBI = DMSBI = -1; - for (i = 2; cmd_params[i]; i++) + for (i = 0; cmd_params[i] != NULL; i++) { - if (!strstr (cmd_params[i], "=")) - continue; - sscanf (cmd_params[i], "%[^=]%*c%s", param, value); - - if (!strcmp ("amode", param)) + if (cmd_params[i]->key == URJ_BUS_PARAM_KEY_AMODE || + cmd_params[i]->key == URJ_BUS_PARAM_KEY_WIDTH) { - if (!strcmp ("x8", value)) + switch (cmd_params[i]->value.lu) + { + case 8: ashift = 0; - else if (!strcmp ("x16", value)) + break; + case 16: ashift = 1; - else if (!strcmp ("x32", value)) + break; + case 32: ashift = 2; - else if (strcmp ("auto", value)) - urj_error_set (URJ_ERROR_INVALID, - _("value %s not defined for parameter %s"), - value, param); - continue; - } + break; + case 0: // "auto" + break; - prototype_bus_signal_parse (value, fmt, &inst); - if (inst > 31) - continue; + default: + urj_error_set (URJ_ERROR_INVALID, + _("value %lu not defined for parameter %s"), + cmd_params[i]->value.lu, + urj_param_string(&urj_bus_param_list, + cmd_params[i])); + failed = 1; // @@@@ RFHH + break; + } - sig = urj_part_find_signal (bus->part, value); - if (!sig) - { - urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"), - value); - failed = 1; - } - else if (!strcmp ("alsb", param)) - { - ALSBI = inst; - A[inst] = sig; - strcpy (afmt, fmt); - } - else if (!strcmp ("amsb", param)) - { - AMSBI = inst; - A[inst] = sig; - strcpy (afmt, fmt); - } - else if (!strcmp ("dlsb", param)) - { - DLSBI = inst; - D[inst] = sig; - strcpy (dfmt, fmt); - } - else if (!strcmp ("dmsb", param)) - { - DMSBI = inst; - D[inst] = sig; - strcpy (dfmt, fmt); - } - else if (!(strcmp ("cs", param) && strcmp ("ncs", param))) - { - CS = sig; - CSA = (*param == 'n') ? 0 : 1; - } - else if (!(strcmp ("oe", param) && strcmp ("noe", param))) - { - OE = sig; - OEA = (*param == 'n') ? 0 : 1; - } - else if (!(strcmp ("we", param) && strcmp ("nwe", param))) - { - WE = sig; - WEA = (*param == 'n' ? 0 : 1); } else { - urj_error_set (URJ_ERROR_INVALID, _("parameter %s is unknown"), - param); - failed = 1; + if (cmd_params[i]->type != URJ_PARAM_TYPE_STRING) + { + urj_error_set (URJ_ERROR_SYNTAX, + "parameter must be of type string"); + failed = 1; + continue; + } + + value = cmd_params[i]->value.string; + + inst = 32; + prototype_bus_signal_parse (value, fmt, &inst); + // @@@@ RFHH Flag error? + // @@@@ RFHH If it is mandatory for a signal to have an int inst + // number, why does prototype_bus_signal_parse() accept values + // without an int? + if (inst > 31 || inst < 0) + continue; + + sig = urj_part_find_signal (bus->part, value); + if (!sig) + { + urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"), + value); + failed = 1; + continue; + } + + switch (cmd_params[i]->key) + { + case URJ_BUS_PARAM_KEY_ALSB: + ALSBI = inst; + A[inst] = sig; + strcpy (afmt, fmt); + break; + case URJ_BUS_PARAM_KEY_AMSB: + AMSBI = inst; + A[inst] = sig; + strcpy (afmt, fmt); + break; + case URJ_BUS_PARAM_KEY_DLSB: + DLSBI = inst; + D[inst] = sig; + strcpy (dfmt, fmt); + break; + case URJ_BUS_PARAM_KEY_DMSB: + DMSBI = inst; + D[inst] = sig; + strcpy (dfmt, fmt); + break; + case URJ_BUS_PARAM_KEY_CS: + case URJ_BUS_PARAM_KEY_NCS: + CS = sig; + CSA = (cmd_params[i]->key == URJ_BUS_PARAM_KEY_CS); + break; + case URJ_BUS_PARAM_KEY_OE: + case URJ_BUS_PARAM_KEY_NOE: + OE = sig; + OEA = (cmd_params[i]->key == URJ_BUS_PARAM_KEY_OE); + break; + case URJ_BUS_PARAM_KEY_WE: + case URJ_BUS_PARAM_KEY_NWE: + WE = sig; + WEA = (cmd_params[i]->key == URJ_BUS_PARAM_KEY_WE); + break; + default: + urj_error_set (URJ_ERROR_INVALID, _("parameter %s is unknown"), + urj_param_string(&urj_bus_param_list, + cmd_params[i])); + failed = 1; + break; + } } } @@ -230,6 +244,7 @@ prototype_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, for (i = 0, j = ALSBI; i < AW; i++, j += AI) { sprintf (buff, afmt, j); + // @@@@ RFHH check result A[j] = urj_part_find_signal (bus->part, buff); } } @@ -323,8 +338,7 @@ prototype_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } @@ -343,6 +357,7 @@ prototype_bus_printinfo (urj_log_level_t ll, urj_bus_t *bus) for (i = 0; i < bus->chain->parts->len; i++) if (bus->part == bus->chain->parts->parts[i]) break; + // @@@@ RFHH check for error 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 82669275..6f7812e5 100644 --- a/urjtag/src/bus/pxa2x0.c +++ b/urjtag/src/bus/pxa2x0.c @@ -143,7 +143,7 @@ typedef struct */ static urj_bus_t * pxa2xx_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_part_t *part; urj_bus_t *bus; @@ -156,34 +156,21 @@ pxa2xx_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, || chain->active_part < 0) return NULL; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } + part = bus->part; - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; if (strcmp (driver->name, "pxa2x0") == 0) PROC = PROC_PXA25x; else if (strcmp (driver->name, "pxa27x") == 0) PROC = PROC_PXA27x; else { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); + urj_error_set (URJ_ERROR_SYNTAX, + "driver must be 'pxa2x0' or 'pxa27x', not '%s'", + driver->name); return NULL; } @@ -242,8 +229,7 @@ pxa2xx_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/s3c4510x.c b/urjtag/src/bus/s3c4510x.c index 30be7238..473ee98c 100644 --- a/urjtag/src/bus/s3c4510x.c +++ b/urjtag/src/bus/s3c4510x.c @@ -102,7 +102,7 @@ typedef struct */ static urj_bus_t * s3c4510_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -110,27 +110,12 @@ s3c4510_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); - return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } + part = bus->part; dbus_width = 16; - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; for (i = 0; i < 22; i++) { @@ -172,8 +157,7 @@ s3c4510_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/sa1110.c b/urjtag/src/bus/sa1110.c index e9e6176e..ef61f4e2 100644 --- a/urjtag/src/bus/sa1110.c +++ b/urjtag/src/bus/sa1110.c @@ -63,7 +63,7 @@ typedef struct */ static urj_bus_t * sa1110_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -71,26 +71,10 @@ sa1110_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 26; i++) { @@ -118,8 +102,7 @@ sa1110_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/sh7727.c b/urjtag/src/bus/sh7727.c index b82d9f7b..3972361b 100644 --- a/urjtag/src/bus/sh7727.c +++ b/urjtag/src/bus/sh7727.c @@ -64,7 +64,7 @@ typedef struct */ static urj_bus_t * sh7727_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -72,26 +72,10 @@ sh7727_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 26; i++) { @@ -129,8 +113,7 @@ sh7727_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/sh7750r.c b/urjtag/src/bus/sh7750r.c index c228be2a..db3a047d 100644 --- a/urjtag/src/bus/sh7750r.c +++ b/urjtag/src/bus/sh7750r.c @@ -64,7 +64,7 @@ typedef struct */ static urj_bus_t * sh7750r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -72,25 +72,10 @@ sh7750r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 26; i++) { @@ -126,8 +111,7 @@ sh7750r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/sh7751r.c b/urjtag/src/bus/sh7751r.c index ca6d987f..33ba2586 100644 --- a/urjtag/src/bus/sh7751r.c +++ b/urjtag/src/bus/sh7751r.c @@ -62,7 +62,7 @@ typedef struct */ static urj_bus_t * sh7751r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -70,27 +70,10 @@ sh7751r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 26; i++) { @@ -122,8 +105,7 @@ sh7751r_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/sharc21065l.c b/urjtag/src/bus/sharc21065l.c index 74745f52..b1ac3036 100644 --- a/urjtag/src/bus/sharc21065l.c +++ b/urjtag/src/bus/sharc21065l.c @@ -66,7 +66,7 @@ typedef struct */ static urj_bus_t * sharc_21065L_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -74,26 +74,10 @@ sharc_21065L_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 19; i++) { @@ -115,8 +99,7 @@ sharc_21065L_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/slsup3.c b/urjtag/src/bus/slsup3.c index 642d45fc..c9703c1d 100644 --- a/urjtag/src/bus/slsup3.c +++ b/urjtag/src/bus/slsup3.c @@ -98,7 +98,7 @@ typedef struct */ static urj_bus_t * slsup3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -106,26 +106,10 @@ slsup3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; for (i = 0; i < 20; i++) { @@ -163,8 +147,7 @@ slsup3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/tx4925.c b/urjtag/src/bus/tx4925.c index 6de44318..186ccc49 100644 --- a/urjtag/src/bus/tx4925.c +++ b/urjtag/src/bus/tx4925.c @@ -72,7 +72,7 @@ typedef struct */ static urj_bus_t * tx4925_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -80,26 +80,10 @@ tx4925_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, int i; int failed = 0; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; failed |= urj_bus_generic_attach_sig (part, &(OE), "OE"); @@ -131,8 +115,7 @@ tx4925_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/bus/zefant-xs3.c b/urjtag/src/bus/zefant-xs3.c index 9803618d..63b22703 100644 --- a/urjtag/src/bus/zefant-xs3.c +++ b/urjtag/src/bus/zefant-xs3.c @@ -157,7 +157,7 @@ typedef struct */ static urj_bus_t * zefant_xs3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, - char *cmd_params[]) + const urj_param_t *cmd_params[]) { urj_bus_t *bus; urj_part_t *part; @@ -165,26 +165,10 @@ zefant_xs3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, component_t *comp; int idx; - bus = calloc (1, sizeof (urj_bus_t)); - if (!bus) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_bus_t)); + bus = urj_bus_generic_new (chain, driver, sizeof (bus_params_t)); + if (bus == NULL) return NULL; - } - - bus->driver = driver; - bus->params = calloc (1, sizeof (bus_params_t)); - if (!bus->params) - { - free (bus); - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (bus_params_t)); - return NULL; - } - - bus->chain = chain; - bus->part = part = chain->parts->parts[chain->active_part]; + part = bus->part; /* * Setup FLASH @@ -413,8 +397,7 @@ zefant_xs3_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver, if (failed) { - free (bus->params); - free (bus); + urj_bus_generic_free (bus); return NULL; } diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index f1716823..67020f17 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -42,9 +42,15 @@ static int cmd_cable_run (urj_chain_t *chain, char *params[]) { - urj_cable_t *cable; + urj_cable_t *cable = NULL; int i; + int j; int paramc = urj_cmd_params (params); + const urj_param_t **cable_params; + urj_cable_parport_devtype_t devtype = -1; + const char *devname = NULL; + int param_start = 2; + urj_cable_driver_t *driver; /* we need at least one parameter for 'cable' command */ if (paramc < 2) @@ -57,7 +63,8 @@ cmd_cable_run (urj_chain_t *chain, char *params[]) /* maybe old syntax was used? search connection type driver */ for (i = 0; urj_tap_parport_drivers[i]; i++) - if (strcasecmp (params[1], urj_tap_parport_drivers[i]->type) == 0) + if (strcasecmp (params[1], + urj_cable_parport_devtype_string(urj_tap_parport_drivers[i]->type)) == 0) break; if (urj_tap_parport_drivers[i] != 0) @@ -85,59 +92,70 @@ cmd_cable_run (urj_chain_t *chain, char *params[]) for (i = 0; urj_tap_cable_drivers[i]; i++) if (strcasecmp (params[1], urj_tap_cable_drivers[i]->name) == 0) break; - if (!urj_tap_cable_drivers[i]) + driver = urj_tap_cable_drivers[i]; + if (!driver) { urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown cable type: '%s'"), params[1]); return URJ_STATUS_FAIL; } - if (paramc >= 3) + if (paramc >= 3 && strcasecmp (params[2], "help") == 0) { - if (strcasecmp (params[2], "help") == 0) - { - urj_tap_cable_drivers[i]->help (URJ_LOG_LEVEL_NORMAL, - urj_tap_cable_drivers[i]->name); - return URJ_STATUS_OK; - } + driver->help (URJ_LOG_LEVEL_NORMAL, driver->name); + return URJ_STATUS_OK; } - if (urj_bus) + if (driver->device_type == URJ_CABLE_DEVICE_PARPORT) { - URJ_BUS_FREE (urj_bus); - urj_bus = NULL; - } - - urj_tap_chain_disconnect (chain); + if (paramc < 4) + { + urj_error_set (URJ_ERROR_SYNTAX, + "parallel cable requires >= 4 parameters"); + return URJ_STATUS_FAIL; + } + for (j = 0; j < URJ_CABLE_PARPORT_N_DEVS; j++) + if (strcasecmp (params[2], + urj_cable_parport_devtype_string(j)) == 0) + break; + if (j == URJ_CABLE_PARPORT_N_DEVS) + { + urj_error_set (URJ_ERROR_INVALID, + "unknown parallel port device type '%s'", params[2]); + return URJ_STATUS_FAIL; + } - cable = calloc (1, sizeof (urj_cable_t)); - if (!cable) - { - urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", - (size_t) 1, sizeof (urj_cable_t)); - return URJ_STATUS_FAIL; + devtype = j; + devname = params[3]; + param_start = 4; } - cable->driver = urj_tap_cable_drivers[i]; + urj_param_init (&cable_params); + for (j = param_start; params[j] != NULL; j++) + if (urj_param_push (&urj_cable_param_list, &cable_params, + params[j]) != URJ_STATUS_OK) + { + urj_param_clear (&cable_params); + return URJ_STATUS_FAIL; + } - if (cable->driver->connect (++params, cable)) + switch (driver->device_type) { - free (cable); - return URJ_STATUS_FAIL; + case URJ_CABLE_DEVICE_PARPORT: + cable = urj_tap_cable_parport_connect (chain, driver, devtype, devname, + cable_params); + break; + case URJ_CABLE_DEVICE_USB: + cable = urj_tap_cable_usb_connect (chain, driver, cable_params); + break; + case URJ_CABLE_DEVICE_OTHER: + cable = urj_tap_cable_other_connect (chain, driver, cable_params); + break; } - chain->cable = cable; - - if (urj_tap_cable_init (chain->cable)) - { - urj_tap_chain_disconnect (chain); - return URJ_STATUS_FAIL; - } - urj_tap_chain_set_trst (chain, 0); - urj_tap_chain_set_trst (chain, 1); - urj_tap_reset (chain); + urj_param_clear (&cable_params); - return URJ_STATUS_OK; + return cable == NULL ? URJ_STATUS_FAIL : URJ_STATUS_OK; } static void diff --git a/urjtag/src/cmd/cmd_initbus.c b/urjtag/src/cmd/cmd_initbus.c index 2a36f797..1e2f5ee5 100644 --- a/urjtag/src/cmd/cmd_initbus.c +++ b/urjtag/src/cmd/cmd_initbus.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,7 @@ static int cmd_initbus_run (urj_chain_t *chain, char *params[]) { int i; + const urj_param_t **bus_params; if (urj_cmd_params (params) < 2) { @@ -56,37 +58,33 @@ cmd_initbus_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_FAIL; for (i = 0; urj_bus_drivers[i] != NULL; i++) - { if (strcasecmp (urj_bus_drivers[i]->name, params[1]) == 0) + break; + + if (urj_bus_drivers[i] == NULL) + { + urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown bus: %s"), params[1]); + return URJ_STATUS_FAIL; + } + + urj_param_init (&bus_params); + for (i = 2; params[i] != NULL; i++) + if (urj_param_push (&urj_bus_param_list, &bus_params, + params[i]) != URJ_STATUS_OK) { - urj_bus_t *abus = urj_bus_drivers[i]->new_bus (chain, - urj_bus_drivers[i], - params); - if (abus == NULL) - { - // @@@@ 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 URJ_STATUS_OK; + urj_param_clear (&bus_params); + return URJ_STATUS_FAIL; } + + if (urj_bus_init_bus(chain, urj_bus_drivers[i], bus_params) == NULL) + { + urj_param_clear (&bus_params); + return URJ_STATUS_FAIL; } - urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown bus: %s"), params[1]); - return URJ_STATUS_FAIL; + urj_param_clear (&bus_params); + + return URJ_STATUS_OK; } static void diff --git a/urjtag/src/cmd/cmd_signal.c b/urjtag/src/cmd/cmd_signal.c index 8a629a9c..23454850 100644 --- a/urjtag/src/cmd/cmd_signal.c +++ b/urjtag/src/cmd/cmd_signal.c @@ -61,19 +61,17 @@ cmd_signal_run (urj_chain_t *chain, char *params[]) if ((s = urj_part_find_signal (part, params[1])) != NULL) { - if (i == 3) - { - urj_log (URJ_LOG_LEVEL_NORMAL, "Defining pin for signal %s\n", - s->name); - - return urj_part_signal_redefine_pin(chain, s, params[2]); - } - else + if (i != 3) { urj_error_set (URJ_ERROR_ALREADY, _("Signal '%s' already defined"), params[1]); return URJ_STATUS_FAIL; } + + urj_log (URJ_LOG_LEVEL_NORMAL, "Defining pin for signal %s\n", + s->name); + + return urj_part_signal_redefine_pin(chain, s, params[2]); } if (i == 3) diff --git a/urjtag/src/global/Makefile.am b/urjtag/src/global/Makefile.am index d1694f47..fb7b7d3c 100644 --- a/urjtag/src/global/Makefile.am +++ b/urjtag/src/global/Makefile.am @@ -27,8 +27,9 @@ noinst_LTLIBRARIES = libglobal.la libglobal_la_SOURCES = \ parse.c \ - urjtag.c \ - data_dir.c + log-error.c \ + data_dir.c \ + params.c AM_CPPFLAGS = -DJTAG_BIN_DIR=\"$(bindir)\" -DJTAG_DATA_DIR=\"$(pkgdatadir)\" diff --git a/urjtag/src/global/urjtag.c b/urjtag/src/global/log-error.c similarity index 100% rename from urjtag/src/global/urjtag.c rename to urjtag/src/global/log-error.c diff --git a/urjtag/src/global/params.c b/urjtag/src/global/params.c new file mode 100644 index 00000000..b1d7aa6e --- /dev/null +++ b/urjtag/src/global/params.c @@ -0,0 +1,337 @@ +/* + * $Id: buses.c 1606 2009-05-19 15:06:20Z rfhh $ + * + * Copyright (C) 2003 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2003. + * + */ + +#include + +#include +#include + +#include +#include + +static const char * +urj_param_key_string(const urj_param_list_t *params, int key) +{ + int i; + + for (i = 0; i < params->n; i++) + if (key == params->list[i].key) + return params->list[i].string; + + return ""; +} + +static int +urj_param_parse_key(const urj_param_list_t *params, const char *p) +{ + int i; + const char *eq; + + eq = strchr(p, '='); + if (eq == NULL) + eq = p + strlen(p); + + for (i = 0; i < params->n; i++) + if (strncasecmp(params->list[i].string, p, eq - p) == 0) + return params->list[i].key; + + urj_error_set (URJ_ERROR_SYNTAX, "unrecognized param key '%s'", p); + return -1; +} + +static urj_param_type_t +urj_param_type_of(const urj_param_list_t *params, int key) +{ + int i; + + for (i = 0; i < params->n; i++) + if (params->list[i].key == key) + return params->list[i].type; + + urj_error_set (URJ_ERROR_INVALID, "unknown key %d", key); + return -1; +} + +static urj_param_t * +urj_param_increase (const urj_param_t ***bp) +{ + size_t n; + const urj_param_t **scan; + urj_param_t *new_p; + + scan = *bp; + for (n = 0; scan[n] != NULL; n++) + { + // count + } + + scan = realloc (*bp, (n + 2) * sizeof *scan); + if (scan == NULL) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "realloc(%s,%zd) fails", + "*bp", (n + 2) * sizeof *scan); + return NULL; + } + + *bp = scan; + + new_p = malloc (sizeof *new_p); + if (new_p == NULL) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", + sizeof *new_p); + return NULL; + } + + (*bp)[n] = new_p; + (*bp)[n + 1] = NULL; + + return new_p; +} + +static int +urj_param_decrease (const urj_param_t ***bp) +{ + size_t n; + const urj_param_t **scan; + + scan = *bp; + for (n = 0; scan[n] != NULL; n++) + { + // count + } + + if (n > 0) + { + --n; + free ((void *) (*bp)[n]); // Yes, I know why I cast + (*bp)[n] = NULL; + } + + return URJ_STATUS_OK; +} + +int +urj_param_push_string (const urj_param_t ***bp, int key, const char *val) +{ + urj_param_t *new_p = urj_param_increase (bp); + + if (new_p == NULL) + return URJ_STATUS_FAIL; + + new_p->type = URJ_PARAM_TYPE_STRING; + new_p->key = key; + new_p->value.string = val; + + return URJ_STATUS_OK; +} + +int +urj_param_push_lu (const urj_param_t ***bp, int key, long unsigned val) +{ + urj_param_t *new_p = urj_param_increase (bp); + + if (new_p == NULL) + return URJ_STATUS_FAIL; + + new_p->type = URJ_PARAM_TYPE_LU; + new_p->key = key; + new_p->value.lu = val; + + return URJ_STATUS_OK; +} + +int +urj_param_push_bool (const urj_param_t ***bp, int key, int val) +{ + urj_param_t *new_p = urj_param_increase (bp); + + if (new_p == NULL) + return URJ_STATUS_FAIL; + + new_p->type = URJ_PARAM_TYPE_BOOL; + new_p->key = key; + new_p->value.enabled = val; + + return URJ_STATUS_OK; +} + +static int +parse_param_lu(const char *eq, long unsigned *lu) +{ + if (sscanf(eq + 1, "%lu", lu) == 1) + return URJ_STATUS_OK; + + urj_error_set (URJ_ERROR_SYNTAX, "need unsigned int, not '%s'", eq + 1); + return URJ_STATUS_FAIL; +} + +static const char * +parse_param_string(const char *eq) +{ + return eq + 1; +} + +static int +parse_param_bool(const char *eq, int *enabled) +{ + if (eq == NULL) + { + *enabled = 1; + return URJ_STATUS_OK; + } + + if (sscanf(eq, "%d", enabled) == 1 && (*enabled == 0 || *enabled == 1)) + return URJ_STATUS_OK; + + urj_error_set (URJ_ERROR_SYNTAX, "need unsigned int, not '%s'", eq + 1); + return URJ_STATUS_FAIL; +} + +int +urj_param_push (const urj_param_list_t *params, const urj_param_t ***bp, + const char *p) +{ + int key; + urj_param_t *new_p; + int r = URJ_STATUS_OK; + const char *eq; + urj_param_type_t type; + + key = urj_param_parse_key(params, p); + if (key == -1) + return URJ_STATUS_FAIL; + + type = urj_param_type_of(params, key); + if (type == -1) + return URJ_STATUS_FAIL; + + eq = strchr(p, '='); + if (type != URJ_PARAM_TYPE_BOOL && eq == NULL) + { + urj_error_set (URJ_ERROR_SYNTAX, + "param should be of the form 'key=value', not '%s'", p); + return URJ_STATUS_FAIL; + } + + new_p = urj_param_increase (bp); + if (new_p == NULL) + return URJ_STATUS_FAIL; + + new_p->type = type; + new_p->key = key; + switch (new_p->type) + { + case URJ_PARAM_TYPE_LU: + r = parse_param_lu(eq, &new_p->value.lu); + break; + case URJ_PARAM_TYPE_STRING: + new_p->value.string = parse_param_string(eq); + if (new_p->value.string == NULL) + r = URJ_STATUS_FAIL; + break; + case URJ_PARAM_TYPE_BOOL: + r = parse_param_bool(eq, &new_p->value.enabled); + break; + } + + if (r == URJ_STATUS_FAIL) + urj_param_decrease (bp); + + return r; +} + +const char * +urj_param_string(const urj_param_list_t *params, const urj_param_t *p) +{ +#define PARAM_BUF_SIZE 256 + static char buf[PARAM_BUF_SIZE]; + size_t size; + + snprintf(buf, sizeof buf, "%s=", urj_param_key_string(params, p->key)); + size = strlen(buf); + + switch (p->type) + { + case URJ_PARAM_TYPE_LU: + snprintf(buf + size, sizeof buf - size, "%lu", p->value.lu); + break; + case URJ_PARAM_TYPE_STRING: + snprintf(buf + size, sizeof buf - size, "%s", p->value.string); + break; + case URJ_PARAM_TYPE_BOOL: + snprintf(buf + size, sizeof buf - size, "%s", + p->value.enabled ? "on" : "off"); + break; + default: + return "urj_param_string(): "; + } + + return buf; +} + +int +urj_param_init (const urj_param_t ***bp) +{ + *bp = calloc (1, sizeof **bp); + if (*bp == NULL) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", + (size_t) 1, sizeof **bp); + return URJ_STATUS_FAIL; + } + + *bp[0] = NULL; + + return URJ_STATUS_OK; +} + +int +urj_param_clear (const urj_param_t ***bp) +{ + const urj_param_t **scan; + + for (scan = *bp; *scan != NULL; scan++) + free ((void *) *scan); + + free (*bp); + + return URJ_STATUS_OK; +} + +size_t +urj_param_num (const urj_param_t *p[]) +{ + size_t n; + + if (p == NULL) + return 0; + + for (n = 0; p[n] != NULL; n++) + { + /* advance n */ + } + + return n; +} diff --git a/urjtag/src/tap/cable.c b/urjtag/src/tap/cable.c index f25473eb..1bb87dfd 100644 --- a/urjtag/src/tap/cable.c +++ b/urjtag/src/tap/cable.c @@ -37,6 +37,10 @@ #include #include +#include +#include +#include +#include #include #undef VERBOSE @@ -630,3 +634,127 @@ urj_tap_cable_wait (urj_cable_t *cable) j = i; } } + +static urj_cable_t * +urj_tap_cable_create (urj_chain_t *chain, urj_cable_driver_t *driver) +{ + urj_cable_t *cable; + + if (urj_bus) + { + URJ_BUS_FREE (urj_bus); + urj_bus = NULL; + } + + urj_tap_chain_disconnect (chain); + + cable = calloc (1, sizeof (urj_cable_t)); + if (!cable) + { + urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails", + (size_t) 1, sizeof (urj_cable_t)); + return NULL; + } + + cable->driver = driver; + + return cable; +} + +static int +urj_tap_cable_start (urj_chain_t *chain, urj_cable_t *cable) +{ + chain->cable = cable; + + if (urj_tap_cable_init (chain->cable) != URJ_STATUS_OK) + { + urj_tap_chain_disconnect (chain); + return URJ_STATUS_FAIL; + } + + urj_tap_chain_set_trst (chain, 0); + urj_tap_chain_set_trst (chain, 1); + urj_tap_reset (chain); + + return URJ_STATUS_OK; +} + +urj_cable_t * +urj_tap_cable_parport_connect (urj_chain_t *chain, urj_cable_driver_t *driver, + urj_cable_parport_devtype_t devtype, + const char *devname, const urj_param_t *params[]) +{ + urj_cable_t *cable = urj_tap_cable_create (chain, driver); + + if (cable == NULL) + return NULL; + + if (cable->driver->connect.parport (cable, devtype, devname, + params) != URJ_STATUS_OK) + { + free (cable); + return NULL; + } + + if (urj_tap_cable_start (chain, cable) != URJ_STATUS_OK) + return NULL; + + return cable; +} + +urj_cable_t * +urj_tap_cable_usb_connect (urj_chain_t *chain, urj_cable_driver_t *driver, + const urj_param_t *params[]) +{ + urj_cable_t *cable = urj_tap_cable_create (chain, driver); + + if (cable == NULL) + return NULL; + + if (cable->driver->connect.usb (cable, params) != URJ_STATUS_OK) + { + free (cable); + return NULL; + } + + if (urj_tap_cable_start (chain, cable) != URJ_STATUS_OK) + return NULL; + + return cable; +} + +urj_cable_t * +urj_tap_cable_other_connect (urj_chain_t *chain, urj_cable_driver_t *driver, + const urj_param_t *params[]) +{ + urj_cable_t *cable = urj_tap_cable_create (chain, driver); + + if (cable == NULL) + return NULL; + + if (cable->driver->connect.other (cable, params) != URJ_STATUS_OK) + { + free (cable); + return NULL; + } + + if (urj_tap_cable_start (chain, cable) != URJ_STATUS_OK) + return NULL; + + return cable; +} + +static urj_param_descr_t cable_param[] = +{ + { URJ_CABLE_PARAM_KEY_PID, URJ_PARAM_TYPE_LU, "pid", }, + { URJ_CABLE_PARAM_KEY_VID, URJ_PARAM_TYPE_LU, "vid", }, + { URJ_CABLE_PARAM_KEY_DESC, URJ_PARAM_TYPE_STRING, "desc", }, + { URJ_CABLE_PARAM_KEY_DRIVER, URJ_PARAM_TYPE_STRING, "driver", }, + { URJ_CABLE_PARAM_KEY_BITMAP, URJ_PARAM_TYPE_STRING, "bitmap", }, +}; + +const urj_param_list_t urj_cable_param_list = +{ + .list = cable_param, + .n = sizeof cable_param / sizeof cable_param[0], +}; diff --git a/urjtag/src/tap/cable/arcom.c b/urjtag/src/tap/cable/arcom.c index 72d2e49b..cc06a077 100644 --- a/urjtag/src/tap/cable/arcom.c +++ b/urjtag/src/tap/cable/arcom.c @@ -135,7 +135,8 @@ arcom_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_arcom_driver = { "ARCOM", N_("Arcom JTAG Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, arcom_init, diff --git a/urjtag/src/tap/cable/byteblaster.c b/urjtag/src/tap/cable/byteblaster.c index 58ba607f..8713058d 100644 --- a/urjtag/src/tap/cable/byteblaster.c +++ b/urjtag/src/tap/cable/byteblaster.c @@ -157,7 +157,8 @@ byteblaster_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_byteblaster_driver = { "ByteBlaster", N_("Altera ByteBlaster/ByteBlaster II/ByteBlasterMV Parallel Port Download Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, byteblaster_init, diff --git a/urjtag/src/tap/cable/dlc5.c b/urjtag/src/tap/cable/dlc5.c index 5f2d7f40..2354c76d 100644 --- a/urjtag/src/tap/cable/dlc5.c +++ b/urjtag/src/tap/cable/dlc5.c @@ -129,7 +129,8 @@ dlc5_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_dlc5_driver = { "DLC5", N_("Xilinx DLC5 JTAG Parallel Cable III"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, dlc5_init, diff --git a/urjtag/src/tap/cable/ea253.c b/urjtag/src/tap/cable/ea253.c index 7682012a..c9c063c8 100644 --- a/urjtag/src/tap/cable/ea253.c +++ b/urjtag/src/tap/cable/ea253.c @@ -135,7 +135,8 @@ ea253_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_ea253_driver = { "EA253", N_("ETC EA253 JTAG Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, ea253_init, diff --git a/urjtag/src/tap/cable/ei012.c b/urjtag/src/tap/cable/ei012.c index ee35db9b..1e863120 100644 --- a/urjtag/src/tap/cable/ei012.c +++ b/urjtag/src/tap/cable/ei012.c @@ -137,7 +137,8 @@ ei012_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_ei012_driver = { "EI012", N_("ETC EI012 JTAG Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, ei012_init, diff --git a/urjtag/src/tap/cable/ft2232.c b/urjtag/src/tap/cable/ft2232.c index 0de2b458..e2559560 100644 --- a/urjtag/src/tap/cable/ft2232.c +++ b/urjtag/src/tap/cable/ft2232.c @@ -1727,12 +1727,12 @@ ft2232_flush (urj_cable_t *cable, urj_cable_flush_amount_t how_much) static int -ft2232_connect (char *params[], urj_cable_t *cable) +ft2232_connect (urj_cable_t *cable, const urj_param_t *params[]) { params_t *cable_params; /* perform urj_tap_cable_generic_usbconn_connect */ - if (urj_tap_cable_generic_usbconn_connect (params, cable) != URJ_STATUS_OK) + if (urj_tap_cable_generic_usbconn_connect (cable, params) != URJ_STATUS_OK) return URJ_STATUS_FAIL; cable_params = malloc (sizeof (params_t)); @@ -1834,7 +1834,8 @@ ft2232_usbcable_help (urj_log_level_t ll, const char *cablename) urj_cable_driver_t urj_tap_cable_ft2232_driver = { "FT2232", N_("Generic FTDI FT2232 Cable"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_generic_init, @@ -1866,7 +1867,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_ft2232_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_armusbocd_driver = { "ARM-USB-OCD", N_("Olimex ARM-USB-OCD[-TINY] (FT2232) Cable"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_armusbocd_init, @@ -1912,7 +1914,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_armusbocdtiny_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_gnice_driver = { "gnICE", N_("Analog Devices Blackfin gnICE (FT2232) Cable (EXPERIMENTAL)"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_gnice_init, @@ -1944,7 +1947,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_gnice_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_jtagkey_driver = { "JTAGkey", N_("Amontec JTAGkey (FT2232) Cable"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_jtagkey_init, @@ -1976,7 +1980,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_jtagkey_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_oocdlinks_driver = { "OOCDLink-s", N_("OOCDLink-s (FT2232) Cable (EXPERIMENTAL)"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_oocdlinks_init, @@ -2008,7 +2013,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_oocdlinks_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_turtelizer2_driver = { "Turtelizer2", N_("Turtelizer 2 Rev. B (FT2232) Cable (EXPERIMENTAL)"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_turtelizer2_init, @@ -2040,7 +2046,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_turtelizer2_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_usbtojtagif_driver = { "USB-to-JTAG-IF", N_("USB to JTAG Interface (FT2232) Cable (EXPERIMENTAL)"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_usbtojtagif_init, @@ -2072,7 +2079,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_usbtojtagif_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_signalyzer_driver = { "Signalyzer", N_("Xverve DT-USB-ST Signalyzer Tool (FT2232) Cable (EXPERIMENTAL)"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_signalyzer_init, @@ -2104,7 +2112,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_signalyzer_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_flyswatter_driver = { "Flyswatter", N_("TinCanTools Flyswatter (FT2232) Cable"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_flyswatter_init, @@ -2136,7 +2145,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_flyswatter_ftd2xx = { urj_cable_driver_t urj_tap_cable_ft2232_usbscarab2_driver = { "usbScarab2", N_("KrisTech usbScarabeus2 (FT2232) Cable"), - ft2232_connect, + URJ_CABLE_DEVICE_USB, + { .usb = ft2232_connect, }, urj_tap_cable_generic_disconnect, ft2232_cable_free, ft2232_usbscarab2_init, diff --git a/urjtag/src/tap/cable/generic.c b/urjtag/src/tap/cable/generic.c index cada586c..2c54bca6 100644 --- a/urjtag/src/tap/cable/generic.c +++ b/urjtag/src/tap/cable/generic.c @@ -311,6 +311,7 @@ urj_tap_cable_generic_flush_using_transfer (urj_cable_t *cable, urj_log (URJ_LOG_LEVEL_DETAIL, "in: "); print_vector (URJ_LOG_LEVEL_DETAIL, bits, in); urj_log (URJ_LOG_LEVEL_DETAIL, "\n"); + // @@@@ RFHH here always: out != NULL if (out) { urj_log (URJ_LOG_LEVEL_DETAIL, "out: "); diff --git a/urjtag/src/tap/cable/generic_parport.c b/urjtag/src/tap/cable/generic_parport.c index 9e3dd2ba..00db7fd7 100644 --- a/urjtag/src/tap/cable/generic_parport.c +++ b/urjtag/src/tap/cable/generic_parport.c @@ -48,32 +48,34 @@ print_vector (urj_log_level_t ll, int len, char *vec) #endif int -urj_tap_cable_generic_parport_connect (char *params[], urj_cable_t *cable) +urj_tap_cable_generic_parport_connect (urj_cable_t *cable, + urj_cable_parport_devtype_t devtype, + const char *devname, + const urj_param_t *params[]) { urj_tap_cable_generic_params_t *cable_params; urj_parport_t *port; int i; - if (urj_cmd_params (params) < 3) + if (urj_param_num (params) > 0) { - urj_error_set (URJ_ERROR_SYNTAX, _("not enough arguments")); + urj_error_set (URJ_ERROR_SYNTAX, _("extra arguments")); return URJ_STATUS_FAIL; } /* search parport driver list */ for (i = 0; urj_tap_parport_drivers[i]; i++) - if (strcasecmp (params[1], urj_tap_parport_drivers[i]->type) == 0) + if (devtype == urj_tap_parport_drivers[i]->type) break; if (!urj_tap_parport_drivers[i]) { - urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown port driver: %s"), - params[1]); + urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown port type: %s"), + urj_cable_parport_devtype_string(devtype)); return URJ_STATUS_FAIL; } /* set up parport driver */ - port = urj_tap_parport_drivers[i]->connect ((const char **) ¶ms[2], - urj_cmd_params (params) - 2); + port = urj_tap_parport_drivers[i]->connect (devname); if (port == NULL) { diff --git a/urjtag/src/tap/cable/generic_parport.h b/urjtag/src/tap/cable/generic_parport.h index 10249268..b7ced65f 100644 --- a/urjtag/src/tap/cable/generic_parport.h +++ b/urjtag/src/tap/cable/generic_parport.h @@ -28,8 +28,10 @@ #include #include -int urj_tap_cable_generic_parport_connect (char *params[], - urj_cable_t *cable); +int urj_tap_cable_generic_parport_connect (urj_cable_t *cable, + urj_cable_parport_devtype_t devtype, + const char *devname, + const urj_param_t *params[]); void urj_tap_cable_generic_parport_free (urj_cable_t *cable); void urj_tap_cable_generic_parport_done (urj_cable_t *cable); void urj_tap_cable_generic_parport_help (urj_log_level_t ll, const char *name); diff --git a/urjtag/src/tap/cable/generic_usbconn.c b/urjtag/src/tap/cable/generic_usbconn.c index 36ec32c0..21313299 100644 --- a/urjtag/src/tap/cable/generic_usbconn.c +++ b/urjtag/src/tap/cable/generic_usbconn.c @@ -140,7 +140,8 @@ urj_usbconn_cable_t *urj_tap_cable_usbconn_cables[] = { }; int -urj_tap_cable_generic_usbconn_connect (char *params[], urj_cable_t *cable) +urj_tap_cable_generic_usbconn_connect (urj_cable_t *cable, + const urj_param_t *params[]) { urj_usbconn_cable_t user_specified = { NULL, /* no name */ @@ -150,36 +151,38 @@ urj_tap_cable_generic_usbconn_connect (char *params[], urj_cable_t *cable) -1, /* no PID */ }; - int paramc = urj_cmd_params (params); urj_tap_cable_generic_params_t *cable_params; urj_usbconn_t *conn = NULL; int i; - if (strcasecmp (params[0], "usb") != 0) + if (strcasecmp (cable->driver->name, "usb") != 0) { - user_specified.name = params[0]; + user_specified.name = cable->driver->name; } - /* parse arguments beyond the cable name */ - for (i = 1; i < paramc; i++) - { - if (strncasecmp ("pid=", params[i], 4) == 0) - { - user_specified.pid = strtol (params[i] + 4, NULL, 16); - } - else if (strncasecmp ("vid=", params[i], 4) == 0) - { - user_specified.vid = strtol (params[i] + 4, NULL, 16); - } - else if (strncasecmp ("desc=", params[i], 5) == 0) + if (params != NULL) + /* parse arguments beyond the cable name */ + for (i = 0; params[i] != NULL; i++) { - user_specified.desc = params[i] + 5; - } - else if (strncasecmp ("driver=", params[i], 7) == 0) - { - user_specified.driver = params[i] + 7; + switch (params[i]->key) + { + case URJ_CABLE_PARAM_KEY_PID: + user_specified.pid = params[i]->value.lu; + break; + case URJ_CABLE_PARAM_KEY_VID: + user_specified.vid = params[i]->value.lu; + break; + case URJ_CABLE_PARAM_KEY_DESC: + user_specified.desc = params[i]->value.string; + break; + case URJ_CABLE_PARAM_KEY_DRIVER: + user_specified.driver = params[i]->value.string; + break; + default: + // hand these to the driver connect() + break; + } } - } /* search usbconn driver list */ for (i = 0; urj_tap_usbconn_drivers[i] && !conn; i++) @@ -210,11 +213,8 @@ urj_tap_cable_generic_usbconn_connect (char *params[], urj_cable_t *cable) if (user_specified.desc != 0) cable_try.desc = user_specified.desc; - // @@@@ RFHH bail out on failure? - conn = - urj_tap_usbconn_drivers[i]-> - connect ((const char **) ¶ms[1], paramc - 1, - &cable_try); + conn = urj_tap_usbconn_drivers[i]->connect (&cable_try, + params); } } } diff --git a/urjtag/src/tap/cable/generic_usbconn.h b/urjtag/src/tap/cable/generic_usbconn.h index 741cbe16..c4fcdf24 100644 --- a/urjtag/src/tap/cable/generic_usbconn.h +++ b/urjtag/src/tap/cable/generic_usbconn.h @@ -28,11 +28,11 @@ #include #include -/** @return 0 on success, > 0 on error. - * Make this: URJ_STATUS_OK on success, URJ_STATUS_FAIL and urj_error on - * error */ -int urj_tap_cable_generic_usbconn_connect (char *params[], - urj_cable_t *cable); +/** + * @return URJ_STATUS_OK on success, URJ_STATUS_FAIL and urj_error on error + */ +int urj_tap_cable_generic_usbconn_connect (urj_cable_t *cable, + const urj_param_t *params[]); void urj_tap_cable_generic_usbconn_done (urj_cable_t *cable); void urj_tap_cable_generic_usbconn_help (urj_log_level_t ll, const char *name); void urj_tap_cable_generic_usbconn_free (urj_cable_t *cable); diff --git a/urjtag/src/tap/cable/jim.c b/urjtag/src/tap/cable/jim.c index 23d26d6e..5a7adefa 100644 --- a/urjtag/src/tap/cable/jim.c +++ b/urjtag/src/tap/cable/jim.c @@ -45,7 +45,7 @@ typedef struct jim_cable_params_t; static int -jim_cable_connect (char *params[], urj_cable_t *cable) +jim_cable_connect (urj_cable_t *cable, const urj_param_t *params[]) { jim_cable_params_t *cable_params; urj_jim_state_t *s; diff --git a/urjtag/src/tap/cable/jlink.c b/urjtag/src/tap/cable/jlink.c index d2516906..31d9e703 100644 --- a/urjtag/src/tap/cable/jlink.c +++ b/urjtag/src/tap/cable/jlink.c @@ -588,7 +588,8 @@ jlink_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_jlink_driver = { "jlink", N_("Segger/IAR J-Link, Atmel SAM-ICE and others."), - urj_tap_cable_generic_usbconn_connect, + URJ_CABLE_DEVICE_USB, + { .usb = urj_tap_cable_generic_usbconn_connect, }, urj_tap_cable_generic_disconnect, jlink_free, jlink_init, diff --git a/urjtag/src/tap/cable/keithkoep.c b/urjtag/src/tap/cable/keithkoep.c index ce9ff5f5..738745d9 100644 --- a/urjtag/src/tap/cable/keithkoep.c +++ b/urjtag/src/tap/cable/keithkoep.c @@ -146,7 +146,8 @@ keithkoep_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_keithkoep_driver = { "KeithKoep", N_("Keith & Koep JTAG cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, keithkoep_init, diff --git a/urjtag/src/tap/cable/lattice.c b/urjtag/src/tap/cable/lattice.c index ea946ed6..97a0e85a 100644 --- a/urjtag/src/tap/cable/lattice.c +++ b/urjtag/src/tap/cable/lattice.c @@ -138,7 +138,8 @@ lattice_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_lattice_driver = { "Lattice", N_("Lattice Parallel Port JTAG Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, lattice_init, diff --git a/urjtag/src/tap/cable/mpcbdm.c b/urjtag/src/tap/cable/mpcbdm.c index 581bff5e..2380e29f 100644 --- a/urjtag/src/tap/cable/mpcbdm.c +++ b/urjtag/src/tap/cable/mpcbdm.c @@ -144,7 +144,8 @@ mpcbdm_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_mpcbdm_driver = { "MPCBDM", N_("Mpcbdm JTAG cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, mpcbdm_init, diff --git a/urjtag/src/tap/cable/triton.c b/urjtag/src/tap/cable/triton.c index ad2796c1..74e017ea 100644 --- a/urjtag/src/tap/cable/triton.c +++ b/urjtag/src/tap/cable/triton.c @@ -148,7 +148,8 @@ triton_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_triton_driver = { "TRITON", N_("Ka-Ro TRITON Starterkit II (PXA255/250) JTAG Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, triton_init, diff --git a/urjtag/src/tap/cable/ts7800.c b/urjtag/src/tap/cable/ts7800.c index 755c3fb4..5638097b 100644 --- a/urjtag/src/tap/cable/ts7800.c +++ b/urjtag/src/tap/cable/ts7800.c @@ -151,7 +151,7 @@ ts7800_gpio_read (urj_cable_t *cable) } static int -ts7800_connect (char *params[], urj_cable_t *cable) +ts7800_connect (urj_cable_t *cable, const urj_param_t *params[]) { ts7800_params_t *cable_params; @@ -301,7 +301,8 @@ ts7800_help (urj_log_level_t ll, const char *cablename) urj_cable_driver_t urj_tap_cable_ts7800_driver = { "ts7800", N_("TS-7800 Built-in JTAG Chain"), - ts7800_connect, + URJ_CABLE_DEVICE_OTHER, + { .other = ts7800_connect, }, ts7800_disconnect, ts7800_cable_free, ts7800_init, diff --git a/urjtag/src/tap/cable/usbblaster.c b/urjtag/src/tap/cable/usbblaster.c index ea2c483d..07516ef6 100644 --- a/urjtag/src/tap/cable/usbblaster.c +++ b/urjtag/src/tap/cable/usbblaster.c @@ -66,12 +66,12 @@ typedef struct } params_t; static int -usbblaster_connect (char *params[], urj_cable_t *cable) +usbblaster_connect (urj_cable_t *cable, const urj_param_t *params[]) { params_t *cable_params; /* perform urj_tap_cable_generic_usbconn_connect */ - if (urj_tap_cable_generic_usbconn_connect (params, cable) != URJ_STATUS_OK) + if (urj_tap_cable_generic_usbconn_connect (cable, params) != URJ_STATUS_OK) return URJ_STATUS_FAIL; cable_params = malloc (sizeof (params_t)); @@ -512,7 +512,8 @@ usbblaster_help (urj_log_level_t ll, const char *cablename) urj_cable_driver_t urj_tap_cable_usbblaster_driver = { "UsbBlaster", N_("Altera USB-Blaster Cable"), - usbblaster_connect, + URJ_CABLE_DEVICE_USB, + { .usb = usbblaster_connect, }, urj_tap_cable_generic_disconnect, usbblaster_cable_free, usbblaster_init, diff --git a/urjtag/src/tap/cable/vision_ep9307.c b/urjtag/src/tap/cable/vision_ep9307.c index 8ad7425c..0fb3b152 100644 --- a/urjtag/src/tap/cable/vision_ep9307.c +++ b/urjtag/src/tap/cable/vision_ep9307.c @@ -194,7 +194,7 @@ ep9307_gpio_read (urj_cable_t *cable) } static int -ep9307_connect (char *params[], urj_cable_t *cable) +ep9307_connect (urj_cable_t *cable, const urj_param_t *params[]) { ep9307_params_t *cable_params; @@ -342,7 +342,8 @@ ep9307_help (urj_log_level_t ll, const char *cablename) urj_cable_driver_t urj_tap_cable_ep9307_driver = { "EP9307", N_("Vision EP9307 SoM GPIO JTAG Cable"), - ep9307_connect, + URJ_CABLE_DEVICE_OTHER, + { .other = ep9307_connect, }, urj_tap_cable_generic_disconnect, ep9307_cable_free, ep9307_init, diff --git a/urjtag/src/tap/cable/wiggler.c b/urjtag/src/tap/cable/wiggler.c index 6d81028d..9b97bce4 100644 --- a/urjtag/src/tap/cable/wiggler.c +++ b/urjtag/src/tap/cable/wiggler.c @@ -110,7 +110,7 @@ typedef struct -static int map_pin (char *pin, int *act, int *inact) +static int map_pin (const char *pin, int *act, int *inact) { int bitnum; int inverted = 0; @@ -139,11 +139,11 @@ static int map_pin (char *pin, int *act, int *inact) static int -set_mapping (char *bitmap, urj_cable_t *cable) +set_mapping (const char *bitmap, urj_cable_t *cable) { const char delim = ','; int syntax = 0; - char *tdo, *trst, *tdi, *tck, *tms, *srst; + const char *tdo, *trst, *tdi, *tck, *tms, *srst; /* assign mappings for each pin */ if ((tdo = bitmap)) @@ -193,24 +193,32 @@ set_mapping (char *bitmap, urj_cable_t *cable) static int -wiggler_connect (char *params[], urj_cable_t *cable) +wiggler_connect (urj_cable_t *cable, urj_cable_parport_devtype_t devtype, + const char *devname, const urj_param_t *params[]) { - char *param_bitmap = NULL; + const urj_param_t *param_bitmap = NULL; + const char *bitmap = NULL; wiggler_params_t *wiggler_params; - if (urj_cmd_params (params) == 4) + if (urj_param_num (params) > 0) { /* acquire optional parameter for bit<->pin mapping */ - param_bitmap = params[3]; + param_bitmap = params[0]; + if (params[0]->type != URJ_PARAM_TYPE_STRING) + { + urj_error_set (URJ_ERROR_SYNTAX, "mapping name should be a string"); + return URJ_STATUS_FAIL; + } /* urj_tap_cable_generic_parport_connect() shouldn't see this parameter */ - params[3] = NULL; + params[0] = NULL; } - if (urj_tap_cable_generic_parport_connect (params, cable) != URJ_STATUS_OK) + if (urj_tap_cable_generic_parport_connect (cable, devtype, devname, + params) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (param_bitmap) - params[3] = param_bitmap; + params[0] = param_bitmap; wiggler_params = malloc (sizeof *wiggler_params); if (!wiggler_params) @@ -231,9 +239,11 @@ wiggler_connect (char *params[], urj_cable_t *cable) cable->params = wiggler_params; if (!param_bitmap) - param_bitmap = (char *) std_wgl_map; + bitmap = (char *) std_wgl_map; + else + bitmap = param_bitmap->value.string; - if (set_mapping (param_bitmap, cable) != 0) + if (set_mapping (bitmap, cable) != 0) { urj_log (URJ_LOG_LEVEL_ERROR, _("Pin mapping failed\n")); /* NOTE: @@ -403,7 +413,8 @@ wiggler_help (urj_log_level_t ll, const char *cablename) urj_cable_driver_t urj_tap_cable_wiggler_driver = { "WIGGLER", N_("Macraigor Wiggler JTAG Cable"), - wiggler_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = wiggler_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, wiggler_init, @@ -421,7 +432,8 @@ urj_cable_driver_t urj_tap_cable_wiggler_driver = { urj_cable_driver_t urj_tap_cable_igloo_driver = { "IGLOO", N_("Excelpoint IGLOO JTAG Cable"), - wiggler_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = wiggler_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, wiggler_init, diff --git a/urjtag/src/tap/cable/wiggler2.c b/urjtag/src/tap/cable/wiggler2.c index e667aae2..2f632614 100644 --- a/urjtag/src/tap/cable/wiggler2.c +++ b/urjtag/src/tap/cable/wiggler2.c @@ -157,7 +157,8 @@ wiggler2_set_signal (urj_cable_t *cable, int mask, int val) urj_cable_driver_t urj_tap_cable_wiggler2_driver = { "WIGGLER2", N_("Modified (with CPU Reset) WIGGLER JTAG Cable"), - urj_tap_cable_generic_parport_connect, + URJ_CABLE_DEVICE_PARPORT, + { .parport = urj_tap_cable_generic_parport_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_parport_free, wiggler2_init, diff --git a/urjtag/src/tap/cable/xpc.c b/urjtag/src/tap/cable/xpc.c index b080249f..9b9cec09 100644 --- a/urjtag/src/tap/cable/xpc.c +++ b/urjtag/src/tap/cable/xpc.c @@ -683,7 +683,8 @@ xpc_ext_transfer (urj_cable_t *cable, int len, const char *in, char *out) urj_cable_driver_t urj_tap_cable_xpc_int_driver = { "xpc_int", N_("Xilinx Platform Cable USB internal chain"), - urj_tap_cable_generic_usbconn_connect, + URJ_CABLE_DEVICE_USB, + { .usb = urj_tap_cable_generic_usbconn_connect, }, urj_tap_cable_generic_disconnect, urj_tap_cable_generic_usbconn_free, xpc_int_init, @@ -709,7 +710,8 @@ urj_usbconn_cable_t urj_tap_cable_usbconn_xpc_int = { urj_cable_driver_t urj_tap_cable_xpc_ext_driver = { "xpc_ext", N_("Xilinx Platform Cable USB external chain"), - urj_tap_cable_generic_usbconn_connect, + URJ_CABLE_DEVICE_USB, + { .usb = urj_tap_cable_generic_usbconn_connect, }, urj_tap_cable_generic_disconnect, xpc_ext_free, xpc_ext_init, diff --git a/urjtag/src/tap/parport.c b/urjtag/src/tap/parport.c index f3497e41..6bc909f2 100644 --- a/urjtag/src/tap/parport.c +++ b/urjtag/src/tap/parport.c @@ -84,3 +84,17 @@ urj_tap_parport_set_control (urj_parport_t *port, const unsigned char data) { return port->driver->set_control (port, data); } + +const char * +urj_cable_parport_devtype_string(urj_cable_parport_devtype_t dt) +{ + switch (dt) + { + case URJ_CABLE_PARPORT_DEV_PARALLEL: return "parallel"; + case URJ_CABLE_PARPORT_DEV_PPDEV: return "ppdev"; + case URJ_CABLE_PARPORT_DEV_PPI: return "ppi"; + case URJ_CABLE_PARPORT_N_DEVS: return "#devs"; + } + return ""; +} + diff --git a/urjtag/src/tap/parport/direct.c b/urjtag/src/tap/parport/direct.c index fa238ac5..65839e1d 100644 --- a/urjtag/src/tap/parport/direct.c +++ b/urjtag/src/tap/parport/direct.c @@ -203,21 +203,21 @@ direct_parport_free (urj_parport_t *port) } static urj_parport_t * -direct_connect (const char **par, int parnum) +direct_connect (const char *devname) { long int port_scan_val; unsigned int port; port_node_t *pn = ports; urj_parport_t *parport; - if (parnum != 1) + errno = 0; + port_scan_val = strtol (devname, NULL, 0); + if (errno != 0) { - urj_error_set (URJ_ERROR_SYNTAX, "#params != 1"); + urj_error_IO_set ("strtol(%s) fails", devname); return NULL; } - port_scan_val = strtol (par[0], NULL, 0); - if (port_scan_val < 0 || (port_scan_val + 3) > 0xffff) { urj_error_set (URJ_ERROR_INVALID, _("Invalid port address")); @@ -317,7 +317,7 @@ direct_set_control (urj_parport_t *parport, unsigned char data) } urj_parport_driver_t urj_tap_parport_direct_parport_driver = { - "parallel", + URJ_CABLE_PARPORT_DEV_PARALLEL, direct_connect, direct_parport_free, direct_open, diff --git a/urjtag/src/tap/parport/ppdev.c b/urjtag/src/tap/parport/ppdev.c index 44cfb9f1..b650343d 100644 --- a/urjtag/src/tap/parport/ppdev.c +++ b/urjtag/src/tap/parport/ppdev.c @@ -120,30 +120,24 @@ ppdev_parport_free (urj_parport_t *port) } static urj_parport_t * -ppdev_connect (const char **par, int parnum) +ppdev_connect (const char *devname) { port_node_t *pn; urj_parport_t *parport; - if (parnum != 1) - { - urj_error_set (URJ_ERROR_SYNTAX, "#param != 1"); - return NULL; - } - for (pn = ports; pn; pn = pn->next) - if (strcmp (pn->port->params, par[0]) == 0) + if (strcmp (pn->port->params, devname) == 0) { urj_log (URJ_LOG_LEVEL_NORMAL, _("Disconnecting %s from ppdev port %s\n"), - _(pn->port->cable->driver->description), par[0]); + _(pn->port->cable->driver->description), devname); pn->port->cable->driver->disconnect (pn->port->cable); break; } - urj_log (URJ_LOG_LEVEL_NORMAL, _("Initializing ppdev port %s\n"), par[0]); + urj_log (URJ_LOG_LEVEL_NORMAL, _("Initializing ppdev port %s\n"), devname); - parport = ppdev_parport_alloc (par[0]); + parport = ppdev_parport_alloc (devname); if (!parport) return NULL; @@ -257,7 +251,7 @@ ppdev_set_control (urj_parport_t *parport, unsigned char data) } urj_parport_driver_t urj_tap_parport_ppdev_parport_driver = { - "ppdev", + URJ_CABLE_PARPORT_DEV_PPDEV, ppdev_connect, ppdev_parport_free, ppdev_open, diff --git a/urjtag/src/tap/parport/ppi.c b/urjtag/src/tap/parport/ppi.c index 19c4689d..12e46240 100644 --- a/urjtag/src/tap/parport/ppi.c +++ b/urjtag/src/tap/parport/ppi.c @@ -116,30 +116,25 @@ ppi_parport_free (urj_parport_t *port) } static urj_cable_t * -ppi_connect (const char **par, int parnum) +ppi_connect (const char *devname) { port_node_t *pn; urj_parport_t *parport; - if (parnum != 1) - { - urj_error_set (URJ_ERROR_SYNTAX, "#params != 1"); - return NULL; - } - for (pn = ports; pn; pn = pn->next) - if (strcmp (pn->port->params, par[0]) == 0) + if (strcmp (pn->port->params, devname) == 0) { urj_log (URJ_LOG_LEVEL_NORMAL, _("Disconnecting %s from ppi port %s\n"), - _(pn->port->cable->driver->description), par[0]); + _(pn->port->cable->driver->description), + devname); pn->port->cable->driver->disconnect (pn->port->cable); break; } - urj_log (URJ_LOG_LEVEL_NORMAL, _("Initializing on ppi port %s\n"), par[0]); + urj_log (URJ_LOG_LEVEL_NORMAL, _("Initializing on ppi port %s\n"), devname); - parport = ppi_parport_alloc (par[0]); + parport = ppi_parport_alloc (devname); if (!parport) { return NULL; @@ -242,7 +237,7 @@ ppi_set_control (urj_parport_t *parport, unsigned char data) } urj_parport_driver_t urj_tap_parport_ppi_parport_driver = { - "ppi", + URJ_CABLE_PARPORT_DEV_PPI, ppi_connect, ppi_parport_free, ppi_open, diff --git a/urjtag/src/tap/usbconn/libftd2xx.c b/urjtag/src/tap/usbconn/libftd2xx.c index 8fb90945..0835b04f 100644 --- a/urjtag/src/tap/usbconn/libftd2xx.c +++ b/urjtag/src/tap/usbconn/libftd2xx.c @@ -302,8 +302,8 @@ usbconn_ftd2xx_write (urj_usbconn_t *conn, uint8_t *buf, int len, int recv) /* ---------------------------------------------------------------------- */ static urj_usbconn_t * -usbconn_ftd2xx_connect (const char **param, int paramc, - urj_usbconn_cable_t *template) +usbconn_ftd2xx_connect (urj_usbconn_cable_t *template, + const urj_param_t *params[]) { urj_usbconn_t *c = malloc (sizeof (urj_usbconn_t)); ftd2xx_param_t *p = malloc (sizeof (ftd2xx_param_t)); @@ -364,10 +364,10 @@ usbconn_ftd2xx_connect (const char **param, int paramc, static urj_usbconn_t * -usbconn_ftd2xx_mpsse_connect (const char **param, int paramc, - urj_usbconn_cable_t *template) +usbconn_ftd2xx_mpsse_connect (urj_usbconn_cable_t *template, + const urj_param_t *params[]) { - urj_usbconn_t *conn = usbconn_ftd2xx_connect (param, paramc, template); + urj_usbconn_t *conn = usbconn_ftd2xx_connect (template, params); if (conn) conn->driver = &urj_tap_usbconn_ftd2xx_mpsse_driver; diff --git a/urjtag/src/tap/usbconn/libftdi.c b/urjtag/src/tap/usbconn/libftdi.c index e05f0103..6e2a6d85 100644 --- a/urjtag/src/tap/usbconn/libftdi.c +++ b/urjtag/src/tap/usbconn/libftdi.c @@ -242,8 +242,8 @@ usbconn_ftdi_write (urj_usbconn_t *conn, uint8_t *buf, int len, int recv) /* ---------------------------------------------------------------------- */ static urj_usbconn_t * -usbconn_ftdi_connect (const char **param, int paramc, - urj_usbconn_cable_t *template) +usbconn_ftdi_connect (urj_usbconn_cable_t *template, + const urj_param_t *params[]) { urj_usbconn_t *c = malloc (sizeof (urj_usbconn_t)); ftdi_param_t *p = malloc (sizeof (ftdi_param_t)); @@ -309,10 +309,10 @@ usbconn_ftdi_connect (const char **param, int paramc, static urj_usbconn_t * -usbconn_ftdi_mpsse_connect (const char **param, int paramc, - urj_usbconn_cable_t *template) +usbconn_ftdi_mpsse_connect (urj_usbconn_cable_t *template, + const urj_param_t *params[]) { - urj_usbconn_t *conn = usbconn_ftdi_connect (param, paramc, template); + urj_usbconn_t *conn = usbconn_ftdi_connect (template, params); if (conn) conn->driver = &urj_tap_usbconn_ftdi_mpsse_driver; diff --git a/urjtag/src/tap/usbconn/libusb.c b/urjtag/src/tap/usbconn/libusb.c index 52194dc9..f630783a 100644 --- a/urjtag/src/tap/usbconn/libusb.c +++ b/urjtag/src/tap/usbconn/libusb.c @@ -58,7 +58,7 @@ urj_usbconn_driver_t urj_tap_usbconn_libusb_driver; /* ---------------------------------------------------------------------- */ static int -libusb_match_desc (struct usb_device *dev, char *desc) +libusb_match_desc (struct usb_device *dev, const char *desc) { int r = 0; char buf[256]; @@ -112,8 +112,8 @@ libusb_match_desc (struct usb_device *dev, char *desc) /* ---------------------------------------------------------------------- */ static urj_usbconn_t * -usbconn_libusb_connect (const char **param, int paramc, - urj_usbconn_cable_t *template) +usbconn_libusb_connect (urj_usbconn_cable_t *template, + const urj_param_t *params[]) { struct usb_bus *bus; struct usb_device *found_dev = NULL;