This is an automated email from Gerrit.

"Daniel Anselmi <danse...@gmx.ch>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/7728

-- gerrit

commit 31b528362e4f2074a902cb02697d3c329236429b
Author: Daniel Anselmi <danse...@gmx.ch>
Date:   Sat Jun 3 20:16:19 2023 +0200

    give pld devices a name for referencing in scripts
    
    Change-Id: I05e8596ffacdb6cd8da4dd8a40bb460183f4930a
    Signed-off-by: Daniel Anselmi <danse...@gmx.ch>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 9b485c5e1f..6df1d0107f 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -8465,22 +8465,23 @@ As it does for JTAG TAPs, debug targets, and flash 
chips (both NOR and NAND),
 OpenOCD maintains a list of PLDs available for use in various commands.
 Also, each such PLD requires a driver.
 
-They are referenced by the number shown by the @command{pld devices} command,
-and new PLDs are defined by @command{pld device driver_name}.
+They are referenced by a number or the device name given when a pld is defined.
+The number and the device names are shown by the @command{pld devices} command.
+New PLDs are defined by @command{pld device driver_name device_name}.
 
-@deffn {Config Command} {pld device} driver_name tap_name [driver_options]
+@deffn {Config Command} {pld device} driver_name device name [driver_options]
 Defines a new PLD device, supported by driver @var{driver_name},
-using the TAP named @var{tap_name}.
+assigning @var{device_name} for further reference.
 The driver may make use of any @var{driver_options} to configure its
 behavior.
 @end deffn
 
 @deffn {Command} {pld devices}
-Lists the PLDs and their numbers.
+Lists the PLDs and their numbers and names.
 @end deffn
 
-@deffn {Command} {pld load} num filename
-Loads the file @file{filename} into the PLD identified by @var{num}.
+@deffn {Command} {pld load} num|name filename
+Loads the file @file{filename} into the PLD identified by @var{num} or 
@var{name}.
 The file format must be inferred by the driver.
 @end deffn
 
@@ -8490,8 +8491,9 @@ Drivers may support PLD-specific options to the 
@command{pld device}
 definition command, and may also define commands usable only with
 that particular type of PLD.
 
-@deffn {FPGA Driver} {virtex2} [no_jstart]
+@deffn {FPGA Driver} {virtex2} tap_name [no_jstart]
 Virtex-II is a family of FPGAs sold by Xilinx.
+Using the TAP named @var{tap_name}.
 This driver can also be used to load Series3, Series6, Series7 and Zynq 7000 
devices.
 It supports the IEEE 1532 standard for In-System Configuration (ISC).
 
@@ -8505,53 +8507,55 @@ openocd -f board/digilent_zedboard.cfg -c "init" \
 @end example
 
 
-@deffn {Command} {virtex2 read_stat} num
+@deffn {Command} {virtex2 read_stat} num|name
 Reads and displays the Virtex-II status register (STAT)
-for FPGA @var{num}.
+for FPGA @var{num} or @var{name}.
 @end deffn
 @end deffn
 
 
 
-@deffn {FPGA Driver} {lattice} [family]
+@deffn {FPGA Driver} {lattice} tap_name [family]
 The FGPA families ECP2, ECP3, ECP5, Certus and CertusPro by Lattice are 
supported.
+Using the TAP named @var{tap_name}.
 This driver can be used to load the bitstream into the FPGA or read the status 
register and read/write the usercode register.
 
 The option @option{family} is one of @var{ecp2 ecp3 ecp5 certus}. This is 
needed when the JTAG ID of the device is not known by openocd (newer NX 
devices).
 
 @deffn {Command} {lattice read_status} num
 Reads and displays the status register
-for FPGA @var{num}.
+for FPGA @var{num} or @var{name}.
 @end deffn
 
-@deffn {Command} {lattice read_user} num
+@deffn {Command} {lattice read_user} num|name
 Reads and displays the user register
-for FPGA @var{num}.
+for FPGA @var{num} or @var{name}.
 @end deffn
 
-@deffn {Command} {lattice write_user} num val
+@deffn {Command} {lattice write_user} num|name val
 Writes the user register.
-for FPGA @var{num} with value @var{val}.
+for FPGA @var{num}/@var{name} with value @var{val}.
 @end deffn
 
-@deffn {Command} {lattice set_preload} num length
+@deffn {Command} {lattice set_preload} num|name length
 Set the length of the register for the preload. This is needed when the JTAG 
