Add support scripts

This commit is contained in:
Michal Moskal 2017-07-25 12:18:48 +01:00
parent 11bcf77402
commit de180e97aa
4 changed files with 79 additions and 0 deletions

34
brick/scripts/dump.js Normal file
View File

@ -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()

33
brick/scripts/img.js Normal file
View File

@ -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()

4
brick/scripts/mkimg Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
sudo mkfs.cramfs dev-ev3 cram.bin
node img
ls -l firmware.bin

View File

@ -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)