static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t len, const uint8_t *buffer) { int result; struct icdi_usb_handle_s *h; h = (struct icdi_usb_handle_s *)handle; size_t cmd_len = snprintf(h->write_buffer, h->max_packet, PACKET_START "X%x,%x:", addr, len); int out_len; cmd_len += remote_escape_output((char *)buffer, len, h->write_buffer + cmd_len, &out_len, h->max_packet - cmd_len); if (out_len < (int)len) { /* for now issue a error as we have no way of allocating a larger buffer */ LOG_ERROR("memory buffer too small: requires 0x%" PRIx32 " actual 0x%" PRIx32, out_len, len); return ERROR_FAIL; } result = icdi_send_packet(handle, cmd_len); if (result != ERROR_OK) return result; /* check result */ result = icdi_get_cmd_result(handle); if (result != ERROR_OK) { LOG_ERROR("memory write failed: 0x%x", result); return ERROR_FAIL; } return ERROR_OK; }
/* Write the response to a successful qXfer read. Returns the length of the (binary) data stored in BUF, corresponding to as much of DATA/LEN as we could fit. IS_MORE controls the first character of the response. */ static int write_qxfer_response (char *buf, unsigned char *data, int len, int is_more) { int out_len; if (is_more) buf[0] = 'm'; else buf[0] = 'l'; return remote_escape_output (data, len, (unsigned char *) buf + 1, &out_len, PBUFSIZ - POVERHSIZ - 1) + 1; }