ID of the device is not known by openocd (newer NX devices).
-The load command for the FPGA @var{num} will use a length for the preload of 
@var{length}.
+The load command for the FPGA @var{num} or @var{name} will use a length for 
the preload of @var{length}.
 @end deffn
 @end deffn
 
 
-@deffn {FPGA Driver} {efinix}
+@deffn {FPGA Driver} {efinix} tap_name
 Both families (Trion and Titanium) sold by Efinix are supported as both use 
the same protocol for In-System Configuration.
-This driver can be used to load the bitstream into the FPGA.
+This driver can be used to load the bitstream into the FPGA using the TAP 
named @var{tap_name}.
 @end deffn
 
 
-@deffn {FPGA Driver} {intel} [@option{family}]
+@deffn {FPGA Driver} {intel} tap_name [@option{family}]
 This driver can be used to load the bitstream into Intel (former Altera) FPGAs.
 The families Cyclone III, Cyclone IV, Cyclone V, Cyclone 10, Arria II are 
supported.
 @c Arria V and Arria 10, MAX II, MAX V, MAX10)
 
+Using the TAP named @var{tap_name}.
 The option @option{family} is one of @var{cycloneiii cycloneiv cyclonev 
cyclone10 arriaii}.
 This is needed when the JTAG ID of the device is ambiguous (same ID is used 
for chips in different families).
 
@@ -8563,12 +8567,12 @@ Defines a new PLD device, an FPGA of the Cyclone III 
family, using the TAP named
 pld device intel cycloneiii.tap cycloneiii
 @end example
 
-@deffn {Command} {intel set_bscan} num len
-Set boundary scan register length of FPGA @var{num} to @var{len}. This is 
needed because the
+@deffn {Command} {intel set_bscan} num|name len
+Set boundary scan register length of FPGA @var{num} or @var{name} to 
@var{len}. This is needed because the
 length can vary between chips with the same JTAG ID.
 @end deffn
 
-@deffn {Command} {intel set_check_pos} num pos
+@deffn {Command} {intel set_check_pos} num|name pos
 Selects the position @var{pos} in the boundary-scan register. The bit at this
 position is checked after loading the bitstream and must be '1', which is the 
case when no error occurred.
 With a value of -1 for @var{pos} the check will be omitted.
@@ -8576,15 +8580,17 @@ With a value of -1 for @var{pos} the check will be 
omitted.
 @end deffn
 
 
-@deffn {FPGA Driver} {gowin}
+@deffn {FPGA Driver} {gowin} tap_name
 This driver can be used to load the bitstream into FPGAs from Gowin.
+Using the TAP named @var{tap_name}.
 It is possible to program the SRAM. Programming the flash is not supported.
 The files @verb{|.fs|} and @verb{|.bin|} generated by Gowin FPGA Designer are 
supported.
 @end deffn
 
 
-@deffn {FPGA Driver} {gatemate}
+@deffn {FPGA Driver} {gatemate} tap_name
 This driver can be used to load the bitstream into GateMate FPGAs form 
CologneChip.
+Using the TAP named @var{tap_name}.
 The files @verb{|.bit|} and @verb{|.cfg|} both generated by p_r tool from 
CologneChip are supported.
 @end deffn
 
diff --git a/src/pld/efinix.c b/src/pld/efinix.c
index f08439476c..300abec066 100644
--- a/src/pld/efinix.c
+++ b/src/pld/efinix.c
@@ -190,12 +190,12 @@ static int efinix_load(struct pld_device *pld_device, 
const char *filename)
 
 PLD_DEVICE_COMMAND_HANDLER(efinix_pld_device_command)
 {
-       if (CMD_ARGC != 2)
+       if (CMD_ARGC != 3)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[1]);
+       struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[2]);
        if (!tap) {
-               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[2]);
                return ERROR_FAIL;
        }
 
diff --git a/src/pld/gatemate.c b/src/pld/gatemate.c
index 43b3f02d1d..35189af87e 100644
--- a/src/pld/gatemate.c
+++ b/src/pld/gatemate.c
@@ -215,12 +215,12 @@ PLD_DEVICE_COMMAND_HANDLER(gatemate_pld_device_command)
 
        struct gatemate_pld_device *gatemate_info;
 
-       if (CMD_ARGC != 2)
+       if (CMD_ARGC != 3)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       tap = jtag_tap_by_string(CMD_ARGV[1]);
+       tap = jtag_tap_by_string(CMD_ARGV[2]);
        if (!tap) {
-               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[2]);
                return ERROR_FAIL;
        }
 
