aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/binarybuffer.c27
-rw-r--r--src/helper/binarybuffer.h5
2 files changed, 32 insertions, 0 deletions
diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index d98fa16..a90ec7b 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -370,3 +370,30 @@ void bit_copy_discard(struct bit_copy_queue *q)
free(qe);
}
}
+
+int unhexify(char *bin, const char *hex, int count)
+{
+ int i, tmp;
+
+ for (i = 0; i < count; i++) {
+ if (sscanf(hex + (2 * i), "%02x", &tmp) != 1)
+ return i;
+ bin[i] = tmp;
+ }
+
+ return i;
+}
+
+int hexify(char *hex, const char *bin, int count, int out_maxlen)
+{
+ int i, cmd_len = 0;
+
+ /* May use a length, or a null-terminated string as input. */
+ if (count == 0)
+ count = strlen(bin);
+
+ for (i = 0; i < count; i++)
+ cmd_len += snprintf(hex + cmd_len, out_maxlen - cmd_len, "%02x", bin[i]);
+
+ return cmd_len;
+}
diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h
index cc0be57..633ed9e 100644
--- a/src/helper/binarybuffer.h
+++ b/src/helper/binarybuffer.h
@@ -156,4 +156,9 @@ int bit_copy_queued(struct bit_copy_queue *q, uint8_t *dst, unsigned dst_offset,
void bit_copy_execute(struct bit_copy_queue *q);
void bit_copy_discard(struct bit_copy_queue *q);
+/* functions to convert to/from hex encoded buffer
+ * used in ti-icdi driver and gdb server */
+int unhexify(char *bin, const char *hex, int count);
+int hexify(char *hex, const char *bin, int count, int out_maxlen);
+
#endif /* BINARYBUFFER_H */