firmware/ice40-riscv: Import common parts to all iCE40/RISC-V firmwares

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
diff --git a/firmware/ice40-riscv/common/utils.c b/firmware/ice40-riscv/common/utils.c
new file mode 100644
index 0000000..67b292f
--- /dev/null
+++ b/firmware/ice40-riscv/common/utils.c
@@ -0,0 +1,31 @@
+/*
+ * utils.c
+ *
+ * Copyright (C) 2019-2020  Sylvain Munaut <tnt@246tNt.com>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+
+char *
+hexstr(void *d, int n, bool space)
+{
+	static const char * const hex = "0123456789abcdef";
+	static char buf[96];
+	uint8_t *p = d;
+	char *s = buf;
+	char c;
+
+	while (n--) {
+		c = *p++;
+		*s++ = hex[c >> 4];
+		*s++ = hex[c & 0xf];
+		if (space)
+			*s++ = ' ';
+	}
+
+	s[space?-1:0] = '\0';
+
+	return buf;
+}