aboutsummaryrefslogtreecommitdiff
path: root/utils/debug
diff options
context:
space:
mode:
authorJakob Stendahl <jakobste@uio.no>2021-01-11 13:41:18 +0100
committerJakob Stendahl <jakobste@uio.no>2021-01-11 13:41:18 +0100
commitd17bc0fc4bb057378fadf3f9feb0de1df60d611a (patch)
treeca3069eeacb0b7379cb289d87be932956e449d9c /utils/debug
parent19d65c7b2e287223113ab916e103638c5c5003f5 (diff)
downloadhoverbit-ble-d17bc0fc4bb057378fadf3f9feb0de1df60d611a.tar.gz
hoverbit-ble-d17bc0fc4bb057378fadf3f9feb0de1df60d611a.zip
:sparkles: Add working bluetooth receiver
Diffstat (limited to 'utils/debug')
-rwxr-xr-xutils/debug/dmesg.js86
-rwxr-xr-xutils/debug/meminfo.js65
2 files changed, 151 insertions, 0 deletions
diff --git a/utils/debug/dmesg.js b/utils/debug/dmesg.js
new file mode 100755
index 0000000..e62b5e3
--- /dev/null
+++ b/utils/debug/dmesg.js
@@ -0,0 +1,86 @@
+#!/usr/bin/env node
+"use strict";
+
+let fs = require("fs")
+let child_process = require("child_process")
+
+function fatal(msg) {
+ console.log("Fatal error:", msg)
+ process.exit(1)
+}
+
+function main() {
+ let mapFileName = process.argv[2]
+ if (!mapFileName) {
+ console.log("usage: node " + process.argv[1] + " build/mytarget/source/myprog.map")
+ return
+ }
+ console.log("Map file: " + mapFileName)
+ let mapFile = fs.readFileSync(mapFileName, "utf8")
+ let addr = 0
+ let logSize = 1024 * 4 + 4
+ for (let ln of mapFile.split(/\r?\n/)) {
+ let m = /^\s*0x00000([0-9a-f]+)\s+(\S+)/.exec(ln)
+ if (m && m[2] == "codalLogStore") {
+ addr = parseInt(m[1], 16)
+ break
+ }
+ }
+ if (!addr) fatal("Cannot find codalLogStore symbol in map file")
+
+ let dirs = [
+ process.env["HOME"] + "/Library/Arduino15",
+ process.env["USERPROFILE"] + "/AppData/Local/Arduino15",
+ process.env["HOME"] + "/.arduino15",
+ ]
+
+ let pkgDir = ""
+
+ for (let d of dirs) {
+ pkgDir = d + "/packages/arduino/"
+ if (fs.existsSync(pkgDir)) break
+ pkgDir = ""
+ }
+
+ if (!pkgDir) fatal("cannot find Arduino packages directory")
+
+ let openocdPath = pkgDir + "tools/openocd/0.9.0-arduino/"
+ if (!fs.existsSync(openocdPath)) fatal("openocd not installed in Arduino")
+
+ let openocdBin = openocdPath + "bin/openocd"
+
+ if (process.platform == "win32")
+ openocdBin += ".exe"
+
+ let zeroCfg = pkgDir + "hardware/samd/1.6.8/variants/arduino_zero/openocd_scripts/arduino_zero.cfg"
+ let cmd = `init; set M(0) 0; mem2array M 8 ${addr} ${logSize}; parray M; exit`
+
+ console.log("Starting openocd")
+ child_process.execFile(openocdBin, ["-d2",
+ "-s", openocdPath + "/share/openocd/scripts/",
+ "-f", zeroCfg,
+ "-c", cmd], {
+ maxBuffer: 1 * 1024 * 1024,
+ }, (err, stdout, stderr) => {
+ if (err) {
+ fatal("error: " + err.message)
+ }
+ let buf = new Buffer(logSize)
+ for (let l of stdout.split(/\r?\n/)) {
+ let m = /^M\((\d+)\)\s*=\s*(\d+)/.exec(l)
+ if (m) {
+ buf[parseInt(m[1])] = parseInt(m[2])
+ }
+ }
+ let len = buf.readUInt32LE(0)
+ if (len == 0 || len > buf.length) {
+ console.log(stderr)
+ console.log("No logs.")
+ } else {
+ console.log("*\n* Logs\n*\n")
+ console.log(buf.slice(4, 4 + len).toString("binary"))
+ }
+ })
+}
+
+main() \ No newline at end of file
diff --git a/utils/debug/meminfo.js b/utils/debug/meminfo.js
new file mode 100755
index 0000000..e25b043
--- /dev/null
+++ b/utils/debug/meminfo.js
@@ -0,0 +1,65 @@
+#!/usr/bin/env node
+"use strict";
+
+function main() {
+ let fs = require("fs");
+ let mfn = process.argv[2]
+ if (!mfn) {
+ console.log("usage: node " + process.argv[1] + " build/mytarget/source/myprog.map")
+ return
+ }
+ console.log("Map file: " + mfn)
+ let map = fs.readFileSync(mfn, "utf8")
+ let inSect = 0
+ let byFileRAM = {}
+ let byFileROM = {}
+ for (let ln of map.split(/\r?\n/)) {
+ if (ln == "Linker script and memory map") {
+ inSect = 1
+ }
+ if (/^OUTPUT\(/.test(ln)) {
+ inSect = 2
+ }
+ if (inSect == 1) {
+ let m = /^\s*(\S*)\s+0x00000([0-9a-f]+)\s+0x([0-9a-f]+)\s+(\S+)/.exec(ln)
+ if (m) {
+ let mark = m[1]
+ if (mark == "*fill*" || mark == ".bss" || mark == ".relocate")
+ continue;
+ let addr = parseInt(m[2], 16)
+ let sz = parseInt(m[3], 16)
+ let fn = m[4]
+ if (fn == "load" && mark) fn = mark;
+ fn = fn.replace(/.*armv6-m/, "")
+ if (sz) {
+ let mm = addr < 0x10000000 ? byFileROM : byFileRAM
+ mm[fn] = (mm[fn] || 0) + sz
+ }
+ }
+ }
+ }
+
+ console.log("*\n* ROM\n*")
+ dumpMap(byFileROM)
+ console.log("*\n* RAM\n*")
+ dumpMap(byFileRAM)
+}
+
+function printEnt(sz, s) {
+ let ff = (" " + sz).slice(-7)
+ console.log(ff + " " + s)
+}
+
+function dumpMap(m) {
+ let k = Object.keys(m)
+ k.sort((a, b) => m[a] - m[b])
+ let sum = 0
+ for (let s of k) {
+ printEnt(m[s], s)
+ sum += m[s]
+ }
+ printEnt(sum, "TOTAL")
+}
+
+
+main() \ No newline at end of file