diff --git a/src/pld/gowin.c b/src/pld/gowin.c
index 467b799374..6247e8a385 100644
--- a/src/pld/gowin.c
+++ b/src/pld/gowin.c
@@ -451,15 +451,12 @@ static int gowin_reload_command(struct pld_device 
*pld_device)
 
 COMMAND_HANDLER(gowin_read_status_command_handler)
 {
-       int dev_id;
-
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -474,15 +471,12 @@ COMMAND_HANDLER(gowin_read_status_command_handler)
 
 COMMAND_HANDLER(gowin_read_user_register_command_handler)
 {
-       int dev_id;
-
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -497,15 +491,12 @@ COMMAND_HANDLER(gowin_read_user_register_command_handler)
 
 COMMAND_HANDLER(gowin_reload_command_handler)
 {
-       int dev_id;
-
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -552,12 +543,12 @@ PLD_DEVICE_COMMAND_HANDLER(gowin_pld_device_command)
 
        struct gowin_pld_device *gowin_info;
 
-       if (CMD_ARGC != 2)
+       if (CMD_ARGC != 3)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       tap = jtag_tap_by_string(CMD_ARGV[1]);
+       tap = jtag_tap_by_string(CMD_ARGV[2]);
        if (!tap) {
-               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[2]);
                return ERROR_FAIL;
        }
 
diff --git a/src/pld/intel.c b/src/pld/intel.c
index 119a5695dc..b27ae57c46 100644
--- a/src/pld/intel.c
+++ b/src/pld/intel.c
@@ -339,16 +339,14 @@ static int intel_load(struct pld_device *pld_device, 
const char *filename)
 
 COMMAND_HANDLER(intel_set_bscan_command_handler)
 {
-       int dev_id;
        unsigned int boundary_scan_length;
 
        if (CMD_ARGC != 2)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *pld_device = get_pld_device_by_num(dev_id);
+       struct pld_device *pld_device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!pld_device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -366,16 +364,14 @@ COMMAND_HANDLER(intel_set_bscan_command_handler)
 
 COMMAND_HANDLER(intel_set_check_pos_command_handler)
 {
-       int dev_id;
        int checkpos;
 
        if (CMD_ARGC != 2)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *pld_device = get_pld_device_by_num(dev_id);
+       struct pld_device *pld_device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!pld_device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -394,12 +390,12 @@ COMMAND_HANDLER(intel_set_check_pos_command_handler)
 
 PLD_DEVICE_COMMAND_HANDLER(intel_pld_device_command)
 {
-       if (CMD_ARGC < 2 || CMD_ARGC > 3)
+       if (CMD_ARGC < 3 || CMD_ARGC > 4)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[1]);
+       struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[2]);
        if (!tap) {
-               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[2]);
                return ERROR_FAIL;
        }
 
@@ -411,16 +407,16 @@ PLD_DEVICE_COMMAND_HANDLER(intel_pld_device_command)
 
        enum intel_family_e family = INTEL_UNKNOWN;
 
-       if (CMD_ARGC == 3) {
-               if (strcmp(CMD_ARGV[2], "cycloneiii") == 0) {
+       if (CMD_ARGC == 4) {
+               if (strcmp(CMD_ARGV[3], "cycloneiii") == 0) {
                        family = INTEL_CYCLONEIII;
-               } else if (strcmp(CMD_ARGV[2], "cycloneiv") == 0) {
+               } else if (strcmp(CMD_ARGV[3], "cycloneiv") == 0) {
                        family = INTEL_CYCLONEIV;
-               } else if (strcmp(CMD_ARGV[2], "cyclonev") == 0) {
+               } else if (strcmp(CMD_ARGV[3], "cyclonev") == 0) {
                        family = INTEL_CYCLONEV;
-               } else if (strcmp(CMD_ARGV[2], "cyclone10") == 0) {
+               } else if (strcmp(CMD_ARGV[3], "cyclone10") == 0) {
                        family = INTEL_CYCLONE10;
-               } else if (strcmp(CMD_ARGV[2], "arriaii") == 0) {
+               } else if (strcmp(CMD_ARGV[3], "arriaii") == 0) {
                        family = INTEL_ARRIAII;
                } else {
                        command_print(CMD, "unknown family");
diff --git a/src/pld/lattice.c b/src/pld/lattice.c
index 4ab5f63c0b..8bdbdde1f2 100644
--- a/src/pld/lattice.c
+++ b/src/pld/lattice.c
@@ -318,12 +318,12 @@ static int lattice_load_command(struct pld_device 
*pld_device, const char *filen
 
 PLD_DEVICE_COMMAND_HANDLER(lattice_pld_device_command)
 {
-       if (CMD_ARGC < 2 || CMD_ARGC > 3)
+       if (CMD_ARGC < 3 || CMD_ARGC > 4)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[1]);
+       struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[2]);
        if (!tap) {
-               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[2]);
                return ERROR_FAIL;
        }
 
@@ -334,14 +334,14 @@ PLD_DEVICE_COMMAND_HANDLER(lattice_pld_device_command)
        }
        /* id is not known yet -> postpone lattice_check_device_family() */
        enum lattice_family_e family = LATTICE_UNKNOWN;
-       if (CMD_ARGC == 3) {
-               if (strcasecmp(CMD_ARGV[2], "ecp2") == 0) {
+       if (CMD_ARGC == 4) {
+               if (strcasecmp(CMD_ARGV[3], "ecp2") == 0) {
                        family = LATTICE_ECP2;
-               } else if (strcasecmp(CMD_ARGV[2], "ecp3") == 0) {
+               } else if (strcasecmp(CMD_ARGV[3], "ecp3") == 0) {
                        family = LATTICE_ECP3;
-               } else if (strcasecmp(CMD_ARGV[2], "ecp5") == 0) {
+               } else if (strcasecmp(CMD_ARGV[3], "ecp5") == 0) {
                        family = LATTICE_ECP5;
-               } else if (strcasecmp(CMD_ARGV[2], "certus") == 0) {
+               } else if (strcasecmp(CMD_ARGV[3], "certus") == 0) {
                        family = LATTICE_CERTUS;
                } else {
                        command_print(CMD, "unknown family");
@@ -360,16 +360,14 @@ PLD_DEVICE_COMMAND_HANDLER(lattice_pld_device_command)
 
 COMMAND_HANDLER(lattice_read_usercode_register_command_handler)
 {
-       int dev_id;
        uint32_t usercode;
 
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -390,16 +388,14 @@ 
COMMAND_HANDLER(lattice_read_usercode_register_command_handler)
 
 COMMAND_HANDLER(lattice_set_preload_command_handler)
 {
-       int dev_id;
        unsigned int preload_length;
 
        if (CMD_ARGC != 2)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -417,16 +413,14 @@ COMMAND_HANDLER(lattice_set_preload_command_handler)
 
 COMMAND_HANDLER(lattice_write_usercode_register_command_handler)
 {
-       int dev_id;
        uint32_t usercode;
 
        if (CMD_ARGC != 2)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -445,15 +439,12 @@ 
COMMAND_HANDLER(lattice_write_usercode_register_command_handler)
 
 COMMAND_HANDLER(lattice_read_status_command_handler)
 {
-       int dev_id;
-
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
-       struct pld_device *device = get_pld_device_by_num(dev_id);
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -487,25 +478,25 @@ static const struct command_registration 
lattice_exec_command_handlers[] = {
                .mode = COMMAND_EXEC,
                .handler = lattice_read_status_command_handler,
                .help = "reading status register from FPGA",
-               .usage = "num_pld",
+               .usage = "num_pld|pld_name",
        }, {
                .name = "read_user",
                .mode = COMMAND_EXEC,
                .handler = lattice_read_usercode_register_command_handler,
                .help = "reading usercode register from FPGA",
-               .usage = "num_pld",
+               .usage = "num_pld|pld_name",
        }, {
                .name = "write_user",
                .mode = COMMAND_EXEC,
                .handler = lattice_write_usercode_register_command_handler,
                .help = "writing usercode register to FPGA",
-               .usage = "num_pld value",
+               .usage = "num_pld|pld_name value",
        }, {
                .name = "set_preload",
                .mode = COMMAND_EXEC,
                .handler = lattice_set_preload_command_handler,
                .help = "set length for preload (device specific)",
-               .usage = "num_pld value",
+               .usage = "num_pld|pld_name value",
        },
        COMMAND_REGISTRATION_DONE
 };
diff --git a/src/pld/pld.c b/src/pld/pld.c
index 07b575f94e..2f19b704cf 100644
--- a/src/pld/pld.c
+++ b/src/pld/pld.c
@@ -41,6 +41,32 @@ struct pld_device *get_pld_device_by_num(int num)
        return NULL;
 }
 
+struct pld_device *get_pld_device_by_name(const char *name)
+{
+       for (struct pld_device *p = pld_devices; p; p = p->next) {
+               if (strcmp(p->name, name) == 0)
+                       return p;
+       }
+
+       return NULL;
+}
+
+struct pld_device *get_pld_device_by_name_or_numstr(const char *str)
+{
+       struct pld_device *dev = get_pld_device_by_name(str);
+       if (dev)
+               return dev;
+
+       char *end;
+       unsigned long dev_num = strtoul(str, &end, 0);
+       if (*end || dev_num > INT_MAX) {
+               LOG_ERROR("Invalid argument");
+               return NULL;
+       }
+
+       return get_pld_device_by_num(dev_num);
+}
+
 /* pld device <driver> [driver_options ...]
  */
 COMMAND_HANDLER(handle_pld_device_command)
@@ -48,7 +74,7 @@ COMMAND_HANDLER(handle_pld_device_command)
        int i;
        int found = 0;
 
-       if (CMD_ARGC < 1)
+       if (CMD_ARGC < 2)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        for (i = 0; pld_drivers[i]; i++) {
@@ -65,7 +91,17 @@ COMMAND_HANDLER(handle_pld_device_command)
                                }
                        }
 
+                       if (get_pld_device_by_name(CMD_ARGV[1])) {
+                               LOG_ERROR("pld device with name '%s' already 
exists", CMD_ARGV[1]);
+                               return ERROR_FAIL;
+                       }
+
                        c = malloc(sizeof(struct pld_device));
+                       if (!c) {
+                               LOG_ERROR("Out of memory");
+                               return ERROR_FAIL;
+                       }
+
                        c->driver = pld_drivers[i];
                        c->next = NULL;
 
@@ -77,6 +113,12 @@ COMMAND_HANDLER(handle_pld_device_command)
                                free(c);
                                return ERROR_OK;
                        }
+                       c->name = alloc_printf("%s", CMD_ARGV[1]);
+                       if (!c->name) {
+                               LOG_ERROR("Out of memory");
+                               free(c);
+                               return ERROR_FAIL;
+                       }
 
                        /* put pld device in linked list */
                        if (pld_devices) {
@@ -112,7 +154,7 @@ COMMAND_HANDLER(handle_pld_devices_command)
        }
 
        for (p = pld_devices; p; p = p->next)
-               command_print(CMD, "#%i: %s", i++, p->driver->name);
+               command_print(CMD, "#%i: %s (driver: %s)", i++, p->name, 
p->driver->name);
 
        return ERROR_OK;
 }
@@ -128,9 +170,7 @@ COMMAND_HANDLER(handle_pld_load_command)
        if (CMD_ARGC < 2)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       unsigned dev_id;
-       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id);
-       p = get_pld_device_by_num(dev_id);
+       p = get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!p) {
                command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
                return ERROR_OK;
@@ -154,15 +194,15 @@ COMMAND_HANDLER(handle_pld_load_command)
 
        retval = p->driver->load(p, CMD_ARGV[1]);
        if (retval != ERROR_OK) {
-               command_print(CMD, "failed loading file %s to pld device %u",
-                       CMD_ARGV[1], dev_id);
+               command_print(CMD, "failed loading file %s to pld device %s",
+                       CMD_ARGV[1], CMD_ARGV[0]);
                return retval;
        } else {
                gettimeofday(&end, NULL);
                timeval_subtract(&duration, &end, &start);
 
-               command_print(CMD, "loaded file %s to pld device %u in %jis 
%jius",
-                       CMD_ARGV[1], dev_id,
+               command_print(CMD, "loaded file %s to pld device %s in %jis 
%jius",
+                       CMD_ARGV[1], CMD_ARGV[0],
                        (intmax_t)duration.tv_sec, (intmax_t)duration.tv_usec);
        }
 
@@ -182,7 +222,7 @@ static const struct command_registration 
pld_exec_command_handlers[] = {
                .handler = handle_pld_load_command,
                .mode = COMMAND_EXEC,
                .help = "load configuration file into PLD",
-               .usage = "pld_num filename",
+               .usage = "pld_num|pld_name filename",
        },
        COMMAND_REGISTRATION_DONE
 };
diff --git a/src/pld/pld.h b/src/pld/pld.h
index 322b96ec6e..b5ab086442 100644
--- a/src/pld/pld.h
+++ b/src/pld/pld.h
@@ -29,11 +29,14 @@ struct pld_device {
        struct pld_driver *driver;
        void *driver_priv;
        struct pld_device *next;
+       char *name;
 };
 
 int pld_register_commands(struct command_context *cmd_ctx);
 
 struct pld_device *get_pld_device_by_num(int num);
+struct pld_device *get_pld_device_by_name(const char *name);
+struct pld_device *get_pld_device_by_name_or_numstr(const char *str);
 
 #define ERROR_PLD_DEVICE_INVALID        (-1000)
 #define ERROR_PLD_FILE_LOAD_FAILED      (-1001)
diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c
index fd0725a63a..bfc20ed5c3 100644
--- a/src/pld/virtex2.c
+++ b/src/pld/virtex2.c
@@ -233,11 +233,9 @@ COMMAND_HANDLER(virtex2_handle_read_stat_command)
        if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       unsigned dev_id;
-       COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id);
-       device = get_pld_device_by_num(dev_id);
+       device = get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
        if (!device) {
-               command_print(CMD, "pld device '#%s' is out of bounds", 
CMD_ARGV[0]);
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
                return ERROR_FAIL;
        }
 
@@ -258,12 +256,12 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command)
 
        struct virtex2_pld_device *virtex2_info;
 
-       if (CMD_ARGC < 2)
+       if (CMD_ARGC < 3)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       tap = jtag_tap_by_string(CMD_ARGV[1]);
+       tap = jtag_tap_by_string(CMD_ARGV[2]);
        if (!tap) {
-               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+               command_print(CMD, "Tap: %s does not exist", CMD_ARGV[2]);
                return ERROR_FAIL;
        }
 
@@ -275,8 +273,8 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command)
        virtex2_info->tap = tap;
 
        virtex2_info->no_jstart = 0;
-       if (CMD_ARGC >= 3)
-               COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], virtex2_info->no_jstart);
+       if (CMD_ARGC >= 4)
+               COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], virtex2_info->no_jstart);
 
        pld->driver_priv = virtex2_info;
 
