From 15f74c2595fe20235b27ce079a35e066d6b6611c Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Wed, 20 Dec 2023 13:20:27 +0100 Subject: drivers/libusb_helper: introduce oocd_libusb_dev_mem_alloc() helper On some systems (at least Windows/CYGWIN and macOS) libusb_dev_mem_alloc() simply returns NULL. Use the result of the very first libusb_dev_mem_alloc() call to decide if the underlining system supports dev mem allocation or we should fall-back to plain heap malloc(). From the decision time on, keep using the selected type of memory allocator and deallocator. Signed-off-by: Tomas Vanek Change-Id: Ia1f0965cea44b4bb6d936b02ec43f5a16a46f080 Reviewed-on: https://review.openocd.org/c/openocd/+/8059 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/libusb_helper.c | 56 ++++++++++++++++++++++++++++++++++++++++ src/jtag/drivers/libusb_helper.h | 23 +++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src/jtag/drivers/libusb_helper.c b/src/jtag/drivers/libusb_helper.c index 9d788ee..57ea8cd 100644 --- a/src/jtag/drivers/libusb_helper.c +++ b/src/jtag/drivers/libusb_helper.c @@ -377,3 +377,59 @@ int jtag_libusb_handle_events_completed(int *completed) { return libusb_handle_events_completed(jtag_libusb_context, completed); } + +static enum { + DEV_MEM_NOT_YET_DECIDED, + DEV_MEM_AVAILABLE, + DEV_MEM_FALLBACK_MALLOC +} dev_mem_allocation; + +/* Older libusb does not implement following API calls - define stubs instead */ +#if !defined(LIBUSB_API_VERSION) || (LIBUSB_API_VERSION < 0x01000105) +static uint8_t *libusb_dev_mem_alloc(libusb_device_handle *devh, size_t length) +{ + return NULL; +} + +static int libusb_dev_mem_free(libusb_device_handle *devh, + uint8_t *buffer, size_t length) +{ + return LIBUSB_ERROR_NOT_SUPPORTED; +} +#endif + +uint8_t *oocd_libusb_dev_mem_alloc(libusb_device_handle *devh, + size_t length) +{ + uint8_t *buffer = NULL; + if (dev_mem_allocation != DEV_MEM_FALLBACK_MALLOC) + buffer = libusb_dev_mem_alloc(devh, length); + + if (dev_mem_allocation == DEV_MEM_NOT_YET_DECIDED) + dev_mem_allocation = buffer ? DEV_MEM_AVAILABLE : DEV_MEM_FALLBACK_MALLOC; + + if (dev_mem_allocation == DEV_MEM_FALLBACK_MALLOC) + buffer = malloc(length); + + return buffer; +} + +int oocd_libusb_dev_mem_free(libusb_device_handle *devh, + uint8_t *buffer, size_t length) +{ + if (!buffer) + return ERROR_OK; + + switch (dev_mem_allocation) { + case DEV_MEM_AVAILABLE: + return jtag_libusb_error(libusb_dev_mem_free(devh, buffer, length)); + + case DEV_MEM_FALLBACK_MALLOC: + free(buffer); + return ERROR_OK; + + case DEV_MEM_NOT_YET_DECIDED: + return ERROR_FAIL; + } + return ERROR_FAIL; +} diff --git a/src/jtag/drivers/libusb_helper.h b/src/jtag/drivers/libusb_helper.h index 09309b4..3cd83c6 100644 --- a/src/jtag/drivers/libusb_helper.h +++ b/src/jtag/drivers/libusb_helper.h @@ -67,4 +67,27 @@ int jtag_libusb_choose_interface(struct libusb_device_handle *devh, int jtag_libusb_get_pid(struct libusb_device *dev, uint16_t *pid); int jtag_libusb_handle_events_completed(int *completed); +/** + * Attempts to allocate a block of persistent DMA memory suitable for transfers + * against the USB device. Fall-back to the ordinary heap malloc() + * if the first libusb_dev_mem_alloc() call fails. + * @param devh _libusb_ device handle. + * @param length size of desired data buffer + * @returns a pointer to the newly allocated memory, or NULL on failure + */ +uint8_t *oocd_libusb_dev_mem_alloc(libusb_device_handle *devh, + size_t length); + +/** + * Free device memory allocated with oocd_libusb_dev_mem_alloc(). + * Uses either libusb_dev_mem_free() or free() consistently with + * the used method of allocation. + * @param devh _libusb_ device handle. + * @param buffer pointer to the previously allocated memory + * @param length size of desired data buffer + * @returns Returns ERROR_OK on success, ERROR_FAIL otherwise. + */ +int oocd_libusb_dev_mem_free(libusb_device_handle *devh, + uint8_t *buffer, size_t length); + #endif /* OPENOCD_JTAG_DRIVERS_LIBUSB_HELPER_H */ -- cgit v1.1 From 44e02e1f49cc09703cb3b4088d0c1c4f9e2d9c87 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 10 Dec 2023 11:58:43 +0100 Subject: jtag/drivers/cmsis_dap: use oocd_libusb_dev_mem_alloc() helper On some systems (at least Windows/CYGWIN and macOS) libusb_dev_mem_alloc() simply returns NULL. The helper can fall-back to malloc() to allocate CMSIS-DAP pending command/response buffers. Fixes: fd75e9e54270 (jtag/drivers/cmsis_dap_bulk: use asynchronous libusb transfer) Signed-off-by: Tomas Vanek Change-Id: I89660f6747ad9d494b8192711cbbee5764e058fa Reviewed-on: https://review.openocd.org/c/openocd/+/8044 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/jtag/drivers/cmsis_dap_usb_bulk.c | 41 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/jtag/drivers/cmsis_dap_usb_bulk.c b/src/jtag/drivers/cmsis_dap_usb_bulk.c index 17e490f..92a972a 100644 --- a/src/jtag/drivers/cmsis_dap_usb_bulk.c +++ b/src/jtag/drivers/cmsis_dap_usb_bulk.c @@ -33,12 +33,6 @@ #include "cmsis_dap.h" #include "libusb_helper.h" -#if !defined(LIBUSB_API_VERSION) || (LIBUSB_API_VERSION < 0x01000105) \ - || defined(_WIN32) || defined(__CYGWIN__) - #define libusb_dev_mem_alloc(dev, sz) malloc(sz) - #define libusb_dev_mem_free(dev, buffer, sz) free(buffer) -#endif - enum { CMSIS_DAP_TRANSFER_PENDING = 0, /* must be 0, used in libusb_handle_events_completed */ CMSIS_DAP_TRANSFER_IDLE, @@ -599,33 +593,34 @@ static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) dap->command = dap->packet_buffer; dap->response = dap->packet_buffer; + struct cmsis_dap_backend_data *bdata = dap->bdata; for (unsigned int i = 0; i < MAX_PENDING_REQUESTS; i++) { - dap->bdata->command_transfers[i].buffer = - libusb_dev_mem_alloc(dap->bdata->dev_handle, pkt_sz); - if (!dap->bdata->command_transfers[i].buffer) { - LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); - return ERROR_FAIL; - } - dap->bdata->response_transfers[i].buffer = - libusb_dev_mem_alloc(dap->bdata->dev_handle, pkt_sz); - if (!dap->bdata->response_transfers[i].buffer) { - LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); + bdata->command_transfers[i].buffer = + oocd_libusb_dev_mem_alloc(bdata->dev_handle, pkt_sz); + + bdata->response_transfers[i].buffer = + oocd_libusb_dev_mem_alloc(bdata->dev_handle, pkt_sz); + + if (!bdata->command_transfers[i].buffer + || !bdata->response_transfers[i].buffer) { + LOG_ERROR("unable to allocate CMSIS-DAP pending packet buffer"); return ERROR_FAIL; } } - return ERROR_OK; } static void cmsis_dap_usb_free(struct cmsis_dap *dap) { + struct cmsis_dap_backend_data *bdata = dap->bdata; + for (unsigned int i = 0; i < MAX_PENDING_REQUESTS; i++) { - libusb_dev_mem_free(dap->bdata->dev_handle, - dap->bdata->command_transfers[i].buffer, dap->packet_size); - dap->bdata->command_transfers[i].buffer = NULL; - libusb_dev_mem_free(dap->bdata->dev_handle, - dap->bdata->response_transfers[i].buffer, dap->packet_size); - dap->bdata->response_transfers[i].buffer = NULL; + oocd_libusb_dev_mem_free(bdata->dev_handle, + bdata->command_transfers[i].buffer, dap->packet_size); + oocd_libusb_dev_mem_free(bdata->dev_handle, + bdata->response_transfers[i].buffer, dap->packet_size); + bdata->command_transfers[i].buffer = NULL; + bdata->response_transfers[i].buffer = NULL; } free(dap->packet_buffer); -- cgit v1.1 From d2b2ac28d9a240a534a8e8bbe2fb0e791f003807 Mon Sep 17 00:00:00 2001 From: Daniel Anselmi Date: Sun, 12 Mar 2023 01:43:32 +0100 Subject: ipdbg: improve ipdbg-host speed By queuing multiple jtag transfers the connection speed between JTAG-Host and JTAG-Hub is improved. This is due to much less calls to OS functions. An improvement of about x30 has been measured with ftdi-based jtag adapters For this to work the JTAG-Host server needs to know if flow control is enabled on the JTAG-Hub ports. This is possible with newer JTAG-Hub/JtagCDC. For old JTAG-Hubs the queuing is not enabled so this change is backwards compatible. Change-Id: I8a5108adbe2a2c1e3d3620b5c9ff77a546bfc14e Signed-off-by: Daniel Anselmi Reviewed-on: https://review.openocd.org/c/openocd/+/7978 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/server/ipdbg.c | 276 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 209 insertions(+), 67 deletions(-) diff --git a/src/server/ipdbg.c b/src/server/ipdbg.c index c1bdb29..0733230 100644 --- a/src/server/ipdbg.c +++ b/src/server/ipdbg.c @@ -20,6 +20,17 @@ #define IPDBG_MIN_DR_LENGTH 11 #define IPDBG_MAX_DR_LENGTH 13 #define IPDBG_TCP_PORT_STR_MAX_LENGTH 6 +#define IPDBG_SCRATCH_MEMORY_SIZE 1024 +#define IPDBG_EMPTY_DOWN_TRANSFERS 1024 +#define IPDBG_CONSECUTIVE_UP_TRANSFERS 1024 + +#if IPDBG_SCRATCH_MEMORY_SIZE < IPDBG_EMPTY_DOWN_TRANSFERS +#error "scratch Memory must be at least IPDBG_EMPTY_DOWN_TRANSFERS" +#endif + +#if IPDBG_SCRATCH_MEMORY_SIZE < IPDBG_CONSECUTIVE_UP_TRANSFERS +#error "scratch Memory must be at least IPDBG_CONSECUTIVE_UP_TRANSFERS" +#endif /* private connection data for IPDBG */ struct ipdbg_fifo { @@ -48,6 +59,13 @@ struct ipdbg_virtual_ir_info { uint32_t value; }; +struct ipdbg_hub_scratch_memory { + uint8_t *dr_out_vals; + uint8_t *dr_in_vals; + uint8_t *vir_out_val; + struct scan_field *fields; +}; + struct ipdbg_hub { uint32_t user_instruction; uint32_t max_tools; @@ -62,7 +80,9 @@ struct ipdbg_hub { struct connection **connections; uint8_t data_register_length; uint8_t dn_xoff; + uint8_t flow_control_enabled; struct ipdbg_virtual_ir_info *virtual_ir; + struct ipdbg_hub_scratch_memory scratch_memory; }; static struct ipdbg_hub *ipdbg_first_hub; @@ -236,20 +256,28 @@ static int ipdbg_create_hub(struct jtag_tap *tap, uint32_t user_instruction, uin { *hub = NULL; struct ipdbg_hub *new_hub = calloc(1, sizeof(struct ipdbg_hub)); - if (!new_hub) { - free(virtual_ir); - LOG_ERROR("Out of memory"); - return ERROR_FAIL; - } + if (!new_hub) + goto mem_err_hub; + const size_t dreg_buffer_size = DIV_ROUND_UP(data_register_length, 8); new_hub->max_tools = ipdbg_max_tools_from_data_register_length(data_register_length); + + new_hub->scratch_memory.dr_out_vals = calloc(IPDBG_SCRATCH_MEMORY_SIZE, dreg_buffer_size); + new_hub->scratch_memory.dr_in_vals = calloc(IPDBG_SCRATCH_MEMORY_SIZE, dreg_buffer_size); + new_hub->scratch_memory.fields = calloc(IPDBG_SCRATCH_MEMORY_SIZE, sizeof(struct scan_field)); new_hub->connections = calloc(new_hub->max_tools, sizeof(struct connection *)); - if (!new_hub->connections) { - free(virtual_ir); - free(new_hub); - LOG_ERROR("Out of memory"); - return ERROR_FAIL; - } + + if (virtual_ir) + new_hub->scratch_memory.vir_out_val = calloc(1, DIV_ROUND_UP(virtual_ir->length, 8)); + + if (!new_hub->scratch_memory.dr_out_vals || !new_hub->scratch_memory.dr_in_vals || + !new_hub->scratch_memory.fields || (virtual_ir && !new_hub->scratch_memory.vir_out_val) || + !new_hub->connections) + goto mem_err2; + + if (virtual_ir) + buf_set_u32(new_hub->scratch_memory.vir_out_val, 0, virtual_ir->length, virtual_ir->value); + new_hub->tap = tap; new_hub->user_instruction = user_instruction; new_hub->data_register_length = data_register_length; @@ -260,8 +288,19 @@ static int ipdbg_create_hub(struct jtag_tap *tap, uint32_t user_instruction, uin new_hub->virtual_ir = virtual_ir; *hub = new_hub; - return ERROR_OK; + +mem_err2: + free(new_hub->scratch_memory.vir_out_val); + free(new_hub->connections); + free(new_hub->scratch_memory.fields); + free(new_hub->scratch_memory.dr_in_vals); + free(new_hub->scratch_memory.dr_out_vals); + free(new_hub); +mem_err_hub: + free(virtual_ir); + LOG_ERROR("Out of memory"); + return ERROR_FAIL; } static void ipdbg_free_hub(struct ipdbg_hub *hub) @@ -270,6 +309,10 @@ static void ipdbg_free_hub(struct ipdbg_hub *hub) return; free(hub->connections); free(hub->virtual_ir); + free(hub->scratch_memory.dr_out_vals); + free(hub->scratch_memory.dr_in_vals); + free(hub->scratch_memory.fields); + free(hub->scratch_memory.vir_out_val); free(hub); } @@ -348,20 +391,11 @@ static int ipdbg_shift_vir(struct ipdbg_hub *hub) if (!tap) return ERROR_FAIL; - uint8_t *dr_out_val = calloc(DIV_ROUND_UP(hub->virtual_ir->length, 8), 1); - if (!dr_out_val) { - LOG_ERROR("Out of memory"); - return ERROR_FAIL; - } - buf_set_u32(dr_out_val, 0, hub->virtual_ir->length, hub->virtual_ir->value); - - struct scan_field fields; - ipdbg_init_scan_field(&fields, NULL, hub->virtual_ir->length, dr_out_val); - jtag_add_dr_scan(tap, 1, &fields, TAP_IDLE); + ipdbg_init_scan_field(hub->scratch_memory.fields, NULL, + hub->virtual_ir->length, hub->scratch_memory.vir_out_val); + jtag_add_dr_scan(tap, 1, hub->scratch_memory.fields, TAP_IDLE); retval = jtag_execute_queue(); - free(dr_out_val); - return retval; } @@ -374,33 +408,15 @@ static int ipdbg_shift_data(struct ipdbg_hub *hub, uint32_t dn_data, uint32_t *u if (!tap) return ERROR_FAIL; - uint8_t *dr_out_val = calloc(DIV_ROUND_UP(hub->data_register_length, 8), 1); - if (!dr_out_val) { - LOG_ERROR("Out of memory"); - return ERROR_FAIL; - } - buf_set_u32(dr_out_val, 0, hub->data_register_length, dn_data); - - uint8_t *dr_in_val = NULL; - if (up_data) { - dr_in_val = calloc(DIV_ROUND_UP(hub->data_register_length, 8), 1); - if (!dr_in_val) { - LOG_ERROR("Out of memory"); - free(dr_out_val); - return ERROR_FAIL; - } - } + buf_set_u32(hub->scratch_memory.dr_out_vals, 0, hub->data_register_length, dn_data); - struct scan_field fields; - ipdbg_init_scan_field(&fields, dr_in_val, hub->data_register_length, dr_out_val); - jtag_add_dr_scan(tap, 1, &fields, TAP_IDLE); + ipdbg_init_scan_field(hub->scratch_memory.fields, hub->scratch_memory.dr_in_vals, + hub->data_register_length, hub->scratch_memory.dr_out_vals); + jtag_add_dr_scan(tap, 1, hub->scratch_memory.fields, TAP_IDLE); int retval = jtag_execute_queue(); if (up_data && retval == ERROR_OK) - *up_data = buf_get_u32(dr_in_val, 0, hub->data_register_length); - - free(dr_out_val); - free(dr_in_val); + *up_data = buf_get_u32(hub->scratch_memory.dr_in_vals, 0, hub->data_register_length); return retval; } @@ -432,6 +448,60 @@ static int ipdbg_distribute_data_from_hub(struct ipdbg_hub *hub, uint32_t up) return ERROR_OK; } +static void ipdbg_check_for_xoff(struct ipdbg_hub *hub, size_t tool, + uint32_t rx_data) +{ + if ((rx_data & hub->xoff_mask) && hub->last_dn_tool != hub->max_tools) { + hub->dn_xoff |= BIT(hub->last_dn_tool); + LOG_INFO("tool %d sent xoff", hub->last_dn_tool); + } + + hub->last_dn_tool = tool; +} + +static int ipdbg_shift_empty_data(struct ipdbg_hub *hub) +{ + if (!hub) + return ERROR_FAIL; + + struct jtag_tap *tap = hub->tap; + if (!tap) + return ERROR_FAIL; + + const size_t dreg_buffer_size = DIV_ROUND_UP(hub->data_register_length, 8); + memset(hub->scratch_memory.dr_out_vals, 0, dreg_buffer_size); + for (size_t i = 0; i < IPDBG_EMPTY_DOWN_TRANSFERS; ++i) { + ipdbg_init_scan_field(hub->scratch_memory.fields + i, + hub->scratch_memory.dr_in_vals + i * dreg_buffer_size, + hub->data_register_length, + hub->scratch_memory.dr_out_vals); + jtag_add_dr_scan(tap, 1, hub->scratch_memory.fields + i, TAP_IDLE); + } + + int retval = jtag_execute_queue(); + + if (retval == ERROR_OK) { + uint32_t up_data; + for (size_t i = 0; i < IPDBG_EMPTY_DOWN_TRANSFERS; ++i) { + up_data = buf_get_u32(hub->scratch_memory.dr_in_vals + + i * dreg_buffer_size, 0, + hub->data_register_length); + int rv = ipdbg_distribute_data_from_hub(hub, up_data); + if (rv != ERROR_OK) + retval = rv; + + if (i == 0) { + /* check if xoff sent is only needed on the first transfer which + may contain the xoff of the prev down transfer. + */ + ipdbg_check_for_xoff(hub, hub->max_tools, up_data); + } + } + } + + return retval; +} + static int ipdbg_jtag_transfer_byte(struct ipdbg_hub *hub, size_t tool, struct ipdbg_connection *connection) { uint32_t dn = hub->valid_mask | ((tool & hub->tool_mask) << 8) | @@ -445,14 +515,63 @@ static int ipdbg_jtag_transfer_byte(struct ipdbg_hub *hub, size_t tool, struct i if (ret != ERROR_OK) return ret; - if ((up & hub->xoff_mask) && (hub->last_dn_tool != hub->max_tools)) { - hub->dn_xoff |= BIT(hub->last_dn_tool); - LOG_INFO("tool %d sent xoff", hub->last_dn_tool); + ipdbg_check_for_xoff(hub, tool, up); + + return ERROR_OK; +} + +static int ipdbg_jtag_transfer_bytes(struct ipdbg_hub *hub, + size_t tool, struct ipdbg_connection *connection) +{ + if (!hub) + return ERROR_FAIL; + + struct jtag_tap *tap = hub->tap; + if (!tap) + return ERROR_FAIL; + + const size_t dreg_buffer_size = DIV_ROUND_UP(hub->data_register_length, 8); + size_t num_tx = (connection->dn_fifo.count < IPDBG_CONSECUTIVE_UP_TRANSFERS) ? + connection->dn_fifo.count : IPDBG_CONSECUTIVE_UP_TRANSFERS; + + for (size_t i = 0; i < num_tx; ++i) { + uint32_t dn_data = hub->valid_mask | ((tool & hub->tool_mask) << 8) | + (0x00fful & ipdbg_get_from_fifo(&connection->dn_fifo)); + buf_set_u32(hub->scratch_memory.dr_out_vals + i * dreg_buffer_size, 0, + hub->data_register_length, dn_data); + + ipdbg_init_scan_field(hub->scratch_memory.fields + i, + hub->scratch_memory.dr_in_vals + + i * dreg_buffer_size, + hub->data_register_length, + hub->scratch_memory.dr_out_vals + + i * dreg_buffer_size); + jtag_add_dr_scan(tap, 1, hub->scratch_memory.fields + i, TAP_IDLE); } - hub->last_dn_tool = tool; + int retval = jtag_execute_queue(); - return ERROR_OK; + if (retval == ERROR_OK) { + uint32_t up_data; + for (size_t i = 0; i < num_tx; ++i) { + up_data = buf_get_u32(hub->scratch_memory.dr_in_vals + + i * dreg_buffer_size, + 0, hub->data_register_length); + int rv = ipdbg_distribute_data_from_hub(hub, up_data); + if (rv != ERROR_OK) + retval = rv; + if (i == 0) { + /* check if xoff sent is only needed on the first transfer which + may contain the xoff of the prev down transfer. + No checks for this channel because this function is only + called for channels without enabled flow control. + */ + ipdbg_check_for_xoff(hub, tool, up_data); + } + } + } + + return retval; } static int ipdbg_polling_callback(void *priv) @@ -468,33 +587,25 @@ static int ipdbg_polling_callback(void *priv) return ret; /* transfer dn buffers to jtag-hub */ - unsigned int num_transfers = 0; for (size_t tool = 0; tool < hub->max_tools; ++tool) { struct connection *conn = hub->connections[tool]; if (conn && conn->priv) { struct ipdbg_connection *connection = conn->priv; while (((hub->dn_xoff & BIT(tool)) == 0) && !ipdbg_fifo_is_empty(&connection->dn_fifo)) { - ret = ipdbg_jtag_transfer_byte(hub, tool, connection); + if (hub->flow_control_enabled & BIT(tool)) + ret = ipdbg_jtag_transfer_byte(hub, tool, connection); + else + ret = ipdbg_jtag_transfer_bytes(hub, tool, connection); if (ret != ERROR_OK) return ret; - ++num_transfers; } } } /* some transfers to get data from jtag-hub in case there is no dn data */ - while (num_transfers++ < hub->max_tools) { - uint32_t dn = 0; - uint32_t up = 0; - - int retval = ipdbg_shift_data(hub, dn, &up); - if (retval != ERROR_OK) - return ret; - - retval = ipdbg_distribute_data_from_hub(hub, up); - if (retval != ERROR_OK) - return ret; - } + ret = ipdbg_shift_empty_data(hub); + if (ret != ERROR_OK) + return ret; /* write from up fifos to sockets */ for (size_t tool = 0; tool < hub->max_tools; ++tool) { @@ -510,6 +621,33 @@ static int ipdbg_polling_callback(void *priv) return ERROR_OK; } +static int ipdbg_get_flow_control_info_from_hub(struct ipdbg_hub *hub) +{ + uint32_t up_data; + + /* on older implementations the flow_control_enable_word is not sent to us. + so we don't know -> assume it's enabled on all channels */ + hub->flow_control_enabled = 0x7f; + + int ret = ipdbg_shift_data(hub, 0UL, &up_data); + if (ret != ERROR_OK) + return ret; + + const bool valid_up_data = up_data & hub->valid_mask; + if (valid_up_data) { + const size_t tool = (up_data >> 8) & hub->tool_mask; + /* the first valid data from hub is flow_control_enable_word */ + if (tool == hub->tool_mask) + hub->flow_control_enabled = up_data & 0x007f; + else + ipdbg_distribute_data_from_hub(hub, up_data); + } + + LOG_INFO("Flow control enabled on IPDBG JTAG Hub: 0x%02x", hub->flow_control_enabled); + + return ERROR_OK; +} + static int ipdbg_start_polling(struct ipdbg_service *service, struct connection *connection) { struct ipdbg_hub *hub = service->hub; @@ -536,6 +674,10 @@ static int ipdbg_start_polling(struct ipdbg_service *service, struct connection if (ret != ERROR_OK) return ret; + ret = ipdbg_get_flow_control_info_from_hub(hub); + if (ret != ERROR_OK) + return ret; + LOG_INFO("IPDBG start_polling"); const int time_ms = 20; -- cgit v1.1 From 22ebb693b62fd05bcbe2c0101e180b92ca5b11f3 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Thu, 28 Apr 2022 03:46:35 +0100 Subject: cortex_m: add detection of MVE feature for Armv8.1-M cores For Armv8.1-M based cores, detect if the core implements the optional M-profile vector extension (MVE), using MVFR1 register. While at there rework armv7m->fp_feature detection based on MVFR0 and MVFR1 registers. Change-Id: I92d5b1759aea9f7561d285f46acdec51d6efb7b4 Signed-off-by: Tarek BOCHKATI Reviewed-on: https://review.openocd.org/c/openocd/+/6950 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/target/armv7m.h | 2 ++ src/target/cortex_m.c | 51 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/target/armv7m.h b/src/target/armv7m.h index 8693404..2878dd1 100644 --- a/src/target/armv7m.h +++ b/src/target/armv7m.h @@ -211,6 +211,8 @@ enum { FPV4_SP, FPV5_SP, FPV5_DP, + FPV5_MVE_I, + FPV5_MVE_F, }; #define ARMV7M_NUM_CORE_REGS (ARMV7M_CORE_LAST_REG - ARMV7M_CORE_FIRST_REG + 1) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index d9e8b53..6a29a5f 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2486,16 +2486,17 @@ static bool cortex_m_has_tz(struct target *target) return (dauthstatus & DAUTHSTATUS_SID_MASK) != 0; } -#define MVFR0 0xe000ef40 -#define MVFR1 0xe000ef44 -#define MVFR0_DEFAULT_M4 0x10110021 -#define MVFR1_DEFAULT_M4 0x11000011 +#define MVFR0 0xE000EF40 +#define MVFR0_SP_MASK 0x000000F0 +#define MVFR0_SP 0x00000020 +#define MVFR0_DP_MASK 0x00000F00 +#define MVFR0_DP 0x00000200 -#define MVFR0_DEFAULT_M7_SP 0x10110021 -#define MVFR0_DEFAULT_M7_DP 0x10110221 -#define MVFR1_DEFAULT_M7_SP 0x11000011 -#define MVFR1_DEFAULT_M7_DP 0x12000011 +#define MVFR1 0xE000EF44 +#define MVFR1_MVE_MASK 0x00000F00 +#define MVFR1_MVE_I 0x00000100 +#define MVFR1_MVE_F 0x00000200 static int cortex_m_find_mem_ap(struct adiv5_dap *swjdp, struct adiv5_ap **debug_ap) @@ -2509,7 +2510,7 @@ static int cortex_m_find_mem_ap(struct adiv5_dap *swjdp, int cortex_m_examine(struct target *target) { int retval; - uint32_t cpuid, fpcr, mvfr0, mvfr1; + uint32_t cpuid, fpcr; struct cortex_m_common *cortex_m = target_to_cm(target); struct adiv5_dap *swjdp = cortex_m->armv7m.arm.dap; struct armv7m_common *armv7m = target_to_armv7m(target); @@ -2584,25 +2585,37 @@ int cortex_m_examine(struct target *target) LOG_TARGET_DEBUG(target, "cpuid: 0x%8.8" PRIx32 "", cpuid); if (cortex_m->core_info->flags & CORTEX_M_F_HAS_FPV4) { + uint32_t mvfr0; target_read_u32(target, MVFR0, &mvfr0); - target_read_u32(target, MVFR1, &mvfr1); - /* test for floating point feature on Cortex-M4 */ - if ((mvfr0 == MVFR0_DEFAULT_M4) && (mvfr1 == MVFR1_DEFAULT_M4)) { - LOG_TARGET_DEBUG(target, "%s floating point feature FPv4_SP found", cortex_m->core_info->name); + if ((mvfr0 & MVFR0_SP_MASK) == MVFR0_SP) { + LOG_TARGET_DEBUG(target, "%s floating point feature FPv4_SP found", + cortex_m->core_info->name); armv7m->fp_feature = FPV4_SP; } } else if (cortex_m->core_info->flags & CORTEX_M_F_HAS_FPV5) { + uint32_t mvfr0, mvfr1; target_read_u32(target, MVFR0, &mvfr0); target_read_u32(target, MVFR1, &mvfr1); - /* test for floating point features on Cortex-M7 */ - if ((mvfr0 == MVFR0_DEFAULT_M7_SP) && (mvfr1 == MVFR1_DEFAULT_M7_SP)) { - LOG_TARGET_DEBUG(target, "%s floating point feature FPv5_SP found", cortex_m->core_info->name); + if ((mvfr0 & MVFR0_DP_MASK) == MVFR0_DP) { + if ((mvfr1 & MVFR1_MVE_MASK) == MVFR1_MVE_F) { + LOG_TARGET_DEBUG(target, "%s floating point feature FPv5_DP + MVE-F found", + cortex_m->core_info->name); + armv7m->fp_feature = FPV5_MVE_F; + } else { + LOG_TARGET_DEBUG(target, "%s floating point feature FPv5_DP found", + cortex_m->core_info->name); + armv7m->fp_feature = FPV5_DP; + } + } else if ((mvfr0 & MVFR0_SP_MASK) == MVFR0_SP) { + LOG_TARGET_DEBUG(target, "%s floating point feature FPv5_SP found", + cortex_m->core_info->name); armv7m->fp_feature = FPV5_SP; - } else if ((mvfr0 == MVFR0_DEFAULT_M7_DP) && (mvfr1 == MVFR1_DEFAULT_M7_DP)) { - LOG_TARGET_DEBUG(target, "%s floating point feature FPv5_DP found", cortex_m->core_info->name); - armv7m->fp_feature = FPV5_DP; + } else if ((mvfr1 & MVFR1_MVE_MASK) == MVFR1_MVE_I) { + LOG_TARGET_DEBUG(target, "%s floating point feature MVE-I found", + cortex_m->core_info->name); + armv7m->fp_feature = FPV5_MVE_I; } } -- cgit v1.1 From 04eda372634f995c732bed4f67855be258ab0e41 Mon Sep 17 00:00:00 2001 From: ianst Date: Wed, 6 Dec 2023 14:34:09 -0800 Subject: target/xtensa: extra debug info for "xtensa exe" failures - Read and display EXCCAUSE on exe error - Clean up error messages - Clarify "xtensa exe" documentation Signed-off-by: ianst Change-Id: I90ed39f6afb6543c0c873301501435384b4dccbe Reviewed-on: https://review.openocd.org/c/openocd/+/7982 Tested-by: jenkins Reviewed-by: Antonio Borneo --- doc/openocd.texi | 9 +++++---- src/target/xtensa/xtensa.c | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 53730ea..e4d4dc5 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -11600,13 +11600,14 @@ This feature is not well implemented and tested yet. @end deffn @deffn {Command} {xtensa exe} -Execute arbitrary instruction(s) provided as an ascii string. The string represents an integer -number of instruction bytes, thus its length must be even. +Execute one arbitrary instruction provided as an ascii string. The string represents an integer +number of instruction bytes, thus its length must be even. The instruction can be of any width +that is valid for the Xtensa core configuration. @end deffn @deffn {Command} {xtensa dm} (address) [value] -Read or write Xtensa Debug Module (DM) registers. @var{address} is required for both reads -and writes and is a 4-byte-aligned value typically between 0 and 0x3ffc. @var{value} is specified +Read or write Xtensa Debug Module (DM) registers. @var{address} is required for both reads +and writes and is a 4-byte-aligned value typically between 0 and 0x3ffc. @var{value} is specified only for write accesses. @end deffn diff --git a/src/target/xtensa/xtensa.c b/src/target/xtensa/xtensa.c index d2ca32c..ab3bfbb 100644 --- a/src/target/xtensa/xtensa.c +++ b/src/target/xtensa/xtensa.c @@ -3483,15 +3483,21 @@ static COMMAND_HELPER(xtensa_cmd_exe_do, struct target *target) LOG_TARGET_DEBUG(target, "execute stub: %s", CMD_ARGV[0]); xtensa_queue_exec_ins_wide(xtensa, ops, oplen); /* Handles endian-swap */ status = xtensa_dm_queue_execute(&xtensa->dbg_mod); - if (status != ERROR_OK) - LOG_TARGET_ERROR(target, "TIE queue execute: %d\n", status); - status = xtensa_core_status_check(target); - if (status != ERROR_OK) - LOG_TARGET_ERROR(target, "TIE instr execute: %d\n", status); + if (status != ERROR_OK) { + LOG_TARGET_ERROR(target, "exec: queue error %d", status); + } else { + status = xtensa_core_status_check(target); + if (status != ERROR_OK) + LOG_TARGET_ERROR(target, "exec: status error %d", status); + } /* Reread register cache and restore saved regs after instruction execution */ if (xtensa_fetch_all_regs(target) != ERROR_OK) - LOG_TARGET_ERROR(target, "%s: Failed to fetch register cache (post-exec).", target_name(target)); + LOG_TARGET_ERROR(target, "post-exec: register fetch error"); + if (status != ERROR_OK) { + LOG_TARGET_ERROR(target, "post-exec: EXCCAUSE 0x%02" PRIx32, + xtensa_reg_get(target, XT_REG_IDX_EXCCAUSE)); + } xtensa_reg_set(target, XT_REG_IDX_EXCCAUSE, exccause); xtensa_reg_set(target, XT_REG_IDX_CPENABLE, cpenable); return status; -- cgit v1.1 From 2c10e3e2577604f5ec75b7f688f53fa2b3cbb0e7 Mon Sep 17 00:00:00 2001 From: Evgeniy Didin Date: Fri, 31 Jul 2020 00:13:12 +0300 Subject: target/arc: restore breakpoints in arc_resume() Presently, we rely on gdb to restore break/watchpoints upon resuming execution in arc_resume(). To match this behavior in absence of gdb (more specifically, when handle_breakpoints is true), this patch explicitly re-enables all breakpoints and watchpoints in arc_resume(). This has previously been committed to the Zephyr project's openocd repo (see https://github.com/zephyrproject-rtos/openocd/pull/31). Change-Id: I59e9c91270ef0b5fd19cfc570663dc67a6022dbd Signed-off-by: Evgeniy Didin Signed-off-by: Stephanos Ioannidis Signed-off-by: Artemiy Volkov Reviewed-on: https://review.openocd.org/c/openocd/+/7816 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Oleksij Rempel --- src/target/arc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/target/arc.c b/src/target/arc.c index 0f7b110..f3449aa 100644 --- a/src/target/arc.c +++ b/src/target/arc.c @@ -50,6 +50,8 @@ static int arc_remove_watchpoint(struct target *target, struct watchpoint *watchpoint); +static int arc_enable_watchpoints(struct target *target); +static int arc_enable_breakpoints(struct target *target); void arc_reg_data_type_add(struct target *target, struct arc_reg_data_type *data_type) @@ -1262,6 +1264,13 @@ static int arc_resume(struct target *target, int current, target_addr_t address, return ERROR_TARGET_NOT_HALTED; } + if (!debug_execution) { + /* (gdb) continue = execute until we hit break/watch-point */ + target_free_all_working_areas(target); + CHECK_RETVAL(arc_enable_breakpoints(target)); + CHECK_RETVAL(arc_enable_watchpoints(target)); + } + /* current = 1: continue on current PC, otherwise continue at
*/ if (!current) { target_buffer_set_u32(target, pc->value, address); @@ -1658,6 +1667,19 @@ static int arc_unset_breakpoint(struct target *target, return retval; } +static int arc_enable_breakpoints(struct target *target) +{ + struct breakpoint *breakpoint = target->breakpoints; + + /* set any pending breakpoints */ + while (breakpoint) { + if (!breakpoint->is_set) + CHECK_RETVAL(arc_set_breakpoint(target, breakpoint)); + breakpoint = breakpoint->next; + } + + return ERROR_OK; +} static int arc_add_breakpoint(struct target *target, struct breakpoint *breakpoint) { @@ -1895,6 +1917,20 @@ static int arc_unset_watchpoint(struct target *target, return retval; } +static int arc_enable_watchpoints(struct target *target) +{ + struct watchpoint *watchpoint = target->watchpoints; + + /* set any pending watchpoints */ + while (watchpoint) { + if (!watchpoint->is_set) + CHECK_RETVAL(arc_set_watchpoint(target, watchpoint)); + watchpoint = watchpoint->next; + } + + return ERROR_OK; +} + static int arc_add_watchpoint(struct target *target, struct watchpoint *watchpoint) { -- cgit v1.1 From 0de852f56130bfffa427bbc04bcea0370eecb0f3 Mon Sep 17 00:00:00 2001 From: Evgeniy Didin Date: Fri, 31 Jul 2020 00:13:12 +0300 Subject: target/arc: skip over breakpoints in arc_resume() When requested by the core code (handle_breakpoints = true), arc_resume() should be able to advance over a potential breakpoint set at the resume address instead of getting stuck in one place. This is achieved by removing the breakpoint, executing one instruction, resetting the breakpoint, then proceeding forward as normal. With this patch applied, openocd is now able to resume from a breakpoint halt when debugging ARCv2 targets via telnet. This has previously been committed to the Zephyr project's openocd repo (see https://github.com/zephyrproject-rtos/openocd/pull/31). Change-Id: I17dba0dcea311d394b303c587bc2dfaa99d67859 Signed-off-by: Evgeniy Didin Signed-off-by: Stephanos Ioannidis Signed-off-by: Artemiy Volkov Reviewed-on: https://review.openocd.org/c/openocd/+/7817 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/target/arc.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/target/arc.c b/src/target/arc.c index f3449aa..72e4d91 100644 --- a/src/target/arc.c +++ b/src/target/arc.c @@ -52,6 +52,11 @@ static int arc_remove_watchpoint(struct target *target, struct watchpoint *watchpoint); static int arc_enable_watchpoints(struct target *target); static int arc_enable_breakpoints(struct target *target); +static int arc_unset_breakpoint(struct target *target, + struct breakpoint *breakpoint); +static int arc_set_breakpoint(struct target *target, + struct breakpoint *breakpoint); +static int arc_single_step_core(struct target *target); void arc_reg_data_type_add(struct target *target, struct arc_reg_data_type *data_type) @@ -750,6 +755,29 @@ static int arc_examine(struct target *target) return ERROR_OK; } +static int arc_exit_debug(struct target *target) +{ + uint32_t value; + struct arc_common *arc = target_to_arc(target); + + /* Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally. */ + CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc->jtag_info, AUX_DEBUG_REG, &value)); + value |= SET_CORE_FORCE_HALT; /* set the HALT bit */ + CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc->jtag_info, AUX_DEBUG_REG, value)); + alive_sleep(1); + + target->state = TARGET_HALTED; + CHECK_RETVAL(target_call_event_callbacks(target, TARGET_EVENT_HALTED)); + + if (debug_level >= LOG_LVL_DEBUG) { + LOG_DEBUG("core stopped (halted) debug-reg: 0x%08" PRIx32, value); + CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc->jtag_info, AUX_STATUS32_REG, &value)); + LOG_DEBUG("core STATUS32: 0x%08" PRIx32, value); + } + + return ERROR_OK; +} + static int arc_halt(struct target *target) { uint32_t value, irq_state; @@ -1251,7 +1279,7 @@ static int arc_resume(struct target *target, int current, target_addr_t address, uint32_t value; struct reg *pc = &arc->core_and_aux_cache->reg_list[arc->pc_index_in_cache]; - LOG_DEBUG("current:%i, address:0x%08" TARGET_PRIxADDR ", handle_breakpoints(not supported yet):%i," + LOG_DEBUG("current:%i, address:0x%08" TARGET_PRIxADDR ", handle_breakpoints:%i," " debug_execution:%i", current, address, handle_breakpoints, debug_execution); /* We need to reset ARC cache variables so caches @@ -1296,6 +1324,19 @@ static int arc_resume(struct target *target, int current, target_addr_t address, CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc->jtag_info, AUX_PC_REG, value)); } + /* the front-end may request us not to handle breakpoints here */ + if (handle_breakpoints) { + /* Single step past breakpoint at current address */ + struct breakpoint *breakpoint = breakpoint_find(target, resume_pc); + if (breakpoint) { + LOG_DEBUG("skipping past breakpoint at 0x%08" TARGET_PRIxADDR, + breakpoint->address); + CHECK_RETVAL(arc_unset_breakpoint(target, breakpoint)); + CHECK_RETVAL(arc_single_step_core(target)); + CHECK_RETVAL(arc_set_breakpoint(target, breakpoint)); + } + } + /* Restore IRQ state if not in debug_execution*/ if (!debug_execution) CHECK_RETVAL(arc_enable_interrupts(target, arc->irq_state)); @@ -2027,6 +2068,22 @@ static int arc_config_step(struct target *target, int enable_step) return ERROR_OK; } +static int arc_single_step_core(struct target *target) +{ + CHECK_RETVAL(arc_debug_entry(target)); + + /* disable interrupts while stepping */ + CHECK_RETVAL(arc_enable_interrupts(target, 0)); + + /* configure single step mode */ + CHECK_RETVAL(arc_config_step(target, 1)); + + /* exit debug mode */ + CHECK_RETVAL(arc_exit_debug(target)); + + return ERROR_OK; +} + static int arc_step(struct target *target, int current, target_addr_t address, int handle_breakpoints) { -- cgit v1.1 From 305f293201a1d75f24eaa188294b78b284c8185b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 4 Jan 2024 22:26:38 +0100 Subject: LICENSES: drop SPDX tag 'GPL-2.0' and use 'GPL-2.0-only' The SPDX tag 'GPL-2.0' has been deprecated in https://spdx.org/licenses/GPL-2.0.html and the preferred tag is now 'GPL-2.0-only' https://spdx.org/licenses/GPL-2.0-only.html Update the LICENSES documents and the SPDX of the only file that reports the deprecated tag. Change-Id: I3c3215438bc4378ff470bb9fa8fa962505a9ae50 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8064 Tested-by: jenkins --- LICENSES/license-rules.txt | 3 --- LICENSES/preferred/GPL-2.0 | 3 --- src/target/mips_cpu.h | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/LICENSES/license-rules.txt b/LICENSES/license-rules.txt index c751929..ecc8e4d 100644 --- a/LICENSES/license-rules.txt +++ b/LICENSES/license-rules.txt @@ -173,7 +173,6 @@ OpenOCD, can be broken down into: File format examples:: - Valid-License-Identifier: GPL-2.0 Valid-License-Identifier: GPL-2.0-only Valid-License-Identifier: GPL-2.0-or-later SPDX-URL: https://spdx.org/licenses/GPL-2.0.html @@ -182,8 +181,6 @@ OpenOCD, can be broken down into: tag/value pairs into a comment according to the placement guidelines in the licensing rules documentation. For 'GNU General Public License (GPL) version 2 only' use: - SPDX-License-Identifier: GPL-2.0 - or SPDX-License-Identifier: GPL-2.0-only For 'GNU General Public License (GPL) version 2 or any later version' use: SPDX-License-Identifier: GPL-2.0-or-later diff --git a/LICENSES/preferred/GPL-2.0 b/LICENSES/preferred/GPL-2.0 index 2ca4651..687bddd 100644 --- a/LICENSES/preferred/GPL-2.0 +++ b/LICENSES/preferred/GPL-2.0 @@ -1,4 +1,3 @@ -Valid-License-Identifier: GPL-2.0 Valid-License-Identifier: GPL-2.0-only Valid-License-Identifier: GPL-2.0-or-later SPDX-URL: https://spdx.org/licenses/GPL-2.0.html @@ -7,8 +6,6 @@ Usage-Guide: tag/value pairs into a comment according to the placement guidelines in the licensing rules documentation. For 'GNU General Public License (GPL) version 2 only' use: - SPDX-License-Identifier: GPL-2.0 - or SPDX-License-Identifier: GPL-2.0-only For 'GNU General Public License (GPL) version 2 or any later version' use: SPDX-License-Identifier: GPL-2.0-or-later diff --git a/src/target/mips_cpu.h b/src/target/mips_cpu.h index 2f31dbd..c3b7b54 100644 --- a/src/target/mips_cpu.h +++ b/src/target/mips_cpu.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef OPENOCD_TARGET_MIPS_CPU_H #define OPENOCD_TARGET_MIPS_CPU_H -- cgit v1.1 From 6e6d486de2c668e14f9534fab820eea305826753 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 3 Dec 2023 18:10:45 +0100 Subject: target: drop deprecated code for mem2array and array2mem Commit e370e06b724f ("target: Deprecate 'array2mem' and 'mem2array''") has already replaced the deprecated root versions of commands mem2array and array2mem with TCL proc's that use 'read_memory' and 'write_memory'. It has left the deprecated code of the target's version of the commands because the effort to code the TCL replacement was not considered valuable. To drop the last jim_handler commands, I consider much easier and less error-prone to code them in TCL instead of converting the deprecated code to COMMAND_HANDLER. Drop the code in target.c and extend the TCL proc's. While there, add the TCL procs to _telnet_autocomplete_skip. Change-Id: I97d2370d8af479434ddf5af68541f90913982bc0 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8052 Tested-by: jenkins --- src/target/startup.tcl | 57 ++++--- src/target/target.c | 419 ------------------------------------------------- 2 files changed, 35 insertions(+), 441 deletions(-) diff --git a/src/target/startup.tcl b/src/target/startup.tcl index 35492a6..75e0edc 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -219,31 +219,44 @@ proc init_target_events {} { proc init_board {} { } -proc mem2array {arrayname bitwidth address count {phys ""}} { - echo "DEPRECATED! use 'read_memory' not 'mem2array'" - - upvar $arrayname $arrayname - set $arrayname "" - set i 0 - - foreach elem [read_memory $address $bitwidth $count {*}$phys] { - set ${arrayname}($i) $elem - incr i - } -} - -proc array2mem {arrayname bitwidth address count {phys ""}} { - echo "DEPRECATED! use 'write_memory' not 'array2mem'" - - upvar $arrayname $arrayname - set data "" +lappend _telnet_autocomplete_skip _post_init_target_array_mem +proc _post_init_target_array_mem {} { + set targets [target names] + lappend targets "" - for {set i 0} {$i < $count} {incr i} { - lappend data [expr $${arrayname}($i)] + foreach t $targets { + if {$t != ""} { + set t "$t " + } + eval [format {lappend ::_telnet_autocomplete_skip "%smem2array"} $t] + eval [format {proc {%smem2array} {arrayname bitwidth address count {phys ""}} { + echo "DEPRECATED! use 'read_memory' not 'mem2array'" + + upvar $arrayname $arrayname + set $arrayname "" + set i 0 + + foreach elem [%sread_memory $address $bitwidth $count {*}$phys] { + set ${arrayname}($i) $elem + incr i + } + }} $t $t] + eval [format {lappend ::_telnet_autocomplete_skip "%sarray2mem"} $t] + eval [format {proc {%sarray2mem} {arrayname bitwidth address count {phys ""}} { + echo "DEPRECATED! use 'write_memory' not 'array2mem'" + + upvar $arrayname $arrayname + set data "" + + for {set i 0} {$i < $count} {incr i} { + lappend data [expr $${arrayname}($i)] + } + + %swrite_memory $address $bitwidth $data {*}$phys + }} $t $t] } - - write_memory $address $bitwidth $data {*}$phys } +lappend post_init_commands _post_init_target_array_mem # smp_on/smp_off were already DEPRECATED in v0.11.0 through http://openocd.zylin.com/4615 lappend _telnet_autocomplete_skip "aarch64 smp_on" diff --git a/src/target/target.c b/src/target/target.c index 61890aa..920511e 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -56,10 +56,6 @@ static int target_read_buffer_default(struct target *target, target_addr_t addre uint32_t count, uint8_t *buffer); static int target_write_buffer_default(struct target *target, target_addr_t address, uint32_t count, const uint8_t *buffer); -static int target_array2mem(Jim_Interp *interp, struct target *target, - int argc, Jim_Obj * const *argv); -static int target_mem2array(Jim_Interp *interp, struct target *target, - int argc, Jim_Obj * const *argv); static int target_register_user_commands(struct command_context *cmd_ctx); static int target_get_gdb_fileio_info_default(struct target *target, struct gdb_fileio_info *fileio_info); @@ -4397,192 +4393,6 @@ COMMAND_HANDLER(handle_profile_command) return retval; } -static int new_u64_array_element(Jim_Interp *interp, const char *varname, int idx, uint64_t val) -{ - char *namebuf; - Jim_Obj *obj_name, *obj_val; - int result; - - namebuf = alloc_printf("%s(%d)", varname, idx); - if (!namebuf) - return JIM_ERR; - - obj_name = Jim_NewStringObj(interp, namebuf, -1); - jim_wide wide_val = val; - obj_val = Jim_NewWideObj(interp, wide_val); - if (!obj_name || !obj_val) { - free(namebuf); - return JIM_ERR; - } - - Jim_IncrRefCount(obj_name); - Jim_IncrRefCount(obj_val); - result = Jim_SetVariable(interp, obj_name, obj_val); - Jim_DecrRefCount(interp, obj_name); - Jim_DecrRefCount(interp, obj_val); - free(namebuf); - /* printf("%s(%d) <= 0%08x\n", varname, idx, val); */ - return result; -} - -static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, Jim_Obj *const *argv) -{ - int e; - - LOG_WARNING("DEPRECATED! use 'read_memory' not 'mem2array'"); - - /* argv[0] = name of array to receive the data - * argv[1] = desired element width in bits - * argv[2] = memory address - * argv[3] = count of times to read - * argv[4] = optional "phys" - */ - if (argc < 4 || argc > 5) { - Jim_WrongNumArgs(interp, 0, argv, "varname width addr nelems [phys]"); - return JIM_ERR; - } - - /* Arg 0: Name of the array variable */ - const char *varname = Jim_GetString(argv[0], NULL); - - /* Arg 1: Bit width of one element */ - long l; - e = Jim_GetLong(interp, argv[1], &l); - if (e != JIM_OK) - return e; - const unsigned int width_bits = l; - - if (width_bits != 8 && - width_bits != 16 && - width_bits != 32 && - width_bits != 64) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), - "Invalid width param. Must be one of: 8, 16, 32 or 64.", NULL); - return JIM_ERR; - } - const unsigned int width = width_bits / 8; - - /* Arg 2: Memory address */ - jim_wide wide_addr; - e = Jim_GetWide(interp, argv[2], &wide_addr); - if (e != JIM_OK) - return e; - target_addr_t addr = (target_addr_t)wide_addr; - - /* Arg 3: Number of elements to read */ - e = Jim_GetLong(interp, argv[3], &l); - if (e != JIM_OK) - return e; - size_t len = l; - - /* Arg 4: phys */ - bool is_phys = false; - if (argc > 4) { - int str_len = 0; - const char *phys = Jim_GetString(argv[4], &str_len); - if (!strncmp(phys, "phys", str_len)) - is_phys = true; - else - return JIM_ERR; - } - - /* Argument checks */ - if (len == 0) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: zero width read?", NULL); - return JIM_ERR; - } - if ((addr + (len * width)) < addr) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: addr + len - wraps to zero?", NULL); - return JIM_ERR; - } - if (len > 65536) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), - "mem2array: too large read request, exceeds 64K items", NULL); - return JIM_ERR; - } - - if ((width == 1) || - ((width == 2) && ((addr & 1) == 0)) || - ((width == 4) && ((addr & 3) == 0)) || - ((width == 8) && ((addr & 7) == 0))) { - /* alignment correct */ - } else { - char buf[100]; - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - sprintf(buf, "mem2array address: " TARGET_ADDR_FMT " is not aligned for %" PRIu32 " byte reads", - addr, - width); - Jim_AppendStrings(interp, Jim_GetResult(interp), buf, NULL); - return JIM_ERR; - } - - /* Transfer loop */ - - /* index counter */ - size_t idx = 0; - - const size_t buffersize = 4096; - uint8_t *buffer = malloc(buffersize); - if (!buffer) - return JIM_ERR; - - /* assume ok */ - e = JIM_OK; - while (len) { - /* Slurp... in buffer size chunks */ - const unsigned int max_chunk_len = buffersize / width; - const size_t chunk_len = MIN(len, max_chunk_len); /* in elements.. */ - - int retval; - if (is_phys) - retval = target_read_phys_memory(target, addr, width, chunk_len, buffer); - else - retval = target_read_memory(target, addr, width, chunk_len, buffer); - if (retval != ERROR_OK) { - /* BOO !*/ - LOG_ERROR("mem2array: Read @ " TARGET_ADDR_FMT ", w=%u, cnt=%zu, failed", - addr, - width, - chunk_len); - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "mem2array: cannot read memory", NULL); - e = JIM_ERR; - break; - } else { - for (size_t i = 0; i < chunk_len ; i++, idx++) { - uint64_t v = 0; - switch (width) { - case 8: - v = target_buffer_get_u64(target, &buffer[i*width]); - break; - case 4: - v = target_buffer_get_u32(target, &buffer[i*width]); - break; - case 2: - v = target_buffer_get_u16(target, &buffer[i*width]); - break; - case 1: - v = buffer[i] & 0x0ff; - break; - } - new_u64_array_element(interp, varname, idx, v); - } - len -= chunk_len; - addr += chunk_len * width; - } - } - - free(buffer); - - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - - return e; -} - COMMAND_HANDLER(handle_target_read_memory) { /* @@ -4706,201 +4516,6 @@ COMMAND_HANDLER(handle_target_read_memory) return ERROR_OK; } -static int get_u64_array_element(Jim_Interp *interp, const char *varname, size_t idx, uint64_t *val) -{ - char *namebuf = alloc_printf("%s(%zu)", varname, idx); - if (!namebuf) - return JIM_ERR; - - Jim_Obj *obj_name = Jim_NewStringObj(interp, namebuf, -1); - if (!obj_name) { - free(namebuf); - return JIM_ERR; - } - - Jim_IncrRefCount(obj_name); - Jim_Obj *obj_val = Jim_GetVariable(interp, obj_name, JIM_ERRMSG); - Jim_DecrRefCount(interp, obj_name); - free(namebuf); - if (!obj_val) - return JIM_ERR; - - jim_wide wide_val; - int result = Jim_GetWide(interp, obj_val, &wide_val); - *val = wide_val; - return result; -} - -static int target_array2mem(Jim_Interp *interp, struct target *target, - int argc, Jim_Obj *const *argv) -{ - int e; - - LOG_WARNING("DEPRECATED! use 'write_memory' not 'array2mem'"); - - /* argv[0] = name of array from which to read the data - * argv[1] = desired element width in bits - * argv[2] = memory address - * argv[3] = number of elements to write - * argv[4] = optional "phys" - */ - if (argc < 4 || argc > 5) { - Jim_WrongNumArgs(interp, 0, argv, "varname width addr nelems [phys]"); - return JIM_ERR; - } - - /* Arg 0: Name of the array variable */ - const char *varname = Jim_GetString(argv[0], NULL); - - /* Arg 1: Bit width of one element */ - long l; - e = Jim_GetLong(interp, argv[1], &l); - if (e != JIM_OK) - return e; - const unsigned int width_bits = l; - - if (width_bits != 8 && - width_bits != 16 && - width_bits != 32 && - width_bits != 64) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), - "Invalid width param. Must be one of: 8, 16, 32 or 64.", NULL); - return JIM_ERR; - } - const unsigned int width = width_bits / 8; - - /* Arg 2: Memory address */ - jim_wide wide_addr; - e = Jim_GetWide(interp, argv[2], &wide_addr); - if (e != JIM_OK) - return e; - target_addr_t addr = (target_addr_t)wide_addr; - - /* Arg 3: Number of elements to write */ - e = Jim_GetLong(interp, argv[3], &l); - if (e != JIM_OK) - return e; - size_t len = l; - - /* Arg 4: Phys */ - bool is_phys = false; - if (argc > 4) { - int str_len = 0; - const char *phys = Jim_GetString(argv[4], &str_len); - if (!strncmp(phys, "phys", str_len)) - is_phys = true; - else - return JIM_ERR; - } - - /* Argument checks */ - if (len == 0) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), - "array2mem: zero width read?", NULL); - return JIM_ERR; - } - - if ((addr + (len * width)) < addr) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), - "array2mem: addr + len - wraps to zero?", NULL); - return JIM_ERR; - } - - if (len > 65536) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), - "array2mem: too large memory write request, exceeds 64K items", NULL); - return JIM_ERR; - } - - if ((width == 1) || - ((width == 2) && ((addr & 1) == 0)) || - ((width == 4) && ((addr & 3) == 0)) || - ((width == 8) && ((addr & 7) == 0))) { - /* alignment correct */ - } else { - char buf[100]; - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - sprintf(buf, "array2mem address: " TARGET_ADDR_FMT " is not aligned for %" PRIu32 " byte reads", - addr, - width); - Jim_AppendStrings(interp, Jim_GetResult(interp), buf, NULL); - return JIM_ERR; - } - - /* Transfer loop */ - - /* assume ok */ - e = JIM_OK; - - const size_t buffersize = 4096; - uint8_t *buffer = malloc(buffersize); - if (!buffer) - return JIM_ERR; - - /* index counter */ - size_t idx = 0; - - while (len) { - /* Slurp... in buffer size chunks */ - const unsigned int max_chunk_len = buffersize / width; - - const size_t chunk_len = MIN(len, max_chunk_len); /* in elements.. */ - - /* Fill the buffer */ - for (size_t i = 0; i < chunk_len; i++, idx++) { - uint64_t v = 0; - if (get_u64_array_element(interp, varname, idx, &v) != JIM_OK) { - free(buffer); - return JIM_ERR; - } - switch (width) { - case 8: - target_buffer_set_u64(target, &buffer[i * width], v); - break; - case 4: - target_buffer_set_u32(target, &buffer[i * width], v); - break; - case 2: - target_buffer_set_u16(target, &buffer[i * width], v); - break; - case 1: - buffer[i] = v & 0x0ff; - break; - } - } - len -= chunk_len; - - /* Write the buffer to memory */ - int retval; - if (is_phys) - retval = target_write_phys_memory(target, addr, width, chunk_len, buffer); - else - retval = target_write_memory(target, addr, width, chunk_len, buffer); - if (retval != ERROR_OK) { - /* BOO !*/ - LOG_ERROR("array2mem: Write @ " TARGET_ADDR_FMT ", w=%u, cnt=%zu, failed", - addr, - width, - chunk_len); - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "array2mem: cannot read memory", NULL); - e = JIM_ERR; - break; - } - addr += chunk_len * width; - } - - free(buffer); - - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - - return e; -} - static int target_jim_write_memory(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { @@ -5637,24 +5252,6 @@ static int jim_target_configure(Jim_Interp *interp, int argc, Jim_Obj * const *a return target_configure(&goi, target); } -static int jim_target_mem2array(Jim_Interp *interp, - int argc, Jim_Obj *const *argv) -{ - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx); - struct target *target = get_current_target(cmd_ctx); - return target_mem2array(interp, target, argc - 1, argv + 1); -} - -static int jim_target_array2mem(Jim_Interp *interp, - int argc, Jim_Obj *const *argv) -{ - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx); - struct target *target = get_current_target(cmd_ctx); - return target_array2mem(interp, target, argc - 1, argv + 1); -} - COMMAND_HANDLER(handle_target_examine) { bool allow_defer = false; @@ -5977,22 +5574,6 @@ static const struct command_registration target_instance_command_handlers[] = { .usage = "address [count]", }, { - .name = "array2mem", - .mode = COMMAND_EXEC, - .jim_handler = jim_target_array2mem, - .help = "Writes Tcl array of 8/16/32 bit numbers " - "to target memory", - .usage = "arrayname bitwidth address count", - }, - { - .name = "mem2array", - .mode = COMMAND_EXEC, - .jim_handler = jim_target_mem2array, - .help = "Loads Tcl array of 8/16/32 bit numbers " - "from target memory", - .usage = "arrayname bitwidth address count", - }, - { .name = "get_reg", .mode = COMMAND_EXEC, .jim_handler = target_jim_get_reg, -- cgit v1.1 From 5e1468da186e65029316a359493e2d2353e21512 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 6 Aug 2023 10:40:03 +0200 Subject: helper/command: drop unused variables In both functions script_debug() and script_command_args_alloc() the variable len is never used, and Jim_GetString() does not mandate it. Drop the variable and pass NULL to Jim_GetString(). Change-Id: I754b27a59c6087cde729496be42609d2a7145b0c Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8053 Tested-by: jenkins --- src/helper/command.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index ef50ab5..9602333 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -145,8 +145,7 @@ static void script_debug(Jim_Interp *interp, unsigned int argc, Jim_Obj * const char *dbg = alloc_printf("command -"); for (unsigned i = 0; i < argc; i++) { - int len; - const char *w = Jim_GetString(argv[i], &len); + const char *w = Jim_GetString(argv[i], NULL); char *t = alloc_printf("%s %s", dbg, w); free(dbg); dbg = t; @@ -171,8 +170,7 @@ static char **script_command_args_alloc( unsigned i; for (i = 0; i < argc; i++) { - int len; - const char *w = Jim_GetString(argv[i], &len); + const char *w = Jim_GetString(argv[i], NULL); words[i] = strdup(w); if (!words[i]) { script_command_args_free(words, i); -- cgit v1.1 From 712c1244e8486bb4519ad0144a03c3c48c030214 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 6 Aug 2023 10:32:46 +0200 Subject: helper/command: simplify script_command_args_alloc() The output parameter nwords is always equal to the input parameter argc, when the function succeeds. Drop the parameter nwords and let the caller use directly the value in argc. While there, convert some 'unsigned' to 'unsigned int'. Change-Id: Ie3d8ce1351792f3c07fe39cdcbcd180fd24dc928 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8054 Tested-by: jenkins --- src/helper/command.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 9602333..f7ec0e2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -161,15 +161,13 @@ static void script_command_args_free(char **words, unsigned nwords) free(words); } -static char **script_command_args_alloc( - unsigned argc, Jim_Obj * const *argv, unsigned *nwords) +static char **script_command_args_alloc(unsigned int argc, Jim_Obj * const *argv) { char **words = malloc(argc * sizeof(char *)); if (!words) return NULL; - unsigned i; - for (i = 0; i < argc; i++) { + for (unsigned int i = 0; i < argc; i++) { const char *w = Jim_GetString(argv[i], NULL); words[i] = strdup(w); if (!words[i]) { @@ -177,7 +175,6 @@ static char **script_command_args_alloc( return NULL; } } - *nwords = i; return words; } @@ -901,8 +898,8 @@ static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx, return c->jim_handler(interp, argc, argv); /* use c->handler */ - unsigned int nwords; - char **words = script_command_args_alloc(argc, argv, &nwords); + unsigned int nwords = argc; + char **words = script_command_args_alloc(argc, argv); if (!words) return JIM_ERR; -- cgit v1.1 From f9ea9ce24cf4423111a7fa033f8ceff61d17aa5b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 6 Aug 2023 11:34:28 +0200 Subject: helper/command: simplify exec_command() The jimtcl interpreter guarantees that the Jim objects in argv[] are not deallocated during the command execution. Thus, there is no need to copy the string content of argv[]. Simplify exec_command() by inlining its two sub-functions and dropping the strdup(). While there, add a LOG_ERROR() for out of memory. Change-Id: I3e21ed7da50ca0bd072edbd49fca9740c81f95b0 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8055 Tested-by: jenkins --- src/helper/command.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index f7ec0e2..8860cf8 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -154,30 +154,6 @@ static void script_debug(Jim_Interp *interp, unsigned int argc, Jim_Obj * const free(dbg); } -static void script_command_args_free(char **words, unsigned nwords) -{ - for (unsigned i = 0; i < nwords; i++) - free(words[i]); - free(words); -} - -static char **script_command_args_alloc(unsigned int argc, Jim_Obj * const *argv) -{ - char **words = malloc(argc * sizeof(char *)); - if (!words) - return NULL; - - for (unsigned int i = 0; i < argc; i++) { - const char *w = Jim_GetString(argv[i], NULL); - words[i] = strdup(w); - if (!words[i]) { - script_command_args_free(words, i); - return NULL; - } - } - return words; -} - struct command_context *current_command_context(Jim_Interp *interp) { /* grab the command context from the associated data */ @@ -898,13 +874,17 @@ static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx, return c->jim_handler(interp, argc, argv); /* use c->handler */ - unsigned int nwords = argc; - char **words = script_command_args_alloc(argc, argv); - if (!words) + const char **words = malloc(argc * sizeof(char *)); + if (!words) { + LOG_ERROR("Out of memory"); return JIM_ERR; + } - int retval = run_command(cmd_ctx, c, (const char **)words, nwords); - script_command_args_free(words, nwords); + for (int i = 0; i < argc; i++) + words[i] = Jim_GetString(argv[i], NULL); + + int retval = run_command(cmd_ctx, c, words, argc); + free(words); return command_retval_set(interp, retval); } -- cgit v1.1 From f857db98bd2a3d97ada208a8137c48c47e9d3a78 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 6 Aug 2023 12:26:25 +0200 Subject: helper/command: inline run_command() in exec_command() Simplify the command execution by inlining run_command() inside exec_command(). Change-Id: Id932b006846720cfd867d22d142cd35831dbd1a2 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8056 Tested-by: jenkins --- src/helper/command.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 8860cf8..57db2ad 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -489,14 +489,27 @@ static bool command_can_run(struct command_context *cmd_ctx, struct command *c, return false; } -static int run_command(struct command_context *context, - struct command *c, const char **words, unsigned num_words) +static int exec_command(Jim_Interp *interp, struct command_context *context, + struct command *c, int argc, Jim_Obj * const *argv) { + if (c->jim_handler) + return c->jim_handler(interp, argc, argv); + + /* use c->handler */ + const char **words = malloc(argc * sizeof(char *)); + if (!words) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } + + for (int i = 0; i < argc; i++) + words[i] = Jim_GetString(argv[i], NULL); + struct command_invocation cmd = { .ctx = context, .current = c, .name = c->name, - .argc = num_words - 1, + .argc = argc - 1, .argv = words + 1, }; @@ -526,7 +539,8 @@ static int run_command(struct command_context *context, } Jim_DecrRefCount(context->interp, cmd.output); - return retval; + free(words); + return command_retval_set(interp, retval); } int command_run_line(struct command_context *context, char *line) @@ -867,27 +881,6 @@ static char *alloc_concatenate_strings(int argc, Jim_Obj * const *argv) return all; } -static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx, - struct command *c, int argc, Jim_Obj * const *argv) -{ - if (c->jim_handler) - return c->jim_handler(interp, argc, argv); - - /* use c->handler */ - const char **words = malloc(argc * sizeof(char *)); - if (!words) { - LOG_ERROR("Out of memory"); - return JIM_ERR; - } - - for (int i = 0; i < argc; i++) - words[i] = Jim_GetString(argv[i], NULL); - - int retval = run_command(cmd_ctx, c, words, argc); - free(words); - return command_retval_set(interp, retval); -} - static int jim_command_dispatch(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { /* check subcommands */ -- cgit v1.1 From e680841fd276439844ecf340f4005860d6e22582 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 6 Aug 2023 12:38:54 +0200 Subject: helper/command: pass command arguments also as Jim_Obj Some OpenOCD command gets fragment of TCL scripts as command-line argument, fragments that will be kept and executed later on. E.g. the command 'configure' gets the body of an OpenOCD event: $TARGET configure -event halted {TCL code} These commands store the argument as a Jim_Obj and pass it to the jimtcl interpreter when the TCL fragment has to be executed. Using Jim_Obj as storage is relevant to let the jimtcl interpreter to recover extra info of the TCL fragment, like the file-name and the line-number that contain the fragment, that will be printed out in case of run-time errors. While converting the commands to COMMAND_HANDLER, we should avoid storing the argument as C strings otherwise we will loose precious info in case of run-time errors making challenging the debugging of such TCL fragments. Extend the struct command_invocation to contain the array that points to the Jim_Obj of the command arguments. This will be used while converting commands to COMMAND_HANDLER. Change-Id: If37c5f20e9a71349f77ba1571baf1e6778e28aa5 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8057 Tested-by: jenkins --- doc/manual/helper.txt | 2 ++ src/helper/command.c | 1 + src/helper/command.h | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/doc/manual/helper.txt b/doc/manual/helper.txt index d5710dd..b59fd66 100644 --- a/doc/manual/helper.txt +++ b/doc/manual/helper.txt @@ -79,6 +79,8 @@ command handlers and helpers: - @c CMD_NAME - invoked command name - @c CMD_ARGC - the number of command arguments - @c CMD_ARGV - array of command argument strings +- @c CMD_JIMTCL_ARGV - array containing the Jim_Obj equivalent of command + argument in @c CMD_ARGV. @section helpercmdregister Command Registration diff --git a/src/helper/command.c b/src/helper/command.c index 57db2ad..a775c73 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -511,6 +511,7 @@ static int exec_command(Jim_Interp *interp, struct command_context *context, .name = c->name, .argc = argc - 1, .argv = words + 1, + .jimtcl_argv = argv + 1, }; cmd.output = Jim_NewEmptyStringObj(context->interp); diff --git a/src/helper/command.h b/src/helper/command.h index 42cb9cb..dc45070 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -79,6 +79,7 @@ struct command_invocation { const char *name; unsigned argc; const char **argv; + Jim_Obj * const *jimtcl_argv; Jim_Obj *output; }; @@ -154,6 +155,11 @@ void *jimcmd_privdata(Jim_Cmd *cmd); */ #define CMD_ARGV (cmd->argv) /** + * Use this macro to access the jimtcl arguments for the command being + * handled, rather than accessing the variable directly. It may be moved. + */ +#define CMD_JIMTCL_ARGV (cmd->jimtcl_argv) +/** * Use this macro to access the name of the command being handled, * rather than accessing the variable directly. It may be moved. */ -- cgit v1.1 From 53811fc584dc8837546be9ac17b77fdf8ad1e8bd Mon Sep 17 00:00:00 2001 From: ianst Date: Wed, 1 Nov 2023 16:41:43 -0700 Subject: target/xtensa: enable xtensa algo support - Add extra error checking - Cache PS; lower PS.INTLEVEL to allow breakpoint trigger (LX) - Xtensa algo support functional on LX per functional flash driver - Test on NX via manual algo validation Change-Id: Ie7cff4933979a0551308b382fa33c33c66376f25 Signed-off-by: ianst Reviewed-on: https://review.openocd.org/c/openocd/+/8075 Reviewed-by: Antonio Borneo Reviewed-by: Erhan Kurubas Tested-by: jenkins --- src/target/xtensa/xtensa.c | 20 +++++++++++++++++--- src/target/xtensa/xtensa.h | 3 ++- src/target/xtensa/xtensa_chip.c | 4 ++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/target/xtensa/xtensa.c b/src/target/xtensa/xtensa.c index ab3bfbb..1ec091c 100644 --- a/src/target/xtensa/xtensa.c +++ b/src/target/xtensa/xtensa.c @@ -2646,6 +2646,7 @@ int xtensa_start_algorithm(struct target *target, struct xtensa_algorithm *algorithm_info = arch_info; int retval = ERROR_OK; bool usr_ps = false; + uint32_t newps; /* NOTE: xtensa_run_algorithm requires that each algorithm uses a software breakpoint * at the exit point */ @@ -2660,7 +2661,17 @@ int xtensa_start_algorithm(struct target *target, buf_cpy(reg->value, xtensa->algo_context_backup[i], reg->size); } /* save debug reason, it will be changed */ + if (!algorithm_info) { + LOG_ERROR("BUG: arch_info not specified"); + return ERROR_FAIL; + } algorithm_info->ctx_debug_reason = target->debug_reason; + if (xtensa->core_config->core_type == XT_LX) { + /* save PS and set to debug_level - 1 */ + algorithm_info->ctx_ps = xtensa_reg_get(target, xtensa->eps_dbglevel_idx); + newps = (algorithm_info->ctx_ps & ~0xf) | (xtensa->core_config->debug.irq_level - 1); + xtensa_reg_set(target, xtensa->eps_dbglevel_idx, newps); + } /* write mem params */ for (int i = 0; i < num_mem_params; i++) { if (mem_params[i].direction != PARAM_IN) { @@ -2688,7 +2699,7 @@ int xtensa_start_algorithm(struct target *target, } if (memcmp(reg_params[i].reg_name, "ps", 3)) { usr_ps = true; - } else { + } else if (xtensa->core_config->core_type == XT_LX) { unsigned int reg_id = xtensa->eps_dbglevel_idx; assert(reg_id < xtensa->core_cache->num_regs && "Attempt to access non-existing reg!"); reg = &xtensa->core_cache->reg_list[reg_id]; @@ -2697,7 +2708,7 @@ int xtensa_start_algorithm(struct target *target, reg->valid = 1; } /* ignore custom core mode if custom PS value is specified */ - if (!usr_ps) { + if (!usr_ps && xtensa->core_config->core_type == XT_LX) { unsigned int eps_reg_idx = xtensa->eps_dbglevel_idx; xtensa_reg_val_t ps = xtensa_reg_get(target, eps_reg_idx); enum xtensa_mode core_mode = XT_PS_RING_GET(ps); @@ -2741,7 +2752,8 @@ int xtensa_wait_algorithm(struct target *target, return retval; LOG_TARGET_ERROR(target, "not halted %d, pc 0x%" PRIx32 ", ps 0x%" PRIx32, retval, xtensa_reg_get(target, XT_REG_IDX_PC), - xtensa_reg_get(target, xtensa->eps_dbglevel_idx)); + xtensa_reg_get(target, (xtensa->core_config->core_type == XT_LX) ? + xtensa->eps_dbglevel_idx : XT_REG_IDX_PS)); return ERROR_TARGET_TIMEOUT; } pc = xtensa_reg_get(target, XT_REG_IDX_PC); @@ -2813,6 +2825,8 @@ int xtensa_wait_algorithm(struct target *target, } } target->debug_reason = algorithm_info->ctx_debug_reason; + if (xtensa->core_config->core_type == XT_LX) + xtensa_reg_set(target, xtensa->eps_dbglevel_idx, algorithm_info->ctx_ps); retval = xtensa_write_dirty_registers(target); if (retval != ERROR_OK) diff --git a/src/target/xtensa/xtensa.h b/src/target/xtensa/xtensa.h index 3b37122..f799208 100644 --- a/src/target/xtensa/xtensa.h +++ b/src/target/xtensa/xtensa.h @@ -228,8 +228,9 @@ struct xtensa_sw_breakpoint { struct xtensa_algorithm { /** User can set this to specify which core mode algorithm should be run in. */ enum xtensa_mode core_mode; - /** Used internally to backup and restore debug_reason. */ + /** Used internally to backup and restore core state. */ enum target_debug_reason ctx_debug_reason; + xtensa_reg_val_t ctx_ps; }; #define XTENSA_COMMON_MAGIC 0x54E4E555U diff --git a/src/target/xtensa/xtensa_chip.c b/src/target/xtensa/xtensa_chip.c index 668aa3a..ac758ed 100644 --- a/src/target/xtensa/xtensa_chip.c +++ b/src/target/xtensa/xtensa_chip.c @@ -184,6 +184,10 @@ struct target_type xtensa_chip_target = { .get_gdb_reg_list = xtensa_get_gdb_reg_list, + .run_algorithm = xtensa_run_algorithm, + .start_algorithm = xtensa_start_algorithm, + .wait_algorithm = xtensa_wait_algorithm, + .add_breakpoint = xtensa_breakpoint_add, .remove_breakpoint = xtensa_breakpoint_remove, -- cgit v1.1 From c47d77780cdaeac241e3be5d4433c7e4c8b475b9 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 6 Jan 2024 17:54:24 +0100 Subject: target/mips32: fix false positive from clang clang build triggers an error for an uninitialized value of the variable 'instr'. This is a false positive, as the macro #define MIPS32_CONFIG3_ISA_MASK (3 << MIPS32_CONFIG3_ISA_SHIFT) guarantees the switch/case already covers all the possible values with cases 0, 1, 2 and 3. Silent clang by adding a useless default case to the switch. While there, fix the indentation of the switch/case accordingly to OpenOCD coding style. Change-Id: I0ae316754ce7d091dd8366bf314b8e6ee780e313 Signed-off-by: Antonio Borneo Fixes: 7de4b1202d50 ("target/mips32: add cpu info detection") Reviewed-on: https://review.openocd.org/c/openocd/+/8065 Tested-by: jenkins Reviewed-by: Oleksij Rempel --- src/target/mips32.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/target/mips32.c b/src/target/mips32.c index 8a3ddbf..5b94e6c 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -1607,17 +1607,18 @@ COMMAND_HANDLER(mips32_handle_cpuinfo_command) char *instr; switch ((config3 & MIPS32_CONFIG3_ISA_MASK) >> MIPS32_CONFIG3_ISA_SHIFT) { - case 0: - instr = "MIPS32"; + case 0: + instr = "MIPS32"; break; - case 1: - instr = "microMIPS"; + case 1: + instr = "microMIPS"; break; - case 2: - instr = "MIPS32 (at reset) and microMIPS"; + case 2: + instr = "MIPS32 (at reset) and microMIPS"; break; - case 3: - instr = "microMIPS (at reset) and MIPS32"; + case 3: + default: + instr = "microMIPS (at reset) and MIPS32"; break; } -- cgit v1.1 From fce7aa754f40475228db345c9dd0bf3eb929fc7b Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Wed, 15 Nov 2023 11:26:28 +0100 Subject: contrib/firmware: update gpif FSM configuration file Change the GPIF state machine, configuring only one of the 4 waveforms to generate the clock signal (CCLK) used to program the FPGA, and send one byte every cycle using an 8-bit bus. Change-Id: I43cf5480b9d5c40cc2f6a62a52ecfe078b76458e Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/7976 Reviewed-by: Antonio Borneo Tested-by: jenkins --- contrib/firmware/angie/c/src/gpif.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/contrib/firmware/angie/c/src/gpif.c b/contrib/firmware/angie/c/src/gpif.c index 80a9571..f4028be 100644 --- a/contrib/firmware/angie/c/src/gpif.c +++ b/contrib/firmware/angie/c/src/gpif.c @@ -13,25 +13,25 @@ /****************************** GPIF PROGRAM CODE ********************************/ /* DO NOT EDIT ... */ const char wavedata[128] = { -/* Wave 0 */ +// Wave 0 /* LenBr */ 0x01, 0x3F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07, /* Opcode*/ 0x02, 0x07, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, /* Output*/ 0x04, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, /* LFun */ 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, -/* Wave 1 */ -/* LenBr */ 0x88, 0x01, 0x3F, 0x01, 0x01, 0x01, 0x01, 0x07, -/* Opcode*/ 0x01, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, -/* Output*/ 0x07, 0x05, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, -/* LFun */ 0x09, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x3F, -/* Wave 2 */ +// Wave 1 /* LenBr */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07, /* Opcode*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -/* Output*/ 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, +/* Output*/ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, /* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, -/* Wave 3 */ +// Wave 2 /* LenBr */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07, /* Opcode*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -/* Output*/ 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, +/* Output*/ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +/* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, +// Wave 3 +/* LenBr */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07, +/* Opcode*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/* Output*/ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, /* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, }; /* END DO NOT EDIT */ -- cgit v1.1 From 995a7af21d6f97f628382e26dc21dc38e4fa846e Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Tue, 21 Nov 2023 17:45:55 +0100 Subject: jtag/drivers: send bitstream size to firmware via libusb Send bitstream size to firmware to initialize the GPIF count registers, since we're going to send this size via GPIF, we need to give the exact number of bytes to be sent, then the GPIF counter will decrement with every clock cycle (every byte sent) until reaching zero and stops. Change-Id: Ib4e8e0f95a6a4a95ef4888ba8a04a0ea45567f5a Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/7988 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/angie.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c index b6bde5b..b7d1f8a 100644 --- a/src/jtag/drivers/angie.c +++ b/src/jtag/drivers/angie.c @@ -17,6 +17,7 @@ #include #include #include "helper/system.h" +#include #include #include #include @@ -61,7 +62,7 @@ #define ANGIE_FIRMWARE_FILE PKGDATADIR "/angie/angie_firmware.bin" /** Default location of ANGIE firmware image. */ -#define ANGIE_BITSTREAM_FILE PKGDATADIR "/angie/angie_bitstream.bit" +#define ANGIE_BITSTREAM_FILE PKGDATADIR "/angie/angie_bitstream.bit" /** Maximum size of a single firmware section. Entire EZ-USB ANGIE code space = 16kB */ #define SECTION_BUFFERSIZE 16384 @@ -404,15 +405,7 @@ static int angie_load_bitstream(struct angie *device, const char *filename) FILE *bitstream_file = NULL; char *bitstream_data = NULL; size_t bitstream_size = 0; - - /* CFGopen */ - ret = jtag_libusb_control_transfer(device->usb_device_handle, - 0x00, 0xB0, 0, 0, NULL, 0, LIBUSB_TIMEOUT_MS, &transferred); - if (ret != ERROR_OK) { - LOG_ERROR("Failed opencfg"); - /* Abort if libusb sent less data than requested */ - return ERROR_FAIL; - } + uint8_t gpifcnt[4]; /* Open the bitstream file */ bitstream_file = fopen(bitstream_file_path, "rb"); @@ -442,6 +435,17 @@ static int angie_load_bitstream(struct angie *device, const char *filename) return ERROR_FAIL; } + h_u32_to_be(gpifcnt, bitstream_size); + + /* CFGopen */ + ret = jtag_libusb_control_transfer(device->usb_device_handle, + 0x00, 0xB0, 0, 0, (char *)gpifcnt, 4, LIBUSB_TIMEOUT_MS, &transferred); + if (ret != ERROR_OK) { + LOG_ERROR("Failed opencfg"); + /* Abort if libusb sent less data than requested */ + return ERROR_FAIL; + } + /* Send the bitstream data to the microcontroller */ int actual_length = 0; ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x02, bitstream_data, bitstream_size, 1000, &actual_length); -- cgit v1.1 From c7073853ebcbb8a94af0ef405cb05f94b7fd02e5 Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Wed, 29 Nov 2023 15:21:27 +0100 Subject: contrib/firmware: Add direction control for 'SCL' i2c signal We want to keep the tri-state buffers located between the FPGA and the board, in 'Z' state until we launch an i2c connection. We launch an i2c start condition, make the SCL direction 'OUT' to start the i2c protocol and at the end of the i2c connection at the stop condition, we re-make the tri-state buffers at 'Z' state. Change-Id: Ic597a70d0427832547f6b539864c24ce20a18c64 Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/7989 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/firmware/angie/c/include/io.h | 2 +- contrib/firmware/angie/c/src/i2c.c | 7 +++++++ contrib/firmware/angie/c/src/usb.c | 6 ------ contrib/firmware/angie/hdl/src/angie_bitstream.ucf | 1 + contrib/firmware/angie/hdl/src/angie_bitstream.vhd | 19 +++++++++++++------ src/jtag/drivers/angie/angie_bitstream.bit | Bin 340704 -> 340704 bytes src/jtag/drivers/angie/angie_firmware.bin | Bin 10158 -> 10256 bytes 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/contrib/firmware/angie/c/include/io.h b/contrib/firmware/angie/c/include/io.h index af488f4..19289d1 100644 --- a/contrib/firmware/angie/c/include/io.h +++ b/contrib/firmware/angie/c/include/io.h @@ -66,7 +66,7 @@ #define PIN_SDA IOD0 #define PIN_SCL IOD1 #define PIN_SDA_DIR IOD2 -/* PD3 Not Connected */ +#define PIN_SCL_DIR IOD3 /* PD4 Not Connected */ /* PD5 Not Connected */ /* PD6 Not Connected */ diff --git a/contrib/firmware/angie/c/src/i2c.c b/contrib/firmware/angie/c/src/i2c.c index 5384010..10a463b 100644 --- a/contrib/firmware/angie/c/src/i2c.c +++ b/contrib/firmware/angie/c/src/i2c.c @@ -14,6 +14,9 @@ void start_cd(void) { + PIN_SCL_DIR = 0; + PIN_SDA_DIR = 0; + delay_us(10); PIN_SDA = 0; //SDA = 1; delay_us(1); PIN_SCL = 0; //SCL = 1; @@ -40,6 +43,10 @@ void stop_cd(void) delay_us(1); PIN_SDA = 1; delay_us(1); + PIN_SDA_DIR = 1; + delay_us(1); + PIN_SCL_DIR = 1; + delay_us(1); } void clock_cd(void) diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c index 1b7aa47..de19641 100644 --- a/contrib/firmware/angie/c/src/usb.c +++ b/contrib/firmware/angie/c/src/usb.c @@ -886,9 +886,6 @@ void io_init(void) PORTACFG = 0x01; /* 0: normal ou 1: alternate function (each bit) */ OEA = 0xEF; /* all OUT exept INIT_B IN */ IOA = 0xFF; - PIN_RDWR_B = 1; - PIN_CSI_B = 1; - PIN_PROGRAM_B = 1; /* PORT B */ OEB = 0xEF; /* all OUT exept TDO */ @@ -899,8 +896,6 @@ void io_init(void) PIN_TDI = 0; PIN_SRST = 1; - - /* PORT C */ PORTCCFG = 0x00; /* 0: normal ou 1: alternate function (each bit) */ OEC = 0xFF; @@ -909,5 +904,4 @@ void io_init(void) /* PORT D */ OED = 0xFF; IOD = 0xFF; - PIN_SDA_DIR = 0; } diff --git a/contrib/firmware/angie/hdl/src/angie_bitstream.ucf b/contrib/firmware/angie/hdl/src/angie_bitstream.ucf index 92a89c9..9eb0c85 100644 --- a/contrib/firmware/angie/hdl/src/angie_bitstream.ucf +++ b/contrib/firmware/angie/hdl/src/angie_bitstream.ucf @@ -20,6 +20,7 @@ net SRST LOC = 'P61' ; net SDA LOC = 'P50' ; net SCL LOC = 'P51' ; net SDA_DIR LOC = 'P56' ; +net SCL_DIR LOC = 'P57' ; net SI_TDO LOC = 'P16' ; net SO_TRST LOC = 'P32' ; diff --git a/contrib/firmware/angie/hdl/src/angie_bitstream.vhd b/contrib/firmware/angie/hdl/src/angie_bitstream.vhd index 21ddb84..6004bf2 100644 --- a/contrib/firmware/angie/hdl/src/angie_bitstream.vhd +++ b/contrib/firmware/angie/hdl/src/angie_bitstream.vhd @@ -26,8 +26,9 @@ entity S609 is port( SDA : inout std_logic; SDA_DIR : in std_logic; SCL : in std_logic; + SCL_DIR : in std_logic; - FTP : out std_logic_vector(7 downto 0):=(others => '1'); -- Test points + FTP : out std_logic_vector(7 downto 0); -- Test points SI_TDO : in std_logic; ST_0 : out std_logic; ST_1 : out std_logic; @@ -55,8 +56,6 @@ begin ST_0 <= '0'; ST_1 <= '1'; -ST_4 <= '0'; - --TDO: TDO <= not SI_TDO; @@ -75,13 +74,21 @@ SO_SDA_OUT <= SDA; process(SDA_DIR) begin - if(SDA_DIR = '1') then - ST_5 <= '1'; - else + if(SDA_DIR = '0') then ST_5 <= '0'; + else + ST_5 <= '1'; end if; end process; +process(SCL_DIR) +begin + if(SCL_DIR = '0') then + ST_4 <= '0'; + else + ST_4 <= '1'; + end if; +end process; --Points de test: FTP(0) <= SDA; diff --git a/src/jtag/drivers/angie/angie_bitstream.bit b/src/jtag/drivers/angie/angie_bitstream.bit index aebd370..7b3a88f 100644 Binary files a/src/jtag/drivers/angie/angie_bitstream.bit and b/src/jtag/drivers/angie/angie_bitstream.bit differ diff --git a/src/jtag/drivers/angie/angie_firmware.bin b/src/jtag/drivers/angie/angie_firmware.bin index da69631..23c4a82 100644 Binary files a/src/jtag/drivers/angie/angie_firmware.bin and b/src/jtag/drivers/angie/angie_firmware.bin differ -- cgit v1.1 From 74807daeb36a3be891913d2e03e58d0a23b6fcb9 Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Mon, 4 Dec 2023 10:58:05 +0100 Subject: jtag/drivers: correct the angie_reset function remove angie_clear_queue function from executing before the angie_execute_queued_commands function and making it at the end of the reset function. Change-Id: Id8a0664fbd5b8f9730545ce0f8f272ae0b0e7e78 Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/7990 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/angie.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c index b7d1f8a..79195a9 100644 --- a/src/jtag/drivers/angie.c +++ b/src/jtag/drivers/angie.c @@ -1725,14 +1725,16 @@ static int angie_reset(int trst, int srst) high |= SIGNAL_SRST; int ret = angie_append_set_signals_cmd(device, low, high); - if (ret == ERROR_OK) - angie_clear_queue(device); + if (ret != ERROR_OK) + return ret; ret = angie_execute_queued_commands(device, LIBUSB_TIMEOUT_MS); - if (ret == ERROR_OK) - angie_clear_queue(device); + if (ret != ERROR_OK) + return ret; - return ret; + angie_clear_queue(device); + + return ERROR_OK; } /** -- cgit v1.1 From 868700e72073ca04ab71e8d03f56e5df031d5a7b Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Wed, 6 Dec 2023 15:28:16 +0100 Subject: jtag/drivers: give ANGIE a new PID after renumeration Give ANGIE a new PID after renumeration to be able to distinguish the two cases (programmed and not programmed) Change-Id: I30a91d8ed2e8e261221488b98d40a027ca41da52 Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/7991 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/60-openocd.rules | 1 + contrib/firmware/angie/c/Makefile | 3 +++ contrib/firmware/angie/c/src/usb.c | 2 +- src/jtag/drivers/angie.c | 13 +++++++------ src/jtag/drivers/angie/angie_firmware.bin | Bin 10256 -> 10256 bytes 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index b0e229d..fe8b00c 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -225,6 +225,7 @@ ATTRS{idVendor}=="303a", ATTRS{idProduct}=="1001", MODE="660", GROUP="plugdev", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="1002", MODE="660", GROUP="plugdev", TAG+="uaccess" # ANGIE USB-JTAG Adapter +ATTRS{idVendor}=="584e", ATTRS{idProduct}=="414f", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="584e", ATTRS{idProduct}=="424e", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="584e", ATTRS{idProduct}=="4255", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="584e", ATTRS{idProduct}=="4355", MODE="660", GROUP="plugdev", TAG+="uaccess" diff --git a/contrib/firmware/angie/c/Makefile b/contrib/firmware/angie/c/Makefile index e919cd0..1bcc1f7 100644 --- a/contrib/firmware/angie/c/Makefile +++ b/contrib/firmware/angie/c/Makefile @@ -74,3 +74,6 @@ clean: bin: angie_firmware.ihx makebin -p angie_firmware.ihx angie_firmware.bin + +hex: angie_firmware.ihx + $(PACKIHX) angie_firmware.ihx > fx2.hex diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c index de19641..a1b72e2 100644 --- a/contrib/firmware/angie/c/src/usb.c +++ b/contrib/firmware/angie/c/src/usb.c @@ -42,7 +42,7 @@ __code struct usb_device_descriptor device_descriptor = { .bdeviceprotocol = 0x01, .bmaxpacketsize0 = 64, .idvendor = 0x584e, - .idproduct = 0x424e, + .idproduct = 0x414f, .bcddevice = 0x0000, .imanufacturer = 1, .iproduct = 2, diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c index 79195a9..d4219d3 100644 --- a/src/jtag/drivers/angie.c +++ b/src/jtag/drivers/angie.c @@ -31,10 +31,11 @@ /** USB Product ID of ANGIE device in unconfigured state (no firmware loaded * yet) or with its firmware. */ -#define ANGIE_PID 0x424e -#define ANGIE_PID_2 0x4255 -#define ANGIE_PID_3 0x4355 -#define ANGIE_PID_4 0x4a55 +#define ANGIE_PID 0x414F +#define ANGIE_PID_2 0x424e +#define ANGIE_PID_3 0x4255 +#define ANGIE_PID_4 0x4355 +#define ANGIE_PID_5 0x4a55 /** Address of EZ-USB ANGIE CPU Control & Status register. This register can be * written by issuing a Control EP0 vendor request. */ @@ -255,8 +256,8 @@ static struct angie *angie_handle; static int angie_usb_open(struct angie *device) { struct libusb_device_handle *usb_device_handle; - const uint16_t vids[] = {ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, 0}; - const uint16_t pids[] = {ANGIE_PID, ANGIE_PID_2, ANGIE_PID_3, ANGIE_PID_4, 0}; + const uint16_t vids[] = {ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, 0}; + const uint16_t pids[] = {ANGIE_PID, ANGIE_PID_2, ANGIE_PID_3, ANGIE_PID_4, ANGIE_PID_5, 0}; int ret = jtag_libusb_open(vids, pids, NULL, &usb_device_handle, NULL); diff --git a/src/jtag/drivers/angie/angie_firmware.bin b/src/jtag/drivers/angie/angie_firmware.bin index 23c4a82..c793abb 100644 Binary files a/src/jtag/drivers/angie/angie_firmware.bin and b/src/jtag/drivers/angie/angie_firmware.bin differ -- cgit v1.1 From b50a8dbe4116c4fa18ab066f961f04d2fb075224 Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Mon, 11 Dec 2023 14:39:57 +0100 Subject: jtag/drivers: Add GPIO extender configuration function to ANGIE driver Add GPIO extender initial configuration that is needed to configure some important GPIOs and ensure that the dev board is ready to work. Add i2c_write function that make a write transfer to any slave device. Give a new Product ID to ANGIE to make it different than the non programmed ANGIE. Change-Id: I0a8dacb7fe218145b7d3ed1cb75f106ed6256714 Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/8072 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/firmware/angie/c/include/usb.h | 1 - contrib/firmware/angie/c/src/usb.c | 11 --- doc/usb_adapters/angie/584e_414f_angie.txt | 98 ++++++++++++++++++++++++ doc/usb_adapters/angie/584e_424e_angie.txt | 107 -------------------------- src/jtag/drivers/angie.c | 118 ++++++++++++++++++++++++++++- src/jtag/drivers/angie/angie_firmware.bin | Bin 10256 -> 10248 bytes 6 files changed, 212 insertions(+), 123 deletions(-) create mode 100644 doc/usb_adapters/angie/584e_414f_angie.txt delete mode 100644 doc/usb_adapters/angie/584e_424e_angie.txt diff --git a/contrib/firmware/angie/c/include/usb.h b/contrib/firmware/angie/c/include/usb.h index 07cb12a..e10947d 100644 --- a/contrib/firmware/angie/c/include/usb.h +++ b/contrib/firmware/angie/c/include/usb.h @@ -32,7 +32,6 @@ #define DESCRIPTOR_TYPE_STRING 0x03 #define DESCRIPTOR_TYPE_INTERFACE 0x04 #define DESCRIPTOR_TYPE_ENDPOINT 0x05 -#define DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION 0x0B #define STR_DESCR(len, ...) { (len) * 2 + 2, DESCRIPTOR_TYPE_STRING, { __VA_ARGS__ } } diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c index a1b72e2..a137d3d 100644 --- a/contrib/firmware/angie/c/src/usb.c +++ b/contrib/firmware/angie/c/src/usb.c @@ -65,17 +65,6 @@ __code struct usb_config_descriptor config_descriptor = { .maxpower = 50 /* 100 mA */ }; -__code struct usb_interface_association_descriptor interface_association_descriptor = { - .blength = sizeof(struct usb_interface_association_descriptor), - .bdescriptortype = DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, - .bfirstinterface = 0x01, - .binterfacecount = 0x02, - .bfunctionclass = 0x02, - .bfunctionsubclass = 0x00, - .bfunctionprotocol = 0x00, - .ifunction = 0x00 -}; - __code struct usb_interface_descriptor interface_descriptor00 = { .blength = sizeof(struct usb_interface_descriptor), .bdescriptortype = DESCRIPTOR_TYPE_INTERFACE, diff --git a/doc/usb_adapters/angie/584e_414f_angie.txt b/doc/usb_adapters/angie/584e_414f_angie.txt new file mode 100644 index 0000000..6c25f43 --- /dev/null +++ b/doc/usb_adapters/angie/584e_414f_angie.txt @@ -0,0 +1,98 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later + +Bus 002 Device 105: ID 584e:414f NanoXplore, SAS. ANGIE Adapter +Device Descriptor: + bLength 18 + bDescriptorType 1 + bcdUSB 2.00 + bDeviceClass 239 Miscellaneous Device + bDeviceSubClass 2 + bDeviceProtocol 1 Interface Association + bMaxPacketSize0 64 + idVendor 0x584e + idProduct 0x414f + bcdDevice 0.00 + iManufacturer 1 NanoXplore, SAS. + iProduct 2 ANGIE Adapter + iSerial 3 000001 + bNumConfigurations 1 + Configuration Descriptor: + bLength 9 + bDescriptorType 2 + wTotalLength 0x0047 + bNumInterfaces 2 + bConfigurationValue 1 + iConfiguration 1 NanoXplore, SAS. + bmAttributes 0x80 + (Bus Powered) + MaxPower 100mA + Interface Descriptor: + bLength 9 + bDescriptorType 4 + bInterfaceNumber 0 + bAlternateSetting 0 + bNumEndpoints 3 + bInterfaceClass 255 Vendor Specific Class + bInterfaceSubClass 0 + bInterfaceProtocol 0 + iInterface 4 JTAG Adapter + Endpoint Descriptor: + bLength 7 + bDescriptorType 5 + bEndpointAddress 0x01 EP 1 OUT + bmAttributes 2 + Transfer Type Bulk + Synch Type None + Usage Type Data + wMaxPacketSize 0x0040 1x 64 bytes + bInterval 0 + Endpoint Descriptor: + bLength 7 + bDescriptorType 5 + bEndpointAddress 0x81 EP 1 IN + bmAttributes 2 + Transfer Type Bulk + Synch Type None + Usage Type Data + wMaxPacketSize 0x0040 1x 64 bytes + bInterval 0 + Endpoint Descriptor: + bLength 7 + bDescriptorType 5 + bEndpointAddress 0x02 EP 2 OUT + bmAttributes 2 + Transfer Type Bulk + Synch Type None + Usage Type Data + wMaxPacketSize 0x0200 1x 512 bytes + bInterval 0 + Interface Descriptor: + bLength 9 + bDescriptorType 4 + bInterfaceNumber 1 + bAlternateSetting 0 + bNumEndpoints 2 + bInterfaceClass 10 CDC Data + bInterfaceSubClass 0 + bInterfaceProtocol 0 + iInterface 0 + Endpoint Descriptor: + bLength 7 + bDescriptorType 5 + bEndpointAddress 0x06 EP 6 OUT + bmAttributes 2 + Transfer Type Bulk + Synch Type None + Usage Type Data + wMaxPacketSize 0x0200 1x 512 bytes + bInterval 0 + Endpoint Descriptor: + bLength 7 + bDescriptorType 5 + bEndpointAddress 0x88 EP 8 IN + bmAttributes 2 + Transfer Type Bulk + Synch Type None + Usage Type Data + wMaxPacketSize 0x0200 1x 512 bytes + bInterval 0 diff --git a/doc/usb_adapters/angie/584e_424e_angie.txt b/doc/usb_adapters/angie/584e_424e_angie.txt deleted file mode 100644 index d68657a..0000000 --- a/doc/usb_adapters/angie/584e_424e_angie.txt +++ /dev/null @@ -1,107 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later - -Bus 001 Device 029: ID 584e:424e NanoXplore, SAS. ANGIE Adapter -Device Descriptor: - bLength 18 - bDescriptorType 1 - bcdUSB 2.00 - bDeviceClass 239 Miscellaneous Device - bDeviceSubClass 2 - bDeviceProtocol 1 Interface Association - bMaxPacketSize0 64 - idVendor 0x584e - idProduct 0x424e - bcdDevice 0.00 - iManufacturer 1 NanoXplore, SAS. - iProduct 2 ANGIE Adapter - iSerial 3 000001 - bNumConfigurations 1 - Configuration Descriptor: - bLength 9 - bDescriptorType 2 - wTotalLength 0x0047 - bNumInterfaces 2 - bConfigurationValue 1 - iConfiguration 1 NanoXplore, SAS. - bmAttributes 0x80 - (Bus Powered) - MaxPower 100mA - Interface Association: - bLength 8 - bDescriptorType 11 - bFirstInterface 1 - bInterfaceCount 2 - bFunctionClass 2 Communications - bFunctionSubClass 0 - bFunctionProtocol 0 - iFunction 0 - Interface Descriptor: - bLength 9 - bDescriptorType 4 - bInterfaceNumber 0 - bAlternateSetting 0 - bNumEndpoints 3 - bInterfaceClass 255 Vendor Specific Class - bInterfaceSubClass 0 - bInterfaceProtocol 0 - iInterface 4 JTAG Adapter - Endpoint Descriptor: - bLength 7 - bDescriptorType 5 - bEndpointAddress 0x01 EP 1 OUT - bmAttributes 2 - Transfer Type Bulk - Synch Type None - Usage Type Data - wMaxPacketSize 0x0040 1x 64 bytes - bInterval 0 - Endpoint Descriptor: - bLength 7 - bDescriptorType 5 - bEndpointAddress 0x81 EP 1 IN - bmAttributes 2 - Transfer Type Bulk - Synch Type None - Usage Type Data - wMaxPacketSize 0x0040 1x 64 bytes - bInterval 0 - Endpoint Descriptor: - bLength 7 - bDescriptorType 5 - bEndpointAddress 0x02 EP 2 OUT - bmAttributes 2 - Transfer Type Bulk - Synch Type None - Usage Type Data - wMaxPacketSize 0x0200 1x 512 bytes - bInterval 0 - Interface Descriptor: - bLength 9 - bDescriptorType 4 - bInterfaceNumber 1 - bAlternateSetting 0 - bNumEndpoints 2 - bInterfaceClass 10 CDC Data - bInterfaceSubClass 0 - bInterfaceProtocol 0 - iInterface 0 - Endpoint Descriptor: - bLength 7 - bDescriptorType 5 - bEndpointAddress 0x06 EP 6 OUT - bmAttributes 2 - Transfer Type Bulk - Synch Type None - Usage Type Data - wMaxPacketSize 0x0200 1x 512 bytes - bInterval 0 - Endpoint Descriptor: - bLength 7 - bDescriptorType 5 - bEndpointAddress 0x88 EP 8 IN - bmAttributes 2 - Transfer Type Bulk - Synch Type None - Usage Type Data - wMaxPacketSize 0x0200 1x 512 bytes - bInterval 0 diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c index d4219d3..dfe65a2 100644 --- a/src/jtag/drivers/angie.c +++ b/src/jtag/drivers/angie.c @@ -167,7 +167,8 @@ static int angie_load_firmware_and_renumerate(struct angie *device, const char * uint32_t delay_us); static int angie_load_firmware(struct angie *device, const char *filename); static int angie_load_bitstream(struct angie *device, const char *filename); - +static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size); +static void angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value, uint8_t value); static int angie_write_firmware_section(struct angie *device, struct image *firmware_image, int section_index); @@ -338,7 +339,15 @@ static int angie_load_firmware_and_renumerate(struct angie *device, usleep(delay_us); - return angie_usb_open(device); + ret = angie_usb_open(device); + if (ret != ERROR_OK) + return ret; + + ret = libusb_claim_interface(angie_handle->usb_device_handle, 0); + if (ret != LIBUSB_SUCCESS) + return ERROR_FAIL; + + return ERROR_OK; } /** @@ -476,6 +485,72 @@ static int angie_load_bitstream(struct angie *device, const char *filename) } /** + * Send an i2c write operation to dev-board components. + * + * @param device pointer to struct angie identifying ANGIE driver instance. + * @param i2c_data table of i2c data that we want to write to slave device. + * @param i2c_data_size the size of i2c data table. + * @return on success: ERROR_OK + * @return on failure: ERROR_FAIL + */ +static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size) +{ + char i2c_data_buffer[i2c_data_size + 2]; + char buffer_received[1]; + int ret, transferred; + i2c_data_buffer[0] = 0; // write = 0 + i2c_data_buffer[1] = i2c_data_size - 1; // i2c_data count (without address) + + for (uint8_t i = 0; i < i2c_data_size; i++) + i2c_data_buffer[i + 2] = i2c_data[i]; + + // Send i2c packet to Dev-board and configure its clock source / + ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x06, i2c_data_buffer, + i2c_data_size + 2, 1000, &transferred); + if (ret != ERROR_OK) { + LOG_ERROR("Error in i2c clock gen configuration : ret ERROR"); + angie_quit(); + return ret; + } + if (transferred != i2c_data_size + 2) { + LOG_ERROR("Error in i2c clock gen configuration : bytes transferred"); + angie_quit(); + return ERROR_FAIL; + } + + usleep(500); + + // Receive packet from ANGIE / + ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x88, buffer_received, 1, 1000, &transferred); + if (ret != ERROR_OK) { + LOG_ERROR("Error in i2c clock gen configuration : ret ERROR"); + angie_quit(); + return ret; + } + return ERROR_OK; +} + +/** + * Configure dev-board gpio extender modules by configuring their + * register 3 and register 1 responsible for IO directions and values. + * + * @param device pointer to struct angie identifying ANGIE driver instance. + * @param i2c_adr i2c address of the gpio extender. + * @param cfg_value IOs configuration to be written in register Number 3. + * @param value the IOs value to be written in register Number 1. + * @return on success: ERROR_OK + * @return on failure: ERROR_FAIL + */ +static void angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value, uint8_t value) +{ + uint8_t ioconfig[3] = {i2c_adr, 3, cfg_value}; + angie_i2c_write(device, ioconfig, 3); + uint8_t iovalue[3] = {i2c_adr, 1, value}; + angie_i2c_write(device, iovalue, 3); + usleep(500); +} + +/** * Send one contiguous firmware section to the ANGIE's EZ-USB microcontroller * over the USB bus. * @@ -2175,7 +2250,7 @@ static int angie_init(void) if (download_firmware) { LOG_INFO("Loading ANGIE firmware. This is reversible by power-cycling ANGIE device."); - if (libusb_claim_interface(angie_handle->usb_device_handle, 0) != ERROR_OK) + if (libusb_claim_interface(angie_handle->usb_device_handle, 0) != LIBUSB_SUCCESS) LOG_ERROR("Could not claim interface"); ret = angie_load_firmware_and_renumerate(angie_handle, @@ -2191,14 +2266,49 @@ static int angie_init(void) angie_quit(); return ret; } + if (libusb_claim_interface(angie_handle->usb_device_handle, 1) != LIBUSB_SUCCESS) { + LOG_ERROR("Could not claim interface 1"); + angie_quit(); + return ERROR_FAIL; + } + angie_io_extender_config(angie_handle, 0x22, 0xFF, 0xFF); + if (ret != ERROR_OK) { + LOG_ERROR("Could not configure io extender 22"); + angie_quit(); + return ret; + } + angie_io_extender_config(angie_handle, 0x23, 0xFF, 0xFF); + if (ret != ERROR_OK) { + LOG_ERROR("Could not configure io extender 23"); + angie_quit(); + return ret; + } + angie_io_extender_config(angie_handle, 0x24, 0x1F, 0x9F); + if (ret != ERROR_OK) { + LOG_ERROR("Could not configure io extender 24"); + angie_quit(); + return ret; + } + angie_io_extender_config(angie_handle, 0x25, 0x07, 0x00); + if (ret != ERROR_OK) { + LOG_ERROR("Could not configure io extender 25"); + angie_quit(); + return ret; + } + if (libusb_release_interface(angie_handle->usb_device_handle, 1) != LIBUSB_SUCCESS) { + LOG_ERROR("Fail release interface 1"); + angie_quit(); + return ERROR_FAIL; + } } else { LOG_INFO("ANGIE device is already running ANGIE firmware"); } /* Get ANGIE USB IN/OUT endpoints and claim the interface */ ret = jtag_libusb_choose_interface(angie_handle->usb_device_handle, - &angie_handle->ep_in, &angie_handle->ep_out, -1, -1, -1, -1); + &angie_handle->ep_in, &angie_handle->ep_out, 0xFF, 0, 0, -1); if (ret != ERROR_OK) { + LOG_ERROR("Choose and claim interface failed"); angie_quit(); return ret; } diff --git a/src/jtag/drivers/angie/angie_firmware.bin b/src/jtag/drivers/angie/angie_firmware.bin index c793abb..bc85208 100644 Binary files a/src/jtag/drivers/angie/angie_firmware.bin and b/src/jtag/drivers/angie/angie_firmware.bin differ -- cgit v1.1 From b9f5262d42f00c563750bfacea97640cda9afbdc Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Fri, 22 Dec 2023 10:59:52 +0100 Subject: contrib/firmware: Change USB interruption handling for JTAG/I2C communications Before this change, when we send an I2C Bulk data at the same time while Jtag bitbanging functions execute, the microcontroller puts JTAG bitbanging on wait and executes all I2C bitbanging function, which causes problems like loss of Ack in DAP responses and other errors. With this commit, When I2C interruption occurs, it sets a variable to true and continues JTAG bitbanging, when it finish it executes the I2C bitbang. Change-Id: Ia80bac21f8a259f4a1176b5346bf74ed0aa6e38b Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/8074 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/firmware/angie/c/include/usb.h | 1 + contrib/firmware/angie/c/src/protocol.c | 50 +++++++++++++++++------------- contrib/firmware/angie/c/src/usb.c | 6 ++-- src/jtag/drivers/angie/angie_firmware.bin | Bin 10248 -> 10216 bytes 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/contrib/firmware/angie/c/include/usb.h b/contrib/firmware/angie/c/include/usb.h index e10947d..ad8be78 100644 --- a/contrib/firmware/angie/c/include/usb.h +++ b/contrib/firmware/angie/c/include/usb.h @@ -129,6 +129,7 @@ struct setup_data { * the USB module */ extern volatile bool ep1_out; extern volatile bool ep1_in; +extern volatile bool ep6_out; extern volatile __xdata __at 0xE6B8 struct setup_data setup_data; diff --git a/contrib/firmware/angie/c/src/protocol.c b/contrib/firmware/angie/c/src/protocol.c index d84534b..e32808d 100644 --- a/contrib/firmware/angie/c/src/protocol.c +++ b/contrib/firmware/angie/c/src/protocol.c @@ -157,30 +157,36 @@ void command_loop(void) cmd_id_index = 0; payload_index_in = 0; - /* Wait until host sends EP1 Bulk-OUT packet */ - while (!ep1_out) + /* Wait until host sends Bulk-OUT packet */ + while ((!ep1_out) && (!ep6_out)) ; - ep1_out = false; - - /* Execute the commands */ - last_command = false; - while (!last_command) - last_command = execute_command(); - - /* Send back EP6 Bulk-IN packet if required */ - if (payload_index_in > 0) { - EP1INBC = payload_index_in; + if (ep6_out) { + /* Execute I2C command */ + i2c_recieve(); + ep6_out = false; + } + if (ep1_out) { + ep1_out = false; + /* Execute the commands */ + last_command = false; + while (!last_command) + last_command = execute_command(); + + /* Send back EP1 Bulk-IN packet if required */ + if (payload_index_in > 0) { + EP1INBC = payload_index_in; + syncdelay(3); + + while (!ep1_in) + ; + ep1_in = false; + } + + /* Re-arm EP1-OUT after command execution */ + EP1OUTBC = 0; + syncdelay(3); + EP1OUTBC = 0; syncdelay(3); - - while (!ep1_in) - ; - ep1_in = false; } - - /* Re-arm EP1-OUT after command execution */ - EP1OUTBC = 0; - syncdelay(3); - EP1OUTBC = 0; - syncdelay(3); } } diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c index a137d3d..ed23dcf 100644 --- a/contrib/firmware/angie/c/src/usb.c +++ b/contrib/firmware/angie/c/src/usb.c @@ -25,6 +25,7 @@ */ volatile bool ep1_out; volatile bool ep1_in; +volatile bool ep6_out; volatile __xdata __at 0xE6B8 struct setup_data setup_data; @@ -195,27 +196,24 @@ void ep0out_isr(void)__interrupt EP0OUT_ISR void ep1in_isr(void)__interrupt EP1IN_ISR { ep1_in = true; - EXIF &= ~0x10; /* Clear USBINT: Main global interrupt */ EPIRQ = 0x04; /* Clear individual EP1IN IRQ */ } void ep1out_isr(void)__interrupt EP1OUT_ISR { ep1_out = true; - EXIF &= ~0x10; /* Clear USBINT: Main global interrupt */ EPIRQ = 0x08; /* Clear individual EP1OUT IRQ */ } void ep2_isr(void)__interrupt EP2_ISR { - ep1_out = false; /* Does nothing but required by the compiler */ } void ep4_isr(void)__interrupt EP4_ISR { } void ep6_isr(void)__interrupt EP6_ISR { - i2c_recieve(); + ep6_out = true; EXIF &= ~0x10; /* Clear USBINT: Main global interrupt */ EPIRQ = 0x40; /* Clear individual EP6OUT IRQ */ diff --git a/src/jtag/drivers/angie/angie_firmware.bin b/src/jtag/drivers/angie/angie_firmware.bin index bc85208..68486ef 100644 Binary files a/src/jtag/drivers/angie/angie_firmware.bin and b/src/jtag/drivers/angie/angie_firmware.bin differ -- cgit v1.1 From ea2e26f7d521f5755b4bfda7bf12d99650277421 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 6 Aug 2023 23:14:15 +0200 Subject: jtag: rewrite jim_jtag_configure() as COMMAND_HANDLER The function is used for commands: - jtag configure - jtag cget While there, add the missing .usage field. Change-Id: I97ddc4898259ddb7fd2d057a997f33a6f4b0e2a8 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8058 Tested-by: jenkins --- src/jtag/hla/hla_transport.c | 3 +- src/jtag/tcl.c | 197 +++++++++++++++++------------------------- src/jtag/tcl.h | 3 +- src/target/adi_v5_dapdirect.c | 3 +- 4 files changed, 82 insertions(+), 124 deletions(-) diff --git a/src/jtag/hla/hla_transport.c b/src/jtag/hla/hla_transport.c index c0443d8..b826eb0 100644 --- a/src/jtag/hla/hla_transport.c +++ b/src/jtag/hla/hla_transport.c @@ -127,7 +127,8 @@ static const struct command_registration hl_transport_jtag_subcommand_handlers[] { .name = "cget", .mode = COMMAND_EXEC, - .jim_handler = jim_jtag_configure, + .handler = handle_jtag_configure, + .usage = "", }, { .name = "names", diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 407aeb1..163edfa 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -41,7 +41,7 @@ * Holds support for accessing JTAG-specific mechanisms from TCl scripts. */ -static const struct jim_nvp nvp_jtag_tap_event[] = { +static const struct nvp nvp_jtag_tap_event[] = { { .value = JTAG_TRST_ASSERTED, .name = "post-reset" }, { .value = JTAG_TAP_EVENT_SETUP, .name = "setup" }, { .value = JTAG_TAP_EVENT_ENABLE, .name = "tap-enable" }, @@ -259,123 +259,104 @@ enum jtag_tap_cfg_param { JCFG_IDCODE, }; -static struct jim_nvp nvp_config_opts[] = { +static struct nvp nvp_config_opts[] = { { .name = "-event", .value = JCFG_EVENT }, { .name = "-idcode", .value = JCFG_IDCODE }, { .name = NULL, .value = -1 } }; -static int jtag_tap_configure_event(struct jim_getopt_info *goi, struct jtag_tap *tap) +static int jtag_tap_set_event(struct command_context *cmd_ctx, struct jtag_tap *tap, + const struct nvp *event, Jim_Obj *body) { - if (goi->argc == 0) { - Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ..."); - return JIM_ERR; - } - - struct jim_nvp *n; - int e = jim_getopt_nvp(goi, nvp_jtag_tap_event, &n); - if (e != JIM_OK) { - jim_getopt_nvp_unknown(goi, nvp_jtag_tap_event, 1); - return e; - } - - if (goi->isconfigure) { - if (goi->argc != 1) { - Jim_WrongNumArgs(goi->interp, - goi->argc, - goi->argv, - "-event "); - return JIM_ERR; - } - } else { - if (goi->argc != 0) { - Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event "); - return JIM_ERR; - } - } + struct jtag_tap_event_action *jteap = tap->event_action; - struct jtag_tap_event_action *jteap = tap->event_action; - /* replace existing event body */ - bool found = false; while (jteap) { - if (jteap->event == (enum jtag_event)n->value) { - found = true; + if (jteap->event == (enum jtag_event)event->value) break; - } jteap = jteap->next; } - Jim_SetEmptyResult(goi->interp); - - if (goi->isconfigure) { - if (!found) - jteap = calloc(1, sizeof(*jteap)); - else if (jteap->body) - Jim_DecrRefCount(goi->interp, jteap->body); + if (!jteap) { + jteap = calloc(1, sizeof(*jteap)); + if (!jteap) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } - jteap->interp = goi->interp; - jteap->event = n->value; + /* add to head of event list */ + jteap->next = tap->event_action; + tap->event_action = jteap; + } else { + Jim_DecrRefCount(cmd_ctx->interp, jteap->body); + } - Jim_Obj *o; - jim_getopt_obj(goi, &o); - jteap->body = Jim_DuplicateObj(goi->interp, o); - Jim_IncrRefCount(jteap->body); + jteap->interp = cmd_ctx->interp; + jteap->event = (enum jtag_event)event->value; + jteap->body = Jim_DuplicateObj(cmd_ctx->interp, body); + Jim_IncrRefCount(jteap->body); - if (!found) { - /* add to head of event list */ - jteap->next = tap->event_action; - tap->event_action = jteap; - } - } else if (found) { - jteap->interp = goi->interp; - Jim_SetResult(goi->interp, - Jim_DuplicateObj(goi->interp, jteap->body)); - } - return JIM_OK; + return ERROR_OK; } -static int jtag_tap_configure_cmd(struct jim_getopt_info *goi, struct jtag_tap *tap) +__COMMAND_HANDLER(handle_jtag_configure) { - /* parse config or cget options */ - while (goi->argc > 0) { - Jim_SetEmptyResult(goi->interp); - - struct jim_nvp *n; - int e = jim_getopt_nvp(goi, nvp_config_opts, &n); - if (e != JIM_OK) { - jim_getopt_nvp_unknown(goi, nvp_config_opts, 0); - return e; - } + bool is_configure = !strcmp(CMD_NAME, "configure"); + + if (CMD_ARGC < (is_configure ? 3 : 2)) + return ERROR_COMMAND_SYNTAX_ERROR; + /* FIXME: rework jtag_tap_by_jim_obj */ + struct jtag_tap *tap = jtag_tap_by_jim_obj(CMD_CTX->interp, CMD_JIMTCL_ARGV[0]); + if (!tap) + return ERROR_FAIL; + + for (unsigned int i = 1; i < CMD_ARGC; i++) { + const struct nvp *n = nvp_name2value(nvp_config_opts, CMD_ARGV[i]); switch (n->value) { - case JCFG_EVENT: - e = jtag_tap_configure_event(goi, tap); - if (e != JIM_OK) - return e; - break; - case JCFG_IDCODE: - if (goi->isconfigure) { - Jim_SetResultFormatted(goi->interp, - "not settable: %s", n->name); - return JIM_ERR; - } else { - if (goi->argc != 0) { - Jim_WrongNumArgs(goi->interp, - goi->argc, goi->argv, - "NO PARAMS"); - return JIM_ERR; + case JCFG_EVENT: + if (i + (is_configure ? 3 : 2) >= CMD_ARGC) { + command_print(CMD, "wrong # args: should be \"-event %s\"", + is_configure ? " " : ""); + return ERROR_COMMAND_ARGUMENT_INVALID; + } + + const struct nvp *event = nvp_name2value(nvp_jtag_tap_event, CMD_ARGV[i + 1]); + if (!event->name) { + nvp_unknown_command_print(CMD, nvp_jtag_tap_event, CMD_ARGV[i], CMD_ARGV[i + 1]); + return ERROR_COMMAND_ARGUMENT_INVALID; + } + + if (is_configure) { + int retval = jtag_tap_set_event(CMD_CTX, tap, event, CMD_JIMTCL_ARGV[i + 2]); + if (retval != ERROR_OK) + return retval; + } else { + struct jtag_tap_event_action *jteap = tap->event_action; + while (jteap) { + if (jteap->event == (enum jtag_event)event->value) { + command_print(CMD, "%s", Jim_GetString(jteap->body, NULL)); + break; } + jteap = jteap->next; } - Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, tap->idcode)); - break; - default: - Jim_SetResultFormatted(goi->interp, "unknown value: %s", n->name); - return JIM_ERR; + } + + i += is_configure ? 2 : 1; + break; + case JCFG_IDCODE: + if (is_configure) { + command_print(CMD, "not settable: %s", n->name); + return ERROR_COMMAND_ARGUMENT_INVALID; + } + command_print(CMD, "0x%08x", tap->idcode); + break; + default: + nvp_unknown_command_print(CMD, nvp_config_opts, NULL, CMD_ARGV[i]); + return ERROR_COMMAND_ARGUMENT_INVALID; } } - - return JIM_OK; + return ERROR_OK; } #define NTAP_OPT_IRLEN 0 @@ -558,7 +539,7 @@ static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e) if (jteap->event != e) continue; - struct jim_nvp *nvp = jim_nvp_value2name_simple(nvp_jtag_tap_event, e); + const struct nvp *nvp = nvp_value2name(nvp_jtag_tap_event, e); LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s", tap->dotted_name, e, nvp->name, Jim_GetString(jteap->body, NULL)); @@ -675,30 +656,6 @@ __COMMAND_HANDLER(handle_jtag_tap_enabler) return ERROR_OK; } -int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - struct command *c = jim_to_command(interp); - const char *cmd_name = c->name; - struct jim_getopt_info goi; - jim_getopt_setup(&goi, interp, argc-1, argv + 1); - goi.isconfigure = !strcmp(cmd_name, "configure"); - if (goi.argc < 2 + goi.isconfigure) { - Jim_WrongNumArgs(goi.interp, 0, NULL, - " ..."); - return JIM_ERR; - } - - struct jtag_tap *t; - - Jim_Obj *o; - jim_getopt_obj(&goi, &o); - t = jtag_tap_by_jim_obj(goi.interp, o); - if (!t) - return JIM_ERR; - - return jtag_tap_configure_cmd(&goi, t); -} - COMMAND_HANDLER(handle_jtag_names) { if (CMD_ARGC != 0) @@ -793,7 +750,7 @@ static const struct command_registration jtag_subcommand_handlers[] = { { .name = "configure", .mode = COMMAND_ANY, - .jim_handler = jim_jtag_configure, + .handler = handle_jtag_configure, .help = "Provide a Tcl handler for the specified " "TAP event.", .usage = "tap_name '-event' event_name handler", @@ -801,7 +758,7 @@ static const struct command_registration jtag_subcommand_handlers[] = { { .name = "cget", .mode = COMMAND_EXEC, - .jim_handler = jim_jtag_configure, + .handler = handle_jtag_configure, .help = "Return any Tcl handler for the specified " "TAP event.", .usage = "tap_name '-event' event_name", diff --git a/src/jtag/tcl.h b/src/jtag/tcl.h index 66867ab..4e49e85 100644 --- a/src/jtag/tcl.h +++ b/src/jtag/tcl.h @@ -20,8 +20,7 @@ #include -int jim_jtag_configure(Jim_Interp *interp, int argc, - Jim_Obj * const *argv); +__COMMAND_HANDLER(handle_jtag_configure); __COMMAND_HANDLER(handle_jtag_tap_enabler); #endif /* OPENOCD_JTAG_TCL_H */ diff --git a/src/target/adi_v5_dapdirect.c b/src/target/adi_v5_dapdirect.c index f3a90c0..d198dac 100644 --- a/src/target/adi_v5_dapdirect.c +++ b/src/target/adi_v5_dapdirect.c @@ -118,7 +118,8 @@ static const struct command_registration dapdirect_jtag_subcommand_handlers[] = { .name = "cget", .mode = COMMAND_EXEC, - .jim_handler = jim_jtag_configure, + .handler = handle_jtag_configure, + .usage = "", }, { .name = "names", -- cgit v1.1 From 43e1d60e77b7984e21a9250a530a34f64bab78c0 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 10 Dec 2023 15:03:46 +0100 Subject: jtag/drivers/cmsis_dap_usb_bulk: fix clang warning Clang static analyzer warnings "1st function call argument is an uninitialized value" on the first libusb_free_transfer() parameter (lines 423, 424) could turn into a real problem in a corner case: If allocation of a libusb transfer struct fails, the pointers of not yet allocated transfers remain uninitialized. Use calloc() to zero whole struct cmsis_dap_backend_data. Fixes: fd75e9e54270 (jtag/drivers/cmsis_dap_bulk: use asynchronous libusb transfer) Signed-off-by: Tomas Vanek Change-Id: I0e489757d82d10ed7416c5e8c215e1facc7f8093 Reviewed-on: https://review.openocd.org/c/openocd/+/8045 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/cmsis_dap_usb_bulk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag/drivers/cmsis_dap_usb_bulk.c b/src/jtag/drivers/cmsis_dap_usb_bulk.c index 92a972a..8d0cb54 100644 --- a/src/jtag/drivers/cmsis_dap_usb_bulk.c +++ b/src/jtag/drivers/cmsis_dap_usb_bulk.c @@ -362,7 +362,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p if (err) LOG_WARNING("could not claim interface: %s", libusb_strerror(err)); - dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data)); + dap->bdata = calloc(1, sizeof(struct cmsis_dap_backend_data)); if (!dap->bdata) { LOG_ERROR("unable to allocate memory"); libusb_release_interface(dev_handle, interface_num); -- cgit v1.1 From d8499687f8d2899508cb7cab3de750d944181b6a Mon Sep 17 00:00:00 2001 From: Ahmed BOUDJELIDA Date: Mon, 15 Jan 2024 15:45:49 +0100 Subject: jtag/drivers: Correct ANGIE driver and GPIO Extender configuration Correct GPIO Extender configuration, after reconsideration, we need to configure the IO extender 0x23 pins as all inputs. Add more LOG_ERRORs to the code to better track bugs. Re-organize angie_init function Change-Id: I1fcf4919ba9ea95576803dd35cce7dafa26853b4 Signed-off-by: Ahmed BOUDJELIDA Reviewed-on: https://review.openocd.org/c/openocd/+/8079 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/angie.c | 93 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c index dfe65a2..62079f0 100644 --- a/src/jtag/drivers/angie.c +++ b/src/jtag/drivers/angie.c @@ -168,7 +168,7 @@ static int angie_load_firmware_and_renumerate(struct angie *device, const char * static int angie_load_firmware(struct angie *device, const char *filename); static int angie_load_bitstream(struct angie *device, const char *filename); static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size); -static void angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value, uint8_t value); +static int angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value); static int angie_write_firmware_section(struct angie *device, struct image *firmware_image, int section_index); @@ -262,8 +262,10 @@ static int angie_usb_open(struct angie *device) int ret = jtag_libusb_open(vids, pids, NULL, &usb_device_handle, NULL); - if (ret != ERROR_OK) + if (ret != ERROR_OK) { + LOG_ERROR("Could not find and open ANGIE"); return ret; + } device->usb_device_handle = usb_device_handle; device->type = ANGIE; @@ -281,8 +283,10 @@ static int angie_usb_open(struct angie *device) static int angie_usb_close(struct angie *device) { if (device->usb_device_handle) { - if (libusb_release_interface(device->usb_device_handle, 0) != 0) + if (libusb_release_interface(device->usb_device_handle, 0) != 0) { + LOG_ERROR("Could not release interface 0"); return ERROR_FAIL; + } jtag_libusb_close(device->usb_device_handle); device->usb_device_handle = NULL; @@ -383,8 +387,10 @@ static int angie_load_firmware(struct angie *device, const char *filename) /* Download all sections in the image to ANGIE */ for (unsigned int i = 0; i < angie_firmware_image.num_sections; i++) { ret = angie_write_firmware_section(device, &angie_firmware_image, i); - if (ret != ERROR_OK) + if (ret != ERROR_OK) { + LOG_ERROR("Could not write firmware section"); return ret; + } } image_close(&angie_firmware_image); @@ -477,7 +483,7 @@ static int angie_load_bitstream(struct angie *device, const char *filename) ret = jtag_libusb_control_transfer(device->usb_device_handle, 0x00, 0xB1, 0, 0, NULL, 0, LIBUSB_TIMEOUT_MS, &transferred); if (ret != ERROR_OK) { - LOG_INFO("error cfgclose"); + LOG_ERROR("Failed cfgclose"); /* Abort if libusb sent less data than requested */ return ERROR_FAIL; } @@ -509,12 +515,10 @@ static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_ i2c_data_size + 2, 1000, &transferred); if (ret != ERROR_OK) { LOG_ERROR("Error in i2c clock gen configuration : ret ERROR"); - angie_quit(); return ret; } if (transferred != i2c_data_size + 2) { LOG_ERROR("Error in i2c clock gen configuration : bytes transferred"); - angie_quit(); return ERROR_FAIL; } @@ -524,7 +528,6 @@ static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_ ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x88, buffer_received, 1, 1000, &transferred); if (ret != ERROR_OK) { LOG_ERROR("Error in i2c clock gen configuration : ret ERROR"); - angie_quit(); return ret; } return ERROR_OK; @@ -541,13 +544,15 @@ static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_ * @return on success: ERROR_OK * @return on failure: ERROR_FAIL */ -static void angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value, uint8_t value) +static int angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value) { uint8_t ioconfig[3] = {i2c_adr, 3, cfg_value}; - angie_i2c_write(device, ioconfig, 3); - uint8_t iovalue[3] = {i2c_adr, 1, value}; - angie_i2c_write(device, iovalue, 3); + int ret = angie_i2c_write(device, ioconfig, 3); + if (ret != ERROR_OK) + return ret; + usleep(500); + return ret; } /** @@ -851,19 +856,27 @@ static int angie_execute_queued_commands(struct angie *device, int timeout_ms) /* Send packet to ANGIE */ ret = jtag_libusb_bulk_write(device->usb_device_handle, device->ep_out, (char *)buffer, count_out, timeout_ms, &transferred); - if (ret != ERROR_OK) + if (ret != ERROR_OK) { + LOG_ERROR("Libusb bulk write queued commands failed."); return ret; - if (transferred != count_out) + } + if (transferred != count_out) { + LOG_ERROR("Libusb bulk write queued commands failed: transferred byte count"); return ERROR_FAIL; + } /* Wait for response if commands contain IN payload data */ if (count_in > 0) { ret = jtag_libusb_bulk_write(device->usb_device_handle, device->ep_in, (char *)buffer, count_in, timeout_ms, &transferred); - if (ret != ERROR_OK) - return ret; - if (transferred != count_in) - return ERROR_FAIL; + if (ret != ERROR_OK) { + LOG_ERROR("Libusb bulk write input payload data failed"); + return ret; + } + if (transferred != count_in) { + LOG_ERROR("Libusb bulk write input payload data failed: transferred byte count"); + return ERROR_FAIL; + } /* Write back IN payload data */ index_in = 0; @@ -2230,7 +2243,6 @@ static int angie_init(void) ret = angie_usb_open(angie_handle); if (ret != ERROR_OK) { - LOG_ERROR("Could not open ANGIE device"); free(angie_handle); angie_handle = NULL; return ret; @@ -2249,10 +2261,10 @@ static int angie_init(void) if (download_firmware) { LOG_INFO("Loading ANGIE firmware. This is reversible by power-cycling ANGIE device."); - - if (libusb_claim_interface(angie_handle->usb_device_handle, 0) != LIBUSB_SUCCESS) - LOG_ERROR("Could not claim interface"); - + if (libusb_claim_interface(angie_handle->usb_device_handle, 0) != LIBUSB_SUCCESS) { + LOG_ERROR("Could not claim interface 0"); + return ERROR_FAIL; + } ret = angie_load_firmware_and_renumerate(angie_handle, ANGIE_FIRMWARE_FILE, ANGIE_RENUMERATION_DELAY_US); if (ret != ERROR_OK) { @@ -2266,45 +2278,29 @@ static int angie_init(void) angie_quit(); return ret; } + if (libusb_release_interface(angie_handle->usb_device_handle, 0) != LIBUSB_SUCCESS) { + LOG_ERROR("Fail release interface 0"); + return ERROR_FAIL; + } if (libusb_claim_interface(angie_handle->usb_device_handle, 1) != LIBUSB_SUCCESS) { LOG_ERROR("Could not claim interface 1"); - angie_quit(); return ERROR_FAIL; } - angie_io_extender_config(angie_handle, 0x22, 0xFF, 0xFF); - if (ret != ERROR_OK) { - LOG_ERROR("Could not configure io extender 22"); - angie_quit(); - return ret; - } - angie_io_extender_config(angie_handle, 0x23, 0xFF, 0xFF); + /* Configure io extender 23: all input */ + ret = angie_io_extender_config(angie_handle, 0x23, 0xFF); if (ret != ERROR_OK) { LOG_ERROR("Could not configure io extender 23"); - angie_quit(); - return ret; - } - angie_io_extender_config(angie_handle, 0x24, 0x1F, 0x9F); - if (ret != ERROR_OK) { - LOG_ERROR("Could not configure io extender 24"); - angie_quit(); - return ret; - } - angie_io_extender_config(angie_handle, 0x25, 0x07, 0x00); - if (ret != ERROR_OK) { - LOG_ERROR("Could not configure io extender 25"); - angie_quit(); return ret; } if (libusb_release_interface(angie_handle->usb_device_handle, 1) != LIBUSB_SUCCESS) { LOG_ERROR("Fail release interface 1"); - angie_quit(); return ERROR_FAIL; } } else { LOG_INFO("ANGIE device is already running ANGIE firmware"); } - /* Get ANGIE USB IN/OUT endpoints and claim the interface */ + /* Get ANGIE USB IN/OUT endpoints and claim the interface 0 */ ret = jtag_libusb_choose_interface(angie_handle->usb_device_handle, &angie_handle->ep_in, &angie_handle->ep_out, 0xFF, 0, 0, -1); if (ret != ERROR_OK) { @@ -2319,6 +2315,7 @@ static int angie_init(void) /* Issue one test command with short timeout */ ret = angie_append_test_cmd(angie_handle); if (ret != ERROR_OK) { + LOG_ERROR("Append test command failed."); angie_quit(); return ret; } @@ -2345,14 +2342,16 @@ static int angie_init(void) angie_clear_queue(angie_handle); + /* Execute get signals command */ ret = angie_append_get_signals_cmd(angie_handle); if (ret != ERROR_OK) { + LOG_ERROR("Append get signals command failed"); angie_quit(); return ret; } - ret = angie_execute_queued_commands(angie_handle, 200); if (ret != ERROR_OK) { + LOG_ERROR("Execute get signals command failed"); angie_quit(); return ret; } -- cgit v1.1 From 3fb729980c6e711146157c8c43a5e06ea6b99758 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 11 Nov 2023 20:10:41 +0100 Subject: LICENSES: Add the Apache-2.0 license for standalone files Add the full text of the Apache-2.0 license to the OpenOCD tree. It has the same content from: https://spdx.org/licenses/Apache-2.0.html#licenseText but reformatted as in the Linux kernel document and added the required tags for reference and tooling. While this commit is specific for standalone files, it already reports the information for dual licensing. Change-Id: I1fd427256c310ab733fb5d50f344ac52c64a56f5 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8005 Tested-by: jenkins Reviewed-by: Erhan Kurubas --- LICENSES/stand-alone/Apache-2.0 | 189 ++++++++++++++++++++++++++++++++++++++++ Makefile.am | 1 + 2 files changed, 190 insertions(+) create mode 100644 LICENSES/stand-alone/Apache-2.0 diff --git a/LICENSES/stand-alone/Apache-2.0 b/LICENSES/stand-alone/Apache-2.0 new file mode 100644 index 0000000..ae8128b --- /dev/null +++ b/LICENSES/stand-alone/Apache-2.0 @@ -0,0 +1,189 @@ +Valid-License-Identifier: Apache-2.0 +SPDX-URL: https://spdx.org/licenses/Apache-2.0.html +Usage-Guide: + Do NOT use on OpenOCD code. The Apache-2.0 is not GPL2 compatible. It may only + be used for dual-licensed files where the other license is GPL2 compatible. + If you end up using this it MUST be used together with a GPL2 compatible + license using "OR". + It may also be used for stand-alone code NOT linked within the OpenOCD binary + but distributed with OpenOCD. + To use the Apache License version 2.0 put the following SPDX tag/value + pair into a comment according to the placement guidelines in the + licensing rules documentation: + SPDX-License-Identifier: Apache-2.0 +License-Text: + +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the +copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other +entities that control, are controlled by, or are under common control with +that entity. For the purposes of this definition, "control" means (i) the +power, direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation +or translation of a Source form, including but not limited to compiled +object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice that +is included in or attached to the work (an example is provided in the +Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, as +a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, or +merely link (or bind by name) to the interfaces of, the Work and Derivative +Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor for +inclusion in the Work by the copyright owner or by an individual or Legal +Entity authorized to submit on behalf of the copyright owner. For the +purposes of this definition, "submitted" means any form of electronic, +verbal, or written communication sent to the Licensor or its +representatives, including but not limited to communication on electronic +mailing lists, source code control systems, and issue tracking systems that +are managed by, or on behalf of, the Licensor for the purpose of discussing +and improving the Work, but excluding communication that is conspicuously +marked or otherwise designated in writing by the copyright owner as "Not a +Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on +behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this + License, each Contributor hereby grants to You a perpetual, worldwide, + non-exclusive, no-charge, royalty-free, irrevocable copyright license to + reproduce, prepare Derivative Works of, publicly display, publicly + perform, sublicense, and distribute the Work and such Derivative Works + in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this + License, each Contributor hereby grants to You a perpetual, worldwide, + non-exclusive, no-charge, royalty-free, irrevocable (except as stated in + this section) patent license to make, have made, use, offer to sell, + sell, import, and otherwise transfer the Work, where such license + applies only to those patent claims licensable by such Contributor that + are necessarily infringed by their Contribution(s) alone or by + combination of their Contribution(s) with the Work to which such + Contribution(s) was submitted. If You institute patent litigation + against any entity (including a cross-claim or counterclaim in a + lawsuit) alleging that the Work or a Contribution incorporated within + the Work constitutes direct or contributory patent infringement, then + any patent licenses granted to You under this License for that Work + shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or + Derivative Works thereof in any medium, with or without modifications, + and in Source or Object form, provided that You meet the following + conditions: + + a. You must give any other recipients of the Work or Derivative Works a + copy of this License; and + + b. You must cause any modified files to carry prominent notices stating + that You changed the files; and + + c. You must retain, in the Source form of any Derivative Works that You + distribute, all copyright, patent, trademark, and attribution notices + from the Source form of the Work, excluding those notices that do not + pertain to any part of the Derivative Works; and + + d. If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained within + such NOTICE file, excluding those notices that do not pertain to any + part of the Derivative Works, in at least one of the following + places: within a NOTICE text file distributed as part of the + Derivative Works; within the Source form or documentation, if + provided along with the Derivative Works; or, within a display + generated by the Derivative Works, if and wherever such third-party + notices normally appear. The contents of the NOTICE file are for + informational purposes only and do not modify the License. You may + add Your own attribution notices within Derivative Works that You + distribute, alongside or as an addendum to the NOTICE text from the + Work, provided that such additional attribution notices cannot be + construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may + provide additional or different license terms and conditions for use, + reproduction, or distribution of Your modifications, or for any such + Derivative Works as a whole, provided Your use, reproduction, and + distribution of the Work otherwise complies with the conditions stated + in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any + Contribution intentionally submitted for inclusion in the Work by You to + the Licensor shall be under the terms and conditions of this License, + without any additional terms or conditions. Notwithstanding the above, + nothing herein shall supersede or modify the terms of any separate + license agreement you may have executed with Licensor regarding such + Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to + in writing, Licensor provides the Work (and each Contributor provides + its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied, including, without limitation, + any warranties or conditions of TITLE, NON-INFRINGEMENT, + MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely + responsible for determining the appropriateness of using or + redistributing the Work and assume any risks associated with Your + exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether + in tort (including negligence), contract, or otherwise, unless required + by applicable law (such as deliberate and grossly negligent acts) or + agreed to in writing, shall any Contributor be liable to You for + damages, including any direct, indirect, special, incidental, or + consequential damages of any character arising as a result of this + License or out of the use or inability to use the Work (including but + not limited to damages for loss of goodwill, work stoppage, computer + failure or malfunction, or any and all other commercial damages or + losses), even if such Contributor has been advised of the possibility of + such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the + Work or Derivative Works thereof, You may choose to offer, and charge a + fee for, acceptance of support, warranty, indemnity, or other liability + obligations and/or rights consistent with this License. However, in + accepting such obligations, You may act only on Your own behalf and on + Your sole responsibility, not on behalf of any other Contributor, and + only if You agree to indemnify, defend, and hold each Contributor + harmless for any liability incurred by, or claims asserted against, such + Contributor by reason of your accepting any such warranty or additional + liability. + +END OF TERMS AND CONDITIONS diff --git a/Makefile.am b/Makefile.am index 153c471..1313d15 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,6 +70,7 @@ EXTRA_DIST += \ LICENSES/preferred/GPL-2.0 \ LICENSES/preferred/LGPL-2.1 \ LICENSES/preferred/MIT \ + LICENSES/stand-alone/Apache-2.0 \ LICENSES/stand-alone/GPL-3.0 \ tools/logger.pl \ tools/rlink_make_speed_table \ -- cgit v1.1 From d7ee0e422eb5b18106b8c50b867fc20c6bcf047c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 9 Nov 2023 15:18:22 +0100 Subject: contrib/rtos-helpers/uCOS-III-openocd: change license to Apache-2.0 This file is intended to be included in any user's project that plans to use OpenOCD awareness for uCOS-III. It is supposed to be distributed under a license compatible with the uCOS-III code, that is Apache-2.0 license. Distribute it under Apache License 2.0. Change-Id: I51ecd469c8ccdd23a069d21e89b7d90886691395 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/7996 Tested-by: jenkins --- contrib/rtos-helpers/uCOS-III-openocd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/rtos-helpers/uCOS-III-openocd.c b/contrib/rtos-helpers/uCOS-III-openocd.c index 9869adf..ff2789e 100644 --- a/contrib/rtos-helpers/uCOS-III-openocd.c +++ b/contrib/rtos-helpers/uCOS-III-openocd.c @@ -1,4 +1,13 @@ -// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: Apache-2.0 + +/* + * The original version of this file did not reported any license nor + * copyright, but the author clearly stated that: + * "This file should be linked along with the [uC/OS-III user's] project + * to enable RTOS support for uC/OS-III." + * Such statement implies the willing to have this file's license compatible + * with the license Apache 2.0 of uC/OS-III. + */ /* * uC/OS-III does not provide a fixed layout for OS_TCB, which makes it -- cgit v1.1 From 987a274a85732e5b23c58456287982260a5959b2 Mon Sep 17 00:00:00 2001 From: Ian Thompson Date: Mon, 8 Jan 2024 10:43:05 -0800 Subject: target/xtensa: update COMMAND_HELPER output to use command_print() API - Change LOG_ERROR() and LOG_INFO() output, but keep DEBUG and WARNING levels for verbosity - Update command error code return values and remove unnecessary output. Signed-off-by: Ian Thompson Change-Id: I4ef0753b3a56be02716f2db43a7d4370a1917237 Reviewed-on: https://review.openocd.org/c/openocd/+/8076 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/xtensa/xtensa.c | 86 ++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 48 deletions(-) diff --git a/src/target/xtensa/xtensa.c b/src/target/xtensa/xtensa.c index 1ec091c..b516c17 100644 --- a/src/target/xtensa/xtensa.c +++ b/src/target/xtensa/xtensa.c @@ -3459,8 +3459,8 @@ static COMMAND_HELPER(xtensa_cmd_exe_do, struct target *target) const char *parm = CMD_ARGV[0]; unsigned int parm_len = strlen(parm); if ((parm_len >= 64) || (parm_len & 1)) { - LOG_ERROR("Invalid parameter length (%d): must be even, < 64 characters", parm_len); - return ERROR_FAIL; + command_print(CMD, "Invalid parameter length (%d): must be even, < 64 characters", parm_len); + return ERROR_COMMAND_ARGUMENT_INVALID; } uint8_t ops[32]; @@ -3480,7 +3480,7 @@ static COMMAND_HELPER(xtensa_cmd_exe_do, struct target *target) */ int status = xtensa_write_dirty_registers(target); if (status != ERROR_OK) { - LOG_ERROR("%s: Failed to write back register cache.", target_name(target)); + command_print(CMD, "%s: Failed to write back register cache.", target_name(target)); return ERROR_FAIL; } xtensa_reg_val_t exccause = xtensa_reg_get(target, XT_REG_IDX_EXCCAUSE); @@ -3498,18 +3498,18 @@ static COMMAND_HELPER(xtensa_cmd_exe_do, struct target *target) xtensa_queue_exec_ins_wide(xtensa, ops, oplen); /* Handles endian-swap */ status = xtensa_dm_queue_execute(&xtensa->dbg_mod); if (status != ERROR_OK) { - LOG_TARGET_ERROR(target, "exec: queue error %d", status); + command_print(CMD, "exec: queue error %d", status); } else { status = xtensa_core_status_check(target); if (status != ERROR_OK) - LOG_TARGET_ERROR(target, "exec: status error %d", status); + command_print(CMD, "exec: status error %d", status); } /* Reread register cache and restore saved regs after instruction execution */ if (xtensa_fetch_all_regs(target) != ERROR_OK) - LOG_TARGET_ERROR(target, "post-exec: register fetch error"); + command_print(CMD, "post-exec: register fetch error"); if (status != ERROR_OK) { - LOG_TARGET_ERROR(target, "post-exec: EXCCAUSE 0x%02" PRIx32, + command_print(CMD, "post-exec: EXCCAUSE 0x%02" PRIx32, xtensa_reg_get(target, XT_REG_IDX_EXCCAUSE)); } xtensa_reg_set(target, XT_REG_IDX_EXCCAUSE, exccause); @@ -3534,8 +3534,8 @@ COMMAND_HELPER(xtensa_cmd_xtdef_do, struct xtensa *xtensa) } else if (strcasecmp(core_name, "NX") == 0) { xtensa->core_config->core_type = XT_NX; } else { - LOG_ERROR("xtdef [LX|NX]\n"); - return ERROR_COMMAND_SYNTAX_ERROR; + command_print(CMD, "xtdef [LX|NX]\n"); + return ERROR_COMMAND_ARGUMENT_INVALID; } return ERROR_OK; } @@ -3592,7 +3592,7 @@ COMMAND_HELPER(xtensa_cmd_xtopt_do, struct xtensa *xtensa) if (!xtensa_cmd_xtopt_legal_val("excmlevel", opt_val, 1, 6)) return ERROR_COMMAND_ARGUMENT_INVALID; if (!xtensa->core_config->high_irq.enabled) { - LOG_ERROR("xtopt excmlevel requires hipriints\n"); + command_print(CMD, "xtopt excmlevel requires hipriints\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } xtensa->core_config->high_irq.excm_level = opt_val; @@ -3605,7 +3605,7 @@ COMMAND_HELPER(xtensa_cmd_xtopt_do, struct xtensa *xtensa) return ERROR_COMMAND_ARGUMENT_INVALID; } if (!xtensa->core_config->high_irq.enabled) { - LOG_ERROR("xtopt intlevels requires hipriints\n"); + command_print(CMD, "xtopt intlevels requires hipriints\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } xtensa->core_config->high_irq.level_num = opt_val; @@ -3662,10 +3662,8 @@ COMMAND_HELPER(xtensa_cmd_xtmem_do, struct xtensa *xtensa) int mem_access = 0; bool is_dcache = false; - if (CMD_ARGC == 0) { - LOG_ERROR("xtmem [parameters]\n"); + if (CMD_ARGC == 0) return ERROR_COMMAND_SYNTAX_ERROR; - } const char *mem_name = CMD_ARGV[0]; if (strcasecmp(mem_name, "icache") == 0) { @@ -3696,25 +3694,21 @@ COMMAND_HELPER(xtensa_cmd_xtmem_do, struct xtensa *xtensa) memp = &xtensa->core_config->srom; mem_access = XT_MEM_ACCESS_READ; } else { - LOG_ERROR("xtmem types: \n"); + command_print(CMD, "xtmem types: \n"); return ERROR_COMMAND_ARGUMENT_INVALID; } if (cachep) { - if ((CMD_ARGC != 4) && (CMD_ARGC != 5)) { - LOG_ERROR("xtmem [writeback]\n"); + if (CMD_ARGC != 4 && CMD_ARGC != 5) return ERROR_COMMAND_SYNTAX_ERROR; - } cachep->line_size = strtoul(CMD_ARGV[1], NULL, 0); cachep->size = strtoul(CMD_ARGV[2], NULL, 0); cachep->way_count = strtoul(CMD_ARGV[3], NULL, 0); cachep->writeback = ((CMD_ARGC == 5) && is_dcache) ? strtoul(CMD_ARGV[4], NULL, 0) : 0; } else if (memp) { - if (CMD_ARGC != 3) { - LOG_ERROR("xtmem \n"); + if (CMD_ARGC != 3) return ERROR_COMMAND_SYNTAX_ERROR; - } struct xtensa_local_mem_region_config *memcfgp = &memp->regions[memp->count]; memcfgp->base = strtoul(CMD_ARGV[1], NULL, 0); memcfgp->size = strtoul(CMD_ARGV[2], NULL, 0); @@ -3734,10 +3728,8 @@ COMMAND_HANDLER(xtensa_cmd_xtmem) /* xtmpu */ COMMAND_HELPER(xtensa_cmd_xtmpu_do, struct xtensa *xtensa) { - if (CMD_ARGC != 4) { - LOG_ERROR("xtmpu \n"); + if (CMD_ARGC != 4) return ERROR_COMMAND_SYNTAX_ERROR; - } unsigned int nfgseg = strtoul(CMD_ARGV[0], NULL, 0); unsigned int minsegsize = strtoul(CMD_ARGV[1], NULL, 0); @@ -3745,16 +3737,16 @@ COMMAND_HELPER(xtensa_cmd_xtmpu_do, struct xtensa *xtensa) unsigned int execonly = strtoul(CMD_ARGV[3], NULL, 0); if ((nfgseg > 32)) { - LOG_ERROR(" must be within [0..32]\n"); + command_print(CMD, " must be within [0..32]\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } else if (minsegsize & (minsegsize - 1)) { - LOG_ERROR(" must be a power of 2 >= 32\n"); + command_print(CMD, " must be a power of 2 >= 32\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } else if (lockable > 1) { - LOG_ERROR(" must be 0 or 1\n"); + command_print(CMD, " must be 0 or 1\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } else if (execonly > 1) { - LOG_ERROR(" must be 0 or 1\n"); + command_print(CMD, " must be 0 or 1\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -3775,18 +3767,16 @@ COMMAND_HANDLER(xtensa_cmd_xtmpu) /* xtmmu */ COMMAND_HELPER(xtensa_cmd_xtmmu_do, struct xtensa *xtensa) { - if (CMD_ARGC != 2) { - LOG_ERROR("xtmmu \n"); + if (CMD_ARGC != 2) return ERROR_COMMAND_SYNTAX_ERROR; - } unsigned int nirefillentries = strtoul(CMD_ARGV[0], NULL, 0); unsigned int ndrefillentries = strtoul(CMD_ARGV[1], NULL, 0); if ((nirefillentries != 16) && (nirefillentries != 32)) { - LOG_ERROR(" must be 16 or 32\n"); + command_print(CMD, " must be 16 or 32\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } else if ((ndrefillentries != 16) && (ndrefillentries != 32)) { - LOG_ERROR(" must be 16 or 32\n"); + command_print(CMD, " must be 16 or 32\n"); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -3809,13 +3799,13 @@ COMMAND_HELPER(xtensa_cmd_xtreg_do, struct xtensa *xtensa) if (CMD_ARGC == 1) { int32_t numregs = strtoul(CMD_ARGV[0], NULL, 0); if ((numregs <= 0) || (numregs > UINT16_MAX)) { - LOG_ERROR("xtreg : Invalid 'numregs' (%d)", numregs); - return ERROR_COMMAND_SYNTAX_ERROR; + command_print(CMD, "xtreg : Invalid 'numregs' (%d)", numregs); + return ERROR_COMMAND_ARGUMENT_INVALID; } if ((xtensa->genpkt_regs_num > 0) && (numregs < (int32_t)xtensa->genpkt_regs_num)) { - LOG_ERROR("xtregs (%d) must be larger than numgenregs (%d) (if xtregfmt specified)", + command_print(CMD, "xtregs (%d) must be larger than numgenregs (%d) (if xtregfmt specified)", numregs, xtensa->genpkt_regs_num); - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_ARGUMENT_INVALID; } xtensa->total_regs_num = numregs; xtensa->core_regs_num = 0; @@ -3844,17 +3834,17 @@ COMMAND_HELPER(xtensa_cmd_xtreg_do, struct xtensa *xtensa) const char *regname = CMD_ARGV[0]; unsigned int regnum = strtoul(CMD_ARGV[1], NULL, 0); if (regnum > UINT16_MAX) { - LOG_ERROR(" must be a 16-bit number"); + command_print(CMD, " must be a 16-bit number"); return ERROR_COMMAND_ARGUMENT_INVALID; } if ((xtensa->num_optregs + xtensa->core_regs_num) >= xtensa->total_regs_num) { if (xtensa->total_regs_num) - LOG_ERROR("'xtreg %s 0x%04x': Too many registers (%d expected, %d core %d extended)", + command_print(CMD, "'xtreg %s 0x%04x': Too many registers (%d expected, %d core %d extended)", regname, regnum, xtensa->total_regs_num, xtensa->core_regs_num, xtensa->num_optregs); else - LOG_ERROR("'xtreg %s 0x%04x': Number of registers unspecified", + command_print(CMD, "'xtreg %s 0x%04x': Number of registers unspecified", regname, regnum); return ERROR_FAIL; } @@ -3934,7 +3924,7 @@ COMMAND_HELPER(xtensa_cmd_xtreg_do, struct xtensa *xtensa) idx = XT_NX_REG_IDX_MESRCLR; if (idx < XT_NX_REG_IDX_NUM) { if (xtensa->nx_reg_idx[idx] != 0) { - LOG_ERROR("nx_reg_idx[%d] previously set to %d", + command_print(CMD, "nx_reg_idx[%d] previously set to %d", idx, xtensa->nx_reg_idx[idx]); return ERROR_FAIL; } @@ -3981,9 +3971,9 @@ COMMAND_HELPER(xtensa_cmd_xtregfmt_do, struct xtensa *xtensa) if ((numgregs <= 0) || ((numgregs > xtensa->total_regs_num) && (xtensa->total_regs_num > 0))) { - LOG_ERROR("xtregfmt: if specified, numgregs (%d) must be <= numregs (%d)", + command_print(CMD, "xtregfmt: if specified, numgregs (%d) must be <= numregs (%d)", numgregs, xtensa->total_regs_num); - return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_COMMAND_ARGUMENT_INVALID; } xtensa->genpkt_regs_num = numgregs; } @@ -4099,7 +4089,7 @@ COMMAND_HELPER(xtensa_cmd_perfmon_dump_do, struct xtensa *xtensa) "%-12" PRIu64 "%s", result.value, result.overflow ? " (overflow)" : ""); - LOG_INFO("%s", result_buf); + command_print(CMD, "%s", result_buf); } return ERROR_OK; @@ -4349,21 +4339,21 @@ COMMAND_HELPER(xtensa_cmd_tracedump_do, struct xtensa *xtensa, const char *fname } memsz = trace_config.memaddr_end - trace_config.memaddr_start + 1; - LOG_INFO("Total trace memory: %d words", memsz); + command_print(CMD, "Total trace memory: %d words", memsz); if ((trace_config.addr & ((TRAXADDR_TWRAP_MASK << TRAXADDR_TWRAP_SHIFT) | TRAXADDR_TWSAT)) == 0) { /*Memory hasn't overwritten itself yet. */ wmem = trace_config.addr & TRAXADDR_TADDR_MASK; - LOG_INFO("...but trace is only %d words", wmem); + command_print(CMD, "...but trace is only %d words", wmem); if (wmem < memsz) memsz = wmem; } else { if (trace_config.addr & TRAXADDR_TWSAT) { - LOG_INFO("Real trace is many times longer than that (overflow)"); + command_print(CMD, "Real trace is many times longer than that (overflow)"); } else { uint32_t trc_sz = (trace_config.addr >> TRAXADDR_TWRAP_SHIFT) & TRAXADDR_TWRAP_MASK; trc_sz = (trc_sz * memsz) + (trace_config.addr & TRAXADDR_TADDR_MASK); - LOG_INFO("Real trace is %d words, but the start has been truncated.", trc_sz); + command_print(CMD, "Real trace is %d words, but the start has been truncated.", trc_sz); } } -- cgit v1.1 From 80b970bd29093a1e3e3b5fdeacda4958721a5afd Mon Sep 17 00:00:00 2001 From: Jacek Wuwer Date: Tue, 9 Jan 2024 11:23:56 +0100 Subject: jtag/vdebug: fix socket options on CYGWIN the socket option RCVLOWAT is not supported on CYGWIN. implemented ifdef __CYGWIN not to set this option. Change-Id: I9f6e81fa98ecf5261ea286deb4675658aae59b8e Signed-off-by: Jacek Wuwer Reviewed-on: https://review.openocd.org/c/openocd/+/8066 Tested-by: jenkins Reviewed-by: Ian Thompson Reviewed-by: Antonio Borneo --- src/jtag/drivers/vdebug.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jtag/drivers/vdebug.c b/src/jtag/drivers/vdebug.c index d2311b2..d51d248 100644 --- a/src/jtag/drivers/vdebug.c +++ b/src/jtag/drivers/vdebug.c @@ -53,7 +53,7 @@ #include "helper/log.h" #include "helper/list.h" -#define VD_VERSION 46 +#define VD_VERSION 47 #define VD_BUFFER_LEN 4024 #define VD_CHEADER_LEN 24 #define VD_SHEADER_LEN 16 @@ -253,6 +253,11 @@ static int vdebug_socket_open(char *server_addr, uint32_t port) hsock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (hsock == INVALID_SOCKET) rc = vdebug_socket_error(); +#elif defined __CYGWIN__ + /* SO_RCVLOWAT unsupported on CYGWIN */ + hsock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); + if (hsock < 0) + rc = errno; #else uint32_t rcvwat = VD_SHEADER_LEN; /* size of the rcv header, as rcv min watermark */ hsock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); -- cgit v1.1 From 151b743714382120dbe0dee0e0eeb75826ef5b3a Mon Sep 17 00:00:00 2001 From: Jacek Wuwer Date: Tue, 9 Jan 2024 14:57:29 +0100 Subject: jtag/vdebug: add support for DAP6 This change implements the support for the ARM Debug Interface v6. The DAP-level interface properly selects the DP Banks and AP address. Sample ARM configuration DAP and JTAG scripts have been updated. Change-Id: I7df87ef764bca587697c778810443649a7f46c2b Signed-off-by: Jacek Wuwer Reviewed-on: https://review.openocd.org/c/openocd/+/8067 Tested-by: jenkins Reviewed-by: Ian Thompson Reviewed-by: Antonio Borneo --- src/jtag/drivers/vdebug.c | 87 +++++++++++++++++++++++++++++++++------------ tcl/board/vd_a53x2_dap.cfg | 19 +++++----- tcl/board/vd_a53x2_jtag.cfg | 20 ++++++----- tcl/board/vd_a75x4_dap.cfg | 30 ++++++++++++++++ tcl/board/vd_a75x4_jtag.cfg | 30 ++++++++++++++++ tcl/board/vd_m4_dap.cfg | 14 ++++---- tcl/board/vd_m4_jtag.cfg | 15 ++++---- tcl/board/vd_m7_jtag.cfg | 15 ++++---- tcl/target/vd_aarch64.cfg | 50 +++++++++++++++----------- tcl/target/vd_cortex_m.cfg | 11 +++--- 10 files changed, 200 insertions(+), 91 deletions(-) create mode 100644 tcl/board/vd_a75x4_dap.cfg create mode 100644 tcl/board/vd_a75x4_jtag.cfg diff --git a/src/jtag/drivers/vdebug.c b/src/jtag/drivers/vdebug.c index d51d248..6d9016e 100644 --- a/src/jtag/drivers/vdebug.c +++ b/src/jtag/drivers/vdebug.c @@ -53,7 +53,7 @@ #include "helper/log.h" #include "helper/list.h" -#define VD_VERSION 47 +#define VD_VERSION 48 #define VD_BUFFER_LEN 4024 #define VD_CHEADER_LEN 24 #define VD_SHEADER_LEN 16 @@ -66,7 +66,8 @@ * @brief List of transactor types */ enum { - VD_BFM_JTDP = 0x0001, /* transactor DAP JTAG DP */ + VD_BFM_TPIU = 0x0000, /* transactor trace TPIU */ + VD_BFM_DAP6 = 0x0001, /* transactor DAP ADI V6 */ VD_BFM_SWDP = 0x0002, /* transactor DAP SWD DP */ VD_BFM_AHB = 0x0003, /* transactor AMBA AHB */ VD_BFM_APB = 0x0004, /* transactor AMBA APB */ @@ -467,14 +468,14 @@ static int vdebug_run_reg_queue(int hsock, struct vd_shm *pm, unsigned int count for (unsigned int j = 0; j < num; j++) memcpy(&data[j * awidth], &pm->rd8[(rwords + j) * awidth], awidth); } - LOG_DEBUG_IO("read %04x AS:%02x RG:%02x O:%05x @%03x D:%08x", le_to_h_u16(pm->wid) - count + req, - aspace, addr, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr, + LOG_DEBUG("read %04x AS:%1x RG:%1x O:%05x @%03x D:%08x", le_to_h_u16(pm->wid) - count + req, + aspace, addr << 2, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr, (num ? le_to_h_u32(&pm->rd8[rwords * 4]) : 0xdead)); rwords += num * wwidth; waddr += sizeof(uint64_t) / 4; /* waddr past header */ } else { - LOG_DEBUG_IO("write %04x AS:%02x RG:%02x O:%05x @%03x D:%08x", le_to_h_u16(pm->wid) - count + req, - aspace, addr, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr, + LOG_DEBUG("write %04x AS:%1x RG:%1x O:%05x @%03x D:%08x", le_to_h_u16(pm->wid) - count + req, + aspace, addr << 2, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr, le_to_h_u32(&pm->wd8[(waddr + num + 1) * 4])); waddr += sizeof(uint64_t) / 4 + (num * wwidth * awidth + 3) / 4; } @@ -518,7 +519,7 @@ static int vdebug_open(int hsock, struct vd_shm *pm, const char *path, rc = VD_ERR_VERSION; } else { pm->cmd = VD_CMD_CONNECT; - pm->type = type; /* BFM type to connect to, here JTAG */ + pm->type = type; /* BFM type to connect to */ h_u32_to_le(pm->rwdata, sig_mask | VD_SIG_BUF | (VD_SIG_BUF << 16)); h_u16_to_le(pm->wbytes, strlen(path) + 1); h_u16_to_le(pm->rbytes, 12); @@ -922,7 +923,7 @@ static int vdebug_reset(int trst, int srst) static int vdebug_jtag_tms_seq(const uint8_t *tms, int num, uint8_t f_flush) { - LOG_INFO("tms len:%d tms:%x", num, *tms); + LOG_DEBUG_IO("tms len:%d tms:%x", num, *tms); return vdebug_jtag_shift_tap(vdc.hsocket, pbuf, num, *tms, 0, NULL, 0, 0, NULL, f_flush); } @@ -930,7 +931,7 @@ static int vdebug_jtag_tms_seq(const uint8_t *tms, int num, uint8_t f_flush) static int vdebug_jtag_path_move(struct pathmove_command *cmd, uint8_t f_flush) { uint8_t tms[DIV_ROUND_UP(cmd->num_states, 8)]; - LOG_INFO("path num states %d", cmd->num_states); + LOG_DEBUG_IO("path num states %d", cmd->num_states); memset(tms, 0, DIV_ROUND_UP(cmd->num_states, 8)); @@ -950,7 +951,7 @@ static int vdebug_jtag_tlr(tap_state_t state, uint8_t f_flush) tap_state_t cur = tap_get_state(); uint8_t tms_pre = tap_get_tms_path(cur, state); uint8_t num_pre = tap_get_tms_path_len(cur, state); - LOG_INFO("tlr from %x to %x", cur, state); + LOG_DEBUG_IO("tlr from %x to %x", cur, state); if (cur != state) { rc = vdebug_jtag_shift_tap(vdc.hsocket, pbuf, num_pre, tms_pre, 0, NULL, 0, 0, NULL, f_flush); tap_set_state(state); @@ -970,7 +971,7 @@ static int vdebug_jtag_scan(struct scan_command *cmd, uint8_t f_flush) uint8_t tms_post = tap_get_tms_path(state, cmd->end_state); uint8_t num_post = tap_get_tms_path_len(state, cmd->end_state); int num_bits = jtag_scan_size(cmd); - LOG_DEBUG("scan len:%d fields:%d ir/!dr:%d state cur:%x end:%x", + LOG_DEBUG_IO("scan len:%d fields:%d ir/!dr:%d state cur:%x end:%x", num_bits, cmd->num_fields, cmd->ir_scan, cur, cmd->end_state); for (int i = 0; i < cmd->num_fields; i++) { uint8_t cur_num_pre = i == 0 ? num_pre : 0; @@ -996,7 +997,7 @@ static int vdebug_jtag_runtest(int cycles, tap_state_t state, uint8_t f_flush) tap_state_t cur = tap_get_state(); uint8_t tms_pre = tap_get_tms_path(cur, state); uint8_t num_pre = tap_get_tms_path_len(cur, state); - LOG_DEBUG("idle len:%d state cur:%x end:%x", cycles, cur, state); + LOG_DEBUG_IO("idle len:%d state cur:%x end:%x", cycles, cur, state); int rc = vdebug_jtag_shift_tap(vdc.hsocket, pbuf, num_pre, tms_pre, cycles, NULL, 0, 0, NULL, f_flush); if (cur != state) tap_set_state(state); @@ -1006,7 +1007,7 @@ static int vdebug_jtag_runtest(int cycles, tap_state_t state, uint8_t f_flush) static int vdebug_jtag_stableclocks(int num, uint8_t f_flush) { - LOG_INFO("stab len:%d state cur:%x", num, tap_get_state()); + LOG_DEBUG("stab len:%d state cur:%x", num, tap_get_state()); return vdebug_jtag_shift_tap(vdc.hsocket, pbuf, 0, 0, num, NULL, 0, 0, NULL, f_flush); } @@ -1081,6 +1082,41 @@ static int vdebug_jtag_execute_queue(void) return rc; } +static int vdebug_dap_bankselect(struct adiv5_ap *ap, unsigned int reg) +{ + int rc = ERROR_OK; + uint64_t sel; + + if (is_adiv6(ap->dap)) { + sel = ap->ap_num | (reg & 0x00000FF0); + if (sel != (ap->dap->select & ~0xfull)) { + sel |= ap->dap->select & DP_SELECT_DPBANK; + if (ap->dap->asize > 32) + sel |= (DP_SELECT1 >> 4) & DP_SELECT_DPBANK; + ap->dap->select = sel; + ap->dap->select_valid = true; + rc = vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, (uint32_t)sel, VD_ASPACE_DP, 0); + if (rc == ERROR_OK) { + ap->dap->select_valid = true; + if (ap->dap->asize > 32) + rc = vdebug_reg_write(vdc.hsocket, pbuf, (DP_SELECT1 & DP_SELECT_DPBANK) >> 2, + (uint32_t)(sel >> 32), VD_ASPACE_DP, 0); + if (rc == ERROR_OK) + ap->dap->select1_valid = true; + } + } + } else { /* ADIv5 */ + sel = (ap->ap_num << 24) | (reg & ADIV5_DP_SELECT_APBANK); + if (sel != ap->dap->select) { + ap->dap->select = sel; + rc = vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, (uint32_t)sel, VD_ASPACE_DP, 0); + if (rc == ERROR_OK) + ap->dap->select_valid = true; + } + } + return rc; +} + static int vdebug_dap_connect(struct adiv5_dap *dap) { return dap_dp_init(dap); @@ -1093,20 +1129,29 @@ static int vdebug_dap_send_sequence(struct adiv5_dap *dap, enum swd_special_seq static int vdebug_dap_queue_dp_read(struct adiv5_dap *dap, unsigned int reg, uint32_t *data) { + if (reg != DP_SELECT && reg != DP_RDBUFF + && (!dap->select_valid || ((reg >> 4) & DP_SELECT_DPBANK) != (dap->select & DP_SELECT_DPBANK))) { + dap->select = (dap->select & ~DP_SELECT_DPBANK) | ((reg >> 4) & DP_SELECT_DPBANK); + vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, dap->select, VD_ASPACE_DP, 0); + dap->select_valid = true; + } return vdebug_reg_read(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, data, VD_ASPACE_DP, 0); } static int vdebug_dap_queue_dp_write(struct adiv5_dap *dap, unsigned int reg, uint32_t data) { + if (reg != DP_SELECT && reg != DP_RDBUFF + && (!dap->select_valid || ((reg >> 4) & DP_SELECT_DPBANK) != (dap->select & DP_SELECT_DPBANK))) { + dap->select = (dap->select & ~DP_SELECT_DPBANK) | ((reg >> 4) & DP_SELECT_DPBANK); + vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, dap->select, VD_ASPACE_DP, 0); + dap->select_valid = true; + } return vdebug_reg_write(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, data, VD_ASPACE_DP, 0); } static int vdebug_dap_queue_ap_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *data) { - if ((reg & ADIV5_DP_SELECT_APBANK) != ap->dap->select) { - vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, reg & ADIV5_DP_SELECT_APBANK, VD_ASPACE_DP, 0); - ap->dap->select = reg & ADIV5_DP_SELECT_APBANK; - } + vdebug_dap_bankselect(ap, reg); vdebug_reg_read(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, NULL, VD_ASPACE_AP, 0); @@ -1115,11 +1160,7 @@ static int vdebug_dap_queue_ap_read(struct adiv5_ap *ap, unsigned int reg, uint3 static int vdebug_dap_queue_ap_write(struct adiv5_ap *ap, unsigned int reg, uint32_t data) { - if ((reg & ADIV5_DP_SELECT_APBANK) != ap->dap->select) { - vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, reg & ADIV5_DP_SELECT_APBANK, VD_ASPACE_DP, 0); - ap->dap->select = reg & ADIV5_DP_SELECT_APBANK; - } - + vdebug_dap_bankselect(ap, reg); return vdebug_reg_write(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, data, VD_ASPACE_AP, 0); } @@ -1175,7 +1216,7 @@ COMMAND_HANDLER(vdebug_set_bfm) break; } if (transport_is_dapdirect_swd()) - vdc.bfm_type = VD_BFM_SWDP; + vdc.bfm_type = strstr(vdc.bfm_path, "dap6") ? VD_BFM_DAP6 : VD_BFM_SWDP; else vdc.bfm_type = VD_BFM_JTAG; LOG_DEBUG("bfm_path: %s clk_period %ups", vdc.bfm_path, vdc.bfm_period); diff --git a/tcl/board/vd_a53x2_dap.cfg b/tcl/board/vd_a53x2_dap.cfg index 4cf5594..bcf8b44 100644 --- a/tcl/board/vd_a53x2_dap.cfg +++ b/tcl/board/vd_a53x2_dap.cfg @@ -4,10 +4,13 @@ source [find interface/vdebug.cfg] -set _CORES 2 -set _CHIPNAME a53 -set _MEMSTART 0x00000000 -set _MEMSIZE 0x1000000 +set CORES 2 +set CHIPNAME a53 +set ACCESSPORT 0 +set MEMSTART 0x00000000 +set MEMSIZE 0x1000000 +set DBGBASE {0x80810000 0x80910000} +set CTIBASE {0x80820000 0x80920000} # vdebug select transport transport select dapdirect_swd @@ -19,11 +22,9 @@ adapter srst delay 5 # BFM hierarchical path and input clk period vdebug bfm_path tbench.u_vd_swdp_bfm 10ns -# DMA Memories to access backdoor (up to 4) -vdebug mem_path tbench.u_memory.mem_array $_MEMSTART $_MEMSIZE +# DMA Memories to access backdoor (up to 20) +vdebug mem_path tbench.u_memory.mem_array $MEMSTART $MEMSIZE -source [find target/swj-dp.tcl] - -swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf +swd newdap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf source [find target/vd_aarch64.cfg] diff --git a/tcl/board/vd_a53x2_jtag.cfg b/tcl/board/vd_a53x2_jtag.cfg index a5e8d24..0c3eebd 100644 --- a/tcl/board/vd_a53x2_jtag.cfg +++ b/tcl/board/vd_a53x2_jtag.cfg @@ -4,11 +4,14 @@ source [find interface/vdebug.cfg] -set _CORES 2 -set _CHIPNAME a53 -set _MEMSTART 0x00000000 -set _MEMSIZE 0x1000000 -set _CPUTAPID 0x5ba00477 +set CORES 2 +set CHIPNAME a53 +set ACCESSPORT 0 +set MEMSTART 0x00000000 +set MEMSIZE 0x1000000 +set DBGBASE {0x80810000 0x80910000} +set CTIBASE {0x80820000 0x80920000} +set CPUTAPID 0x5ba00477 # vdebug select transport transport select jtag @@ -21,11 +24,10 @@ adapter srst delay 5 # BFM hierarchical path and input clk period vdebug bfm_path tbench.u_vd_jtag_bfm 10ns -# DMA Memories to access backdoor (up to 4) -vdebug mem_path tbench.u_memory.mem_array $_MEMSTART $_MEMSIZE - -jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID +# DMA Memories to access backdoor (up to 20) +vdebug mem_path tbench.u_memory.mem_array $MEMSTART $MEMSIZE +jtag newtap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $CPUTAPID jtag arp_init-reset source [find target/vd_aarch64.cfg] diff --git a/tcl/board/vd_a75x4_dap.cfg b/tcl/board/vd_a75x4_dap.cfg new file mode 100644 index 0000000..5c2a2ef --- /dev/null +++ b/tcl/board/vd_a75x4_dap.cfg @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Cadence virtual debug interface +# Arm Cortex A53x2 through DAP + +source [find interface/vdebug.cfg] + +set CORES 4 +set CHIPNAME a75 +set ACCESSPORT 0x00040000 +set MEMSTART 0x00000000 +set MEMSIZE 0x1000000 +set DBGBASE {0x01010000 0x01110000 0x01210000 0x01310000} +set CTIBASE {0x01020000 0x01120000 0x01220000 0x01320000} + +# vdebug select transport +transport select dapdirect_swd + +# JTAG reset config, frequency and reset delay +adapter speed 200000 +adapter srst delay 5 + +# BFM hierarchical path and input clk period +vdebug bfm_path tbench.u_vd_dap6_bfm 2250ps + +# DMA Memories to access backdoor (up to 20) +#vdebug mem_path tbench.u_memory.mem_array $_MEMSTART $_MEMSIZE + +swd newdap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf + +source [find target/vd_aarch64.cfg] diff --git a/tcl/board/vd_a75x4_jtag.cfg b/tcl/board/vd_a75x4_jtag.cfg new file mode 100644 index 0000000..c94a719 --- /dev/null +++ b/tcl/board/vd_a75x4_jtag.cfg @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Cadence virtual debug interface +# Arm Cortex A53x2 through DAP + +source [find interface/vdebug.cfg] + +set CORES 4 +set CHIPNAME a75 +set ACCESSPORT 0x00040000 +set MEMSTART 0x00000000 +set MEMSIZE 0x1000000 +set DBGBASE {0x01010000 0x01110000 0x01210000 0x01310000} +set CTIBASE {0x01020000 0x01120000 0x01220000 0x01320000} +set CPUTAPID 0x4ba06477 + +# vdebug select transport +transport select jtag + +# JTAG reset config, frequency and reset delay +reset_config trst_and_srst +adapter speed 1500000 +adapter srst delay 5 + +# BFM hierarchical path and input clk period +vdebug bfm_path tbench.u_vd_jtag_bfm 333ps + +jtag newtap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $CPUTAPID +jtag arp_init-reset + +source [find target/vd_aarch64.cfg] diff --git a/tcl/board/vd_m4_dap.cfg b/tcl/board/vd_m4_dap.cfg index 691b623..5d3605a 100644 --- a/tcl/board/vd_m4_dap.cfg +++ b/tcl/board/vd_m4_dap.cfg @@ -4,9 +4,9 @@ source [find interface/vdebug.cfg] -set _CHIPNAME m4 -set _MEMSTART 0x00000000 -set _MEMSIZE 0x10000 +set CHIPNAME m4 +set MEMSTART 0x00000000 +set MEMSIZE 0x10000 # vdebug select transport transport select dapdirect_swd @@ -16,11 +16,9 @@ adapter srst delay 5 # BFM hierarchical path and input clk period vdebug bfm_path tbench.u_vd_swdp_bfm 20ns -# DMA Memories to access backdoor (up to 4) -vdebug mem_path tbench.u_mcu.u_sys.u_rom.rom $_MEMSTART $_MEMSIZE +# DMA Memories to access backdoor (up to 20) +vdebug mem_path tbench.u_mcu.u_sys.u_rom.rom $MEMSTART $MEMSIZE -source [find target/swj-dp.tcl] - -swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf +swd newdap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf source [find target/vd_cortex_m.cfg] diff --git a/tcl/board/vd_m4_jtag.cfg b/tcl/board/vd_m4_jtag.cfg index 4c795eb..3b32e17 100644 --- a/tcl/board/vd_m4_jtag.cfg +++ b/tcl/board/vd_m4_jtag.cfg @@ -4,10 +4,10 @@ source [find interface/vdebug.cfg] -set _CHIPNAME m4 -set _MEMSTART 0x00000000 -set _MEMSIZE 0x10000 -set _CPUTAPID 0x4ba00477 +set CHIPNAME m4 +set MEMSTART 0x00000000 +set MEMSIZE 0x10000 +set CPUTAPID 0x4ba00477 # vdebug select transport transport select jtag @@ -20,11 +20,10 @@ adapter srst delay 5 # BFM hierarchical path and input clk period vdebug bfm_path tbench.u_vd_jtag_bfm 20ns -# DMA Memories to access backdoor (up to 4) -vdebug mem_path tbench.u_mcu.u_sys.u_rom.rom $_MEMSTART $_MEMSIZE - -jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID +# DMA Memories to access backdoor (up to 20) +vdebug mem_path tbench.u_mcu.u_sys.u_rom.rom $MEMSTART $MEMSIZE +jtag newtap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $CPUTAPID jtag arp_init-reset source [find target/vd_cortex_m.cfg] diff --git a/tcl/board/vd_m7_jtag.cfg b/tcl/board/vd_m7_jtag.cfg index 880ef9b..9a89584 100644 --- a/tcl/board/vd_m7_jtag.cfg +++ b/tcl/board/vd_m7_jtag.cfg @@ -4,10 +4,10 @@ source [find interface/vdebug.cfg] -set _CHIPNAME m7 -set _MEMSTART 0x00000000 -set _MEMSIZE 0x100000 -set _CPUTAPID 0x0ba02477 +set CHIPNAME m7 +set MEMSTART 0x00000000 +set MEMSIZE 0x100000 +set CPUTAPID 0x0ba02477 # vdebug select JTAG transport transport select jtag @@ -20,11 +20,10 @@ adapter srst delay 5 # BFM hierarchical path and input clk period vdebug bfm_path tbench.u_vd_jtag_bfm 10ns -# DMA Memories to access backdoor (up to 4) -vdebug mem_path tbench.u_mcu.u_sys.u_itcm_ram.Mem $_MEMSTART $_MEMSIZE - -jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID +# DMA Memories to access backdoor (up to 20) +vdebug mem_path tbench.u_mcu.u_sys.u_itcm_ram.Mem $MEMSTART $MEMSIZE +jtag newtap $CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $CPUTAPID jtag arp_init-reset source [find target/vd_cortex_m.cfg] diff --git a/tcl/target/vd_aarch64.cfg b/tcl/target/vd_aarch64.cfg index 619134a..177416b 100644 --- a/tcl/target/vd_aarch64.cfg +++ b/tcl/target/vd_aarch64.cfg @@ -2,36 +2,44 @@ # Cadence virtual debug interface # Arm v8 64b Cortex A -if {![info exists _CORES]} { - set _CORES 1 +if {![info exists CORES]} { + set CORES 1 } -if {![info exists _CHIPNAME]} { - set _CHIPNAME aarch64 +if {![info exists CHIPNAME]} { + set CHIPNAME aarch64 +} +if {[info exists ACCESSPORT]} { + set _APNUM "-ap-num $ACCESSPORT" + if { $ACCESSPORT > 0xff } { + set _DAP6 "-adiv6" + } else { + set _DAP6 "-adiv5" + } +} else { + set _APNUM "" } -set _TARGETNAME $_CHIPNAME.cpu -set _CTINAME $_CHIPNAME.cti -set DBGBASE {0x80810000 0x80910000} -set CTIBASE {0x80820000 0x80920000} +set _TARGETNAME $CHIPNAME.cpu +set _CTINAME $CHIPNAME.cti +set _DAPNAME $CHIPNAME.dap -dap create $_CHIPNAME.dap -chain-position $_TARGETNAME -$_CHIPNAME.dap apsel 1 +dap create $_DAPNAME $_DAP6 -chain-position $_TARGETNAME -for { set _core 0 } { $_core < $_CORES } { incr _core } \ +for { set _core 0 } { $_core < $CORES } { incr _core } \ { - cti create $_CTINAME.$_core -dap $_CHIPNAME.dap -ap-num 1 -baseaddr [lindex $CTIBASE $_core] - set _command "target create $_TARGETNAME.$_core aarch64 -dap $_CHIPNAME.dap \ - -dbgbase [lindex $DBGBASE $_core] -cti $_CTINAME.$_core -coreid $_core" + set _cmd "cti create $_CTINAME.$_core -dap $_DAPNAME $_APNUM -baseaddr [lindex $CTIBASE $_core]" + eval $_cmd + set _cmd "target create $_TARGETNAME.$_core aarch64 -dap $_DAPNAME $_APNUM -dbgbase [lindex $DBGBASE $_core] -cti $_CTINAME.$_core -coreid $_core" if { $_core != 0 } { # non-boot core examination may fail - set _command "$_command -defer-examine" - set _smp_command "$_smp_command $_TARGETNAME.$_core" + set _cmd "$_cmd -defer-examine" + set _smp_cmd "$_smp_cmd $_TARGETNAME.$_core" } else { - set _smp_command "target smp $_TARGETNAME.$_core" + set _smp_cmd "target smp $_TARGETNAME.$_core" } - eval $_command + eval $_cmd } -eval $_smp_command +eval $_smp_cmd -# default target is core 0 -targets $_TARGETNAME.0 +set _TARGETCUR $_TARGETNAME.0 +targets $_TARGETCUR diff --git a/tcl/target/vd_cortex_m.cfg b/tcl/target/vd_cortex_m.cfg index 4d7b0df..7db9d3a 100644 --- a/tcl/target/vd_cortex_m.cfg +++ b/tcl/target/vd_cortex_m.cfg @@ -2,11 +2,12 @@ # Cadence virtual debug interface # ARM Cortex M -if {![info exists _CHIPNAME]} { - set _CHIPNAME cortex_m +if {![info exists CHIPNAME]} { + set CHIPNAME cortex_m } -set _TARGETNAME $_CHIPNAME.cpu +set _TARGETNAME $CHIPNAME.cpu +set _DAPNAME $CHIPNAME.dap -dap create $_CHIPNAME.dap -chain-position $_TARGETNAME +dap create $_DAPNAME -chain-position $_TARGETNAME -target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap +target create $_TARGETNAME cortex_m -dap $_DAPNAME -- cgit v1.1 From 3d3f82392045384e4cfe81bf19140a60312a47e8 Mon Sep 17 00:00:00 2001 From: Ian Thompson Date: Thu, 18 Jan 2024 16:10:26 -0800 Subject: target/xtensa: add dual-core support - Example for configuring multiple non-SMP Xtensa cores e.g. for heterogeneous debug - JTAG only at this time; DAP out of scope - Dual-Xtensa Palladium example via VDebug - Update Xtensa core config examples Signed-off-by: Ian Thompson Change-Id: I6d2b3d13fa8075416dcd383cf256a3e8582ee1c1 Reviewed-on: https://review.openocd.org/c/openocd/+/8078 Tested-by: jenkins Reviewed-by: Jacek Wuwer Reviewed-by: Antonio Borneo --- tcl/board/xtensa-palladium-vdebug-dual.cfg | 33 +++ tcl/board/xtensa-palladium-vdebug.cfg | 16 +- tcl/target/xtensa-core-nxp_rt600.cfg | 456 +++++++++++++++-------------- tcl/target/xtensa-core-xt8.cfg | 297 ++++++++++--------- tcl/target/xtensa.cfg | 25 +- 5 files changed, 455 insertions(+), 372 deletions(-) create mode 100644 tcl/board/xtensa-palladium-vdebug-dual.cfg diff --git a/tcl/board/xtensa-palladium-vdebug-dual.cfg b/tcl/board/xtensa-palladium-vdebug-dual.cfg new file mode 100644 index 0000000..447bc1f --- /dev/null +++ b/tcl/board/xtensa-palladium-vdebug-dual.cfg @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Cadence virtual debug interface +# for Palladium emulation systems +# + +source [find interface/vdebug.cfg] + +# vdebug select JTAG transport +transport select jtag + +# JTAG reset config, frequency and reset delay +reset_config trst_and_srst +adapter speed 50000 +adapter srst delay 5 + +# Future improvement: Enable backdoor memory access +# set _MEMSTART 0x00000000 +# set _MEMSIZE 0x100000 + +# BFM hierarchical path and input clk period +vdebug bfm_path Testbench.VJTAG 10ns + +# DMA Memories to access backdoor (up to 4) +# vdebug mem_path tbench.u_mcu.u_sys.u_itcm_ram.Mem $_MEMSTART $_MEMSIZE + +# Configure dual-core TAP chain +set XTENSA_NUM_CORES 2 + +# Create Xtensa target first +source [find target/xtensa.cfg] + +# Configure Xtensa core parameters next +# Generate [xtensa-core-XXX.cfg] via "xt-gdb --dump-oocd-config" diff --git a/tcl/board/xtensa-palladium-vdebug.cfg b/tcl/board/xtensa-palladium-vdebug.cfg index d4a700e..f14d92d 100644 --- a/tcl/board/xtensa-palladium-vdebug.cfg +++ b/tcl/board/xtensa-palladium-vdebug.cfg @@ -13,4 +13,18 @@ reset_config trst_and_srst adapter speed 50000 adapter srst delay 5 -source [find target/vd_xtensa_jtag.cfg] +# Future improvement: Enable backdoor memory access +# set _MEMSTART 0x00000000 +# set _MEMSIZE 0x100000 + +# BFM hierarchical path and input clk period +vdebug bfm_path Testbench.VJTAG 10ns + +# DMA Memories to access backdoor (up to 4) +# vdebug mem_path tbench.u_mcu.u_sys.u_itcm_ram.Mem $_MEMSTART $_MEMSIZE + +# Create Xtensa target first +source [find target/xtensa.cfg] + +# Configure Xtensa core parameters next +# Generate [xtensa-core-XXX.cfg] via "xt-gdb --dump-oocd-config" diff --git a/tcl/target/xtensa-core-nxp_rt600.cfg b/tcl/target/xtensa-core-nxp_rt600.cfg index abd961e..ca7fd68 100644 --- a/tcl/target/xtensa-core-nxp_rt600.cfg +++ b/tcl/target/xtensa-core-nxp_rt600.cfg @@ -2,246 +2,254 @@ # OpenOCD configuration file for Xtensa HiFi DSP in NXP RT600 target +# Core instance default definition +if { [info exists XTNAME] } { + set _XTNAME $XTNAME +} else { + set _XTNAME xtensa.cpu +} + + # Core definition and ABI -xtensa xtdef LX -xtensa xtopt arnum 32 -xtensa xtopt windowed 1 +$_XTNAME xtensa xtdef LX +$_XTNAME xtensa xtopt arnum 32 +$_XTNAME xtensa xtopt windowed 1 # Exception/Interrupt Options -xtensa xtopt exceptions 1 -xtensa xtopt hipriints 1 -xtensa xtopt intlevels 4 -xtensa xtopt excmlevel 2 +$_XTNAME xtensa xtopt exceptions 1 +$_XTNAME xtensa xtopt hipriints 1 +$_XTNAME xtensa xtopt intlevels 4 +$_XTNAME xtensa xtopt excmlevel 2 # Cache Options -xtensa xtmem icache 256 32768 4 -xtensa xtmem dcache 256 65536 4 1 +$_XTNAME xtensa xtmem icache 256 32768 4 +$_XTNAME xtensa xtmem dcache 256 65536 4 1 # Memory Options -xtensa xtmem iram 0x24020000 65536 -xtensa xtmem dram 0x24000000 65536 -xtensa xtmem sram 0x00000000 603979776 +$_XTNAME xtensa xtmem iram 0x24020000 65536 +$_XTNAME xtensa xtmem dram 0x24000000 65536 +$_XTNAME xtensa xtmem sram 0x00000000 603979776 # Memory Protection/Translation Options # Debug Options -xtensa xtopt debuglevel 4 -xtensa xtopt ibreaknum 2 -xtensa xtopt dbreaknum 2 +$_XTNAME xtensa xtopt debuglevel 4 +$_XTNAME xtensa xtopt ibreaknum 2 +$_XTNAME xtensa xtopt dbreaknum 2 # Core Registers -xtensa xtregs 208 -xtensa xtreg pc 0x0020 -xtensa xtreg ar0 0x0100 -xtensa xtreg ar1 0x0101 -xtensa xtreg ar2 0x0102 -xtensa xtreg ar3 0x0103 -xtensa xtreg ar4 0x0104 -xtensa xtreg ar5 0x0105 -xtensa xtreg ar6 0x0106 -xtensa xtreg ar7 0x0107 -xtensa xtreg ar8 0x0108 -xtensa xtreg ar9 0x0109 -xtensa xtreg ar10 0x010a -xtensa xtreg ar11 0x010b -xtensa xtreg ar12 0x010c -xtensa xtreg ar13 0x010d -xtensa xtreg ar14 0x010e -xtensa xtreg ar15 0x010f -xtensa xtreg ar16 0x0110 -xtensa xtreg ar17 0x0111 -xtensa xtreg ar18 0x0112 -xtensa xtreg ar19 0x0113 -xtensa xtreg ar20 0x0114 -xtensa xtreg ar21 0x0115 -xtensa xtreg ar22 0x0116 -xtensa xtreg ar23 0x0117 -xtensa xtreg ar24 0x0118 -xtensa xtreg ar25 0x0119 -xtensa xtreg ar26 0x011a -xtensa xtreg ar27 0x011b -xtensa xtreg ar28 0x011c -xtensa xtreg ar29 0x011d -xtensa xtreg ar30 0x011e -xtensa xtreg ar31 0x011f -xtensa xtreg lbeg 0x0200 -xtensa xtreg lend 0x0201 -xtensa xtreg lcount 0x0202 -xtensa xtreg sar 0x0203 -xtensa xtreg prefctl 0x0228 -xtensa xtreg windowbase 0x0248 -xtensa xtreg windowstart 0x0249 -xtensa xtreg configid0 0x02b0 -xtensa xtreg configid1 0x02d0 -xtensa xtreg ps 0x02e6 -xtensa xtreg threadptr 0x03e7 -xtensa xtreg br 0x0204 -xtensa xtreg scompare1 0x020c -xtensa xtreg acclo 0x0210 -xtensa xtreg acchi 0x0211 -xtensa xtreg m0 0x0220 -xtensa xtreg m1 0x0221 -xtensa xtreg m2 0x0222 -xtensa xtreg m3 0x0223 -xtensa xtreg expstate 0x03e6 -xtensa xtreg f64r_lo 0x03ea -xtensa xtreg f64r_hi 0x03eb -xtensa xtreg f64s 0x03ec -xtensa xtreg ae_ovf_sar 0x03f0 -xtensa xtreg ae_bithead 0x03f1 -xtensa xtreg ae_ts_fts_bu_bp 0x03f2 -xtensa xtreg ae_cw_sd_no 0x03f3 -xtensa xtreg ae_cbegin0 0x03f6 -xtensa xtreg ae_cend0 0x03f7 -xtensa xtreg ae_cbegin1 0x03f8 -xtensa xtreg ae_cend1 0x03f9 -xtensa xtreg aed0 0x1010 -xtensa xtreg aed1 0x1011 -xtensa xtreg aed2 0x1012 -xtensa xtreg aed3 0x1013 -xtensa xtreg aed4 0x1014 -xtensa xtreg aed5 0x1015 -xtensa xtreg aed6 0x1016 -xtensa xtreg aed7 0x1017 -xtensa xtreg aed8 0x1018 -xtensa xtreg aed9 0x1019 -xtensa xtreg aed10 0x101a -xtensa xtreg aed11 0x101b -xtensa xtreg aed12 0x101c -xtensa xtreg aed13 0x101d -xtensa xtreg aed14 0x101e -xtensa xtreg aed15 0x101f -xtensa xtreg u0 0x1020 -xtensa xtreg u1 0x1021 -xtensa xtreg u2 0x1022 -xtensa xtreg u3 0x1023 -xtensa xtreg aep0 0x1024 -xtensa xtreg aep1 0x1025 -xtensa xtreg aep2 0x1026 -xtensa xtreg aep3 0x1027 -xtensa xtreg fcr_fsr 0x1029 -xtensa xtreg mmid 0x0259 -xtensa xtreg ibreakenable 0x0260 -xtensa xtreg memctl 0x0261 -xtensa xtreg atomctl 0x0263 -xtensa xtreg ddr 0x0268 -xtensa xtreg ibreaka0 0x0280 -xtensa xtreg ibreaka1 0x0281 -xtensa xtreg dbreaka0 0x0290 -xtensa xtreg dbreaka1 0x0291 -xtensa xtreg dbreakc0 0x02a0 -xtensa xtreg dbreakc1 0x02a1 -xtensa xtreg epc1 0x02b1 -xtensa xtreg epc2 0x02b2 -xtensa xtreg epc3 0x02b3 -xtensa xtreg epc4 0x02b4 -xtensa xtreg epc5 0x02b5 -xtensa xtreg depc 0x02c0 -xtensa xtreg eps2 0x02c2 -xtensa xtreg eps3 0x02c3 -xtensa xtreg eps4 0x02c4 -xtensa xtreg eps5 0x02c5 -xtensa xtreg excsave1 0x02d1 -xtensa xtreg excsave2 0x02d2 -xtensa xtreg excsave3 0x02d3 -xtensa xtreg excsave4 0x02d4 -xtensa xtreg excsave5 0x02d5 -xtensa xtreg cpenable 0x02e0 -xtensa xtreg interrupt 0x02e2 -xtensa xtreg intset 0x02e2 -xtensa xtreg intclear 0x02e3 -xtensa xtreg intenable 0x02e4 -xtensa xtreg vecbase 0x02e7 -xtensa xtreg exccause 0x02e8 -xtensa xtreg debugcause 0x02e9 -xtensa xtreg ccount 0x02ea -xtensa xtreg prid 0x02eb -xtensa xtreg icount 0x02ec -xtensa xtreg icountlevel 0x02ed -xtensa xtreg excvaddr 0x02ee -xtensa xtreg ccompare0 0x02f0 -xtensa xtreg ccompare1 0x02f1 -xtensa xtreg misc0 0x02f4 -xtensa xtreg misc1 0x02f5 -xtensa xtreg pwrctl 0x2024 -xtensa xtreg pwrstat 0x2025 -xtensa xtreg eristat 0x2026 -xtensa xtreg cs_itctrl 0x2027 -xtensa xtreg cs_claimset 0x2028 -xtensa xtreg cs_claimclr 0x2029 -xtensa xtreg cs_lockaccess 0x202a -xtensa xtreg cs_lockstatus 0x202b -xtensa xtreg cs_authstatus 0x202c -xtensa xtreg pmg 0x203b -xtensa xtreg pmpc 0x203c -xtensa xtreg pm0 0x203d -xtensa xtreg pm1 0x203e -xtensa xtreg pmctrl0 0x203f -xtensa xtreg pmctrl1 0x2040 -xtensa xtreg pmstat0 0x2041 -xtensa xtreg pmstat1 0x2042 -xtensa xtreg ocdid 0x2043 -xtensa xtreg ocd_dcrclr 0x2044 -xtensa xtreg ocd_dcrset 0x2045 -xtensa xtreg ocd_dsr 0x2046 -xtensa xtreg a0 0x0000 -xtensa xtreg a1 0x0001 -xtensa xtreg a2 0x0002 -xtensa xtreg a3 0x0003 -xtensa xtreg a4 0x0004 -xtensa xtreg a5 0x0005 -xtensa xtreg a6 0x0006 -xtensa xtreg a7 0x0007 -xtensa xtreg a8 0x0008 -xtensa xtreg a9 0x0009 -xtensa xtreg a10 0x000a -xtensa xtreg a11 0x000b -xtensa xtreg a12 0x000c -xtensa xtreg a13 0x000d -xtensa xtreg a14 0x000e -xtensa xtreg a15 0x000f -xtensa xtreg b0 0x0010 -xtensa xtreg b1 0x0011 -xtensa xtreg b2 0x0012 -xtensa xtreg b3 0x0013 -xtensa xtreg b4 0x0014 -xtensa xtreg b5 0x0015 -xtensa xtreg b6 0x0016 -xtensa xtreg b7 0x0017 -xtensa xtreg b8 0x0018 -xtensa xtreg b9 0x0019 -xtensa xtreg b10 0x001a -xtensa xtreg b11 0x001b -xtensa xtreg b12 0x001c -xtensa xtreg b13 0x001d -xtensa xtreg b14 0x001e -xtensa xtreg b15 0x001f -xtensa xtreg psintlevel 0x2006 -xtensa xtreg psum 0x2007 -xtensa xtreg pswoe 0x2008 -xtensa xtreg psexcm 0x2009 -xtensa xtreg pscallinc 0x200a -xtensa xtreg psowb 0x200b -xtensa xtreg acc 0x200c -xtensa xtreg dbnum 0x2011 -xtensa xtreg ae_overflow 0x2014 -xtensa xtreg ae_sar 0x2015 -xtensa xtreg ae_cwrap 0x2016 -xtensa xtreg ae_bitptr 0x2017 -xtensa xtreg ae_bitsused 0x2018 -xtensa xtreg ae_tablesize 0x2019 -xtensa xtreg ae_first_ts 0x201a -xtensa xtreg ae_nextoffset 0x201b -xtensa xtreg ae_searchdone 0x201c -xtensa xtreg roundmode 0x201d -xtensa xtreg invalidflag 0x201e -xtensa xtreg divzeroflag 0x201f -xtensa xtreg overflowflag 0x2020 -xtensa xtreg underflowflag 0x2021 -xtensa xtreg inexactflag 0x2022 +$_XTNAME xtensa xtregs 208 +$_XTNAME xtensa xtreg pc 0x0020 +$_XTNAME xtensa xtreg ar0 0x0100 +$_XTNAME xtensa xtreg ar1 0x0101 +$_XTNAME xtensa xtreg ar2 0x0102 +$_XTNAME xtensa xtreg ar3 0x0103 +$_XTNAME xtensa xtreg ar4 0x0104 +$_XTNAME xtensa xtreg ar5 0x0105 +$_XTNAME xtensa xtreg ar6 0x0106 +$_XTNAME xtensa xtreg ar7 0x0107 +$_XTNAME xtensa xtreg ar8 0x0108 +$_XTNAME xtensa xtreg ar9 0x0109 +$_XTNAME xtensa xtreg ar10 0x010a +$_XTNAME xtensa xtreg ar11 0x010b +$_XTNAME xtensa xtreg ar12 0x010c +$_XTNAME xtensa xtreg ar13 0x010d +$_XTNAME xtensa xtreg ar14 0x010e +$_XTNAME xtensa xtreg ar15 0x010f +$_XTNAME xtensa xtreg ar16 0x0110 +$_XTNAME xtensa xtreg ar17 0x0111 +$_XTNAME xtensa xtreg ar18 0x0112 +$_XTNAME xtensa xtreg ar19 0x0113 +$_XTNAME xtensa xtreg ar20 0x0114 +$_XTNAME xtensa xtreg ar21 0x0115 +$_XTNAME xtensa xtreg ar22 0x0116 +$_XTNAME xtensa xtreg ar23 0x0117 +$_XTNAME xtensa xtreg ar24 0x0118 +$_XTNAME xtensa xtreg ar25 0x0119 +$_XTNAME xtensa xtreg ar26 0x011a +$_XTNAME xtensa xtreg ar27 0x011b +$_XTNAME xtensa xtreg ar28 0x011c +$_XTNAME xtensa xtreg ar29 0x011d +$_XTNAME xtensa xtreg ar30 0x011e +$_XTNAME xtensa xtreg ar31 0x011f +$_XTNAME xtensa xtreg lbeg 0x0200 +$_XTNAME xtensa xtreg lend 0x0201 +$_XTNAME xtensa xtreg lcount 0x0202 +$_XTNAME xtensa xtreg sar 0x0203 +$_XTNAME xtensa xtreg prefctl 0x0228 +$_XTNAME xtensa xtreg windowbase 0x0248 +$_XTNAME xtensa xtreg windowstart 0x0249 +$_XTNAME xtensa xtreg configid0 0x02b0 +$_XTNAME xtensa xtreg configid1 0x02d0 +$_XTNAME xtensa xtreg ps 0x02e6 +$_XTNAME xtensa xtreg threadptr 0x03e7 +$_XTNAME xtensa xtreg br 0x0204 +$_XTNAME xtensa xtreg scompare1 0x020c +$_XTNAME xtensa xtreg acclo 0x0210 +$_XTNAME xtensa xtreg acchi 0x0211 +$_XTNAME xtensa xtreg m0 0x0220 +$_XTNAME xtensa xtreg m1 0x0221 +$_XTNAME xtensa xtreg m2 0x0222 +$_XTNAME xtensa xtreg m3 0x0223 +$_XTNAME xtensa xtreg expstate 0x03e6 +$_XTNAME xtensa xtreg f64r_lo 0x03ea +$_XTNAME xtensa xtreg f64r_hi 0x03eb +$_XTNAME xtensa xtreg f64s 0x03ec +$_XTNAME xtensa xtreg ae_ovf_sar 0x03f0 +$_XTNAME xtensa xtreg ae_bithead 0x03f1 +$_XTNAME xtensa xtreg ae_ts_fts_bu_bp 0x03f2 +$_XTNAME xtensa xtreg ae_cw_sd_no 0x03f3 +$_XTNAME xtensa xtreg ae_cbegin0 0x03f6 +$_XTNAME xtensa xtreg ae_cend0 0x03f7 +$_XTNAME xtensa xtreg ae_cbegin1 0x03f8 +$_XTNAME xtensa xtreg ae_cend1 0x03f9 +$_XTNAME xtensa xtreg aed0 0x1010 +$_XTNAME xtensa xtreg aed1 0x1011 +$_XTNAME xtensa xtreg aed2 0x1012 +$_XTNAME xtensa xtreg aed3 0x1013 +$_XTNAME xtensa xtreg aed4 0x1014 +$_XTNAME xtensa xtreg aed5 0x1015 +$_XTNAME xtensa xtreg aed6 0x1016 +$_XTNAME xtensa xtreg aed7 0x1017 +$_XTNAME xtensa xtreg aed8 0x1018 +$_XTNAME xtensa xtreg aed9 0x1019 +$_XTNAME xtensa xtreg aed10 0x101a +$_XTNAME xtensa xtreg aed11 0x101b +$_XTNAME xtensa xtreg aed12 0x101c +$_XTNAME xtensa xtreg aed13 0x101d +$_XTNAME xtensa xtreg aed14 0x101e +$_XTNAME xtensa xtreg aed15 0x101f +$_XTNAME xtensa xtreg u0 0x1020 +$_XTNAME xtensa xtreg u1 0x1021 +$_XTNAME xtensa xtreg u2 0x1022 +$_XTNAME xtensa xtreg u3 0x1023 +$_XTNAME xtensa xtreg aep0 0x1024 +$_XTNAME xtensa xtreg aep1 0x1025 +$_XTNAME xtensa xtreg aep2 0x1026 +$_XTNAME xtensa xtreg aep3 0x1027 +$_XTNAME xtensa xtreg fcr_fsr 0x1029 +$_XTNAME xtensa xtreg mmid 0x0259 +$_XTNAME xtensa xtreg ibreakenable 0x0260 +$_XTNAME xtensa xtreg memctl 0x0261 +$_XTNAME xtensa xtreg atomctl 0x0263 +$_XTNAME xtensa xtreg ddr 0x0268 +$_XTNAME xtensa xtreg ibreaka0 0x0280 +$_XTNAME xtensa xtreg ibreaka1 0x0281 +$_XTNAME xtensa xtreg dbreaka0 0x0290 +$_XTNAME xtensa xtreg dbreaka1 0x0291 +$_XTNAME xtensa xtreg dbreakc0 0x02a0 +$_XTNAME xtensa xtreg dbreakc1 0x02a1 +$_XTNAME xtensa xtreg epc1 0x02b1 +$_XTNAME xtensa xtreg epc2 0x02b2 +$_XTNAME xtensa xtreg epc3 0x02b3 +$_XTNAME xtensa xtreg epc4 0x02b4 +$_XTNAME xtensa xtreg epc5 0x02b5 +$_XTNAME xtensa xtreg depc 0x02c0 +$_XTNAME xtensa xtreg eps2 0x02c2 +$_XTNAME xtensa xtreg eps3 0x02c3 +$_XTNAME xtensa xtreg eps4 0x02c4 +$_XTNAME xtensa xtreg eps5 0x02c5 +$_XTNAME xtensa xtreg excsave1 0x02d1 +$_XTNAME xtensa xtreg excsave2 0x02d2 +$_XTNAME xtensa xtreg excsave3 0x02d3 +$_XTNAME xtensa xtreg excsave4 0x02d4 +$_XTNAME xtensa xtreg excsave5 0x02d5 +$_XTNAME xtensa xtreg cpenable 0x02e0 +$_XTNAME xtensa xtreg interrupt 0x02e2 +$_XTNAME xtensa xtreg intset 0x02e2 +$_XTNAME xtensa xtreg intclear 0x02e3 +$_XTNAME xtensa xtreg intenable 0x02e4 +$_XTNAME xtensa xtreg vecbase 0x02e7 +$_XTNAME xtensa xtreg exccause 0x02e8 +$_XTNAME xtensa xtreg debugcause 0x02e9 +$_XTNAME xtensa xtreg ccount 0x02ea +$_XTNAME xtensa xtreg prid 0x02eb +$_XTNAME xtensa xtreg icount 0x02ec +$_XTNAME xtensa xtreg icountlevel 0x02ed +$_XTNAME xtensa xtreg excvaddr 0x02ee +$_XTNAME xtensa xtreg ccompare0 0x02f0 +$_XTNAME xtensa xtreg ccompare1 0x02f1 +$_XTNAME xtensa xtreg misc0 0x02f4 +$_XTNAME xtensa xtreg misc1 0x02f5 +$_XTNAME xtensa xtreg pwrctl 0x2024 +$_XTNAME xtensa xtreg pwrstat 0x2025 +$_XTNAME xtensa xtreg eristat 0x2026 +$_XTNAME xtensa xtreg cs_itctrl 0x2027 +$_XTNAME xtensa xtreg cs_claimset 0x2028 +$_XTNAME xtensa xtreg cs_claimclr 0x2029 +$_XTNAME xtensa xtreg cs_lockaccess 0x202a +$_XTNAME xtensa xtreg cs_lockstatus 0x202b +$_XTNAME xtensa xtreg cs_authstatus 0x202c +$_XTNAME xtensa xtreg pmg 0x203b +$_XTNAME xtensa xtreg pmpc 0x203c +$_XTNAME xtensa xtreg pm0 0x203d +$_XTNAME xtensa xtreg pm1 0x203e +$_XTNAME xtensa xtreg pmctrl0 0x203f +$_XTNAME xtensa xtreg pmctrl1 0x2040 +$_XTNAME xtensa xtreg pmstat0 0x2041 +$_XTNAME xtensa xtreg pmstat1 0x2042 +$_XTNAME xtensa xtreg ocdid 0x2043 +$_XTNAME xtensa xtreg ocd_dcrclr 0x2044 +$_XTNAME xtensa xtreg ocd_dcrset 0x2045 +$_XTNAME xtensa xtreg ocd_dsr 0x2046 +$_XTNAME xtensa xtreg a0 0x0000 +$_XTNAME xtensa xtreg a1 0x0001 +$_XTNAME xtensa xtreg a2 0x0002 +$_XTNAME xtensa xtreg a3 0x0003 +$_XTNAME xtensa xtreg a4 0x0004 +$_XTNAME xtensa xtreg a5 0x0005 +$_XTNAME xtensa xtreg a6 0x0006 +$_XTNAME xtensa xtreg a7 0x0007 +$_XTNAME xtensa xtreg a8 0x0008 +$_XTNAME xtensa xtreg a9 0x0009 +$_XTNAME xtensa xtreg a10 0x000a +$_XTNAME xtensa xtreg a11 0x000b +$_XTNAME xtensa xtreg a12 0x000c +$_XTNAME xtensa xtreg a13 0x000d +$_XTNAME xtensa xtreg a14 0x000e +$_XTNAME xtensa xtreg a15 0x000f +$_XTNAME xtensa xtreg b0 0x0010 +$_XTNAME xtensa xtreg b1 0x0011 +$_XTNAME xtensa xtreg b2 0x0012 +$_XTNAME xtensa xtreg b3 0x0013 +$_XTNAME xtensa xtreg b4 0x0014 +$_XTNAME xtensa xtreg b5 0x0015 +$_XTNAME xtensa xtreg b6 0x0016 +$_XTNAME xtensa xtreg b7 0x0017 +$_XTNAME xtensa xtreg b8 0x0018 +$_XTNAME xtensa xtreg b9 0x0019 +$_XTNAME xtensa xtreg b10 0x001a +$_XTNAME xtensa xtreg b11 0x001b +$_XTNAME xtensa xtreg b12 0x001c +$_XTNAME xtensa xtreg b13 0x001d +$_XTNAME xtensa xtreg b14 0x001e +$_XTNAME xtensa xtreg b15 0x001f +$_XTNAME xtensa xtreg psintlevel 0x2006 +$_XTNAME xtensa xtreg psum 0x2007 +$_XTNAME xtensa xtreg pswoe 0x2008 +$_XTNAME xtensa xtreg psexcm 0x2009 +$_XTNAME xtensa xtreg pscallinc 0x200a +$_XTNAME xtensa xtreg psowb 0x200b +$_XTNAME xtensa xtreg acc 0x200c +$_XTNAME xtensa xtreg dbnum 0x2011 +$_XTNAME xtensa xtreg ae_overflow 0x2014 +$_XTNAME xtensa xtreg ae_sar 0x2015 +$_XTNAME xtensa xtreg ae_cwrap 0x2016 +$_XTNAME xtensa xtreg ae_bitptr 0x2017 +$_XTNAME xtensa xtreg ae_bitsused 0x2018 +$_XTNAME xtensa xtreg ae_tablesize 0x2019 +$_XTNAME xtensa xtreg ae_first_ts 0x201a +$_XTNAME xtensa xtreg ae_nextoffset 0x201b +$_XTNAME xtensa xtreg ae_searchdone 0x201c +$_XTNAME xtensa xtreg roundmode 0x201d +$_XTNAME xtensa xtreg invalidflag 0x201e +$_XTNAME xtensa xtreg divzeroflag 0x201f +$_XTNAME xtensa xtreg overflowflag 0x2020 +$_XTNAME xtensa xtreg underflowflag 0x2021 +$_XTNAME xtensa xtreg inexactflag 0x2022 diff --git a/tcl/target/xtensa-core-xt8.cfg b/tcl/target/xtensa-core-xt8.cfg index e544d78..523dc74 100644 --- a/tcl/target/xtensa-core-xt8.cfg +++ b/tcl/target/xtensa-core-xt8.cfg @@ -1,166 +1,175 @@ # SPDX-License-Identifier: GPL-2.0-or-later # OpenOCD configuration file for Xtensa xt8 target + +# Core instance default definition +if { [info exists XTNAME] } { + set _XTNAME $XTNAME +} else { + set _XTNAME xtensa +} + + # Core definition and ABI -xtensa xtdef LX -xtensa xtopt arnum 32 -xtensa xtopt windowed 1 +$_XTNAME xtensa xtdef LX +$_XTNAME xtensa xtopt arnum 32 +$_XTNAME xtensa xtopt windowed 1 # Exception/Interrupt Options -xtensa xtopt exceptions 1 -xtensa xtopt hipriints 1 -xtensa xtopt intlevels 3 -xtensa xtopt excmlevel 1 +$_XTNAME xtensa xtopt exceptions 1 +$_XTNAME xtensa xtopt hipriints 1 +$_XTNAME xtensa xtopt intlevels 3 +$_XTNAME xtensa xtopt excmlevel 1 # Cache Options -xtensa xtmem icache 16 1024 1 -xtensa xtmem dcache 16 1024 1 1 +$_XTNAME xtensa xtmem icache 16 1024 1 +$_XTNAME xtensa xtmem dcache 16 1024 1 1 # Memory Options -xtensa xtmem iram 0x40000000 1048576 -xtensa xtmem dram 0x3ff00000 262144 -xtensa xtmem srom 0x50000000 131072 -xtensa xtmem sram 0x60000000 4194304 +$_XTNAME xtensa xtmem iram 0x40000000 1048576 +$_XTNAME xtensa xtmem dram 0x3ff00000 262144 +$_XTNAME xtensa xtmem srom 0x50000000 131072 +$_XTNAME xtensa xtmem sram 0x60000000 4194304 # Memory Protection/Translation Options # Debug Options -xtensa xtopt debuglevel 3 -xtensa xtopt ibreaknum 2 -xtensa xtopt dbreaknum 2 +$_XTNAME xtensa xtopt debuglevel 3 +$_XTNAME xtensa xtopt ibreaknum 2 +$_XTNAME xtensa xtopt dbreaknum 2 # Core Registers -xtensa xtregs 127 -xtensa xtreg a0 0x0000 -xtensa xtreg a1 0x0001 -xtensa xtreg a2 0x0002 -xtensa xtreg a3 0x0003 -xtensa xtreg a4 0x0004 -xtensa xtreg a5 0x0005 -xtensa xtreg a6 0x0006 -xtensa xtreg a7 0x0007 -xtensa xtreg a8 0x0008 -xtensa xtreg a9 0x0009 -xtensa xtreg a10 0x000a -xtensa xtreg a11 0x000b -xtensa xtreg a12 0x000c -xtensa xtreg a13 0x000d -xtensa xtreg a14 0x000e -xtensa xtreg a15 0x000f -xtensa xtreg pc 0x0020 -xtensa xtreg ar0 0x0100 -xtensa xtreg ar1 0x0101 -xtensa xtreg ar2 0x0102 -xtensa xtreg ar3 0x0103 -xtensa xtreg ar4 0x0104 -xtensa xtreg ar5 0x0105 -xtensa xtreg ar6 0x0106 -xtensa xtreg ar7 0x0107 -xtensa xtreg ar8 0x0108 -xtensa xtreg ar9 0x0109 -xtensa xtreg ar10 0x010a -xtensa xtreg ar11 0x010b -xtensa xtreg ar12 0x010c -xtensa xtreg ar13 0x010d -xtensa xtreg ar14 0x010e -xtensa xtreg ar15 0x010f -xtensa xtreg ar16 0x0110 -xtensa xtreg ar17 0x0111 -xtensa xtreg ar18 0x0112 -xtensa xtreg ar19 0x0113 -xtensa xtreg ar20 0x0114 -xtensa xtreg ar21 0x0115 -xtensa xtreg ar22 0x0116 -xtensa xtreg ar23 0x0117 -xtensa xtreg ar24 0x0118 -xtensa xtreg ar25 0x0119 -xtensa xtreg ar26 0x011a -xtensa xtreg ar27 0x011b -xtensa xtreg ar28 0x011c -xtensa xtreg ar29 0x011d -xtensa xtreg ar30 0x011e -xtensa xtreg ar31 0x011f -xtensa xtreg lbeg 0x0200 -xtensa xtreg lend 0x0201 -xtensa xtreg lcount 0x0202 -xtensa xtreg sar 0x0203 -xtensa xtreg windowbase 0x0248 -xtensa xtreg windowstart 0x0249 -xtensa xtreg configid0 0x02b0 -xtensa xtreg configid1 0x02d0 -xtensa xtreg ps 0x02e6 -xtensa xtreg expstate 0x03e6 -xtensa xtreg mmid 0x0259 -xtensa xtreg ibreakenable 0x0260 -xtensa xtreg ddr 0x0268 -xtensa xtreg ibreaka0 0x0280 -xtensa xtreg ibreaka1 0x0281 -xtensa xtreg dbreaka0 0x0290 -xtensa xtreg dbreaka1 0x0291 -xtensa xtreg dbreakc0 0x02a0 -xtensa xtreg dbreakc1 0x02a1 -xtensa xtreg epc1 0x02b1 -xtensa xtreg epc2 0x02b2 -xtensa xtreg epc3 0x02b3 -xtensa xtreg depc 0x02c0 -xtensa xtreg eps2 0x02c2 -xtensa xtreg eps3 0x02c3 -xtensa xtreg excsave1 0x02d1 -xtensa xtreg excsave2 0x02d2 -xtensa xtreg excsave3 0x02d3 -xtensa xtreg interrupt 0x02e2 -xtensa xtreg intset 0x02e2 -xtensa xtreg intclear 0x02e3 -xtensa xtreg intenable 0x02e4 -xtensa xtreg exccause 0x02e8 -xtensa xtreg debugcause 0x02e9 -xtensa xtreg ccount 0x02ea -xtensa xtreg icount 0x02ec -xtensa xtreg icountlevel 0x02ed -xtensa xtreg excvaddr 0x02ee -xtensa xtreg ccompare0 0x02f0 -xtensa xtreg ccompare1 0x02f1 -xtensa xtreg pwrctl 0x200f -xtensa xtreg pwrstat 0x2010 -xtensa xtreg eristat 0x2011 -xtensa xtreg cs_itctrl 0x2012 -xtensa xtreg cs_claimset 0x2013 -xtensa xtreg cs_claimclr 0x2014 -xtensa xtreg cs_lockaccess 0x2015 -xtensa xtreg cs_lockstatus 0x2016 -xtensa xtreg cs_authstatus 0x2017 -xtensa xtreg fault_info 0x2026 -xtensa xtreg trax_id 0x2027 -xtensa xtreg trax_control 0x2028 -xtensa xtreg trax_status 0x2029 -xtensa xtreg trax_data 0x202a -xtensa xtreg trax_address 0x202b -xtensa xtreg trax_pctrigger 0x202c -xtensa xtreg trax_pcmatch 0x202d -xtensa xtreg trax_delay 0x202e -xtensa xtreg trax_memstart 0x202f -xtensa xtreg trax_memend 0x2030 -xtensa xtreg pmg 0x203e -xtensa xtreg pmpc 0x203f -xtensa xtreg pm0 0x2040 -xtensa xtreg pm1 0x2041 -xtensa xtreg pmctrl0 0x2042 -xtensa xtreg pmctrl1 0x2043 -xtensa xtreg pmstat0 0x2044 -xtensa xtreg pmstat1 0x2045 -xtensa xtreg ocdid 0x2046 -xtensa xtreg ocd_dcrclr 0x2047 -xtensa xtreg ocd_dcrset 0x2048 -xtensa xtreg ocd_dsr 0x2049 -xtensa xtreg psintlevel 0x2003 -xtensa xtreg psum 0x2004 -xtensa xtreg pswoe 0x2005 -xtensa xtreg psexcm 0x2006 -xtensa xtreg pscallinc 0x2007 -xtensa xtreg psowb 0x2008 +$_XTNAME xtensa xtregs 127 +$_XTNAME xtensa xtreg a0 0x0000 +$_XTNAME xtensa xtreg a1 0x0001 +$_XTNAME xtensa xtreg a2 0x0002 +$_XTNAME xtensa xtreg a3 0x0003 +$_XTNAME xtensa xtreg a4 0x0004 +$_XTNAME xtensa xtreg a5 0x0005 +$_XTNAME xtensa xtreg a6 0x0006 +$_XTNAME xtensa xtreg a7 0x0007 +$_XTNAME xtensa xtreg a8 0x0008 +$_XTNAME xtensa xtreg a9 0x0009 +$_XTNAME xtensa xtreg a10 0x000a +$_XTNAME xtensa xtreg a11 0x000b +$_XTNAME xtensa xtreg a12 0x000c +$_XTNAME xtensa xtreg a13 0x000d +$_XTNAME xtensa xtreg a14 0x000e +$_XTNAME xtensa xtreg a15 0x000f +$_XTNAME xtensa xtreg pc 0x0020 +$_XTNAME xtensa xtreg ar0 0x0100 +$_XTNAME xtensa xtreg ar1 0x0101 +$_XTNAME xtensa xtreg ar2 0x0102 +$_XTNAME xtensa xtreg ar3 0x0103 +$_XTNAME xtensa xtreg ar4 0x0104 +$_XTNAME xtensa xtreg ar5 0x0105 +$_XTNAME xtensa xtreg ar6 0x0106 +$_XTNAME xtensa xtreg ar7 0x0107 +$_XTNAME xtensa xtreg ar8 0x0108 +$_XTNAME xtensa xtreg ar9 0x0109 +$_XTNAME xtensa xtreg ar10 0x010a +$_XTNAME xtensa xtreg ar11 0x010b +$_XTNAME xtensa xtreg ar12 0x010c +$_XTNAME xtensa xtreg ar13 0x010d +$_XTNAME xtensa xtreg ar14 0x010e +$_XTNAME xtensa xtreg ar15 0x010f +$_XTNAME xtensa xtreg ar16 0x0110 +$_XTNAME xtensa xtreg ar17 0x0111 +$_XTNAME xtensa xtreg ar18 0x0112 +$_XTNAME xtensa xtreg ar19 0x0113 +$_XTNAME xtensa xtreg ar20 0x0114 +$_XTNAME xtensa xtreg ar21 0x0115 +$_XTNAME xtensa xtreg ar22 0x0116 +$_XTNAME xtensa xtreg ar23 0x0117 +$_XTNAME xtensa xtreg ar24 0x0118 +$_XTNAME xtensa xtreg ar25 0x0119 +$_XTNAME xtensa xtreg ar26 0x011a +$_XTNAME xtensa xtreg ar27 0x011b +$_XTNAME xtensa xtreg ar28 0x011c +$_XTNAME xtensa xtreg ar29 0x011d +$_XTNAME xtensa xtreg ar30 0x011e +$_XTNAME xtensa xtreg ar31 0x011f +$_XTNAME xtensa xtreg lbeg 0x0200 +$_XTNAME xtensa xtreg lend 0x0201 +$_XTNAME xtensa xtreg lcount 0x0202 +$_XTNAME xtensa xtreg sar 0x0203 +$_XTNAME xtensa xtreg windowbase 0x0248 +$_XTNAME xtensa xtreg windowstart 0x0249 +$_XTNAME xtensa xtreg configid0 0x02b0 +$_XTNAME xtensa xtreg configid1 0x02d0 +$_XTNAME xtensa xtreg ps 0x02e6 +$_XTNAME xtensa xtreg expstate 0x03e6 +$_XTNAME xtensa xtreg mmid 0x0259 +$_XTNAME xtensa xtreg ibreakenable 0x0260 +$_XTNAME xtensa xtreg ddr 0x0268 +$_XTNAME xtensa xtreg ibreaka0 0x0280 +$_XTNAME xtensa xtreg ibreaka1 0x0281 +$_XTNAME xtensa xtreg dbreaka0 0x0290 +$_XTNAME xtensa xtreg dbreaka1 0x0291 +$_XTNAME xtensa xtreg dbreakc0 0x02a0 +$_XTNAME xtensa xtreg dbreakc1 0x02a1 +$_XTNAME xtensa xtreg epc1 0x02b1 +$_XTNAME xtensa xtreg epc2 0x02b2 +$_XTNAME xtensa xtreg epc3 0x02b3 +$_XTNAME xtensa xtreg depc 0x02c0 +$_XTNAME xtensa xtreg eps2 0x02c2 +$_XTNAME xtensa xtreg eps3 0x02c3 +$_XTNAME xtensa xtreg excsave1 0x02d1 +$_XTNAME xtensa xtreg excsave2 0x02d2 +$_XTNAME xtensa xtreg excsave3 0x02d3 +$_XTNAME xtensa xtreg interrupt 0x02e2 +$_XTNAME xtensa xtreg intset 0x02e2 +$_XTNAME xtensa xtreg intclear 0x02e3 +$_XTNAME xtensa xtreg intenable 0x02e4 +$_XTNAME xtensa xtreg exccause 0x02e8 +$_XTNAME xtensa xtreg debugcause 0x02e9 +$_XTNAME xtensa xtreg ccount 0x02ea +$_XTNAME xtensa xtreg icount 0x02ec +$_XTNAME xtensa xtreg icountlevel 0x02ed +$_XTNAME xtensa xtreg excvaddr 0x02ee +$_XTNAME xtensa xtreg ccompare0 0x02f0 +$_XTNAME xtensa xtreg ccompare1 0x02f1 +$_XTNAME xtensa xtreg pwrctl 0x200f +$_XTNAME xtensa xtreg pwrstat 0x2010 +$_XTNAME xtensa xtreg eristat 0x2011 +$_XTNAME xtensa xtreg cs_itctrl 0x2012 +$_XTNAME xtensa xtreg cs_claimset 0x2013 +$_XTNAME xtensa xtreg cs_claimclr 0x2014 +$_XTNAME xtensa xtreg cs_lockaccess 0x2015 +$_XTNAME xtensa xtreg cs_lockstatus 0x2016 +$_XTNAME xtensa xtreg cs_authstatus 0x2017 +$_XTNAME xtensa xtreg fault_info 0x2026 +$_XTNAME xtensa xtreg trax_id 0x2027 +$_XTNAME xtensa xtreg trax_control 0x2028 +$_XTNAME xtensa xtreg trax_status 0x2029 +$_XTNAME xtensa xtreg trax_data 0x202a +$_XTNAME xtensa xtreg trax_address 0x202b +$_XTNAME xtensa xtreg trax_pctrigger 0x202c +$_XTNAME xtensa xtreg trax_pcmatch 0x202d +$_XTNAME xtensa xtreg trax_delay 0x202e +$_XTNAME xtensa xtreg trax_memstart 0x202f +$_XTNAME xtensa xtreg trax_memend 0x2030 +$_XTNAME xtensa xtreg pmg 0x203e +$_XTNAME xtensa xtreg pmpc 0x203f +$_XTNAME xtensa xtreg pm0 0x2040 +$_XTNAME xtensa xtreg pm1 0x2041 +$_XTNAME xtensa xtreg pmctrl0 0x2042 +$_XTNAME xtensa xtreg pmctrl1 0x2043 +$_XTNAME xtensa xtreg pmstat0 0x2044 +$_XTNAME xtensa xtreg pmstat1 0x2045 +$_XTNAME xtensa xtreg ocdid 0x2046 +$_XTNAME xtensa xtreg ocd_dcrclr 0x2047 +$_XTNAME xtensa xtreg ocd_dcrset 0x2048 +$_XTNAME xtensa xtreg ocd_dsr 0x2049 +$_XTNAME xtensa xtreg psintlevel 0x2003 +$_XTNAME xtensa xtreg psum 0x2004 +$_XTNAME xtensa xtreg pswoe 0x2005 +$_XTNAME xtensa xtreg psexcm 0x2006 +$_XTNAME xtensa xtreg pscallinc 0x2007 +$_XTNAME xtensa xtreg psowb 0x2008 diff --git a/tcl/target/xtensa.cfg b/tcl/target/xtensa.cfg index 101e135..561131d 100644 --- a/tcl/target/xtensa.cfg +++ b/tcl/target/xtensa.cfg @@ -5,7 +5,7 @@ set xtensa_ids { 0x120034e5 0x120134e5 0x209034e5 0x209134e5 0x209234e5 0x209334e5 0x209434e5 0x209534e5 0x209634e5 0x209734e5 0x20a034e5 0x20a134e5 0x20a234e5 0x20a334e5 0x20a434e5 0x20a534e5 0x20a634e5 0x20a734e5 0x20a834e5 - 0x20b034e5 } + 0x20b034e5 0x20b33ac5 0x20b33ac7 } set expected_xtensa_ids {} foreach i $xtensa_ids { lappend expected_xtensa_ids -expected-id $i @@ -23,6 +23,12 @@ if { [info exists CPUTAPID] } { set _CPUTAPARGLIST [join $expected_xtensa_ids] } +if { [info exists XTENSA_NUM_CORES] } { + set _XTENSA_NUM_CORES $XTENSA_NUM_CORES +} else { + set _XTENSA_NUM_CORES 1 +} + set _TARGETNAME $_CHIPNAME set _CPU0NAME cpu set _TAPNAME $_CHIPNAME.$_CPU0NAME @@ -40,12 +46,25 @@ if { [info exists XTENSA_DAP] } { } else { target create $_TARGETNAME xtensa -dap $_CHIPNAME.dap } -} else { +} elseif { $_XTENSA_NUM_CORES > 1 } { # JTAG direct (without DAP) + for {set i 0} {$i < $_XTENSA_NUM_CORES} {incr i} { + set _LCPUNAME $_CPU0NAME$i + set _LTAPNAME $_CHIPNAME.$_LCPUNAME + eval jtag newtap $_CHIPNAME $_LCPUNAME -irlen 5 $_CPUTAPARGLIST + target create $_LTAPNAME xtensa -chain-position $_LTAPNAME -coreid $i + + $_LTAPNAME configure -event reset-assert-post { soft_reset_halt } + } +} else { + # JTAG direct (without DAP) - for legacy xtensa-config-XXX.cfg format eval jtag newtap $_CHIPNAME $_CPU0NAME -irlen 5 $_CPUTAPARGLIST target create $_TARGETNAME xtensa -chain-position $_TAPNAME } -$_TARGETNAME configure -event reset-assert-post { soft_reset_halt } +if { $_XTENSA_NUM_CORES == 1 } { + # DAP and single-core legacy JTAG + $_TARGETNAME configure -event reset-assert-post { soft_reset_halt } +} gdb_report_register_access_error enable -- cgit v1.1 From 67675323e1ea09b5d1a4250bf58163103c85b844 Mon Sep 17 00:00:00 2001 From: Evgeniy Naydanov Date: Thu, 11 Jan 2024 14:02:28 +0300 Subject: target: pass target to observers via const pointer There are quite a lot of "getters" in target interface. They do not change target structure, nevertheless the structure is passed to these functions via a plain pointer. The intention is to clarify the purpouse of these functions by passing the `target` structure as a pointer to constant data. Change-Id: Ida4a798da94938753b86a293a308d93b091d1bf3 Signed-off-by: Evgeniy Naydanov Reviewed-on: https://review.openocd.org/c/openocd/+/8092 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/target.c | 10 +++++----- src/target/target.h | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 920511e..a411270 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -244,7 +244,7 @@ static const struct nvp nvp_reset_modes[] = { { .name = NULL, .value = -1 }, }; -const char *debug_reason_name(struct target *t) +const char *debug_reason_name(const struct target *t) { const char *cp; @@ -257,7 +257,7 @@ const char *debug_reason_name(struct target *t) return cp; } -const char *target_state_name(struct target *t) +const char *target_state_name(const struct target *t) { const char *cp; cp = nvp_value2name(nvp_target_state, t->state)->name; @@ -733,7 +733,7 @@ int target_examine(void) return retval; } -const char *target_type_name(struct target *target) +const char *target_type_name(const struct target *target) { return target->type->name; } @@ -1398,7 +1398,7 @@ int target_get_gdb_reg_list_noread(struct target *target, return target_get_gdb_reg_list(target, reg_list, reg_list_size, reg_class); } -bool target_supports_gdb_connection(struct target *target) +bool target_supports_gdb_connection(const struct target *target) { /* * exclude all the targets that don't provide get_gdb_reg_list @@ -4851,7 +4851,7 @@ static int target_jim_set_reg(Jim_Interp *interp, int argc, /** * Returns true only if the target has a handler for the specified event. */ -bool target_has_event_action(struct target *target, enum target_event event) +bool target_has_event_action(const struct target *target, enum target_event event) { struct target_event_action *teap; diff --git a/src/target/target.h b/src/target/target.h index f69ee77..bd01f5e 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -222,19 +222,19 @@ struct gdb_fileio_info { }; /** Returns a description of the endianness for the specified target. */ -static inline const char *target_endianness(struct target *target) +static inline const char *target_endianness(const struct target *target) { return (target->endianness == TARGET_ENDIAN_UNKNOWN) ? "unknown" : (target->endianness == TARGET_BIG_ENDIAN) ? "big endian" : "little endian"; } /** Returns the instance-specific name of the specified target. */ -static inline const char *target_name(struct target *target) +static inline const char *target_name(const struct target *target) { return target->cmd_name; } -const char *debug_reason_name(struct target *t); +const char *debug_reason_name(const struct target *t); enum target_event { @@ -301,7 +301,7 @@ struct target_event_action { struct target_event_action *next; }; -bool target_has_event_action(struct target *target, enum target_event event); +bool target_has_event_action(const struct target *target, enum target_event event); struct target_event_callback { int (*callback)(struct target *target, enum target_event event, void *priv); @@ -421,7 +421,7 @@ struct target *get_target(const char *id); * This routine is a wrapper for the target->type->name field. * Note that this is not an instance-specific name for his target. */ -const char *target_type_name(struct target *target); +const char *target_type_name(const struct target *target); /** * Examine the specified @a target, letting it perform any @@ -432,7 +432,7 @@ const char *target_type_name(struct target *target); int target_examine_one(struct target *target); /** @returns @c true if target_set_examined() has been called. */ -static inline bool target_was_examined(struct target *target) +static inline bool target_was_examined(const struct target *target) { return target->examined; } @@ -527,7 +527,7 @@ int target_get_gdb_reg_list_noread(struct target *target, * * Some target do not implement the necessary code required by GDB. */ -bool target_supports_gdb_connection(struct target *target); +bool target_supports_gdb_connection(const struct target *target); /** * Step the target. @@ -694,7 +694,7 @@ unsigned target_address_bits(struct target *target); unsigned int target_data_bits(struct target *target); /** Return the *name* of this targets current state */ -const char *target_state_name(struct target *target); +const char *target_state_name(const struct target *target); /** Return the *name* of a target event enumeration value */ const char *target_event_name(enum target_event event); -- cgit v1.1 From 1b0ffa97ea90c09e96b068450644e462102c10ae Mon Sep 17 00:00:00 2001 From: Evgeniy Naydanov Date: Fri, 12 Jan 2024 16:29:32 +0300 Subject: target: get_gdb_arch() accepts target via const pointer The function in question does not need to change target state. It is a target-type-dependant function, however, IMHO, it is safe to assume that any target type would not need to change type-independant state of a target to figure out the arch. Change-Id: I607cb3aee6529cd5a97bc1200a0226cf6ef43caf Signed-off-by: Evgeniy Naydanov Reviewed-on: https://review.openocd.org/c/openocd/+/8093 Tested-by: jenkins Reviewed-by: Jan Matyas Reviewed-by: Antonio Borneo --- src/target/arm.h | 6 +++--- src/target/armv4_5.c | 2 +- src/target/armv8.c | 2 +- src/target/esirisc.c | 2 +- src/target/esirisc.h | 2 +- src/target/mem_ap.c | 2 +- src/target/riscv/riscv.c | 2 +- src/target/stm8.c | 2 +- src/target/target.c | 2 +- src/target/target.h | 2 +- src/target/target_type.h | 2 +- src/target/xtensa/xtensa.c | 2 +- src/target/xtensa/xtensa.h | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/target/arm.h b/src/target/arm.h index d5053af..486666b 100644 --- a/src/target/arm.h +++ b/src/target/arm.h @@ -257,7 +257,7 @@ struct arm { }; /** Convert target handle to generic ARM target state handle. */ -static inline struct arm *target_to_arm(struct target *target) +static inline struct arm *target_to_arm(const struct target *target) { assert(target); return target->arch_info; @@ -293,11 +293,11 @@ extern const struct command_registration arm_command_handlers[]; extern const struct command_registration arm_all_profiles_command_handlers[]; int arm_arch_state(struct target *target); -const char *arm_get_gdb_arch(struct target *target); +const char *arm_get_gdb_arch(const struct target *target); int arm_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class); -const char *armv8_get_gdb_arch(struct target *target); +const char *armv8_get_gdb_arch(const struct target *target); int armv8_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class); diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index 7debb94..1886d5e 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -1264,7 +1264,7 @@ const struct command_registration arm_command_handlers[] = { * same way as a gdb for arm. This can be changed later on. User can still * set the specific architecture variant with the gdb command. */ -const char *arm_get_gdb_arch(struct target *target) +const char *arm_get_gdb_arch(const struct target *target) { return "arm"; } diff --git a/src/target/armv8.c b/src/target/armv8.c index daf1ffc..bf582ff 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -1865,7 +1865,7 @@ const struct command_registration armv8_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -const char *armv8_get_gdb_arch(struct target *target) +const char *armv8_get_gdb_arch(const struct target *target) { struct arm *arm = target_to_arm(target); return arm->core_state == ARM_STATE_AARCH64 ? "aarch64" : "arm"; diff --git a/src/target/esirisc.c b/src/target/esirisc.c index 561edb2..c9ac1d6 100644 --- a/src/target/esirisc.c +++ b/src/target/esirisc.c @@ -1248,7 +1248,7 @@ static int esirisc_arch_state(struct target *target) return ERROR_OK; } -static const char *esirisc_get_gdb_arch(struct target *target) +static const char *esirisc_get_gdb_arch(const struct target *target) { struct esirisc_common *esirisc = target_to_esirisc(target); diff --git a/src/target/esirisc.h b/src/target/esirisc.h index 7496b1e..6f8cd14 100644 --- a/src/target/esirisc.h +++ b/src/target/esirisc.h @@ -106,7 +106,7 @@ struct esirisc_reg { int (*write)(struct reg *reg); }; -static inline struct esirisc_common *target_to_esirisc(struct target *target) +static inline struct esirisc_common *target_to_esirisc(const struct target *target) { return (struct esirisc_common *)target->arch_info; } diff --git a/src/target/mem_ap.c b/src/target/mem_ap.c index 50dc91c..5c81e3a 100644 --- a/src/target/mem_ap.c +++ b/src/target/mem_ap.c @@ -182,7 +182,7 @@ static struct reg_arch_type mem_ap_reg_arch_type = { .set = mem_ap_reg_set, }; -static const char *mem_ap_get_gdb_arch(struct target *target) +static const char *mem_ap_get_gdb_arch(const struct target *target) { return "arm"; } diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index cb8d04f..d895ca3 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1744,7 +1744,7 @@ static int riscv_write_memory(struct target *target, target_addr_t address, return tt->write_memory(target, address, size, count, buffer); } -static const char *riscv_get_gdb_arch(struct target *target) +static const char *riscv_get_gdb_arch(const struct target *target) { switch (riscv_xlen(target)) { case 32: diff --git a/src/target/stm8.c b/src/target/stm8.c index ad4a452..227101b 100644 --- a/src/target/stm8.c +++ b/src/target/stm8.c @@ -1158,7 +1158,7 @@ static int stm8_write_core_reg(struct target *target, unsigned int num) return ERROR_OK; } -static const char *stm8_get_gdb_arch(struct target *target) +static const char *stm8_get_gdb_arch(const struct target *target) { return "stm8"; } diff --git a/src/target/target.c b/src/target/target.c index a411270..45698a6 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1358,7 +1358,7 @@ int target_hit_watchpoint(struct target *target, return target->type->hit_watchpoint(target, hit_watchpoint); } -const char *target_get_gdb_arch(struct target *target) +const char *target_get_gdb_arch(const struct target *target) { if (!target->type->get_gdb_arch) return NULL; diff --git a/src/target/target.h b/src/target/target.h index bd01f5e..1713448 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -501,7 +501,7 @@ int target_hit_watchpoint(struct target *target, * * This routine is a wrapper for target->type->get_gdb_arch. */ -const char *target_get_gdb_arch(struct target *target); +const char *target_get_gdb_arch(const struct target *target); /** * Obtain the registers for GDB. diff --git a/src/target/target_type.h b/src/target/target_type.h index 678ce0f..bc42c2d 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -83,7 +83,7 @@ struct target_type { * if dynamic allocation is used for this value, it must be managed by * the target, ideally by caching the result for subsequent calls. */ - const char *(*get_gdb_arch)(struct target *target); + const char *(*get_gdb_arch)(const struct target *target); /** * Target register access for GDB. Do @b not call this function diff --git a/src/target/xtensa/xtensa.c b/src/target/xtensa/xtensa.c index b516c17..fb7748a 100644 --- a/src/target/xtensa/xtensa.c +++ b/src/target/xtensa/xtensa.c @@ -3442,7 +3442,7 @@ void xtensa_target_deinit(struct target *target) free(xtensa->core_config); } -const char *xtensa_get_gdb_arch(struct target *target) +const char *xtensa_get_gdb_arch(const struct target *target) { return "xtensa"; } diff --git a/src/target/xtensa/xtensa.h b/src/target/xtensa/xtensa.h index f799208..a220021 100644 --- a/src/target/xtensa/xtensa.h +++ b/src/target/xtensa/xtensa.h @@ -422,7 +422,7 @@ int xtensa_run_algorithm(struct target *target, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info); void xtensa_set_permissive_mode(struct target *target, bool state); -const char *xtensa_get_gdb_arch(struct target *target); +const char *xtensa_get_gdb_arch(const struct target *target); int xtensa_gdb_query_custom(struct target *target, const char *packet, char **response_p); COMMAND_HELPER(xtensa_cmd_xtdef_do, struct xtensa *xtensa); -- cgit v1.1 From 9659a9b5e28dc615dfb508d301fdd8fa426c191b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 14 Jan 2024 17:51:41 +0100 Subject: target/esirisc: free memory at OpenOCD exit The target esirisc does not free the allocated memory resources, causing memory leaks at OpenOCD exit. Add esirisc_free_reg_cache() and esirisc_deinit_target() and use them to free all the allocated resources. Change-Id: I17b8ebff54906fa25a37f2d96c01d010a98cffbd Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8094 Tested-by: jenkins Reviewed-by: Steven Stallion --- src/target/esirisc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/target/esirisc.c b/src/target/esirisc.c index c9ac1d6..0f76b59 100644 --- a/src/target/esirisc.c +++ b/src/target/esirisc.c @@ -1486,6 +1486,32 @@ static struct reg_cache *esirisc_build_reg_cache(struct target *target) return cache; } +static void esirisc_free_reg_cache(struct target *target) +{ + struct esirisc_common *esirisc = target_to_esirisc(target); + struct reg_cache *cache = esirisc->reg_cache; + struct reg *reg_list = cache->reg_list; + + for (int i = 0; i < esirisc->num_regs; ++i) { + struct reg *reg = reg_list + esirisc_regs[i].number; + + free(reg->arch_info); + free(reg->value); + free(reg->reg_data_type); + } + + for (size_t i = 0; i < ARRAY_SIZE(esirisc_csrs); ++i) { + struct reg *reg = reg_list + esirisc_csrs[i].number; + + free(reg->arch_info); + free(reg->value); + free(reg->reg_data_type); + } + + free(reg_list); + free(cache); +} + static int esirisc_identify(struct target *target) { struct esirisc_common *esirisc = target_to_esirisc(target); @@ -1584,6 +1610,19 @@ static int esirisc_init_target(struct command_context *cmd_ctx, struct target *t return ERROR_OK; } +static void esirisc_deinit_target(struct target *target) +{ + struct esirisc_common *esirisc = target_to_esirisc(target); + + if (!target_was_examined(target)) + return; + + esirisc_free_reg_cache(target); + + free(esirisc->gdb_arch); + free(esirisc); +} + static int esirisc_examine(struct target *target) { struct esirisc_common *esirisc = target_to_esirisc(target); @@ -1822,5 +1861,6 @@ struct target_type esirisc_target = { .target_create = esirisc_target_create, .init_target = esirisc_init_target, + .deinit_target = esirisc_deinit_target, .examine = esirisc_examine, }; -- cgit v1.1