2017-07-25 13:18:48 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
let fs = require("fs")
|
2017-07-27 13:49:34 +02:00
|
|
|
// we try to use shorter versions of all parameters for the additional parameters to fit
|
|
|
|
let bootargs = "mem=${memsize} initrd=${filesysaddr},${filesyssize} root=/dev/ram0 rw rootfstype=cramfs console=${console} ip=${ipaddr} lpj=747520 quiet"
|
|
|
|
let bootnews = "mem=64M initrd=0xC1180000,10M root=1:0 rw rootfstype=cramfs console=${console} lpj=747520 musb_hdrc.use_dma=0 log_buf_len=128k quiet"
|
2017-07-26 19:57:46 +02:00
|
|
|
let piggy = true
|
2017-07-25 13:18:48 +02:00
|
|
|
|
|
|
|
function build() {
|
2017-07-26 19:57:46 +02:00
|
|
|
if (bootnews.length > bootargs.length) {
|
|
|
|
console.log("args too long")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
while (bootnews.length < bootargs.length)
|
|
|
|
bootnews += " "
|
|
|
|
|
2017-07-25 13:18:48 +02:00
|
|
|
let cr = fs.readFileSync("cram.bin")
|
2017-07-27 22:11:23 +02:00
|
|
|
|
|
|
|
if (cr.length > 10485760) {
|
|
|
|
console.log("too big by " + (cr.length - 10485760))
|
2017-07-25 13:18:48 +02:00
|
|
|
return
|
|
|
|
}
|
2017-07-26 19:57:46 +02:00
|
|
|
let img = fs.readFileSync("EV3 Firmware V1.09D.bin")
|
|
|
|
|
|
|
|
for (let i = 0; i < bootnews.length; ++i) {
|
|
|
|
if (img[0x21DDA + i] != bootargs.charCodeAt(i)) {
|
|
|
|
console.log("boot args mismatch")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
img[0x21DDA + i] = bootnews.charCodeAt(i)
|
|
|
|
}
|
|
|
|
|
2017-07-25 13:18:48 +02:00
|
|
|
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)
|
|
|
|
|
2017-07-26 19:57:46 +02:00
|
|
|
let kern = fs.readFileSync(piggy ? "piggy-patched.gzip" : "linux/arch/arm/boot/uImage")
|
|
|
|
off = piggy ? 0x0005540f : 0x00050000
|
2017-07-25 13:18:48 +02:00
|
|
|
|
|
|
|
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()
|