@@ -289,7 +287,7 @@ static const struct command_registration 
virtex2_exec_command_handlers[] = {
                .mode = COMMAND_EXEC,
                .handler = virtex2_handle_read_stat_command,
                .help = "read status register",
-               .usage = "pld_num",
+               .usage = "pld_num|pld_name",
        },
        COMMAND_REGISTRATION_DONE
 };
diff --git a/tcl/cpld/xilinx-xc6s.cfg b/tcl/cpld/xilinx-xc6s.cfg
index 82b87fb415..6a65646d8a 100644
--- a/tcl/cpld/xilinx-xc6s.cfg
+++ b/tcl/cpld/xilinx-xc6s.cfg
@@ -25,7 +25,7 @@ jtag newtap $_CHIPNAME tap -irlen 6 -ignore-version \
        -expected-id 0x0401D093 \
        -expected-id 0x0403D093
 
-pld device virtex2 $_CHIPNAME.tap
+pld device virtex2 $_CHIPNAME.pld $_CHIPNAME.tap
 
 set XC6S_CFG_IN 0x05
 set XC6S_JSHUTDOWN 0x0d
diff --git a/tcl/cpld/xilinx-xc7.cfg b/tcl/cpld/xilinx-xc7.cfg
index 91a07f9eb4..209c2d339a 100644
--- a/tcl/cpld/xilinx-xc7.cfg
+++ b/tcl/cpld/xilinx-xc7.cfg
@@ -49,7 +49,7 @@ jtag newtap $_CHIPNAME tap -irlen 6 -ignore-version \
 
 #jtag newtap $_CHIPNAME tap -irlen 38 -ignore-version -expected-id 0x036DB093
 
