jtagspi/pld: add support from lattice ecp2/ecp3 driver 23/7823/12
authorDaniel Anselmi <danselmi@gmx.ch>
Fri, 24 Feb 2023 14:57:30 +0000 (15:57 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 23 Sep 2023 14:33:59 +0000 (14:33 +0000)
Provide jtagspi with specific procedures to be able to
use jtagspi for programming spi-flash devices on lattice
ecp2 and ecp3 devices.

Change-Id: I39028aba47a74a0479be16d52d318f4bff7f2ed4
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/7823
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/pld/ecp2_3.c
src/pld/ecp2_3.h
src/pld/lattice.c

index b1c2833d53b868e85a28670da96381e6e302c0f3..a7b7580c72ca945dd386648e5e737c2e36971a34 100644 (file)
@@ -21,6 +21,7 @@
 #define ISC_DISABLE          0x1E
 #define LSCC_READ_STATUS     0x53
 #define LSCC_BITSTREAM_BURST 0x02
+#define PROGRAM_SPI          0x3A
 
 #define STATUS_DONE_BIT        0x00020000
 #define STATUS_ERROR_BITS_ECP2 0x00040003
@@ -249,3 +250,57 @@ int lattice_ecp3_load(struct lattice_pld_device *lattice_device, struct lattice_
        const uint32_t expected = STATUS_DONE_BIT;
        return lattice_verify_status_register_u32(lattice_device, out, expected, mask, false);
 }
+
+int lattice_ecp2_3_connect_spi_to_jtag(struct lattice_pld_device *pld_device_info)
+{
+       if (!pld_device_info)
+               return ERROR_FAIL;
+
+       struct jtag_tap *tap = pld_device_info->tap;
+       if (!tap)
+               return ERROR_FAIL;
+
+       // erase configuration
+       int retval = lattice_set_instr(tap, ISC_ENABLE, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = lattice_set_instr(tap, ISC_ERASE, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = lattice_set_instr(tap, ISC_DISABLE, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+
+       // connect jtag to spi pins
+       retval = lattice_set_instr(tap, PROGRAM_SPI, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+
+       return jtag_execute_queue();
+}
+
+int lattice_ecp2_3_disconnect_spi_from_jtag(struct lattice_pld_device *pld_device_info)
+{
+       if (!pld_device_info)
+               return ERROR_FAIL;
+
+       struct jtag_tap *tap = pld_device_info->tap;
+       if (!tap)
+               return ERROR_FAIL;
+
+       int retval = lattice_set_instr(tap, BYPASS, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+
+       return jtag_execute_queue();
+}
+
+int lattice_ecp2_3_get_facing_read_bits(struct lattice_pld_device *pld_device_info, unsigned int *facing_read_bits)
+{
+       if (!pld_device_info)
+               return ERROR_FAIL;
+
+       *facing_read_bits = 1;
+
+       return ERROR_OK;
+}
index 5f3e9e97b3b99278fb049972e9736e0125343385..c5dec5693a1ed1960e27bdd0fb6b2d02b01183a3 100644 (file)
@@ -15,5 +15,8 @@ int lattice_ecp2_3_read_usercode(struct jtag_tap *tap, uint32_t *usercode, uint3
 int lattice_ecp2_3_write_usercode(struct lattice_pld_device *lattice_device, uint32_t usercode);
 int lattice_ecp2_load(struct lattice_pld_device *lattice_device, struct lattice_bit_file *bit_file);
 int lattice_ecp3_load(struct lattice_pld_device *lattice_device, struct lattice_bit_file *bit_file);
+int lattice_ecp2_3_connect_spi_to_jtag(struct lattice_pld_device *pld_device_info);
+int lattice_ecp2_3_disconnect_spi_from_jtag(struct lattice_pld_device *pld_device_info);
+int lattice_ecp2_3_get_facing_read_bits(struct lattice_pld_device *pld_device_info, unsigned int *facing_read_bits);
 
 #endif /* OPENOCD_PLD_ECP2_3_H */
index 0cd08dd331263153ce414d280989c09658101351..4085ec194ed3af604bbc0833e886e2b33ec1f9d6 100644 (file)
@@ -342,6 +342,64 @@ static int lattice_get_ipdbg_hub(int user_num, struct pld_device *pld_device, st
        return ERROR_OK;
 }
 
+static int lattice_connect_spi_to_jtag(struct pld_device *pld_device)
+{
+       if (!pld_device)
+               return ERROR_FAIL;
+
+       struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
+
+       int retval = lattice_check_device_family(pld_device_info);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family == LATTICE_ECP3)
+               return lattice_ecp2_3_connect_spi_to_jtag(pld_device_info);
+
+       return ERROR_FAIL;
+}
+
+static int lattice_disconnect_spi_from_jtag(struct pld_device *pld_device)
+{
+       if (!pld_device)
+               return ERROR_FAIL;
+
+       struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
+
+       int retval = lattice_check_device_family(pld_device_info);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family == LATTICE_ECP3)
+               return lattice_ecp2_3_disconnect_spi_from_jtag(pld_device_info);
+
+       return ERROR_FAIL;
+}
+
+static int lattice_get_stuff_bits(struct pld_device *pld_device, unsigned int *facing_read_bits,
+               unsigned int *trailing_write_bits)
+{
+       if (!pld_device)
+               return ERROR_FAIL;
+
+       struct lattice_pld_device *pld_device_info = pld_device->driver_priv;
+
+       int retval = lattice_check_device_family(pld_device_info);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (pld_device_info->family == LATTICE_ECP2 || pld_device_info->family == LATTICE_ECP3)
+               return lattice_ecp2_3_get_facing_read_bits(pld_device_info, facing_read_bits);
+
+       return ERROR_FAIL;
+}
+
+static int lattice_has_jtagspi_instruction(struct pld_device *device, bool *has_instruction)
+{
+       *has_instruction = true;
+       return ERROR_OK;
+}
+
 PLD_CREATE_COMMAND_HANDLER(lattice_pld_create_command)
 {
        if (CMD_ARGC != 4 && CMD_ARGC != 6)
@@ -551,4 +609,8 @@ struct pld_driver lattice_pld = {
        .pld_create_command = &lattice_pld_create_command,
        .load = &lattice_load_command,
        .get_ipdbg_hub = lattice_get_ipdbg_hub,
+       .has_jtagspi_instruction = lattice_has_jtagspi_instruction,
+       .connect_spi_to_jtag = lattice_connect_spi_to_jtag,
+       .disconnect_spi_from_jtag = lattice_disconnect_spi_from_jtag,
+       .get_stuff_bits = lattice_get_stuff_bits,
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)