1 /***************************************************************************
2 * Copyright (C) 2009 by Dimitar Dimitrov <dinuxbg@gmail.com> *
3 * based on Dominic Rath's and Benedikt Sauter's usbprog.c *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
19 ***************************************************************************/
25 #include <jtag/interface.h>
26 #include <jtag/commands.h>
28 #include "usb_common.h"
30 #define USB_VID 0x15ba
31 #define USB_PID 0x001e
33 #define ARMJTAGEW_EPT_BULK_OUT 0x01u
34 #define ARMJTAGEW_EPT_BULK_IN 0x82u
36 #define ARMJTAGEW_USB_TIMEOUT 2000
38 #define ARMJTAGEW_IN_BUFFER_SIZE (4*1024)
39 #define ARMJTAGEW_OUT_BUFFER_SIZE (4*1024)
41 /* USB command request codes. */
42 #define CMD_GET_VERSION 0x00
43 #define CMD_SELECT_DPIMPL 0x10
44 #define CMD_SET_TCK_FREQUENCY 0x11
45 #define CMD_GET_TCK_FREQUENCY 0x12
46 #define CMD_MEASURE_MAX_TCK_FREQ 0x15
47 #define CMD_MEASURE_RTCK_RESPONSE 0x16
48 #define CMD_TAP_SHIFT 0x17
49 #define CMD_SET_TAPHW_STATE 0x20
50 #define CMD_GET_TAPHW_STATE 0x21
51 #define CMD_TGPWR_SETUP 0x22
53 /* Global USB buffers */
54 static uint8_t usb_in_buffer
[ARMJTAGEW_IN_BUFFER_SIZE
];
55 static uint8_t usb_out_buffer
[ARMJTAGEW_OUT_BUFFER_SIZE
];
57 /* Queue command functions */
58 static void armjtagew_end_state(tap_state_t state
);
59 static void armjtagew_state_move(void);
60 static void armjtagew_path_move(int num_states
, tap_state_t
*path
);
61 static void armjtagew_runtest(int num_cycles
);
62 static void armjtagew_scan(bool ir_scan
,
66 struct scan_command
*command
);
67 static void armjtagew_reset(int trst
, int srst
);
68 /* static void armjtagew_simple_command(uint8_t command); */
69 static int armjtagew_get_status(void);
71 /* tap buffer functions */
72 static void armjtagew_tap_init(void);
73 static int armjtagew_tap_execute(void);
74 static void armjtagew_tap_ensure_space(int scans
, int bits
);
75 static void armjtagew_tap_append_step(int tms
, int tdi
);
76 static void armjtagew_tap_append_scan(int length
, uint8_t *buffer
, struct scan_command
*command
);
78 /* ARM-JTAG-EW lowlevel functions */
80 struct usb_dev_handle
*usb_handle
;
83 static struct armjtagew
*armjtagew_usb_open(void);
84 static void armjtagew_usb_close(struct armjtagew
*armjtagew
);
85 static int armjtagew_usb_message(struct armjtagew
*armjtagew
, int out_length
, int in_length
);
86 static int armjtagew_usb_write(struct armjtagew
*armjtagew
, int out_length
);
87 static int armjtagew_usb_read(struct armjtagew
*armjtagew
, int exp_in_length
);
89 /* helper functions */
90 static int armjtagew_get_version_info(void);
92 #ifdef _DEBUG_USB_COMMS_
93 static void armjtagew_debug_buffer(uint8_t *buffer
, int length
);
96 static struct armjtagew
*armjtagew_handle
;
98 /**************************************************************************
99 * External interface implementation */
101 static int armjtagew_execute_queue(void)
103 struct jtag_command
*cmd
= jtag_command_queue
;
108 while (cmd
!= NULL
) {
111 DEBUG_JTAG_IO("runtest %i cycles, end in %i",
112 cmd
->cmd
.runtest
->num_cycles
, \
113 cmd
->cmd
.runtest
->end_state
);
115 armjtagew_end_state(cmd
->cmd
.runtest
->end_state
);
116 armjtagew_runtest(cmd
->cmd
.runtest
->num_cycles
);
120 DEBUG_JTAG_IO("statemove end in %i", cmd
->cmd
.statemove
->end_state
);
122 armjtagew_end_state(cmd
->cmd
.statemove
->end_state
);
123 armjtagew_state_move();
127 DEBUG_JTAG_IO("pathmove: %i states, end in %i", \
128 cmd
->cmd
.pathmove
->num_states
, \
129 cmd
->cmd
.pathmove
->path
[cmd
->cmd
.pathmove
->num_states
- 1]);
131 armjtagew_path_move(cmd
->cmd
.pathmove
->num_states
,
132 cmd
->cmd
.pathmove
->path
);
136 DEBUG_JTAG_IO("scan end in %i", cmd
->cmd
.scan
->end_state
);
138 armjtagew_end_state(cmd
->cmd
.scan
->end_state
);
140 scan_size
= jtag_build_buffer(cmd
->cmd
.scan
, &buffer
);
141 DEBUG_JTAG_IO("scan input, length = %d", scan_size
);
143 #ifdef _DEBUG_USB_COMMS_
144 armjtagew_debug_buffer(buffer
, (scan_size
+ 7) / 8);
146 type
= jtag_scan_type(cmd
->cmd
.scan
);
147 armjtagew_scan(cmd
->cmd
.scan
->ir_scan
,
149 scan_size
, cmd
->cmd
.scan
);
153 DEBUG_JTAG_IO("reset trst: %i srst %i",
154 cmd
->cmd
.reset
->trst
,
155 cmd
->cmd
.reset
->srst
);
157 armjtagew_tap_execute();
159 if (cmd
->cmd
.reset
->trst
== 1)
160 tap_set_state(TAP_RESET
);
161 armjtagew_reset(cmd
->cmd
.reset
->trst
, cmd
->cmd
.reset
->srst
);
165 DEBUG_JTAG_IO("sleep %i", cmd
->cmd
.sleep
->us
);
166 armjtagew_tap_execute();
167 jtag_sleep(cmd
->cmd
.sleep
->us
);
171 LOG_ERROR("BUG: unknown JTAG command type encountered");
177 return armjtagew_tap_execute();
180 /* Sets speed in kHz. */
181 static int armjtagew_speed(int speed
)
187 usb_out_buffer
[0] = CMD_SET_TCK_FREQUENCY
;
188 buf_set_u32(usb_out_buffer
+ 1, 0, 32, speed
*1000);
190 result
= armjtagew_usb_message(armjtagew_handle
, 5, 4);
193 LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result
);
194 return ERROR_JTAG_DEVICE_ERROR
;
197 usb_out_buffer
[0] = CMD_GET_TCK_FREQUENCY
;
198 result
= armjtagew_usb_message(armjtagew_handle
, 1, 4);
199 speed_real
= (int)buf_get_u32(usb_in_buffer
, 0, 32) / 1000;
201 LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result
);
202 return ERROR_JTAG_DEVICE_ERROR
;
204 LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed
, speed_real
);
209 static int armjtagew_khz(int khz
, int *jtag_speed
)
216 static int armjtagew_speed_div(int speed
, int *khz
)
223 static int armjtagew_init(void)
227 armjtagew_handle
= armjtagew_usb_open();
229 if (armjtagew_handle
== 0) {
231 "Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
232 return ERROR_JTAG_INIT_FAILED
;
236 while (check_cnt
< 3) {
237 if (armjtagew_get_version_info() == ERROR_OK
) {
238 /* attempt to get status */
239 armjtagew_get_status();
247 LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
249 /* Initial JTAG speed (for reset and initialization): 32 kHz */
252 LOG_INFO("ARM-JTAG-EW JTAG Interface ready");
254 armjtagew_reset(0, 0);
255 armjtagew_tap_init();
260 static int armjtagew_quit(void)
262 armjtagew_usb_close(armjtagew_handle
);
266 /**************************************************************************
267 * Queue command implementations */
269 static void armjtagew_end_state(tap_state_t state
)
271 if (tap_is_state_stable(state
))
272 tap_set_end_state(state
);
274 LOG_ERROR("BUG: %i is not a valid end state", state
);
279 /* Goes to the end state. */
280 static void armjtagew_state_move(void)
284 uint8_t tms_scan
= tap_get_tms_path(tap_get_state(), tap_get_end_state());
285 int tms_count
= tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
287 for (i
= 0; i
< tms_count
; i
++) {
288 tms
= (tms_scan
>> i
) & 1;
289 armjtagew_tap_append_step(tms
, 0);
292 tap_set_state(tap_get_end_state());
295 static void armjtagew_path_move(int num_states
, tap_state_t
*path
)
299 for (i
= 0; i
< num_states
; i
++) {
301 * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
302 * Either handle that here, or update the documentation with examples
303 * how to fix that in the configuration files.
305 if (path
[i
] == tap_state_transition(tap_get_state(), false))
306 armjtagew_tap_append_step(0, 0);
307 else if (path
[i
] == tap_state_transition(tap_get_state(), true))
308 armjtagew_tap_append_step(1, 0);
310 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
311 tap_state_name(tap_get_state()), tap_state_name(path
[i
]));
315 tap_set_state(path
[i
]);
318 tap_set_end_state(tap_get_state());
321 static void armjtagew_runtest(int num_cycles
)
325 tap_state_t saved_end_state
= tap_get_end_state();
327 /* only do a state_move when we're not already in IDLE */
328 if (tap_get_state() != TAP_IDLE
) {
329 armjtagew_end_state(TAP_IDLE
);
330 armjtagew_state_move();
333 /* execute num_cycles */
334 for (i
= 0; i
< num_cycles
; i
++)
335 armjtagew_tap_append_step(0, 0);
337 /* finish in end_state */
338 armjtagew_end_state(saved_end_state
);
339 if (tap_get_state() != tap_get_end_state())
340 armjtagew_state_move();
343 static void armjtagew_scan(bool ir_scan
,
347 struct scan_command
*command
)
349 tap_state_t saved_end_state
;
351 armjtagew_tap_ensure_space(1, scan_size
+ 8);
353 saved_end_state
= tap_get_end_state();
355 /* Move to appropriate scan state */
356 armjtagew_end_state(ir_scan
? TAP_IRSHIFT
: TAP_DRSHIFT
);
358 /* Only move if we're not already there */
359 if (tap_get_state() != tap_get_end_state())
360 armjtagew_state_move();
362 armjtagew_end_state(saved_end_state
);
365 armjtagew_tap_append_scan(scan_size
, buffer
, command
);
367 /* We are in Exit1, go to Pause */
368 armjtagew_tap_append_step(0, 0);
370 tap_set_state(ir_scan
? TAP_IRPAUSE
: TAP_DRPAUSE
);
372 if (tap_get_state() != tap_get_end_state())
373 armjtagew_state_move();
376 static void armjtagew_reset(int trst
, int srst
)
378 const uint8_t trst_mask
= (1u << 5);
379 const uint8_t srst_mask
= (1u << 6);
382 uint8_t change_mask
= 0;
385 LOG_DEBUG("trst: %i, srst: %i", trst
, srst
);
389 outp_en
&= ~srst_mask
; /* tristate */
390 change_mask
|= srst_mask
;
391 } else if (srst
== 1) {
393 outp_en
|= srst_mask
;
394 change_mask
|= srst_mask
;
399 outp_en
&= ~trst_mask
; /* tristate */
400 change_mask
|= trst_mask
;
401 } else if (trst
== 1) {
403 outp_en
|= trst_mask
;
404 change_mask
|= trst_mask
;
407 usb_out_buffer
[0] = CMD_SET_TAPHW_STATE
;
408 usb_out_buffer
[1] = val
;
409 usb_out_buffer
[2] = outp_en
;
410 usb_out_buffer
[3] = change_mask
;
411 result
= armjtagew_usb_write(armjtagew_handle
, 4);
413 LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result
);
416 static int armjtagew_get_status(void)
420 usb_out_buffer
[0] = CMD_GET_TAPHW_STATE
;
421 result
= armjtagew_usb_message(armjtagew_handle
, 1, 12);
424 unsigned int u_tg
= buf_get_u32(usb_in_buffer
, 0, 16);
426 "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
427 (int)(buf_get_u32(usb_in_buffer
+ 0, 0, 16)),
428 (int)(buf_get_u32(usb_in_buffer
+ 2, 0, 16)),
429 (int)(buf_get_u32(usb_in_buffer
+ 4, 0, 16)),
430 (int)(buf_get_u32(usb_in_buffer
+ 6, 0, 16)),
432 usb_in_buffer
[11] ? "OVERCURRENT" : "OK",
433 usb_in_buffer
[10] ? "enabled" : "disabled");
436 LOG_ERROR("Vref too low. Check Target Power");
438 LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result
);
443 static int armjtagew_get_version_info(void)
449 /* query hardware version */
450 usb_out_buffer
[0] = CMD_GET_VERSION
;
451 result
= armjtagew_usb_message(armjtagew_handle
, 1, 4 + 15 + 256);
454 LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result
);
455 return ERROR_JTAG_DEVICE_ERROR
;
458 memcpy(sn
, usb_in_buffer
+ 4, 15);
460 memcpy(auxinfo
, usb_in_buffer
+ 4+15, 256);
464 "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \
467 isgraph(usb_in_buffer
[2]) ? usb_in_buffer
[2] : 'X', \
471 if (1 != usb_in_buffer
[1] || 6 != usb_in_buffer
[0])
473 "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
479 COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command
)
481 if (armjtagew_get_version_info() == ERROR_OK
) {
482 /* attempt to get status */
483 armjtagew_get_status();
489 static const struct command_registration armjtagew_command_handlers
[] = {
491 .name
= "armjtagew_info",
492 .handler
= &armjtagew_handle_armjtagew_info_command
,
493 .mode
= COMMAND_EXEC
,
494 .help
= "query armjtagew info",
496 COMMAND_REGISTRATION_DONE
499 struct jtag_interface armjtagew_interface
= {
500 .name
= "arm-jtag-ew",
501 .commands
= armjtagew_command_handlers
,
502 .transports
= jtag_only
,
503 .execute_queue
= armjtagew_execute_queue
,
504 .speed
= armjtagew_speed
,
505 .speed_div
= armjtagew_speed_div
,
506 .khz
= armjtagew_khz
,
507 .init
= armjtagew_init
,
508 .quit
= armjtagew_quit
,
511 /**************************************************************************
512 * ARM-JTAG-EW tap functions */
514 /* 2048 is the max value we can use here */
515 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
517 static int tap_length
;
518 static uint8_t tms_buffer
[ARMJTAGEW_TAP_BUFFER_SIZE
];
519 static uint8_t tdi_buffer
[ARMJTAGEW_TAP_BUFFER_SIZE
];
520 static uint8_t tdo_buffer
[ARMJTAGEW_TAP_BUFFER_SIZE
];
522 struct pending_scan_result
{
523 int first
; /* First bit position in tdo_buffer to read */
524 int length
; /* Number of bits to read */
525 struct scan_command
*command
; /* Corresponding scan command */
529 #define MAX_PENDING_SCAN_RESULTS 256
531 static int pending_scan_results_length
;
532 static struct pending_scan_result pending_scan_results_buffer
[MAX_PENDING_SCAN_RESULTS
];
536 static void armjtagew_tap_init(void)
539 pending_scan_results_length
= 0;
542 static void armjtagew_tap_ensure_space(int scans
, int bits
)
544 int available_scans
= MAX_PENDING_SCAN_RESULTS
- pending_scan_results_length
;
545 int available_bits
= ARMJTAGEW_TAP_BUFFER_SIZE
* 8 - tap_length
;
547 if (scans
> available_scans
|| bits
> available_bits
)
548 armjtagew_tap_execute();
551 static void armjtagew_tap_append_step(int tms
, int tdi
)
554 int index_local
= tap_length
/ 8;
556 if (index_local
< ARMJTAGEW_TAP_BUFFER_SIZE
) {
557 int bit_index
= tap_length
% 8;
558 uint8_t bit
= 1 << bit_index
;
561 tms_buffer
[index_local
] |= bit
;
563 tms_buffer
[index_local
] &= ~bit
;
566 tdi_buffer
[index_local
] |= bit
;
568 tdi_buffer
[index_local
] &= ~bit
;
572 LOG_ERROR("armjtagew_tap_append_step, overflow");
575 void armjtagew_tap_append_scan(int length
, uint8_t *buffer
, struct scan_command
*command
)
577 struct pending_scan_result
*pending_scan_result
=
578 &pending_scan_results_buffer
[pending_scan_results_length
];
581 pending_scan_result
->first
= tap_length
;
582 pending_scan_result
->length
= length
;
583 pending_scan_result
->command
= command
;
584 pending_scan_result
->buffer
= buffer
;
586 for (i
= 0; i
< length
; i
++)
587 armjtagew_tap_append_step((i
< length
-1 ? 0 : 1), (buffer
[i
/8] >> (i
%8)) & 1);
588 pending_scan_results_length
++;
591 /* Pad and send a tap sequence to the device, and receive the answer.
592 * For the purpose of padding we assume that we are in idle or pause state. */
593 static int armjtagew_tap_execute(void)
601 if (tap_length
> 0) {
602 /* Pad last byte so that tap_length is divisible by 8 */
603 while (tap_length
% 8 != 0) {
604 /* More of the last TMS value keeps us in the same state,
605 * analogous to free-running JTAG interfaces. */
606 armjtagew_tap_append_step(last_tms
, 0);
609 byte_length
= tap_length
/ 8;
611 usb_out_buffer
[0] = CMD_TAP_SHIFT
;
612 buf_set_u32(usb_out_buffer
+ 1, 0, 16, byte_length
);
615 for (i
= 0; i
< byte_length
; i
++)
616 usb_out_buffer
[tms_offset
+ i
] = flip_u32(tms_buffer
[i
], 8);
618 tdi_offset
= tms_offset
+ byte_length
;
619 for (i
= 0; i
< byte_length
; i
++)
620 usb_out_buffer
[tdi_offset
+ i
] = flip_u32(tdi_buffer
[i
], 8);
622 result
= armjtagew_usb_message(armjtagew_handle
,
629 stat_local
= (int)buf_get_u32(usb_in_buffer
+ byte_length
, 0, 32);
632 "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
634 return ERROR_JTAG_QUEUE_FAILED
;
637 for (i
= 0; i
< byte_length
; i
++)
638 tdo_buffer
[i
] = flip_u32(usb_in_buffer
[i
], 8);
640 for (i
= 0; i
< pending_scan_results_length
; i
++) {
641 struct pending_scan_result
*pending_scan_result
=
642 &pending_scan_results_buffer
[i
];
643 uint8_t *buffer
= pending_scan_result
->buffer
;
644 int length
= pending_scan_result
->length
;
645 int first
= pending_scan_result
->first
;
646 struct scan_command
*command
= pending_scan_result
->command
;
649 buf_set_buf(tdo_buffer
, first
, buffer
, 0, length
);
651 DEBUG_JTAG_IO("pending scan result, length = %d", length
);
653 #ifdef _DEBUG_USB_COMMS_
654 armjtagew_debug_buffer(buffer
, byte_length
);
657 if (jtag_read_buffer(buffer
, command
) != ERROR_OK
) {
658 armjtagew_tap_init();
659 return ERROR_JTAG_QUEUE_FAILED
;
662 if (pending_scan_result
->buffer
!= NULL
)
663 free(pending_scan_result
->buffer
);
666 LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
669 return ERROR_JTAG_QUEUE_FAILED
;
672 armjtagew_tap_init();
678 /****************************************************************************
679 * JLink USB low-level functions */
681 static struct armjtagew
*armjtagew_usb_open()
685 const uint16_t vids
[] = { USB_VID
, 0 };
686 const uint16_t pids
[] = { USB_PID
, 0 };
687 struct usb_dev_handle
*dev
;
688 if (jtag_usb_open(vids
, pids
, &dev
) != ERROR_OK
)
691 struct armjtagew
*result
= malloc(sizeof(struct armjtagew
));
692 result
->usb_handle
= dev
;
695 /* usb_set_configuration required under win32 */
696 usb_set_configuration(dev
, dev
->config
[0].bConfigurationValue
);
698 usb_claim_interface(dev
, 0);
701 * This makes problems under Mac OS X. And is not needed
702 * under Windows. Hopefully this will not break a linux build
704 usb_set_altinterface(dev
, 0);
709 static void armjtagew_usb_close(struct armjtagew
*armjtagew
)
711 usb_close(armjtagew
->usb_handle
);
715 /* Send a message and receive the reply. */
716 static int armjtagew_usb_message(struct armjtagew
*armjtagew
, int out_length
, int in_length
)
720 result
= armjtagew_usb_write(armjtagew
, out_length
);
721 if (result
== out_length
) {
722 result
= armjtagew_usb_read(armjtagew
, in_length
);
723 if (result
!= in_length
) {
724 LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
730 LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length
, result
);
736 /* Write data from out_buffer to USB. */
737 static int armjtagew_usb_write(struct armjtagew
*armjtagew
, int out_length
)
741 if (out_length
> ARMJTAGEW_OUT_BUFFER_SIZE
) {
742 LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
744 ARMJTAGEW_OUT_BUFFER_SIZE
);
748 result
= usb_bulk_write(armjtagew
->usb_handle
, ARMJTAGEW_EPT_BULK_OUT
, \
749 (char *)usb_out_buffer
, out_length
, ARMJTAGEW_USB_TIMEOUT
);
751 DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length
, result
);
753 #ifdef _DEBUG_USB_COMMS_
754 armjtagew_debug_buffer(usb_out_buffer
, out_length
);
759 /* Read data from USB into in_buffer. */
760 static int armjtagew_usb_read(struct armjtagew
*armjtagew
, int exp_in_length
)
762 int result
= usb_bulk_read(armjtagew
->usb_handle
, ARMJTAGEW_EPT_BULK_IN
, \
763 (char *)usb_in_buffer
, exp_in_length
, ARMJTAGEW_USB_TIMEOUT
);
765 DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result
);
767 #ifdef _DEBUG_USB_COMMS_
768 armjtagew_debug_buffer(usb_in_buffer
, result
);
773 #ifdef _DEBUG_USB_COMMS_
774 #define BYTES_PER_LINE 16
776 static void armjtagew_debug_buffer(uint8_t *buffer
, int length
)
783 for (i
= 0; i
< length
; i
+= BYTES_PER_LINE
) {
784 snprintf(line
, 5, "%04x", i
);
785 for (j
= i
; j
< i
+ BYTES_PER_LINE
&& j
< length
; j
++) {
786 snprintf(s
, 4, " %02x", buffer
[j
]);
789 LOG_DEBUG("%s", line
);
791 /* Prevent GDB timeout (writing to log might take some time) */