-pld device virtex2 $_CHIPNAME.tap 1
+pld device virtex2 $_CHIPNAME.pld $_CHIPNAME.tap 1
 
 set XC7_JSHUTDOWN 0x0d
 set XC7_JPROGRAM 0x0b
diff --git a/tcl/cpld/xilinx-xcu.cfg b/tcl/cpld/xilinx-xcu.cfg
index 9df696d4ca..4a961fb1f1 100644
--- a/tcl/cpld/xilinx-xcu.cfg
+++ b/tcl/cpld/xilinx-xcu.cfg
@@ -54,7 +54,7 @@ set _IRLEN [lindex $_XCU_DATA($CHIP) 1]
 # the 4 top bits (28:31) are the die stepping/revisions. ignore it.
 jtag newtap $_CHIPNAME tap -irlen $_IRLEN -ignore-version -expected-id $_EXPID
 
-pld device virtex2 $_CHIPNAME.tap 1
+pld device virtex2 $_CHIPNAME.pld $_CHIPNAME.tap 1
 
 set XCU_JSHUTDOWN 0x0d
 set XCU_JPROGRAM 0x0b
diff --git a/tcl/fpga/altera-arriaii.cfg b/tcl/fpga/altera-arriaii.cfg
index ae752dfb16..6a98898da6 100644
--- a/tcl/fpga/altera-arriaii.cfg
+++ b/tcl/fpga/altera-arriaii.cfg
@@ -28,4 +28,4 @@ jtag newtap $_CHIPNAME tap -irlen 10 \
   -expected-id 0x025030dd -expected-id 0x024820dd \
   -expected-id 0x025140dd
 
