56 #define DEFAULT_HALT_TIMEOUT 5000
73 int fileio_errno,
bool ctrl_c);
138 { .name =
NULL, .value = -1 }
153 { .value = -1, .name =
NULL }
216 { .name =
NULL, .value = -1 }
226 { .name =
NULL, .value = -1 },
239 { .name =
NULL, .value = -1 },
247 { .name =
NULL, .value = -1 },
255 { .name =
NULL, .value = -1 },
266 cp =
"(*BUG*unknown*BUG*)";
277 cp =
"(*BUG*unknown*BUG*)";
281 cp =
"examine deferred";
291 LOG_ERROR(
"Invalid target event: %d", (
int)(event));
292 cp =
"(*BUG*unknown*BUG*)";
302 LOG_ERROR(
"Invalid target reset mode: %d", (
int)(reset_mode));
303 cp =
"(*BUG*unknown*BUG*)";
399 for (i = 0; i <
count; i++)
407 for (i = 0; i <
count; i++)
415 for (i = 0; i <
count; i++)
423 for (i = 0; i <
count; i++)
431 for (i = 0; i <
count; i++)
439 for (i = 0; i <
count; i++)
457 unsigned int index, counter;
458 if (parse_uint(
id, &index) !=
ERROR_OK)
474 LOG_ERROR(
"BUG: current_target out of bounds");
509 LOG_INFO(
"Halt timed out, wake up GDB.");
568 bool handle_breakpoints,
bool debug_execution)
625 sprintf(buf,
"ocd_process_reset %s", n->
name);
626 retval = Jim_Eval(
cmd->ctx->interp, buf);
630 if (retval != JIM_OK) {
631 Jim_MakeErrorMessage(
cmd->ctx->interp);
762 LOG_ERROR(
"Target %s does not support soft_reset_halt",
788 int num_mem_params,
struct mem_param *mem_params,
791 unsigned int timeout_ms,
void *
arch_info)
802 LOG_ERROR(
"Target type '%s' does not support %s",
810 num_mem_params, mem_params,
812 entry_point, exit_point, timeout_ms,
arch_info);
815 num_mem_params, mem_params,
820 num_mem_params, mem_params,
843 int num_mem_params,
struct mem_param *mem_params,
844 int num_reg_params,
struct reg_param *reg_params,
856 LOG_ERROR(
"Target type '%s' does not support %s",
861 LOG_ERROR(
"Target is already running an algorithm");
867 num_mem_params, mem_params,
868 num_reg_params, reg_params,
888 int num_mem_params,
struct mem_param *mem_params,
889 int num_reg_params,
struct reg_param *reg_params,
896 LOG_ERROR(
"Target type '%s' does not support %s",
901 LOG_ERROR(
"Target is not running an algorithm");
906 num_mem_params, mem_params,
907 num_reg_params, reg_params,
960 const uint8_t *
buffer, uint32_t
count,
int block_size,
961 int num_mem_params,
struct mem_param *mem_params,
962 int num_reg_params,
struct reg_param *reg_params,
964 uint32_t entry_point, uint32_t exit_point,
void *
arch_info)
969 const uint8_t *buffer_orig =
buffer;
973 uint32_t wp_addr = buffer_start;
974 uint32_t rp_addr = buffer_start + 4;
975 uint32_t fifo_start_addr = buffer_start + 8;
976 uint32_t fifo_end_addr = buffer_start +
buffer_size;
978 uint32_t wp = fifo_start_addr;
979 uint32_t rp = fifo_start_addr;
993 num_reg_params, reg_params,
999 LOG_ERROR(
"error starting target flash write algorithm");
1007 LOG_ERROR(
"failed to get read pointer");
1011 LOG_DEBUG(
"offs 0x%zx count 0x%" PRIx32
" wp 0x%" PRIx32
" rp 0x%" PRIx32,
1015 LOG_ERROR(
"flash write algorithm aborted by target");
1020 if (!
IS_ALIGNED(rp - fifo_start_addr, block_size) || rp < fifo_start_addr || rp >= fifo_end_addr) {
1021 LOG_ERROR(
"corrupted fifo read pointer 0x%" PRIx32, rp);
1028 uint32_t thisrun_bytes;
1030 thisrun_bytes = rp - wp - block_size;
1031 else if (rp > fifo_start_addr)
1032 thisrun_bytes = fifo_end_addr - wp;
1034 thisrun_bytes = fifo_end_addr - wp - block_size;
1036 if (thisrun_bytes == 0) {
1046 LOG_ERROR(
"timeout waiting for algorithm, a target reset is recommended");
1056 if (thisrun_bytes >
count * block_size)
1057 thisrun_bytes =
count * block_size;
1060 if (thisrun_bytes >= 16)
1061 thisrun_bytes -= (rp + thisrun_bytes) & 0x03;
1070 count -= thisrun_bytes / block_size;
1071 wp += thisrun_bytes;
1072 if (wp >= fifo_end_addr)
1073 wp = fifo_start_addr;
1090 num_reg_params, reg_params,
1096 LOG_ERROR(
"error waiting for target flash write algorithm");
1103 if (retval ==
ERROR_OK && rp == 0) {
1104 LOG_ERROR(
"flash write algorithm aborted by target");
1114 int num_mem_params,
struct mem_param *mem_params,
1115 int num_reg_params,
struct reg_param *reg_params,
1117 uint32_t entry_point, uint32_t exit_point,
void *
arch_info)
1122 const uint8_t *buffer_orig =
buffer;
1126 uint32_t wp_addr = buffer_start;
1127 uint32_t rp_addr = buffer_start + 4;
1128 uint32_t fifo_start_addr = buffer_start + 8;
1129 uint32_t fifo_end_addr = buffer_start +
buffer_size;
1131 uint32_t wp = fifo_start_addr;
1132 uint32_t rp = fifo_start_addr;
1146 num_reg_params, reg_params,
1152 LOG_ERROR(
"error starting target flash read algorithm");
1159 LOG_ERROR(
"failed to get write pointer");
1163 LOG_DEBUG(
"offs 0x%zx count 0x%" PRIx32
" wp 0x%" PRIx32
" rp 0x%" PRIx32,
1167 LOG_ERROR(
"flash read algorithm aborted by target");
1172 if (!
IS_ALIGNED(wp - fifo_start_addr, block_size) || wp < fifo_start_addr || wp >= fifo_end_addr) {
1173 LOG_ERROR(
"corrupted fifo write pointer 0x%" PRIx32, wp);
1179 uint32_t thisrun_bytes;
1181 thisrun_bytes = wp - rp;
1183 thisrun_bytes = fifo_end_addr - rp;
1185 if (thisrun_bytes == 0) {
1195 LOG_ERROR(
"timeout waiting for algorithm, a target reset is recommended");
1205 if (thisrun_bytes >
count * block_size)
1206 thisrun_bytes =
count * block_size;
1209 if (thisrun_bytes >= 16)
1210 thisrun_bytes -= (rp + thisrun_bytes) & 0x03;
1219 count -= thisrun_bytes / block_size;
1220 rp += thisrun_bytes;
1221 if (rp >= fifo_end_addr)
1222 rp = fifo_start_addr;
1244 num_reg_params, reg_params,
1250 LOG_ERROR(
"error waiting for target flash write algorithm");
1257 if (retval ==
ERROR_OK && wp == 0) {
1258 LOG_ERROR(
"flash read algorithm aborted by target");
1406 struct reg **reg_list[],
int *reg_list_size,
1418 reg_list_size, reg_class);
1429 struct reg **reg_list[],
int *reg_list_size,
1434 reg_list_size, reg_class) ==
ERROR_OK)
1511 uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
1514 num_samples, seconds);
1529 if (!
type->check_reset)
1532 assert(
type->init_target);
1534 int retval =
type->init_target(cmd_ctx,
target);
1544 if (!
type->virt2phys) {
1553 if (
type->write_phys_memory ||
type->read_phys_memory ||
type->virt2phys)
1557 type->write_phys_memory =
type->write_memory;
1558 type->read_phys_memory =
type->read_memory;
1613 static bool target_initialized;
1614 if (target_initialized) {
1615 LOG_INFO(
"'target init' has already been called");
1618 target_initialized =
true;
1645 while ((*callbacks_p)->next)
1646 callbacks_p = &((*callbacks_p)->next);
1647 callbacks_p = &((*callbacks_p)->next);
1651 (*callbacks_p)->callback =
callback;
1652 (*callbacks_p)->priv =
priv;
1653 (*callbacks_p)->next =
NULL;
1668 LOG_ERROR(
"error allocating buffer for reset callback entry");
1681 size_t len, uint8_t *data,
void *
priv),
void *
priv)
1690 LOG_ERROR(
"error allocating buffer for trace callback entry");
1723 while ((*callbacks_p)->next)
1724 callbacks_p = &((*callbacks_p)->next);
1725 callbacks_p = &((*callbacks_p)->next);
1729 (*callbacks_p)->callback =
callback;
1730 (*callbacks_p)->type =
type;
1731 (*callbacks_p)->removed =
false;
1733 (*callbacks_p)->priv =
priv;
1734 (*callbacks_p)->next =
NULL;
1782 size_t len, uint8_t *data,
void *
priv),
void *
priv)
1839 LOG_DEBUG(
"target event %i (%s) for core %s", event,
1858 LOG_DEBUG(
"target reset %i (%s)", reset_mode,
1897 static bool callback_processing;
1900 if (callback_processing)
1903 callback_processing =
true;
1919 if ((*callback)->removed) {
1926 bool call_it = (*callback)->callback &&
1928 now >= (*callback)->when);
1939 callback_processing =
false;
1976 assert(size <= area->
size);
1979 if (size < area->
size) {
1990 new_wa->
free =
true;
1992 area->
next = new_wa;
2007 while (c && c->
next) {
2044 LOG_DEBUG(
"MMU disabled, using physical "
2049 LOG_ERROR(
"No working memory available. "
2050 "Specify -work-area-phys to target.");
2060 LOG_ERROR(
"No working memory available. "
2061 "Specify -work-area-virt to target.");
2074 new_wa->
free =
true;
2137 LOG_WARNING(
"not enough working area available(requested %"PRIu32
")",
size);
2161 if (!area || area->
free)
2236 uint32_t max_size = 0;
2253 assert(smp_targets);
2254 if (smp_targets == &empty_smp_targets)
2356 int retcode,
int fileio_errno,
bool ctrl_c)
2362 uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
2364 int64_t then =
timeval_ms() + seconds * 1000LL;
2366 LOG_INFO(
"Starting profiling. Halting and resuming the"
2367 " target as often as we can...");
2369 uint32_t sample_count = 0;
2378 samples[sample_count++] = t;
2387 LOG_INFO(
"Target not halted or running");
2395 if (sample_count >= max_num_samples ||
timeval_ms() >= then) {
2396 LOG_INFO(
"Profiling completed. %" PRIu32
" samples.", sample_count);
2401 *num_samples = sample_count;
2406 const char **insn_set)
2411 command_print(
cmd,
"Instruction-set detection not implemented on target %s",
2413 command_print(
cmd,
"Change target or specify one of the instruction set:");
2566 LOG_ERROR(
"error allocating buffer for section (%" PRIu32
" bytes)",
size);
2581 uint8_t erased_value,
unsigned int *checked)
2592 erased_value, checked);
2597 uint8_t value_buf[8];
2617 uint8_t value_buf[4];
2637 uint8_t value_buf[2];
2675 uint8_t value_buf[8];
2692 uint8_t value_buf[4];
2709 uint8_t value_buf[2];
2740 uint8_t value_buf[8];
2757 uint8_t value_buf[4];
2774 uint8_t value_buf[2];
2811 "can't be the current target\n",
2817 if (
cmd->ctx->current_target_override)
2818 cmd->ctx->current_target_override =
target;
2835 unsigned int index = 0;
2837 command_print(
CMD,
"-- ------------------ ---------- ------ ------------------ ------------");
2845 state =
"tap-disabled";
2852 "%2d%c %-18s %-10s %-6s %-18s %s",
2877 static int prev_srst_asserted;
2878 static int prev_power_dropout;
2890 static int64_t last_power;
2891 bool wait_more = last_power + 2000 > current;
2894 last_power = current;
2901 int srst_deasserted;
2904 static int64_t last_srst;
2905 wait_more = last_srst + 2000 > current;
2906 if (srst_deasserted && !wait_more) {
2908 last_srst = current;
2917 if (srst_deasserted || power_restored) {
2944 Jim_Interp *interp = (Jim_Interp *)
priv;
2952 static int recursive;
2960 int did_something = 0;
2962 LOG_INFO(
"srst asserted detected, running srst_asserted proc.");
2963 Jim_Eval(interp,
"srst_asserted");
2967 Jim_Eval(interp,
"srst_deasserted");
2971 LOG_INFO(
"Power dropout detected, running power_dropout proc.");
2972 Jim_Eval(interp,
"power_dropout");
2976 Jim_Eval(interp,
"power_restore");
2980 if (did_something) {
3045 unsigned int count = 0;
3061 "(%i) %s (/%" PRIu32
"): 0x%s%s",
3074 cache = cache->
next;
3086 unsigned int count = 0;
3089 for (i = 0; i < cache->
num_regs; i++) {
3090 if (
count++ == num) {
3097 cache = cache->
next;
3102 "has only %i registers (0 - %i)", num,
count,
count - 1);
3211 retval = parse_uint(
CMD_ARGV[0], &ms);
3238 int retval = parse_uint(
CMD_ARGV[0], &ms);
3254 int64_t then = 0, cur;
3275 if ((cur-then) > ms) {
3276 LOG_ERROR(
"timed out while waiting for target %s",
3298 unsigned int wait_local;
3299 retval = parse_uint(
CMD_ARGV[0], &wait_local);
3327 const struct nvp *n;
3331 reset_mode = n->
value;
3341 bool current =
true;
3383 unsigned int count,
const uint8_t *
buffer,
bool include_address)
3385 const unsigned int line_bytecnt = 32;
3386 unsigned int line_modulo = line_bytecnt /
size;
3388 char output[line_bytecnt * 4 + 1];
3389 unsigned int output_len = 0;
3391 const char *value_fmt;
3394 value_fmt =
"%16.16"PRIx64
" ";
3397 value_fmt =
"%8.8"PRIx64
" ";
3400 value_fmt =
"%4.4"PRIx64
" ";
3403 value_fmt =
"%2.2"PRIx64
" ";
3411 for (
unsigned int i = 0; i <
count; i++) {
3412 if (include_address && i % line_modulo == 0) {
3413 output_len += snprintf(
output + output_len,
3414 sizeof(
output) - output_len,
3420 const uint8_t *value_ptr =
buffer + i *
size;
3434 output_len += snprintf(
output + output_len,
3435 sizeof(
output) - output_len,
3438 if ((i % line_modulo == line_modulo - 1) || (i ==
count - 1)) {
3450 unsigned int size = 0;
3468 bool physical = strcmp(
CMD_ARGV[0],
"phys") == 0;
3483 unsigned int count = 1;
3489 LOG_ERROR(
"Failed to allocate md read buffer");
3509 unsigned int data_size,
3517 const unsigned int chunk_size = 16384;
3518 uint8_t *target_buf = malloc(chunk_size * data_size);
3526 for (
unsigned int i = 0; i < chunk_size; i++) {
3527 switch (data_size) {
3541 LOG_ERROR(
"Unsupported data size %u", data_size);
3547 for (
unsigned int x = 0; x < c; x += chunk_size) {
3548 unsigned int current;
3550 if (current > chunk_size)
3551 current = chunk_size;
3552 retval = fn(
target,
address + x * data_size, data_size, current, target_buf);
3574 bool physical = strcmp(
CMD_ARGV[0],
"phys") == 0;
3591 unsigned int count = 1;
3596 unsigned int wordsize;
3620 if (CMD_ARGC < 1 || CMD_ARGC > 5)
3640 *max_address += *min_address;
3643 if (*min_address > *max_address)
3653 uint32_t image_size;
3659 &
image, &min_address, &max_address);
3681 "error allocating buffer for section (%d bytes)",
3694 uint32_t
length = buf_cnt;
3727 "in %fs (%0.3f KiB/s)", image_size,
3741 int retval, retvaltemp;
3752 uint32_t buf_size = (
size > 4096) ? 4096 :
size;
3753 buffer = malloc(buf_size);
3766 size_t size_written;
3767 uint32_t this_run_size = (
size > buf_size) ? buf_size :
size;
3776 size -= this_run_size;
3788 "dumped %zu bytes in %fs (%0.3f KiB/s)", filesize,
3809 uint32_t image_size;
3811 uint32_t checksum = 0;
3812 uint32_t mem_checksum = 0;
3852 "error allocating buffer for section (%" PRIu32
" bytes)",
3881 if (checksum != mem_checksum) {
3886 LOG_ERROR(
"checksum mismatch - attempting binary compare");
3888 data = malloc(buf_cnt);
3893 for (t = 0; t < buf_cnt; t++) {
3894 if (data[t] !=
buffer[t]) {
3896 "diff %d address " TARGET_ADDR_FMT ". Was 0x%02" PRIx8
" instead of 0x%02" PRIx8,
3901 if (diffs++ >= 127) {
3926 image_size += buf_cnt;
3935 "in %fs (%0.3f KiB/s)", image_size,
4005 command_print(
cmd,
"Context breakpoint: asid=0x%8.8" PRIx32
", len=0x%x, num=%u",
4037 }
else if (
addr == 0) {
4078 if (strcmp(
CMD_ARGV[2],
"hw") == 0) {
4084 }
else if (strcmp(
CMD_ARGV[2],
"hw_ctx") == 0) {
4117 command_print(
CMD,
"Error encountered during removal of all breakpoints.");
4144 ", r/w/a: %c, value: 0x%8.8" PRIx64
4145 ", mask: 0x%8.8" PRIx64,
4159 uint64_t data_value = 0x0;
4161 bool mask_specified =
false;
4166 mask_specified =
true;
4171 if (!mask_specified)
4200 data_value, data_mask);
4219 command_print(
CMD,
"Error encountered during removal of all watchpoints.");
4260 size_t written = fwrite(data, 1, len, f);
4262 LOG_ERROR(
"failed to write %zu bytes: %s", len, strerror(errno));
4283 uint32_t min = samples[0];
4284 uint32_t max = samples[sample_num - 1];
4294 if ((max - min) % 2)
4296 uint32_t address_space = max - min;
4307 for (
size_t i = strlen(
"seconds"); i < 15; i++)
4312 bool saturated_once =
false;
4313 for (uint32_t i = 0, bidx = 0; bidx < address_space; bidx +=
sizeof(
UNIT)) {
4315 uint32_t bmax = min + bidx +
sizeof(
UNIT);
4316 while (i < sample_num && samples[i] < bmax)
4320 if (val > UINT16_MAX) {
4322 if (!saturated_once)
4323 LOG_WARNING(
"profiler bucket saturated, will read as 65535");
4324 saturated_once =
true;
4334 static void write_gmon(
const uint32_t *samples, uint32_t sample_num,
const char *filename,
4337 float sample_rate = sample_num / (duration_ms / 1000.0);
4338 FILE *f = fopen(filename,
"wb");
4347 while (sample_num) {
4349 const uint32_t MAX_GAP = 32;
4352 uint32_t max = samples[0];
4353 uint32_t this_pass = 1;
4354 while (this_pass < sample_num && samples[this_pass] - max < MAX_GAP)
4355 max = samples[this_pass++];
4359 samples += this_pass;
4360 sample_num -= this_pass;
4369 uint32_t lhs = *(
const uint32_t *)p1;
4370 uint32_t rhs = *(
const uint32_t *)p2;
4371 return (lhs > rhs) - (lhs < rhs);
4383 const uint32_t MAX_PROFILE_SAMPLE_NUM = 1000000;
4385 uint32_t num_of_samples;
4391 uint32_t start_address = 0;
4392 uint32_t end_address = 0;
4393 bool with_range =
false;
4398 if (start_address > end_address || (end_address - start_address) < 2) {
4404 uint32_t *samples = malloc(
sizeof(uint32_t) * MAX_PROFILE_SAMPLE_NUM);
4406 LOG_ERROR(
"No memory to store samples.");
4417 &num_of_samples,
offset);
4422 uint64_t duration_ms =
timeval_ms() - timestart_ms;
4424 assert(num_of_samples <= MAX_PROFILE_SAMPLE_NUM);
4456 if (!num_of_samples) {
4463 uint32_t num_filtered_samples = 0;
4464 for (uint32_t in = 0; in < num_of_samples; ++in) {
4465 uint32_t sample = samples[in];
4466 if (sample >= start_address && sample < end_address)
4467 samples[num_filtered_samples++] = sample;
4469 duration_ms = (duration_ms * num_filtered_samples + num_of_samples / 2) / num_of_samples;
4470 if (duration_ms < 1)
4472 num_of_samples = num_filtered_samples;
4474 if (!num_of_samples) {
4481 qsort(samples, num_of_samples,
sizeof(samples[0]),
compare_pc32);
4499 if (CMD_ARGC < 3 || CMD_ARGC > 4)
4507 unsigned int width_bits;
4515 bool is_phys =
false;
4525 switch (width_bits) {
4536 if (
count > 65536) {
4541 const unsigned int width = width_bits / 8;
4552 const size_t buffersize = 4096;
4553 uint8_t *
buffer = malloc(buffersize);
4560 char *separator =
"";
4562 const unsigned int max_chunk_len = buffersize /
width;
4563 const size_t chunk_len = MIN(
count, max_chunk_len);
4574 addr, width_bits, chunk_len);
4584 for (
size_t i = 0; i < chunk_len ; i++) {
4624 if (CMD_ARGC < 3 || CMD_ARGC > 4)
4632 unsigned int width_bits;
4639 bool is_phys =
false;
4650 switch (width_bits) {
4661 if (
count > 65536) {
4662 command_print(
CMD,
"too large memory write request, exceeds 64K elements");
4666 const unsigned int width = width_bits / 8;
4677 const size_t buffersize = 4096;
4678 uint8_t *
buffer = malloc(buffersize);
4688 const unsigned int max_chunk_len = buffersize /
width;
4689 const size_t chunk_len = MIN(
count, max_chunk_len);
4691 for (
size_t i = 0; i < chunk_len; i++, j++) {
4693 jim_wide element_wide;
4694 int jimretval = Jim_GetWide(
CMD_CTX->interp, tmp, &element_wide);
4695 if (jimretval != JIM_OK) {
4701 const uint64_t v = element_wide;
4730 addr, width_bits, chunk_len);
4753 if (teap->
event == e) {
4761 LOG_DEBUG(
"target: %s (%s) event: %d (%s) action: %s",
4780 Jim_IncrRefCount(teap->
body);
4781 retval = Jim_EvalObj(teap->
interp, teap->
body);
4789 if (retval == JIM_RETURN)
4790 retval = teap->
interp->returnCode;
4792 if (retval != JIM_OK) {
4793 Jim_MakeErrorMessage(teap->
interp);
4796 Jim_GetString(Jim_GetResult(teap->
interp),
NULL));
4798 Jim_Eval(teap->
interp,
"error \"\" \"\"");
4806 if (CMD_ARGC < 1 || CMD_ARGC > 2)
4813 if (strcmp(
CMD_ARGV[0],
"-force")) {
4822 const int length = Jim_ListLength(
CMD_CTX->interp, next_argv);
4830 for (
int i = 0; i <
length; i++) {
4831 Jim_Obj *elem = Jim_ListGetIndex(
CMD_CTX->interp, next_argv, i);
4833 const char *reg_name = Jim_String(elem);
4872 #if JIM_VERSION >= 80
4885 const unsigned int length = tmp;
4895 for (
unsigned int i = 0; i <
length; i += 2) {
4896 const char *reg_name = Jim_String(dict[i]);
4897 const char *reg_value = Jim_String(dict[i + 1]);
4922 reg_value, reg_name);
4972 { .name =
"-tap", .value =
TCFG_TAP },
4974 { .name =
"-rtos", .value =
TCFG_RTOS },
4978 { .name =
NULL, .value = -1 }
4983 const struct nvp *n;
4998 const char *result = Jim_GetString(Jim_GetResult(
CMD_CTX->interp), &reslen);
5068 LOG_INFO(
"DEPRECATED target event %s; use TPIU events {pre,post}-{enable,disable}", n->
name);
5071 if (strlen(
CMD_ARGV[index]) == 0) {
5082 bool replace =
true;
5085 teap = calloc(1,
sizeof(*teap));
5105 Jim_IncrRefCount(teap->
body);
5348 command_print(
CMD,
"-gdb-max-connections must be configured before 'init'");
5374 bool is_configure = !strcmp(
CMD_NAME,
"configure");
5383 bool allow_defer =
false;
5389 if (strcmp(
CMD_ARGV[0],
"allow-defer"))
5402 LOG_INFO(
"Use arp_examine command to examine it manually!");
5549 "target: %s wait %s fails (%d) %s",
5568 "----------------------------------------");
5633 if (CMD_ARGC < 1 || CMD_ARGC > 3)
5642 unsigned int count = 1;
5646 const char *insn_set;
5661 .
name =
"configure",
5663 .handler = handle_target_configure,
5664 .help =
"configure a new target for use",
5665 .usage =
"[target_attribute ...]",
5670 .handler = handle_target_configure,
5671 .help =
"returns the specified target attribute",
5672 .usage =
"target_attribute",
5676 .handler = handle_mw_command,
5678 .help =
"Write 64-bit word(s) to target memory",
5679 .usage =
"address data [count]",
5683 .handler = handle_mw_command,
5685 .help =
"Write 32-bit word(s) to target memory",
5686 .usage =
"address data [count]",
5690 .handler = handle_mw_command,
5692 .help =
"Write 16-bit half-word(s) to target memory",
5693 .usage =
"address data [count]",
5697 .handler = handle_mw_command,
5699 .help =
"Write byte(s) to target memory",
5700 .usage =
"address data [count]",
5704 .handler = handle_md_command,
5706 .help =
"Display target memory as 64-bit words",
5707 .usage =
"address [count]",
5711 .handler = handle_md_command,
5713 .help =
"Display target memory as 32-bit words",
5714 .usage =
"address [count]",
5718 .handler = handle_md_command,
5720 .help =
"Display target memory as 16-bit half-words",
5721 .usage =
"address [count]",
5725 .handler = handle_md_command,
5727 .help =
"Display target memory as 8-bit bytes",
5728 .usage =
"address [count]",
5733 .handler = handle_target_get_reg,
5734 .help =
"Get register values from the target",
5735 .usage =
"[-force] list",
5740 .handler = handle_set_reg_command,
5741 .help =
"Set target register values",
5745 .name =
"read_memory",
5747 .handler = handle_target_read_memory,
5748 .help =
"Read Tcl list of 8/16/32/64 bit numbers from target memory",
5749 .usage =
"address width count ['phys']",
5752 .name =
"write_memory",
5754 .handler = handle_target_write_memory,
5755 .help =
"Write Tcl list of 8/16/32/64 bit numbers to target memory",
5756 .usage =
"address width data ['phys']",
5759 .name =
"calculate_checksum",
5760 .handler = handle_calculate_checksum_command,
5762 .usage =
"address size",
5765 .name =
"eventlist",
5766 .handler = handle_target_event_list,
5768 .help =
"displays a table of events defined for this target",
5774 .handler = handle_target_current_state,
5775 .help =
"displays the current state of this target",
5779 .name =
"debug_reason",
5781 .handler = handle_target_debug_reason,
5782 .help =
"displays the debug reason of this target",
5786 .name =
"arp_examine",
5788 .handler = handle_target_examine,
5789 .help =
"used internally for reset processing",
5790 .usage =
"['allow-defer']",
5793 .name =
"was_examined",
5795 .handler = handle_target_was_examined,
5796 .help =
"used internally for reset processing",
5800 .name =
"examine_deferred",
5802 .handler = handle_target_examine_deferred,
5803 .help =
"used internally for reset processing",
5807 .name =
"arp_halt_gdb",
5809 .handler = handle_target_halt_gdb,
5810 .help =
"used internally for reset processing to halt GDB",
5816 .handler = handle_target_poll,
5817 .help =
"used internally for reset processing",
5821 .name =
"arp_reset",
5823 .handler = handle_target_reset,
5824 .help =
"used internally for reset processing",
5825 .usage =
"'assert'|'deassert' halt",
5830 .handler = handle_target_halt,
5831 .help =
"used internally for reset processing",
5835 .name =
"arp_waitstate",
5837 .handler = handle_target_wait_state,
5838 .help =
"used internally for reset processing",
5839 .usage =
"statename timeoutmsecs",
5842 .name =
"invoke-event",
5844 .handler = handle_target_invoke_event,
5845 .help =
"invoke handler for specified event",
5846 .usage =
"event_name",
5849 .name =
"disassemble",
5851 .handler = handle_target_disassemble,
5852 .help =
"disassemble instructions",
5853 .usage =
"list | address [count [instruction_set]]",
5881 LOG_INFO(
"The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD");
5982 bool is_configure =
true;
6052 .help =
"target command group",
6054 .chain = target_subcommands,
6117 create_target_list_node(
const char *targetname)
6155 static unsigned int smp_group = 1;
6174 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
6192 struct target *rtos_target;
6194 if (retval ==
ERROR_OK && rtos_target)
6207 .handler = handle_target_init_command,
6208 .help =
"initialize targets",
6214 .handler = handle_target_create,
6215 .usage =
"name type [options ...]",
6216 .help =
"Creates and selects a new target",
6221 .handler = handle_target_current,
6222 .help =
"Returns the currently selected target",
6228 .handler = handle_target_types,
6229 .help =
"Returns the available target types as "
6230 "a list of strings",
6236 .handler = handle_target_names,
6237 .help =
"Returns the names of all targets as a list of strings",
6243 .handler = handle_target_smp,
6244 .usage =
"targetname1 targetname2 ...",
6245 .help =
"gather several target in a smp list"
6275 uint32_t image_size;
6279 LOG_WARNING(
"DEPRECATED! command 'fast_load_image' will be removed in the future, use 'load_image' or 'write_memory' instead");
6284 &
image, &min_address, &max_address);
6321 uint32_t
length = buf_cnt;
6340 command_print(
CMD,
"error allocating buffer for section (%" PRIu32
" bytes)",
6359 "in %fs (%0.3f KiB/s)", image_size,
6363 "WARNING: image has not been loaded to target!"
6364 "You can issue a 'fast_load' to finish loading.");
6377 LOG_WARNING(
"DEPRECATED! command 'fast_load' will be removed in the future, use 'load_image' or 'write_memory' instead");
6412 command_print(
CMD,
"Loaded image %f kBytes/s", (
float)(
size/1024.0)/((
float)(after-ms)/1000.0));
6420 .handler = handle_targets_command,
6422 .help =
"change current default target (one parameter) "
6423 "or prints table of all targets (no parameters)",
6424 .usage =
"[target]",
6429 .help =
"configure target",
6434 .name =
"poll_interval",
6435 .handler = handle_poll_interval_command,
6437 .help =
"print or set the target state polling interval",
6438 .usage =
"[milliseconds]",
6487 for (
int i = 0; i <
size; i++)
6509 size_t num_bytes = test_size + 4;
6518 uint8_t *test_pattern = malloc(num_bytes);
6520 for (
size_t i = 0; i < num_bytes; i++)
6521 test_pattern[i] = rand();
6529 for (
int host_offset = 0; host_offset <= 1; host_offset++) {
6533 size_t host_bufsiz = (
count + 2) *
size + host_offset;
6534 uint8_t *read_ref = malloc(host_bufsiz);
6535 uint8_t *read_buf = malloc(host_bufsiz);
6537 for (
size_t i = 0; i < host_bufsiz; i++) {
6538 read_ref[i] = rand();
6539 read_buf[i] = read_ref[i];
6542 "Test read %" PRIu32
" x %d @ %d to %saligned buffer: ",
count,
6549 read_buf +
size + host_offset);
6565 int result = memcmp(read_ref, read_buf, host_bufsiz);
6588 num_bytes = test_size + 4 + 4 + 4;
6596 test_pattern = malloc(num_bytes);
6598 for (
size_t i = 0; i < num_bytes; i++)
6599 test_pattern[i] = rand();
6601 for (
int host_offset = 0; host_offset <= 1; host_offset++) {
6605 size_t host_bufsiz =
count *
size + host_offset;
6606 uint8_t *read_ref = malloc(num_bytes);
6607 uint8_t *read_buf = malloc(num_bytes);
6608 uint8_t *write_buf = malloc(host_bufsiz);
6610 for (
size_t i = 0; i < host_bufsiz; i++)
6611 write_buf[i] = rand();
6613 "Test write %" PRIu32
" x %d @ %d from %saligned buffer: ",
count,
6623 memcpy(read_ref, test_pattern, num_bytes);
6630 write_buf + host_offset);
6650 int result = memcmp(read_ref, read_buf, num_bytes);
6675 .
name =
"fast_load_image",
6676 .handler = handle_fast_load_image_command,
6678 .help =
"Load image into server memory for later use by "
6679 "fast_load; primarily for profiling",
6680 .usage =
"filename [address ['bin'|'ihex'|'elf'|'s19' "
6681 "[min_address [max_length]]]]",
6684 .name =
"fast_load",
6685 .handler = handle_fast_load_command,
6687 .help =
"loads active fast load image to current target "
6688 "- mainly for profiling purposes",
6693 .handler = handle_profile_command,
6695 .usage =
"seconds filename [start end]",
6696 .help =
"profiling samples the CPU PC",
6700 .name =
"virt2phys",
6701 .handler = handle_virt2phys_command,
6703 .help =
"translate a virtual address into a physical address",
6704 .usage =
"virtual_address",
6708 .handler = handle_reg_command,
6710 .help =
"display (reread from target with \"force\") or set a register; "
6711 "with no arguments, displays all registers and their values",
6712 .usage =
"[(register_number|register_name) [(value|'force')]]",
6716 .handler = handle_poll_command,
6718 .help =
"poll target state; or reconfigure background polling",
6719 .usage =
"['on'|'off']",
6722 .name =
"wait_halt",
6723 .handler = handle_wait_halt_command,
6725 .help =
"wait up to the specified number of milliseconds "
6726 "(default 5000) for a previously requested halt",
6727 .usage =
"[milliseconds]",
6731 .handler = handle_halt_command,
6733 .help =
"request target to halt, then wait up to the specified "
6734 "number of milliseconds (default 5000) for it to complete",
6735 .usage =
"[milliseconds]",
6739 .handler = handle_resume_command,
6741 .help =
"resume target execution from current PC or address",
6742 .usage =
"[address]",
6746 .handler = handle_reset_command,
6748 .usage =
"[run|halt|init]",
6749 .help =
"Reset all targets into the specified mode. "
6750 "Default reset mode is run, if not given.",
6753 .name =
"soft_reset_halt",
6754 .handler = handle_soft_reset_halt_command,
6757 .help =
"halt the target and do a soft reset",
6761 .handler = handle_step_command,
6763 .help =
"step one instruction from current PC or address",
6764 .usage =
"[address]",
6768 .handler = handle_md_command,
6770 .help =
"display memory double-words",
6771 .usage =
"['phys'] address [count]",
6775 .handler = handle_md_command,
6777 .help =
"display memory words",
6778 .usage =
"['phys'] address [count]",
6782 .handler = handle_md_command,
6784 .help =
"display memory half-words",
6785 .usage =
"['phys'] address [count]",
6789 .handler = handle_md_command,
6791 .help =
"display memory bytes",
6792 .usage =
"['phys'] address [count]",
6796 .handler = handle_mw_command,
6798 .help =
"write memory double-word",
6799 .usage =
"['phys'] address value [count]",
6803 .handler = handle_mw_command,
6805 .help =
"write memory word",
6806 .usage =
"['phys'] address value [count]",
6810 .handler = handle_mw_command,
6812 .help =
"write memory half-word",
6813 .usage =
"['phys'] address value [count]",
6817 .handler = handle_mw_command,
6819 .help =
"write memory byte",
6820 .usage =
"['phys'] address value [count]",
6824 .handler = handle_bp_command,
6826 .help =
"list or set hardware or software breakpoint",
6827 .usage =
"[<address> [<asid>] <length> ['hw'|'hw_ctx']]",
6831 .handler = handle_rbp_command,
6833 .help =
"remove breakpoint",
6834 .usage =
"'all' | address",
6838 .handler = handle_wp_command,
6840 .help =
"list (no params) or create watchpoints",
6841 .usage =
"[address length [('r'|'w'|'a') [value [mask]]]]",
6845 .handler = handle_rwp_command,
6847 .help =
"remove watchpoint",
6848 .usage =
"'all' | address",
6851 .name =
"load_image",
6852 .handler = handle_load_image_command,
6854 .usage =
"filename [address ['bin'|'ihex'|'elf'|'s19' "
6855 "[min_address [max_length]]]]",
6858 .name =
"dump_image",
6859 .handler = handle_dump_image_command,
6861 .usage =
"filename address size",
6864 .name =
"verify_image_checksum",
6865 .handler = handle_verify_image_checksum_command,
6867 .usage =
"filename [offset [type]]",
6870 .name =
"verify_image",
6871 .handler = handle_verify_image_command,
6873 .usage =
"filename [offset [type]]",
6876 .name =
"test_image",
6877 .handler = handle_test_image_command,
6879 .usage =
"filename [offset [type]]",
6884 .handler = handle_target_get_reg,
6885 .help =
"Get register values from the target",
6886 .usage =
"[-force] list",
6891 .handler = handle_set_reg_command,
6892 .help =
"Set target register values",
6896 .name =
"read_memory",
6898 .handler = handle_target_read_memory,
6899 .help =
"Read Tcl list of 8/16/32/64 bit numbers from target memory",
6900 .usage =
"address width count ['phys']",
6903 .name =
"write_memory",
6905 .handler = handle_target_write_memory,
6906 .help =
"Write Tcl list of 8/16/32/64 bit numbers to target memory",
6907 .usage =
"address width data ['phys']",
6910 .name =
"calculate_checksum",
6911 .handler = handle_calculate_checksum_command,
6913 .usage =
"address size",
6916 .name =
"debug_reason",
6918 .handler = handle_target_debug_reason,
6919 .help =
"displays the debug reason of this target",
6923 .name =
"reset_nag",
6924 .handler = handle_target_reset_nag,
6926 .help =
"Nag after each reset about options that could have been "
6927 "enabled to improve performance.",
6928 .usage =
"['enable'|'disable']",
6932 .handler = handle_ps_command,
6934 .help =
"list all tasks",
6938 .name =
"test_mem_access",
6939 .handler = handle_test_mem_access_command,
6941 .help =
"Test the target's memory access functions",
6945 .name =
"disassemble",
6947 .handler = handle_target_disassemble,
6948 .help =
"disassemble instructions",
6949 .usage =
"list | address [count [instruction_set]]",
6975 return "BREAKPOINT";
6977 return "WATCHPOINT";
6979 return "WPTANDBKPT";
6981 return "SINGLESTEP";
struct target_type aarch64_target
struct target_type armv8r_target
struct target_type arcv2_target
struct target_type arm11_target
Holds methods for ARM11xx targets.
struct target_type arm720t_target
Holds methods for ARM720 targets.
struct target_type arm7tdmi_target
Holds methods for ARM7TDMI targets.
struct target_type arm920t_target
Holds methods for ARM920 targets.
struct target_type arm926ejs_target
Holds methods for ARM926 targets.
struct target_type arm946e_target
Holds methods for ARM946 targets.
struct target_type arm966e_target
Holds methods for ARM966 targets.
struct target_type arm9tdmi_target
Holds methods for ARM9TDMI targets.
struct target_type avr32_ap7k_target
struct target_type avr_target
char * buf_to_hex_str(const void *_buf, unsigned int buf_len)
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
int watchpoint_add(struct target *target, target_addr_t address, unsigned int length, enum watchpoint_rw rw, uint64_t value, uint64_t mask)
int breakpoint_remove(struct target *target, target_addr_t address)
int watchpoint_remove(struct target *target, target_addr_t address)
int breakpoint_add(struct target *target, target_addr_t address, unsigned int length, enum breakpoint_type type)
int context_breakpoint_add(struct target *target, uint32_t asid, unsigned int length, enum breakpoint_type type)
int watchpoint_remove_all(struct target *target)
int breakpoint_remove_all(struct target *target)
int hybrid_breakpoint_add(struct target *target, target_addr_t address, uint32_t asid, unsigned int length, enum breakpoint_type type)
#define WATCHPOINT_IGNORE_DATA_VALUE_MASK
struct command_context * current_command_context(Jim_Interp *interp)
int command_parse_bool_arg(const char *in, bool *out)
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
int command_run_line(struct command_context *context, char *line)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define COMMAND_PARSE_ADDRESS(in, out)
#define COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#define ERROR_COMMAND_SYNTAX_ERROR
static int register_commands_override_target(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds, struct target *target)
Register one or more commands, as register_commands(), plus specify that command should override the ...
#define ERROR_COMMAND_CLOSE_CONNECTION
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define CMD_JIMTCL_ARGV
Use this macro to access the jimtcl arguments for the command being handled, rather than accessing th...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
struct target_type cortexr4_target
struct target_type cortexa_target
struct target_type cortexm_target
struct target_type dsp563xx_target
Holds methods for DSP563XX targets.
struct target_type dsp5680xx_target
Holds methods for dsp5680xx targets.
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
uint32_t buffer_size
Size of dw_spi_program::buffer.
uint32_t address
Starting address. Sector aligned.
struct target_type esirisc_target
struct target_type esp32_target
Holds methods for Xtensa targets.
struct target_type esp32s2_target
struct target_type esp32s3_target
Holds methods for Xtensa targets.
static struct esp_usb_jtag * priv
struct target_type fa526_target
Holds methods for FA526 targets.
struct target_type dragonite_target
struct target_type feroceon_target
#define ERROR_FLASH_OPERATION_FAILED
int fileio_write(struct fileio *fileio, size_t size, const void *buffer, size_t *size_written)
int fileio_close(struct fileio *fileio)
int fileio_size(struct fileio *fileio, size_t *size)
FIX!!!!
int fileio_open(struct fileio **fileio, const char *url, enum fileio_access access_type, enum fileio_type type)
struct target_type hla_target
void image_close(struct image *image)
int image_read_section(struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
int image_calculate_checksum(const uint8_t *buffer, uint32_t nbytes, uint32_t *checksum)
int image_open(struct image *image, const char *url, const char *type_string)
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv)
void jtag_poll_unmask(bool saved)
Restore saved mask for polling.
struct jtag_tap * jtag_tap_by_string(const char *s)
void jtag_poll_set_enabled(bool value)
Assign flag reporting whether JTAG polling is disallowed.
int jtag_srst_asserted(int *srst_asserted)
bool is_jtag_poll_safe(void)
Return true if it's safe for a background polling task to access the JTAG scan chain.
int jtag_power_dropout(int *dropout)
int jtag_register_event_callback(jtag_event_handler_t callback, void *priv)
bool jtag_poll_get_enabled(void)
Return flag reporting whether JTAG polling is disallowed.
bool jtag_poll_mask(void)
Mask (disable) polling and return the current mask status that should be feed to jtag_poll_unmask() t...
The JTAG interface can be implemented with a software or hardware fifo.
static void list_add(struct list_head *new, struct list_head *head)
static void list_add_tail(struct list_head *new, struct list_head *head)
#define list_for_each_entry_safe(p, n, h, field)
#define list_for_each_entry(p, h, field)
static void list_del(struct list_head *entry)
static void INIT_LIST_HEAD(struct list_head *list)
void alive_sleep(uint64_t ms)
char * alloc_printf(const char *format,...)
#define LOG_TARGET_INFO(target, fmt_str,...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_TARGET_DEBUG_IO(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
struct target_type ls1_sap_target
struct target_type mem_ap_target
struct target_type mips_m4k_target
struct target_type mips_mips64_target
Upper level NOR flash interfaces.
void nvp_unknown_command_print(struct command_invocation *cmd, const struct nvp *nvp, const char *param_name, const char *param_value)
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
const struct nvp * nvp_value2name(const struct nvp *p, int value)
int oocd_cs_disassemble(struct command_invocation *cmd, struct target *target, uint64_t address, unsigned int count, const char *insn_set)
int oocd_cs_list_insn_types(struct command_invocation *cmd)
static uint32_t lh(unsigned int rd, unsigned int base, int16_t offset) __attribute__((unused))
struct target_type or1k_target
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
struct target_type quark_d20xx_target
struct target_type quark_x10xx_target
struct reg * register_get_by_name(struct reg_cache *first, const char *name, bool search_all)
struct target_type riscv_target
int rtos_create(struct command_invocation *cmd, struct target *target, const char *rtos_name)
void rtos_destroy(struct target *target)
int rtos_smp_init(struct target *target)
target_addr_t addr
Start address to search for the control block.
bool openocd_is_shutdown_pending(void)
#define CONNECTION_LIMIT_UNLIMITED
#define ERROR_SERVER_INTERRUPTED
#define foreach_smp_target(pos, head)
enum stldr_func_type type
struct target_type stm8_target
enum breakpoint_type type
struct target * current_target_override
struct target * current_target
When run_command is called, a new instance will be created on the stack, filled with the proper value...
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
const char * usage
a string listing the options and arguments, required or optional
unsigned int num_sections
struct imagesection * sections
target_addr_t base_address
A TCL -ish GetOpt like code.
bool enabled
Is this TAP currently enabled?
Name Value Pairs, aka: NVP.
int(* get)(struct reg *reg)
int(* set)(struct reg *reg, uint8_t *buf)
const struct reg_arch_type * type
char *(* ps_command)(struct target *target)
const struct rtos_type * type
char * basedir
Base directory for semihosting I/O operations.
int(* callback)(struct target *target, enum target_event event, void *priv)
struct target_event_callback * next
int(* callback)(struct target *target, enum target_reset_mode reset_mode, void *priv)
int(* callback)(void *priv)
struct target_timer_callback * next
enum target_timer_type type
int(* callback)(struct target *target, size_t len, uint8_t *data, void *priv)
This holds methods shared between all instances of a given target type.
int(* add_context_breakpoint)(struct target *target, struct breakpoint *breakpoint)
int(* add_breakpoint)(struct target *target, struct breakpoint *breakpoint)
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Target memory write callback.
int(* hit_watchpoint)(struct target *target, struct watchpoint **hit_watchpoint)
const char * name
Name of this type of target.
int(* deassert_reset)(struct target *target)
The implementation is responsible for polling the target such that target->state reflects the state c...
int(* get_gdb_reg_list)(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Target register access for GDB.
int(* insn_set)(struct command_invocation *cmd, struct target *target, const char **insn_set)
int(* resume)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
int(* blank_check_memory)(struct target *target, struct target_memory_check_block *blocks, unsigned int num_blocks, uint8_t erased_value, unsigned int *checked)
void(* deinit_target)(struct target *target)
Free all the resources allocated by the target.
int(* halt)(struct target *target)
int(* check_reset)(struct target *target)
int(* gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
int(* assert_reset)(struct target *target)
int(* run_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Target algorithm support.
int(* wait_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
const struct command_registration * commands
int(* profiling)(struct target *target, uint32_t *samples, uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
int(* soft_reset_halt)(struct target *target)
const char *(* get_gdb_arch)(const struct target *target)
Target architecture for GDB.
int(* arch_state)(struct target *target)
unsigned int(* address_bits)(struct target *target)
int(* read_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Target memory read callback.
int(* get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info)
unsigned int(* data_bits)(struct target *target)
int(* target_jim_configure)(struct target *target, struct jim_getopt_info *goi)
int(* step)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
int(* read_phys_memory)(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer)
int(* get_gdb_reg_list_noread)(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Same as get_gdb_reg_list, but doesn't read the register values.
int(* start_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
int(* read_buffer)(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int(* add_watchpoint)(struct target *target, struct watchpoint *watchpoint)
int(* target_create)(struct target *target)
bool(* memory_ready)(struct target *target)
Returns true if target memory is read to read/write.
int(* write_buffer)(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int(* poll)(struct target *target)
int(* mmu)(struct target *target, bool *enabled)
int(* add_hybrid_breakpoint)(struct target *target, struct breakpoint *breakpoint)
int(* examine)(struct target *target)
This method is used to perform target setup that requires JTAG access.
int(* write_phys_memory)(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, const uint8_t *buffer)
int(* remove_breakpoint)(struct target *target, struct breakpoint *breakpoint)
int(* virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical)
int(* checksum_memory)(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
int(* remove_watchpoint)(struct target *target, struct watchpoint *watchpoint)
struct semihosting * semihosting
target_addr_t working_area
target_addr_t working_area_virt
uint32_t working_area_size
struct trace * trace_info
enum target_debug_reason debug_reason
bool active_polled
The flag is set after a successful examine call.
enum target_endianness endianness
struct reg_cache * reg_cache
struct list_head * smp_targets
struct breakpoint * breakpoints
struct working_area * working_areas
struct gdb_fileio_info * fileio_info
struct debug_msg_receiver * dbgmsg
struct list_head events_action
struct target_type * type
struct backoff_timer backoff
target_addr_t working_area_phys
struct watchpoint * watchpoints
bool working_area_phys_spec
bool running_alg
true if the target is currently running a downloaded "algorithm" instead of arbitrary user code.
bool working_area_virt_spec
bool examined
Indicates whether this target has been examined, remembers the last result of examine call.
bool defer_examine
Should we defer examine to later.
Wrapper for transport lifecycle operations.
int(* override_target)(const char **targetname)
Optional.
struct working_area * next
struct working_area ** user
COMMAND_HANDLER(handle_target_init_command)
static bool target_reset_nag
void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf)
void target_buffer_set_u24(struct target *target, uint8_t *buffer, uint32_t value)
int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
Obtain file-I/O information from target for GDB to do syscall.
static int run_srst_deasserted
int target_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Add the watchpoint for target.
static int target_call_timer_callback(struct target_timer_callback *cb, int64_t *now)
static int no_mmu(struct target *target, bool *enabled)
struct target * all_targets
static int target_get_gdb_fileio_info_default(struct target *target, struct gdb_fileio_info *fileio_info)
int target_run_read_async_algorithm(struct target *target, uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
This routine is a wrapper for asynchronous algorithms.
int target_write_phys_u32(struct target *target, target_addr_t address, uint32_t value)
static int compare_pc32(const void *p1, const void *p2)
static int sensed_power_dropout
uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer)
int target_call_event_callbacks(struct target *target, enum target_event event)
struct target * get_target(const char *id)
void target_free_all_working_areas(struct target *target)
int target_unregister_reset_callback(int(*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv), void *priv)
int target_write_phys_u64(struct target *target, target_addr_t address, uint64_t value)
static const struct nvp nvp_target_event[]
static OOCD_LIST_HEAD(target_reset_callback_list)
static int target_write_buffer_default(struct target *target, target_addr_t address, uint32_t count, const uint8_t *buffer)
int target_unregister_event_callback(int(*callback)(struct target *target, enum target_event event, void *priv), void *priv)
static void write_long(FILE *f, int l, struct target *target)
int target_read_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
static void target_free_all_working_areas_restore(struct target *target, bool restore)
static void binprint(struct command_invocation *cmd, const char *text, const uint8_t *buf, int size)
int target_register_event_callback(int(*callback)(struct target *target, enum target_event event, void *priv), void *priv)
static const struct command_registration target_command_handlers[]
int target_write_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int run_power_restore
int target_halt(struct target *target)
static struct target_timer_callback * target_timer_callbacks
int target_get_gdb_reg_list_noread(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Obtain the registers for GDB, but don't read register values from the target.
static int target_timer_callback_set_period(struct target_timer_callback *cb, unsigned int time_ms)
bool target_supports_gdb_connection(const struct target *target)
Check if target allows GDB connections.
int target_arch_state(struct target *target)
void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value)
int target_call_timer_callbacks_now(void)
Invoke this to ensure that e.g.
int target_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Remove the breakpoint for target.
static int target_profiling(struct target *target, uint32_t *samples, uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
int target_register_commands(struct command_context *cmd_ctx)
static const struct nvp nvp_target_debug_reason[]
static int target_read_buffer_default(struct target *target, target_addr_t address, uint32_t count, uint8_t *buffer)
int target_checksum_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t *crc)
static void target_merge_working_areas(struct target *target)
static const struct nvp nvp_target_state[]
static unsigned int polling_interval
static int handle_bp_command_list(struct command_invocation *cmd)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
static int get_target_with_common_rtos_type(struct command_invocation *cmd, struct list_head *lh, struct target **result)
int target_add_hybrid_breakpoint(struct target *target, struct breakpoint *breakpoint)
Add the ContextID & IVA breakpoint for target.
static int default_examine(struct target *target)
int target_write_u8(struct target *target, target_addr_t address, uint8_t value)
int target_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Add the breakpoint for target.
target_addr_t target_address_max(struct target *target)
Return the highest accessible address for this target.
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
static void free_smp_target_list(struct list_head *smp_targets)
int target_unregister_timer_callback(int(*callback)(void *priv), void *priv)
int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
Pass GDB file-I/O response to target after finishing host syscall.
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_unregister_trace_callback(int(*callback)(struct target *target, size_t len, uint8_t *data, void *priv), void *priv)
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
static void write_string(FILE *f, char *s)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
static void target_buffer_set_u8(struct target *target, uint8_t *buffer, uint8_t value)
unsigned int target_address_bits(struct target *target)
Return the number of address bits this target supports.
static struct target_list * __attribute__((warn_unused_result))
int target_profiling_default(struct target *target, uint32_t *samples, uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
static const struct command_registration target_subcommand_handlers[]
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
static struct target_timer_callback * target_find_timer_callback(int(*callback)(void *priv), void *priv)
static int jtag_enable_callback(enum jtag_event event, void *priv)
int target_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Obtain the registers for GDB.
static int target_insn_set(struct command_invocation *cmd, struct target *target, const char **insn_set)
static const struct nvp nvp_error_target[]
int target_call_timer_callbacks(void)
int target_write_u64(struct target *target, target_addr_t address, uint64_t value)
static struct target_event_callback * target_event_callbacks
static COMMAND_HELPER(parse_load_image_command, struct image *image, target_addr_t *min_address, target_addr_t *max_address)
struct target * get_current_target_or_null(struct command_context *cmd_ctx)
static void target_split_working_area(struct working_area *area, uint32_t size)
const char * target_debug_reason_str(enum target_debug_reason reason)
static int target_init(struct command_context *cmd_ctx)
int target_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
Find out the just hit watchpoint for target.
int target_call_reset_callbacks(struct target *target, enum target_reset_mode reset_mode)
uint32_t target_get_working_area_avail(struct target *target)
@ TCFG_GDB_MAX_CONNECTIONS
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
static void write_gmon_hist(FILE *f, const uint32_t *samples, uint32_t sample_num, float sample_rate, struct target *target)
static const struct command_registration target_instance_command_handlers[]
bool get_target_reset_nag(void)
unsigned int target_data_bits(struct target *target)
Return the number of data bits this target supports.
static int find_target(struct command_invocation *cmd, const char *name)
int target_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Remove the watchpoint for target.
const char * target_event_name(enum target_event event)
Return the name of a target event enumeration value.
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_examine_one(struct target *target)
Examine the specified target, letting it perform any Initialisation that requires JTAG access.
bool target_memory_ready(struct target *target)
Returns true if target memory is ready to read/write.
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
int(* target_write_fn)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static void print_wa_layout(struct target *target)
#define DEFAULT_HALT_TIMEOUT
static int handle_one_target(struct target *target)
int target_poll(struct target *target)
static int target_call_timer_callbacks_check_time(int checktime)
static int sense_handler(void)
static int target_timer_callback_periodic_restart(struct target_timer_callback *cb, int64_t *now)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
static const struct nvp nvp_target_endian[]
int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
static int sensed_srst_asserted
int target_register_timer_callback(int(*callback)(void *priv), unsigned int time_ms, enum target_timer_type type, void *priv)
The period is very approximate, the callback can happen much more often or much more rarely than spec...
static struct nvp nvp_config_opts[]
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
int target_run_flash_async_algorithm(struct target *target, const uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
Streams data to a circular buffer on target intended for consumption by code running asynchronously o...
void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value)
void target_buffer_set_u64_array(struct target *target, uint8_t *buffer, uint32_t count, const uint64_t *srcbuf)
static void target_reset_examined(struct target *target)
Reset the examined flag for the given target.
int target_add_context_breakpoint(struct target *target, struct breakpoint *breakpoint)
Add the ContextID breakpoint for target.
static int target_init_one(struct command_context *cmd_ctx, struct target *target)
static int run_power_dropout
int target_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
int target_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, unsigned int num_blocks, uint8_t erased_value, unsigned int *checked)
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer)
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
bool target_has_event_action(const struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
static const struct command_registration target_exec_command_handlers[]
void target_buffer_get_u64_array(struct target *target, const uint8_t *buffer, uint32_t count, uint64_t *dstbuf)
static const struct nvp nvp_reset_modes[]
const char * debug_reason_name(const struct target *t)
static int default_check_reset(struct target *target)
void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf)
static struct fast_load * fastload
int target_register_reset_callback(int(*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv), void *priv)
uint32_t target_buffer_get_u24(struct target *target, const uint8_t *buffer)
static int run_srst_asserted
void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf)
int64_t target_timer_next_event(void)
Returns when the next registered event will take place.
int target_write_phys_u16(struct target *target, target_addr_t address, uint16_t value)
static void free_fastload(void)
static void write_gmon(const uint32_t *samples, uint32_t sample_num, const char *filename, struct target *target, uint32_t duration_ms)
static int handle_target(void *priv)
const char * target_get_gdb_arch(const struct target *target)
Obtain the architecture for GDB.
static int target_restore_working_area(struct target *target, struct working_area *area)
static int target_gdb_fileio_end_default(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
int target_wait_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Waits for an algorithm started with target_start_algorithm() to complete.
static int target_fill_mem(struct target *target, target_addr_t address, target_write_fn fn, unsigned int data_size, uint64_t b, unsigned int c)
static void target_destroy(struct target *target)
static void target_reset_active_polled(struct target *target)
int target_wait_state(struct target *target, enum target_state state, unsigned int ms)
int target_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Step the target.
int target_register_trace_callback(int(*callback)(struct target *target, size_t len, uint8_t *data, void *priv), void *priv)
struct target * get_current_target(struct command_context *cmd_ctx)
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
static int target_free_working_area_restore(struct target *target, struct working_area *area, bool restore)
static int handle_bp_command_set(struct command_invocation *cmd, target_addr_t addr, uint32_t asid, unsigned int length, int hw)
static int identity_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
static int target_register_user_commands(struct command_context *cmd_ctx)
static void append_to_list_all_targets(struct target *target)
void target_handle_event(struct target *target, enum target_event e)
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
static int target_soft_reset_halt(struct target *target)
const char * target_type_name(const struct target *target)
Get the target type name.
int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data)
static int target_process_reset(struct command_invocation *cmd, enum target_reset_mode reset_mode)
static const char * target_strerror_safe(int err)
static int64_t target_timer_next_event_value
int target_start_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
Executes a target-specific native code algorithm and leaves it running.
static void write_data(FILE *f, const void *data, size_t len)
void target_quit(void)
Free all the resources allocated by targets and the target layer.
int target_write_phys_u8(struct target *target, target_addr_t address, uint8_t value)
static struct target_type * target_types[]
void target_handle_md_output(struct command_invocation *cmd, struct target *target, target_addr_t address, unsigned int size, unsigned int count, const uint8_t *buffer, bool include_address)
int target_read_u64(struct target *target, target_addr_t address, uint64_t *value)
const char * target_reset_mode_name(enum target_reset_mode reset_mode)
Return the name of a target reset reason enumeration value.
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_INIT_FAILED
static bool target_was_examined(const struct target *target)
static bool target_active_polled(const struct target *target)
#define ERROR_TARGET_UNALIGNED_ACCESS
#define ERROR_TARGET_INVALID
@ TARGET_TIMER_TYPE_PERIODIC
@ TARGET_EVENT_DEBUG_RESUMED
@ TARGET_EVENT_EXAMINE_START
@ TARGET_EVENT_RESET_START
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X106
@ TARGET_EVENT_GDB_FLASH_WRITE_END
@ TARGET_EVENT_RESET_ASSERT_POST
@ TARGET_EVENT_RESET_DEASSERT_POST
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X102
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X107
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X105
@ TARGET_EVENT_EXAMINE_FAIL
@ TARGET_EVENT_EXAMINE_END
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X104
@ TARGET_EVENT_RESET_INIT
@ TARGET_EVENT_RESET_DEASSERT_PRE
@ TARGET_EVENT_GDB_FLASH_ERASE_START
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X103
@ TARGET_EVENT_DEBUG_HALTED
@ TARGET_EVENT_RESET_ASSERT_PRE
@ TARGET_EVENT_RESET_ASSERT
@ TARGET_EVENT_GDB_FLASH_WRITE_START
@ TARGET_EVENT_RESUME_START
@ TARGET_EVENT_STEP_START
@ TARGET_EVENT_GDB_ATTACH
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X100
@ TARGET_EVENT_SEMIHOSTING_USER_CMD_0X101
@ TARGET_EVENT_RESUME_END
@ TARGET_EVENT_GDB_FLASH_ERASE_END
@ TARGET_EVENT_GDB_DETACH
@ TARGET_EVENT_TRACE_CONFIG
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ERROR_TARGET_NOT_EXAMINED
#define TARGET_DEFAULT_POLLING_INTERVAL
#define ERROR_TARGET_TIMEOUT
#define TARGET_MAX_POLLING_INTERVAL_MS
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
static void target_set_examined(struct target *target)
Sets the examined and active_polled flags for the given target.
#define ERROR_TARGET_NOT_RUNNING
#define ERROR_TARGET_DATA_ABORT
#define ERROR_TARGET_FAILURE
#define ERROR_TARGET_TRANSLATION_FAULT
int target_request_register_commands(struct command_context *cmd_ctx)
struct target_type testee_target
struct target_type xtensa_chip_target
Methods for generic example of Xtensa-based chip-level targets.
struct target_type xscale_target
float duration_elapsed(const struct duration *duration)
int duration_measure(struct duration *duration)
Update the duration->elapsed field to finish the duration measurement.
int duration_start(struct duration *duration)
Update the duration->start field to start the duration measurement.
float duration_kbps(const struct duration *duration, size_t count)
int trace_register_commands(struct command_context *cmd_ctx)
struct transport * get_current_transport(void)
Returns the transport currently being used by this debug or programming session.
static void h_u32_to_be(uint8_t *buf, uint32_t val)
static uint64_t le_to_h_u64(const uint8_t *buf)
static uint32_t be_to_h_u24(const uint8_t *buf)
static void h_u16_to_be(uint8_t *buf, uint16_t val)
static uint64_t be_to_h_u64(const uint8_t *buf)
static uint16_t le_to_h_u16(const uint8_t *buf)
static uint32_t le_to_h_u24(const uint8_t *buf)
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static uint32_t be_to_h_u32(const uint8_t *buf)
static void h_u24_to_le(uint8_t *buf, unsigned int val)
static void h_u24_to_be(uint8_t *buf, unsigned int val)
static uint16_t be_to_h_u16(const uint8_t *buf)
static void h_u16_to_le(uint8_t *buf, uint16_t val)
static uint32_t le_to_h_u32(const uint8_t *buf)
static void h_u64_to_be(uint8_t *buf, uint64_t val)
static void h_u64_to_le(uint8_t *buf, uint64_t val)