diff --git a/brick/scripts/dump.js b/brick/scripts/dump.js new file mode 100644 index 00000000..9e017231 --- /dev/null +++ b/brick/scripts/dump.js @@ -0,0 +1,34 @@ +#!/bin/sh + +let fs = require("fs") + +let styles = { + "0": "rxtx", + "1": " tx", + "2": "rx ", +} + +function build() { + let kern = fs.readFileSync( "foo") + let off = 0x0001df30 + + kern = kern.slice(off + 6 * 5, off + 6 * (5 + 6)) +console.log(kern.toString("hex")) +off = 0 + +for (let i = 0; i < 30; ++i) { + if (kern[off+4] == 64) { + kern[off+4] = 0 + kern[off+5] = 2 + } +if(kern[off] == 3 || kern[off] == 4) { + kern[off+4] = 0 + kern[off+5] = 1 +} + console.log(`ep=${kern[off]} style=${styles[kern[off+1]]} buf=${kern[off+2] == 0 ? "sin" : kern[off+2] == 1 ? "dbl" : "XXX"} pad=${kern[off+3]} sz=${kern[off+4]+(kern[off+5]<<8)}`) + off += 6 +} +console.log(kern.toString("hex")) +} + +build() diff --git a/brick/scripts/img.js b/brick/scripts/img.js new file mode 100644 index 00000000..b421a138 --- /dev/null +++ b/brick/scripts/img.js @@ -0,0 +1,33 @@ +#!/bin/sh + +let fs = require("fs") + +function build() { + let cr = fs.readFileSync("cram.bin") + if (cr.length > 10878976) { + console.log("too big") + return + } + let img = fs.readFileSync("boot.bin") + let off = 0x250000 + if (img[off] != 0x45 || img[off + 1] != 0x3d) { + console.log("bad magic: " + img[off] + " / " + img[off+1]) + return + } + + cr.copy(img, off) + + let kern = fs.readFileSync("piggy-patched.gzip") + off = 0x0005540f + + if (img[off] != kern[0] || img[off+1] != kern[1]) { + console.log("bad kernel magic: " + img[off] + " / " + img[off+1]) + return + } + + kern.copy(img, off) + + fs.writeFileSync("firmware.bin", img) +} + +build() diff --git a/brick/scripts/mkimg b/brick/scripts/mkimg new file mode 100755 index 00000000..f67277d3 --- /dev/null +++ b/brick/scripts/mkimg @@ -0,0 +1,4 @@ +#!/bin/sh +sudo mkfs.cramfs dev-ev3 cram.bin +node img +ls -l firmware.bin diff --git a/brick/scripts/patchkern.js b/brick/scripts/patchkern.js new file mode 100644 index 00000000..8ceb2041 --- /dev/null +++ b/brick/scripts/patchkern.js @@ -0,0 +1,8 @@ +let small = "010100000004010200000004020100004000020200004000030100000004040000008000" +let big = "010100000004010200000004020100000002020200000002030100000001040000000001" + +let fs = require("fs") + +let kern = fs.readFileSync( "foo") +let kern2 = new Buffer(kern.toString("hex").replace(small, big), "hex") +fs.writeFileSync("foo2", kern2)