-pld device intel $_CHIPNAME.tap arriaii
+pld device intel  $_CHIPNAME.pld $_CHIPNAME.tap arriaii
diff --git a/tcl/fpga/altera-cycloneiii.cfg b/tcl/fpga/altera-cycloneiii.cfg
index e143572451..3fc4667df6 100644
--- a/tcl/fpga/altera-cycloneiii.cfg
+++ b/tcl/fpga/altera-cycloneiii.cfg
@@ -32,4 +32,4 @@ jtag newtap $_CHIPNAME tap -irlen 10 \
   -expected-id 0x027000dd -expected-id 0x027030dd \
   -expected-id 0x027020dd
 
-pld device intel $_CHIPNAME.tap cycloneiii
+pld device intel $_CHIPNAME.pld $_CHIPNAME.tap cycloneiii
diff --git a/tcl/fpga/altera-cycloneiv.cfg b/tcl/fpga/altera-cycloneiv.cfg
index 59243cfd09..9ea72fc6e9 100644
--- a/tcl/fpga/altera-cycloneiv.cfg
+++ b/tcl/fpga/altera-cycloneiv.cfg
@@ -38,4 +38,4 @@ jtag newtap $_CHIPNAME tap -irlen 10 \
   -expected-id 0x028030dd -expected-id 0x028140dd \
   -expected-id 0x028040dd
 
-pld device intel $_CHIPNAME.tap cycloneiv
+pld device intel $_CHIPNAME.pld $_CHIPNAME.tap cycloneiv
diff --git a/tcl/fpga/altera-cyclonev.cfg b/tcl/fpga/altera-cyclonev.cfg
index 1e9c9c405d..0fd6bdb195 100644
--- a/tcl/fpga/altera-cyclonev.cfg
+++ b/tcl/fpga/altera-cyclonev.cfg
@@ -44,4 +44,4 @@ jtag newtap $_CHIPNAME tap -irlen 10 \
   -expected-id 0x02d110dd -expected-id 0x02d010dd \
   -expected-id 0x02d120dd -expected-id 0x02d020dd
 
-pld device intel $_CHIPNAME.tap cyclonev
+pld device intel $_CHIPNAME.pld $_CHIPNAME.tap cyclonev
diff --git a/tcl/fpga/efinix_titanium.cfg b/tcl/fpga/efinix_titanium.cfg
index 681b58fc81..15f9209c44 100644
--- a/tcl/fpga/efinix_titanium.cfg
+++ b/tcl/fpga/efinix_titanium.cfg
@@ -20,4 +20,4 @@ jtag newtap $_CHIPNAME tap -irlen 5 -ignore-version \
        -expected-id 0x00680A79 \
        -expected-id 0x00684A79
 
-pld device efinix $_CHIPNAME.tap
+pld device efinix $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/efinix_trion.cfg b/tcl/fpga/efinix_trion.cfg
index ecd2edad4f..cbef819dfe 100644
--- a/tcl/fpga/efinix_trion.cfg
+++ b/tcl/fpga/efinix_trion.cfg
@@ -14,4 +14,4 @@ jtag newtap $_CHIPNAME tap -irlen 4 -ignore-version \
        -expected-id 0x00240A79 \
        -expected-id 0x00220A79
 
-pld device efinix $_CHIPNAME.tap
+pld device efinix $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/gatemate.cfg b/tcl/fpga/gatemate.cfg
index cc19fd4c20..6465d638db 100644
--- a/tcl/fpga/gatemate.cfg
+++ b/tcl/fpga/gatemate.cfg
@@ -13,4 +13,4 @@ if { [info exists CHIPNAME] } {
 jtag newtap $_CHIPNAME tap -irlen 6 -ignore-version \
        -expected-id 0x20000001
 
-pld device gatemate $_CHIPNAME.tap
+pld device gatemate $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/gowin_gw1n.cfg b/tcl/fpga/gowin_gw1n.cfg
index 43d66b70eb..9e4d25f160 100644
--- a/tcl/fpga/gowin_gw1n.cfg
+++ b/tcl/fpga/gowin_gw1n.cfg
@@ -26,4 +26,4 @@ jtag newtap $_CHIPNAME tap -irlen 8 -ignore-version \
        -expected-id 0x1100181B \
        -expected-id 0x0100481B
 
-pld device gowin $_CHIPNAME.tap
+pld device gowin $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/lattice_certus.cfg b/tcl/fpga/lattice_certus.cfg
index 95b6e59d8b..38092ab28a 100644
--- a/tcl/fpga/lattice_certus.cfg
+++ b/tcl/fpga/lattice_certus.cfg
@@ -15,4 +15,4 @@ if { [info exists CHIPNAME] } {
 jtag newtap $_CHIPNAME tap -irlen 8 -irmask 0x83 -ircapture 0x1 \
        -expected-id 0x310F1043 -expected-id 0x310F0043
 
-pld device lattice $_CHIPNAME.tap
+pld device lattice $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/lattice_certuspro.cfg b/tcl/fpga/lattice_certuspro.cfg
index c15a379aea..f4f7957b79 100644
--- a/tcl/fpga/lattice_certuspro.cfg
+++ b/tcl/fpga/lattice_certuspro.cfg
@@ -15,4 +15,4 @@ jtag newtap $_CHIPNAME tap -irlen 8 -irmask 0x83 -ircapture 
0x1 \
        -expected-id 0x010f4043
 #    -expected-id 0x01112043
 
-pld device lattice $_CHIPNAME.tap
+pld device lattice $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/lattice_ecp2.cfg b/tcl/fpga/lattice_ecp2.cfg
index a1aa2eff1f..a63bffb1f1 100644
--- a/tcl/fpga/lattice_ecp2.cfg
+++ b/tcl/fpga/lattice_ecp2.cfg
@@ -28,4 +28,4 @@ jtag newtap $_CHIPNAME tap -irlen 8  \
        -expected-id 0x01271043 -expected-id 0x01272043 -expected-id 0x01274043 
\
        -expected-id 0x01273043 -expected-id 0x01275043
 
-pld device lattice $_CHIPNAME.tap
+pld device lattice $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/lattice_ecp3.cfg b/tcl/fpga/lattice_ecp3.cfg
index 7cd5706495..3654eb7019 100644
--- a/tcl/fpga/lattice_ecp3.cfg
+++ b/tcl/fpga/lattice_ecp3.cfg
@@ -19,4 +19,4 @@ jtag newtap $_CHIPNAME tap -irlen 8  \
        -expected-id 0x01010043 -expected-id 0x01012043 \
        -expected-id 0x01014043 -expected-id 0x01015043
 
-pld device lattice $_CHIPNAME.tap
+pld device lattice $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/fpga/lattice_ecp5.cfg b/tcl/fpga/lattice_ecp5.cfg
index 41442492e9..7933320129 100644
--- a/tcl/fpga/lattice_ecp5.cfg
+++ b/tcl/fpga/lattice_ecp5.cfg
@@ -27,4 +27,4 @@ jtag newtap $_CHIPNAME tap -irlen 8 -irmask 0x83 -ircapture 
0x1 \
        -expected-id 0x41113043 -expected-id 0x81111043 -expected-id 0x81112043 
\
        -expected-id 0x81113043
 
-pld device lattice $_CHIPNAME.tap
+pld device lattice $_CHIPNAME.pld $_CHIPNAME.tap
diff --git a/tcl/target/zynq_7000.cfg b/tcl/target/zynq_7000.cfg
index a6f8995417..01eb07f6b6 100644
--- a/tcl/target/zynq_7000.cfg
+++ b/tcl/target/zynq_7000.cfg
@@ -46,7 +46,7 @@ adapter speed 1000
 ${_TARGETNAME}0 configure -event reset-assert-post "cortex_a dbginit"
 ${_TARGETNAME}1 configure -event reset-assert-post "cortex_a dbginit"
 
-pld device virtex2 zynq_pl.bs 1
+pld device virtex2 zynq_pl.pld zynq_pl.bs 1
 
 set XC7_JSHUTDOWN 0x0d
 set XC7_JPROGRAM 0x0b

-- 

Reply via email to